Exemplo n.º 1
0
        public QuicStreamContext(QuicStream stream, QuicConnectionContext connection, QuicTransportContext context)
        {
            _stream     = stream;
            _connection = connection;
            _context    = context;
            _log        = context.Log;
            MemoryPool  = connection.MemoryPool;

            ConnectionClosed = _streamClosedTokenSource.Token;

            var maxReadBufferSize  = context.Options.MaxReadBufferSize ?? 0;
            var maxWriteBufferSize = context.Options.MaxWriteBufferSize ?? 0;

            // TODO should we allow these PipeScheduler to be configurable here?
            var inputOptions  = new PipeOptions(MemoryPool, PipeScheduler.ThreadPool, PipeScheduler.Inline, maxReadBufferSize, maxReadBufferSize / 2, useSynchronizationContext: false);
            var outputOptions = new PipeOptions(MemoryPool, PipeScheduler.Inline, PipeScheduler.ThreadPool, maxWriteBufferSize, maxWriteBufferSize / 2, useSynchronizationContext: false);

            var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions);

            Features.Set <IStreamDirectionFeature>(this);
            Features.Set <IProtocolErrorCodeFeature>(this);
            Features.Set <IStreamIdFeature>(this);

            // TODO populate the ITlsConnectionFeature (requires client certs).
            Features.Set <ITlsConnectionFeature>(new FakeTlsConnectionFeature());
            CanRead  = stream.CanRead;
            CanWrite = stream.CanWrite;

            Transport   = pair.Transport;
            Application = pair.Application;
        }
        public QuicConnectionListener(QuicTransportOptions options, IQuicTrace log, EndPoint endpoint)
        {
            if (options.Alpn == null)
            {
                throw new InvalidOperationException("QuicTransportOptions.Alpn must be configured with a value.");
            }

            _log     = log;
            _context = new QuicTransportContext(_log, options);
            EndPoint = endpoint;

            var quicListenerOptions = new QuicListenerOptions();
            var sslConfig           = new SslServerAuthenticationOptions();

            sslConfig.ServerCertificate    = options.Certificate;
            sslConfig.ApplicationProtocols = new List <SslApplicationProtocol>()
            {
                new SslApplicationProtocol(options.Alpn)
            };

            quicListenerOptions.ServerAuthenticationOptions = sslConfig;
            quicListenerOptions.CertificateFilePath         = options.CertificateFilePath;
            quicListenerOptions.PrivateKeyFilePath          = options.PrivateKeyFilePath;
            quicListenerOptions.ListenEndPoint = endpoint as IPEndPoint;
            quicListenerOptions.IdleTimeout    = TimeSpan.FromMinutes(2);

            _listener = new QuicListener(QuicImplementationProviders.MsQuic, quicListenerOptions);
            _listener.Start();
        }
Exemplo n.º 3
0
        public QuicConnectionListener(QuicTransportOptions options, IQuicTrace log, EndPoint endpoint, SslServerAuthenticationOptions sslServerAuthenticationOptions)
        {
            if (options.Alpn == null)
            {
                throw new InvalidOperationException("QuicTransportOptions.Alpn must be configured with a value.");
            }

            _log     = log;
            _context = new QuicTransportContext(_log, options);
            EndPoint = endpoint;
            var quicListenerOptions = new QuicListenerOptions();

            // TODO Should HTTP/3 specific ALPN still be global? Revisit whether it can be statically set once HTTP/3 is finalized.
            sslServerAuthenticationOptions.ApplicationProtocols = new List <SslApplicationProtocol>()
            {
                new SslApplicationProtocol(options.Alpn)
            };

            quicListenerOptions.ServerAuthenticationOptions = sslServerAuthenticationOptions;
            quicListenerOptions.ListenEndPoint = endpoint as IPEndPoint;
            quicListenerOptions.IdleTimeout    = options.IdleTimeout;

            _listener = new QuicListener(QuicImplementationProviders.MsQuic, quicListenerOptions);
            _listener.Start();
        }
Exemplo n.º 4
0
        public QuicConnectionContext(QuicConnection connection, QuicTransportContext context)
        {
            _log        = context.Log;
            _context    = context;
            _connection = connection;
            Features.Set <ITlsConnectionFeature>(new FakeTlsConnectionFeature());
            Features.Set <IProtocolErrorCodeFeature>(this);

            _log.NewConnection(ConnectionId);
        }
Exemplo n.º 5
0
        public QuicConnectionContext(QuicConnection connection, QuicTransportContext context)
        {
            _log             = context.Log;
            _context         = context;
            _connection      = connection;
            ConnectionClosed = _connectionClosedTokenSource.Token;
            Features.Set <ITlsConnectionFeature>(new FakeTlsConnectionFeature());
            Features.Set <IProtocolErrorCodeFeature>(this);

            _log.AcceptedConnection(this);
        }
Exemplo n.º 6
0
        public QuicConnectionListener(QuicTransportOptions options, IQuicTrace log, EndPoint endpoint)
        {
            _log     = log;
            _context = new QuicTransportContext(_log, options);
            EndPoint = endpoint;

            var quicListenerOptions = new QuicListenerOptions();
            var sslConfig           = new SslServerAuthenticationOptions();

            sslConfig.ServerCertificate    = options.Certificate;
            sslConfig.ApplicationProtocols = new List <SslApplicationProtocol>()
            {
                new SslApplicationProtocol(options.Alpn)
            };

            quicListenerOptions.ServerAuthenticationOptions = sslConfig;
            quicListenerOptions.CertificateFilePath         = options.CertificateFilePath;
            quicListenerOptions.PrivateKeyFilePath          = options.PrivateKeyFilePath;
            quicListenerOptions.ListenEndPoint = endpoint as IPEndPoint;

            _listener = new QuicListener(QuicImplementationProviders.MsQuic, quicListenerOptions);
            _listener.Start();
        }