diff --git a/lib/http2.dart b/lib/http2.dart index 3f1ed78..fc2f4be 100644 --- a/lib/http2.dart +++ b/lib/http2.dart @@ -42,7 +42,7 @@ /// /// A simple example on how to connect to a http/2 capable server and /// requesting a resource is available at https://github.com/dart-lang/http2/blob/master/example/display_headers.dart. -library http2.http2; +library; import 'transport.dart'; export 'transport.dart'; diff --git a/lib/src/flowcontrol/window.dart b/lib/src/flowcontrol/window.dart index 51b9016..8530ef2 100644 --- a/lib/src/flowcontrol/window.dart +++ b/lib/src/flowcontrol/window.dart @@ -11,13 +11,20 @@ class Window { /// streams is 65535). /// /// NOTE: This value can potentially become negative. + final int _initialSize; int _size; - Window({int initialSize = (1 << 16) - 1}) : _size = initialSize; + Window({int initialSize = (1 << 16) - 1}) + : _size = initialSize, + _initialSize = initialSize; /// The current size of the flow control window. int get size => _size; + bool get isTooSmall => size < _initialSize / 2; + + int get updateSize => _initialSize ~/ 2; + void modify(int difference) { _size += difference; } diff --git a/lib/src/flowcontrol/window_handler.dart b/lib/src/flowcontrol/window_handler.dart index 27d0321..0f82b98 100644 --- a/lib/src/flowcontrol/window_handler.dart +++ b/lib/src/flowcontrol/window_handler.dart @@ -152,11 +152,15 @@ class IncomingWindowHandler { // - either stop sending window update frames // - or decreasing the window size void dataProcessed(int numberOfBytes) { - _localWindow.modify(numberOfBytes); - // TODO: This can be optimized by delaying the window update to // send one update with a bigger difference than multiple small update // frames. - _frameWriter.writeWindowUpdate(numberOfBytes, streamId: _streamId); + if (_localWindow.isTooSmall) { + _frameWriter.writeWindowUpdate( + _localWindow.updateSize, + streamId: _streamId, + ); + } + _localWindow.modify(_localWindow.updateSize); } } diff --git a/lib/src/frames/frames.dart b/lib/src/frames/frames.dart index f6e74d2..cb39587 100644 --- a/lib/src/frames/frames.dart +++ b/lib/src/frames/frames.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -library http2.src.frames; +library; import 'dart:async'; import 'dart:math' show max; diff --git a/lib/src/hpack/hpack.dart b/lib/src/hpack/hpack.dart index ab5d9c8..0de0f5a 100644 --- a/lib/src/hpack/hpack.dart +++ b/lib/src/hpack/hpack.dart @@ -5,7 +5,7 @@ /// Implements a [HPackContext] for encoding/decoding headers according to the /// HPACK specificaiton. See here for more information: /// https://tools.ietf.org/html/draft-ietf-httpbis-header-compression-10 -library http2.hpack; +library; import 'dart:convert' show ascii; import 'dart:typed_data'; diff --git a/pubspec.yaml b/pubspec.yaml index ac0e139..2dc2e33 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,6 +13,6 @@ environment: dev_dependencies: build_runner: ^2.3.0 - dart_flutter_team_lints: ^2.0.0 + dart_flutter_team_lints: ^3.0.0 mockito: ^5.3.2 test: ^1.21.4 diff --git a/test/src/flowcontrol/window_handler_test.dart b/test/src/flowcontrol/window_handler_test.dart index 017dadd..09d037f 100644 --- a/test/src/flowcontrol/window_handler_test.dart +++ b/test/src/flowcontrol/window_handler_test.dart @@ -102,7 +102,7 @@ void main() { const STREAM_ID = 99; var fw = FrameWriterMock(); - var window = Window(); + var window = Window(initialSize: 150); var initialSize = window.size; var handler = IncomingWindowHandler.stream(fw, window, STREAM_ID); @@ -112,17 +112,18 @@ void main() { // If the remote end sends us now 100 bytes, it reduces the local // incoming window by 100 bytes. Once we handled these bytes, it, // will send a [WindowUpdateFrame] to the remote peer to ACK it. - handler.gotData(100); - expect(handler.localWindowSize, initialSize - 100); - expect(window.size, initialSize - 100); + var numberOfBytes = 100; + handler.gotData(numberOfBytes); + expect(handler.localWindowSize, initialSize - numberOfBytes); + expect(window.size, initialSize - numberOfBytes); // The data might sit in a queue. Once the user drains enough data of // the queue, we will start ACKing the data and the window becomes // positive again. - handler.dataProcessed(100); - expect(handler.localWindowSize, initialSize); - expect(window.size, initialSize); - verify(fw.writeWindowUpdate(100, streamId: STREAM_ID)).called(1); + handler.dataProcessed(numberOfBytes); + expect(handler.localWindowSize, 125); + expect(window.size, 125); + verify(fw.writeWindowUpdate(75, streamId: STREAM_ID)).called(1); verifyNoMoreInteractions(fw); }); });