// methods public ICluster BuildCluster() { IStreamFactory streamFactory = new TcpStreamFactory(_tcpStreamSettings); if (_sslStreamSettings != null) { streamFactory = new SslStreamFactory(_sslStreamSettings, streamFactory); } streamFactory = _streamFactoryWrapper(streamFactory); var connectionFactory = new BinaryConnectionFactory( _connectionSettings, streamFactory, _connectionListener); var connectionPoolFactory = new ExclusiveConnectionPoolFactory( _connectionPoolSettings, connectionFactory, _connectionPoolListener); var serverFactory = new ServerFactory( _serverSettings, connectionPoolFactory, connectionFactory, _serverListener); var clusterFactory = new ClusterFactory( _clusterSettings, serverFactory, _clusterListener); return(clusterFactory.CreateCluster()); }
private IStreamFactory CreateTcpStreamFactory(TcpStreamSettings tcpStreamSettings) { var streamFactory = (IStreamFactory) new TcpStreamFactory(tcpStreamSettings); if (_sslStreamSettings != null) { streamFactory = new SslStreamFactory(_sslStreamSettings, streamFactory); } return(_streamFactoryWrapper(streamFactory)); }
// methods /// <summary> /// Builds the cluster. /// </summary> /// <returns>A cluster.</returns> public ICluster BuildCluster() { IStreamFactory streamFactory = new TcpStreamFactory(_tcpStreamSettings); if (_sslStreamSettings != null) { streamFactory = new SslStreamFactory(_sslStreamSettings, streamFactory); } streamFactory = _streamFactoryWrapper(streamFactory); var connectionFactory = new BinaryConnectionFactory( _connectionSettings, streamFactory, _eventAggregator); var connectionPoolFactory = new ExclusiveConnectionPoolFactory( _connectionPoolSettings, connectionFactory, _eventAggregator); var serverMonitorConnectionSettings = _connectionSettings.With(authenticators: new IAuthenticator[] { }); var serverMonitorConnectionFactory = new BinaryConnectionFactory( serverMonitorConnectionSettings, streamFactory, new EventAggregator()); var serverMonitorFactory = new ServerMonitorFactory( _serverSettings, serverMonitorConnectionFactory, _eventAggregator); var serverFactory = new ServerFactory( _clusterSettings.ConnectionMode, _serverSettings, connectionPoolFactory, serverMonitorFactory, _eventAggregator); var clusterFactory = new ClusterFactory( _clusterSettings, serverFactory, _eventAggregator); return(clusterFactory.CreateCluster()); }
private IStreamFactory CreateStreamFactory(ClusterKey clusterKey) { var tcpStreamSettings = CreateTcpStreamSettings(clusterKey); IStreamFactory streamFactory = new TcpStreamFactory(tcpStreamSettings); if (clusterKey.SslSettings != null) { var sslStreamSettings = new SslStreamSettings( clientCertificates: Optional.Create(clusterKey.SslSettings.ClientCertificates ?? Enumerable.Empty <X509Certificate>()), checkCertificateRevocation: clusterKey.SslSettings.CheckCertificateRevocation, clientCertificateSelectionCallback: clusterKey.SslSettings.ClientCertificateSelectionCallback, enabledProtocols: clusterKey.SslSettings.EnabledSslProtocols, serverCertificateValidationCallback: clusterKey.SslSettings.ServerCertificateValidationCallback); streamFactory = new SslStreamFactory(sslStreamSettings, streamFactory); } return(streamFactory); }
private IStreamFactory CreateStreamFactory(ClusterKey clusterKey) { var tcpStreamSettings = CreateTcpStreamSettings(clusterKey); IStreamFactory streamFactory = new TcpStreamFactory(tcpStreamSettings); if (clusterKey.SslSettings != null) { var sslStreamSettings = new SslStreamSettings( new Optional <IEnumerable <X509Certificate> >(clusterKey.SslSettings.ClientCertificates), clusterKey.SslSettings.CheckCertificateRevocation, clusterKey.SslSettings.ClientCertificateSelectionCallback, clusterKey.SslSettings.EnabledSslProtocols, clusterKey.SslSettings.ServerCertificateValidationCallback); streamFactory = new SslStreamFactory(sslStreamSettings, streamFactory); } return(streamFactory); }
private void SendKmsRequest(KmsRequest request, CancellationToken cancellation) { var endpoint = CreateKmsEndPoint(request.Endpoint); var tlsStreamSettings = GetTlsStreamSettings(request.KmsProvider); var sslStreamFactory = new SslStreamFactory(tlsStreamSettings, _networkStreamFactory); using (var sslStream = sslStreamFactory.CreateStream(endpoint, cancellation)) { var requestBytes = request.Message.ToArray(); sslStream.Write(requestBytes, 0, requestBytes.Length); while (request.BytesNeeded > 0) { var buffer = new byte[request.BytesNeeded]; // BytesNeeded is the maximum number of bytes that libmongocrypt wants to receive. var count = sslStream.Read(buffer, 0, buffer.Length); var responseBytes = new byte[count]; Buffer.BlockCopy(buffer, 0, responseBytes, 0, count); request.Feed(responseBytes); } } }