@decentnetwork/peer 0.1.85 → 0.1.86

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
@@ -45,6 +45,11 @@ export declare class Peer {
45
45
  selfAnnounceStoredOn: number;
46
46
  udpLocalPort: number | null;
47
47
  tcpRelayConnected: number;
48
+ /** TCP-relay onion diagnostics: requests handed to relays / responses
49
+ * routed back. If sent>0 but recv=0, relays aren't returning onion
50
+ * responses (relay doesn't forward, or wire mismatch). */
51
+ tcpOnionSent: number;
52
+ tcpOnionRecv: number;
48
53
  /** The specific relay endpoints this peer has live connections to.
49
54
  * Lets us compare two peers' relay sets — if there's NO overlap,
50
55
  * net_crypto handshake packets between them have nowhere to route
package/dist/peer.js CHANGED
@@ -280,6 +280,12 @@ export class Peer {
280
280
  // 25s forever for stale persisted entries.
281
281
  #dhtPkConsecutiveFailures = new Map();
282
282
  #lastSelfAnnounceStoredCount = -1;
283
+ // Diagnostics for the TCP-relay onion path (announce/discovery over TCP).
284
+ // Surfaced in dhtHealth so `agentnet diag` shows whether it's active without
285
+ // needing verbose logs: sent = onion requests handed to relays, recv = onion
286
+ // responses routed back over TCP.
287
+ #diagTcpOnionSent = 0;
288
+ #diagTcpOnionRecv = 0;
283
289
  // Per-friend last-logged route count from #discoverFriendRoutes so we
284
290
  // only emit a "routes=N for friend=…" debug line when it changes.
285
291
  #lastLoggedRoutesForFriend = new Map();
@@ -521,6 +527,8 @@ export class Peer {
521
527
  this.#tcpRelays.on("onionResponse", (packet) => {
522
528
  if (packet.length === 0)
523
529
  return;
530
+ this.#diagTcpOnionRecv += 1;
531
+ this.#debugVerboseLog(`tcp onion response received (${packet.length} bytes, type=${packet[0]})`);
524
532
  this.#udp.emit("datagram", {
525
533
  data: Buffer.from(packet),
526
534
  remote: { address: "tcp-relay", port: 0 },
@@ -686,6 +694,8 @@ export class Peer {
686
694
  selfAnnounceStoredOn: this.#lastSelfAnnounceStoredCount,
687
695
  udpLocalPort: this.#udp?.localPort() ?? null,
688
696
  tcpRelayConnected: relays.length,
697
+ tcpOnionSent: this.#diagTcpOnionSent,
698
+ tcpOnionRecv: this.#diagTcpOnionRecv,
689
699
  tcpRelayEndpoints: relays.map((r) => ({ host: r.host, port: r.port })),
690
700
  };
691
701
  }
@@ -5279,7 +5289,11 @@ export class Peer {
5279
5289
  nodeDPort: nodeD.port,
5280
5290
  payloadForNodeD
5281
5291
  });
5282
- this.#tcpRelays.sendOnionRequest(tcpPacket);
5292
+ const sent = this.#tcpRelays.sendOnionRequest(tcpPacket);
5293
+ if (sent > 0) {
5294
+ this.#diagTcpOnionSent += 1;
5295
+ this.#debugVerboseLog(`tcp onion request sent via ${sent} relay(s) to ${nodeD.host}:${nodeD.port} (B=${path.nodeB.host} C=${path.nodeC.host})`);
5296
+ }
5283
5297
  }
5284
5298
  catch {
5285
5299
  /* malformed path node key — the UDP attempt above still stands */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.85",
3
+ "version": "0.1.86",
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",