Skip to content

Commit c5e466e

Browse files
committed
quic: additional API cleanups
1 parent 036b9e2 commit c5e466e

File tree

4 files changed

+46
-41
lines changed

4 files changed

+46
-41
lines changed

lib/internal/quic/quic.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ const onEndpointServerSessionChannel = dc.channel('quic.session.created.server')
165165
* @property {bigint|number} [handshakeTimeout] The handshake timeout
166166
* @property {bigint|number} [maxStreamWindow] The maximum stream window
167167
* @property {bigint|number} [maxWindow] The maximum window
168-
* @property {number} [rxDiagnosticLoss] The receive diagnostic loss (range 0.0-1.0)
169-
* @property {number} [txDiagnosticLoss] The transmit diagnostic loss (range 0.0-1.0)
168+
* @property {number} [rxDiagnosticLoss] The receive diagnostic loss probability (range 0.0-1.0)
169+
* @property {number} [txDiagnosticLoss] The transmit diagnostic loss probability (range 0.0-1.0)
170170
* @property {number} [udpReceiveBufferSize] The UDP receive buffer size
171171
* @property {number} [udpSendBufferSize] The UDP send buffer size
172172
* @property {number} [udpTTL] The UDP TTL
@@ -395,6 +395,31 @@ const onEndpointServerSessionChannel = dc.channel('quic.session.created.server')
395395
* @property {OnStreamErrorCallback} [onreset] The reset callback
396396
* @property {OnHeadersCallback} [onheaders] The headers callback
397397
* @property {OnTrailersCallback} [ontrailers] The trailers callback
398+
* @property {SocketAddress} [address] The local address to bind to
399+
* @property {bigint|number} [retryTokenExpiration] The retry token expiration
400+
* @property {bigint|number} [tokenExpiration] The token expiration
401+
* @property {bigint|number} [maxConnectionsPerHost] The maximum number of connections per host
402+
* @property {bigint|number} [maxConnectionsTotal] The maximum number of total connections
403+
* @property {bigint|number} [maxStatelessResetsPerHost] The maximum number of stateless resets per host
404+
* @property {bigint|number} [addressLRUSize] The size of the address LRU cache
405+
* @property {bigint|number} [maxRetries] The maximum number of retries
406+
* @property {bigint|number} [maxPayloadSize] The maximum payload size
407+
* @property {bigint|number} [unacknowledgedPacketThreshold] The unacknowledged packet threshold
408+
* @property {bigint|number} [handshakeTimeout] The handshake timeout
409+
* @property {bigint|number} [maxStreamWindow] The maximum stream window
410+
* @property {bigint|number} [maxWindow] The maximum window
411+
* @property {number} [rxDiagnosticLoss] The receive diagnostic loss probability (range 0.0-1.0)
412+
* @property {number} [txDiagnosticLoss] The transmit diagnostic loss probability (range 0.0-1.0)
413+
* @property {number} [udpReceiveBufferSize] The UDP receive buffer size
414+
* @property {number} [udpSendBufferSize] The UDP send buffer size
415+
* @property {number} [udpTTL] The UDP TTL
416+
* @property {boolean} [noUdpPayloadSizeShaping] Disable UDP payload size shaping
417+
* @property {boolean} [validateAddress] Validate the address
418+
* @property {boolean} [disableActiveMigration] Disable active migration
419+
* @property {boolean} [ipv6Only] Use IPv6 only
420+
* @property {'reno'|'cubic'|'bbr'|number} [cc] The congestion control algorithm
421+
* @property {ArrayBufferView} [resetTokenSecret] The reset token secret
422+
* @property {ArrayBufferView} [tokenSecret] The token secret
398423
*/
399424

400425
/**
@@ -1342,7 +1367,7 @@ class QuicEndpoint {
13421367
}
13431368

13441369
/**
1345-
* @param {EndpointOptions} options
1370+
* @param {EndpointCallbackConfiguration} options
13461371
* @returns {EndpointOptions}
13471372
*/
13481373
#processEndpointOptions(options) {
@@ -1421,9 +1446,8 @@ class QuicEndpoint {
14211446

14221447
/**
14231448
* @param {EndpointCallbackConfiguration} config
1424-
* @param {EndpointOptions} [options]
14251449
*/
1426-
constructor(config = kEmptyObject, options = kEmptyObject) {
1450+
constructor(config = kEmptyObject) {
14271451
const {
14281452
onsession,
14291453
session,
@@ -1437,15 +1461,15 @@ class QuicEndpoint {
14371461
}
14381462
this.#sessionConfig = session;
14391463

1440-
this.#handle = new Endpoint_(this.#processEndpointOptions(options));
1464+
this.#handle = new Endpoint_(this.#processEndpointOptions(config));
14411465
this.#handle[kOwner] = this;
14421466
this.#stats = new QuicEndpointStats(kPrivateConstructor, this.#handle.stats);
14431467
this.#state = new QuicEndpointState(kPrivateConstructor, this.#handle.state);
14441468

14451469
if (onEndpointCreatedChannel.hasSubscribers) {
14461470
onEndpointCreatedChannel.publish({
14471471
endpoint: this,
1448-
options,
1472+
config,
14491473
});
14501474
}
14511475
}
@@ -1618,7 +1642,6 @@ class QuicEndpoint {
16181642
throw new ERR_INVALID_ARG_VALUE('options.preferredAddressPolicy', policy);
16191643
}
16201644

1621-
16221645
/**
16231646
* @param {SessionOptions} options
16241647
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('quic internal endpoint listen defaults', { skip: !hasQuic }, async ()
2626
it('are reasonable and work as expected', async () => {
2727
const endpoint = new QuicEndpoint({
2828
onsession() {},
29-
}, {});
29+
});
3030

3131
ok(!endpoint.state.isBound);
3232
ok(!endpoint.state.isReceiving);

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,17 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
2222
inspect,
2323
} = require('util');
2424

25-
const callbackConfig = {
26-
onsession() {},
27-
};
28-
2925
it('invalid options', async () => {
3026
['a', null, false, NaN].forEach((i) => {
31-
throws(() => new QuicEndpoint(callbackConfig, i), {
27+
throws(() => new QuicEndpoint(i), {
3228
code: 'ERR_INVALID_ARG_TYPE',
3329
});
3430
});
3531
});
3632

3733
it('valid options', async () => {
3834
// Just Works... using all defaults
39-
new QuicEndpoint(callbackConfig, {});
40-
new QuicEndpoint(callbackConfig);
41-
new QuicEndpoint(callbackConfig, undefined);
35+
new QuicEndpoint();
4236
});
4337

4438
it('various cases', async () => {
@@ -188,39 +182,39 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
188182
for (const value of valid) {
189183
const options = {};
190184
options[key] = value;
191-
new QuicEndpoint(callbackConfig, options);
185+
new QuicEndpoint(options);
192186
}
193187

194188
for (const value of invalid) {
195189
const options = {};
196190
options[key] = value;
197-
throws(() => new QuicEndpoint(callbackConfig, options), {
191+
throws(() => new QuicEndpoint(options), {
198192
code: 'ERR_INVALID_ARG_VALUE',
199193
});
200194
}
201195
}
202196
});
203197

204198
it('endpoint can be ref/unrefed without error', async () => {
205-
const endpoint = new QuicEndpoint(callbackConfig, {});
199+
const endpoint = new QuicEndpoint();
206200
endpoint.unref();
207201
endpoint.ref();
208202
endpoint.close();
209203
await endpoint.closed;
210204
});
211205

212206
it('endpoint can be inspected', async () => {
213-
const endpoint = new QuicEndpoint(callbackConfig, {});
207+
const endpoint = new QuicEndpoint({});
214208
strictEqual(typeof inspect(endpoint), 'string');
215209
endpoint.close();
216210
await endpoint.closed;
217211
});
218212

219213
it('endpoint with object address', () => {
220-
new QuicEndpoint(callbackConfig, {
214+
new QuicEndpoint({
221215
address: { host: '127.0.0.1:0' },
222216
});
223-
throws(() => new QuicEndpoint(callbackConfig, { address: '127.0.0.1:0' }), {
217+
throws(() => new QuicEndpoint({ address: '127.0.0.1:0' }), {
224218
code: 'ERR_INVALID_ARG_TYPE',
225219
});
226220
});

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
3333
} = require('node:assert');
3434

3535
it('endpoint state', () => {
36-
const endpoint = new QuicEndpoint({
37-
onsession() {},
38-
});
36+
const endpoint = new QuicEndpoint();
3937

4038
strictEqual(endpoint.state.isBound, false);
4139
strictEqual(endpoint.state.isReceiving, false);
@@ -64,29 +62,23 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
6462
});
6563

6664
it('state is not readable after close', () => {
67-
const endpoint = new QuicEndpoint({
68-
onsession() {},
69-
}, {});
65+
const endpoint = new QuicEndpoint();
7066
endpoint.state[kFinishClose]();
7167
throws(() => endpoint.state.isBound, {
7268
name: 'Error',
7369
});
7470
});
7571

7672
it('state constructor argument is ArrayBuffer', () => {
77-
const endpoint = new QuicEndpoint({
78-
onsession() {},
79-
}, {});
73+
const endpoint = new QuicEndpoint();
8074
const Cons = endpoint.state.constructor;
8175
throws(() => new Cons(kPrivateConstructor, 1), {
8276
code: 'ERR_INVALID_ARG_TYPE'
8377
});
8478
});
8579

8680
it('endpoint stats', () => {
87-
const endpoint = new QuicEndpoint({
88-
onsession() {},
89-
});
81+
const endpoint = new QuicEndpoint();
9082

9183
strictEqual(typeof endpoint.stats.isConnected, 'boolean');
9284
strictEqual(typeof endpoint.stats.createdAt, 'bigint');
@@ -126,9 +118,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
126118
});
127119

128120
it('stats are still readble after close', () => {
129-
const endpoint = new QuicEndpoint({
130-
onsession() {},
131-
}, {});
121+
const endpoint = new QuicEndpoint();
132122
strictEqual(typeof endpoint.stats.toJSON(), 'object');
133123
endpoint.stats[kFinishClose]();
134124
strictEqual(endpoint.stats.isConnected, false);
@@ -137,9 +127,7 @@ describe('quic internal endpoint stats and state', { skip: !hasQuic }, () => {
137127
});
138128

139129
it('stats constructor argument is ArrayBuffer', () => {
140-
const endpoint = new QuicEndpoint({
141-
onsession() {},
142-
}, {});
130+
const endpoint = new QuicEndpoint();
143131
const Cons = endpoint.stats.constructor;
144132
throws(() => new Cons(kPrivateConstructor, 1), {
145133
code: 'ERR_INVALID_ARG_TYPE',

0 commit comments

Comments
 (0)