@decentnetwork/peer 0.1.59 → 0.1.61

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.
Files changed (2) hide show
  1. package/dist/peer.js +23 -1
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -3247,6 +3247,14 @@ export class Peer {
3247
3247
  resolve();
3248
3248
  });
3249
3249
  });
3250
+ // CRITICAL: a persistent 'error' listener. A TURN send to an
3251
+ // unresolvable host (DNS NXDOMAIN — e.g. tokyo.fi.chat on a box whose
3252
+ // resolver doesn't know it) emits an 'error' on this dgram socket;
3253
+ // with no listener, Node re-throws it as an uncaught exception and
3254
+ // CRASHES THE ENTIRE DAEMON (observed: snoopy repeatedly dying on
3255
+ // "getaddrinfo ENOTFOUND tokyo.fi.chat", which churned every session).
3256
+ // Swallow it — the relay simply won't allocate/relay over this server.
3257
+ sock.on("error", (e) => this.#debugLog(`turn socket error (${srv.host}): ${e.message}`));
3250
3258
  const client = new TurnClient({
3251
3259
  sock,
3252
3260
  creds: { host: srv.host, port: srv.port, realm: "", username: srv.username, password: srv.password }
@@ -4057,8 +4065,22 @@ export class Peer {
4057
4065
  const r = session.remote;
4058
4066
  const remoteIsSameLan = !!r && isPrivateAddress(r.host) && !isCgnatAddress(r.host) &&
4059
4067
  getPhysicalLanSubnets().some((s) => isInIpv4Subnet(r.host, s));
4060
- if (!remoteIsSameLan)
4068
+ if (!remoteIsSameLan) {
4069
+ // If we ALREADY hold a same-LAN candidate for this peer (learned from
4070
+ // an earlier offer), switch the session onto it NOW — don't wait to
4071
+ // receive yet another offer at exactly the right moment. That delay is
4072
+ // what kept sessions stuck on the public/Tailscale-hairpin path after
4073
+ // the staggered restarts. Then send a keepalive over the LAN so the
4074
+ // peer learns our LAN source and replies over it; the downgrade guard
4075
+ // keeps us there once it sticks.
4076
+ const lanCand = (session.endpointCandidates ?? []).find((c) => isPrivateAddress(c.host) && !isCgnatAddress(c.host) &&
4077
+ getPhysicalLanSubnets().some((s) => isInIpv4Subnet(c.host, s)));
4078
+ if (lanCand) {
4079
+ session.remote = { host: lanCand.host, port: lanCand.port };
4080
+ void this.#sendMessengerPacket(friendId, PACKET_ID_ALIVE, new Uint8Array()).catch(() => undefined);
4081
+ }
4061
4082
  void this.#sendUdpEndpointOffer(friendId).catch(() => undefined);
4083
+ }
4062
4084
  }
4063
4085
  }
4064
4086
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.59",
3
+ "version": "0.1.61",
4
4
  "description": "Pure TypeScript port of Elastos Carrier (toxcore-derived) P2P messaging. DHT, onion routing, TCP relay, FlatBuffers app payloads, Express offline relay. Wire-compatible with iOS Beagle and the Carrier C SDK.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",