Skip to content

Commit

Permalink
http2: expose nghttp2_option_set_stream_reset_rate_limit as an option
Browse files Browse the repository at this point in the history
PR-URL: #54875
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
  • Loading branch information
arcanis authored and targos committed Oct 4, 2024
1 parent 781ffd8 commit 914db60
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
7 changes: 7 additions & 0 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,10 @@ Throws `ERR_INVALID_ARG_TYPE` for invalid `settings` argument.
<!-- YAML
added: v8.4.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/54875
description: Added `streamResetBurst` and `streamResetRate`.
- version:
- v15.10.0
- v14.16.0
Expand Down Expand Up @@ -2868,6 +2872,9 @@ changes:
**Default:** `100`.
* `settings` {HTTP/2 Settings Object} The initial settings to send to the
remote peer upon connection.
* `streamResetBurst` {number} and `streamResetRate` {number} Sets the rate
limit for the incoming stream reset (RST\_STREAM frame). Both settings must
be set to have any effect, and default to 1000 and 33 respectively.
* `remoteCustomSettings` {Array} The array of integer values determines the
settings types, which are included in the `CustomSettings`-property of
the received remoteSettings. Please see the `CustomSettings`-property of
Expand Down
14 changes: 13 additions & 1 deletion lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ const IDX_OPTIONS_MAX_OUTSTANDING_PINGS = 6;
const IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS = 7;
const IDX_OPTIONS_MAX_SESSION_MEMORY = 8;
const IDX_OPTIONS_MAX_SETTINGS = 9;
const IDX_OPTIONS_FLAGS = 10;
const IDX_OPTIONS_STREAM_RESET_RATE = 10;
const IDX_OPTIONS_STREAM_RESET_BURST = 11;
const IDX_OPTIONS_FLAGS = 12;

function updateOptionsBuffer(options) {
let flags = 0;
Expand Down Expand Up @@ -270,6 +272,16 @@ function updateOptionsBuffer(options) {
optionsBuffer[IDX_OPTIONS_MAX_SETTINGS] =
MathMax(1, options.maxSettings);
}
if (typeof options.streamResetRate === 'number') {
flags |= (1 << IDX_OPTIONS_STREAM_RESET_RATE);
optionsBuffer[IDX_OPTIONS_STREAM_RESET_RATE] =
MathMax(1, options.streamResetRate);
}
if (typeof options.streamResetBurst === 'number') {
flags |= (1 << IDX_OPTIONS_STREAM_RESET_BURST);
optionsBuffer[IDX_OPTIONS_STREAM_RESET_BURST] =
MathMax(1, options.streamResetBurst);
}
optionsBuffer[IDX_OPTIONS_FLAGS] = flags;
}

Expand Down
8 changes: 8 additions & 0 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ Http2Options::Http2Options(Http2State* http2_state, SessionType type) {
option,
static_cast<size_t>(buffer[IDX_OPTIONS_MAX_SETTINGS]));
}

if ((flags & (1 << IDX_OPTIONS_STREAM_RESET_BURST)) &&
(flags & (1 << IDX_OPTIONS_STREAM_RESET_RATE))) {
nghttp2_option_set_stream_reset_rate_limit(
option,
static_cast<uint64_t>(buffer[IDX_OPTIONS_STREAM_RESET_BURST]),
static_cast<uint64_t>(buffer[IDX_OPTIONS_STREAM_RESET_RATE]));
}
}

#define GRABSETTING(entries, count, name) \
Expand Down
2 changes: 2 additions & 0 deletions src/node_http2_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace http2 {
IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS,
IDX_OPTIONS_MAX_SESSION_MEMORY,
IDX_OPTIONS_MAX_SETTINGS,
IDX_OPTIONS_STREAM_RESET_RATE,
IDX_OPTIONS_STREAM_RESET_BURST,
IDX_OPTIONS_FLAGS
};

Expand Down
10 changes: 9 additions & 1 deletion test/parallel/test-http2-util-update-options-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const IDX_OPTIONS_MAX_OUTSTANDING_PINGS = 6;
const IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS = 7;
const IDX_OPTIONS_MAX_SESSION_MEMORY = 8;
const IDX_OPTIONS_MAX_SETTINGS = 9;
const IDX_OPTIONS_FLAGS = 10;
const IDX_OPTIONS_STREAM_RESET_RATE = 10;
const IDX_OPTIONS_STREAM_RESET_BURST = 11;
const IDX_OPTIONS_FLAGS = 12;

{
updateOptionsBuffer({
Expand All @@ -37,6 +39,8 @@ const IDX_OPTIONS_FLAGS = 10;
maxOutstandingSettings: 8,
maxSessionMemory: 9,
maxSettings: 10,
streamResetRate: 11,
streamResetBurst: 12,
});

strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
Expand All @@ -49,6 +53,8 @@ const IDX_OPTIONS_FLAGS = 10;
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS], 8);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SESSION_MEMORY], 9);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SETTINGS], 10);
strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_RATE], 11);
strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_BURST], 12);

const flags = optionsBuffer[IDX_OPTIONS_FLAGS];

Expand All @@ -61,6 +67,8 @@ const IDX_OPTIONS_FLAGS = 10;
ok(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_PINGS));
ok(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS));
ok(flags & (1 << IDX_OPTIONS_MAX_SETTINGS));
ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_RATE));
ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_BURST));
}

{
Expand Down

0 comments on commit 914db60

Please sign in to comment.