@ghostlytools/cli 1.10.3 → 1.10.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.
Files changed (89) hide show
  1. package/dist/assets/{api-BdaxsDvA.js → api-DgS7f5TT.js} +2 -2
  2. package/dist/assets/{api-C4MLg5Rs.js → api-DkcMOWLX.js} +12 -12
  3. package/dist/assets/api-DkcMOWLX.js.map +1 -0
  4. package/dist/assets/{apiKit-BbNaxZGZ.js → apiKit-D6Oj-vFx.js} +2 -2
  5. package/dist/assets/{apiKit-BbNaxZGZ.js.map → apiKit-D6Oj-vFx.js.map} +1 -1
  6. package/dist/assets/{apps-BluQgEhv.js → apps-B22SeD6T.js} +3 -3
  7. package/dist/assets/{apps-BluQgEhv.js.map → apps-B22SeD6T.js.map} +1 -1
  8. package/dist/assets/{apps-BtGFth7o.js → apps-DgALLHzS.js} +1 -1
  9. package/dist/assets/{arkade-DdZx4b_I.js → arkade-D5cPr_dV.js} +2 -2
  10. package/dist/assets/{arkade-DdZx4b_I.js.map → arkade-D5cPr_dV.js.map} +1 -1
  11. package/dist/assets/{backup-I1n7ccz7.js → backup-DndsW2uX.js} +1 -1
  12. package/dist/assets/{backup-DyDsW7sC.js → backup-dzJLzg-k.js} +6 -6
  13. package/dist/assets/{backup-DyDsW7sC.js.map → backup-dzJLzg-k.js.map} +1 -1
  14. package/dist/assets/{blobFiles-BnjN_Vrz.js → blobFiles-XZ9PEXYy.js} +2 -2
  15. package/dist/assets/{blobFiles-BnjN_Vrz.js.map → blobFiles-XZ9PEXYy.js.map} +1 -1
  16. package/dist/assets/{buttons-Do7dCku6.js → buttons-ByKT_vP8.js} +3 -3
  17. package/dist/assets/{buttons-Do7dCku6.js.map → buttons-ByKT_vP8.js.map} +1 -1
  18. package/dist/assets/buttons-TVCNj280.js +2 -0
  19. package/dist/assets/{client-CWsjRiH8.js → client-q7dVOtYb.js} +10 -4
  20. package/dist/assets/client-q7dVOtYb.js.map +1 -0
  21. package/dist/assets/{codec-DPaXhuYc.js → codec-HD6iOn_D.js} +2 -2
  22. package/dist/assets/{codec-DPaXhuYc.js.map → codec-HD6iOn_D.js.map} +1 -1
  23. package/dist/assets/{envelope-5Gu9yGk_.js → envelope-C-0tfbOG.js} +2 -2
  24. package/dist/assets/{envelope-5Gu9yGk_.js.map → envelope-C-0tfbOG.js.map} +1 -1
  25. package/dist/assets/{fileBytes-DjBYYyXT.js → fileBytes-BABGEF13.js} +2 -2
  26. package/dist/assets/{fileBytes-DjBYYyXT.js.map → fileBytes-BABGEF13.js.map} +1 -1
  27. package/dist/assets/{fileBytes-DMzrIdCu.js → fileBytes-CQQK2uOh.js} +1 -1
  28. package/dist/assets/{fileBytes-Douk1yOp.js → fileBytes-DqnfKIkj.js} +2 -2
  29. package/dist/assets/{fileBytes-Douk1yOp.js.map → fileBytes-DqnfKIkj.js.map} +1 -1
  30. package/dist/assets/fileBytesIdb-BtXATa7j.js +2 -0
  31. package/dist/assets/{fileBytesIdb-CkClu9YI.js → fileBytesIdb-DrXmDUSy.js} +2 -2
  32. package/dist/assets/{fileBytesIdb-CkClu9YI.js.map → fileBytesIdb-DrXmDUSy.js.map} +1 -1
  33. package/dist/assets/{fileBytesOpfs-WryQuOgK.js → fileBytesOpfs-udKCzcLe.js} +6 -9
  34. package/dist/assets/{fileBytesOpfs-WryQuOgK.js.map → fileBytesOpfs-udKCzcLe.js.map} +1 -1
  35. package/dist/assets/{fixedHosts-PR1BcfKX.js → fixedHosts-CN3CsslV.js} +3 -3
  36. package/dist/assets/{fixedHosts-PR1BcfKX.js.map → fixedHosts-CN3CsslV.js.map} +1 -1
  37. package/dist/assets/{groupFiles-BuToTMUk.js → groupFiles-BFv9K_za.js} +104 -81
  38. package/dist/assets/groupFiles-BFv9K_za.js.map +1 -0
  39. package/dist/assets/{host-fkQYBvKH.js → host-C-wwtVt2.js} +162 -41
  40. package/dist/assets/host-C-wwtVt2.js.map +1 -0
  41. package/dist/assets/{hyperdhtRelay-DDCak5PY.js → hyperdhtRelay-B9EQTm_M.js} +2 -2
  42. package/dist/assets/{hyperdhtRelay-DDCak5PY.js.map → hyperdhtRelay-B9EQTm_M.js.map} +1 -1
  43. package/dist/assets/{irohWeb-B4_swKx0.js → irohWeb-o0H_NlCF.js} +2 -2
  44. package/dist/assets/{irohWeb-B4_swKx0.js.map → irohWeb-o0H_NlCF.js.map} +1 -1
  45. package/dist/assets/{main-ClYsttvY.js → main-CLUIPy4d.js} +19 -19
  46. package/dist/assets/{main-ClYsttvY.js.map → main-CLUIPy4d.js.map} +1 -1
  47. package/dist/assets/{mainline-Hsk2SZ1B.js → mainline-B2qmNsib.js} +94 -2
  48. package/dist/assets/mainline-B2qmNsib.js.map +1 -0
  49. package/dist/assets/{networkReason-C9Hr-hO7.js → networkReason-BEl-DDWd.js} +3 -3
  50. package/dist/assets/{networkReason-C9Hr-hO7.js.map → networkReason-BEl-DDWd.js.map} +1 -1
  51. package/dist/assets/{nwc-BbK6qNxS.js → nwc-BNkhjJHN.js} +3 -3
  52. package/dist/assets/{nwc-BbK6qNxS.js.map → nwc-BNkhjJHN.js.map} +1 -1
  53. package/dist/assets/{nwcProvider-D_tt2X3Z.js → nwcProvider-CvaRJdHT.js} +2 -2
  54. package/dist/assets/{nwcProvider-D_tt2X3Z.js.map → nwcProvider-CvaRJdHT.js.map} +1 -1
  55. package/dist/assets/{ownDid-DkK_jem4.js → ownDid-D67KNdJq.js} +3 -2
  56. package/dist/assets/ownDid-D67KNdJq.js.map +1 -0
  57. package/dist/assets/{profiles-aV9vaK0B.js → profiles-QDB7V_Qt.js} +3 -3
  58. package/dist/assets/{profiles-aV9vaK0B.js.map → profiles-QDB7V_Qt.js.map} +1 -1
  59. package/dist/assets/{registry-CEjnubep.js → registry-BKkSnpjL.js} +123 -17
  60. package/dist/assets/registry-BKkSnpjL.js.map +1 -0
  61. package/dist/assets/{registry-C9T6tYCO.js → registry-DN5a8Ul6.js} +1 -1
  62. package/dist/assets/{resolve-BBOrN13E.js → resolve-DhpAggDP.js} +2 -2
  63. package/dist/assets/{resolve-BBOrN13E.js.map → resolve-DhpAggDP.js.map} +1 -1
  64. package/dist/assets/{server-BJ3T-kx3.js → server-7w2O5wsv.js} +722 -183
  65. package/dist/assets/server-7w2O5wsv.js.map +1 -0
  66. package/dist/assets/{src-BIdfHB7t.js → src-BZkY6N3J.js} +668 -140
  67. package/dist/assets/src-BZkY6N3J.js.map +1 -0
  68. package/dist/assets/{sshForges-CRg-NGld.js → sshForges-Cxjt3c51.js} +2 -2
  69. package/dist/assets/{sshForges-CRg-NGld.js.map → sshForges-Cxjt3c51.js.map} +1 -1
  70. package/dist/assets/{translate-b0X61WMI.js → translate-v8wF1GcF.js} +2 -2
  71. package/dist/assets/{translate-b0X61WMI.js.map → translate-v8wF1GcF.js.map} +1 -1
  72. package/dist/assets/{usdt-6CQdfye1.js → usdt-63gYjM5E.js} +3 -3
  73. package/dist/assets/{usdt-6CQdfye1.js.map → usdt-63gYjM5E.js.map} +1 -1
  74. package/dist/assets/{words-Dk6o6wz4.js → words-PUnyO4ph.js} +3 -3
  75. package/dist/assets/words-PUnyO4ph.js.map +1 -0
  76. package/dist/ghostly.mjs +1 -1
  77. package/package.json +1 -1
  78. package/dist/assets/api-C4MLg5Rs.js.map +0 -1
  79. package/dist/assets/buttons-DpjwXePb.js +0 -2
  80. package/dist/assets/client-CWsjRiH8.js.map +0 -1
  81. package/dist/assets/fileBytesIdb-CD5Uv490.js +0 -2
  82. package/dist/assets/groupFiles-BuToTMUk.js.map +0 -1
  83. package/dist/assets/host-fkQYBvKH.js.map +0 -1
  84. package/dist/assets/mainline-Hsk2SZ1B.js.map +0 -1
  85. package/dist/assets/ownDid-DkK_jem4.js.map +0 -1
  86. package/dist/assets/registry-CEjnubep.js.map +0 -1
  87. package/dist/assets/server-BJ3T-kx3.js.map +0 -1
  88. package/dist/assets/src-BIdfHB7t.js.map +0 -1
  89. package/dist/assets/words-Dk6o6wz4.js.map +0 -1
@@ -1,23 +1,23 @@
1
- import { Nu as setLinkTraceSink, Xo as DAEMON_WATCH_PEER_IDLE_MS, _s as callSignalHeardAt, ba as ACTIVE_DHT_POLL_MS, bs as parseCallSignal, ds as CALL_SIGNAL_MAX_AGE_MS, fa as isPublicAddress, fi as checkPushEndpoint, gs as callRtcConfig, hs as buildSdpFromSignal, ms as answersOffer, nd as fromBase64Url, ps as RTC_CONFIG, xs as signalHasVideo, ys as extractParamsFromSdp } from "./src-BIdfHB7t.js";
2
- import { o as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-B4_swKx0.js";
1
+ import { Nu as setLinkTraceSink, Xo as DAEMON_WATCH_PEER_IDLE_MS, _s as callSignalHeardAt, ba as ACTIVE_DHT_POLL_MS, bs as parseCallSignal, ds as CALL_SIGNAL_MAX_AGE_MS, fa as isPublicAddress, fi as checkPushEndpoint, gs as callRtcConfig, hs as buildSdpFromSignal, ms as answersOffer, nd as fromBase64Url, ps as RTC_CONFIG, xs as signalHasVideo, ys as extractParamsFromSdp } from "./src-BZkY6N3J.js";
2
+ import { o as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-o0H_NlCF.js";
3
3
  import { r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
4
- import { s as findChat, u as findOwnNamedChat } from "./apiKit-BbNaxZGZ.js";
5
- import { _ as flushCardUpdates, c as paymentJson, d as nodeLocalFetch, f as chatJson, g as resumeHolds, h as groupMessageJson, l as reportAppFrames, m as groupJson, p as chatMessageJson, r as callApi, u as servedApps } from "./api-C4MLg5Rs.js";
6
- import { C as runtimePath, S as privateFolder, _ as startingPath, b as ownProfile, n as RESTORED_MARK, r as acquireLock, y as ownFolder } from "./profiles-aV9vaK0B.js";
7
- import { c as proof, d as DEFAULT_RATE, f as PlaybackQueue, g as isCallRate, h as frameSamples, l as removeDaemonSecret, m as frameBytes, o as greeting, p as bytesToMs, s as newDaemonSecret } from "./client-CWsjRiH8.js";
4
+ import { s as findChat, u as findOwnNamedChat } from "./apiKit-D6Oj-vFx.js";
5
+ import { _ as flushCardUpdates, c as paymentJson, d as nodeLocalFetch, f as chatJson, g as resumeHolds, h as groupMessageJson, l as reportAppFrames, m as groupJson, p as chatMessageJson, r as callApi, u as servedApps } from "./api-DkcMOWLX.js";
6
+ import { C as runtimePath, S as privateFolder, _ as startingPath, b as ownProfile, n as RESTORED_MARK, r as acquireLock, y as ownFolder } from "./profiles-QDB7V_Qt.js";
7
+ import { _ as monotonic, c as proof, d as DEFAULT_RATE, f as PlaybackQueue, g as isCallRate, h as frameSamples, l as removeDaemonSecret, m as frameBytes, o as greeting, p as bytesToMs, s as newDaemonSecret } from "./client-q7dVOtYb.js";
8
8
  import { createRequire } from "node:module";
9
9
  import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, truncateSync, writeFileSync, writeSync } from "node:fs";
10
10
  import { readFile } from "node:fs/promises";
11
11
  import { dirname, join } from "node:path";
12
12
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
13
+ import { networkInterfaces } from "node:os";
13
14
  import { Readable } from "node:stream";
14
15
  import { createServer, isIP } from "node:net";
15
16
  import { createInterface } from "node:readline";
16
- import { lookup } from "node:dns/promises";
17
17
  import { fileURLToPath, pathToFileURL } from "node:url";
18
18
  import { Worker } from "node:worker_threads";
19
19
  import { request } from "node:https";
20
- import { lookup as lookup$1 } from "node:dns";
20
+ import { lookup } from "node:dns";
21
21
  import { deserialize, serialize } from "node:v8";
22
22
  import { IDBFactory, IDBKeyRange, IDBTransaction } from "fake-indexeddb";
23
23
  //#region src/announce.ts
@@ -341,17 +341,21 @@ var CallAudio = class {
341
341
  lastQuiet = null;
342
342
  same = 0;
343
343
  quiet = null;
344
+ /** The contact's last packet decoded, what it decoded to, and whether the one before was the same and gave the same (see `decoded`). */
345
+ lastIn = null;
346
+ lastPcm = null;
347
+ steady = false;
344
348
  /** Whether the encoder's FEC is on (`OpusCodec.fec`); unknown until the first frame. */
345
349
  fecOn;
346
350
  stopped = false;
347
351
  /** Frames sent and received, for `call list`. */
348
352
  sent = 0;
349
353
  received = 0;
350
- /** When the last packet, RTP or RTCP, came from the contact (Date.now(); 0: none yet), for the call's watch. */
354
+ /** When the last packet, RTP or RTCP, came from the contact (on `now`, `monotonic` by default; 0: none yet), for the call's watch. */
351
355
  heardAt = 0;
352
356
  constructor(options) {
353
357
  this.options = options;
354
- const now = options.now ?? Date.now;
358
+ const now = options.now ?? monotonic;
355
359
  this.queue = options.queue ?? new PlaybackQueue(options.rate, now);
356
360
  this.writer = new RtpWriter(options.ssrc, options.payloadType);
357
361
  this.frame = frameBytes(options.rate);
@@ -362,7 +366,7 @@ var CallAudio = class {
362
366
  /** Starts sending, a frame every 20 ms from now on. */
363
367
  start() {
364
368
  if (this.timer || this.stopped) return;
365
- this.startedAt = (this.options.now ?? Date.now)();
369
+ this.startedAt = (this.options.now ?? monotonic)();
366
370
  this.ticks = 0;
367
371
  this.schedule();
368
372
  }
@@ -423,25 +427,49 @@ var CallAudio = class {
423
427
  /** Handles one packet from the track. Exposed for tests. */
424
428
  receive(packet) {
425
429
  if (this.stopped) return;
426
- this.heardAt = (this.options.now ?? Date.now)();
430
+ this.heardAt = (this.options.now ?? monotonic)();
427
431
  if (isRtcp(packet)) return;
428
432
  const rtp = parseRtp(packet);
429
433
  if (!rtp || rtp.payloadType !== this.options.payloadType) return;
430
434
  for (const item of this.reorder.push(rtp)) {
431
435
  let pcm;
432
- if ("lost" in item) pcm = this.conceal();
433
- else {
436
+ if ("lost" in item) {
437
+ this.forgetSteady();
438
+ pcm = this.conceal();
439
+ } else {
434
440
  this.concealed = null;
435
- try {
436
- pcm = this.options.decoder.decode(item.payload);
437
- } catch {
438
- pcm = this.silence;
439
- }
441
+ pcm = this.decoded(item.payload);
440
442
  }
441
443
  this.emit(pcm);
442
444
  }
443
445
  }
444
446
  /**
447
+ * A packet of the contact's, decoded. Their silence settles into one packet sent again and again (the CLI's own,
448
+ * `settle`; an app's muted microphone), and the decoder settles with it: once the same packet gave the same audio
449
+ * twice in a row, it is not decoded again while it lasts, and the program gets that audio again. The audio after it
450
+ * decodes to the same bytes as with every packet decoded, and decoding it was half of a quiet call's work on the
451
+ * daemon's thread (libopus in WebAssembly, 50 times a second).
452
+ */
453
+ decoded(payload) {
454
+ if (this.steady && this.lastIn.equals(payload)) return this.lastPcm;
455
+ let pcm;
456
+ try {
457
+ pcm = this.options.decoder.decode(payload);
458
+ } catch {
459
+ this.forgetSteady();
460
+ return this.silence;
461
+ }
462
+ this.steady = !!this.lastIn?.equals(payload) && !!this.lastPcm?.equals(pcm);
463
+ this.lastIn = Buffer.from(payload);
464
+ this.lastPcm = Buffer.from(pcm);
465
+ return pcm;
466
+ }
467
+ /** A packet lost or unreadable: the decoder moved on without the packet (`decoded`) that came last. */
468
+ forgetSteady() {
469
+ this.lastIn = this.lastPcm = null;
470
+ this.steady = false;
471
+ }
472
+ /**
445
473
  * A frame for one that never came: the decoder's loss concealment (libopus PLC, what an empty packet decodes to), as
446
474
  * the apps' WebRTC stacks do, not a frame of silence (a click). opusscript conceals 60 ms at a time (its largest
447
475
  * frame), so one run of it serves the frames of a gap in turn (ReorderBuffer gives MAX_LOST_FRAMES at most).
@@ -468,7 +496,7 @@ var CallAudio = class {
468
496
  this.pending = Buffer.from(data);
469
497
  }
470
498
  schedule() {
471
- const now = this.options.now ?? Date.now;
499
+ const now = this.options.now ?? monotonic;
472
500
  const due = this.startedAt + (this.ticks + 1) * 20;
473
501
  this.timer = setTimeout(() => {
474
502
  if (this.stopped) return;
@@ -494,7 +522,7 @@ var CallAudio = class {
494
522
  * rest of the call.
495
523
  */
496
524
  catchUp(late) {
497
- const now = this.options.now ?? Date.now;
525
+ const now = this.options.now ?? monotonic;
498
526
  if (late > 1e3) {
499
527
  this.owed = late;
500
528
  this.kept = this.ahead;
@@ -517,7 +545,7 @@ var CallAudio = class {
517
545
  */
518
546
  drop() {
519
547
  if (this.owed <= 0) return;
520
- if ((this.options.now ?? Date.now)() > this.owedUntil) {
548
+ if ((this.options.now ?? monotonic)() > this.owedUntil) {
521
549
  this.owed = 0;
522
550
  return;
523
551
  }
@@ -910,13 +938,14 @@ var CallMedia = class CallMedia {
910
938
  /**
911
939
  * WebKit (Safari, the macOS app) hides its host addresses behind mDNS names, which other machines, and often this
912
940
  * one, cannot resolve: then the call can only connect when the contact's own checks reach this side. The log says so,
913
- * since that is what a call stuck on "connecting" needs to be understood.
941
+ * since that is what a call stuck on "connecting" needs to be understood. The names are not looked up for it: a name
942
+ * nobody answers holds one of the few threads every other lookup of the daemon waits on, for seconds.
914
943
  */
915
944
  function mdnsNote(signal, log) {
916
945
  for (const candidate of signal.c ?? []) {
917
946
  const host = candidate.split(" ")[4];
918
947
  if (!host?.endsWith(".local")) continue;
919
- lookup(host, { all: true }).then((found) => log(`${host} resolves here to ${found.map((a) => a.address).join(", ")}`), () => log(`${host} does not resolve here: the call connects only if the contact's checks reach this side`));
948
+ log(`${host}: an mDNS name, not resolved here: the call connects only if the contact's checks reach this side`);
920
949
  }
921
950
  }
922
951
  /** Whether a call's ICE servers (`callIceServers`) have a TURN server: its relay candidate is then the one waited for. */
@@ -1089,7 +1118,7 @@ var CallManager = class {
1089
1118
  call.offering = false;
1090
1119
  call.state = "connecting";
1091
1120
  const attempt = call.answered = call.attempt;
1092
- call.answeredAt = Date.now();
1121
+ call.answeredAt = monotonic();
1093
1122
  try {
1094
1123
  call.media.applyAnswer(answer);
1095
1124
  } catch (error) {
@@ -1240,7 +1269,7 @@ var CallManager = class {
1240
1269
  const link = this.callable(chat);
1241
1270
  if (this.byChat(link.id)) throw new CliError("busy", "A call is already on in this chat");
1242
1271
  const held = this.held.get(link.id);
1243
- if (held && this.now - held.at < 6e4) {
1272
+ if (held && this.within(held.at, 6e4)) {
1244
1273
  this.incoming(link.id, held.offer);
1245
1274
  throw new CliError("busy", "The contact is calling: their call rings here");
1246
1275
  }
@@ -1409,6 +1438,7 @@ var CallManager = class {
1409
1438
  queue: null,
1410
1439
  startedAt: this.now,
1411
1440
  connectedAt: null,
1441
+ connectedTick: null,
1412
1442
  timer: null,
1413
1443
  watcher: null,
1414
1444
  stalledFrom: null,
@@ -1456,7 +1486,7 @@ var CallManager = class {
1456
1486
  }
1457
1487
  if (state === "closed" && failed) return;
1458
1488
  failed ||= state === "failed";
1459
- if (state === "failed" && call.direction === "out" && call.answered === attempt && call.state !== "connected" && Date.now() - call.answeredAt < 2e3) {
1489
+ if (state === "failed" && call.direction === "out" && call.answered === attempt && call.state !== "connected" && monotonic() - call.answeredAt < 2e3) {
1460
1490
  this.refused(call, "the connection failed as the answer went in");
1461
1491
  return;
1462
1492
  }
@@ -1474,6 +1504,7 @@ var CallManager = class {
1474
1504
  if (call.state === "connected") return;
1475
1505
  call.state = "connected";
1476
1506
  call.connectedAt = this.now;
1507
+ call.connectedTick = monotonic();
1477
1508
  this.disarm(call);
1478
1509
  this.host.emit("call.connected", `call.connected:${call.id}`, {
1479
1510
  call: call.id,
@@ -1494,11 +1525,11 @@ var CallManager = class {
1494
1525
  afterMs: 5e3,
1495
1526
  endMs: 15e3
1496
1527
  };
1497
- const since = Date.now();
1528
+ const since = monotonic();
1498
1529
  call.watcher = setInterval(() => {
1499
1530
  if (call.ended) return;
1500
1531
  const heardAt = Math.max(since, call.media?.audio.heardAt ?? 0);
1501
- const silentMs = Date.now() - heardAt;
1532
+ const silentMs = monotonic() - heardAt;
1502
1533
  const fields = {
1503
1534
  call: call.id,
1504
1535
  chat: call.chat,
@@ -1536,7 +1567,7 @@ var CallManager = class {
1536
1567
  this.calls.delete(call.id);
1537
1568
  if (call.direction === "out" && call.connectedAt === null && call.state === "ringing" && (reason === "hangup" || reason === "unanswered")) this.unansweredAt.set(call.chat, this.now);
1538
1569
  if (call.direction === "in" && call.connectedAt === null && reason !== "hangup" && reason !== "stopped") {
1539
- if (this.now - call.startedAt < 1e3) this.missedAt.set(call.chat, this.now);
1570
+ if (this.within(call.startedAt, 1e3)) this.missedAt.set(call.chat, this.now);
1540
1571
  else this.missedAt.delete(call.chat);
1541
1572
  }
1542
1573
  if (report) process.stderr.write(`ghostly: call ${call.id}: ended (${reason})${call.media ? `, ice ${call.media.ice.state}` : ""}\n`);
@@ -1568,7 +1599,7 @@ var CallManager = class {
1568
1599
  chat: call.chat,
1569
1600
  direction: call.direction,
1570
1601
  reason,
1571
- ...call.connectedAt !== null ? { duration: this.now - call.connectedAt } : {}
1602
+ ...call.connectedTick !== null ? { duration: Math.round(monotonic() - call.connectedTick) } : {}
1572
1603
  });
1573
1604
  if (this.stopping) await closing;
1574
1605
  }
@@ -1576,17 +1607,25 @@ var CallManager = class {
1576
1607
  paced(chat) {
1577
1608
  const pace = this.host.callPaceMs ?? 2e3, last = this.unansweredAt.get(chat);
1578
1609
  if (!pace || last === void 0) return;
1579
- const left = last + pace - this.now;
1580
- if (left <= 0) {
1610
+ if (!this.within(last, pace)) {
1581
1611
  this.unansweredAt.delete(chat);
1582
1612
  return;
1583
1613
  }
1614
+ const left = last + pace - this.now;
1584
1615
  throw new CliError("busy", `Your last call in this chat ended unanswered a moment ago: call again in ${Math.ceil(left / 100) / 10} s`, { retryAfterMs: left });
1585
1616
  }
1586
1617
  /** Whether the contact's call coming now in the chat is held back: its last one was missed after it barely rang, or held, a moment ago. */
1587
1618
  quickRedial(chat) {
1588
1619
  const quick = this.host.quickRedialMs ?? 2e3, last = this.missedAt.get(chat);
1589
- return !!quick && last !== void 0 && this.now - last < quick;
1620
+ return !!quick && last !== void 0 && this.within(last, quick);
1621
+ }
1622
+ /**
1623
+ * Whether less than `ms` passed since `at`, on the device's clock (`now`, which the timestamps the contact sees are on).
1624
+ * An `at` later than now is the clock set back since: the wait is taken as over, not as lasting as long as the jump.
1625
+ */
1626
+ within(at, ms) {
1627
+ const passed = this.now - at;
1628
+ return passed >= 0 && passed < ms;
1590
1629
  }
1591
1630
  arm(call, ms, reason, tell) {
1592
1631
  this.disarm(call);
@@ -3267,7 +3306,7 @@ var publicOnly = (resolve) => (hostname, options, callback) => {
3267
3306
  callback(null, addresses[0].address, addresses[0].family);
3268
3307
  });
3269
3308
  };
3270
- var publicOnlyLookup = publicOnly(lookup$1);
3309
+ var publicOnlyLookup = publicOnly(lookup);
3271
3310
  /**
3272
3311
  * Posts a wake-up (WISP 401 § Wake-up push) the way the Desktop does from Rust: only to a push service's endpoint
3273
3312
  * (`checkPushEndpoint`), whose name must resolve to public addresses only, no redirect followed, no proxy, 10 s at most.
@@ -5138,6 +5177,84 @@ function blobsFromDisk(value, depth = 0) {
5138
5177
  for (const [k, v] of Object.entries(value)) out[k] = blobsFromDisk(v, depth + 1);
5139
5178
  return out;
5140
5179
  }
5180
+ /**
5181
+ * A wake republishes every chat with nothing published in the last seconds (on the CLI the DHT copy goes whatever the
5182
+ * relays' budgets say: 200 chats are 200 DHT puts and a ~76 ms turn). A network that flaps (Wi-Fi at the edge of range,
5183
+ * a VPN in a reconnect loop) changed the addresses every tick and woke the engine every 10 s for nothing new. A network
5184
+ * wake within this long of the previous wake is held and runs once when the gap is over, the latest change included; each
5185
+ * held one run doubles the gap, up to `WAKE_GAP_MAX_MS`, and a whole gap with no change brings it back. A network change
5186
+ * after a quiet spell, and a sleep, still wake at once.
5187
+ */
5188
+ var WAKE_GAP_MS = 6e4;
5189
+ var WAKE_GAP_MAX_MS = 6e5;
5190
+ /**
5191
+ * The machine's own virtual bridges, for containers and VMs on it: Docker's (`docker0`, a compose network's `br-<id>`,
5192
+ * `veth*`), libvirt's, CNI's, LXD's, VirtualBox's and VMware's host networks, macOS's `bridge100` (sharing, a VM), and
5193
+ * Windows's WSL and Default Switch. A container network made or removed changes them with nothing changed for the
5194
+ * internet, and a network wake makes every chat read and publish at once. A Hyper-V switch bound to the network card (`vEthernet
5195
+ * (External)`) holds the machine's real address and stays.
5196
+ */
5197
+ var LOCAL_BRIDGE = /^(docker\d*|br-[0-9a-f]+|veth.*|virbr\d+|cni\d+|flannel.*|cali.*|lxcbr\d+|lxdbr\d+|incusbr\d+|podman\d+|vboxnet\d+|vmnet\d+|bridge\d+|vEthernet \((WSL.*|Default Switch)\))$/;
5198
+ /** The machine's own non-internal addresses, sorted: a change means another network (Wi-Fi to cable, a new DHCP lease). */
5199
+ function addressesKey(nets = networkInterfaces()) {
5200
+ const out = [];
5201
+ for (const [name, list] of Object.entries(nets)) {
5202
+ if (LOCAL_BRIDGE.test(name)) continue;
5203
+ for (const entry of list ?? []) {
5204
+ if (entry.internal || entry.family === "IPv6" && entry.address.toLowerCase().startsWith("fe80")) continue;
5205
+ out.push(`${name}/${entry.address}`);
5206
+ }
5207
+ }
5208
+ return out.sort().join(",");
5209
+ }
5210
+ /** Starts the watch; the returned function stops it. The timer never keeps the process alive. */
5211
+ function watchWake(onWake, options = {}) {
5212
+ const tickMs = options.tickMs ?? 1e4;
5213
+ const lateMs = options.lateMs ?? 3e4;
5214
+ const now = options.now ?? Date.now;
5215
+ const addresses = options.addresses ?? (() => addressesKey());
5216
+ let last = now();
5217
+ let key = safe(addresses);
5218
+ let wokeAt = -Infinity;
5219
+ let gap = WAKE_GAP_MS;
5220
+ /** A network change seen within the gap, not woken for yet. */
5221
+ let held = false;
5222
+ const wake = (why, at) => {
5223
+ wokeAt = at;
5224
+ held = false;
5225
+ try {
5226
+ onWake(why);
5227
+ } catch {}
5228
+ };
5229
+ const timer = setInterval(() => {
5230
+ const at = now();
5231
+ const slept = at - last > tickMs + lateMs;
5232
+ last = at;
5233
+ const next = safe(addresses);
5234
+ const moved = next !== "" && next !== key;
5235
+ key = next;
5236
+ if (slept) return wake("sleep", at);
5237
+ if (!(at - wokeAt >= gap)) {
5238
+ held ||= moved;
5239
+ return;
5240
+ }
5241
+ if (held) {
5242
+ gap = Math.min(gap * 2, WAKE_GAP_MAX_MS);
5243
+ return wake("network", at);
5244
+ }
5245
+ gap = WAKE_GAP_MS;
5246
+ if (moved) wake("network", at);
5247
+ }, tickMs);
5248
+ timer.unref?.();
5249
+ return () => clearInterval(timer);
5250
+ }
5251
+ function safe(read) {
5252
+ try {
5253
+ return read();
5254
+ } catch {
5255
+ return "";
5256
+ }
5257
+ }
5141
5258
  //#endregion
5142
5259
  //#region src/runtime/engine.ts
5143
5260
  /**
@@ -5360,15 +5477,15 @@ async function startRuntime(paths, options = {}) {
5360
5477
  await installEventSource();
5361
5478
  await preloadWalletModules();
5362
5479
  (await import("./ghostly_iroh_web-BzAXJUYH.js")).initSync({ module: irohWasmBytes() });
5363
- const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-DMzrIdCu.js"), import("./fileBytes-Douk1yOp.js")]);
5480
+ const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-CQQK2uOh.js"), import("./fileBytes-DqnfKIkj.js")]);
5364
5481
  registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
5365
- if (await (await import("./blobFiles-BnjN_Vrz.js")).moveBlobFiles()) await store.compact();
5366
- const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-BJ3T-kx3.js"), import("./endpoint-DWHkXWVM.js")]);
5367
- const mainline = dht.off ? null : new (await (import("./mainline-Hsk2SZ1B.js"))).Mainline({
5482
+ if (await (await import("./blobFiles-XZ9PEXYy.js")).moveBlobFiles()) await store.compact();
5483
+ const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-7w2O5wsv.js"), import("./endpoint-DWHkXWVM.js")]);
5484
+ const mainline = dht.off ? null : new (await (import("./mainline-B2qmNsib.js"))).Mainline({
5368
5485
  bootstrap: dht.bootstrap,
5369
5486
  host: dht.host
5370
5487
  });
5371
- const transport = mainline || pinned ? new (await (import("./mainline-Hsk2SZ1B.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
5488
+ const transport = mainline || pinned ? new (await (import("./mainline-B2qmNsib.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
5372
5489
  const apps = servedApps(paths.dir).length > 0;
5373
5490
  const server = new EngineServer({
5374
5491
  ...transport ? { transport } : {},
@@ -5400,6 +5517,9 @@ async function startRuntime(paths, options = {}) {
5400
5517
  await store.close().catch(() => {});
5401
5518
  throw error;
5402
5519
  }
5520
+ const stopWake = options.offline ? () => {} : watchWake(() => {
5521
+ server.node.wake({ network: true });
5522
+ });
5403
5523
  let closing = null;
5404
5524
  return {
5405
5525
  paths,
@@ -5409,6 +5529,7 @@ async function startRuntime(paths, options = {}) {
5409
5529
  callsUnavailable,
5410
5530
  apps,
5411
5531
  close: () => closing ??= (async () => {
5532
+ stopWake();
5412
5533
  await server.node.shutdown({ quitting: true }).catch(() => {});
5413
5534
  await mainline?.destroy().catch(() => {});
5414
5535
  await store.close();
@@ -5731,4 +5852,4 @@ function connection(ctx, socket, secret) {
5731
5852
  //#endregion
5732
5853
  export { BASELINE_NEWEST, MAX_UNREAD, keepServing, openHost, serve };
5733
5854
 
5734
- //# sourceMappingURL=host-fkQYBvKH.js.map
5855
+ //# sourceMappingURL=host-C-wwtVt2.js.map