Пример #1
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);
        }
Пример #2
0
        public static ITcpConnection CreateConnectingConnection(Guid connectionId,
                                                                IPEndPoint remoteEndPoint,
                                                                bool validateServer,
                                                                X509CertificateCollection clientCertificates,
                                                                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(remoteEndPoint.Address.ToString(), validateServer, clientCertificates, 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 CreateClientFromSocket(Guid connectionId,
                                                            IPEndPoint remoteEndPoint,
                                                            Socket socket,
                                                            string targetHost,
                                                            bool validateServer,
                                                            bool verbose)
        {
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            connection.InitClientSocket(socket);
            connection.InitSslStream(targetHost, validateServer, verbose);
            return(connection);
        }