@decentnetwork/peer 0.1.126 → 0.1.127

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 +17 -8
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -393,8 +393,9 @@ export class Peer {
393
393
  * same friend, and sharing one timestamp would let whichever ran first
394
394
  * suppress the other for a full budget. */
395
395
  #onionLookupCooldown = new Map();
396
- /** Consecutive failed endpoint lookups per (friend,target) drives how wide
397
- * the next fan-out goes. Cleared on success. */
396
+ /** Consecutive failed endpoint lookups per (friend,target). Kept for
397
+ * diagnostics — it no longer narrows the sweep (see the width comment in
398
+ * #discoverAndCacheFriendEndpoint for why that was reverted). */
398
399
  #onionLookupMisses = new Map();
399
400
  // Per-friend cooldown for re-asserting the TCP-relay route toward an
400
401
  // unconnected friend (the "accepted friend that never connects" wedge —
@@ -3114,9 +3115,18 @@ export class Peer {
3114
3115
  // peer that only just came back is still found without waiting for a
3115
3116
  // restart. Widening beats a permanently narrow sweep: the failure we must
3116
3117
  // not introduce is "never discovers", not "discovers a bit later".
3117
- const misses = this.#onionLookupMisses.get(budgetKey) ?? 0;
3118
- const fullWidth = Math.max(8, Math.min(24, MAX_FRIEND_ROUTE_ATTEMPTS));
3119
- const width = misses === 0 || misses % 8 === 0 ? fullWidth : 4;
3118
+ // Width stays FULL. An earlier cut narrowed repeats to 4 nodes and only
3119
+ // went wide every 8th attempt — with the 25s budget that put 200s between
3120
+ // full sweeps, and iOS peers (which come online in short windows and are
3121
+ // the hardest to find at the best of times) stopped being seen at all.
3122
+ // Reported from the field the same day: weili.beagles.eth went offline and
3123
+ // stayed offline.
3124
+ //
3125
+ // Cost here is width x frequency, and the frequency gate above already
3126
+ // took 3s -> 25s, an 8x cut on its own. Narrowing width bought another 6x
3127
+ // and paid for it with the one property this code exists to provide.
3128
+ // Keep the cheap half, drop the expensive one.
3129
+ const width = Math.max(8, Math.min(24, MAX_FRIEND_ROUTE_ATTEMPTS));
3120
3130
  const queue = dedupeNodes(this.#knownNodes.length > 0 ? this.#knownNodes : this.#opts.bootstrapNodes)
3121
3131
  .filter((n) => !this.#isNodeBlacklisted(`${n.host}:${n.port}`))
3122
3132
  .sort((a, b) => this.#nodeScore(`${b.host}:${b.port}`) - this.#nodeScore(`${a.host}:${a.port}`))
@@ -3186,9 +3196,8 @@ export class Peer {
3186
3196
  return true;
3187
3197
  }
3188
3198
  }
3189
- // Nothing found: remember, so the next sweep for this target probes
3190
- // narrowly instead of paying the full 24-node price again.
3191
- this.#onionLookupMisses.set(budgetKey, misses + 1);
3199
+ // Nothing found: count it, for diagnostics only.
3200
+ this.#onionLookupMisses.set(budgetKey, (this.#onionLookupMisses.get(budgetKey) ?? 0) + 1);
3192
3201
  return false;
3193
3202
  }
3194
3203
  async #announceSelfBestEffort(force = false, deadlineMs = Number.POSITIVE_INFINITY) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.126",
3
+ "version": "0.1.127",
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",