@decentnetwork/peer 0.1.35 → 0.1.36

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 +16 -0
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -332,6 +332,14 @@ export class Peer {
332
332
  session.friendRealPublicKey ??= new Uint8Array(friendKey);
333
333
  this.#friendSessions.set(friendId, session);
334
334
  if (!session.established) {
335
+ // A fresh relay-online signal means the peer just (re)connected —
336
+ // almost always a restart. Clear any accumulated cookie backoff so
337
+ // the connection loop retries the handshake at the 8s base cadence
338
+ // instead of the 120s cap it had grown to while the peer was gone.
339
+ // Without this, a peer that restarts after a long outage sits
340
+ // "online but not established" for up to 2 minutes before the next
341
+ // handshake attempt — the exact cn/callpass post-restart wedge.
342
+ this.#cookieRetryCount.delete(friendId);
335
343
  void this.#initiateSession(friendId).catch(() => { });
336
344
  }
337
345
  });
@@ -1763,6 +1771,14 @@ export class Peer {
1763
1771
  this.#cacheFriendRemote(senderId, knownMatch.host, knownMatch.port, senderPublicKey, friendDhtPublicKey);
1764
1772
  this.#debugLog(`onion dhtpk matched known node for ${senderId} at ${knownMatch.host}:${knownMatch.port}`);
1765
1773
  }
1774
+ // A dhtpk_update is proof the friend is announcing and reachable. If our
1775
+ // session to them isn't established, clear the accumulated cookie backoff
1776
+ // so the connection loop retries the handshake at the base cadence rather
1777
+ // than the up-to-120s cap (mirrors the relay friendOnline reset; covers the
1778
+ // UDP/onion reconnect path after a restart).
1779
+ if (!this.#friendSessions.get(senderId)?.established) {
1780
+ this.#cookieRetryCount.delete(senderId);
1781
+ }
1766
1782
  this.#debugLog(`dhtpk_update friend=${senderId} noReplay=${noReplay.toString()} ` +
1767
1783
  `dhtpk=${carrierIdFromPublicKey(friendDhtPublicKey)} extraLen=${extra.length} ` +
1768
1784
  `extraNodes=${extraNodes.length} extraPreviewHex=${extraPreview}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
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",