diff --git a/doc/api/errors.md b/doc/api/errors.md
index 248944097f6a3f..2f7968031d7726 100644
--- a/doc/api/errors.md
+++ b/doc/api/errors.md
@@ -1748,12 +1748,36 @@ Accessing `Object.prototype.__proto__` has been forbidden using
[`Object.setPrototypeOf`][] should be used to get and set the prototype of an
object.
-
-### `ERR_QUICSESSION_VERSION_NEGOTIATION`
+
+### `ERR_QUIC_FAILED_TO_CREATE_SESSION`
> Stability: 1 - Experimental
-TBD
+An unspecified failure occured trying to initialize a new `QuicClientSession`.
+
+
+### `ERR_QUIC_INVALID_REMOTE_TRANSPORT_PARAMS`
+
+> Stability: 1 - Experimental
+
+An attempt to resume a `QuicClientSession` using remembered remote transport
+parameters failed because the transport parameters were invalid.
+
+
+### `ERR_QUIC_INVALID_TLS_SESSION_TICKET`
+
+> Stability: 1 - Experimental
+
+An attempt resume a `QuicClientSession` using a remembered TLS session ticket
+failed because the session ticket was invalid.
+
+
+### `ERR_QUIC_VERSION_NEGOTIATION`
+
+> Stability: 1 - Experimental
+
+A `QuicClientSession` received a version negotiation request from the
+server and was shutdown accordingly.
### `ERR_REQUIRE_ESM`
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index b1ea26ab3e04b3..a9c69eda7b0e6c 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -1301,7 +1301,12 @@ E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath}package.json${base ? ` imported from ${base}` : ''}`;
}, Error);
-E('ERR_QUICSESSION_VERSION_NEGOTIATION',
+E('ERR_QUIC_FAILED_TO_CREATE_SESSION', 'Failed to create QuicSession', Error);
+E('ERR_QUIC_INVALID_REMOTE_TRANSPORT_PARAMS',
+ 'Invalid remote transport params', Error);
+E('ERR_QUIC_INVALID_TLS_SESSION_TICKET',
+ 'Invalid TLS session ticket', Error);
+E('ERR_QUIC_VERSION_NEGOTIATION',
(version, requestedVersions, supportedVersions) => {
return 'QUIC session received version negotiation from server. ' +
`Version: ${version}. Requested: ${requestedVersions.join(', ')} ` +
diff --git a/lib/internal/quic/core.js b/lib/internal/quic/core.js
index 43f979cbd837d7..3aac7c66395e44 100644
--- a/lib/internal/quic/core.js
+++ b/lib/internal/quic/core.js
@@ -101,7 +101,10 @@ const {
ERR_INVALID_CALLBACK,
ERR_INVALID_STATE,
ERR_OPERATION_FAILED,
- ERR_QUICSESSION_VERSION_NEGOTIATION,
+ ERR_QUIC_FAILED_TO_CREATE_SESSION,
+ ERR_QUIC_INVALID_REMOTE_TRANSPORT_PARAMS,
+ ERR_QUIC_INVALID_TLS_SESSION_TICKET,
+ ERR_QUIC_VERSION_NEGOTIATION,
ERR_TLS_DH_PARAM_SIZE,
},
hideStackFrames,
@@ -1753,7 +1756,7 @@ class QuicSession extends EventEmitter {
// QuicSessions.
[kVersionNegotiation](version, requestedVersions, supportedVersions) {
const err =
- new ERR_QUICSESSION_VERSION_NEGOTIATION(
+ new ERR_QUIC_VERSION_NEGOTIATION(
version,
requestedVersions,
supportedVersions);
@@ -2347,19 +2350,9 @@ class QuicServerSession extends QuicSession {
class QuicClientSession extends QuicSession {
[kInternalClientState] = {
allowEarlyData: false,
- autoStart: true,
- dcid: undefined,
handshakeStarted: false,
minDHSize: undefined,
- port: undefined,
- remoteTransportParams: undefined,
- requestOCSP: undefined,
secureContext: undefined,
- sessionTicket: undefined,
- transportParams: undefined,
- preferredAddressPolicy: undefined,
- verifyHostnameIdentity: true,
- qlogEnabled: false,
};
constructor(socket, options, type, ip) {
@@ -2396,74 +2389,55 @@ class QuicClientSession extends QuicSession {
super(socket, { servername, alpn, highWaterMark, defaultEncoding });
const state = this[kInternalClientState];
- state.autoStart = autoStart;
state.handshakeStarted = autoStart;
- state.dcid = dcid;
state.minDHSize = minDHSize;
- state.port = port || 0;
- state.preferredAddressPolicy = preferredAddressPolicy;
- state.requestOCSP = requestOCSP;
+
state.secureContext =
createSecureContext(
sc_options,
initSecureContextClient);
- state.transportParams = validateTransportParams(options);
- state.verifyHostnameIdentity = verifyHostnameIdentity;
- state.qlogEnabled = qlog;
-
- // If provided, indicates that the client is attempting to
- // resume a prior session. Early data would be enabled.
- state.remoteTransportParams = remoteTransportParams;
- state.sessionTicket = sessionTicket;
+
+ const transportParams = validateTransportParams(options);
+
state.allowEarlyData =
remoteTransportParams !== undefined &&
sessionTicket !== undefined;
- setTransportParams(state.transportParams);
+ setTransportParams(transportParams);
const handle =
_createClientSession(
this.socket[kHandle],
type,
ip,
- state.port,
+ port,
state.secureContext.context,
this.servername || ip,
- state.remoteTransportParams,
- state.sessionTicket,
- state.dcid,
- state.preferredAddressPolicy,
+ remoteTransportParams,
+ sessionTicket,
+ dcid,
+ preferredAddressPolicy,
this.alpnProtocol,
- (state.verifyHostnameIdentity ?
+ (verifyHostnameIdentity ?
QUICCLIENTSESSION_OPTION_VERIFY_HOSTNAME_IDENTITY : 0) |
- (state.requestOCSP ?
+ (requestOCSP ?
QUICCLIENTSESSION_OPTION_REQUEST_OCSP : 0),
- state.qlogEnabled,
- state.autoStart);
-
- // We no longer need these, unset them so
- // memory can be garbage collected.
- state.remoteTransportParams = undefined;
- state.sessionTicket = undefined;
- state.dcid = undefined;
+ qlog,
+ autoStart);
// If handle is a number, creating the session failed.
if (typeof handle === 'number') {
let reason;
switch (handle) {
case ERR_FAILED_TO_CREATE_SESSION:
- reason = 'QuicSession bootstrap failed';
- break;
+ throw new ERR_QUIC_FAILED_TO_CREATE_SESSION();
case ERR_INVALID_REMOTE_TRANSPORT_PARAMS:
- reason = 'Invalid Remote Transport Params';
- break;
+ throw new ERR_QUIC_INVALID_REMOTE_TRANSPORT_PARAMS();
case ERR_INVALID_TLS_SESSION_TICKET:
- reason = 'Invalid TLS Session Ticket';
- break;
+ throw new ERR_QUIC_INVALID_TLS_SESSION_TICKET();
default:
- reason = `${handle}`;
+ throw new ERR_OPERATION_FAILED(`Unspecified reason [${reason}]`);
}
- throw new ERR_OPERATION_FAILED(reason);
}
this[kSetHandle](handle);