mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
quic: improve the quic js structure
* Adds invalid this protections in the stats classes * Collects internal private fields into a single private symbol to reduce the number of private field accesses * Adds and corrects isQuic* class checks * Preserve stream id and direction after destroy * Improve stats close snapshotting * Fixes a handful of other bugs and doc issues Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode:Opus 4.6 PR-URL: https://github.com/nodejs/node/pull/63267 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
0045dc30b6
commit
378dbf00e9
10 files changed
+1549
-1114
No files matched your search
@@ -178,6 +178,12 @@ function handleErrorFromBinding(error) {
|
||||
}
|
||||
|
||||
class FileHandle extends EventEmitter {
|
||||
#brandCheck = undefined;
|
||||
|
||||
static isFileHandle(value) {
|
||||
return (value != null && typeof value === 'object' && #brandCheck in value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InternalFSBinding.FileHandle | undefined} filehandle
|
||||
*/
|
||||
|
||||
+739
-694
File diff suppressed because it is too large.
Load diff
+400
-233
@@ -5,7 +5,6 @@
|
||||
/* c8 ignore start */
|
||||
|
||||
const {
|
||||
ArrayBuffer,
|
||||
DataView,
|
||||
DataViewPrototypeGetBigInt64,
|
||||
DataViewPrototypeGetBigUint64,
|
||||
@@ -16,21 +15,15 @@ const {
|
||||
DataViewPrototypeSetUint16,
|
||||
DataViewPrototypeSetUint32,
|
||||
DataViewPrototypeSetUint8,
|
||||
Float32Array,
|
||||
JSONStringify,
|
||||
Uint8Array,
|
||||
Number,
|
||||
} = primordials;
|
||||
|
||||
// Determine native byte order. The shared state buffer is written by
|
||||
// C++ in native byte order, so DataView reads must match.
|
||||
const kIsLittleEndian = (() => {
|
||||
// -1 as float32 is 0xBF800000. On little-endian, the bytes are
|
||||
// [0x00, 0x00, 0x80, 0xBF], so byte[3] is 0xBF (non-zero).
|
||||
// On big-endian, the bytes are [0xBF, 0x80, 0x00, 0x00], so byte[3] is 0.
|
||||
const buf = new Float32Array(1);
|
||||
buf[0] = -1;
|
||||
return new Uint8Array(buf.buffer)[3] !== 0;
|
||||
})();
|
||||
const {
|
||||
isBigEndian,
|
||||
} = internalBinding('os');
|
||||
|
||||
const kIsLittleEndian = !isBigEndian;
|
||||
|
||||
const {
|
||||
getOptionValue,
|
||||
@@ -58,8 +51,6 @@ const {
|
||||
kFinishClose,
|
||||
kInspect,
|
||||
kPrivateConstructor,
|
||||
kWantsHeaders,
|
||||
kWantsTrailers,
|
||||
} = require('internal/quic/symbols');
|
||||
|
||||
// This file defines the helper objects for accessing state for
|
||||
@@ -155,6 +146,11 @@ assert(IDX_STATE_STREAM_WANTS_TRAILERS !== undefined);
|
||||
assert(IDX_STATE_STREAM_WRITE_DESIRED_SIZE !== undefined);
|
||||
assert(IDX_STATE_STREAM_RESET_CODE !== undefined);
|
||||
|
||||
const kEmptyObject = { __proto__: null };
|
||||
|
||||
// The internal state objects for endpoints, sessions, and streams.
|
||||
// These are not exposed directly to users.
|
||||
|
||||
class QuicEndpointState {
|
||||
/** @type {DataView} */
|
||||
#handle;
|
||||
@@ -175,58 +171,67 @@ class QuicEndpointState {
|
||||
|
||||
/** @type {boolean} */
|
||||
get isBound() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_ENDPOINT_BOUND);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, IDX_STATE_ENDPOINT_BOUND) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isReceiving() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_ENDPOINT_RECEIVING);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, IDX_STATE_ENDPOINT_RECEIVING) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isListening() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_ENDPOINT_LISTENING);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, IDX_STATE_ENDPOINT_LISTENING) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isClosing() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_ENDPOINT_CLOSING);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, IDX_STATE_ENDPOINT_CLOSING) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isBusy() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, IDX_STATE_ENDPOINT_BUSY);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, IDX_STATE_ENDPOINT_BUSY) !== 0;
|
||||
}
|
||||
|
||||
/** @type {number} */
|
||||
get maxConnectionsPerHost() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint16(
|
||||
this.#handle, IDX_STATE_ENDPOINT_MAX_CONNECTIONS_PER_HOST, kIsLittleEndian);
|
||||
handle, IDX_STATE_ENDPOINT_MAX_CONNECTIONS_PER_HOST, kIsLittleEndian);
|
||||
}
|
||||
|
||||
set maxConnectionsPerHost(val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint16(
|
||||
this.#handle, IDX_STATE_ENDPOINT_MAX_CONNECTIONS_PER_HOST, val, kIsLittleEndian);
|
||||
handle, IDX_STATE_ENDPOINT_MAX_CONNECTIONS_PER_HOST, val, kIsLittleEndian);
|
||||
}
|
||||
|
||||
/** @type {number} */
|
||||
get maxConnectionsTotal() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint16(
|
||||
this.#handle, IDX_STATE_ENDPOINT_MAX_CONNECTIONS_TOTAL, kIsLittleEndian);
|
||||
handle, IDX_STATE_ENDPOINT_MAX_CONNECTIONS_TOTAL, kIsLittleEndian);
|
||||
}
|
||||
|
||||
set maxConnectionsTotal(val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint16(
|
||||
this.#handle, IDX_STATE_ENDPOINT_MAX_CONNECTIONS_TOTAL, val, kIsLittleEndian);
|
||||
handle, IDX_STATE_ENDPOINT_MAX_CONNECTIONS_TOTAL, val, kIsLittleEndian);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,8 +241,9 @@ class QuicEndpointState {
|
||||
* @type {bigint}
|
||||
*/
|
||||
get pendingCallbacks() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return DataViewPrototypeGetBigUint64(this.#handle, IDX_STATE_ENDPOINT_PENDING_CALLBACKS, kIsLittleEndian);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetBigUint64(handle, IDX_STATE_ENDPOINT_PENDING_CALLBACKS, kIsLittleEndian);
|
||||
}
|
||||
|
||||
toString() {
|
||||
@@ -245,49 +251,70 @@ class QuicEndpointState {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return {};
|
||||
if (this.#handle === undefined) return kEmptyObject;
|
||||
const {
|
||||
isBound,
|
||||
isReceiving,
|
||||
isListening,
|
||||
isClosing,
|
||||
isBusy,
|
||||
maxConnectionsPerHost,
|
||||
maxConnectionsTotal,
|
||||
pendingCallbacks,
|
||||
} = this;
|
||||
return {
|
||||
__proto__: null,
|
||||
isBound: this.isBound,
|
||||
isReceiving: this.isReceiving,
|
||||
isListening: this.isListening,
|
||||
isClosing: this.isClosing,
|
||||
isBusy: this.isBusy,
|
||||
maxConnectionsPerHost: this.maxConnectionsPerHost,
|
||||
maxConnectionsTotal: this.maxConnectionsTotal,
|
||||
pendingCallbacks: `${this.pendingCallbacks}`,
|
||||
isBound,
|
||||
isReceiving,
|
||||
isListening,
|
||||
isClosing,
|
||||
isBusy,
|
||||
maxConnectionsPerHost,
|
||||
maxConnectionsTotal,
|
||||
pendingCallbacks: Number(pendingCallbacks),
|
||||
};
|
||||
}
|
||||
|
||||
[kInspect](depth, options) {
|
||||
if (depth < 0)
|
||||
return this;
|
||||
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) {
|
||||
if (this.#handle === undefined) {
|
||||
return 'QuicEndpointState { <Closed> }';
|
||||
}
|
||||
|
||||
if (depth < 0) {
|
||||
return 'QuicEndpointState { }';
|
||||
}
|
||||
|
||||
const opts = {
|
||||
__proto__: null,
|
||||
...options,
|
||||
depth: options.depth == null ? null : options.depth - 1,
|
||||
};
|
||||
|
||||
const {
|
||||
isBound,
|
||||
isReceiving,
|
||||
isListening,
|
||||
isClosing,
|
||||
isBusy,
|
||||
maxConnectionsPerHost,
|
||||
maxConnectionsTotal,
|
||||
pendingCallbacks,
|
||||
} = this;
|
||||
|
||||
return `QuicEndpointState ${inspect({
|
||||
isBound: this.isBound,
|
||||
isReceiving: this.isReceiving,
|
||||
isListening: this.isListening,
|
||||
isClosing: this.isClosing,
|
||||
isBusy: this.isBusy,
|
||||
pendingCallbacks: this.pendingCallbacks,
|
||||
isBound,
|
||||
isReceiving,
|
||||
isListening,
|
||||
isClosing,
|
||||
isBusy,
|
||||
maxConnectionsPerHost,
|
||||
maxConnectionsTotal,
|
||||
pendingCallbacks,
|
||||
}, opts)}`;
|
||||
}
|
||||
|
||||
[kFinishClose]() {
|
||||
// Snapshot the state into a new DataView since the underlying
|
||||
// buffer will be destroyed.
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
this.#handle = new DataView(new ArrayBuffer(0));
|
||||
this.#handle = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,17 +351,19 @@ class QuicSessionState {
|
||||
static #LISTENER_ORIGIN = 1 << 5;
|
||||
|
||||
#getListenerFlag(flag) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!(DataViewPrototypeGetUint32(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_LISTENER_FLAGS, kIsLittleEndian) & flag);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return (DataViewPrototypeGetUint32(
|
||||
handle, this.#offset + IDX_STATE_SESSION_LISTENER_FLAGS, kIsLittleEndian) & flag) !== 0;
|
||||
}
|
||||
|
||||
#setListenerFlag(flag, val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
const current = DataViewPrototypeGetUint32(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_LISTENER_FLAGS, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_SESSION_LISTENER_FLAGS, kIsLittleEndian);
|
||||
DataViewPrototypeSetUint32(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_LISTENER_FLAGS,
|
||||
handle, this.#offset + IDX_STATE_SESSION_LISTENER_FLAGS,
|
||||
val ? (current | flag) : (current & ~flag), kIsLittleEndian);
|
||||
}
|
||||
|
||||
@@ -388,50 +417,58 @@ class QuicSessionState {
|
||||
|
||||
/** @type {boolean} */
|
||||
get isClosing() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_CLOSING);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_CLOSING) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isGracefulClose() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_GRACEFUL_CLOSE);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_GRACEFUL_CLOSE) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isSilentClose() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_SILENT_CLOSE);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_SILENT_CLOSE) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isStatelessReset() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_STATELESS_RESET);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_STATELESS_RESET) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isHandshakeCompleted() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_HANDSHAKE_COMPLETED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_HANDSHAKE_COMPLETED) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isHandshakeConfirmed() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_HANDSHAKE_CONFIRMED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_HANDSHAKE_CONFIRMED) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isStreamOpenAllowed() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_STREAM_OPEN_ALLOWED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_STREAM_OPEN_ALLOWED) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isPrioritySupported() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_PRIORITY_SUPPORTED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_PRIORITY_SUPPORTED) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -440,20 +477,23 @@ class QuicSessionState {
|
||||
* @type {number}
|
||||
*/
|
||||
get headersSupported() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_HEADERS_SUPPORTED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_HEADERS_SUPPORTED);
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get isWrapped() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_WRAPPED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_WRAPPED) !== 0;
|
||||
}
|
||||
|
||||
/** @type {number} */
|
||||
get applicationType() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_SESSION_APPLICATION_TYPE);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_SESSION_APPLICATION_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,9 +504,10 @@ class QuicSessionState {
|
||||
* @type {bigint}
|
||||
*/
|
||||
get noErrorCode() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetBigUint64(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_NO_ERROR_CODE, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_SESSION_NO_ERROR_CODE, kIsLittleEndian);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,38 +520,43 @@ class QuicSessionState {
|
||||
* @type {bigint}
|
||||
*/
|
||||
get internalErrorCode() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetBigUint64(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_INTERNAL_ERROR_CODE, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_SESSION_INTERNAL_ERROR_CODE, kIsLittleEndian);
|
||||
}
|
||||
|
||||
/** @type {number} */
|
||||
get maxDatagramSize() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint16(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_MAX_DATAGRAM_SIZE,
|
||||
handle, this.#offset + IDX_STATE_SESSION_MAX_DATAGRAM_SIZE,
|
||||
kIsLittleEndian);
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get lastDatagramId() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetBigUint64(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_LAST_DATAGRAM_ID,
|
||||
handle, this.#offset + IDX_STATE_SESSION_LAST_DATAGRAM_ID,
|
||||
kIsLittleEndian);
|
||||
}
|
||||
|
||||
/** @type {number} */
|
||||
get maxPendingDatagrams() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint16(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_MAX_PENDING_DATAGRAMS, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_SESSION_MAX_PENDING_DATAGRAMS, kIsLittleEndian);
|
||||
}
|
||||
|
||||
set maxPendingDatagrams(val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint16(
|
||||
this.#handle, this.#offset + IDX_STATE_SESSION_MAX_PENDING_DATAGRAMS, val, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_SESSION_MAX_PENDING_DATAGRAMS, val, kIsLittleEndian);
|
||||
}
|
||||
|
||||
toString() {
|
||||
@@ -518,78 +564,126 @@ class QuicSessionState {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return {};
|
||||
if (this.#handle === undefined) return kEmptyObject;
|
||||
const {
|
||||
hasPathValidationListener,
|
||||
hasDatagramListener,
|
||||
hasDatagramStatusListener,
|
||||
hasSessionTicketListener,
|
||||
hasNewTokenListener,
|
||||
hasOriginListener,
|
||||
isClosing,
|
||||
isGracefulClose,
|
||||
isSilentClose,
|
||||
isStatelessReset,
|
||||
isHandshakeCompleted,
|
||||
isHandshakeConfirmed,
|
||||
isStreamOpenAllowed,
|
||||
isPrioritySupported,
|
||||
headersSupported,
|
||||
isWrapped,
|
||||
applicationType,
|
||||
noErrorCode,
|
||||
internalErrorCode,
|
||||
maxDatagramSize,
|
||||
lastDatagramId,
|
||||
maxPendingDatagrams,
|
||||
} = this;
|
||||
return {
|
||||
__proto__: null,
|
||||
hasPathValidationListener: this.hasPathValidationListener,
|
||||
hasDatagramListener: this.hasDatagramListener,
|
||||
hasDatagramStatusListener: this.hasDatagramStatusListener,
|
||||
hasSessionTicketListener: this.hasSessionTicketListener,
|
||||
hasNewTokenListener: this.hasNewTokenListener,
|
||||
hasOriginListener: this.hasOriginListener,
|
||||
isClosing: this.isClosing,
|
||||
isGracefulClose: this.isGracefulClose,
|
||||
isSilentClose: this.isSilentClose,
|
||||
isStatelessReset: this.isStatelessReset,
|
||||
isHandshakeCompleted: this.isHandshakeCompleted,
|
||||
isHandshakeConfirmed: this.isHandshakeConfirmed,
|
||||
isStreamOpenAllowed: this.isStreamOpenAllowed,
|
||||
isPrioritySupported: this.isPrioritySupported,
|
||||
headersSupported: this.headersSupported,
|
||||
isWrapped: this.isWrapped,
|
||||
applicationType: this.applicationType,
|
||||
noErrorCode: `${this.noErrorCode}`,
|
||||
internalErrorCode: `${this.internalErrorCode}`,
|
||||
maxDatagramSize: `${this.maxDatagramSize}`,
|
||||
lastDatagramId: `${this.lastDatagramId}`,
|
||||
maxPendingDatagrams: this.maxPendingDatagrams,
|
||||
hasPathValidationListener,
|
||||
hasDatagramListener,
|
||||
hasDatagramStatusListener,
|
||||
hasSessionTicketListener,
|
||||
hasNewTokenListener,
|
||||
hasOriginListener,
|
||||
isClosing,
|
||||
isGracefulClose,
|
||||
isSilentClose,
|
||||
isStatelessReset,
|
||||
isHandshakeCompleted,
|
||||
isHandshakeConfirmed,
|
||||
isStreamOpenAllowed,
|
||||
isPrioritySupported,
|
||||
headersSupported,
|
||||
isWrapped,
|
||||
applicationType,
|
||||
noErrorCode: `${noErrorCode}`,
|
||||
internalErrorCode: `${internalErrorCode}`,
|
||||
maxDatagramSize: `${maxDatagramSize}`,
|
||||
lastDatagramId: `${lastDatagramId}`,
|
||||
maxPendingDatagrams,
|
||||
};
|
||||
}
|
||||
|
||||
[kInspect](depth, options) {
|
||||
if (depth < 0)
|
||||
return this;
|
||||
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) {
|
||||
if (this.#handle === undefined) {
|
||||
return 'QuicSessionState { <Closed> }';
|
||||
}
|
||||
|
||||
if (depth < 0) {
|
||||
return 'QuicSessionState { }';
|
||||
}
|
||||
|
||||
const opts = {
|
||||
__proto__: null,
|
||||
...options,
|
||||
depth: options.depth == null ? null : options.depth - 1,
|
||||
};
|
||||
|
||||
const {
|
||||
hasPathValidationListener,
|
||||
hasDatagramListener,
|
||||
hasDatagramStatusListener,
|
||||
hasSessionTicketListener,
|
||||
hasNewTokenListener,
|
||||
hasOriginListener,
|
||||
isClosing,
|
||||
isGracefulClose,
|
||||
isSilentClose,
|
||||
isStatelessReset,
|
||||
isHandshakeCompleted,
|
||||
isHandshakeConfirmed,
|
||||
isStreamOpenAllowed,
|
||||
isPrioritySupported,
|
||||
headersSupported,
|
||||
isWrapped,
|
||||
applicationType,
|
||||
noErrorCode,
|
||||
internalErrorCode,
|
||||
maxDatagramSize,
|
||||
lastDatagramId,
|
||||
maxPendingDatagrams,
|
||||
} = this;
|
||||
|
||||
return `QuicSessionState ${inspect({
|
||||
hasPathValidationListener: this.hasPathValidationListener,
|
||||
hasDatagramListener: this.hasDatagramListener,
|
||||
hasDatagramStatusListener: this.hasDatagramStatusListener,
|
||||
hasSessionTicketListener: this.hasSessionTicketListener,
|
||||
hasNewTokenListener: this.hasNewTokenListener,
|
||||
hasOriginListener: this.hasOriginListener,
|
||||
isClosing: this.isClosing,
|
||||
isGracefulClose: this.isGracefulClose,
|
||||
isSilentClose: this.isSilentClose,
|
||||
isStatelessReset: this.isStatelessReset,
|
||||
isHandshakeCompleted: this.isHandshakeCompleted,
|
||||
isHandshakeConfirmed: this.isHandshakeConfirmed,
|
||||
isStreamOpenAllowed: this.isStreamOpenAllowed,
|
||||
isPrioritySupported: this.isPrioritySupported,
|
||||
headersSupported: this.headersSupported,
|
||||
isWrapped: this.isWrapped,
|
||||
applicationType: this.applicationType,
|
||||
noErrorCode: this.noErrorCode,
|
||||
internalErrorCode: this.internalErrorCode,
|
||||
maxDatagramSize: this.maxDatagramSize,
|
||||
lastDatagramId: this.lastDatagramId,
|
||||
hasPathValidationListener,
|
||||
hasDatagramListener,
|
||||
hasDatagramStatusListener,
|
||||
hasSessionTicketListener,
|
||||
hasNewTokenListener,
|
||||
hasOriginListener,
|
||||
isClosing,
|
||||
isGracefulClose,
|
||||
isSilentClose,
|
||||
isStatelessReset,
|
||||
isHandshakeCompleted,
|
||||
isHandshakeConfirmed,
|
||||
isStreamOpenAllowed,
|
||||
isPrioritySupported,
|
||||
headersSupported,
|
||||
isWrapped,
|
||||
applicationType,
|
||||
noErrorCode,
|
||||
internalErrorCode,
|
||||
maxDatagramSize,
|
||||
lastDatagramId,
|
||||
maxPendingDatagrams,
|
||||
}, opts)}`;
|
||||
}
|
||||
|
||||
[kFinishClose]() {
|
||||
// Snapshot the state into a new DataView since the underlying
|
||||
// buffer will be destroyed.
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
this.#handle = new DataView(new ArrayBuffer(0));
|
||||
this.#handle = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,6 +692,8 @@ class QuicStreamState {
|
||||
#handle;
|
||||
/** @type {number} */
|
||||
#offset = 0;
|
||||
/** @type {bigint|undefined} */
|
||||
#id = undefined;
|
||||
|
||||
/**
|
||||
* @param {symbol} privateSymbol
|
||||
@@ -618,144 +714,166 @@ class QuicStreamState {
|
||||
|
||||
/** @type {bigint} */
|
||||
get id() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return DataViewPrototypeGetBigInt64(this.#handle, this.#offset + IDX_STATE_STREAM_ID, kIsLittleEndian);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return this.#id;
|
||||
return DataViewPrototypeGetBigInt64(handle, this.#offset + IDX_STATE_STREAM_ID, kIsLittleEndian);
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get pending() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_PENDING);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_PENDING) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get finSent() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_FIN_SENT);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_FIN_SENT) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get finReceived() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_FIN_RECEIVED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_FIN_RECEIVED) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get readEnded() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_READ_ENDED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_READ_ENDED) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get writeEnded() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WRITE_ENDED);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_WRITE_ENDED) !== 0;
|
||||
}
|
||||
|
||||
|
||||
/** @type {boolean} */
|
||||
get reset() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_RESET);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_RESET) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get hasOutbound() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_HAS_OUTBOUND);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_HAS_OUTBOUND) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get hasReader() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_HAS_READER);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_HAS_READER) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get wantsBlock() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WANTS_BLOCK);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_WANTS_BLOCK) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
set wantsBlock(val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
DataViewPrototypeSetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WANTS_BLOCK, val ? 1 : 0);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint8(handle, this.#offset + IDX_STATE_STREAM_WANTS_BLOCK, val ? 1 : 0);
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get [kWantsHeaders]() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WANTS_HEADERS);
|
||||
get wantsHeaders() {
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_WANTS_HEADERS) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
set [kWantsHeaders](val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
DataViewPrototypeSetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WANTS_HEADERS, val ? 1 : 0);
|
||||
set wantsHeaders(val) {
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint8(handle, this.#offset + IDX_STATE_STREAM_WANTS_HEADERS, val ? 1 : 0);
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get wantsReset() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WANTS_RESET);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_WANTS_RESET) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
set wantsReset(val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
DataViewPrototypeSetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WANTS_RESET, val ? 1 : 0);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint8(handle, this.#offset + IDX_STATE_STREAM_WANTS_RESET, val ? 1 : 0);
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get [kWantsTrailers]() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WANTS_TRAILERS);
|
||||
get wantsTrailers() {
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_WANTS_TRAILERS) !== 0;
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
set [kWantsTrailers](val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
DataViewPrototypeSetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_WANTS_TRAILERS, val ? 1 : 0);
|
||||
set wantsTrailers(val) {
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint8(handle, this.#offset + IDX_STATE_STREAM_WANTS_TRAILERS, val ? 1 : 0);
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get early() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
return !!DataViewPrototypeGetUint8(this.#handle, this.#offset + IDX_STATE_STREAM_RECEIVED_EARLY_DATA);
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint8(handle, this.#offset + IDX_STATE_STREAM_RECEIVED_EARLY_DATA) !== 0;
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get resetCode() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetBigUint64(
|
||||
this.#handle, this.#offset + IDX_STATE_STREAM_RESET_CODE, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_STREAM_RESET_CODE, kIsLittleEndian);
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get writeDesiredSize() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint32(
|
||||
this.#handle, this.#offset + IDX_STATE_STREAM_WRITE_DESIRED_SIZE, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_STREAM_WRITE_DESIRED_SIZE, kIsLittleEndian);
|
||||
}
|
||||
|
||||
set writeDesiredSize(val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint32(
|
||||
this.#handle, this.#offset + IDX_STATE_STREAM_WRITE_DESIRED_SIZE, val, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_STREAM_WRITE_DESIRED_SIZE, val, kIsLittleEndian);
|
||||
}
|
||||
|
||||
/** @type {number} */
|
||||
get highWaterMark() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return undefined;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return undefined;
|
||||
return DataViewPrototypeGetUint32(
|
||||
this.#handle, this.#offset + IDX_STATE_STREAM_HIGH_WATER_MARK, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_STREAM_HIGH_WATER_MARK, kIsLittleEndian);
|
||||
}
|
||||
|
||||
set highWaterMark(val) {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
const handle = this.#handle;
|
||||
if (handle === undefined) return;
|
||||
DataViewPrototypeSetUint32(
|
||||
this.#handle, this.#offset + IDX_STATE_STREAM_HIGH_WATER_MARK, val, kIsLittleEndian);
|
||||
handle, this.#offset + IDX_STATE_STREAM_HIGH_WATER_MARK, val, kIsLittleEndian);
|
||||
}
|
||||
|
||||
toString() {
|
||||
@@ -763,59 +881,108 @@ class QuicStreamState {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return {};
|
||||
if (this.#handle === undefined) return kEmptyObject;
|
||||
const {
|
||||
id,
|
||||
pending,
|
||||
finSent,
|
||||
finReceived,
|
||||
readEnded,
|
||||
writeEnded,
|
||||
reset,
|
||||
hasOutbound,
|
||||
hasReader,
|
||||
wantsBlock,
|
||||
wantsReset,
|
||||
wantsHeaders,
|
||||
wantsTrailers,
|
||||
early,
|
||||
resetCode,
|
||||
writeDesiredSize,
|
||||
highWaterMark,
|
||||
} = this;
|
||||
return {
|
||||
__proto__: null,
|
||||
id: `${this.id}`,
|
||||
pending: this.pending,
|
||||
finSent: this.finSent,
|
||||
finReceived: this.finReceived,
|
||||
readEnded: this.readEnded,
|
||||
writeEnded: this.writeEnded,
|
||||
reset: this.reset,
|
||||
hasOutbound: this.hasOutbound,
|
||||
hasReader: this.hasReader,
|
||||
wantsBlock: this.wantsBlock,
|
||||
wantsReset: this.wantsReset,
|
||||
early: this.early,
|
||||
id: `${id}`,
|
||||
pending,
|
||||
finSent,
|
||||
finReceived,
|
||||
readEnded,
|
||||
writeEnded,
|
||||
reset,
|
||||
hasOutbound,
|
||||
hasReader,
|
||||
wantsBlock,
|
||||
wantsReset,
|
||||
wantsHeaders,
|
||||
wantsTrailers,
|
||||
early,
|
||||
resetCode,
|
||||
writeDesiredSize,
|
||||
highWaterMark,
|
||||
};
|
||||
}
|
||||
|
||||
[kInspect](depth, options) {
|
||||
if (depth < 0)
|
||||
return this;
|
||||
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) {
|
||||
return 'QuicStreamState { <Closed> }';
|
||||
}
|
||||
|
||||
if (depth < 0) {
|
||||
return 'QuicStreamState { }';
|
||||
}
|
||||
|
||||
const opts = {
|
||||
__proto__: null,
|
||||
...options,
|
||||
depth: options.depth == null ? null : options.depth - 1,
|
||||
};
|
||||
|
||||
const {
|
||||
id,
|
||||
pending,
|
||||
finSent,
|
||||
finReceived,
|
||||
readEnded,
|
||||
writeEnded,
|
||||
reset,
|
||||
hasOutbound,
|
||||
hasReader,
|
||||
wantsBlock,
|
||||
wantsReset,
|
||||
wantsHeaders,
|
||||
wantsTrailers,
|
||||
early,
|
||||
resetCode,
|
||||
writeDesiredSize,
|
||||
highWaterMark,
|
||||
} = this;
|
||||
|
||||
return `QuicStreamState ${inspect({
|
||||
id: this.id,
|
||||
pending: this.pending,
|
||||
finSent: this.finSent,
|
||||
finReceived: this.finReceived,
|
||||
readEnded: this.readEnded,
|
||||
writeEnded: this.writeEnded,
|
||||
reset: this.reset,
|
||||
hasOutbound: this.hasOutbound,
|
||||
hasReader: this.hasReader,
|
||||
wantsBlock: this.wantsBlock,
|
||||
wantsReset: this.wantsReset,
|
||||
early: this.early,
|
||||
id,
|
||||
pending,
|
||||
finSent,
|
||||
finReceived,
|
||||
readEnded,
|
||||
writeEnded,
|
||||
reset,
|
||||
hasOutbound,
|
||||
hasReader,
|
||||
wantsBlock,
|
||||
wantsReset,
|
||||
wantsHeaders,
|
||||
wantsTrailers,
|
||||
early,
|
||||
resetCode,
|
||||
writeDesiredSize,
|
||||
highWaterMark,
|
||||
}, opts)}`;
|
||||
}
|
||||
|
||||
[kFinishClose]() {
|
||||
// Snapshot the state into a new DataView since the underlying
|
||||
// buffer will be destroyed.
|
||||
if (DataViewPrototypeGetByteLength(this.#handle) === 0) return;
|
||||
this.#handle = new DataView(new ArrayBuffer(0));
|
||||
// Cache the stream ID since the buffer will be zeroed out and the ID will be lost.
|
||||
this.#id = this.id;
|
||||
this.#handle = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+383
-148
@@ -7,6 +7,8 @@
|
||||
const {
|
||||
BigUint64Array,
|
||||
JSONStringify,
|
||||
Symbol,
|
||||
TypedArrayPrototypeSubarray,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
@@ -25,6 +27,7 @@ const {
|
||||
codes: {
|
||||
ERR_ILLEGAL_CONSTRUCTOR,
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_THIS,
|
||||
},
|
||||
} = require('internal/errors');
|
||||
|
||||
@@ -88,11 +91,11 @@ const {
|
||||
IDX_STATS_SESSION_BYTES_LOST,
|
||||
IDX_STATS_SESSION_PING_RECV,
|
||||
IDX_STATS_SESSION_PKT_DISCARDED,
|
||||
|
||||
IDX_STATS_SESSION_DATAGRAMS_RECEIVED,
|
||||
IDX_STATS_SESSION_DATAGRAMS_SENT,
|
||||
IDX_STATS_SESSION_DATAGRAMS_ACKNOWLEDGED,
|
||||
IDX_STATS_SESSION_DATAGRAMS_LOST,
|
||||
IDX_STATS_SESSION_COUNT,
|
||||
|
||||
IDX_STATS_STREAM_CREATED_AT,
|
||||
IDX_STATS_STREAM_OPENED_AT,
|
||||
@@ -105,6 +108,7 @@ const {
|
||||
IDX_STATS_STREAM_MAX_OFFSET_ACK,
|
||||
IDX_STATS_STREAM_MAX_OFFSET_RECV,
|
||||
IDX_STATS_STREAM_FINAL_SIZE,
|
||||
IDX_STATS_STREAM_COUNT,
|
||||
} = internalBinding('quic');
|
||||
|
||||
assert(IDX_STATS_ENDPOINT_CREATED_AT !== undefined);
|
||||
@@ -162,6 +166,23 @@ assert(IDX_STATS_STREAM_MAX_OFFSET !== undefined);
|
||||
assert(IDX_STATS_STREAM_MAX_OFFSET_ACK !== undefined);
|
||||
assert(IDX_STATS_STREAM_MAX_OFFSET_RECV !== undefined);
|
||||
assert(IDX_STATS_STREAM_FINAL_SIZE !== undefined);
|
||||
assert(IDX_STATS_STREAM_COUNT !== undefined);
|
||||
assert(IDX_STATS_SESSION_COUNT !== undefined);
|
||||
|
||||
const kCreateDisconnected = Symbol('kCreateDisconnected');
|
||||
|
||||
let assertIsQuicEndpointStats;
|
||||
let assertIsQuicSessionStats;
|
||||
let assertIsQuicStreamStats;
|
||||
let isQuicEndpointStats;
|
||||
let isQuicSessionStats;
|
||||
let isQuicStreamStats;
|
||||
|
||||
function assertIsPrivateConstructor(privateSymbol) {
|
||||
if (privateSymbol !== kPrivateConstructor) {
|
||||
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
||||
}
|
||||
}
|
||||
|
||||
class QuicEndpointStats {
|
||||
/** @type {BigUint64Array} */
|
||||
@@ -169,6 +190,18 @@ class QuicEndpointStats {
|
||||
/** @type {boolean} */
|
||||
#disconnected = false;
|
||||
|
||||
static {
|
||||
isQuicEndpointStats = function(val) {
|
||||
return val != null && typeof val === 'object' && #handle in val;
|
||||
};
|
||||
|
||||
assertIsQuicEndpointStats = function(val) {
|
||||
if (!isQuicEndpointStats(val)) {
|
||||
throw new ERR_INVALID_THIS('QuicEndpointStats');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {symbol} privateSymbol
|
||||
* @param {ArrayBuffer} buffer
|
||||
@@ -176,9 +209,7 @@ class QuicEndpointStats {
|
||||
constructor(privateSymbol, buffer) {
|
||||
// We use the kPrivateConstructor symbol to restrict the ability to
|
||||
// create new instances of QuicEndpointStats to internal code.
|
||||
if (privateSymbol !== kPrivateConstructor) {
|
||||
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
||||
}
|
||||
assertIsPrivateConstructor(privateSymbol);
|
||||
if (!isArrayBuffer(buffer)) {
|
||||
throw new ERR_INVALID_ARG_TYPE('buffer', ['ArrayBuffer'], buffer);
|
||||
}
|
||||
@@ -187,66 +218,79 @@ class QuicEndpointStats {
|
||||
|
||||
/** @type {bigint} */
|
||||
get createdAt() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_CREATED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get destroyedAt() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_DESTROYED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get bytesReceived() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_BYTES_RECEIVED];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get bytesSent() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_BYTES_SENT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get packetsReceived() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_PACKETS_RECEIVED];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get packetsSent() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_PACKETS_SENT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get serverSessions() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_SERVER_SESSIONS];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get clientSessions() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_CLIENT_SESSIONS];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get serverBusyCount() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_SERVER_BUSY_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get retryCount() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_RETRY_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get versionNegotiationCount() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_VERSION_NEGOTIATION_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get statelessResetCount() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_STATELESS_RESET_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get immediateCloseCount() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return this.#handle[IDX_STATS_ENDPOINT_IMMEDIATE_CLOSE_COUNT];
|
||||
}
|
||||
|
||||
@@ -255,30 +299,48 @@ class QuicEndpointStats {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
const {
|
||||
createdAt,
|
||||
destroyedAt,
|
||||
bytesReceived,
|
||||
bytesSent,
|
||||
packetsReceived,
|
||||
packetsSent,
|
||||
serverSessions,
|
||||
clientSessions,
|
||||
serverBusyCount,
|
||||
retryCount,
|
||||
versionNegotiationCount,
|
||||
statelessResetCount,
|
||||
immediateCloseCount,
|
||||
} = this;
|
||||
return {
|
||||
__proto__: null,
|
||||
connected: this.isConnected,
|
||||
// We need to convert the values to strings because JSON does not
|
||||
// support BigInts.
|
||||
createdAt: `${this.createdAt}`,
|
||||
destroyedAt: `${this.destroyedAt}`,
|
||||
bytesReceived: `${this.bytesReceived}`,
|
||||
bytesSent: `${this.bytesSent}`,
|
||||
packetsReceived: `${this.packetsReceived}`,
|
||||
packetsSent: `${this.packetsSent}`,
|
||||
serverSessions: `${this.serverSessions}`,
|
||||
clientSessions: `${this.clientSessions}`,
|
||||
serverBusyCount: `${this.serverBusyCount}`,
|
||||
retryCount: `${this.retryCount}`,
|
||||
versionNegotiationCount: `${this.versionNegotiationCount}`,
|
||||
statelessResetCount: `${this.statelessResetCount}`,
|
||||
immediateCloseCount: `${this.immediateCloseCount}`,
|
||||
createdAt: `${createdAt}`,
|
||||
destroyedAt: `${destroyedAt}`,
|
||||
bytesReceived: `${bytesReceived}`,
|
||||
bytesSent: `${bytesSent}`,
|
||||
packetsReceived: `${packetsReceived}`,
|
||||
packetsSent: `${packetsSent}`,
|
||||
serverSessions: `${serverSessions}`,
|
||||
clientSessions: `${clientSessions}`,
|
||||
serverBusyCount: `${serverBusyCount}`,
|
||||
retryCount: `${retryCount}`,
|
||||
versionNegotiationCount: `${versionNegotiationCount}`,
|
||||
statelessResetCount: `${statelessResetCount}`,
|
||||
immediateCloseCount: `${immediateCloseCount}`,
|
||||
};
|
||||
}
|
||||
|
||||
[kInspect](depth, options) {
|
||||
if (depth < 0)
|
||||
return this;
|
||||
assertIsQuicEndpointStats(this);
|
||||
if (depth < 0) {
|
||||
return 'QuicEndpointStats { }';
|
||||
}
|
||||
|
||||
const opts = {
|
||||
__proto__: null,
|
||||
@@ -286,21 +348,37 @@ class QuicEndpointStats {
|
||||
depth: options.depth == null ? null : options.depth - 1,
|
||||
};
|
||||
|
||||
const {
|
||||
createdAt,
|
||||
destroyedAt,
|
||||
bytesReceived,
|
||||
bytesSent,
|
||||
packetsReceived,
|
||||
packetsSent,
|
||||
serverSessions,
|
||||
clientSessions,
|
||||
serverBusyCount,
|
||||
retryCount,
|
||||
versionNegotiationCount,
|
||||
statelessResetCount,
|
||||
immediateCloseCount,
|
||||
} = this;
|
||||
|
||||
return `QuicEndpointStats ${inspect({
|
||||
connected: this.isConnected,
|
||||
createdAt: this.createdAt,
|
||||
destroyedAt: this.destroyedAt,
|
||||
bytesReceived: this.bytesReceived,
|
||||
bytesSent: this.bytesSent,
|
||||
packetsReceived: this.packetsReceived,
|
||||
packetsSent: this.packetsSent,
|
||||
serverSessions: this.serverSessions,
|
||||
clientSessions: this.clientSessions,
|
||||
serverBusyCount: this.serverBusyCount,
|
||||
retryCount: this.retryCount,
|
||||
versionNegotiationCount: this.versionNegotiationCount,
|
||||
statelessResetCount: this.statelessResetCount,
|
||||
immediateCloseCount: this.immediateCloseCount,
|
||||
createdAt,
|
||||
destroyedAt,
|
||||
bytesReceived,
|
||||
bytesSent,
|
||||
packetsReceived,
|
||||
packetsSent,
|
||||
serverSessions,
|
||||
clientSessions,
|
||||
serverBusyCount,
|
||||
retryCount,
|
||||
versionNegotiationCount,
|
||||
statelessResetCount,
|
||||
immediateCloseCount,
|
||||
}, opts)}`;
|
||||
}
|
||||
|
||||
@@ -311,12 +389,11 @@ class QuicEndpointStats {
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isConnected() {
|
||||
assertIsQuicEndpointStats(this);
|
||||
return !this.#disconnected;
|
||||
}
|
||||
|
||||
[kFinishClose]() {
|
||||
// Snapshot the stats into a new BigUint64Array since the underlying
|
||||
// buffer will be destroyed.
|
||||
this.#handle = new BigUint64Array(this.#handle);
|
||||
this.#disconnected = true;
|
||||
}
|
||||
@@ -325,22 +402,31 @@ class QuicEndpointStats {
|
||||
class QuicSessionStats {
|
||||
/** @type {BigUint64Array} */
|
||||
#handle;
|
||||
/** @type {boolean} */
|
||||
#disconnected = false;
|
||||
#offset = 0;
|
||||
|
||||
static {
|
||||
isQuicSessionStats = function(val) {
|
||||
return val != null && typeof val === 'object' && #handle in val;
|
||||
};
|
||||
|
||||
assertIsQuicSessionStats = function(val) {
|
||||
if (!isQuicSessionStats(val)) {
|
||||
throw new ERR_INVALID_THIS('QuicSessionStats');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {symbol} privateSymbol
|
||||
* @param {ArrayBuffer} buffer
|
||||
* @param {ArrayBuffer} view
|
||||
* @param {number} [byteOffset]
|
||||
*/
|
||||
/** @type {number} */
|
||||
#offset = 0;
|
||||
|
||||
constructor(privateSymbol, view, byteOffset = 0) {
|
||||
// We use the kPrivateConstructor symbol to restrict the ability to
|
||||
// create new instances of QuicSessionStats to internal code.
|
||||
if (privateSymbol !== kPrivateConstructor) {
|
||||
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
||||
}
|
||||
assertIsPrivateConstructor(privateSymbol);
|
||||
if (isArrayBuffer(view)) {
|
||||
this.#handle = new BigUint64Array(view);
|
||||
} else {
|
||||
@@ -351,148 +437,179 @@ class QuicSessionStats {
|
||||
|
||||
/** @type {bigint} */
|
||||
get createdAt() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_CREATED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get destroyedAt() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_DESTROYED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get closingAt() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_CLOSING_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get handshakeCompletedAt() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_HANDSHAKE_COMPLETED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get handshakeConfirmedAt() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_HANDSHAKE_CONFIRMED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get bytesReceived() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_BYTES_RECEIVED];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get bidiInStreamCount() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_BIDI_IN_STREAM_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get bidiOutStreamCount() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_BIDI_OUT_STREAM_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get uniInStreamCount() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_UNI_IN_STREAM_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get uniOutStreamCount() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_UNI_OUT_STREAM_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get maxBytesInFlight() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_MAX_BYTES_IN_FLIGHT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get bytesInFlight() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_BYTES_IN_FLIGHT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get blockCount() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_BLOCK_COUNT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get cwnd() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_CWND];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get latestRtt() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_LATEST_RTT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get minRtt() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_MIN_RTT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get rttVar() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_RTTVAR];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get smoothedRtt() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_SMOOTHED_RTT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get ssthresh() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_SSTHRESH];
|
||||
}
|
||||
|
||||
get pktSent() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_PKT_SENT];
|
||||
}
|
||||
|
||||
get bytesSent() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_BYTES_SENT];
|
||||
}
|
||||
|
||||
get pktRecv() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_PKT_RECV];
|
||||
}
|
||||
|
||||
get bytesRecv() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_BYTES_RECV];
|
||||
}
|
||||
|
||||
get pktLost() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_PKT_LOST];
|
||||
}
|
||||
|
||||
get bytesLost() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_BYTES_LOST];
|
||||
}
|
||||
|
||||
get pingRecv() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_PING_RECV];
|
||||
}
|
||||
|
||||
get pktDiscarded() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_PKT_DISCARDED];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get datagramsReceived() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_DATAGRAMS_RECEIVED];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get datagramsSent() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_DATAGRAMS_SENT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get datagramsAcknowledged() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_DATAGRAMS_ACKNOWLEDGED];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get datagramsLost() {
|
||||
assertIsQuicSessionStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_SESSION_DATAGRAMS_LOST];
|
||||
}
|
||||
|
||||
@@ -501,47 +618,81 @@ class QuicSessionStats {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
assertIsQuicSessionStats(this);
|
||||
const {
|
||||
createdAt,
|
||||
closingAt,
|
||||
handshakeCompletedAt,
|
||||
handshakeConfirmedAt,
|
||||
bytesReceived,
|
||||
bidiInStreamCount,
|
||||
bidiOutStreamCount,
|
||||
uniInStreamCount,
|
||||
uniOutStreamCount,
|
||||
maxBytesInFlight,
|
||||
bytesInFlight,
|
||||
blockCount,
|
||||
cwnd,
|
||||
latestRtt,
|
||||
minRtt,
|
||||
rttVar,
|
||||
smoothedRtt,
|
||||
ssthresh,
|
||||
pktSent,
|
||||
bytesSent,
|
||||
pktRecv,
|
||||
bytesRecv,
|
||||
pktLost,
|
||||
bytesLost,
|
||||
pingRecv,
|
||||
pktDiscarded,
|
||||
datagramsReceived,
|
||||
datagramsSent,
|
||||
datagramsAcknowledged,
|
||||
datagramsLost,
|
||||
} = this;
|
||||
return {
|
||||
__proto__: null,
|
||||
connected: this.isConnected,
|
||||
// We need to convert the values to strings because JSON does not
|
||||
// support BigInts.
|
||||
createdAt: `${this.createdAt}`,
|
||||
closingAt: `${this.closingAt}`,
|
||||
handshakeCompletedAt: `${this.handshakeCompletedAt}`,
|
||||
handshakeConfirmedAt: `${this.handshakeConfirmedAt}`,
|
||||
bytesReceived: `${this.bytesReceived}`,
|
||||
bidiInStreamCount: `${this.bidiInStreamCount}`,
|
||||
bidiOutStreamCount: `${this.bidiOutStreamCount}`,
|
||||
uniInStreamCount: `${this.uniInStreamCount}`,
|
||||
uniOutStreamCount: `${this.uniOutStreamCount}`,
|
||||
maxBytesInFlight: `${this.maxBytesInFlight}`,
|
||||
bytesInFlight: `${this.bytesInFlight}`,
|
||||
blockCount: `${this.blockCount}`,
|
||||
cwnd: `${this.cwnd}`,
|
||||
latestRtt: `${this.latestRtt}`,
|
||||
minRtt: `${this.minRtt}`,
|
||||
rttVar: `${this.rttVar}`,
|
||||
smoothedRtt: `${this.smoothedRtt}`,
|
||||
ssthresh: `${this.ssthresh}`,
|
||||
pktSent: `${this.pktSent}`,
|
||||
bytesSent: `${this.bytesSent}`,
|
||||
pktRecv: `${this.pktRecv}`,
|
||||
bytesRecv: `${this.bytesRecv}`,
|
||||
pktLost: `${this.pktLost}`,
|
||||
bytesLost: `${this.bytesLost}`,
|
||||
pingRecv: `${this.pingRecv}`,
|
||||
pktDiscarded: `${this.pktDiscarded}`,
|
||||
datagramsReceived: `${this.datagramsReceived}`,
|
||||
datagramsSent: `${this.datagramsSent}`,
|
||||
datagramsAcknowledged: `${this.datagramsAcknowledged}`,
|
||||
datagramsLost: `${this.datagramsLost}`,
|
||||
createdAt: `${createdAt}`,
|
||||
closingAt: `${closingAt}`,
|
||||
handshakeCompletedAt: `${handshakeCompletedAt}`,
|
||||
handshakeConfirmedAt: `${handshakeConfirmedAt}`,
|
||||
bytesReceived: `${bytesReceived}`,
|
||||
bidiInStreamCount: `${bidiInStreamCount}`,
|
||||
bidiOutStreamCount: `${bidiOutStreamCount}`,
|
||||
uniInStreamCount: `${uniInStreamCount}`,
|
||||
uniOutStreamCount: `${uniOutStreamCount}`,
|
||||
maxBytesInFlight: `${maxBytesInFlight}`,
|
||||
bytesInFlight: `${bytesInFlight}`,
|
||||
blockCount: `${blockCount}`,
|
||||
cwnd: `${cwnd}`,
|
||||
latestRtt: `${latestRtt}`,
|
||||
minRtt: `${minRtt}`,
|
||||
rttVar: `${rttVar}`,
|
||||
smoothedRtt: `${smoothedRtt}`,
|
||||
ssthresh: `${ssthresh}`,
|
||||
pktSent: `${pktSent}`,
|
||||
bytesSent: `${bytesSent}`,
|
||||
pktRecv: `${pktRecv}`,
|
||||
bytesRecv: `${bytesRecv}`,
|
||||
pktLost: `${pktLost}`,
|
||||
bytesLost: `${bytesLost}`,
|
||||
pingRecv: `${pingRecv}`,
|
||||
pktDiscarded: `${pktDiscarded}`,
|
||||
datagramsReceived: `${datagramsReceived}`,
|
||||
datagramsSent: `${datagramsSent}`,
|
||||
datagramsAcknowledged: `${datagramsAcknowledged}`,
|
||||
datagramsLost: `${datagramsLost}`,
|
||||
};
|
||||
}
|
||||
|
||||
[kInspect](depth, options) {
|
||||
if (depth < 0)
|
||||
return this;
|
||||
if (depth < 0) {
|
||||
return 'QuicSessionStats { }';
|
||||
}
|
||||
|
||||
const opts = {
|
||||
__proto__: null,
|
||||
@@ -549,38 +700,71 @@ class QuicSessionStats {
|
||||
depth: options.depth == null ? null : options.depth - 1,
|
||||
};
|
||||
|
||||
const {
|
||||
createdAt,
|
||||
closingAt,
|
||||
handshakeCompletedAt,
|
||||
handshakeConfirmedAt,
|
||||
bytesReceived,
|
||||
bidiInStreamCount,
|
||||
bidiOutStreamCount,
|
||||
uniInStreamCount,
|
||||
uniOutStreamCount,
|
||||
maxBytesInFlight,
|
||||
bytesInFlight,
|
||||
blockCount,
|
||||
cwnd,
|
||||
latestRtt,
|
||||
minRtt,
|
||||
rttVar,
|
||||
smoothedRtt,
|
||||
ssthresh,
|
||||
pktSent,
|
||||
bytesSent,
|
||||
pktRecv,
|
||||
bytesRecv,
|
||||
pktLost,
|
||||
bytesLost,
|
||||
pingRecv,
|
||||
pktDiscarded,
|
||||
datagramsReceived,
|
||||
datagramsSent,
|
||||
datagramsAcknowledged,
|
||||
datagramsLost,
|
||||
} = this;
|
||||
|
||||
return `QuicSessionStats ${inspect({
|
||||
connected: this.isConnected,
|
||||
createdAt: this.createdAt,
|
||||
closingAt: this.closingAt,
|
||||
handshakeCompletedAt: this.handshakeCompletedAt,
|
||||
handshakeConfirmedAt: this.handshakeConfirmedAt,
|
||||
bytesReceived: this.bytesReceived,
|
||||
bidiInStreamCount: this.bidiInStreamCount,
|
||||
bidiOutStreamCount: this.bidiOutStreamCount,
|
||||
uniInStreamCount: this.uniInStreamCount,
|
||||
uniOutStreamCount: this.uniOutStreamCount,
|
||||
maxBytesInFlight: this.maxBytesInFlight,
|
||||
bytesInFlight: this.bytesInFlight,
|
||||
blockCount: this.blockCount,
|
||||
cwnd: this.cwnd,
|
||||
latestRtt: this.latestRtt,
|
||||
minRtt: this.minRtt,
|
||||
rttVar: this.rttVar,
|
||||
smoothedRtt: this.smoothedRtt,
|
||||
ssthresh: this.ssthresh,
|
||||
pktSent: this.pktSent,
|
||||
bytesSent: this.bytesSent,
|
||||
pktRecv: this.pktRecv,
|
||||
bytesRecv: this.bytesRecv,
|
||||
pktLost: this.pktLost,
|
||||
bytesLost: this.bytesLost,
|
||||
pingRecv: this.pingRecv,
|
||||
pktDiscarded: this.pktDiscarded,
|
||||
datagramsReceived: this.datagramsReceived,
|
||||
datagramsSent: this.datagramsSent,
|
||||
datagramsAcknowledged: this.datagramsAcknowledged,
|
||||
datagramsLost: this.datagramsLost,
|
||||
createdAt,
|
||||
closingAt,
|
||||
handshakeCompletedAt,
|
||||
handshakeConfirmedAt,
|
||||
bytesReceived,
|
||||
bidiInStreamCount,
|
||||
bidiOutStreamCount,
|
||||
uniInStreamCount,
|
||||
uniOutStreamCount,
|
||||
maxBytesInFlight,
|
||||
bytesInFlight,
|
||||
blockCount,
|
||||
cwnd,
|
||||
latestRtt,
|
||||
minRtt,
|
||||
rttVar,
|
||||
smoothedRtt,
|
||||
ssthresh,
|
||||
pktSent,
|
||||
bytesSent,
|
||||
pktRecv,
|
||||
bytesRecv,
|
||||
pktLost,
|
||||
bytesLost,
|
||||
pingRecv,
|
||||
pktDiscarded,
|
||||
datagramsReceived,
|
||||
datagramsSent,
|
||||
datagramsAcknowledged,
|
||||
datagramsLost,
|
||||
}, opts)}`;
|
||||
}
|
||||
|
||||
@@ -595,13 +779,10 @@ class QuicSessionStats {
|
||||
}
|
||||
|
||||
[kFinishClose]() {
|
||||
// Snapshot this session's stats slice into a standalone BigUint64Array.
|
||||
const count = IDX_STATS_SESSION_DATAGRAMS_LOST + 1;
|
||||
const snapshot = new BigUint64Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
snapshot[i] = this.#handle[this.#offset + i];
|
||||
}
|
||||
this.#handle = snapshot;
|
||||
const view = TypedArrayPrototypeSubarray(this.#handle,
|
||||
this.#offset,
|
||||
this.#offset + IDX_STATS_STREAM_COUNT);
|
||||
this.#handle = new BigUint64Array(view);
|
||||
this.#offset = 0;
|
||||
this.#disconnected = true;
|
||||
}
|
||||
@@ -610,11 +791,21 @@ class QuicSessionStats {
|
||||
class QuicStreamStats {
|
||||
/** @type {BigUint64Array} */
|
||||
#handle;
|
||||
/** @type {number} */
|
||||
#offset = 0;
|
||||
/** type {boolean} */
|
||||
#disconnected = false;
|
||||
|
||||
static {
|
||||
isQuicStreamStats = function(val) {
|
||||
return val != null && typeof val === 'object' && #handle in val;
|
||||
};
|
||||
|
||||
assertIsQuicStreamStats = function(val) {
|
||||
if (!isQuicStreamStats(val)) {
|
||||
throw new ERR_INVALID_THIS('QuicStreamStats');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {symbol} privateSymbol
|
||||
* @param {BigUint64Array|ArrayBuffer} view
|
||||
@@ -623,70 +814,78 @@ class QuicStreamStats {
|
||||
constructor(privateSymbol, view, byteOffset = 0) {
|
||||
// We use the kPrivateConstructor symbol to restrict the ability to
|
||||
// create new instances of QuicStreamStats to internal code.
|
||||
if (privateSymbol !== kPrivateConstructor) {
|
||||
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
||||
}
|
||||
assertIsPrivateConstructor(privateSymbol);
|
||||
if (isArrayBuffer(view)) {
|
||||
this.#handle = new BigUint64Array(view);
|
||||
} else {
|
||||
this.#handle = view;
|
||||
}
|
||||
// Convert byte offset to element offset (8 bytes per uint64).
|
||||
this.#offset = byteOffset / 8;
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get createdAt() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_CREATED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get openedAt() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_OPENED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get receivedAt() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_RECEIVED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get ackedAt() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_ACKED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get destroyedAt() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_DESTROYED_AT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get bytesReceived() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_BYTES_RECEIVED];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get bytesSent() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_BYTES_SENT];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get maxOffset() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_MAX_OFFSET];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get maxOffsetAcknowledged() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_MAX_OFFSET_ACK];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get maxOffsetReceived() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_MAX_OFFSET_RECV];
|
||||
}
|
||||
|
||||
/** @type {bigint} */
|
||||
get finalSize() {
|
||||
assertIsQuicStreamStats(this);
|
||||
return this.#handle[this.#offset + IDX_STATS_STREAM_FINAL_SIZE];
|
||||
}
|
||||
|
||||
@@ -695,28 +894,43 @@ class QuicStreamStats {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
assertIsQuicStreamStats(this);
|
||||
const {
|
||||
createdAt,
|
||||
openedAt,
|
||||
receivedAt,
|
||||
ackedAt,
|
||||
destroyedAt,
|
||||
bytesReceived,
|
||||
bytesSent,
|
||||
maxOffset,
|
||||
maxOffsetAcknowledged,
|
||||
maxOffsetReceived,
|
||||
finalSize,
|
||||
} = this;
|
||||
return {
|
||||
__proto__: null,
|
||||
connected: this.isConnected,
|
||||
// We need to convert the values to strings because JSON does not
|
||||
// support BigInts.
|
||||
createdAt: `${this.createdAt}`,
|
||||
openedAt: `${this.openedAt}`,
|
||||
receivedAt: `${this.receivedAt}`,
|
||||
ackedAt: `${this.ackedAt}`,
|
||||
destroyedAt: `${this.destroyedAt}`,
|
||||
bytesReceived: `${this.bytesReceived}`,
|
||||
bytesSent: `${this.bytesSent}`,
|
||||
maxOffset: `${this.maxOffset}`,
|
||||
maxOffsetAcknowledged: `${this.maxOffsetAcknowledged}`,
|
||||
maxOffsetReceived: `${this.maxOffsetReceived}`,
|
||||
finalSize: `${this.finalSize}`,
|
||||
createdAt: `${createdAt}`,
|
||||
openedAt: `${openedAt}`,
|
||||
receivedAt: `${receivedAt}`,
|
||||
ackedAt: `${ackedAt}`,
|
||||
destroyedAt: `${destroyedAt}`,
|
||||
bytesReceived: `${bytesReceived}`,
|
||||
bytesSent: `${bytesSent}`,
|
||||
maxOffset: `${maxOffset}`,
|
||||
maxOffsetAcknowledged: `${maxOffsetAcknowledged}`,
|
||||
maxOffsetReceived: `${maxOffsetReceived}`,
|
||||
finalSize: `${finalSize}`,
|
||||
};
|
||||
}
|
||||
|
||||
[kInspect](depth, options) {
|
||||
if (depth < 0)
|
||||
return this;
|
||||
if (depth < 0) {
|
||||
return 'QuicStreamStats { }';
|
||||
}
|
||||
|
||||
const opts = {
|
||||
__proto__: null,
|
||||
@@ -724,19 +938,33 @@ class QuicStreamStats {
|
||||
depth: options.depth == null ? null : options.depth - 1,
|
||||
};
|
||||
|
||||
const {
|
||||
createdAt,
|
||||
openedAt,
|
||||
receivedAt,
|
||||
ackedAt,
|
||||
destroyedAt,
|
||||
bytesReceived,
|
||||
bytesSent,
|
||||
maxOffset,
|
||||
maxOffsetAcknowledged,
|
||||
maxOffsetReceived,
|
||||
finalSize,
|
||||
} = this;
|
||||
|
||||
return `QuicStreamStats ${inspect({
|
||||
connected: this.isConnected,
|
||||
createdAt: this.createdAt,
|
||||
openedAt: this.openedAt,
|
||||
receivedAt: this.receivedAt,
|
||||
ackedAt: this.ackedAt,
|
||||
destroyedAt: this.destroyedAt,
|
||||
bytesReceived: this.bytesReceived,
|
||||
bytesSent: this.bytesSent,
|
||||
maxOffset: this.maxOffset,
|
||||
maxOffsetAcknowledged: this.maxOffsetAcknowledged,
|
||||
maxOffsetReceived: this.maxOffsetReceived,
|
||||
finalSize: this.finalSize,
|
||||
createdAt,
|
||||
openedAt,
|
||||
receivedAt,
|
||||
ackedAt,
|
||||
destroyedAt,
|
||||
bytesReceived,
|
||||
bytesSent,
|
||||
maxOffset,
|
||||
maxOffsetAcknowledged,
|
||||
maxOffsetReceived,
|
||||
finalSize,
|
||||
}, opts)}`;
|
||||
}
|
||||
|
||||
@@ -751,22 +979,29 @@ class QuicStreamStats {
|
||||
}
|
||||
|
||||
[kFinishClose]() {
|
||||
// Snapshot this stream's stats slice into a standalone BigUint64Array.
|
||||
const count = IDX_STATS_STREAM_FINAL_SIZE + 1;
|
||||
const snapshot = new BigUint64Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
snapshot[i] = this.#handle[this.#offset + i];
|
||||
}
|
||||
this.#handle = snapshot;
|
||||
const view = TypedArrayPrototypeSubarray(this.#handle,
|
||||
this.#offset,
|
||||
this.#offset + IDX_STATS_STREAM_COUNT);
|
||||
this.#handle = new BigUint64Array(view);
|
||||
this.#offset = 0;
|
||||
this.#disconnected = true;
|
||||
}
|
||||
|
||||
// Creates an immediately disconnected QuicStreamStats object. Used when
|
||||
// lazily creating stats for a stream that has already been destroyed.
|
||||
static [kCreateDisconnected]() {
|
||||
const count = IDX_STATS_STREAM_FINAL_SIZE + 1;
|
||||
const stats = new QuicStreamStats(kPrivateConstructor, new BigUint64Array(count), 0);
|
||||
stats.#disconnected = true;
|
||||
return stats;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
QuicEndpointStats,
|
||||
QuicSessionStats,
|
||||
QuicStreamStats,
|
||||
kCreateDisconnected,
|
||||
};
|
||||
|
||||
/* c8 ignore stop */
|
||||
@@ -57,8 +57,6 @@ const kSendHeaders = Symbol('kSendHeaders');
|
||||
const kSessionTicket = Symbol('kSessionTicket');
|
||||
const kTrailers = Symbol('kTrailers');
|
||||
const kVersionNegotiation = Symbol('kVersionNegotiation');
|
||||
const kWantsHeaders = Symbol('kWantsHeaders');
|
||||
const kWantsTrailers = Symbol('kWantsTrailers');
|
||||
|
||||
module.exports = {
|
||||
kAttachFileHandle,
|
||||
@@ -93,8 +91,6 @@ module.exports = {
|
||||
kSessionTicket,
|
||||
kTrailers,
|
||||
kVersionNegotiation,
|
||||
kWantsHeaders,
|
||||
kWantsTrailers,
|
||||
};
|
||||
|
||||
/* c8 ignore stop */
|
||||
@@ -3729,6 +3729,8 @@ void Session::InitPerContext(Realm* realm, Local<Object> target) {
|
||||
SESSION_STATE(V)
|
||||
#undef V
|
||||
|
||||
NODE_DEFINE_CONSTANT(target, IDX_STATS_SESSION_COUNT);
|
||||
|
||||
#define V(name, _) NODE_DEFINE_CONSTANT(target, IDX_STATS_SESSION_##name);
|
||||
SESSION_STATS(V)
|
||||
NODE_DEFINE_CONSTANT(target, IDX_STATS_SESSION_COUNT);
|
||||
|
||||
@@ -983,6 +983,8 @@ void Stream::InitPerContext(Realm* realm, Local<Object> target) {
|
||||
STREAM_STATE(V)
|
||||
#undef V
|
||||
|
||||
NODE_DEFINE_CONSTANT(target, IDX_STATS_STREAM_COUNT);
|
||||
|
||||
constexpr int QUIC_STREAM_HEADERS_KIND_HINTS =
|
||||
static_cast<uint8_t>(HeadersKind::HINTS);
|
||||
constexpr int QUIC_STREAM_HEADERS_KIND_INITIAL =
|
||||
|
||||
@@ -27,43 +27,30 @@ const serverDone = Promise.withResolvers();
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
// Sending headers on non-H3 stream throws.
|
||||
throws(() => {
|
||||
stream.sendHeaders({ ':status': '200' });
|
||||
}, { code: 'ERR_INVALID_STATE' });
|
||||
throws(() => stream.sendHeaders({ ':status': '200' }), { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// Setting onheaders on non-H3 stream throws.
|
||||
throws(() => {
|
||||
stream.onheaders = () => {};
|
||||
}, { code: 'ERR_INVALID_STATE' });
|
||||
throws(() => stream.onheaders = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// Setting ontrailers on non-H3 stream throws.
|
||||
throws(() => {
|
||||
stream.ontrailers = () => {};
|
||||
}, { code: 'ERR_INVALID_STATE' });
|
||||
throws(() => stream.ontrailers = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// Setting oninfo on non-H3 stream throws.
|
||||
throws(() => {
|
||||
stream.oninfo = () => {};
|
||||
}, { code: 'ERR_INVALID_STATE' });
|
||||
throws(() => stream.oninfo = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// Setting onwanttrailers on non-H3 stream throws.
|
||||
throws(() => {
|
||||
stream.onwanttrailers = () => {};
|
||||
}, { code: 'ERR_INVALID_STATE' });
|
||||
throws(() => stream.onwanttrailers = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// sendInformationalHeaders throws on non-H3.
|
||||
throws(() => {
|
||||
stream.sendInformationalHeaders({ ':status': '103' });
|
||||
}, { code: 'ERR_INVALID_STATE' });
|
||||
throws(() => stream.sendInformationalHeaders({ ':status': '103' }), {
|
||||
code: 'ERR_INVALID_STATE',
|
||||
});
|
||||
|
||||
// sendTrailers throws on non-H3.
|
||||
throws(() => {
|
||||
stream.sendTrailers({ 'x-trailer': 'value' });
|
||||
}, { code: 'ERR_INVALID_STATE' });
|
||||
throws(() => stream.sendTrailers({ 'x-trailer': 'value' }), { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
stream.writer.endSync();
|
||||
|
||||
try { await stream.closed; } catch {
|
||||
// Stream may close with error.
|
||||
}
|
||||
serverSession.close();
|
||||
serverDone.resolve();
|
||||
});
|
||||
@@ -81,15 +68,9 @@ await clientSession.opened;
|
||||
const stream = await clientSession.createBidirectionalStream({
|
||||
body: encoder.encode('ping'),
|
||||
});
|
||||
stream.closed.catch(() => {});
|
||||
|
||||
// Client side — sending headers on non-H3 stream throws.
|
||||
throws(() => {
|
||||
stream.sendHeaders({ ':method': 'GET' });
|
||||
}, { code: 'ERR_INVALID_STATE' });
|
||||
throws(() => stream.sendHeaders({ ':method': 'GET' }), { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
try { await stream.closed; } catch {
|
||||
// Stream may close with error.
|
||||
}
|
||||
await serverDone.promise;
|
||||
clientSession.close();
|
||||
@@ -45,7 +45,7 @@ const {
|
||||
isBusy: false,
|
||||
maxConnectionsPerHost: 100,
|
||||
maxConnectionsTotal: 10_000,
|
||||
pendingCallbacks: '0',
|
||||
pendingCallbacks: 0,
|
||||
});
|
||||
|
||||
endpoint.busy = true;
|
||||
|
||||
@@ -90,8 +90,9 @@ strictEqual(clientSession.endpoint, null);
|
||||
strictEqual(clientSession.stats.isConnected, false);
|
||||
|
||||
strictEqual(stream.destroyed, true);
|
||||
strictEqual(stream.session, null);
|
||||
strictEqual(stream.id, null);
|
||||
strictEqual(stream.direction, null);
|
||||
|
||||
// The stream id and direction should still be available after destruction
|
||||
strictEqual(stream.id, 0n);
|
||||
strictEqual(stream.direction, 'bidi');
|
||||
|
||||
await serverEndpoint.close();
|
||||
Reference in new issue
Block a user