Skip to content

Commit 1fb30d6

Browse files
jasnelladuh95
authored andcommitted
quic: multiple updates to quic impl
* separate stats and symbols into separate files * quic: rename `EndpointStats` and `SessionStats` to be consistent * s/EndpointStats/QuicEndpointStats/ * s/SessionStats/QuicSessionStats/ * separate state into separate files and other cleanups * extend tls options validations * rename classes for consistency and other cleanups PR-URL: #55971 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent baed276 commit 1fb30d6

8 files changed

+1449
-1222
lines changed

lib/internal/quic/quic.js

+137-1,186
Large diffs are not rendered by default.

lib/internal/quic/state.js

+566
Large diffs are not rendered by default.

lib/internal/quic/stats.js

+646
Large diffs are not rendered by default.

lib/internal/quic/symbols.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
3+
const {
4+
Symbol,
5+
} = primordials;
6+
7+
const {
8+
customInspectSymbol: kInspect,
9+
} = require('internal/util');
10+
11+
const {
12+
kHandle: kKeyObjectHandle,
13+
kKeyObject: kKeyObjectInner,
14+
} = require('internal/crypto/util');
15+
16+
// Symbols used to hide various private properties and methods from the
17+
// public API.
18+
19+
const kBlocked = Symbol('kBlocked');
20+
const kDatagram = Symbol('kDatagram');
21+
const kDatagramStatus = Symbol('kDatagramStatus');
22+
const kError = Symbol('kError');
23+
const kFinishClose = Symbol('kFinishClose');
24+
const kHandshake = Symbol('kHandshake');
25+
const kHeaders = Symbol('kHeaders');
26+
const kOwner = Symbol('kOwner');
27+
const kNewSession = Symbol('kNewSession');
28+
const kNewStream = Symbol('kNewStream');
29+
const kPathValidation = Symbol('kPathValidation');
30+
const kReset = Symbol('kReset');
31+
const kSessionTicket = Symbol('kSessionTicket');
32+
const kTrailers = Symbol('kTrailers');
33+
const kVersionNegotiation = Symbol('kVersionNegotiation');
34+
const kPrivateConstructor = Symbol('kPrivateConstructor');
35+
36+
module.exports = {
37+
kBlocked,
38+
kDatagram,
39+
kDatagramStatus,
40+
kError,
41+
kFinishClose,
42+
kHandshake,
43+
kHeaders,
44+
kOwner,
45+
kNewSession,
46+
kNewStream,
47+
kPathValidation,
48+
kReset,
49+
kSessionTicket,
50+
kTrailers,
51+
kVersionNegotiation,
52+
kInspect,
53+
kKeyObjectHandle,
54+
kKeyObjectInner,
55+
kPrivateConstructor,
56+
};

src/node_builtins.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
133133
"internal/streams/lazy_transform",
134134
#endif // !HAVE_OPENSSL
135135
#if !NODE_OPENSSL_HAS_QUIC
136-
"internal/quic/quic",
136+
"internal/quic/quic", "internal/quic/symbols", "internal/quic/stats",
137+
"internal/quic/state",
137138
#endif // !NODE_OPENSSL_HAS_QUIC
138139
"sqlite", // Experimental.
139140
"sys", // Deprecated.

test/parallel/test-quic-internal-endpoint-listen-defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ describe('quic internal endpoint listen defaults', { skip: !hasQuic }, async ()
2020
} = require('net');
2121

2222
const {
23-
Endpoint,
23+
QuicEndpoint,
2424
} = require('internal/quic/quic');
2525

2626
it('are reasonable and work as expected', async () => {
27-
const endpoint = new Endpoint({
27+
const endpoint = new QuicEndpoint({
2828
onsession() {},
2929
session: {},
3030
stream: {},

test/parallel/test-quic-internal-endpoint-options.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
1515
} = require('node:assert');
1616

1717
const {
18-
Endpoint,
18+
QuicEndpoint,
1919
} = require('internal/quic/quic');
2020

2121
const {
@@ -30,17 +30,17 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
3030

3131
it('invalid options', async () => {
3232
['a', null, false, NaN].forEach((i) => {
33-
throws(() => new Endpoint(callbackConfig, i), {
33+
throws(() => new QuicEndpoint(callbackConfig, i), {
3434
code: 'ERR_INVALID_ARG_TYPE',
3535
});
3636
});
3737
});
3838

3939
it('valid options', async () => {
4040
// Just Works... using all defaults
41-
new Endpoint(callbackConfig, {});
42-
new Endpoint(callbackConfig);
43-
new Endpoint(callbackConfig, undefined);
41+
new QuicEndpoint(callbackConfig, {});
42+
new QuicEndpoint(callbackConfig);
43+
new QuicEndpoint(callbackConfig, undefined);
4444
});
4545

4646
it('various cases', async () => {
@@ -126,12 +126,12 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
126126
{
127127
key: 'cc',
128128
valid: [
129-
Endpoint.CC_ALGO_RENO,
130-
Endpoint.CC_ALGO_CUBIC,
131-
Endpoint.CC_ALGO_BBR,
132-
Endpoint.CC_ALGO_RENO_STR,
133-
Endpoint.CC_ALGO_CUBIC_STR,
134-
Endpoint.CC_ALGO_BBR_STR,
129+
QuicEndpoint.CC_ALGO_RENO,
130+
QuicEndpoint.CC_ALGO_CUBIC,
131+
QuicEndpoint.CC_ALGO_BBR,
132+
QuicEndpoint.CC_ALGO_RENO_STR,
133+
QuicEndpoint.CC_ALGO_CUBIC_STR,
134+
QuicEndpoint.CC_ALGO_BBR_STR,
135135
],
136136
invalid: [-1, 4, 1n, 'a', null, false, true, {}, [], () => {}],
137137
},
@@ -190,39 +190,39 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
190190
for (const value of valid) {
191191
const options = {};
192192
options[key] = value;
193-
new Endpoint(callbackConfig, options);
193+
new QuicEndpoint(callbackConfig, options);
194194
}
195195

196196
for (const value of invalid) {
197197
const options = {};
198198
options[key] = value;
199-
throws(() => new Endpoint(callbackConfig, options), {
199+
throws(() => new QuicEndpoint(callbackConfig, options), {
200200
code: 'ERR_INVALID_ARG_VALUE',
201201
});
202202
}
203203
}
204204
});
205205

206206
it('endpoint can be ref/unrefed without error', async () => {
207-
const endpoint = new Endpoint(callbackConfig, {});
207+
const endpoint = new QuicEndpoint(callbackConfig, {});
208208
endpoint.unref();
209209
endpoint.ref();
210210
endpoint.close();
211211
await endpoint.closed;
212212
});
213213

214214
it('endpoint can be inspected', async () => {
215-
const endpoint = new Endpoint(callbackConfig, {});
215+
const endpoint = new QuicEndpoint(callbackConfig, {});
216216
strictEqual(typeof inspect(endpoint), 'string');
217217
endpoint.close();
218218
await endpoint.closed;
219219
});
220220

221221
it('endpoint with object address', () => {
222-
new Endpoint(callbackConfig, {
222+
new QuicEndpoint(callbackConfig, {
223223
address: { host: '127.0.0.1:0' },
224224
});
225-
throws(() => new Endpoint(callbackConfig, { address: '127.0.0.1:0' }), {
225+
throws(() => new QuicEndpoint(callbackConfig, { address: '127.0.0.1:0' }), {
226226
code: 'ERR_INVALID_ARG_TYPE',
227227
});
228228
});

test/parallel/test-quic-internal-endpoint-stats-state.js

+23-16
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ const {
1010

1111
describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
1212
const {
13-
Endpoint,
13+
QuicEndpoint,
1414
QuicStreamState,
1515
QuicStreamStats,
16-
SessionState,
17-
SessionStats,
18-
kFinishClose,
16+
QuicSessionState,
17+
QuicSessionStats,
1918
} = require('internal/quic/quic');
2019

20+
const {
21+
kFinishClose,
22+
kPrivateConstructor,
23+
} = require('internal/quic/symbols');
24+
2125
const {
2226
inspect,
2327
} = require('util');
@@ -29,7 +33,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
2933
} = require('node:assert');
3034

3135
it('endpoint state', () => {
32-
const endpoint = new Endpoint({
36+
const endpoint = new QuicEndpoint({
3337
onsession() {},
3438
session: {},
3539
stream: {},
@@ -62,7 +66,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
6266
});
6367

6468
it('state is not readable after close', () => {
65-
const endpoint = new Endpoint({
69+
const endpoint = new QuicEndpoint({
6670
onsession() {},
6771
session: {},
6872
stream: {},
@@ -74,24 +78,25 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
7478
});
7579

7680
it('state constructor argument is ArrayBuffer', () => {
77-
const endpoint = new Endpoint({
81+
const endpoint = new QuicEndpoint({
7882
onsession() {},
7983
session: {},
8084
stream: {},
8185
}, {});
8286
const Cons = endpoint.state.constructor;
83-
throws(() => new Cons(1), {
87+
throws(() => new Cons(kPrivateConstructor, 1), {
8488
code: 'ERR_INVALID_ARG_TYPE'
8589
});
8690
});
8791

8892
it('endpoint stats', () => {
89-
const endpoint = new Endpoint({
93+
const endpoint = new QuicEndpoint({
9094
onsession() {},
9195
session: {},
9296
stream: {},
9397
});
9498

99+
strictEqual(typeof endpoint.stats.isConnected, 'boolean');
95100
strictEqual(typeof endpoint.stats.createdAt, 'bigint');
96101
strictEqual(typeof endpoint.stats.destroyedAt, 'bigint');
97102
strictEqual(typeof endpoint.stats.bytesReceived, 'bigint');
@@ -107,6 +112,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
107112
strictEqual(typeof endpoint.stats.immediateCloseCount, 'bigint');
108113

109114
deepStrictEqual(Object.keys(endpoint.stats.toJSON()), [
115+
'connected',
110116
'createdAt',
111117
'destroyedAt',
112118
'bytesReceived',
@@ -128,25 +134,26 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
128134
});
129135

130136
it('stats are still readble after close', () => {
131-
const endpoint = new Endpoint({
137+
const endpoint = new QuicEndpoint({
132138
onsession() {},
133139
session: {},
134140
stream: {},
135141
}, {});
136142
strictEqual(typeof endpoint.stats.toJSON(), 'object');
137143
endpoint.stats[kFinishClose]();
144+
strictEqual(endpoint.stats.isConnected, false);
138145
strictEqual(typeof endpoint.stats.destroyedAt, 'bigint');
139146
strictEqual(typeof endpoint.stats.toJSON(), 'object');
140147
});
141148

142149
it('stats constructor argument is ArrayBuffer', () => {
143-
const endpoint = new Endpoint({
150+
const endpoint = new QuicEndpoint({
144151
onsession() {},
145152
session: {},
146153
stream: {},
147154
}, {});
148155
const Cons = endpoint.stats.constructor;
149-
throws(() => new Cons(1), {
156+
throws(() => new Cons(kPrivateConstructor, 1), {
150157
code: 'ERR_INVALID_ARG_TYPE',
151158
});
152159
});
@@ -156,8 +163,8 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
156163
// temporarily while the rest of the functionality is being
157164
// implemented.
158165
it('stream and session states', () => {
159-
const streamState = new QuicStreamState(new ArrayBuffer(1024));
160-
const sessionState = new SessionState(new ArrayBuffer(1024));
166+
const streamState = new QuicStreamState(kPrivateConstructor, new ArrayBuffer(1024));
167+
const sessionState = new QuicSessionState(kPrivateConstructor, new ArrayBuffer(1024));
161168

162169
strictEqual(streamState.finSent, false);
163170
strictEqual(streamState.finReceived, false);
@@ -195,8 +202,8 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
195202
});
196203

197204
it('stream and session stats', () => {
198-
const streamStats = new QuicStreamStats(new ArrayBuffer(1024));
199-
const sessionStats = new SessionStats(new ArrayBuffer(1024));
205+
const streamStats = new QuicStreamStats(kPrivateConstructor, new ArrayBuffer(1024));
206+
const sessionStats = new QuicSessionStats(kPrivateConstructor, new ArrayBuffer(1024));
200207
strictEqual(streamStats.createdAt, undefined);
201208
strictEqual(streamStats.receivedAt, undefined);
202209
strictEqual(streamStats.ackedAt, undefined);

0 commit comments

Comments
 (0)