Repository navigation
quic: add Http3Session, so you can explicitly pick the app protocol #65993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pimterry
wants to merge
12
commits into
nodejs:main
Choose a base branch
from
pimterry:http3-attach
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,080
−1,058
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1f983e3
quic: add Http3Session, so you can explicitly pick the app protocol
pimterry 5990b89
fixup! quic: add Http3Session, so you can explicitly pick the app pro…
pimterry a13654d
quic: add kInspect & AsyncDispose to Http3Session
pimterry 03e1b40
quic: replace PENDING application type flag with a separate state bit
pimterry 8a9945a
quic: extract and validate Http3Settings separately into a fixed shape
pimterry 792509f
quic: move HTTP/3 events to Http3Session, use .from() to attach
pimterry 0e63cec
quic: fix subtle bugs in resume & failed H3 start teardown
pimterry 954233d
quic: add autoWrap option to auto-attach HTTP/3
pimterry 157777e
quic: move pure-QUIC fields back from Http3Session to QuicSession
pimterry c1d4200
quic: split quic connection & session, rename autoWrap to autoStart
pimterry ca63d86
quic: fix bug in setSNIContexts that lost ALPN config
pimterry e24abc9
quic: fix QUIC code broken by V8 update
pimterry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| 'use strict'; | ||
|
|
||
| const { | ||
| BigInt, | ||
| NumberIsInteger, | ||
| PromiseReject, | ||
| } = primordials; | ||
|
|
||
| const { | ||
| getOptionValue, | ||
| } = require('internal/options'); | ||
|
|
||
| if (!process.features.quic || !getOptionValue('--experimental-quic')) { | ||
| return; | ||
| } | ||
|
|
||
| // Internal, experimental HTTP/3 layer over node:quic. | ||
| // | ||
| // An Http3Session is started on a QuicConnection that has no session yet, | ||
| // and from then on the connection's streams are HTTP/3 request streams. | ||
|
|
||
| const { | ||
| QuicSessionBase, | ||
| createApplicationStream, | ||
| getApplicationCallback, | ||
| isServerConnection, | ||
| setApplicationCallback, | ||
| } = require('internal/quic/quic'); | ||
|
|
||
| const { | ||
| kPrivateConstructor, | ||
| } = require('internal/quic/symbols'); | ||
| const { kEmptyObject } = require('internal/util'); | ||
|
|
||
| const { | ||
| QUIC_APPLICATION_HTTP3, | ||
| STREAM_DIRECTION_BIDIRECTIONAL: kStreamDirectionBidirectional, | ||
| } = internalBinding('quic'); | ||
|
|
||
| const { | ||
| validateBoolean, | ||
| validateFunction, | ||
| validateObject, | ||
| } = require('internal/validators'); | ||
|
|
||
| const { | ||
| codes: { | ||
| ERR_INVALID_ARG_TYPE, | ||
| ERR_INVALID_STATE, | ||
| ERR_OUT_OF_RANGE, | ||
| }, | ||
| } = require('internal/errors'); | ||
|
|
||
| const kMaxUint64 = (1n << 64n) - 1n; | ||
|
|
||
| function validateUint64Setting(value, name) { | ||
| if (value === undefined) return undefined; | ||
| let big; | ||
| if (typeof value === 'bigint') { | ||
| big = value; | ||
| } else if (typeof value === 'number') { | ||
| if (!NumberIsInteger(value)) { | ||
| throw new ERR_OUT_OF_RANGE(`options.settings.${name}`, 'an integer', | ||
| value); | ||
| } | ||
| big = BigInt(value); | ||
| } else { | ||
| throw new ERR_INVALID_ARG_TYPE(`options.settings.${name}`, | ||
| ['number', 'bigint'], value); | ||
| } | ||
| if (big < 0n || big > kMaxUint64) { | ||
| throw new ERR_OUT_OF_RANGE(`options.settings.${name}`, | ||
| `>= 0 && <= ${kMaxUint64}`, value); | ||
| } | ||
| return big; | ||
| } | ||
|
|
||
| function validateBooleanSetting(value, name) { | ||
| if (value !== undefined) validateBoolean(value, `options.settings.${name}`); | ||
| return value; | ||
| } | ||
|
|
||
| // Read each setting just once (they may be getters), then validate and return | ||
| // them as a plain null-proto object: | ||
| function prepareH3Settings(settings) { | ||
| const { | ||
| maxHeaderPairs, | ||
| maxHeaderLength, | ||
| maxFieldSectionSize, | ||
| qpackMaxDTableCapacity, | ||
| qpackEncoderMaxDTableCapacity, | ||
| qpackBlockedStreams, | ||
| enableConnectProtocol, | ||
| enableDatagrams, | ||
| } = settings; | ||
| return { | ||
| __proto__: null, | ||
| maxHeaderPairs: validateUint64Setting(maxHeaderPairs, 'maxHeaderPairs'), | ||
| maxHeaderLength: validateUint64Setting(maxHeaderLength, 'maxHeaderLength'), | ||
| maxFieldSectionSize: | ||
| validateUint64Setting(maxFieldSectionSize, 'maxFieldSectionSize'), | ||
| qpackMaxDTableCapacity: | ||
| validateUint64Setting(qpackMaxDTableCapacity, 'qpackMaxDTableCapacity'), | ||
| qpackEncoderMaxDTableCapacity: validateUint64Setting( | ||
| qpackEncoderMaxDTableCapacity, 'qpackEncoderMaxDTableCapacity'), | ||
| qpackBlockedStreams: | ||
| validateUint64Setting(qpackBlockedStreams, 'qpackBlockedStreams'), | ||
| enableConnectProtocol: | ||
| validateBooleanSetting(enableConnectProtocol, 'enableConnectProtocol'), | ||
| enableDatagrams: validateBooleanSetting(enableDatagrams, 'enableDatagrams'), | ||
| }; | ||
| } | ||
|
|
||
| class Http3Session extends QuicSessionBase { | ||
| /** | ||
| * Starts HTTP/3 on a QuicConnection that has no session yet. | ||
| * @param {QuicConnection} connection | ||
| * @param {object} [options] | ||
| * @param {ApplicationOptions} [options.settings] | ||
| * @param {Function} [options.ongoaway] | ||
| * @param {Function} [options.onorigin] | ||
| * @param {Function} [options.onsettings] | ||
| * @returns {Http3Session} | ||
| */ | ||
| static start(connection, options) { | ||
| return new Http3Session(kPrivateConstructor, connection, options); | ||
| } | ||
|
|
||
| constructor(privateSymbol, connection, options = kEmptyObject) { | ||
| validateObject(options, 'options'); | ||
| const { ongoaway, onorigin, onsettings, settings } = options; | ||
| if (ongoaway !== undefined) validateFunction(ongoaway, 'options.ongoaway'); | ||
| if (onorigin !== undefined) validateFunction(onorigin, 'options.onorigin'); | ||
| if (onsettings !== undefined) { | ||
| validateFunction(onsettings, 'options.onsettings'); | ||
| } | ||
| let preparedSettings; | ||
| if (settings !== undefined) { | ||
| validateObject(settings, 'options.settings'); | ||
| preparedSettings = prepareH3Settings(settings); | ||
| } | ||
|
|
||
| // Reading settings could call getters and go into JS, so start after: | ||
| super(privateSymbol, connection, QUIC_APPLICATION_HTTP3, preparedSettings); | ||
|
|
||
| if (ongoaway !== undefined) this.ongoaway = ongoaway; | ||
| if (onorigin !== undefined) this.onorigin = onorigin; | ||
| if (onsettings !== undefined) this.onsettings = onsettings; | ||
| } | ||
|
|
||
| /** | ||
| * The settings in effect, including any update from the peer's SETTINGS | ||
| * frame, which may arrive after the session opens. Null once destroyed. | ||
| * @type {ApplicationOptions|null} | ||
| */ | ||
| get settings() { return this.connection.applicationOptions; } | ||
|
|
||
| /** @type {Function|undefined} */ | ||
| get ongoaway() { return getApplicationCallback(this.connection, 'ongoaway'); } | ||
| set ongoaway(fn) { setApplicationCallback(this.connection, 'ongoaway', fn, this); } | ||
|
|
||
| /** @type {Function|undefined} */ | ||
| get onorigin() { return getApplicationCallback(this.connection, 'onorigin'); } | ||
| set onorigin(fn) { setApplicationCallback(this.connection, 'onorigin', fn, this); } | ||
|
|
||
| /** @type {Function|undefined} */ | ||
| get onsettings() { return getApplicationCallback(this.connection, 'onapplication'); } | ||
| set onsettings(fn) { | ||
| setApplicationCallback(this.connection, 'onapplication', fn, this, 'onsettings'); | ||
| } | ||
|
|
||
| /** | ||
| * Opens a request stream. | ||
| * @returns {Promise<QuicStream>} | ||
| */ | ||
| createBidirectionalStream(options) { | ||
| if (isServerConnection(this.connection)) { | ||
| return PromiseReject(new ERR_INVALID_STATE( | ||
| 'Server sessions cannot open HTTP/3 request streams')); | ||
| } | ||
| return createApplicationStream( | ||
| this.connection, kStreamDirectionBidirectional, options); | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| Http3Session, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also go into
'internal/validators'?