@decentnetwork/peer 0.1.118 → 0.1.120

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 +33 -2
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -2566,7 +2566,13 @@ export class Peer {
2566
2566
  dataSecretKey: this.#announceDataKey.secretKey
2567
2567
  });
2568
2568
  if (!routed) {
2569
- this.#debugLog("onion data response decrypt failed");
2569
+ // Log enough to distinguish "sender used a stale data pk from an old
2570
+ // announce entry" from "packet framing we mis-parse" — the temp pk
2571
+ // the sender encrypted to sits at bytes [25..57) in toxcore layout.
2572
+ const pkPreview = Buffer.from(packet.slice(25, 57)).toString("hex").slice(0, 16);
2573
+ this.#debugLog(`onion data response decrypt failed from=${remote.address}:${remote.port} ` +
2574
+ `len=${packet.length} ourDataPk=${Buffer.from(this.#announceDataKey.publicKey).toString("hex").slice(0, 16)} ` +
2575
+ `pkAt25=${pkPreview}`);
2570
2576
  return;
2571
2577
  }
2572
2578
  const onionData = openOnionDataPacket(routed.payload, {
@@ -3163,8 +3169,33 @@ export class Peer {
3163
3169
  return storedNodes;
3164
3170
  }
3165
3171
  waves += 1;
3166
- // Pull the closest unvisited candidates for this wave.
3172
+ // Pull the closest unvisited candidates for this wave. Wave 1 reserves
3173
+ // slots for the BOOTSTRAP nodes: XOR-closest entries in our table are
3174
+ // mostly dead NAT'd peers, so a purely distance-ordered walk burned its
3175
+ // whole deadline before ever asking the only guaranteed-public,
3176
+ // always-on nodes. Announce storage capacity is large (toxcore keeps
3177
+ // ~160 entries, evicting furthest), so in this small network the fleet
3178
+ // WILL store us when asked — and every peer's lookup walk reaches the
3179
+ // fleet, so an announce stored there is universally findable.
3167
3180
  const wave = [];
3181
+ if (waves === 1) {
3182
+ // ALL bootstraps, not a distance-picked subset: only a minority of
3183
+ // the fleet still answers UDP DHT (observed: 1 of 9), and a subset
3184
+ // pick chose 4 dead ones while skipping the live one.
3185
+ const bootstrapIdSet = new Set(this.#opts.bootstrapNodes.map((n) => `${n.host}:${n.port}`));
3186
+ for (let qi = 0; qi < queue.length && wave.length < bootstrapIdSet.size;) {
3187
+ const c = queue[qi];
3188
+ const id = `${c.node.host}:${c.node.port}`;
3189
+ if (bootstrapIdSet.has(id) && !visited.has(id)) {
3190
+ visited.add(id);
3191
+ wave.push(c);
3192
+ queue.splice(qi, 1);
3193
+ }
3194
+ else {
3195
+ qi++;
3196
+ }
3197
+ }
3198
+ }
3168
3199
  while (queue.length > 0 && wave.length < SELF_ANNOUNCE_BATCH_SIZE) {
3169
3200
  const c = queue.shift();
3170
3201
  const id = `${c.node.host}:${c.node.port}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.118",
3
+ "version": "0.1.120",
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",