@decentnetwork/peer 0.1.27 → 0.1.29

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 +20 -2
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -551,7 +551,25 @@ export class Peer {
551
551
  if (this.#selfAnnouncePromise) {
552
552
  await this.#selfAnnouncePromise.catch(() => { });
553
553
  }
554
- await this.#announceSelfBestEffort(false, Date.now() + 4000);
554
+ // An onion friend-request only has a return path once OUR OWN announce
555
+ // has actually STORED on the DHT. The old code fired a single 4s
556
+ // best-effort announce and pushed on regardless — so a request sent
557
+ // before the announce propagated (right after join, DHT not yet settled)
558
+ // had nowhere for the reply to come back and silently failed. That, not
559
+ // Carrier, is why client→exit friend-requests never landed. Match the C
560
+ // SDK: keep announcing until at least one node stores us (up to ~8s)
561
+ // before sending. If it genuinely never stores, we fall through to the
562
+ // express fallback below — but normally it stores within a couple of
563
+ // seconds and the plain onion friend-request just works.
564
+ const announceDeadline = Date.now() + 8000;
565
+ while (this.#lastSelfAnnounceStoredCount === 0 &&
566
+ Date.now() < announceDeadline) {
567
+ await this.#announceSelfBestEffort(true, Math.min(Date.now() + 3000, announceDeadline));
568
+ if (this.#lastSelfAnnounceStoredCount > 0)
569
+ break;
570
+ await sleep(500);
571
+ }
572
+ this.#debugLog(`friend-request: announce stored on ${this.#lastSelfAnnounceStoredCount} node(s) before send`);
555
573
  const appPayload = encodeFriendRequestPacket({
556
574
  name: PEER_NICKNAME,
557
575
  descr: PEER_STATUS_MESSAGE || "decent peer",
@@ -634,7 +652,7 @@ export class Peer {
634
652
  throw new Error(`friend request dispatch failed: ${errors.join("; ")}`);
635
653
  }
636
654
  this.#lastFriendRequestDispatch = {
637
- transport: sent > 0 ? "onion" : "express",
655
+ transport: sent > 0 ? "onion" : "direct",
638
656
  routes: routes.length,
639
657
  targets: sent
640
658
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
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",