Skip to content

Commit 8113f6a

Browse files
committed
quic: add --experimental-quic cli option, add node:quic module
1 parent 0892e34 commit 8113f6a

File tree

9 files changed

+48
-17
lines changed

9 files changed

+48
-17
lines changed

doc/node.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ flag is no longer required as WASI is enabled by default.
217217
.It Fl -experimental-wasm-modules
218218
Enable experimental WebAssembly module support.
219219
.
220+
.It Fl -experimental-quic
221+
Enable the experimental QUIC support.
222+
.
220223
.It Fl -force-context-aware
221224
Disable loading native addons that are not context-aware.
222225
.

lib/internal/bootstrap/realm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ const legacyWrapperList = new SafeSet([
131131
const schemelessBlockList = new SafeSet([
132132
'sea',
133133
'sqlite',
134+
'quic',
134135
'test',
135136
'test/reporters',
136137
]);
137138
// Modules that will only be enabled at run time.
138-
const experimentalModuleList = new SafeSet(['sqlite']);
139+
const experimentalModuleList = new SafeSet(['sqlite', 'quic']);
139140

140141
// Set up process.binding() and process._linkedBinding().
141142
{

lib/internal/process/pre_execution.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function prepareExecution(options) {
101101
setupNavigator();
102102
setupWarningHandler();
103103
setupSQLite();
104+
setupQuic();
104105
setupWebStorage();
105106
setupWebsocket();
106107
setupEventsource();
@@ -311,6 +312,15 @@ function setupSQLite() {
311312
BuiltinModule.allowRequireByUsers('sqlite');
312313
}
313314

315+
function setupQuic() {
316+
if (!getOptionValue('--experimental-quic')) {
317+
return;
318+
}
319+
320+
const { BuiltinModule } = require('internal/bootstrap/realm');
321+
BuiltinModule.allowRequireByUsers('quic');
322+
}
323+
314324
function setupWebStorage() {
315325
if (getEmbedderOptions().noBrowserGlobals ||
316326
!getOptionValue('--experimental-webstorage')) {

lib/internal/quic/quic.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ const {
108108
kBlocked,
109109
kDatagram,
110110
kDatagramStatus,
111-
kError,
112111
kFinishClose,
113112
kHandshake,
114113
kHeaders,
@@ -591,7 +590,7 @@ setCallbacks({
591590
},
592591
onStreamClose(error) {
593592
// Called when the stream C++ handle has been closed.
594-
debug('stream closed callback', this[kOwner], error)
593+
debug('stream closed callback', this[kOwner], error);
595594
this[kOwner].destroy(error);
596595
},
597596
onStreamReset(error) {
@@ -1410,6 +1409,10 @@ class QuicSession {
14101409
async [SymbolAsyncDispose]() { await this.close(); }
14111410
}
14121411

1412+
// The QuicEndpoint represents a local UDP port binding. It can act as both a
1413+
// server for receiving peer sessions, or a client for initiating them. The
1414+
// local UDP port will be lazily bound only when connect() or listen() are
1415+
// called.
14131416
class QuicEndpoint {
14141417
/**
14151418
* The local socket address on which the endpoint is listening (lazily created)
@@ -1696,7 +1699,10 @@ class QuicEndpoint {
16961699
debug('endpoint created');
16971700
}
16981701

1699-
/** @type {QuicEndpointStats} */
1702+
/**
1703+
* Statistics collected while the endpoint is operational.
1704+
* @type {QuicEndpointStats}
1705+
*/
17001706
get stats() { return this.#stats; }
17011707

17021708
/** @type {QuicEndpointState} */
@@ -2034,14 +2040,6 @@ class QuicEndpoint {
20342040
return this.closed;
20352041
}
20362042

2037-
ref() {
2038-
if (this.#handle !== undefined) this.#handle.ref(true);
2039-
}
2040-
2041-
unref() {
2042-
if (this.#handle !== undefined) this.#handle.ref(false);
2043-
}
2044-
20452043
#maybeGetCloseError(context, status) {
20462044
switch (context) {
20472045
case kCloseContextClose: {

lib/internal/quic/symbols.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const {
1919
const kBlocked = Symbol('kBlocked');
2020
const kDatagram = Symbol('kDatagram');
2121
const kDatagramStatus = Symbol('kDatagramStatus');
22-
const kError = Symbol('kError');
2322
const kFinishClose = Symbol('kFinishClose');
2423
const kHandshake = Symbol('kHandshake');
2524
const kHeaders = Symbol('kHeaders');
@@ -39,7 +38,6 @@ module.exports = {
3938
kBlocked,
4039
kDatagram,
4140
kDatagramStatus,
42-
kError,
4341
kFinishClose,
4442
kHandshake,
4543
kHeaders,

lib/quic.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const {
4+
QuicEndpoint,
5+
QuicEndpointState,
6+
QuicEndpointStats,
7+
} = require('internal/quic/quic');
8+
9+
module.exports = {
10+
QuicEndpoint,
11+
QuicEndpointState,
12+
QuicEndpointStats,
13+
};

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
435435
&EnvironmentOptions::experimental_sqlite,
436436
kAllowedInEnvvar,
437437
true);
438+
AddOption("--experimental-quic",
439+
"experimental QUIC API",
440+
&EnvironmentOptions::experimental_quic,
441+
kAllowedInEnvvar);
438442
AddOption("--experimental-webstorage",
439443
"experimental Web Storage API",
440444
&EnvironmentOptions::experimental_webstorage,

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class EnvironmentOptions : public Options {
126126
bool experimental_websocket = true;
127127
bool experimental_sqlite = true;
128128
bool experimental_webstorage = false;
129+
bool experimental_quic = false;
129130
std::string localstorage_file;
130131
bool experimental_global_navigator = true;
131132
bool experimental_global_web_crypto = true;

src/quic/data.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,12 @@ std::optional<int> QuicError::crypto_error() const {
257257
}
258258

259259
MaybeLocal<Value> QuicError::ToV8Value(Environment* env) const {
260-
if ((type() == QuicError::Type::TRANSPORT && code() == NGTCP2_NO_ERROR) ||
261-
(type() == QuicError::Type::APPLICATION && code() == NGTCP2_APP_NOERROR) ||
262-
(type() == QuicError::Type::APPLICATION && code() == NGHTTP3_H3_NO_ERROR)) {
260+
if ((type() == QuicError::Type::TRANSPORT &&
261+
code() == NGTCP2_NO_ERROR) ||
262+
(type() == QuicError::Type::APPLICATION &&
263+
code() == NGTCP2_APP_NOERROR) ||
264+
(type() == QuicError::Type::APPLICATION &&
265+
code() == NGHTTP3_H3_NO_ERROR)) {
263266
return Undefined(env->isolate());
264267
}
265268

0 commit comments

Comments
 (0)