Пример #1
0
        public TcpConnectionManager(string connectionName,
                                    Guid connectionId,
                                    ITcpDispatcher dispatcher,
                                    IPublisher publisher,
                                    TcpConnection openedConnection)
        {
            Ensure.NotEmptyGuid(connectionId, "connectionId");
            Ensure.NotNull(dispatcher, "dispatcher");
            Ensure.NotNull(publisher, "publisher");
            Ensure.NotNull(openedConnection, "openedConnnection");

            _connectionName = connectionName;
            _connectionId   = connectionId;

            _tcpEnvelope = new SendOverTcpEnvelope(this);
            _publisher   = publisher;
            _dispatcher  = dispatcher;

            EndPoint = openedConnection.EffectiveEndPoint;

            _framer = new LengthPrefixMessageFramer();
            _framer.RegisterMessageArrivedCallback(OnMessageArrived);

            _connection = openedConnection;
            _connection.ConnectionClosed += OnConnectionClosed;
            ScheduleHeartbeat(0);
        }
Пример #2
0
        public TcpConnectionManager(string connectionName,
                                    ITcpDispatcher dispatcher,
                                    IPublisher publisher,
                                    IPEndPoint remoteEndPoint,
                                    TcpClientConnector connector)
        {
            Ensure.NotNull(dispatcher, "dispatcher");
            Ensure.NotNull(publisher, "publisher");
            Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
            Ensure.NotNull(connector, "connector");

            _connectionName = connectionName;

            _tcpEnvelope = new SendOverTcpEnvelope(this);
            _publisher   = publisher;
            _dispatcher  = dispatcher;

            EndPoint = remoteEndPoint;

            _framer = new LengthPrefixMessageFramer();
            _framer.RegisterMessageArrivedCallback(OnMessageArrived);

            _connection = connector.ConnectTo(remoteEndPoint, OnConnectionEstablished, OnConnectionFailed);
            _connection.ConnectionClosed += OnConnectionClosed;
        }
        public TcpConnectionManager(string connectionName,
                                    Guid connectionId,
                                    ITcpDispatcher dispatcher,
                                    IPublisher publisher,
                                    string targetHost,
                                    EndPoint remoteEndPoint,
                                    TcpClientConnector connector,
                                    bool useSsl,
                                    Func <X509Certificate, X509Chain, SslPolicyErrors, ValueTuple <bool, string> > sslServerCertValidator,
                                    Func <X509CertificateCollection> sslClientCertificatesSelector,
                                    IPublisher networkSendQueue,
                                    IAuthenticationProvider authProvider,
                                    AuthorizationGateway authorization,
                                    TimeSpan heartbeatInterval,
                                    TimeSpan heartbeatTimeout,
                                    Action <TcpConnectionManager> onConnectionEstablished,
                                    Action <TcpConnectionManager, SocketError> onConnectionClosed)
        {
            Ensure.NotEmptyGuid(connectionId, "connectionId");
            Ensure.NotNull(dispatcher, "dispatcher");
            Ensure.NotNull(publisher, "publisher");
            Ensure.NotNull(authProvider, "authProvider");
            Ensure.NotNull(authorization, "authorization");
            Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
            Ensure.NotNull(connector, "connector");

            ConnectionId   = connectionId;
            ConnectionName = connectionName;

            _tcpEnvelope   = new SendOverTcpEnvelope(this, networkSendQueue);
            _publisher     = publisher;
            _dispatcher    = dispatcher;
            _authProvider  = authProvider;
            _authorization = authorization;

            _framer = new LengthPrefixMessageFramer();
            _framer.RegisterMessageArrivedCallback(OnMessageArrived);

            _weakThisEnvelope  = new SendToWeakThisEnvelope(this);
            _heartbeatInterval = heartbeatInterval;
            _heartbeatTimeout  = heartbeatTimeout;
            _connectionPendingSendBytesThreshold = ESConsts.UnrestrictedPendingSendBytes;
            _connectionQueueSizeThreshold        = ESConsts.MaxConnectionQueueSize;

            _connectionEstablished = onConnectionEstablished;
            _connectionClosed      = onConnectionClosed;

            RemoteEndPoint = remoteEndPoint;
            _connection    = useSsl
                                ? connector.ConnectSslTo(ConnectionId, targetHost, remoteEndPoint.ResolveDnsToIPAddress(), ConnectionTimeout,
                                                         sslServerCertValidator, sslClientCertificatesSelector, OnConnectionEstablished, OnConnectionFailed)
                                : connector.ConnectTo(ConnectionId, remoteEndPoint.ResolveDnsToIPAddress(), ConnectionTimeout, OnConnectionEstablished,
                                                      OnConnectionFailed);
            _connection.ConnectionClosed += OnConnectionClosed;
            if (_connection.IsClosed)
            {
                OnConnectionClosed(_connection, SocketError.Success);
            }
        }
Пример #4
0
        public TcpConnectionManager(string connectionName,
                                    Guid connectionId,
                                    ITcpDispatcher dispatcher,
                                    IPublisher publisher,
                                    IPEndPoint remoteEndPoint,
                                    TcpClientConnector connector,
                                    bool useSsl,
                                    string sslTargetHost,
                                    bool sslValidateServer,
                                    IPublisher networkSendQueue,
                                    IAuthenticationProvider authProvider,
                                    TimeSpan heartbeatInterval,
                                    TimeSpan heartbeatTimeout,
                                    Action <TcpConnectionManager> onConnectionEstablished,
                                    Action <TcpConnectionManager, SocketError> onConnectionClosed)
        {
            Ensure.NotEmptyGuid(connectionId, "connectionId");
            Ensure.NotNull(dispatcher, "dispatcher");
            Ensure.NotNull(publisher, "publisher");
            Ensure.NotNull(authProvider, "authProvider");
            Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
            Ensure.NotNull(connector, "connector");
            if (useSsl)
            {
                Ensure.NotNull(sslTargetHost, "sslTargetHost");
            }

            ConnectionId   = connectionId;
            ConnectionName = connectionName;

            _tcpEnvelope  = new SendOverTcpEnvelope(this, networkSendQueue);
            _publisher    = publisher;
            _dispatcher   = dispatcher;
            _authProvider = authProvider;

            _framer = new LengthPrefixMessageFramer();
            _framer.RegisterMessageArrivedCallback(OnMessageArrived);

            _weakThisEnvelope  = new SendToWeakThisEnvelope(this);
            _heartbeatInterval = heartbeatInterval;
            _heartbeatTimeout  = heartbeatTimeout;
            _connectionPendingSendBytesThreshold = ESConsts.UnrestrictedPendingSendBytes;
            _connectionQueueSizeThreshold        = ESConsts.MaxConnectionQueueSize;

            _connectionEstablished = onConnectionEstablished;
            _connectionClosed      = onConnectionClosed;

            RemoteEndPoint = remoteEndPoint;
            _connection    = useSsl
                                ? connector.ConnectSslTo(ConnectionId, remoteEndPoint, ConnectionTimeout,
                                                         sslTargetHost, sslValidateServer, OnConnectionEstablished, OnConnectionFailed)
                                : connector.ConnectTo(ConnectionId, remoteEndPoint, ConnectionTimeout, OnConnectionEstablished,
                                                      OnConnectionFailed);
            _connection.ConnectionClosed += OnConnectionClosed;
            if (_connection.IsClosed)
            {
                OnConnectionClosed(_connection, SocketError.Success);
            }
        }
Пример #5
0
        public TcpService(IPublisher publisher, IPEndPoint serverEndPoint)
        {
            Ensure.NotNull(publisher, "publisher");
            Ensure.NotNull(serverEndPoint, "serverEndPoint");

            _publisher      = publisher;
            _serverEndPoint = serverEndPoint;
            _tcpDispatcher  = new ClientTcpDispatcher();
            _serverListener = new TcpServerListener(_serverEndPoint);
        }
        public TcpConnectionManager(string connectionName,
                                    TcpServiceType serviceType,
                                    ITcpDispatcher dispatcher,
                                    IPublisher publisher,
                                    ITcpConnection openedConnection,
                                    IPublisher networkSendQueue,
                                    IAuthenticationProvider authProvider,
                                    AuthorizationGateway authorization,
                                    TimeSpan heartbeatInterval,
                                    TimeSpan heartbeatTimeout,
                                    Action <TcpConnectionManager, SocketError> onConnectionClosed,
                                    int connectionPendingSendBytesThreshold,
                                    int connectionQueueSizeThreshold)
        {
            Ensure.NotNull(dispatcher, "dispatcher");
            Ensure.NotNull(publisher, "publisher");
            Ensure.NotNull(openedConnection, "openedConnnection");
            Ensure.NotNull(networkSendQueue, "networkSendQueue");
            Ensure.NotNull(authProvider, "authProvider");
            Ensure.NotNull(authorization, "authorization");
            ConnectionId   = openedConnection.ConnectionId;
            ConnectionName = connectionName;

            _serviceType   = serviceType;
            _tcpEnvelope   = new SendOverTcpEnvelope(this, networkSendQueue);
            _publisher     = publisher;
            _dispatcher    = dispatcher;
            _authProvider  = authProvider;
            _authorization = authorization;

            _framer = new LengthPrefixMessageFramer();
            _framer.RegisterMessageArrivedCallback(OnMessageArrived);

            _weakThisEnvelope  = new SendToWeakThisEnvelope(this);
            _heartbeatInterval = heartbeatInterval;
            _heartbeatTimeout  = heartbeatTimeout;
            _connectionPendingSendBytesThreshold = connectionPendingSendBytesThreshold;
            _connectionQueueSizeThreshold        = connectionQueueSizeThreshold;

            _connectionClosed = onConnectionClosed;

            RemoteEndPoint = openedConnection.RemoteEndPoint;
            _connection    = openedConnection;
            _connection.ConnectionClosed += OnConnectionClosed;
            if (_connection.IsClosed)
            {
                OnConnectionClosed(_connection, SocketError.Success);
                return;
            }

            ScheduleHeartbeat(0);
        }
Пример #7
0
 public TcpService(IPublisher publisher,
                   IPEndPoint serverEndPoint,
                   IPublisher networkSendQueue,
                   TcpServiceType serviceType,
                   TcpSecurityType securityType,
                   ITcpDispatcher dispatcher,
                   TimeSpan heartbeatInterval,
                   TimeSpan heartbeatTimeout,
                   IAuthenticationProvider authProvider,
                   X509Certificate certificate)
     : this(publisher, serverEndPoint, networkSendQueue, serviceType, securityType, (_, __) => dispatcher,
            heartbeatInterval, heartbeatTimeout, authProvider, certificate)
 {
 }
Пример #8
0
 public TcpService(IPublisher publisher,
                   IPEndPoint serverEndPoint,
                   IPublisher networkSendQueue,
                   TcpServiceType serviceType,
                   TcpSecurityType securityType,
                   ITcpDispatcher dispatcher,
                   TimeSpan heartbeatInterval,
                   TimeSpan heartbeatTimeout,
                   IAuthenticationProvider authProvider,
                   X509Certificate certificate,
                   int connectionPendingSendBytesThreshold,
                   int connectionQueueSizeThreshold)
     : this(publisher, serverEndPoint, networkSendQueue, serviceType, securityType, (_, __) => dispatcher,
            heartbeatInterval, heartbeatTimeout, authProvider, certificate, connectionPendingSendBytesThreshold, connectionQueueSizeThreshold)
 {
 }
Пример #9
0
 public TcpService(IPublisher publisher,
                   IPEndPoint serverEndPoint,
                   IPublisher networkSendQueue,
                   TcpServiceType serviceType,
                   TcpSecurityType securityType,
                   ITcpDispatcher dispatcher,
                   TimeSpan heartbeatInterval,
                   TimeSpan heartbeatTimeout,
                   IAuthenticationProvider authProvider,
                   AuthorizationGateway authorizationGateway,
                   X509Certificate certificate,
                   Func <X509Certificate, X509Chain, SslPolicyErrors, ValueTuple <bool, string> > sslClientCertValidator,
                   int connectionPendingSendBytesThreshold,
                   int connectionQueueSizeThreshold)
     : this(publisher, serverEndPoint, networkSendQueue, serviceType, securityType, (_, __) => dispatcher,
            heartbeatInterval, heartbeatTimeout, authProvider, authorizationGateway, certificate, sslClientCertValidator, connectionPendingSendBytesThreshold, connectionQueueSizeThreshold)
 {
 }