@decentnetwork/peer 0.1.5 → 0.1.6

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
@@ -13,6 +13,31 @@ export declare class Peer {
13
13
  joinNetwork(): Promise<BootstrapResult>;
14
14
  lookup(pubkey: string): Promise<LookupResult>;
15
15
  announceSelf(timeoutMs?: number): Promise<NetworkNode[]>;
16
+ /**
17
+ * Aggregate DHT health snapshot — surfaces the layers that have to
18
+ * work for UDP holepunch / route discovery to succeed.
19
+ * bootstrapsConfigured – nodes the SDK is allowed to talk to
20
+ * knownNodesCount – nodes discovered or persisted in our DHT view
21
+ * lastSelfAnnounceMs – last time we ran a self-announce sweep
22
+ * selfAnnounceStoredOn – how many nodes acknowledged STORING our
23
+ * announce last time. **If 0, our outbound
24
+ * DHT is broken** — peers can't find us,
25
+ * #discoverFriendRoutes returns nothing,
26
+ * UDP holepunch is impossible. Most common
27
+ * failure mode when sessions stay on
28
+ * tcp-relay forever.
29
+ * udpLocalPort – the OS-assigned UDP port (null = no socket)
30
+ * tcpRelayConnected – fallback relay path; if >0, sessions get
31
+ * through even when DHT is dead.
32
+ */
33
+ dhtHealth(): {
34
+ bootstrapsConfigured: number;
35
+ knownNodesCount: number;
36
+ lastSelfAnnounceMs: number;
37
+ selfAnnounceStoredOn: number;
38
+ udpLocalPort: number | null;
39
+ tcpRelayConnected: number;
40
+ };
16
41
  addKnownNodes(nodes: NetworkNode[]): void;
17
42
  knownNodes(): NetworkNode[];
18
43
  sendFriendRequest(pubkey: string, hello?: string): Promise<void>;
package/dist/peer.js CHANGED
@@ -434,6 +434,33 @@ export class Peer {
434
434
  async announceSelf(timeoutMs = 15000) {
435
435
  return this.#runSelfAnnounce(true, Date.now() + timeoutMs);
436
436
  }
437
+ /**
438
+ * Aggregate DHT health snapshot — surfaces the layers that have to
439
+ * work for UDP holepunch / route discovery to succeed.
440
+ * bootstrapsConfigured – nodes the SDK is allowed to talk to
441
+ * knownNodesCount – nodes discovered or persisted in our DHT view
442
+ * lastSelfAnnounceMs – last time we ran a self-announce sweep
443
+ * selfAnnounceStoredOn – how many nodes acknowledged STORING our
444
+ * announce last time. **If 0, our outbound
445
+ * DHT is broken** — peers can't find us,
446
+ * #discoverFriendRoutes returns nothing,
447
+ * UDP holepunch is impossible. Most common
448
+ * failure mode when sessions stay on
449
+ * tcp-relay forever.
450
+ * udpLocalPort – the OS-assigned UDP port (null = no socket)
451
+ * tcpRelayConnected – fallback relay path; if >0, sessions get
452
+ * through even when DHT is dead.
453
+ */
454
+ dhtHealth() {
455
+ return {
456
+ bootstrapsConfigured: this.#opts.bootstrapNodes.length,
457
+ knownNodesCount: this.#knownNodes.length,
458
+ lastSelfAnnounceMs: this.#lastSelfAnnounceMs,
459
+ selfAnnounceStoredOn: this.#lastSelfAnnounceStoredCount,
460
+ udpLocalPort: this.#udp?.localPort() ?? null,
461
+ tcpRelayConnected: this.#tcpRelays?.connectedRelays(99).length ?? 0,
462
+ };
463
+ }
437
464
  addKnownNodes(nodes) {
438
465
  this.#knownNodes = dedupeNodes([...nodes, ...this.#knownNodes]);
439
466
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
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",