@decentnetwork/peer 0.1.21 → 0.1.23

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 +25 -1
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -768,6 +768,7 @@ export class Peer {
768
768
  return;
769
769
  }
770
770
  catch (error) {
771
+ const emsg = error.message;
771
772
  // Mirrors Carrier C SDK behavior: when an in-session send fails
772
773
  // (no transport accepted the encrypted packet), fall through to
773
774
  // the express offline relay rather than dropping the message
@@ -775,7 +776,20 @@ export class Peer {
775
776
  // express pull. Without this the message is just lost when the
776
777
  // friend's NAT briefly forgets us — observed when iPad rebinds
777
778
  // its TCP relay slot, or when UDP and TCP relay both blip.
778
- this.#debugLog(`sendText: in-session send failed for ${pubkey}, falling back to express: ${error.message}`);
779
+ //
780
+ // EXCEPT a "payload too big" failure (>1373 bytes), which is
781
+ // PERMANENT, not transient: it fails identically every retry, so
782
+ // queuing it to express just piles undeliverable oversized blobs
783
+ // into the recipient's offline queue. A dora's oversized roster
784
+ // reply re-sent every 60s produced a 69k-message backlog that made
785
+ // every pull time out — starving real friend-requests. Oversized
786
+ // payloads must be chunked by the caller (the dora now paginates),
787
+ // not flooded through express; drop to the caller instead.
788
+ if (/1\.\.1373 bytes|payload must be 1/i.test(emsg)) {
789
+ this.#debugLog(`sendText: oversized payload for ${pubkey} (${emsg}) — NOT queuing to express (would flood); caller must chunk`);
790
+ throw error;
791
+ }
792
+ this.#debugLog(`sendText: in-session send failed for ${pubkey}, falling back to express: ${emsg}`);
779
793
  }
780
794
  }
781
795
  // Offline / fallback path via Carrier express HTTP store-and-forward.
@@ -1759,6 +1773,16 @@ export class Peer {
1759
1773
  catch {
1760
1774
  return;
1761
1775
  }
1776
+ // Already an established friend? Ignore this (re-)request. Auto-friend
1777
+ // re-sends and reconnect retries pile up offline friend-requests on the
1778
+ // express relay; once we've accepted them, re-emitting would re-run the
1779
+ // accept path and churn. The express pull still ack-deletes the stale R
1780
+ // via its timestamp watermark — we just don't act on it again.
1781
+ const existingFriend = this.#friends.get(fromUserId);
1782
+ if (existingFriend?.acceptedAt || existingFriend?.status === "online") {
1783
+ this.#debugLog(`ignoring offline friend-request from already-accepted friend ${fromUserId}`);
1784
+ return;
1785
+ }
1762
1786
  if (this.#pendingFriendRequests.has(fromUserId)) {
1763
1787
  return;
1764
1788
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
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",