Skip to content

Commit

Permalink
quic: make multiple fixes, cleanups and simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Dec 20, 2024
1 parent 5471883 commit bfaf60f
Show file tree
Hide file tree
Showing 26 changed files with 3,047 additions and 2,571 deletions.
397 changes: 145 additions & 252 deletions doc/api/quic.md

Large diffs are not rendered by default.

305 changes: 181 additions & 124 deletions lib/internal/quic/quic.js

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions lib/internal/quic/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const {
kFinishClose,
kInspect,
kPrivateConstructor,
kWantsHeaders,
kWantsTrailers,
} = require('internal/quic/symbols');

// This file defines the helper objects for accessing state for
Expand All @@ -47,7 +49,6 @@ const {
IDX_STATE_SESSION_GRACEFUL_CLOSE,
IDX_STATE_SESSION_SILENT_CLOSE,
IDX_STATE_SESSION_STATELESS_RESET,
IDX_STATE_SESSION_DESTROYED,
IDX_STATE_SESSION_HANDSHAKE_COMPLETED,
IDX_STATE_SESSION_HANDSHAKE_CONFIRMED,
IDX_STATE_SESSION_STREAM_OPEN_ALLOWED,
Expand All @@ -70,6 +71,7 @@ const {
IDX_STATE_STREAM_WRITE_ENDED,
IDX_STATE_STREAM_PAUSED,
IDX_STATE_STREAM_RESET,
IDX_STATE_STREAM_HAS_OUTBOUND,
IDX_STATE_STREAM_HAS_READER,
IDX_STATE_STREAM_WANTS_BLOCK,
IDX_STATE_STREAM_WANTS_HEADERS,
Expand All @@ -85,7 +87,6 @@ assert(IDX_STATE_SESSION_CLOSING !== undefined);
assert(IDX_STATE_SESSION_GRACEFUL_CLOSE !== undefined);
assert(IDX_STATE_SESSION_SILENT_CLOSE !== undefined);
assert(IDX_STATE_SESSION_STATELESS_RESET !== undefined);
assert(IDX_STATE_SESSION_DESTROYED !== undefined);
assert(IDX_STATE_SESSION_HANDSHAKE_COMPLETED !== undefined);
assert(IDX_STATE_SESSION_HANDSHAKE_CONFIRMED !== undefined);
assert(IDX_STATE_SESSION_STREAM_OPEN_ALLOWED !== undefined);
Expand All @@ -106,6 +107,7 @@ assert(IDX_STATE_STREAM_READ_ENDED !== undefined);
assert(IDX_STATE_STREAM_WRITE_ENDED !== undefined);
assert(IDX_STATE_STREAM_PAUSED !== undefined);
assert(IDX_STATE_STREAM_RESET !== undefined);
assert(IDX_STATE_STREAM_HAS_OUTBOUND !== undefined);
assert(IDX_STATE_STREAM_HAS_READER !== undefined);
assert(IDX_STATE_STREAM_WANTS_BLOCK !== undefined);
assert(IDX_STATE_STREAM_WANTS_HEADERS !== undefined);
Expand Down Expand Up @@ -309,12 +311,6 @@ class QuicSessionState {
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_SESSION_STATELESS_RESET);
}

/** @type {boolean} */
get isDestroyed() {
if (this.#handle.byteLength === 0) return undefined;
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_SESSION_DESTROYED);
}

/** @type {boolean} */
get isHandshakeCompleted() {
if (this.#handle.byteLength === 0) return undefined;
Expand Down Expand Up @@ -483,6 +479,12 @@ class QuicStreamState {
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_STREAM_RESET);
}

/** @type {boolean} */
get hasOutbound() {
if (this.#handle.byteLength === 0) return undefined;
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_STREAM_HAS_OUTBOUND);
}

/** @type {boolean} */
get hasReader() {
if (this.#handle.byteLength === 0) return undefined;
Expand All @@ -502,13 +504,13 @@ class QuicStreamState {
}

/** @type {boolean} */
get wantsHeaders() {
get [kWantsHeaders]() {
if (this.#handle.byteLength === 0) return undefined;
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_STREAM_WANTS_HEADERS);
}

/** @type {boolean} */
set wantsHeaders(val) {
set [kWantsHeaders](val) {
if (this.#handle.byteLength === 0) return;
DataViewPrototypeSetUint8(this.#handle, IDX_STATE_STREAM_WANTS_HEADERS, val ? 1 : 0);
}
Expand All @@ -526,13 +528,13 @@ class QuicStreamState {
}

/** @type {boolean} */
get wantsTrailers() {
get [kWantsTrailers]() {
if (this.#handle.byteLength === 0) return undefined;
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_STREAM_WANTS_TRAILERS);
}

/** @type {boolean} */
set wantsTrailers(val) {
set [kWantsTrailers](val) {
if (this.#handle.byteLength === 0) return;
DataViewPrototypeSetUint8(this.#handle, IDX_STATE_STREAM_WANTS_TRAILERS, val ? 1 : 0);
}
Expand All @@ -553,11 +555,10 @@ class QuicStreamState {
writeEnded: this.writeEnded,
paused: this.paused,
reset: this.reset,
hasOutbound: this.hasOutbound,
hasReader: this.hasReader,
wantsBlock: this.wantsBlock,
wantsHeaders: this.wantsHeaders,
wantsReset: this.wantsReset,
wantsTrailers: this.wantsTrailers,
};
}

Expand All @@ -583,11 +584,10 @@ class QuicStreamState {
writeEnded: this.writeEnded,
paused: this.paused,
reset: this.reset,
hasOutbound: this.hasOutbound,
hasReader: this.hasReader,
wantsBlock: this.wantsBlock,
wantsHeaders: this.wantsHeaders,
wantsReset: this.wantsReset,
wantsTrailers: this.wantsTrailers,
}, opts)}`;
}

Expand Down
23 changes: 0 additions & 23 deletions lib/internal/quic/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ const {

IDX_STATS_SESSION_CREATED_AT,
IDX_STATS_SESSION_CLOSING_AT,
IDX_STATS_SESSION_DESTROYED_AT,
IDX_STATS_SESSION_HANDSHAKE_COMPLETED_AT,
IDX_STATS_SESSION_HANDSHAKE_CONFIRMED_AT,
IDX_STATS_SESSION_GRACEFUL_CLOSING_AT,
IDX_STATS_SESSION_BYTES_RECEIVED,
IDX_STATS_SESSION_BYTES_SENT,
IDX_STATS_SESSION_BIDI_IN_STREAM_COUNT,
IDX_STATS_SESSION_BIDI_OUT_STREAM_COUNT,
IDX_STATS_SESSION_UNI_IN_STREAM_COUNT,
IDX_STATS_SESSION_UNI_OUT_STREAM_COUNT,
IDX_STATS_SESSION_LOSS_RETRANSMIT_COUNT,
IDX_STATS_SESSION_MAX_BYTES_IN_FLIGHT,
IDX_STATS_SESSION_BYTES_IN_FLIGHT,
IDX_STATS_SESSION_BLOCK_COUNT,
Expand Down Expand Up @@ -104,17 +101,14 @@ assert(IDX_STATS_ENDPOINT_STATELESS_RESET_COUNT !== undefined);
assert(IDX_STATS_ENDPOINT_IMMEDIATE_CLOSE_COUNT !== undefined);
assert(IDX_STATS_SESSION_CREATED_AT !== undefined);
assert(IDX_STATS_SESSION_CLOSING_AT !== undefined);
assert(IDX_STATS_SESSION_DESTROYED_AT !== undefined);
assert(IDX_STATS_SESSION_HANDSHAKE_COMPLETED_AT !== undefined);
assert(IDX_STATS_SESSION_HANDSHAKE_CONFIRMED_AT !== undefined);
assert(IDX_STATS_SESSION_GRACEFUL_CLOSING_AT !== undefined);
assert(IDX_STATS_SESSION_BYTES_RECEIVED !== undefined);
assert(IDX_STATS_SESSION_BYTES_SENT !== undefined);
assert(IDX_STATS_SESSION_BIDI_IN_STREAM_COUNT !== undefined);
assert(IDX_STATS_SESSION_BIDI_OUT_STREAM_COUNT !== undefined);
assert(IDX_STATS_SESSION_UNI_IN_STREAM_COUNT !== undefined);
assert(IDX_STATS_SESSION_UNI_OUT_STREAM_COUNT !== undefined);
assert(IDX_STATS_SESSION_LOSS_RETRANSMIT_COUNT !== undefined);
assert(IDX_STATS_SESSION_MAX_BYTES_IN_FLIGHT !== undefined);
assert(IDX_STATS_SESSION_BYTES_IN_FLIGHT !== undefined);
assert(IDX_STATS_SESSION_BLOCK_COUNT !== undefined);
Expand Down Expand Up @@ -330,11 +324,6 @@ class QuicSessionStats {
return this.#handle[IDX_STATS_SESSION_CLOSING_AT];
}

/** @type {bigint} */
get destroyedAt() {
return this.#handle[IDX_STATS_SESSION_DESTROYED_AT];
}

/** @type {bigint} */
get handshakeCompletedAt() {
return this.#handle[IDX_STATS_SESSION_HANDSHAKE_COMPLETED_AT];
Expand All @@ -345,11 +334,6 @@ class QuicSessionStats {
return this.#handle[IDX_STATS_SESSION_HANDSHAKE_CONFIRMED_AT];
}

/** @type {bigint} */
get gracefulClosingAt() {
return this.#handle[IDX_STATS_SESSION_GRACEFUL_CLOSING_AT];
}

/** @type {bigint} */
get bytesReceived() {
return this.#handle[IDX_STATS_SESSION_BYTES_RECEIVED];
Expand Down Expand Up @@ -380,11 +364,6 @@ class QuicSessionStats {
return this.#handle[IDX_STATS_SESSION_UNI_OUT_STREAM_COUNT];
}

/** @type {bigint} */
get lossRetransmitCount() {
return this.#handle[IDX_STATS_SESSION_LOSS_RETRANSMIT_COUNT];
}

/** @type {bigint} */
get maxBytesInFlights() {
return this.#handle[IDX_STATS_SESSION_MAX_BYTES_IN_FLIGHT];
Expand Down Expand Up @@ -472,7 +451,6 @@ class QuicSessionStats {
bidiOutStreamCount: `${this.bidiOutStreamCount}`,
uniInStreamCount: `${this.uniInStreamCount}`,
uniOutStreamCount: `${this.uniOutStreamCount}`,
lossRetransmitCount: `${this.lossRetransmitCount}`,
maxBytesInFlights: `${this.maxBytesInFlights}`,
bytesInFlight: `${this.bytesInFlight}`,
blockCount: `${this.blockCount}`,
Expand Down Expand Up @@ -512,7 +490,6 @@ class QuicSessionStats {
bidiOutStreamCount: this.bidiOutStreamCount,
uniInStreamCount: this.uniInStreamCount,
uniOutStreamCount: this.uniOutStreamCount,
lossRetransmitCount: this.lossRetransmitCount,
maxBytesInFlights: this.maxBytesInFlights,
bytesInFlight: this.bytesInFlight,
blockCount: this.blockCount,
Expand Down
34 changes: 23 additions & 11 deletions lib/internal/quic/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,55 @@ const {
// Symbols used to hide various private properties and methods from the
// public API.

const kApplicationProvider = Symbol('kApplicationProvider');
const kBlocked = Symbol('kBlocked');
const kDatagram = Symbol('kDatagram');
const kDatagramStatus = Symbol('kDatagramStatus');
const kFinishClose = Symbol('kFinishClose');
const kHandshake = Symbol('kHandshake');
const kHeaders = Symbol('kHeaders');
const kOwner = Symbol('kOwner');
const kRemoveSession = Symbol('kRemoveSession');
const kNewSession = Symbol('kNewSession');
const kRemoveStream = Symbol('kRemoveStream');
const kNewStream = Symbol('kNewStream');
const kOnHeaders = Symbol('kOnHeaders');
const kOnTrailers = Symbol('kOwnTrailers');
const kOwner = Symbol('kOwner');
const kPathValidation = Symbol('kPathValidation');
const kPrivateConstructor = Symbol('kPrivateConstructor');
const kRemoveSession = Symbol('kRemoveSession');
const kRemoveStream = Symbol('kRemoveStream');
const kReset = Symbol('kReset');
const kSendHeaders = Symbol('kSendHeaders');
const kSessionTicket = Symbol('kSessionTicket');
const kTrailers = Symbol('kTrailers');
const kVersionNegotiation = Symbol('kVersionNegotiation');
const kPrivateConstructor = Symbol('kPrivateConstructor');
const kWantsHeaders = Symbol('kWantsHeaders');
const kWantsTrailers = Symbol('kWantsTrailers');

module.exports = {
kApplicationProvider,
kBlocked,
kDatagram,
kDatagramStatus,
kFinishClose,
kHandshake,
kHeaders,
kOwner,
kRemoveSession,
kInspect,
kKeyObjectHandle,
kKeyObjectInner,
kNewSession,
kRemoveStream,
kNewStream,
kOnHeaders,
kOnTrailers,
kOwner,
kPathValidation,
kPrivateConstructor,
kRemoveSession,
kRemoveStream,
kReset,
kSendHeaders,
kSessionTicket,
kTrailers,
kVersionNegotiation,
kInspect,
kKeyObjectHandle,
kKeyObjectInner,
kPrivateConstructor,
kWantsHeaders,
kWantsTrailers,
};
5 changes: 5 additions & 0 deletions lib/quic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

const {
emitExperimentalWarning,
} = require('internal/util');
emitExperimentalWarning('quic');

const {
QuicEndpoint,
QuicSession,
Expand Down
Loading

0 comments on commit bfaf60f

Please sign in to comment.