Skip to content

Commit

Permalink
quic: rename classes for consistency and other cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Nov 23, 2024
1 parent 122e5eb commit fd7b4ea
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 55 deletions.
58 changes: 29 additions & 29 deletions lib/internal/quic/quic.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,22 @@ const {
/**
* Called when the Endpoint receives a new server-side Session.
* @callback OnSessionCallback
* @param {Session} session
* @param {Endpoint} endpoint
* @param {QuicSession} session
* @param {QuicEndpoint} endpoint
* @returns {void}
*/

/**
* @callback OnStreamCallback
* @param {QuicStream} stream
* @param {Session} session
* @param {QuicSession} session
* @returns {void}
*/

/**
* @callback OnDatagramCallback
* @param {Uint8Array} datagram
* @param {Session} session
* @param {QuicSession} session
* @param {boolean} early
* @returns {void}
*/
Expand All @@ -255,7 +255,7 @@ const {
* @callback OnDatagramStatusCallback
* @param {bigint} id
* @param {'lost'|'acknowledged'} status
* @param {Session} session
* @param {QuicSession} session
* @returns {void}
*/

Expand All @@ -267,14 +267,14 @@ const {
* @param {SocketAddress} oldLocalAddress
* @param {SocketAddress} oldRemoteAddress
* @param {boolean} preferredAddress
* @param {Session} session
* @param {QuicSession} session
* @returns {void}
*/

/**
* @callback OnSessionTicketCallback
* @param {object} ticket
* @param {Session} session
* @param {QuicSession} session
* @returns {void}
*/

Expand All @@ -283,7 +283,7 @@ const {
* @param {number} version
* @param {number[]} requestedVersions
* @param {number[]} supportedVersions
* @param {Session} session
* @param {QuicSession} session
* @returns {void}
*/

Expand All @@ -296,7 +296,7 @@ const {
* @param {string} validationErrorReason
* @param {number} validationErrorCode
* @param {boolean} earlyDataAccepted
* @param {Session} session
* @param {QuicSession} session
* @returns {void}
*/

Expand Down Expand Up @@ -443,9 +443,9 @@ function processTlsOptions(tls) {
ciphers = DEFAULT_CIPHERS,
groups = DEFAULT_GROUPS,
keylog = false,
verifyClient = true,
verifyClient = false,
tlsTrace = false,
verifyPrivateKey = true,
verifyPrivateKey = false,
keys,
certs,
ca,
Expand Down Expand Up @@ -538,7 +538,7 @@ function processTlsOptions(tls) {
class QuicStream {
/** @type {object} */
#handle;
/** @type {Session} */
/** @type {QuicSession} */
#session;
/** @type {QuicStreamStats} */
#stats;
Expand All @@ -560,7 +560,7 @@ class QuicStream {
/**
* @param {StreamCallbackConfiguration} config
* @param {object} handle
* @param {Session} session
* @param {QuicSession} session
*/
constructor(config, handle, session, direction) {
validateObject(config, 'config');
Expand Down Expand Up @@ -607,7 +607,7 @@ class QuicStream {
/** @type {QuicStreamState} */
get state() { return this.#state; }

/** @type {Session} */
/** @type {QuicSession} */
get session() { return this.#session; }

/** @type {bigint} */
Expand Down Expand Up @@ -657,8 +657,8 @@ class QuicStream {
}
}

class Session {
/** @type {Endpoint} */
class QuicSession {
/** @type {QuicEndpoint} */
#endpoint = undefined;
/** @type {boolean} */
#isPendingClose = false;
Expand Down Expand Up @@ -695,7 +695,7 @@ class Session {
* @param {SessionCallbackConfiguration} config
* @param {StreamCallbackConfiguration} streamConfig
* @param {object} [handle]
* @param {Endpoint} [endpoint]
* @param {QuicEndpoint} [endpoint]
*/
constructor(config, streamConfig, handle, endpoint) {
validateObject(config, 'config');
Expand Down Expand Up @@ -753,7 +753,7 @@ class Session {
/** @type {QuicSessionState} */
get state() { return this.#state; }

/** @type {Endpoint} */
/** @type {QuicEndpoint} */
get endpoint() { return this.#endpoint; }

/** @type {Path} */
Expand Down Expand Up @@ -976,7 +976,7 @@ class Session {
depth: options.depth == null ? null : options.depth - 1,
};

return `Session ${inspect({
return `QuicSession ${inspect({
closed: this.closed,
closing: this.#isPendingClose,
destroyed: this.destroyed,
Expand Down Expand Up @@ -1039,7 +1039,7 @@ function validateEndpointConfig(config) {
return config;
}

class Endpoint {
class QuicEndpoint {
/** @type {SocketAddress|undefined} */
#address = undefined;
/** @type {boolean} */
Expand All @@ -1054,7 +1054,7 @@ class Endpoint {
#pendingClose;
/** @type {any} */
#pendingError = undefined;
/** @type {Session[]} */
/** @type {QuicSession[]} */
#sessions = [];
/** @type {QuicEndpointState} */
#state;
Expand Down Expand Up @@ -1235,7 +1235,7 @@ class Endpoint {
* Initiates a session with a remote endpoint.
* @param {SocketAddress} address
* @param {SessionOptions} [options]
* @returns {Session}
* @returns {QuicSession}
*/
connect(address, options = kEmptyObject) {
if (this.#isClosedOrClosing) {
Expand Down Expand Up @@ -1278,7 +1278,7 @@ class Endpoint {
if (handle === undefined) {
throw new ERR_QUIC_CONNECTION_FAILED();
}
const session = new Session(this.#sessionConfig, this.#streamConfig, handle, this);
const session = new QuicSession(this.#sessionConfig, this.#streamConfig, handle, this);
ArrayPrototypePush(this.#sessions, session);
return session;
}
Expand Down Expand Up @@ -1393,7 +1393,7 @@ class Endpoint {
}

[kNewSession](handle) {
const session = new Session(this.#sessionConfig, this.#streamConfig, handle, this);
const session = new QuicSession(this.#sessionConfig, this.#streamConfig, handle, this);
ArrayPrototypePush(this.#sessions, session);
this.#onsession(session, this);
}
Expand All @@ -1409,7 +1409,7 @@ class Endpoint {
depth: options.depth == null ? null : options.depth - 1,
};

return `Endpoint ${inspect({
return `QuicEndpoint ${inspect({
address: this.address,
busy: this.busy,
closed: this.closed,
Expand All @@ -1423,7 +1423,7 @@ class Endpoint {
}
};

ObjectDefineProperties(Endpoint, {
ObjectDefineProperties(QuicEndpoint, {
CC_ALGO_RENO: {
__proto__: null,
value: CC_ALGO_RENO,
Expand Down Expand Up @@ -1467,7 +1467,7 @@ ObjectDefineProperties(Endpoint, {
enumerable: true,
},
});
ObjectDefineProperties(Session, {
ObjectDefineProperties(QuicSession, {
DEFAULT_CIPHERS: {
__proto__: null,
value: DEFAULT_CIPHERS,
Expand All @@ -1485,8 +1485,8 @@ ObjectDefineProperties(Session, {
});

module.exports = {
Endpoint,
Session,
QuicEndpoint,
QuicSession,
QuicStream,
QuicSessionState,
QuicSessionStats,
Expand Down
3 changes: 3 additions & 0 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
#endif // !HAVE_OPENSSL
#if !NODE_OPENSSL_HAS_QUIC
"internal/quic/quic",
"internal/quic/symbols",
"internal/quic/stats",
"internal/quic/state",
#endif // !NODE_OPENSSL_HAS_QUIC
"sqlite", // Experimental.
"sys", // Deprecated.
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-quic-internal-endpoint-listen-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('quic internal endpoint listen defaults', { skip: !hasQuic }, async ()
} = require('net');

const {
Endpoint,
QuicEndpoint,
} = require('internal/quic/quic');

it('are reasonable and work as expected', async () => {
const endpoint = new Endpoint({
const endpoint = new QuicEndpoint({
onsession() {},
session: {},
stream: {},
Expand Down
34 changes: 17 additions & 17 deletions test/parallel/test-quic-internal-endpoint-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
} = require('node:assert');

const {
Endpoint,
QuicEndpoint,
} = require('internal/quic/quic');

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

it('invalid options', async () => {
['a', null, false, NaN].forEach((i) => {
throws(() => new Endpoint(callbackConfig, i), {
throws(() => new QuicEndpoint(callbackConfig, i), {
code: 'ERR_INVALID_ARG_TYPE',
});
});
});

it('valid options', async () => {
// Just Works... using all defaults
new Endpoint(callbackConfig, {});
new Endpoint(callbackConfig);
new Endpoint(callbackConfig, undefined);
new QuicEndpoint(callbackConfig, {});
new QuicEndpoint(callbackConfig);
new QuicEndpoint(callbackConfig, undefined);
});

it('various cases', async () => {
Expand Down Expand Up @@ -126,12 +126,12 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
{
key: 'cc',
valid: [
Endpoint.CC_ALGO_RENO,
Endpoint.CC_ALGO_CUBIC,
Endpoint.CC_ALGO_BBR,
Endpoint.CC_ALGO_RENO_STR,
Endpoint.CC_ALGO_CUBIC_STR,
Endpoint.CC_ALGO_BBR_STR,
QuicEndpoint.CC_ALGO_RENO,
QuicEndpoint.CC_ALGO_CUBIC,
QuicEndpoint.CC_ALGO_BBR,
QuicEndpoint.CC_ALGO_RENO_STR,
QuicEndpoint.CC_ALGO_CUBIC_STR,
QuicEndpoint.CC_ALGO_BBR_STR,
],
invalid: [-1, 4, 1n, 'a', null, false, true, {}, [], () => {}],
},
Expand Down Expand Up @@ -190,39 +190,39 @@ describe('quic internal endpoint options', { skip: !hasQuic }, async () => {
for (const value of valid) {
const options = {};
options[key] = value;
new Endpoint(callbackConfig, options);
new QuicEndpoint(callbackConfig, options);
}

for (const value of invalid) {
const options = {};
options[key] = value;
throws(() => new Endpoint(callbackConfig, options), {
throws(() => new QuicEndpoint(callbackConfig, options), {
code: 'ERR_INVALID_ARG_VALUE',
});
}
}
});

it('endpoint can be ref/unrefed without error', async () => {
const endpoint = new Endpoint(callbackConfig, {});
const endpoint = new QuicEndpoint(callbackConfig, {});
endpoint.unref();
endpoint.ref();
endpoint.close();
await endpoint.closed;
});

it('endpoint can be inspected', async () => {
const endpoint = new Endpoint(callbackConfig, {});
const endpoint = new QuicEndpoint(callbackConfig, {});
strictEqual(typeof inspect(endpoint), 'string');
endpoint.close();
await endpoint.closed;
});

it('endpoint with object address', () => {
new Endpoint(callbackConfig, {
new QuicEndpoint(callbackConfig, {
address: { host: '127.0.0.1:0' },
});
throws(() => new Endpoint(callbackConfig, { address: '127.0.0.1:0' }), {
throws(() => new QuicEndpoint(callbackConfig, { address: '127.0.0.1:0' }), {
code: 'ERR_INVALID_ARG_TYPE',
});
});
Expand Down
Loading

0 comments on commit fd7b4ea

Please sign in to comment.