Esempio n. 1
0
        public ServerConnection(Socket socket, ServiceDispatcher dispatcher, ServiceHostConfig config, ServiceHostCounters counters, ISerializer serializer, X509Certificate?certificate)
        {
            _dispatcher    = dispatcher;
            _socket        = socket;
            _config        = config;
            _requestLogger = new RequestLogger(socket.GetRemoteAddressName(), dispatcher.MessageMap);

            Stream readerStream, writerStream;

            if (config.TlsSettings == null || certificate == null)
            {
                readerStream = new NetworkStream(socket, FileAccess.Read, false);
                writerStream = new NetworkStream(socket, FileAccess.Write, false);
            }
            else
            {
                var networkStream = new NetworkStream(socket, FileAccess.ReadWrite, false);
                var tlsStream     = new SslStream(networkStream, true);

                readerStream = writerStream = tlsStream;

                _tls = new TlsData(certificate, tlsStream);
            }

            _messageReader = new DelimitedMessageReader(socket.GetRemoteAddressName(), readerStream, serializer);
            _messageWriter = new DelimitedMessageWriter(socket.GetRemoteAddressName(), writerStream, serializer);

            _responsePropagatorTask = PropagateResponses();
            _counters = counters;
        }
Esempio n. 2
0
 public Network(SslStream?tlsStream, DelimitedMessageReader messageReader, DelimitedMessageWriter messageWriter)
 {
     TlsStream     = tlsStream;
     MessageReader = messageReader;
     MessageWriter = messageWriter;
 }