@decentnetwork/peer 0.1.19 → 0.1.20

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 +27 -0
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -188,6 +188,10 @@ export class Peer {
188
188
  // session entry exists yet so the connection loop does not flood DHT-PK
189
189
  // requests when route discovery keeps failing.
190
190
  #dhtPkSendCooldown = new Map();
191
+ // Per-friend cooldown for re-asserting the TCP-relay route toward an
192
+ // unconnected friend (the "accepted friend that never connects" wedge —
193
+ // requestRoute only fired once at startup and was never retried).
194
+ #routeRequestCooldown = new Map();
191
195
  // Per-friend consecutive "no routes available" count for DHT-PK so the
192
196
  // backoff grows if a friend stays unreachable, instead of retrying every
193
197
  // 25s forever for stale persisted entries.
@@ -2387,6 +2391,29 @@ export class Peer {
2387
2391
  // nothing re-tried it. Counting the relay route lets the retry fire.
2388
2392
  const haveEndpoint = (friend.remoteHost && friend.remotePort) || session?.remote || session?.hasTcpRoute;
2389
2393
  if (!haveEndpoint) {
2394
+ // No UDP endpoint AND no relay route yet. For a peer whose DHT
2395
+ // self-announce never stored (WSL2, symmetric NAT, restrictive
2396
+ // firewall), neither onion discovery nor UDP punch can ever find
2397
+ // them — the ONLY bootstrap is the TCP relay: ask our relays to
2398
+ // route to the friend's pubkey, and when they're also connected to
2399
+ // a shared relay the pool fires `friendOnline` -> #initiateSession.
2400
+ // requestRoute was only issued once at start(); if the friend or a
2401
+ // relay wasn't connected in that instant it was never retried, so an
2402
+ // accepted friend could sit at "requested" forever (the WSL-client-
2403
+ // never-gets-an-IP bug). Re-assert it here on a cooldown — cheap and
2404
+ // idempotent — so it eventually catches once both ends share a relay.
2405
+ const lastRouteReq = this.#routeRequestCooldown.get(friendId) ?? 0;
2406
+ if (this.#tcpRelays && now - lastRouteReq > 15_000) {
2407
+ try {
2408
+ const pk = base58ToBytes(friend.pubkey);
2409
+ if (pk.length === 32) {
2410
+ this.#tcpRelays.requestRoute(pk);
2411
+ this.#routeRequestCooldown.set(friendId, now);
2412
+ this.#debugLog(`re-requesting relay route for unconnected friend ${friendId}`);
2413
+ }
2414
+ }
2415
+ catch { /* skip malformed pubkey */ }
2416
+ }
2390
2417
  const dhtPk = session?.friendDhtPublicKey;
2391
2418
  if (dhtPk) {
2392
2419
  const found = await this.#discoverAndCacheFriendEndpoint(friendId, dhtPk).catch(() => false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
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",