@decentnetwork/lan 0.1.49 → 0.1.51

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.
@@ -180,6 +180,7 @@ export class PeerManager extends EventEmitter {
180
180
  address: friend.address,
181
181
  lastSeen: friend.acceptedAt,
182
182
  acceptedAt: friend.acceptedAt,
183
+ requestedAt: friend.requestedAt,
183
184
  };
184
185
  });
185
186
  }
@@ -673,6 +673,7 @@ export async function cmdFriendsList(args) {
673
673
  status: f.status,
674
674
  address: f.address,
675
675
  acceptedAt: f.acceptedAt,
676
+ requestedAt: f.requestedAt,
676
677
  }));
677
678
  await peer.stop();
678
679
  source = "disk";
@@ -681,16 +682,43 @@ export async function cmdFriendsList(args) {
681
682
  console.log("No friends. Use 'agentnet friend-request --address <addr>' to add one.");
682
683
  return;
683
684
  }
685
+ // A friend we only friend-requested (status "requested") has no name in
686
+ // the local SDK record yet — but the dora roster knows it. Cross-reference
687
+ // live IPAM so the list shows "cn", "mac-dev", … instead of "(unnamed)".
688
+ const ipamNames = new Map();
689
+ try {
690
+ const { peers } = await fetchLiveIpam(config);
691
+ for (const p of peers) {
692
+ if (p.carrierId && p.name)
693
+ ipamNames.set(p.carrierId, p.name);
694
+ }
695
+ }
696
+ catch {
697
+ // IPAM unavailable (daemon down / no dora) — fall back to (unnamed).
698
+ }
699
+ const ago = (ms) => {
700
+ const s = Math.max(0, Math.round((Date.now() - ms) / 1000));
701
+ if (s < 60)
702
+ return `${s}s ago`;
703
+ if (s < 3600)
704
+ return `${Math.round(s / 60)}m ago`;
705
+ if (s < 86400)
706
+ return `${Math.round(s / 3600)}h ago`;
707
+ return `${Math.round(s / 86400)}d ago`;
708
+ };
684
709
  console.log(`Friends (${friends.length}) ${source === "daemon" ? "[live]" : "[disk]"}:`);
685
710
  for (const friend of friends) {
686
- console.log(``);
687
- console.log(` ${friend.name || "(unnamed)"} status=${friend.status}`);
688
711
  const userid = friend.carrierId || friend.pubkey;
712
+ const name = friend.name || ipamNames.get(userid) || "(unnamed)";
713
+ console.log(``);
714
+ console.log(` ${name} status=${friend.status}`);
689
715
  console.log(` userid: ${userid}`);
690
716
  if (friend.address)
691
717
  console.log(` address: ${friend.address}`);
718
+ if (friend.requestedAt)
719
+ console.log(` requested: ${new Date(friend.requestedAt).toISOString()} (${ago(friend.requestedAt)})`);
692
720
  if (friend.acceptedAt)
693
- console.log(` accepted: ${new Date(friend.acceptedAt).toISOString()}`);
721
+ console.log(` accepted: ${new Date(friend.acceptedAt).toISOString()} (${ago(friend.acceptedAt)})`);
694
722
  }
695
723
  }
696
724
  /**
@@ -35,11 +35,21 @@ export declare class DaemonServer {
35
35
  private pendingFriends?;
36
36
  private startedAt;
37
37
  private isRunning;
38
+ private statusTimer?;
38
39
  private pidFile?;
39
40
  private configDir;
40
41
  constructor(opts: DaemonOptions);
41
42
  start(): Promise<void>;
42
43
  stop(): Promise<void>;
44
+ /**
45
+ * Periodic one-line peer-connection summary at INFO. Between the
46
+ * startup block and the first friend flipping online the log is
47
+ * otherwise silent — which looks like the daemon is idle when it's
48
+ * actually retrying handshakes (those are only logged at debug). This
49
+ * line shows, every 30s, who's connected vs. still connecting so an
50
+ * operator can see it IS working without enabling DECENT_DEBUG.
51
+ */
52
+ private startPeerStatusSummary;
43
53
  getStatus(): DaemonStatus;
44
54
  /**
45
55
  * Periodically poke the SDK to (re-)initiate a session with the friend.
@@ -52,6 +52,7 @@ export class DaemonServer {
52
52
  pendingFriends;
53
53
  startedAt = 0;
54
54
  isRunning = false;
55
+ statusTimer;
55
56
  pidFile;
56
57
  configDir;
57
58
  constructor(opts) {
@@ -576,6 +577,7 @@ export class DaemonServer {
576
577
  }
577
578
  this.isRunning = true;
578
579
  this.logger.info("Daemon started successfully");
580
+ this.startPeerStatusSummary();
579
581
  }
580
582
  catch (error) {
581
583
  this.logger.error("Failed to start daemon:", error);
@@ -591,6 +593,41 @@ export class DaemonServer {
591
593
  await this.cleanup();
592
594
  this.logger.info("Daemon stopped");
593
595
  }
596
+ /**
597
+ * Periodic one-line peer-connection summary at INFO. Between the
598
+ * startup block and the first friend flipping online the log is
599
+ * otherwise silent — which looks like the daemon is idle when it's
600
+ * actually retrying handshakes (those are only logged at debug). This
601
+ * line shows, every 30s, who's connected vs. still connecting so an
602
+ * operator can see it IS working without enabling DECENT_DEBUG.
603
+ */
604
+ startPeerStatusSummary() {
605
+ const label = (p) => {
606
+ const id = p.carrierId || p.pubkey;
607
+ return p.name || this.ipam?.resolveCarrierId(id)?.name || `${id.slice(0, 8)}…`;
608
+ };
609
+ const tick = () => {
610
+ if (!this.isRunning || !this.peerManager)
611
+ return;
612
+ let peers;
613
+ try {
614
+ peers = this.peerManager.getFriends();
615
+ }
616
+ catch {
617
+ return;
618
+ }
619
+ if (peers.length === 0)
620
+ return;
621
+ const online = peers.filter((p) => p.status === "online");
622
+ const connecting = peers.filter((p) => p.status !== "online");
623
+ const fmt = (list) => list.length === 0 ? "none" : list.map(label).join(", ");
624
+ this.logger.info(`Peers: ${online.length} connected (${fmt(online)}) · ` +
625
+ `${connecting.length} connecting (${fmt(connecting)})`);
626
+ };
627
+ // First summary shortly after startup, then every 30s.
628
+ setTimeout(tick, 5_000);
629
+ this.statusTimer = setInterval(tick, 30_000);
630
+ }
594
631
  getStatus() {
595
632
  return {
596
633
  isRunning: this.isRunning,
@@ -681,6 +718,10 @@ export class DaemonServer {
681
718
  return this.doraIntegration;
682
719
  }
683
720
  async cleanup() {
721
+ if (this.statusTimer) {
722
+ clearInterval(this.statusTimer);
723
+ this.statusTimer = undefined;
724
+ }
684
725
  try {
685
726
  if (this.dnsServer) {
686
727
  await this.dnsServer.stop();
package/dist/types.d.ts CHANGED
@@ -23,6 +23,8 @@ export interface RemotePeer {
23
23
  address?: string;
24
24
  lastSeen?: number;
25
25
  acceptedAt?: number;
26
+ /** When we sent the outbound friend-request (ms epoch). */
27
+ requestedAt?: number;
26
28
  }
27
29
  export interface FriendConnectionEvent {
28
30
  pubkey: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/lan",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "description": "Private virtual LAN for self-hosted services and AI agents, built on Elastos Carrier. NAT-traversal, name service, ACL, all over a peer-to-peer mesh — no public IP required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@decentnetwork/dora": "^0.1.6",
78
- "@decentnetwork/peer": "^0.1.20",
78
+ "@decentnetwork/peer": "^0.1.21",
79
79
  "js-yaml": "^4.1.0",
80
80
  "yargs": "^17.7.2"
81
81
  },