Skip to content

Commit bc5fe2a

Browse files
committed
lib: shorten extraneous comments in dtls.js
Signed-off-by: James M Snell <jasnell@gmail.com>
1 parent 0a12c91 commit bc5fe2a

1 file changed

Lines changed: 3 additions & 39 deletions

File tree

lib/internal/dtls/dtls.js

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,8 @@ const {
102102

103103
const kEmptyObject = { __proto__: null };
104104

105-
// Default bounds on how many server sessions an endpoint will hold. Each one
106-
// owns an SSL, two BIOs and a timer, so an unbounded table is a memory
107-
// exhaustion vector for anyone willing to complete cookie exchanges. The
108-
// per-host cap is what stops a single peer taking the whole table; it is set
109-
// well above what a large NAT would plausibly need, and either can be raised,
110-
// or set to 0 to disable, via dtls.listen().
111105
// Upper bound on exported keying material. RFC 5705 sets no limit, but every
112-
// real exporter wants tens of bytes -- DTLS-SRTP's is 60 -- and without a
113-
// bound a caller can ask for a 4 GiB allocation. Rejecting that with a
114-
// TypeError beats failing the allocation.
106+
// real exporter wants tens of bytes -- DTLS-SRTP's is 60.
115107
const kMaxKeyingMaterialLength = 65536;
116108

117109
// Matches node:tls, which derives the default from the process invocation so
@@ -359,22 +351,13 @@ class DTLSSession {
359351
}
360352

361353
get peerX509Certificate() {
362-
// Cached deliberately, not just to hand back a stable object. The
363-
// underlying X509Certificate::GetPeerCert() is destructive on the client
364-
// side: with no peer certificate of its own to start from it lifts the
365-
// leaf out of the SSL's chain with sk_X509_delete(), so calling it a
366-
// second time yields a shorter chain and eventually nothing at all.
367-
// Calling it once and keeping the result is the only correct use.
368354
if (this.#peerX509Certificate !== undefined) {
369355
return this.#peerX509Certificate;
370356
}
371357
if (this.#handle === null) return undefined;
372358

373359
const cert = this.#handle.getPeerX509Certificate();
374360
if (!cert) {
375-
// No peer certificate yet, or none at all. Not cached: before the
376-
// handshake completes there is nothing to take, and the call does not
377-
// disturb the chain when it finds none, so a later access can retry.
378361
return undefined;
379362
}
380363

@@ -524,12 +507,6 @@ class DTLSSession {
524507
}
525508
}
526509

527-
// Mark that this session owns its endpoint (for client sessions
528-
// created by connect() where the endpoint is internal).
529-
// Not a public accessor. This says whether closing the session should take
530-
// the endpoint with it, which is true only for the endpoint connect()
531-
// creates for a single session. Setting it on a server session made closing
532-
// that one session tear down the listener and every other session on it.
533510
get [kOwnsEndpoint]() { return this.#ownsEndpoint; }
534511
set [kOwnsEndpoint](val) { this.#ownsEndpoint = val; }
535512

@@ -1241,10 +1218,6 @@ function resolveSNIValue(value, name) {
12411218

12421219
function applySNIContexts(context, sni) {
12431220
if (typeof sni === 'function') {
1244-
// The binding calls this during the handshake and wants a context back,
1245-
// so the conversion an options bag needs is done here rather than there.
1246-
// Building one costs a certificate parse on every handshake, which is
1247-
// why returning a prepared DTLSSecureContext is worth doing.
12481221
const select = (servername) => {
12491222
const value = sni(servername);
12501223
if (value === undefined || value === null) return undefined;
@@ -1270,10 +1243,6 @@ function applySNIContexts(context, sni) {
12701243
resolveSNIValue(sni[hostname], `options.sni['${hostname}']`));
12711244
}
12721245

1273-
// The binding holds these weakly. A context is allowed to appear in its own
1274-
// SNI map, or in a cycle with another, and a reference count cannot free
1275-
// either -- but a property on the owning wrapper is an edge the garbage
1276-
// collector can trace, so the whole group goes when nothing else holds it.
12771246
context[kSNIContexts] = flat;
12781247
context.setSNIContexts(flat, undefined);
12791248
}
@@ -1423,11 +1392,6 @@ function connect(host, port, options = kEmptyObject) {
14231392
validateInteger(port, 'port', 0, 65535);
14241393
validateObject(options, 'options');
14251394

1426-
// The local socket has to be in the same family as the peer: binding the
1427-
// IPv4 wildcard and then sending to an IPv6 address cannot work. Default to
1428-
// the wildcard matching the remote literal. isIP() only parses, so this
1429-
// stays synchronous -- a hostname returns 0 and keeps the IPv4 default,
1430-
// which is what happens today for anything DNS would have resolved.
14311395
if (options.bindHost !== undefined) {
14321396
validateString(options.bindHost, 'options.bindHost');
14331397
}
@@ -1458,8 +1422,8 @@ function connect(host, port, options = kEmptyObject) {
14581422
endpoint[kBind](bindHost, bindPort);
14591423

14601424
// SNI and peer-identity verification are resolved inside
1461-
// DTLSEndpoint.connect(), which defaults both to the host argument (matching
1462-
// Node.js TLS). The identity is enforced whenever the context verifies, i.e.
1425+
// DTLSEndpoint.connect(), which defaults both to the host argument.
1426+
// The identity is enforced whenever the context verifies, i.e.
14631427
// unless rejectUnauthorized is false.
14641428
const session = endpoint[kDoConnect](
14651429
context, host, port, options.servername, options.session);

0 commit comments

Comments
 (0)