@decentnetwork/peer 0.1.115 → 0.1.117

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 +32 -2
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -841,7 +841,24 @@ export class Peer {
841
841
  // reply) makes the hot distance-sort + memory grow without limit; a few
842
842
  // hundred nodes is plenty to stay findable and to announce on the closest.
843
843
  const merged = dedupeNodes([...nodes, ...this.#knownNodes]);
844
- this.#knownNodes = merged.length > MAX_KNOWN_NODES ? merged.slice(0, MAX_KNOWN_NODES) : merged;
844
+ if (merged.length > MAX_KNOWN_NODES) {
845
+ const kept = merged.slice(0, MAX_KNOWN_NODES);
846
+ // Pin the bootstrap nodes. They are the only guaranteed-public,
847
+ // onion-capable nodes we have; newest-first truncation on a busy DHT
848
+ // evicted them within hours, leaving the onion hop pool with only
849
+ // NAT'd/CGNAT peers — every onion path died at hop A, so announce and
850
+ // DHTPK delivery failed for days ("no onion path" / "self announce
851
+ // step1 no response" floods) and natives could never (re)discover us.
852
+ const keptIds = new Set(kept.map((node) => `${node.host}:${node.port}`));
853
+ for (const bn of this.#opts.bootstrapNodes) {
854
+ if (!keptIds.has(`${bn.host}:${bn.port}`))
855
+ kept.push(bn);
856
+ }
857
+ this.#knownNodes = kept;
858
+ }
859
+ else {
860
+ this.#knownNodes = merged;
861
+ }
845
862
  }
846
863
  knownNodes() {
847
864
  return [...this.#knownNodes];
@@ -6176,7 +6193,11 @@ export class Peer {
6176
6193
  const bootstrapIds = new Set(this.#opts.bootstrapNodes.map((node) => `${node.host}:${node.port}`));
6177
6194
  const seenHosts = new Set();
6178
6195
  const seenPublicKeys = new Set();
6179
- for (const node of this.#knownNodes) {
6196
+ // Bootstraps first: the loop below keeps only the FIRST entry per host
6197
+ // (seenHosts), and #knownNodes iterates newest-first — so a just-learned
6198
+ // ephemeral port on a bootstrap's host (e.g. 45.63.127.106:52621, dead)
6199
+ // claimed the host and shadowed the real always-on port (:33445/:443).
6200
+ for (const node of dedupeNodes([...this.#opts.bootstrapNodes, ...this.#knownNodes])) {
6180
6201
  if (!node.pk) {
6181
6202
  continue;
6182
6203
  }
@@ -6184,6 +6205,15 @@ export class Peer {
6184
6205
  if (id === nodeDId || node.host === nodeD.host || seenHosts.has(node.host)) {
6185
6206
  continue;
6186
6207
  }
6208
+ // Onion hops must be PUBLICLY routable: they forward our request onward
6209
+ // and route the response back. A CGNAT (Tailscale 100.64/10), RFC1918,
6210
+ // or own-host address cannot do either from the open internet — yet
6211
+ // such peer endpoints leak into #knownNodes and were being picked as
6212
+ // hop A (observed: 1900+ onion initials sent via a friend's Tailscale
6213
+ // 100.76.x address, all black-holed).
6214
+ if (isPrivateAddress(node.host) || isCgnatAddress(node.host) || isOwnAddress(node.host)) {
6215
+ continue;
6216
+ }
6187
6217
  // Skip blacklisted relays — onion paths through dead nodes
6188
6218
  // silently swallow the request and the announce times out.
6189
6219
  if (this.#isNodeBlacklisted(id)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.115",
3
+ "version": "0.1.117",
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",