Пример #1
0
        public static ITcpConnection CreateConnectingConnection(Guid connectionId,
                                                                IPEndPoint remoteEndPoint,
                                                                string targetHost,
                                                                bool validateServer,
                                                                TcpClientConnector connector,
                                                                TimeSpan connectionTimeout,
                                                                Action <ITcpConnection> onConnectionEstablished,
                                                                Action <ITcpConnection, SocketError> onConnectionFailed,
                                                                bool verbose)
        {
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            // ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (_, socket) => {
                connection.InitClientSocket(socket, targetHost, validateServer, verbose);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
            },
                                  (_, socketError) => {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection, connectionTimeout);
            // ReSharper restore ImplicitlyCapturedClosure
            return(connection);
        }
Пример #2
0
        public static ITcpConnection CreateConnectingConnection(Guid connectionId,
                                                                string targetHost,
                                                                IPEndPoint remoteEndPoint,
                                                                Func <X509Certificate, X509Chain, SslPolicyErrors, ValueTuple <bool, string> > serverCertValidator,
                                                                Func <X509CertificateCollection> clientCertificatesSelector,
                                                                TcpClientConnector connector,
                                                                TimeSpan connectionTimeout,
                                                                Action <ITcpConnection> onConnectionEstablished,
                                                                Action <ITcpConnection, SocketError> onConnectionFailed,
                                                                bool verbose)
        {
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            // ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (socket) => {
                connection.InitClientSocket(socket);
            },
                                  (_, socket) => {
                connection.InitSslStream(targetHost, serverCertValidator, clientCertificatesSelector, verbose);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
            },
                                  (_, socketError) => {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection, connectionTimeout);
            // ReSharper restore ImplicitlyCapturedClosure
            return(connection);
        }
Пример #3
0
 public static ITcpConnection CreateConnectingConnection(Guid connectionId, 
                                                         IPEndPoint remoteEndPoint, 
                                                         string targetHost,
                                                         bool validateServer,
                                                         TcpClientConnector connector, 
                                                         TimeSpan connectionTimeout,
                                                         Action<ITcpConnection> onConnectionEstablished, 
                                                         Action<ITcpConnection, SocketError> onConnectionFailed,
                                                         bool verbose)
 {
     var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);
     // ReSharper disable ImplicitlyCapturedClosure
     connector.InitConnect(remoteEndPoint,
                           (_, socket) =>
                           {
                               connection.InitClientSocket(socket, targetHost, validateServer, verbose);
                               if (onConnectionEstablished != null)
                                   onConnectionEstablished(connection);
                           },
                           (_, socketError) =>
                           {
                               if (onConnectionFailed != null)
                                   onConnectionFailed(connection, socketError);
                           }, connection, connectionTimeout);
     // ReSharper restore ImplicitlyCapturedClosure
     return connection;
 }
Пример #4
0
 public static ITcpConnection CreateClientFromSocket(Guid connectionId, 
                                                     IPEndPoint remoteEndPoint, 
                                                     Socket socket, 
                                                     string targetHost,
                                                     bool validateServer,
                                                     bool verbose)
 {
     var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);
     connection.InitClientSocket(socket, targetHost, validateServer, verbose);
     return connection;
 }
Пример #5
0
 public static ITcpConnection CreateServerFromSocket(Guid connectionId,
                                                     IPEndPoint remoteEndPoint,
                                                     Socket socket,
                                                     X509Certificate certificate,
                                                     bool verbose)
 {
     Ensure.NotNull(certificate, "certificate");
     var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);
     connection.InitServerSocket(socket, certificate, verbose);
     return connection;
 }
Пример #6
0
        public static ITcpConnection CreateServerFromSocket(Guid connectionId,
                                                            IPEndPoint remoteEndPoint,
                                                            Socket socket,
                                                            X509Certificate certificate,
                                                            bool verbose)
        {
            Ensure.NotNull(certificate, "certificate");
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            connection.InitServerSocket(socket, certificate, verbose);
            return(connection);
        }
Пример #7
0
        public static ITcpConnection CreateClientFromSocket(Guid connectionId,
                                                            IPEndPoint remoteEndPoint,
                                                            Socket socket,
                                                            string targetHost,
                                                            bool validateServer,
                                                            bool verbose)
        {
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            connection.InitClientSocket(socket, targetHost, validateServer, verbose);
            return(connection);
        }
Пример #8
0
        public static ITcpConnection CreateServerFromSocket(Guid connectionId,
                                                            IPEndPoint remoteEndPoint,
                                                            Socket socket,
                                                            Func <X509Certificate> serverCertificateSelector,
                                                            Func <X509Certificate, X509Chain, SslPolicyErrors, ValueTuple <bool, string> > clientCertValidator,
                                                            bool verbose)
        {
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            connection.InitServerSocket(socket, serverCertificateSelector, clientCertValidator, verbose);
            return(connection);
        }
Пример #9
0
 public ITcpConnection ConnectSslTo(Guid connectionId,
                                    IPEndPoint remoteEndPoint,
                                    TimeSpan connectionTimeout,
                                    bool validateServer,
                                    X509CertificateCollection clientCertificates,
                                    Action <ITcpConnection> onConnectionEstablished         = null,
                                    Action <ITcpConnection, SocketError> onConnectionFailed = null,
                                    bool verbose = true)
 {
     Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
     return(TcpConnectionSsl.CreateConnectingConnection(connectionId, remoteEndPoint, validateServer, clientCertificates,
                                                        this, connectionTimeout, onConnectionEstablished, onConnectionFailed, verbose));
 }
Пример #10
0
 public ITcpConnection ConnectSslTo(Guid connectionId,
                                    IPEndPoint remoteEndPoint,
                                    TimeSpan connectionTimeout,
                                    Func <X509Certificate, X509Chain, SslPolicyErrors, ValueTuple <bool, string> > sslServerCertValidator,
                                    X509CertificateCollection clientCertificates,
                                    Action <ITcpConnection> onConnectionEstablished         = null,
                                    Action <ITcpConnection, SocketError> onConnectionFailed = null,
                                    bool verbose = true)
 {
     Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
     return(TcpConnectionSsl.CreateConnectingConnection(connectionId, remoteEndPoint, sslServerCertValidator, clientCertificates,
                                                        this, connectionTimeout, onConnectionEstablished, onConnectionFailed, verbose));
 }
Пример #11
0
        public static ITcpConnection CreateClientFromSocket(Guid connectionId,
                                                            IPEndPoint remoteEndPoint,
                                                            Socket socket,
                                                            string targetHost,
                                                            bool validateServer,
                                                            X509CertificateCollection clientCertificates,
                                                            bool verbose)
        {
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            connection.InitClientSocket(socket);
            connection.InitSslStream(targetHost, validateServer, clientCertificates, verbose);
            return(connection);
        }
Пример #12
0
 public ITcpConnection ConnectSslTo(Guid connectionId,
                                    IPEndPoint remoteEndPoint,
                                    TimeSpan connectionTimeout,
                                    string targetHost,
                                    bool validateServer,
                                    Action <ITcpConnection> onConnectionEstablished         = null,
                                    Action <ITcpConnection, SocketError> onConnectionFailed = null,
                                    bool verbose = true)
 {
     Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
     Ensure.NotNullOrEmpty(targetHost, "targetHost");
     return(TcpConnectionSsl.CreateConnectingConnection(connectionId, remoteEndPoint, targetHost, validateServer,
                                                        this, connectionTimeout, onConnectionEstablished, onConnectionFailed, verbose));
 }