quic: restrict addEndpoint to before QuicSocket bind
Restricting this to pre-bind keeps things simple PR-URL: https://github.com/nodejs/node/pull/34283 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
81c01bbdba
commit
b80108c033
@ -1458,7 +1458,10 @@ added: REPLACEME
|
|||||||
**Default**: `'udp4'`.
|
**Default**: `'udp4'`.
|
||||||
* Returns: {QuicEndpoint}
|
* Returns: {QuicEndpoint}
|
||||||
|
|
||||||
Creates and adds a new `QuicEndpoint` to the `QuicSocket` instance.
|
Creates and adds a new `QuicEndpoint` to the `QuicSocket` instance. An
|
||||||
|
error will be thrown if `quicsock.addEndpoint()` is called either after
|
||||||
|
the `QuicSocket` has already started binding to the local ports or after
|
||||||
|
the `QuicSocket` has been destroyed.
|
||||||
|
|
||||||
#### quicsocket.bound
|
#### quicsocket.bound
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
|
@ -1102,22 +1102,19 @@ class QuicSocket extends EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A QuicSocket will typically bind only to a single local port, but it is
|
||||||
|
// possible to bind to multiple, even if those use different IP families
|
||||||
|
// (e.g. IPv4 or IPv6). Calls to addEndpoint() must be made before the
|
||||||
|
// QuicSocket is bound (e.g. before any calls to listen() or connect()).
|
||||||
addEndpoint(options = {}) {
|
addEndpoint(options = {}) {
|
||||||
const state = this[kInternalState];
|
const state = this[kInternalState];
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
throw new ERR_INVALID_STATE('QuicSocket is already destroyed');
|
throw new ERR_INVALID_STATE('QuicSocket is already destroyed');
|
||||||
|
if (state.state !== kSocketUnbound)
|
||||||
// TODO(@jasnell): Also forbid adding an endpoint if
|
throw new ERR_INVALID_STATE('QuicSocket is already being bound');
|
||||||
// the QuicSocket is closing.
|
|
||||||
|
|
||||||
const endpoint = new QuicEndpoint(this, options);
|
const endpoint = new QuicEndpoint(this, options);
|
||||||
state.endpoints.add(endpoint);
|
state.endpoints.add(endpoint);
|
||||||
|
|
||||||
// If the QuicSocket is already bound at this point,
|
|
||||||
// also bind the newly created QuicEndpoint.
|
|
||||||
if (state.state !== kSocketUnbound)
|
|
||||||
endpoint[kMaybeBind]();
|
|
||||||
|
|
||||||
return endpoint;
|
return endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,11 @@ async function Test2() {
|
|||||||
|
|
||||||
server.listen({ key, cert, ca, alpn: 'zzz' });
|
server.listen({ key, cert, ca, alpn: 'zzz' });
|
||||||
|
|
||||||
|
// Attempting to add an endpoint after fails.
|
||||||
|
assert.throws(() => server.addEndpoint(), {
|
||||||
|
code: 'ERR_INVALID_STATE'
|
||||||
|
});
|
||||||
|
|
||||||
await once(server, 'ready');
|
await once(server, 'ready');
|
||||||
|
|
||||||
assert.strictEqual(server.endpoints.length, 2);
|
assert.strictEqual(server.endpoints.length, 2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user