On this page

QUIC

History
Source Code: lib/quic.js
Stability: 1.0Early development

The 'node:quic' module provides an implementation of the QUIC protocol. To access it, start Node.js with the --experimental-quic option and:

The module is only available under the node: scheme.

M

quic.connect

History
quic.connect(address, options?): Promise
PropertyTypeDescription
address<string> | <net.SocketAddress>-
options<quic.SessionOptions>-
Returns<Promise>a promise for a <quic.QuicSession>

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 local QuicEndpoint instance 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 the endpoint option with either a QuicEndpoint or EndpointOptions as 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 });
M

quic.listen

History
quic.listen(onsession, options?): Promise
PropertyTypeDescription
onsession<quic.OnSessionCallback>-
options<quic.SessionOptions>-
Returns<Promise>a promise for a <quic.QuicEndpoint>

Configures the endpoint to listen as a server. When a new session is initiated by a remote peer, the given onsession callback 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 local QuicEndpoint instance 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 the endpoint option with either a QuicEndpoint or EndpointOptions as the argument.

At most, any single QuicEndpoint can only be configured to listen as a server once.

A QuicEndpoint encapsulates the local UDP-port binding for QUIC. It can be used as both a client and a server.

C

QuicEndpoint Constructor

History
new QuicEndpoint(options?)
PropertyTypeDescription
options<quic.EndpointOptions>-
P

endpoint.address

History
PropertyTypeDescription
-<net.SocketAddress> | <undefined>-

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.

P

endpoint.busy

History
PropertyTypeDescription
-<boolean>-

When endpoint.busy is 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 busy property is useful when the endpoint is under heavy load and needs to temporarily reject new sessions while it catches up.

M

endpoint.close

History
endpoint.close(): Promise
PropertyTypeDescription
Returns<Promise>-

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.

P

endpoint.closed

History
PropertyTypeDescription
-<Promise>-

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.

P

endpoint.closing

History
PropertyTypeDescription
-<boolean>-

True if endpoint.close() has been called and closing the endpoint has not yet completed. Read only.

M

endpoint.destroy

History
endpoint.destroy(error?)
PropertyTypeDescription
error<any>-

Forcefully closes the endpoint by forcing all open sessions to be immediately closed.

P

endpoint.destroyed

History
PropertyTypeDescription
-<boolean>-

True if endpoint.destroy() has been called. Read only.

P

endpoint.stats

History
PropertyTypeDescription
-<quic.QuicEndpoint.Stats>-

The statistics collected for an active session. Read only.

M

endpoint[Symbol.asyncDispose]

History
endpoint[Symbol.asyncDispose]()

Calls endpoint.close() and returns a promise that fulfills when the endpoint has closed.

C

QuicEndpoint.Stats

History

A view of the collected statistics for an endpoint.

P

endpointStats.createdAt

History
PropertyTypeDescription
-<bigint>A timestamp indicating the moment the endpoint was created. Read only.
P

endpointStats.destroyedAt

History
PropertyTypeDescription
-<bigint>A timestamp indicating the moment the endpoint was destroyed. Read only.
P

endpointStats.bytesReceived

History
PropertyTypeDescription
-<bigint>The total number of bytes received by this endpoint. Read only.
P

endpointStats.bytesSent

History
PropertyTypeDescription
-<bigint>The total number of bytes sent by this endpoint. Read only.
P

endpointStats.packetsReceived

History
PropertyTypeDescription
-<bigint>The total number of QUIC packets successfully received by this endpoint. Read only.
P

endpointStats.packetsSent

History
PropertyTypeDescription
-<bigint>The total number of QUIC packets successfully sent by this endpoint. Read only.
P

endpointStats.serverSessions

History
PropertyTypeDescription
-<bigint>The total number of peer-initiated sessions received by this endpoint. Read only.
P

endpointStats.clientSessions

History
PropertyTypeDescription
-<bigint>The total number of sessions initiated by this endpoint. Read only.
P

endpointStats.serverBusyCount

History
PropertyTypeDescription
-<bigint>The total number of times an initial packet was rejected due to the endpoint being marked busy. Read only.
P

endpointStats.retryCount

History
PropertyTypeDescription
-<bigint>The total number of QUIC retry attempts on this endpoint. Read only.
P

endpointStats.versionNegotiationCount

History
PropertyTypeDescription
-<bigint>The total number sessions rejected due to QUIC version mismatch. Read only.
P

endpointStats.statelessResetCount

History
PropertyTypeDescription
-<bigint>The total number of stateless resets handled by this endpoint. Read only.
P

endpointStats.immediateCloseCount

History
PropertyTypeDescription
-<bigint>The total number of sessions that were closed before handshake completed. Read only.
C

QuicSession

History

A QuicSession represents the local side of a QUIC connection.

M

session.close

History
session.close(): Promise
PropertyTypeDescription
Returns<Promise>-

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.

P

session.closed

History
PropertyTypeDescription
-<Promise>-

A promise that is fulfilled once the session is destroyed.

M

session.destroy

History
session.destroy(error?)
PropertyTypeDescription
error<any>-

Immediately destroy the session. All streams will be destroys and the session will be closed.

P

session.destroyed

History
PropertyTypeDescription
-<boolean>-

True if session.destroy() has been called. Read only.

P

session.endpoint

History
PropertyTypeDescription
-<quic.QuicEndpoint>-

The endpoint that created this session. Read only.

P

session.onstream

History
PropertyTypeDescription
-<quic.OnStreamCallback>-

The callback to invoke when a new stream is initiated by a remote peer. Read/write.

P

session.ondatagram

History
PropertyTypeDescription
-<quic.OnDatagramCallback>-

The callback to invoke when a new datagram is received from a remote peer. Read/write.

P

session.ondatagramstatus

History
PropertyTypeDescription
-<quic.OnDatagramStatusCallback>-

The callback to invoke when the status of a datagram is updated. Read/write.

P

session.onpathvalidation

History
PropertyTypeDescription
-<quic.OnPathValidationCallback>-

The callback to invoke when the path validation is updated. Read/write.

P

session.onsessionticket

History
PropertyTypeDescription
-<quic.OnSessionTicketCallback>-

The callback to invoke when a new session ticket is received. Read/write.

P

session.onversionnegotiation

History
PropertyTypeDescription
-<quic.OnVersionNegotiationCallback>-

The callback to invoke when a version negotiation is initiated. Read/write.

P

session.onhandshake

History
PropertyTypeDescription
-<quic.OnHandshakeCallback>-

The callback to invoke when the TLS handshake is completed. Read/write.

M

session.createBidirectionalStream

History
session.createBidirectionalStream(options?): Promise
PropertyTypeDescription
options<Object>-
Returns<Promise>for a <quic.QuicStream>

Open a new bidirectional stream. If the body option is not specified, the outgoing stream will be half-closed.

M

session.createUnidirectionalStream

History
session.createUnidirectionalStream(options?): Promise
PropertyTypeDescription
options<Object>-
Returns<Promise>for a <quic.QuicStream>

Open a new unidirectional stream. If the body option is not specified, the outgoing stream will be closed.

P

session.path

History
PropertyTypeDescription
-<Object> | <undefined>-

The local and remote socket addresses associated with the session. Read only.

M

session.sendDatagram

History
session.sendDatagram(datagram): bigint
PropertyTypeDescription
datagram<string> | <ArrayBufferView>-
Returns<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.

P

session.stats

History
PropertyTypeDescription
-<quic.QuicSession.Stats>-

Return the current statistics for the session. Read only.

M

session.updateKey

History
session.updateKey()

Initiate a key update for the session.

M

session[Symbol.asyncDispose]

History
session[Symbol.asyncDispose]()

Calls session.close() and returns a promise that fulfills when the session has closed.

C

QuicSession.Stats

History
P

sessionStats.createdAt

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.closingAt

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.handshakeCompletedAt

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.handshakeConfirmedAt

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.bytesReceived

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.bytesSent

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.bidiInStreamCount

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.bidiOutStreamCount

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.uniInStreamCount

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.uniOutStreamCount

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.maxBytesInFlights

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.bytesInFlight

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.blockCount

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.cwnd

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.latestRtt

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.minRtt

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.rttVar

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.smoothedRtt

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.ssthresh

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.datagramsReceived

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.datagramsSent

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.datagramsAcknowledged

History
PropertyTypeDescription
-<bigint>-
P

sessionStats.datagramsLost

History
PropertyTypeDescription
-<bigint>-
C

QuicStream

History
P

stream.closed

History
PropertyTypeDescription
-<Promise>-

A promise that is fulfilled when the stream is fully closed.

M

stream.destroy

History
stream.destroy(error?)
PropertyTypeDescription
error<any>-

Immediately and abruptly destroys the stream.

P

stream.destroyed

History
PropertyTypeDescription
-<boolean>-

True if stream.destroy() has been called.

P

stream.direction

History
PropertyTypeDescription
-<string>One of either 'bidi' or 'uni'.

The directionality of the stream. Read only.

P

stream.id

History
PropertyTypeDescription
-<bigint>-

The stream ID. Read only.

P

stream.onblocked

History
PropertyTypeDescription
-<quic.OnBlockedCallback>-

The callback to invoke when the stream is blocked. Read/write.

P

stream.onreset

History
PropertyTypeDescription
-<quic.OnStreamErrorCallback>-

The callback to invoke when the stream is reset. Read/write.

P

stream.readable

History
PropertyTypeDescription
-<ReadableStream>-
P

stream.session

History
PropertyTypeDescription
-<quic.QuicSession>-

The session that created this stream. Read only.

P

stream.stats

History
PropertyTypeDescription
-<quic.QuicStream.Stats>-

The current statistics for the stream. Read only.

C

QuicStream.Stats

History
P

streamStats.ackedAt

History
PropertyTypeDescription
-<bigint>-
P

streamStats.bytesReceived

History
PropertyTypeDescription
-<bigint>-
P

streamStats.bytesSent

History
PropertyTypeDescription
-<bigint>-
P

streamStats.createdAt

History
PropertyTypeDescription
-<bigint>-
P

streamStats.destroyedAt

History
PropertyTypeDescription
-<bigint>-
P

streamStats.finalSize

History
PropertyTypeDescription
-<bigint>-
P

streamStats.isConnected

History
PropertyTypeDescription
-<bigint>-
P

streamStats.maxOffset

History
PropertyTypeDescription
-<bigint>-
P

streamStats.maxOffsetAcknowledged

History
PropertyTypeDescription
-<bigint>-
P

streamStats.maxOffsetReceived

History
PropertyTypeDescription
-<bigint>-
P

streamStats.openedAt

History
PropertyTypeDescription
-<bigint>-
P

streamStats.receivedAt

History
PropertyTypeDescription
-<bigint>-

Type: EndpointOptions

History
PropertyTypeDescription
-<Object>-

The endpoint configuration options passed when constructing a new QuicEndpoint instance.

P

endpointOptions.address

History
PropertyTypeDescription
-<net.SocketAddress> | <string>The local UDP address and port the endpoint should bind to.

If not specified the endpoint will bind to IPv4 localhost on a random port.

P

endpointOptions.addressLRUSize

History
PropertyTypeDescription
-<bigint> | <number>-

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.

P

endpointOptions.ipv6Only

History
PropertyTypeDescription
-<boolean>-

When true, indicates that the endpoint should bind only to IPv6 addresses.

P

endpointOptions.maxConnectionsPerHost

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum number of concurrent sessions allowed per remote peer address.

P

endpointOptions.maxConnectionsTotal

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum total number of concurrent sessions.

P

endpointOptions.maxRetries

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum number of QUIC retry attempts allowed per remote peer address.

P

endpointOptions.maxStatelessResetsPerHost

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum number of stateless resets that are allowed per remote peer address.

P

endpointOptions.retryTokenExpiration

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the length of time a QUIC retry token is considered valid.

P

endpointOptions.resetTokenSecret

History
PropertyTypeDescription
-<ArrayBufferView>-

Specifies the 16-byte secret used to generate QUIC retry tokens.

P

endpointOptions.tokenExpiration

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the length of time a QUIC token is considered valid.

P

endpointOptions.tokenSecret

History
PropertyTypeDescription
-<ArrayBufferView>-

Specifies the 16-byte secret used to generate QUIC tokens.

P

endpointOptions.udpReceiveBufferSize

History
PropertyTypeDescription
-<number>-
P

endpointOptions.udpSendBufferSize

History
PropertyTypeDescription
-<number>-
P

endpointOptions.udpTTL

History
PropertyTypeDescription
-<number>-
P

endpointOptions.validateAddress

History
PropertyTypeDescription
-<boolean>-

When true, requires that the endpoint validate peer addresses using retry packets while establishing a new connection.

Type: SessionOptions

History
P

sessionOptions.alpn

History
PropertyTypeDescription
-<string>-

The ALPN protocol identifier.

P

sessionOptions.ca

History

The CA certificates to use for sessions.

P

sessionOptions.cc

History
PropertyTypeDescription
-<string>-

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.

P

sessionOptions.certs

History

The TLS certificates to use for sessions.

P

sessionOptions.ciphers

History
PropertyTypeDescription
-<string>-

The list of supported TLS 1.3 cipher algorithms.

P

sessionOptions.crl

History

The CRL to use for sessions.

P

sessionOptions.groups

History
PropertyTypeDescription
-<string>-

The list of support TLS 1.3 cipher groups.

P

sessionOptions.keylog

History
PropertyTypeDescription
-<boolean>-

True to enable TLS keylogging output.

P

sessionOptions.keys

History
PropertyTypeDescription
-<KeyObject> | <CryptoKey> | <KeyObject[]> | <CryptoKey[]>-

The TLS crypto keys to use for sessions.

P

sessionOptions.maxPayloadSize

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum UDP packet payload size.

P

sessionOptions.maxStreamWindow

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum stream flow-control window size.

P

sessionOptions.maxWindow

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum session flow-control window size.

P

sessionOptions.minVersion

History
PropertyTypeDescription
-<number>-

The minimum QUIC version number to allow. This is an advanced option that users typically won't have need to specify.

P

sessionOptions.preferredAddressPolicy

History
PropertyTypeDescription
-<string>One of 'use', 'ignore', or 'default'.

When the remote peer advertises a preferred address, this option specifies whether to use it or ignore it.

P

sessionOptions.qlog

History
PropertyTypeDescription
-<boolean>-

True if qlog output should be enabled.

P

sessionOptions.sessionTicket

History
PropertyTypeDescription
-<ArrayBufferView>A session ticket to use for 0RTT session resumption.
P

sessionOptions.handshakeTimeout

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum number of milliseconds a TLS handshake is permitted to take to complete before timing out.

P

sessionOptions.sni

History
PropertyTypeDescription
-<string>-

The peer server name to target.

P

sessionOptions.tlsTrace

History
PropertyTypeDescription
-<boolean>-

True to enable TLS tracing output.

P

sessionOptions.transportParams

History
PropertyTypeDescription
-<quic.TransportParams>-

The QUIC transport parameters to use for the session.

P

sessionOptions.unacknowledgedPacketThreshold

History
PropertyTypeDescription
-<bigint> | <number>-

Specifies the maximum number of unacknowledged packets a session should allow.

P

sessionOptions.verifyClient

History
PropertyTypeDescription
-<boolean>-

True to require verification of TLS client certificate.

P

sessionOptions.verifyPrivateKey

History
PropertyTypeDescription
-<boolean>-

True to require private key verification.

P

sessionOptions.version

History
PropertyTypeDescription
-<number>-

The QUIC version number to use. This is an advanced option that users typically won't have need to specify.

Type: TransportParams

History
P

transportParams.preferredAddressIpv4

History
PropertyTypeDescription
-<net.SocketAddress>The preferred IPv4 address to advertise.
P

transportParams.preferredAddressIpv6

History
PropertyTypeDescription
-<net.SocketAddress>The preferred IPv6 address to advertise.
P

transportParams.initialMaxStreamDataBidiLocal

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.initialMaxStreamDataBidiRemote

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.initialMaxStreamDataUni

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.initialMaxData

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.initialMaxStreamsBidi

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.initialMaxStreamsUni

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.maxIdleTimeout

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.activeConnectionIDLimit

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.ackDelayExponent

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.maxAckDelay

History
PropertyTypeDescription
-<bigint> | <number>-
P

transportParams.maxDatagramFrameSize

History
PropertyTypeDescription
-<bigint> | <number>-

Callback: OnSessionCallback

History
PropertyTypeDescription
this<quic.QuicEndpoint>-
session<quic.QuicSession>-

The callback function that is invoked when a new session is initiated by a remote peer.

Callback: OnStreamCallback

History
PropertyTypeDescription
this<quic.QuicSession>-
stream<quic.QuicStream>-

Callback: OnDatagramCallback

History
PropertyTypeDescription
this<quic.QuicSession>-
datagram<Uint8Array>-
early<boolean>-

Callback: OnDatagramStatusCallback

History
PropertyTypeDescription
this<quic.QuicSession>-
id<bigint>-
status<string>One of either 'lost' or 'acknowledged'.

Callback: OnPathValidationCallback

History
PropertyTypeDescription
this<quic.QuicSession>-
result<string>One of either 'success', 'failure', or 'aborted'.
newLocalAddress<net.SocketAddress>-
newRemoteAddress<net.SocketAddress>-
oldLocalAddress<net.SocketAddress>-
oldRemoteAddress<net.SocketAddress>-
preferredAddress<boolean>-

Callback: OnSessionTicketCallback

History
PropertyTypeDescription
this<quic.QuicSession>-
ticket<Object>-

Callback: OnVersionNegotiationCallback

History
PropertyTypeDescription
this<quic.QuicSession>-
version<number>-
requestedVersions<number[]>-
supportedVersions<number[]>-

Callback: OnHandshakeCallback

History
PropertyTypeDescription
this<quic.QuicSession>-
sni<string>-
alpn<string>-
cipher<string>-
cipherVersion<string>-
validationErrorReason<string>-
validationErrorCode<number>-
earlyDataAccepted<boolean>-

Callback: OnBlockedCallback

History
PropertyTypeDescription
this<quic.QuicStream>-

Callback: OnStreamErrorCallback

History
PropertyTypeDescription
this<quic.QuicStream>-
error<any>-

Channel: quic.endpoint.created

History
PropertyTypeDescription
endpoint<quic.QuicEndpoint>-
config<quic.EndpointOptions>-

Channel: quic.endpoint.listen

History
PropertyTypeDescription
endpoint<quic.QuicEndpoint>-
optoins<quic.SessionOptions>-

Channel: quic.endpoint.closing

History
PropertyTypeDescription
endpoint<quic.QuicEndpoint>-
hasPendingError<boolean>-

Channel: quic.endpoint.closed

History
PropertyTypeDescription
endpoint<quic.QuicEndpoint>-

Channel: quic.endpoint.error

History
PropertyTypeDescription
endpoint<quic.QuicEndpoint>-
error<any>-

Channel: quic.endpoint.busy.change

History
PropertyTypeDescription
endpoint<quic.QuicEndpoint>-
busy<boolean>-

Channel: quic.session.created.client

History

Channel: quic.session.created.server

History

Channel: quic.session.open.stream

History

Channel: quic.session.received.stream

History

Channel: quic.session.send.datagram

History

Channel: quic.session.update.key

History

Channel: quic.session.closing

History

Channel: quic.session.closed

History

Channel: quic.session.receive.datagram

History

Channel: quic.session.receive.datagram.status

History

Channel: quic.session.path.validation

History

Channel: quic.session.ticket

History

Channel: quic.session.version.negotiation

History

Channel: quic.session.handshake

History