@decentnetwork/peer 0.1.26 → 0.1.27

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 +21 -8
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -611,20 +611,33 @@ export class Peer {
611
611
  errors.push(`${route.node.host}:${route.node.port} ${error.message}`);
612
612
  }
613
613
  }
614
- if (sent === 0) {
614
+ // Record locally so the connection loop keeps retrying, then ALWAYS
615
+ // queue via express — even when every onion send failed. Onion delivery
616
+ // is unreliable (broken DHT onion-announce), and the old code threw on
617
+ // `sent === 0` BEFORE this express fallback ran, so a friend-request to
618
+ // a peer with stale-but-dead onion routes was silently dropped: the node
619
+ // "sent" it, nothing reached the relay, the recipient never friended
620
+ // back, and the session could never bridge. That stranded 2nd/3rd exits.
621
+ this.#recordOutgoingFriendRequest(friendId, pubkey, friendAddress.nospam, hello);
622
+ let expressOk = false;
623
+ if (this.#express?.hasNodes()) {
624
+ try {
625
+ await this.#express.sendOfflineFriendRequest(pubkey, appPayload);
626
+ expressOk = true;
627
+ }
628
+ catch (error) {
629
+ this.#debugLog(`offline friend request dispatch failed: ${error.message}`);
630
+ }
631
+ }
632
+ // Only a true failure if BOTH transports got nothing out.
633
+ if (sent === 0 && !expressOk) {
615
634
  throw new Error(`friend request dispatch failed: ${errors.join("; ")}`);
616
635
  }
617
636
  this.#lastFriendRequestDispatch = {
618
- transport: "onion",
637
+ transport: sent > 0 ? "onion" : "express",
619
638
  routes: routes.length,
620
639
  targets: sent
621
640
  };
622
- this.#recordOutgoingFriendRequest(friendId, pubkey, friendAddress.nospam, hello);
623
- if (this.#express?.hasNodes()) {
624
- void this.#express.sendOfflineFriendRequest(pubkey, appPayload).catch((error) => {
625
- this.#debugLog(`offline friend request dispatch failed: ${error.message}`);
626
- });
627
- }
628
641
  }
629
642
  finally {
630
643
  resumeSelfAnnounce();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
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",