A view of the collected statistics for an endpoint.
Node.js module
node:quic
namespace constants
namespace QuicEndpoint
class Stats
- readonly destroyedAt: bigint
A timestamp indicating the moment the endpoint was destroyed. Read only.
- readonly immediateCloseCount: bigint
The total number of sessions that were closed before handshake completed. Read only.
- readonly packetsReceived: bigint
The total number of QUIC packets successfully received by this endpoint. Read only.
- readonly packetsSent: bigint
The total number of QUIC packets successfully sent by this endpoint. Read only.
- readonly serverBusyCount: bigint
The total number of times an initial packet was rejected due to the endpoint being marked busy. Read only.
- readonly serverSessions: bigint
The total number of peer-initiated sessions received by this endpoint. Read only.
- readonly statelessResetCount: bigint
The total number of stateless resets handled by this endpoint. Read only.
- readonly versionNegotiationCount: bigint
The total number sessions rejected due to QUIC version mismatch. Read only.
namespace QuicSession
class Stats
namespace QuicStream
class Stats
class QuicEndpoint
A
QuicEndpointencapsulates the local UDP-port binding for QUIC. It can be used as both a client and a server.- readonly address: undefined | SocketAddress
The local UDP socket address to which the endpoint is bound, if any.
If the endpoint is not currently bound then the value will be
undefined. Read only. - busy: boolean
When
endpoint.busyis set to true, the endpoint will temporarily reject new sessions from being created. Read/write.// Mark the endpoint busy. New sessions will be prevented. endpoint.busy = true; // Mark the endpoint free. New session will be allowed. endpoint.busy = false;The
busyproperty is useful when the endpoint is under heavy load and needs to temporarily reject new sessions while it catches up. - readonly closed: Promise<void>
A promise that is fulfilled when the endpoint is destroyed. This will be the same promise that is returned by the
endpoint.close()function. Read only. - readonly closing: boolean
True if
endpoint.close()has been called and closing the endpoint has not yet completed. Read only. Calls
endpoint.close()and returns a promise that fulfills when the endpoint has closed.Gracefully close the endpoint. The endpoint will close and destroy itself when all currently open sessions close. Once called, new sessions will be rejected.
Returns a promise that is fulfilled when the endpoint is destroyed.
- error?: any): void;
Forcefully closes the endpoint by forcing all open sessions to be immediately closed.
class QuicSession
A
QuicSessionrepresents the local side of a QUIC connection.- ondatagram: undefined | OnDatagramCallback
The callback to invoke when a new datagram is received from a remote peer. Read/write.
- ondatagramstatus: undefined | OnDatagramStatusCallback
The callback to invoke when the status of a datagram is updated. Read/write.
- onhandshake: undefined | OnHandshakeCallback
The callback to invoke when the TLS handshake is completed. Read/write.
- onpathvalidation: undefined | OnPathValidationCallback
The callback to invoke when the path validation is updated. Read/write.
- onsessionticket: undefined | OnSessionTicketCallback
The callback to invoke when a new session ticket is received. Read/write.
- onstream: undefined | OnStreamCallback
The callback to invoke when a new stream is initiated by a remote peer. Read/write.
- onversionnegotiation: undefined | OnVersionNegotiationCallback
The callback to invoke when a version negotiation is initiated. Read/write.
- path: undefined | SessionPath
The local and remote socket addresses associated with the session. Read only.
Calls
session.close()and returns a promise that fulfills when the session has closed.Initiate a graceful close of the session. Existing streams will be allowed to complete but no new streams will be opened. Once all streams have closed, the session will be destroyed. The returned promise will be fulfilled once the session has been destroyed.
Open a new bidirectional stream. If the
bodyoption is not specified, the outgoing stream will be half-closed.Open a new unidirectional stream. If the
bodyoption is not specified, the outgoing stream will be closed.- error?: any): void;
Immediately destroy the session. All streams will be destroys and the session will be closed.
- datagram: string | ArrayBufferView<ArrayBufferLike>): bigint;
Sends an unreliable datagram to the remote peer, returning the datagram ID. If the datagram payload is specified as an
ArrayBufferView, then ownership of that view will be transfered to the underlying stream. Initiate a key update for the session.
class QuicStream
- onblocked: undefined | OnBlockedCallback
The callback to invoke when the stream is blocked. Read/write.
- onreset: undefined | OnStreamErrorCallback
The callback to invoke when the stream is reset. Read/write.
Initiate a new client-side session.
import { connect } from 'node:quic'; import { Buffer } from 'node:buffer'; const enc = new TextEncoder(); const alpn = 'foo'; const client = await connect('123.123.123.123:8888', { alpn }); await client.createUnidirectionalStream({ body: enc.encode('hello world'), });By default, every call to
connect(...)will create a new localQuicEndpointinstance bound to a new random local IP port. To specify the exact local address to use, or to multiplex multiple QUIC sessions over a single local port, pass theendpointoption with either aQuicEndpointorEndpointOptionsas the argument.import { QuicEndpoint, connect } from 'node:quic'; const endpoint = new QuicEndpoint({ address: '127.0.0.1:1234', }); const client = await connect('123.123.123.123:8888', { endpoint });Configures the endpoint to listen as a server. When a new session is initiated by a remote peer, the given
onsessioncallback will be invoked with the created session.import { listen } from 'node:quic'; const endpoint = await listen((session) => { // ... handle the session }); // Closing the endpoint allows any sessions open when close is called // to complete naturally while preventing new sessions from being // initiated. Once all existing sessions have finished, the endpoint // will be destroyed. The call returns a promise that is resolved once // the endpoint is destroyed. await endpoint.close();By default, every call to
listen(...)will create a new localQuicEndpointinstance bound to a new random local IP port. To specify the exact local address to use, or to multiplex multiple QUIC sessions over a single local port, pass theendpointoption with either aQuicEndpointorEndpointOptionsas the argument.At most, any single
QuicEndpointcan only be configured to listen as a server once.
Type definitions
interface CreateStreamOptions
interface EndpointOptions
The endpoint configuration options passed when constructing a new
QuicEndpointinstance.- address?: string | SocketAddress
If not specified the endpoint will bind to IPv4
localhoston a random port. - addressLRUSize?: number | bigint
The endpoint maintains an internal cache of validated socket addresses as a performance optimization. This option sets the maximum number of addresses that are cache. This is an advanced option that users typically won't have need to specify.
- maxConnectionsPerHost?: number | bigint
Specifies the maximum number of concurrent sessions allowed per remote peer address.
- maxRetries?: number | bigint
Specifies the maximum number of QUIC retry attempts allowed per remote peer address.
- maxStatelessResetsPerHost?: number | bigint
Specifies the maximum number of stateless resets that are allowed per remote peer address.
- resetTokenSecret?: ArrayBufferView<ArrayBufferLike>
Specifies the 16-byte secret used to generate QUIC retry tokens.
- retryTokenExpiration?: number | bigint
Specifies the length of time a QUIC retry token is considered valid.
- tokenSecret?: ArrayBufferView<ArrayBufferLike>
Specifies the 16-byte secret used to generate QUIC tokens.
- validateAddress?: boolean
When
true, requires that the endpoint validate peer addresses using retry packets while establishing a new connection.
interface SessionOptions
- ca?: ArrayBuffer | ArrayBufferView<ArrayBufferLike> | readonly unknown[]
The CA certificates to use for sessions.
- cc?: 'reno' | 'cubic' | 'bbr'
Specifies the congestion control algorithm that will be used. Must be set to one of either
'reno','cubic', or'bbr'.This is an advanced option that users typically won't have need to specify.
- certs?: ArrayBuffer | ArrayBufferView<ArrayBufferLike> | readonly unknown[]
The TLS certificates to use for sessions.
- crl?: ArrayBuffer | ArrayBufferView<ArrayBufferLike> | readonly unknown[]
The CRL to use for sessions.
- handshakeTimeout?: number | bigint
Specifies the maximum number of milliseconds a TLS handshake is permitted to take to complete before timing out.
- minVersion?: number
The minimum QUIC version number to allow. This is an advanced option that users typically won't have need to specify.
- preferredAddressPolicy?: 'ignore' | 'default' | 'use'
When the remote peer advertises a preferred address, this option specifies whether to use it or ignore it.
- sessionTicket?: ArrayBufferView<ArrayBufferLike>
A session ticket to use for 0RTT session resumption.
- unacknowledgedPacketThreshold?: number | bigint
Specifies the maximum number of unacknowledged packets a session should allow.
- version?: number
The QUIC version number to use. This is an advanced option that users typically won't have need to specify.
interface SessionPath
- type OnBlockedCallback = (this: QuicStream) => void
- type OnDatagramCallback = (this: QuicSession, datagram: Uint8Array, early: boolean) => void
- type OnDatagramStatusCallback = (this: QuicSession, id: bigint, status: 'lost' | 'acknowledged') => void
- type OnHandshakeCallback = (this: QuicSession, sni: string, alpn: string, cipher: string, cipherVersion: string, validationErrorReason: string, validationErrorCode: number, earlyDataAccepted: boolean) => void
- type OnPathValidationCallback = (this: QuicSession, result: 'success' | 'failure' | 'aborted', newLocalAddress: SocketAddress, newRemoteAddress: SocketAddress, oldLocalAddress: SocketAddress, oldRemoteAddress: SocketAddress, preferredAddress: boolean) => void
- type OnSessionCallback = (this: QuicEndpoint, session: QuicSession) => void
- type OnSessionTicketCallback = (this: QuicSession, ticket: object) => void
- type OnStreamCallback = (this: QuicSession, stream: QuicStream) => void
- type OnStreamErrorCallback = (this: QuicStream, error: any) => void
- type OnVersionNegotiationCallback = (this: QuicSession, version: number, requestedVersions: number[], supportedVersions: number[]) => void