@decentnetwork/peer 0.1.120 → 0.1.121

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 +27 -3
  2. package/package.json +1 -1
package/dist/peer.js CHANGED
@@ -5213,7 +5213,11 @@ export class Peer {
5213
5213
  // Prefer DHT key learned from DHTPK updates; fallback to real key.
5214
5214
  const friendDhtPk = session?.friendDhtPublicKey ?? friendRealPk;
5215
5215
  const connectCandidates = this.#collectSessionEndpointCandidates(friendId, friend, session);
5216
- const tcpAvailable = !!this.#tcpRelays?.isFriendOnline(friendRealPk);
5216
+ // Natives are known to the relay by their DHT key, not their identity
5217
+ // key — check both, else tcpAvailable stays false for every native.
5218
+ const dhtKeyForTcp = session?.friendDhtPublicKey ?? this.#friendDhtKeys.get(friendId);
5219
+ const tcpAvailable = !!this.#tcpRelays?.isFriendOnline(friendRealPk) ||
5220
+ (!!dhtKeyForTcp && !!this.#tcpRelays?.isFriendOnline(dhtKeyForTcp));
5217
5221
  if (connectCandidates.length === 0 && !tcpAvailable) {
5218
5222
  this.#debugLog(`initiate session: no known endpoint for ${friendId} yet`);
5219
5223
  return false;
@@ -5354,8 +5358,28 @@ export class Peer {
5354
5358
  }
5355
5359
  // Also send via TCP relay if available, in parallel. Whichever
5356
5360
  // arrives at the friend first triggers their cookie response.
5357
- if (tcpAvailable && this.#tcpRelays) {
5358
- tcpSent = this.#tcpRelays.sendToFriend(friendRealPk, packet);
5361
+ // Route/notify state at the relay is keyed by the key the FRIEND
5362
+ // handshook the relay with — for natives that's their (rotated) DHT
5363
+ // key, NOT their identity key. The old real-pk-only calls meant
5364
+ // tcpAvailable was never true for a native and the routed send would
5365
+ // have gone to a key the relay didn't know (tcp=0 forever while both
5366
+ // ends sat on the same relay).
5367
+ if (this.#tcpRelays) {
5368
+ const tcpKey = session.friendDhtPublicKey ?? friendRealPk;
5369
+ if (this.#tcpRelays.isFriendOnline(tcpKey) || this.#tcpRelays.isFriendOnline(friendRealPk)) {
5370
+ tcpSent = this.#tcpRelays.sendToFriend(tcpKey, packet);
5371
+ if (tcpSent === 0 && tcpKey !== friendRealPk) {
5372
+ tcpSent = this.#tcpRelays.sendToFriend(friendRealPk, packet);
5373
+ }
5374
+ }
5375
+ // OOB fallback: needs no route/cid — the relay forwards to any
5376
+ // connected client by key, and toxcore's oob handler accepts cookie
5377
+ // requests (0x18). This is exactly how the iOS side reaches US when
5378
+ // only a shared relay exists; without the mirror-image our own
5379
+ // initiation had no TCP path until a route linked.
5380
+ if (tcpSent === 0) {
5381
+ tcpSent = this.#tcpRelays.sendOobToFriend(tcpKey, packet);
5382
+ }
5359
5383
  }
5360
5384
  if (sent === 0 && tcpSent === 0 && selfSent === 0) {
5361
5385
  throw new Error("no cookie request packet was sent");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.120",
3
+ "version": "0.1.121",
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",