@decentnetwork/peer 0.1.3 → 0.1.4

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.
package/dist/peer.d.ts CHANGED
@@ -71,6 +71,28 @@ export declare class Peer {
71
71
  hasTcpRoute: boolean;
72
72
  transport: "udp" | "tcp-relay" | "both" | "none";
73
73
  lastPingRecvMs: number | null;
74
+ /** OS-assigned UDP port THIS node is listening on. Useful to confirm
75
+ * we even have a UDP socket bound. */
76
+ ourLocalUdpPort: number | null;
77
+ /** Cached UDP endpoint for the peer from a previous online state
78
+ * (persisted across restarts). Set != null means UDP holepunch
79
+ * has succeeded at some point — but null when we've only ever
80
+ * reached them via TCP-relay. Tells us whether discovery has
81
+ * ever found a usable UDP endpoint. */
82
+ friendUdpEndpoint: {
83
+ host: string;
84
+ port: number;
85
+ } | null;
86
+ /** UDP endpoints picked up by recent DHT discovery for this peer,
87
+ * whether or not the cookie exchange has succeeded yet. If this
88
+ * is empty AND friendUdpEndpoint is null AND we keep getting
89
+ * tcp-relay, discovery itself is broken — we don't even know
90
+ * where to send a cookie request. */
91
+ endpointCandidatesCount: number;
92
+ /** Last time we sent an outbound cookie request via UDP for this
93
+ * peer (null = never). Used to confirm Phase 1.2 retries are
94
+ * actually firing. */
95
+ cookieRequestSentMs: number | null;
74
96
  } | null;
75
97
  waitForFriendRequest(timeoutMs?: number): Promise<FriendRequest>;
76
98
  }
package/dist/peer.js CHANGED
@@ -772,6 +772,7 @@ export class Peer {
772
772
  const s = this.#friendSessions.get(pubkey);
773
773
  if (!s)
774
774
  return null;
775
+ const friend = this.#friends.get(pubkey);
775
776
  // session.remote can be a synthetic `tcp:<dhtpk>:0` placeholder
776
777
  // when the TCP relay path reports an endpoint with no real UDP
777
778
  // address; treat those as no-UDP for reporting.
@@ -785,12 +786,22 @@ export class Peer {
785
786
  : s.hasTcpRoute
786
787
  ? "tcp-relay"
787
788
  : "none";
789
+ const friendUdp = friend?.remoteHost &&
790
+ friend.remotePort &&
791
+ !friend.remoteHost.startsWith("tcp:") &&
792
+ friend.remotePort !== 0
793
+ ? { host: friend.remoteHost, port: friend.remotePort }
794
+ : null;
788
795
  return {
789
796
  established: s.established === true,
790
797
  udpRemote: realUdp,
791
798
  hasTcpRoute: s.hasTcpRoute === true,
792
799
  transport,
793
800
  lastPingRecvMs: s.lastPingRecvMs ?? null,
801
+ ourLocalUdpPort: this.#udp?.localPort() ?? null,
802
+ friendUdpEndpoint: friendUdp,
803
+ endpointCandidatesCount: s.endpointCandidates?.length ?? 0,
804
+ cookieRequestSentMs: s.cookieRequestSentMs ?? null,
794
805
  };
795
806
  }
796
807
  waitForFriendRequest(timeoutMs = 30000) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
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",