Exemplo n.º 1
0
            public TClientTransport CreateTransport()
            {
                if (url == null)
                {
                    // endpoint transport
                    TClientTransport trans = null;

                    if (pipe != null)
                    {
                        trans = new TNamedPipeClientTransport(pipe);
                    }
                    else
                    {
                        if (encrypted)
                        {
                            var certPath = "../../keys/client.p12";
                            var cert = new X509Certificate2(certPath, "thrift");
                            trans = new TTlsSocketClientTransport(host, port, 0, cert, (o, c, chain, errors) => true, null, SslProtocols.Tls);
                        }
                        else
                        {
                            trans = new TSocketClientTransport(host, port);
                        }
                    }

                    // layered transport
                    if (buffered)
                    {
                        trans = new TBufferedClientTransport(trans);
                    }

                    if (framed)
                    {
                        trans = new TFramedClientTransport(trans);
                    }

                    return trans;
                }

                return new THttpClientTransport(new Uri(url), null);
            }
Exemplo n.º 2
0
        protected override async Task<TClientTransport> AcceptImplementationAsync(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return await Task.FromCanceled<TClientTransport>(cancellationToken);
            }

            if (_server == null)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
            }

            try
            {
                var client = await _server.AcceptTcpClientAsync();
                client.SendTimeout = client.ReceiveTimeout = _clientTimeout;

                //wrap the client in an SSL Socket passing in the SSL cert
                var tTlsSocket = new TTlsSocketClientTransport(client, _serverCertificate, true, _clientCertValidator,
                    _localCertificateSelectionCallback, _sslProtocols);

                await tTlsSocket.SetupTlsAsync();

                if (_useBufferedSockets)
                {
                    var trans = new TBufferedClientTransport(tTlsSocket);
                    return trans;
                }

                return tTlsSocket;
            }
            catch (Exception ex)
            {
                throw new TTransportException(ex.ToString());
            }
        }