Exemple #1
0
        public DefaultHttp2RemoteFlowController(IHttp2Connection connection, IStreamByteDistributor streamByteDistributor, IHttp2RemoteFlowControllerListener listener)
        {
            if (connection is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.connection);
            }
            if (streamByteDistributor is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.streamByteDistributor);
            }
            _connection            = connection;
            _streamByteDistributor = streamByteDistributor;

            // Add a flow state for the connection.
            _stateKey        = connection.NewKey();
            _connectionState = new FlowState(this, _connection.ConnectionStream);
            _ = connection.ConnectionStream.SetProperty(_stateKey, _connectionState);

            // Monitor may depend upon connectionState, and so initialize after connectionState
            Listener(listener);
            _monitor.WindowSize(_connectionState, _initialWindowSize);

            // Register for notification of new streams.
            connection.AddListener(this);
        }
        public WeightedFairQueueByteDistributor(IHttp2Connection connection, int maxStateOnlySize)
        {
            uint uMaxStateOnlySize = (uint)maxStateOnlySize;

            if (uMaxStateOnlySize > SharedConstants.TooBigOrNegative)
            {
                ThrowHelper.ThrowArgumentException_PositiveOrZero(maxStateOnlySize, ExceptionArgument.maxStateOnlySize);
            }
            if (0u >= uMaxStateOnlySize)
            {
                _stateOnlyMap          = EmptyDictionary <int, State> .Instance;
                _stateOnlyRemovalQueue = EmptyPriorityQueue <State> .Instance;
            }
            else
            {
                _stateOnlyMap = new Dictionary <int, State>(maxStateOnlySize);
                // +2 because we may exceed the limit by 2 if a new dependency has no associated IHttp2Stream object. We need
                // to create the State objects to put them into the dependency tree, which then impacts priority.
                _stateOnlyRemovalQueue = new PriorityQueue <State>(StateOnlyComparator.Instance, maxStateOnlySize + 2);
            }

            _maxStateOnlySize = maxStateOnlySize;

            _connection = connection;
            _stateKey   = connection.NewKey();
            IHttp2Stream connectionStream = connection.ConnectionStream;

            _ = connectionStream.SetProperty(_stateKey, _connectionState = new State(this, connectionStream, 16));

            // Register for notification of new streams.
            connection.AddListener(this);
        }
 public DefaultHttp2FrameStream SetStreamAndProperty(IHttp2ConnectionPropertyKey streamKey, IHttp2Stream stream)
 {
     Debug.Assert(v_id == -1 || stream.Id == v_id);
     _ = stream.SetProperty(streamKey, this);
     InternalStream = stream;
     return(this);
 }
Exemple #4
0
        public DelegatingDecompressorFrameListener(IHttp2Connection connection, IHttp2FrameListener listener, bool strict)
            : base(listener)
        {
            _connection = connection;
            _strict     = strict;

            _propertyKey = connection.NewKey();
            _connection.AddListener(new DelegatingConnectionAdapter(this));
        }
Exemple #5
0
        public UniformStreamByteDistributor(IHttp2Connection connection)
        {
            // Add a state for the connection.
            _stateKey = connection.NewKey();
            var connectionStream = connection.ConnectionStream;

            _ = connectionStream.SetProperty(_stateKey, new State(this, connectionStream));

            // Register for notification of new streams.
            connection.AddListener(this);
        }
Exemple #6
0
        public Http2FrameCodec(IHttp2ConnectionEncoder encoder, IHttp2ConnectionDecoder decoder, Http2Settings initialSettings, bool decoupleCloseAndGoAway)
            : base(decoder, encoder, initialSettings, decoupleCloseAndGoAway)
        {
            _frameStreamToInitializeMap = new ConcurrentDictionary <int, DefaultHttp2FrameStream>();

            decoder.FrameListener = new FrameListener(this);
            var connection = Connection;

            connection.AddListener(new ConnectionListener(this));
            connection.Remote.FlowController.Listener(new Http2RemoteFlowControllerListener(this));
            _streamKey  = connection.NewKey();
            _upgradeKey = connection.NewKey();
            _initialFlowControlWindowSize = initialSettings.InitialWindowSize();
        }
        public InboundHttp2ToHttpAdapter(IHttp2Connection connection, int maxContentLength,
                                         bool validateHttpHeaders, bool propagateSettings)
        {
            if (connection is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.connection);
            }
            if ((uint)(maxContentLength - 1) > SharedConstants.TooBigOrNegative)
            {
                ThrowHelper.ThrowArgumentException_Positive(maxContentLength, ExceptionArgument.maxContentLength);
            }

            _connection          = connection;
            _maxContentLength    = maxContentLength;
            _validateHttpHeaders = validateHttpHeaders;
            _propagateSettings   = propagateSettings;
            _sendDetector        = DefaultImmediateSendDetector.Instance;
            _messageKey          = connection.NewKey();
        }
Exemple #8
0
        /// <summary>
        /// Constructs a controller with the given settings.
        /// </summary>
        /// <param name="connection">the connection state.</param>
        /// <param name="windowUpdateRatio">the window percentage below which to send a <c>WINDOW_UPDATE</c>.</param>
        /// <param name="autoRefillConnectionWindow">if <c>true</c>, effectively disables the connection window
        /// in the flow control algorithm as they will always refill automatically without requiring the
        /// application to consume the bytes. When enabled, the maximum bytes you must be prepared to
        /// queue is proportional to <c>maximum number of concurrent streams * the initial window
        /// size per stream</c>
        /// (<a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_MAX_CONCURRENT_STREAMS</a>
        /// <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_INITIAL_WINDOW_SIZE</a>).
        /// </param>
        public DefaultHttp2LocalFlowController(IHttp2Connection connection, float windowUpdateRatio, bool autoRefillConnectionWindow)
        {
            if (connection is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.connection);
            }

            _connection = connection;
            WindowUpdateRatio(windowUpdateRatio);

            // Add a flow state for the connection.
            _stateKey = connection.NewKey();
            IFlowState connectionState = autoRefillConnectionWindow
                ? new AutoRefillState(this, connection.ConnectionStream, _initialWindowSize)
                : new DefaultState(this, connection.ConnectionStream, _initialWindowSize);

            _ = connection.ConnectionStream.SetProperty(_stateKey, connectionState);

            // Register for notification of new streams.
            connection.AddListener(this);
        }
        public CompressorHttp2ConnectionEncoder(IHttp2ConnectionEncoder encoder, int compressionLevel, int windowBits, int memLevel)
            : base(encoder)
        {
            if (compressionLevel < 0 || compressionLevel > 9)
            {
                ThrowHelper.ThrowArgumentException_InvalidCompressionLevel(compressionLevel);
            }
            if (windowBits < 9 || windowBits > 15)
            {
                ThrowHelper.ThrowArgumentException_InvalidWindowBits(windowBits);
            }
            if (memLevel < 1 || memLevel > 9)
            {
                ThrowHelper.ThrowArgumentException_InvalidMemLevel(memLevel);
            }
            _compressionLevel = compressionLevel;
            _windowBits       = windowBits;
            _memLevel         = memLevel;

            var connect = Connection;

            _propertyKey = connect.NewKey();
            connect.AddListener(new DelegatingConnectionAdapter(this));
        }