http2: expose nghttp2_option_set_stream_reset_rate_limit as an option

PR-URL: https://github.com/nodejs/node/pull/54875
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
Maël Nison 2024-09-30 11:52:08 +02:00 committed by GitHub
parent 0f02810fc9
commit 6c6562ce8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 2 deletions

View File

@ -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
@ -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

View File

@ -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;
@ -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;
}

View File

@ -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) \

View File

@ -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
};

View File

@ -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({
@ -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);
@ -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];
@ -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));
}
{