Skip to content

Commit 630c355

Browse files
committed
quic: add proper support for session callbacks, info details
1 parent 385bfb2 commit 630c355

6 files changed

Lines changed: 543 additions & 146 deletions

File tree

doc/api/quic.md

Lines changed: 113 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,36 @@ to complete but no new streams will be opened. Once all streams have closed,
385385
the session will be destroyed. The returned promise will be fulfilled once
386386
the session has been destroyed.
387387

388+
### `session.opened`
389+
390+
<!-- YAML
391+
added: REPLACEME
392+
-->
393+
394+
* Type: {Promise} for an {Object}
395+
* `local` {net.SocketAddress} The local socket address.
396+
* `remote` {net.SocketAddress} The remote socket address.
397+
* `servername` {string} The SNI server name negotiated during the handshake.
398+
* `protocol` {string} The ALPN protocol negotiated during the handshake.
399+
* `cipher` {string} The name of the negotiated TLS cipher suite.
400+
* `cipherVersion` {string} The TLS protocol version of the cipher suite
401+
(e.g., `'TLSv1.3'`).
402+
* `validationErrorReason` {string} If certificate validation failed, the
403+
reason string. Empty string if validation succeeded.
404+
* `validationErrorCode` {number} If certificate validation failed, the
405+
error code. `0` if validation succeeded.
406+
* `earlyDataAttempted` {boolean} Whether 0-RTT early data was attempted.
407+
* `earlyDataAccepted` {boolean} Whether 0-RTT early data was accepted by
408+
the server.
409+
410+
A promise that is fulfilled once the TLS handshake completes successfully.
411+
The resolved value contains information about the established session
412+
including the negotiated protocol, cipher suite, certificate validation
413+
status, and 0-RTT early data status.
414+
415+
If the handshake fails or the session is destroyed before the handshake
416+
completes, the promise will be rejected.
417+
388418
### `session.closed`
389419

390420
<!-- YAML
@@ -496,6 +526,30 @@ added: v23.8.0
496526

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

529+
### `session.onnewtoken`
530+
531+
<!-- YAML
532+
added: REPLACEME
533+
-->
534+
535+
* Type: {quic.OnNewTokenCallback}
536+
537+
The callback to invoke when a NEW\_TOKEN token is received from the server.
538+
The token can be passed as the `token` option on a future connection to
539+
the same server to skip address validation. Read/write.
540+
541+
### `session.onorigin`
542+
543+
<!-- YAML
544+
added: REPLACEME
545+
-->
546+
547+
* Type: {quic.OnOriginCallback}
548+
549+
The callback to invoke when an ORIGIN frame (RFC 9412) is received from
550+
the server, indicating which origins the server is authoritative for.
551+
Read/write.
552+
499553
### `session.createBidirectionalStream([options])`
500554

501555
<!-- YAML
@@ -586,6 +640,42 @@ will be silently dropped and `0n` returned. The local
586640
`maxDatagramFrameSize` transport parameter (default: `1200` bytes) controls
587641
what this endpoint advertises to the peer as its own maximum.
588642

643+
### `session.certificate`
644+
645+
<!-- YAML
646+
added: REPLACEME
647+
-->
648+
649+
* Type: {Object|undefined}
650+
651+
The local certificate as an object with properties such as `subject`,
652+
`issuer`, `valid_from`, `valid_to`, `fingerprint`, etc. Returns `undefined`
653+
if the session is destroyed or no certificate is available.
654+
655+
### `session.peerCertificate`
656+
657+
<!-- YAML
658+
added: REPLACEME
659+
-->
660+
661+
* Type: {Object|undefined}
662+
663+
The peer's certificate as an object with properties such as `subject`,
664+
`issuer`, `valid_from`, `valid_to`, `fingerprint`, etc. Returns `undefined`
665+
if the session is destroyed or the peer did not present a certificate.
666+
667+
### `session.ephemeralKeyInfo`
668+
669+
<!-- YAML
670+
added: REPLACEME
671+
-->
672+
673+
* Type: {Object|undefined}
674+
675+
The ephemeral key information for the session, with properties such as
676+
`type`, `name`, and `size`. Only available on client sessions. Returns
677+
`undefined` for server sessions or if the session is destroyed.
678+
589679
### `session.maxDatagramSize`
590680

591681
<!-- YAML
@@ -609,19 +699,6 @@ added: v23.8.0
609699

610700
Return the current statistics for the session. Read only.
611701

612-
### `session.token`
613-
614-
<!-- YAML
615-
added: REPLACEME
616-
-->
617-
618-
* Type: {object|undefined}
619-
620-
The most recently received NEW\_TOKEN token from the server, if any.
621-
The object has `token` {Buffer} and `address` {SocketAddress} properties.
622-
The token can be passed as the `token` option on a future connection to
623-
the same server to skip address validation.
624-
625702
### `session.updateKey()`
626703

627704
<!-- YAML
@@ -1537,9 +1614,9 @@ added: REPLACEME
15371614
* Type: {ArrayBufferView}
15381615

15391616
An opaque address validation token previously received from the server
1540-
via `session.token`. Providing a valid token on reconnection allows
1541-
the client to skip the server's address validation, reducing handshake
1542-
latency.
1617+
via the [`session.onnewtoken`][] callback. Providing a valid token on
1618+
reconnection allows the client to skip the server's address validation,
1619+
reducing handshake latency.
15431620

15441621
#### `sessionOptions.transportParams`
15451622

@@ -1817,6 +1894,25 @@ added: v23.8.0
18171894
* `earlyDataAttempted` {boolean}
18181895
* `earlyDataAccepted` {boolean}
18191896

1897+
### Callback: `OnNewTokenCallback`
1898+
1899+
<!-- YAML
1900+
added: REPLACEME
1901+
-->
1902+
1903+
* `this` {quic.QuicSession}
1904+
* `token` {Buffer} The NEW\_TOKEN token data.
1905+
* `address` {SocketAddress} The remote address the token is associated with.
1906+
1907+
### Callback: `OnOriginCallback`
1908+
1909+
<!-- YAML
1910+
added: REPLACEME
1911+
-->
1912+
1913+
* `this` {quic.QuicSession}
1914+
* `origins` {string\[]} The list of origins the server is authoritative for.
1915+
18201916
### Callback: `OnBlockedCallback`
18211917

18221918
<!-- YAML
@@ -1983,5 +2079,6 @@ added: v23.8.0
19832079
added: v23.8.0
19842080
-->
19852081

2082+
[`session.onnewtoken`]: #sessiononnewtoken
19862083
[`sessionOptions.sni`]: #sessionoptionssni-server-only
19872084
[`stream.setPriority()`]: #streamsetpriorityoptions

0 commit comments

Comments
 (0)