@volter/browser-substrate 0.1.107 → 0.1.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7497,14 +7497,20 @@ class TCPConnectWrap {
7497
7497
  __publicField(this, "addressType");
7498
7498
  }
7499
7499
  }
7500
- const boundPorts = /* @__PURE__ */ new Map();
7500
+ const v4Ports = /* @__PURE__ */ new Map();
7501
+ const v6Ports = /* @__PURE__ */ new Map();
7501
7502
  const ephemeralPorts = /* @__PURE__ */ new Set();
7503
+ const portTaken = (port) => v4Ports.has(port) || v6Ports.has(port) || ephemeralPorts.has(port);
7504
+ function spacesOf(family, flags) {
7505
+ if (family !== "IPv6") return [v4Ports];
7506
+ return flags & constants$6.UV_TCP_IPV6ONLY ? [v6Ports] : [v4Ports, v6Ports];
7507
+ }
7502
7508
  let nextEphemeral = 49152;
7503
7509
  function allocatePort() {
7504
7510
  for (let tries = 0; tries < 16384; tries += 1) {
7505
7511
  const port = nextEphemeral;
7506
7512
  nextEphemeral = nextEphemeral >= 65535 ? 49152 : nextEphemeral + 1;
7507
- if (!boundPorts.has(port) && !ephemeralPorts.has(port)) return port;
7513
+ if (!portTaken(port)) return port;
7508
7514
  }
7509
7515
  return 0;
7510
7516
  }
@@ -7516,9 +7522,13 @@ function isThisHost(address) {
7516
7522
  }
7517
7523
  var onListenWatcher = null;
7518
7524
  var onCloseWatcher = null;
7519
- function listenerOnPort(port) {
7520
- const bound = boundPorts.get(port);
7521
- return bound && bound.listening ? bound : void 0;
7525
+ function listenerOnPort(port, family) {
7526
+ const order = family === "IPv6" ? [v6Ports, v4Ports] : [v4Ports, v6Ports];
7527
+ for (const space of order) {
7528
+ const bound = space.get(port);
7529
+ if (bound && bound.listening) return bound;
7530
+ }
7531
+ return void 0;
7522
7532
  }
7523
7533
  class TCP extends LibuvStreamWrap {
7524
7534
  constructor(type2 = constants$6.SOCKET) {
@@ -7536,24 +7546,27 @@ class TCP extends LibuvStreamWrap {
7536
7546
  bind(address, port, _flags) {
7537
7547
  const native = nativeStreamFor(this);
7538
7548
  if (native) return native.call({ operation: "bind", id: native.descriptor.id, address, port, flags: _flags }).status;
7539
- return this.bindTo(address || "0.0.0.0", port, "IPv4");
7549
+ return this.bindTo(address || "0.0.0.0", port, "IPv4", Number(_flags) || 0);
7540
7550
  }
7541
7551
  bind6(address, port, _flags) {
7542
7552
  const native = nativeStreamFor(this);
7543
7553
  if (native) return native.call({ operation: "bind", id: native.descriptor.id, address, port, flags: _flags, ipv6: true }).status;
7544
- return this.bindTo(address || "::", port, "IPv6");
7554
+ return this.bindTo(address || "::", port, "IPv6", Number(_flags) || 0);
7545
7555
  }
7546
- bindTo(address, port, family) {
7556
+ bindTo(address, port, family, flags = 0) {
7547
7557
  if (!isThisHost(address)) return UV_EADDRINUSE;
7548
7558
  const wanted = Number(port) || 0;
7549
- if (wanted !== 0 && boundPorts.has(wanted)) return UV_EADDRINUSE;
7559
+ const spaces = spacesOf(family, flags);
7560
+ if (wanted !== 0 && spaces.some((space) => space.has(wanted))) return UV_EADDRINUSE;
7550
7561
  if (wanted !== 0 && ephemeralPorts.has(wanted)) return UV_EADDRINUSE;
7551
7562
  const bound = wanted === 0 ? allocatePort() : wanted;
7552
- if (this.local && boundPorts.get(this.local.port) === this) boundPorts.delete(this.local.port);
7563
+ if (this.local) {
7564
+ for (const space of [v4Ports, v6Ports]) if (space.get(this.local.port) === this) space.delete(this.local.port);
7565
+ }
7553
7566
  this.local = { address, family, port: bound };
7554
- boundPorts.set(bound, this);
7567
+ for (const space of spaces) space.set(bound, this);
7555
7568
  this.onLastReferenceClose(() => {
7556
- if (boundPorts.get(bound) === this) boundPorts.delete(bound);
7569
+ for (const space of spaces) if (space.get(bound) === this) space.delete(bound);
7557
7570
  });
7558
7571
  return 0;
7559
7572
  }
@@ -7603,7 +7616,7 @@ class TCP extends LibuvStreamWrap {
7603
7616
  queueMicrotask(() => {
7604
7617
  var _a3, _b3, _c3;
7605
7618
  if (this.closed) return;
7606
- const server = reachable ? listenerOnPort(target) : void 0;
7619
+ const server = reachable ? listenerOnPort(target, family) : void 0;
7607
7620
  if (!server) {
7608
7621
  (_a3 = req.oncomplete) == null ? void 0 : _a3.call(req, UV_ECONNREFUSED, this, req, true, true);
7609
7622
  return;