public EpoxyListener( EpoxyTransport parentTransport, IPEndPoint listenEndpoint, Logger logger, Metrics metrics) : base(logger, metrics) { this.parentTransport = parentTransport; listener = new System.Net.Sockets.TcpListener(listenEndpoint); serviceHost = new ServiceHost(parentTransport, logger, metrics); connections = new HashSet <EpoxyConnection>(); shutdownTokenSource = new CancellationTokenSource(); }
internal static EpoxyConnection MakeServerConnection( EpoxyTransport parentTransport, EpoxyListener parentListener, ServiceHost serviceHost, Socket socket) { return(new EpoxyConnection( ConnectionType.Server, parentTransport, parentListener, serviceHost, socket)); }
internal static EpoxyConnection MakeClientConnection( EpoxyTransport parentTransport, Socket clientSocket) { const EpoxyListener parentListener = null; return(new EpoxyConnection( ConnectionType.Client, parentTransport, parentListener, new ServiceHost(parentTransport), clientSocket)); }
internal static EpoxyConnection MakeServerConnection( EpoxyTransport parentTransport, EpoxyListener parentListener, ServiceHost serviceHost, EpoxyNetworkStream networkStream, Logger logger, Metrics metrics) { return(new EpoxyConnection( ConnectionType.Server, parentTransport, parentListener, serviceHost, networkStream, logger, metrics)); }
internal static EpoxyConnection MakeClientConnection( EpoxyTransport parentTransport, EpoxyNetworkStream networkStream, Logger logger, Metrics metrics) { const EpoxyListener parentListener = null; return(new EpoxyConnection( ConnectionType.Client, parentTransport, parentListener, new ServiceHost(logger), networkStream, logger, metrics)); }
private EpoxyConnection( ConnectionType connectionType, EpoxyTransport parentTransport, EpoxyListener parentListener, ServiceHost serviceHost, Socket socket, Logger logger, Metrics metrics) { Debug.Assert(parentTransport != null); Debug.Assert(connectionType != ConnectionType.Server || parentListener != null, "Server connections must have a listener"); Debug.Assert(serviceHost != null); Debug.Assert(socket != null); this.connectionType = connectionType; this.parentTransport = parentTransport; this.parentListener = parentListener; this.serviceHost = serviceHost; netSocket = new EpoxySocket(socket, logger); // cache these so we can use them after the socket has been shutdown LocalEndPoint = (IPEndPoint)socket.LocalEndPoint; RemoteEndPoint = (IPEndPoint)socket.RemoteEndPoint; responseMap = new ResponseMap(); state = State.Created; startTask = new TaskCompletionSource <bool>(); stopTask = new TaskCompletionSource <bool>(); shutdownTokenSource = new CancellationTokenSource(); // start at -1 or 0 so the first conversation ID is 1 or 2. prevConversationId = (connectionType == ConnectionType.Client) ? -1 : 0; connectionMetrics.connection_id = Guid.NewGuid().ToString(); connectionMetrics.local_endpoint = LocalEndPoint.ToString(); connectionMetrics.remote_endpoint = RemoteEndPoint.ToString(); this.logger = logger; this.metrics = metrics; }
public EpoxyListener( EpoxyTransport parentTransport, IPEndPoint listenEndpoint, EpoxyServerTlsConfig tlsConfig, Logger logger, Metrics metrics) : base(logger, metrics) { Debug.Assert(parentTransport != null); Debug.Assert(listenEndpoint != null); this.parentTransport = parentTransport; // will be null if not using TLS this.tlsConfig = tlsConfig; listener = new TcpListener(listenEndpoint); serviceHost = new ServiceHost(logger); connections = new HashSet <EpoxyConnection>(); shutdownTokenSource = new CancellationTokenSource(); ListenEndpoint = listenEndpoint; }
private EpoxyConnection( ConnectionType connectionType, EpoxyTransport parentTransport, EpoxyListener parentListener, ServiceHost serviceHost, EpoxyNetworkStream networkStream, Logger logger, Metrics metrics) { Debug.Assert(parentTransport != null); Debug.Assert(connectionType != ConnectionType.Server || parentListener != null, "Server connections must have a listener"); Debug.Assert(serviceHost != null); Debug.Assert(networkStream != null); this.connectionType = connectionType; this.parentTransport = parentTransport; this.parentListener = parentListener; this.serviceHost = serviceHost; this.networkStream = networkStream; responseMap = new ResponseMap(); state = State.Created; startTask = new TaskCompletionSource <bool>(); stopTask = new TaskCompletionSource <bool>(); shutdownTokenSource = new CancellationTokenSource(); // start at -1 or 0 so the first conversation ID is 1 or 2. prevConversationId = (connectionType == ConnectionType.Client) ? -1 : 0; ConnectionMetrics.local_endpoint = LocalEndPoint.ToString(); ConnectionMetrics.remote_endpoint = RemoteEndPoint.ToString(); this.logger = logger; this.metrics = metrics; }
async Task StartClientConnectionAsync(Socket socket) { EpoxyNetworkStream epoxyStream = null; try { EpoxyTransport.ConfigureSocketKeepAlive(socket, timeoutConfig, logger); epoxyStream = await EpoxyNetworkStream.MakeServerStreamAsync(socket, tlsConfig, logger); socket = null; // epoxyStream now owns the socket var connection = EpoxyConnection.MakeServerConnection( parentTransport, this, serviceHost, epoxyStream, logger, metrics); // connection now owns the EpoxyNetworkStream epoxyStream = null; lock (connectionsLock) { connections.Add(connection); } logger.Site().Debug("Setup server-side connection for {0}. Starting Epoxy handshake.", connection.RemoteEndPoint); await connection.StartAsync(); } catch (Exception) { ShutdownSocketSafe(socket, epoxyStream); throw; } }