Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Increase Window Update size #124

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/http2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
9 changes: 8 additions & 1 deletion lib/src/flowcontrol/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 7 additions & 3 deletions lib/src/flowcontrol/window_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion lib/src/frames/frames.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/hpack/hpack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 9 additions & 8 deletions test/src/flowcontrol/window_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
});
});
Expand Down
Loading