mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
quic: add reusePort option to QuicEndpoint
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode:Opus 4.6 PR-URL: https://github.com/nodejs/node/pull/63267 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
9a2afffec9
commit
409460f2ce
5 files changed
+30
-1
No files matched your search
@@ -2286,6 +2286,23 @@ added: v23.8.0
|
||||
|
||||
When `true`, indicates that the endpoint should bind only to IPv6 addresses.
|
||||
|
||||
#### `endpointOptions.reusePort`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
* Type: {boolean}
|
||||
* Default: `false`
|
||||
|
||||
When `true`, allows multiple endpoints (across separate processes) to bind to
|
||||
the same address and port. The kernel will load-balance incoming UDP datagrams
|
||||
across all sockets bound with this option. This enables horizontal scaling of
|
||||
QUIC servers by running multiple Node.js processes on the same port.
|
||||
|
||||
Supported on Linux 3.9+ and DragonFlyBSD 3.6+. On unsupported platforms, the
|
||||
bind will fail with an error.
|
||||
|
||||
#### `endpointOptions.maxConnectionsPerHost`
|
||||
|
||||
<!-- YAML
|
||||
|
||||
@@ -304,6 +304,7 @@ const endpointRegistry = new SafeSet();
|
||||
* @property {boolean} [disableStatelessReset] When true, the endpoint will not send stateless resets
|
||||
* @property {bigint|number} [idleTimeout] The default idle timeout for sessions on this endpoint
|
||||
* @property {boolean} [ipv6Only] Use IPv6 only
|
||||
* @property {boolean} [reusePort] Enable SO_REUSEPORT for multi-process load balancing
|
||||
* @property {bigint|number} [maxConnectionsPerHost] The maximum number of connections per host
|
||||
* @property {bigint|number} [maxConnectionsTotal] The maximum number of total connections
|
||||
* @property {bigint|number} [maxRetries] The maximum number of retries
|
||||
@@ -3956,6 +3957,7 @@ class QuicEndpoint {
|
||||
idleTimeout,
|
||||
validateAddress,
|
||||
ipv6Only,
|
||||
reusePort,
|
||||
cc,
|
||||
resetTokenSecret,
|
||||
tokenSecret,
|
||||
@@ -3992,6 +3994,7 @@ class QuicEndpoint {
|
||||
idleTimeout,
|
||||
validateAddress,
|
||||
ipv6Only,
|
||||
reusePort,
|
||||
cc,
|
||||
resetTokenSecret,
|
||||
tokenSecret,
|
||||
|
||||
@@ -101,6 +101,7 @@ class SessionManager;
|
||||
V(initial_max_streams_bidi, "initialMaxStreamsBidi") \
|
||||
V(initial_max_streams_uni, "initialMaxStreamsUni") \
|
||||
V(ipv6_only, "ipv6Only") \
|
||||
V(reuse_port, "reusePort") \
|
||||
V(keylog, "keylog") \
|
||||
V(keys, "keys") \
|
||||
V(lost, "lost") \
|
||||
|
||||
@@ -197,7 +197,7 @@ Maybe<Endpoint::Options> Endpoint::Options::From(Environment* env,
|
||||
if (!SET(retry_token_expiration) || !SET(token_expiration) ||
|
||||
!SET(max_stateless_resets) || !SET(address_lru_size) ||
|
||||
!SET(max_retries) || !SET(validate_address) ||
|
||||
!SET(disable_stateless_reset) || !SET(ipv6_only) ||
|
||||
!SET(disable_stateless_reset) || !SET(ipv6_only) || !SET(reuse_port) ||
|
||||
#ifdef DEBUG
|
||||
!SET(rx_loss) || !SET(tx_loss) ||
|
||||
#endif
|
||||
@@ -265,6 +265,7 @@ std::string Endpoint::Options::ToString() const {
|
||||
res += prefix + "reset token secret: " + reset_token_secret.ToString();
|
||||
res += prefix + "token secret: " + token_secret.ToString();
|
||||
res += prefix + "ipv6 only: " + boolToString(ipv6_only);
|
||||
res += prefix + "reuse port: " + boolToString(reuse_port);
|
||||
res += prefix +
|
||||
"udp receive buffer size: " + std::to_string(udp_receive_buffer_size);
|
||||
res +=
|
||||
@@ -384,6 +385,7 @@ int Endpoint::UDP::Bind(const Options& options) {
|
||||
int flags = 0;
|
||||
if (options.local_address->family() == AF_INET6 && options.ipv6_only)
|
||||
flags |= UV_UDP_IPV6ONLY;
|
||||
if (options.reuse_port) flags |= UV_UDP_REUSEPORT;
|
||||
int err = uv_udp_bind(&impl_->handle_, options.local_address->data(), flags);
|
||||
int size;
|
||||
|
||||
|
||||
@@ -148,6 +148,12 @@ class Endpoint final : public AsyncWrap, public Packet::Listener {
|
||||
// flag on the underlying uv_udp_t.
|
||||
bool ipv6_only = false;
|
||||
|
||||
// When true, multiple endpoints (across separate processes) can bind to
|
||||
// the same address:port and the kernel will load-balance incoming UDP
|
||||
// datagrams across them. This sets the UV_UDP_REUSEPORT flag on the
|
||||
// underlying uv_udp_t. Supported on Linux 3.9+ and DragonFlyBSD 3.6+.
|
||||
bool reuse_port = false;
|
||||
|
||||
uint32_t udp_receive_buffer_size = 0;
|
||||
uint32_t udp_send_buffer_size = 0;
|
||||
|
||||
|
||||
Reference in new issue
Block a user