예제 #1
0
        public static NetworkChannel OpenChannel(string targetServerName, ISimpleBufferPool socketStreamBufferPool, IPool <SocketStreamAsyncArgs> socketStreamAsyncArgPool, SocketStream.ISocketStreamPerfCounters perfCtrs, bool suppressTransparentCompression)
        {
            if (socketStreamAsyncArgPool != null ^ socketStreamBufferPool != null)
            {
                string message = "SocketStream use requires both pools or neither";
                throw new ArgumentException(message);
            }
            ITcpConnector    tcpConnector = Dependencies.TcpConnector;
            NetworkPath      netPath      = null;
            TcpClientChannel tcpChannel   = tcpConnector.OpenChannel(targetServerName, socketStreamBufferPool, socketStreamAsyncArgPool, perfCtrs, out netPath);

            return(NetworkChannel.FinishConnect(tcpChannel, netPath, suppressTransparentCompression));
        }
 public DefaultProxyFactory(
     IDatagramInterceptor datagramInterceptor,
     ITcpConnector tcpConnector,
     IUdpClientFactory udpClientFactory,
     ILoggerFactory loggerFactory)
 {
     this._datagramInterceptor = datagramInterceptor
                                 ?? throw new ArgumentNullException(nameof(datagramInterceptor));
     this._tcpConnector     = tcpConnector ?? throw new ArgumentNullException(nameof(tcpConnector));
     this._udpClientFactory = udpClientFactory ?? throw new ArgumentNullException(nameof(udpClientFactory));
     this._loggerFactory    = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this._timerFactory     = ThreadingTimerFactory.Instance;
 }
예제 #3
0
		internal static TcpClientChannel OpenConnection(ref NetworkPath actualPath, int timeoutInMsec, bool ignoreNodeDown)
		{
			NetworkPath networkPath = actualPath;
			NetworkTransportException ex = null;
			ITcpConnector tcpConnector = Dependencies.TcpConnector;
			TcpClientChannel tcpClientChannel = tcpConnector.TryConnect(networkPath, timeoutInMsec, out ex);
			if (tcpClientChannel != null)
			{
				return tcpClientChannel;
			}
			if (!networkPath.NetworkChoiceIsMandatory)
			{
				NetworkManager.TraceError("Attempting alternate routes", new object[0]);
				List<NetworkPath> list = null;
				ExchangeNetworkMap map = NetworkManager.GetMap();
				if (map != null)
				{
					list = map.EnumeratePaths(networkPath.TargetNodeName, ignoreNodeDown);
					if (list != null)
					{
						NetworkPath networkPath2 = null;
						foreach (NetworkPath networkPath3 in list)
						{
							if (string.Equals(networkPath3.NetworkName, networkPath.NetworkName, DatabaseAvailabilityGroupNetwork.NameComparison))
							{
								networkPath2 = networkPath3;
								break;
							}
						}
						if (networkPath2 != null)
						{
							list.Remove(networkPath2);
						}
						DagNetConfig dagConfig = DagNetEnvironment.FetchNetConfig();
						foreach (NetworkPath networkPath4 in list)
						{
							networkPath4.Purpose = networkPath.Purpose;
							networkPath4.ApplyNetworkPolicy(dagConfig);
							tcpClientChannel = tcpConnector.TryConnect(networkPath, timeoutInMsec, out ex);
							if (tcpClientChannel != null)
							{
								actualPath = networkPath4;
								return tcpClientChannel;
							}
						}
					}
				}
			}
			throw ex;
		}
예제 #4
0
        public TcpConnectionManager(string connectionName,
                                    Guid connectionId,
                                    IPEndPoint remoteEndPoint,
                                    ITcpConnector connector,
                                    bool useSsl,
                                    string sslTargetHost,
                                    bool sslValidateServer,
                                    IMessageFramer framer,
                                    Action <TcpConnectionManager, byte[]> messageReceived,
                                    Action <TcpConnectionManager> onConnectionEstablished,
                                    Action <TcpConnectionManager, SocketError> onConnectionClosed)
        {
            Ensure.NotEmptyGuid(connectionId, "connectionId");
            Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
            Ensure.NotNull(connector, "connector");
            Ensure.NotNull(framer, nameof(framer));
            if (useSsl)
            {
                Ensure.NotNull(sslTargetHost, "sslTargetHost");
            }

            ConnectionName = connectionName;
            ConnectionId   = connectionId;

            _framer = framer;
            _framer.RegisterMessageArrivedCallback(OnMessageArrived);

            _messageReceived       = messageReceived;
            _connectionEstablished = onConnectionEstablished;
            _connectionClosed      = onConnectionClosed;

            RemoteEndPoint = remoteEndPoint;

            _tcpConnection = useSsl
                ? connector.ConnectSslTo(ConnectionId, remoteEndPoint, ConnectionTimeout, sslTargetHost, sslValidateServer, OnConnectionEstablished, OnConnectionFailed, true)
                : connector.ConnectTo(ConnectionId, remoteEndPoint, ConnectionTimeout, OnConnectionEstablished, OnConnectionFailed, true);

            _tcpConnection.ConnectionClosed += OnConnectionClosed;
            if (_tcpConnection.IsClosed)
            {
                OnConnectionClosed(_tcpConnection, SocketError.Success);
                return;
            }
        }
예제 #5
0
        public TcpProxy(
            ITcpStream clientStream,
            EndPoint destinationEndPoint,
            ITcpConnector tcpConnector,
            ArrayPool <byte> bufferPool)
        {
            this._clientStream        = clientStream ?? throw new ArgumentNullException(nameof(clientStream));
            this._destinationEndPoint = destinationEndPoint
                                        ?? throw new ArgumentNullException(nameof(destinationEndPoint));
            this._tcpConnector = tcpConnector ?? throw new ArgumentNullException(nameof(tcpConnector));
            this._bufferPool   = bufferPool ?? throw new ArgumentNullException(nameof(bufferPool));

            if (!(destinationEndPoint is IPEndPoint) && !(destinationEndPoint is DnsEndPoint))
            {
                throw new ArgumentException(
                          "EndPoint must be either IPEndPoint or DnsEndPoint",
                          nameof(destinationEndPoint));
            }
        }
 public ConverseFlatBuffersClient(ITcpConnector connector, IResponseParser responseParser) : base(connector)
 {
     m_responseParser = responseParser;
 }
        // TODO(HonzaS): This was not thread safe, but now we're allocating a lot - optimize later.
        //private readonly MemoryStream m_sendingMemStream = new MemoryStream(InitialBufferSize);  // Resizable memory stream.
        //private readonly MemoryStream m_replyMemStream = new MemoryStream(InitialBufferSize);    // Resizable memory stream.

        public ConverseProtoBufClient(ITcpConnector connector) : base(connector)
        {
        }
예제 #8
0
		public static NetworkPath ChooseNetworkPath(string targetName, string networkName, NetworkPath.ConnectionPurpose purpose)
		{
			ITcpConnector tcpConnector = Dependencies.TcpConnector;
			return tcpConnector.ChooseDagNetworkPath(targetName, networkName, purpose);
		}
예제 #9
0
 internal static void OverrideTcpConnector(ITcpConnector conn)
 {
     Dependencies.tcpConnector = conn;
 }
예제 #10
0
        internal static bool TestHealth(string targetServer, int targetPort, int timeOutInMs, out string errMsg)
        {
            errMsg = null;
            NetworkChannel networkChannel = null;
            Exception      ex             = null;

            ExTraceGlobals.TcpChannelTracer.TraceFunction <string>(0L, "TcpHealthCheck: testing {0}", targetServer);
            try
            {
                ushort num = (ushort)targetPort;
                if (num == 0)
                {
                    num = 64327;
                }
                ITcpConnector tcpConnector = Dependencies.TcpConnector;
                NetworkPath   netPath      = tcpConnector.BuildDnsNetworkPath(targetServer, (int)num);
                networkChannel = NetworkChannel.Connect(netPath, TcpChannel.GetDefaultTimeoutInMs(), false);
                TestHealthRequest testHealthRequest = new TestHealthRequest(networkChannel);
                testHealthRequest.Send();
                NetworkChannelMessage message = networkChannel.GetMessage();
                if (!(message is TestHealthReply))
                {
                    networkChannel.ThrowUnexpectedMessage(message);
                }
                ExTraceGlobals.TcpChannelTracer.TraceFunction <string>(0L, "TcpHealthCheck: {0} is healthy", targetServer);
                return(true);
            }
            catch (NetworkRemoteException ex2)
            {
                ex = ex2.InnerException;
            }
            catch (NetworkTransportException ex3)
            {
                ex = ex3;
            }
            catch (Win32Exception ex4)
            {
                ex = ex4;
            }
            catch (COMException ex5)
            {
                ex = ex5;
            }
            catch (ClusCommonFailException ex6)
            {
                ex = ex6;
            }
            catch (ClusCommonTransientException ex7)
            {
                ex = ex7;
            }
            finally
            {
                if (networkChannel != null)
                {
                    networkChannel.Close();
                }
            }
            if (ex != null)
            {
                ExTraceGlobals.TcpChannelTracer.TraceError <Exception>(0L, "TcpHealthCheck: failed: {0}", ex);
                errMsg = ex.Message;
            }
            return(false);
        }
예제 #11
0
 public ConverseClient(ITcpConnector connector)
 {
     m_connector = connector;
 }