@ghostlytools/cli 1.10.6 → 1.11.0
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/README.md +27 -22
- package/SKILL.md +8 -5
- package/dist/assets/api-B-52sVYp.js +3 -0
- package/dist/assets/{api-DppWqAP3.js → api-CTqIcdu7.js} +532 -197
- package/dist/assets/api-CTqIcdu7.js.map +1 -0
- package/dist/assets/{apiKit-DFIho4Ev.js → apiKit-CZq4Lq4f.js} +97 -13
- package/dist/assets/apiKit-CZq4Lq4f.js.map +1 -0
- package/dist/assets/{apps-yBnbEtfV.js → apps-C_X0zgSG.js} +16 -4
- package/dist/assets/apps-C_X0zgSG.js.map +1 -0
- package/dist/assets/{apps-1MkGMH8m.js → apps-kRsY9S2S.js} +1 -1
- package/dist/assets/{arkade-bFAS6imn.js → arkade-_aaB7VbW.js} +2 -2
- package/dist/assets/{arkade-bFAS6imn.js.map → arkade-_aaB7VbW.js.map} +1 -1
- package/dist/assets/{backup-ejIX59o7.js → backup-DBg388Ke.js} +1 -1
- package/dist/assets/{backup-vj4J7M3e.js → backup-OTvrmk-w.js} +35 -7
- package/dist/assets/backup-OTvrmk-w.js.map +1 -0
- package/dist/assets/{blobFiles-XZ9PEXYy.js → blobFiles-BmsrvZc3.js} +3 -3
- package/dist/assets/{blobFiles-XZ9PEXYy.js.map → blobFiles-BmsrvZc3.js.map} +1 -1
- package/dist/assets/buttons-4EKtQl-7.js +2 -0
- package/dist/assets/{buttons-BoDMx3Ky.js → buttons-DUu7hxxT.js} +61 -30
- package/dist/assets/buttons-DUu7hxxT.js.map +1 -0
- package/dist/assets/{client-BQArefYa.js → client-DDpZP1R1.js} +55 -10
- package/dist/assets/client-DDpZP1R1.js.map +1 -0
- package/dist/assets/{codec-_MwTUz5E.js → codec-DrryGcPT.js} +2 -2
- package/dist/assets/{codec-_MwTUz5E.js.map → codec-DrryGcPT.js.map} +1 -1
- package/dist/assets/{envelope-CeZBNGX-.js → envelope-Q_rMgoE9.js} +2 -2
- package/dist/assets/{envelope-CeZBNGX-.js.map → envelope-Q_rMgoE9.js.map} +1 -1
- package/dist/assets/{irohWeb-C_Wnw7Q9.js → fedimintSdk-CqTeMdF0.js} +2 -354
- package/dist/assets/fedimintSdk-CqTeMdF0.js.map +1 -0
- package/dist/assets/{fileBytes-DqnfKIkj.js → fileBytes-B0z9A6Le.js} +2 -2
- package/dist/assets/{fileBytes-DqnfKIkj.js.map → fileBytes-B0z9A6Le.js.map} +1 -1
- package/dist/assets/{fileBytes-BABGEF13.js → fileBytes-BLPZq9YU.js} +3 -3
- package/dist/assets/{fileBytes-BABGEF13.js.map → fileBytes-BLPZq9YU.js.map} +1 -1
- package/dist/assets/{fileBytes-CQQK2uOh.js → fileBytes-BtIyoDF2.js} +1 -1
- package/dist/assets/{fileBytesIdb-DrXmDUSy.js → fileBytesIdb-Bmlrl9EO.js} +3 -3
- package/dist/assets/{fileBytesIdb-DrXmDUSy.js.map → fileBytesIdb-Bmlrl9EO.js.map} +1 -1
- package/dist/assets/fileBytesIdb-D8mAK4pF.js +2 -0
- package/dist/assets/{fileBytesOpfs-udKCzcLe.js → fileBytesOpfs-DBS0kbPT.js} +3 -3
- package/dist/assets/{fileBytesOpfs-udKCzcLe.js.map → fileBytesOpfs-DBS0kbPT.js.map} +1 -1
- package/dist/assets/{fixedHosts-B_2Rvyja.js → fixedHosts-BV5GDiTU.js} +3 -3
- package/dist/assets/{fixedHosts-B_2Rvyja.js.map → fixedHosts-BV5GDiTU.js.map} +1 -1
- package/dist/assets/{host-DFLzzKNr.js → host-BlUzZgQL.js} +336 -84
- package/dist/assets/host-BlUzZgQL.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CV6qMrom.js → hyperdhtRelay-BvI_uNZO.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CV6qMrom.js.map → hyperdhtRelay-BvI_uNZO.js.map} +1 -1
- package/dist/assets/{idb-BHsAqENE.js → idb-CEuoNsTv.js} +16 -5
- package/dist/assets/idb-CEuoNsTv.js.map +1 -0
- package/dist/assets/{groupFiles-D-ZUUHrx.js → irohWeb-CqPN8VPY.js} +469 -16
- package/dist/assets/irohWeb-CqPN8VPY.js.map +1 -0
- package/dist/assets/{main-DxRwajM_.js → main-vQjlgEnt.js} +409 -126
- package/dist/assets/main-vQjlgEnt.js.map +1 -0
- package/dist/assets/{mainline-Bx184Ixg.js → mainline-p6HOW7sb.js} +2 -2
- package/dist/assets/{mainline-Bx184Ixg.js.map → mainline-p6HOW7sb.js.map} +1 -1
- package/dist/assets/{networkReason-BlQhTbXk.js → networkReason-DMffkiJ6.js} +4 -4
- package/dist/assets/{networkReason-BlQhTbXk.js.map → networkReason-DMffkiJ6.js.map} +1 -1
- package/dist/assets/{nwc-B3-PHX0L.js → nwc-2vH18oNy.js} +4 -4
- package/dist/assets/nwc-2vH18oNy.js.map +1 -0
- package/dist/assets/{nwcProvider-BeQBPB2q.js → nwcProvider-DpeDy0bV.js} +11 -3
- package/dist/assets/nwcProvider-DpeDy0bV.js.map +1 -0
- package/dist/assets/{ownDid-DAzW-Urb.js → ownDid-iKz8u_fM.js} +2 -2
- package/dist/assets/{ownDid-DAzW-Urb.js.map → ownDid-iKz8u_fM.js.map} +1 -1
- package/dist/assets/{words-BvdNuw_v.js → ownStatus-BlRKnM5F.js} +56 -4
- package/dist/assets/ownStatus-BlRKnM5F.js.map +1 -0
- package/dist/assets/{profiles-Bg43mRXu.js → profiles-B5e0TyvS.js} +22 -12
- package/dist/assets/profiles-B5e0TyvS.js.map +1 -0
- package/dist/assets/{registry-CAk2-5BQ.js → registry-Cc_PQb3k.js} +1 -1
- package/dist/assets/{registry-BDnsZJBi.js → registry-CnFO2Pp5.js} +123 -99
- package/dist/assets/registry-CnFO2Pp5.js.map +1 -0
- package/dist/assets/{resolve-UAfshn6j.js → resolve-DI8uAM_Y.js} +2 -2
- package/dist/assets/{resolve-UAfshn6j.js.map → resolve-DI8uAM_Y.js.map} +1 -1
- package/dist/assets/{restoredRows-YhlbokEE.js → restoredRows-C3LcxmOw.js} +4 -4
- package/dist/assets/{restoredRows-YhlbokEE.js.map → restoredRows-C3LcxmOw.js.map} +1 -1
- package/dist/assets/{server-DYdR0_Fj.js → server-DdtPxkqI.js} +2057 -655
- package/dist/assets/server-DdtPxkqI.js.map +1 -0
- package/dist/assets/{src-BTRPAi5X.js → src-BnpEQqzk.js} +813 -144
- package/dist/assets/src-BnpEQqzk.js.map +1 -0
- package/dist/assets/{sshForges-KtHK5x1x.js → sshForges-cdIAraDw.js} +2 -2
- package/dist/assets/{sshForges-KtHK5x1x.js.map → sshForges-cdIAraDw.js.map} +1 -1
- package/dist/assets/{translate-CYuygrvA.js → translate-kNopA04L.js} +2 -2
- package/dist/assets/{translate-CYuygrvA.js.map → translate-kNopA04L.js.map} +1 -1
- package/dist/assets/{usdt-Dw9IENe_.js → usdt-CDaLhEYh.js} +3 -3
- package/dist/assets/{usdt-Dw9IENe_.js.map → usdt-CDaLhEYh.js.map} +1 -1
- package/dist/assets/{waitNotice-Ce3YCinu.js → waitNotice-Cn0WJ-He.js} +3 -1
- package/dist/assets/waitNotice-Cn0WJ-He.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/claude-code-agent.sh +5 -0
- package/package.json +2 -2
- package/dist/assets/api-DppWqAP3.js.map +0 -1
- package/dist/assets/api-K-i5MrP-.js +0 -3
- package/dist/assets/apiKit-DFIho4Ev.js.map +0 -1
- package/dist/assets/apps-yBnbEtfV.js.map +0 -1
- package/dist/assets/backup-vj4J7M3e.js.map +0 -1
- package/dist/assets/buttons-BoDMx3Ky.js.map +0 -1
- package/dist/assets/buttons-DG1CKgAI.js +0 -2
- package/dist/assets/client-BQArefYa.js.map +0 -1
- package/dist/assets/fileBytesIdb-BtXATa7j.js +0 -2
- package/dist/assets/groupFiles-D-ZUUHrx.js.map +0 -1
- package/dist/assets/host-DFLzzKNr.js.map +0 -1
- package/dist/assets/idb-BHsAqENE.js.map +0 -1
- package/dist/assets/irohWeb-C_Wnw7Q9.js.map +0 -1
- package/dist/assets/main-DxRwajM_.js.map +0 -1
- package/dist/assets/nwc-B3-PHX0L.js.map +0 -1
- package/dist/assets/nwcProvider-BeQBPB2q.js.map +0 -1
- package/dist/assets/profiles-Bg43mRXu.js.map +0 -1
- package/dist/assets/registry-BDnsZJBi.js.map +0 -1
- package/dist/assets/server-DYdR0_Fj.js.map +0 -1
- package/dist/assets/src-BTRPAi5X.js.map +0 -1
- package/dist/assets/waitNotice-Ce3YCinu.js.map +0 -1
- package/dist/assets/words-BvdNuw_v.js.map +0 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { As as signalHasVideo, Cs as answersOffer, Es as callSignalHeardAt, Oa as ACTIVE_DHT_POLL_MS, Os as extractParamsFromSdp, Ss as RTC_CONFIG, Ts as callRtcConfig, Uu as setLinkTraceSink, as as DAEMON_WATCH_PEER_IDLE_MS, ba as isPublicAddress, bi as checkPushEndpoint, bs as CALL_SIGNAL_MAX_AGE_MS, fd as fromBase64Url, ks as parseCallSignal, ws as buildSdpFromSignal } from "./src-BnpEQqzk.js";
|
|
2
|
+
import { p as fileStore } from "./idb-CEuoNsTv.js";
|
|
3
|
+
import { r as irohRelayProblem } from "./irohWeb-CqPN8VPY.js";
|
|
4
|
+
import { n as fedimintSdkOn } from "./fedimintSdk-CqTeMdF0.js";
|
|
3
5
|
import { r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
|
|
4
|
-
import { s as findChat, u as findOwnNamedChat } from "./apiKit-
|
|
5
|
-
import { _ as
|
|
6
|
-
import { C as
|
|
7
|
-
import { _ as
|
|
6
|
+
import { A as sinceSeq, s as findChat, u as findOwnNamedChat } from "./apiKit-CZq4Lq4f.js";
|
|
7
|
+
import { _ as resumeHolds, d as servedApps, f as nodeLocalFetch, g as groupMessageJson, h as groupJson, l as paymentJson, m as chatMessageJson, p as chatJson, r as callApi, u as reportAppFrames, v as flushCardUpdates } from "./api-CTqIcdu7.js";
|
|
8
|
+
import { C as privateFolder, b as ownFolder, n as RESTORED_MARK, r as acquireLock, v as startingPath, w as runtimePath, x as ownProfile } from "./profiles-B5e0TyvS.js";
|
|
9
|
+
import { _ as isCallRate, c as newDaemonSecret, f as DEFAULT_RATE, g as frameSamples, h as frameBytes, l as proof, m as bytesToMs, p as PlaybackQueue, s as greeting, u as removeDaemonSecret, v as monotonic } from "./client-DDpZP1R1.js";
|
|
8
10
|
import { createRequire } from "node:module";
|
|
9
11
|
import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, truncateSync, writeFileSync, writeSync } from "node:fs";
|
|
10
12
|
import { readFile } from "node:fs/promises";
|
|
@@ -1211,8 +1213,9 @@ var CallManager = class {
|
|
|
1211
1213
|
*/
|
|
1212
1214
|
prepare(call) {
|
|
1213
1215
|
if (this.host.answers === false || call.ended || call.state !== "ringing") return;
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1216
|
+
const settings = this.host.engine.getState().settings;
|
|
1217
|
+
const iceServers = settings?.iceServers ?? [];
|
|
1218
|
+
if (settings?.relayOnly === true || callUsesTurn(callIceServers(iceServers))) return;
|
|
1216
1219
|
this.stopEarly(call);
|
|
1217
1220
|
call.earlyTimer = setTimeout(() => this.prepare(call), this.host.earlyAnswerMs ?? 3e4);
|
|
1218
1221
|
call.earlyTimer.unref?.();
|
|
@@ -1525,11 +1528,20 @@ var CallManager = class {
|
|
|
1525
1528
|
afterMs: 5e3,
|
|
1526
1529
|
endMs: 15e3
|
|
1527
1530
|
};
|
|
1528
|
-
const since = monotonic();
|
|
1531
|
+
const since = monotonic(), every = Math.min(1e3, afterMs / 5);
|
|
1532
|
+
let ticked = since, own = 0, ownUntil = 0;
|
|
1529
1533
|
call.watcher = setInterval(() => {
|
|
1530
1534
|
if (call.ended) return;
|
|
1535
|
+
const now = monotonic(), gap = now - ticked;
|
|
1536
|
+
ticked = now;
|
|
1537
|
+
if (gap > 2 * every) {
|
|
1538
|
+
own += gap - every;
|
|
1539
|
+
ownUntil = now;
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1531
1542
|
const heardAt = Math.max(since, call.media?.audio.heardAt ?? 0);
|
|
1532
|
-
|
|
1543
|
+
if (heardAt >= ownUntil) own = 0;
|
|
1544
|
+
const silentMs = now - heardAt - own;
|
|
1533
1545
|
const fields = {
|
|
1534
1546
|
call: call.id,
|
|
1535
1547
|
chat: call.chat,
|
|
@@ -1555,7 +1567,7 @@ var CallManager = class {
|
|
|
1555
1567
|
silentMs: gapMs
|
|
1556
1568
|
});
|
|
1557
1569
|
}
|
|
1558
|
-
},
|
|
1570
|
+
}, every);
|
|
1559
1571
|
call.watcher.unref?.();
|
|
1560
1572
|
}
|
|
1561
1573
|
async end(call, reason, tell, report = true) {
|
|
@@ -1718,6 +1730,7 @@ var CallManager = class {
|
|
|
1718
1730
|
if (this.host.answers === false) throw new CliError("unavailable", CALLS_NEED_DAEMON);
|
|
1719
1731
|
if (!link.profile) throw new CliError("unavailable", "Calls are in chats made since 0.4 (the chat session): this is a compatibility chat");
|
|
1720
1732
|
if (link.callsUnavailable) throw new CliError("unavailable", link.callsUnavailable);
|
|
1733
|
+
if (this.host.engine.getState().settings?.relayOnly === true) throw new CliError("unavailable", CALLS_OFF_RELAY_ONLY);
|
|
1721
1734
|
return link;
|
|
1722
1735
|
}
|
|
1723
1736
|
autoFor(chat) {
|
|
@@ -1725,6 +1738,13 @@ var CallManager = class {
|
|
|
1725
1738
|
}
|
|
1726
1739
|
};
|
|
1727
1740
|
var CALLS_NEED_DAEMON = "Calls need the daemon (a call outlives this command): start it with `ghostly daemon --detach`";
|
|
1741
|
+
/**
|
|
1742
|
+
* Hide my IP from contacts (`relayOnly`, WISP 601 Relay only): libdatachannel's relay policy only keeps the other
|
|
1743
|
+
* candidates out of the signal; its ICE still checks from this machine's own sockets, and a call connected on a direct
|
|
1744
|
+
* pair in a local lab. So the CLI places and answers no call while it is on, as the apps do with media that cannot keep
|
|
1745
|
+
* to the relay.
|
|
1746
|
+
*/
|
|
1747
|
+
var CALLS_OFF_RELAY_ONLY = "Calls are off while Hide my IP from contacts is on: this headless Ghostly cannot keep a call to the relay";
|
|
1728
1748
|
function nameOf(link) {
|
|
1729
1749
|
return link.label?.trim() || link.peerNick?.trim() || null;
|
|
1730
1750
|
}
|
|
@@ -1966,7 +1986,7 @@ var EventHub = class {
|
|
|
1966
1986
|
const cutoff = Math.min(this.now(), newest) - SEEN_KEEP_MS;
|
|
1967
1987
|
let dropped = 0;
|
|
1968
1988
|
for (const [chat, known] of this.seen) {
|
|
1969
|
-
if (chat === FORMAT || chat.startsWith("said:")) continue;
|
|
1989
|
+
if (chat === FORMAT || chat === UNDERWAY || chat.startsWith("said:")) continue;
|
|
1970
1990
|
const reactions = chat.startsWith("reactions:");
|
|
1971
1991
|
const gone = [];
|
|
1972
1992
|
for (const [id, note] of known) {
|
|
@@ -2452,59 +2472,109 @@ var EventHub = class {
|
|
|
2452
2472
|
}
|
|
2453
2473
|
});
|
|
2454
2474
|
}
|
|
2455
|
-
for (const [id, transfer] of Object.entries(state.transfers ?? {}))
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2475
|
+
for (const [id, transfer] of Object.entries(state.transfers ?? {})) this.transferChanged(id, transfer, state, quiet);
|
|
2476
|
+
this.state = state;
|
|
2477
|
+
for (const listener of this.stateListeners) try {
|
|
2478
|
+
listener(state);
|
|
2479
|
+
} catch {}
|
|
2480
|
+
}
|
|
2481
|
+
/**
|
|
2482
|
+
* A transfer's `file.*` event, when its shape changed. One under way is noted in the seen set until its end is told:
|
|
2483
|
+
* one that ends while no hub watches (a stop, a start before the baseline) is told by the next start, at its baseline
|
|
2484
|
+
* or from its record (`ended`), once. `quiet`: the baseline, which tells only those ends.
|
|
2485
|
+
*/
|
|
2486
|
+
transferChanged(id, transfer, state, quiet) {
|
|
2487
|
+
const shape = `${transfer.state}|${transfer.stage ?? ""}`, before = this.transfers.get(id);
|
|
2488
|
+
this.transfers.set(id, shape);
|
|
2489
|
+
const end = transfer.state === "done" || transfer.state === "failed", underway = this.seen.get(UNDERWAY)?.has(id) ?? false;
|
|
2490
|
+
if (!end && !underway) {
|
|
2491
|
+
this.seenOf(UNDERWAY).set(id, "yes");
|
|
2492
|
+
this.persist(UNDERWAY, [[id, "yes"]]);
|
|
2493
|
+
}
|
|
2494
|
+
if (quiet && !(end && underway) || before === shape) return;
|
|
2495
|
+
const chat = state.links.find((l) => id.startsWith(`${l.id}-`))?.id ?? null;
|
|
2496
|
+
const group = chat ? void 0 : state.groups.find((g) => id.startsWith(`group-${g.id}-`))?.id;
|
|
2497
|
+
const fields = {
|
|
2498
|
+
chat,
|
|
2499
|
+
...group ? { group } : {},
|
|
2500
|
+
file: id,
|
|
2501
|
+
direction: transfer.direction ?? (id.includes("-in-") ? "in" : "out"),
|
|
2502
|
+
size: transfer.size,
|
|
2503
|
+
transferred: transfer.transferred,
|
|
2504
|
+
...transfer.error ? { error: transfer.error } : {}
|
|
2505
|
+
};
|
|
2506
|
+
const told = () => {
|
|
2507
|
+
if (!this.seen.get(UNDERWAY)?.delete(id)) return;
|
|
2508
|
+
this.persist(UNDERWAY, [[id, null]]);
|
|
2509
|
+
};
|
|
2510
|
+
let emit = null;
|
|
2511
|
+
if (transfer.state === "done") {
|
|
2512
|
+
const key = `file.done:${id}`;
|
|
2513
|
+
emit = (messageId) => {
|
|
2514
|
+
told();
|
|
2515
|
+
this.emit("file.done", key, {
|
|
2474
2516
|
...fields,
|
|
2475
2517
|
messageId
|
|
2476
2518
|
});
|
|
2477
|
-
}
|
|
2478
|
-
|
|
2479
|
-
|
|
2519
|
+
};
|
|
2520
|
+
} else if (transfer.state === "failed") {
|
|
2521
|
+
const key = `file.failed:${id}:${this.now()}`;
|
|
2522
|
+
emit = (messageId) => {
|
|
2523
|
+
told();
|
|
2524
|
+
this.emit("file.failed", key, {
|
|
2480
2525
|
...fields,
|
|
2481
2526
|
messageId,
|
|
2482
2527
|
retry: !!transfer.retry
|
|
2483
2528
|
});
|
|
2484
|
-
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
}
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
}
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2529
|
+
};
|
|
2530
|
+
} else if (transfer.stage === "asking" && fields.direction === "in") {
|
|
2531
|
+
const key = `file.offered:${id}:${this.now()}`;
|
|
2532
|
+
emit = (messageId) => this.emit("file.offered", key, {
|
|
2533
|
+
...fields,
|
|
2534
|
+
messageId,
|
|
2535
|
+
room: transfer.room ?? null
|
|
2536
|
+
});
|
|
2537
|
+
} else if (transfer.stage) {
|
|
2538
|
+
const key = `file.stage:${id}:${transfer.stage}:${this.now()}`, stage = {
|
|
2539
|
+
stage: transfer.stage,
|
|
2540
|
+
...transfer.pausedBy ? { pausedBy: transfer.pausedBy } : {}
|
|
2541
|
+
};
|
|
2542
|
+
emit = (messageId) => this.emit("file.stage", key, {
|
|
2543
|
+
...fields,
|
|
2544
|
+
messageId,
|
|
2545
|
+
...stage
|
|
2546
|
+
});
|
|
2547
|
+
}
|
|
2548
|
+
if (emit) this.fileEvent(id, emit, chat ?? (group ? `group:${group}` : null));
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* After the baseline, before the sink is attached: the transfers noted under way that the engine's state no longer
|
|
2552
|
+
* shows. A finished file has no transfer there after a restart, only its record (`stored`): one that ended while the
|
|
2553
|
+
* daemon stopped is told now. A record gone (the file deleted) drops its note.
|
|
2554
|
+
*/
|
|
2555
|
+
async ended(stored) {
|
|
2556
|
+
const state = this.state;
|
|
2557
|
+
if (!state) return;
|
|
2558
|
+
for (const id of [...this.seen.get(UNDERWAY)?.keys() ?? []]) {
|
|
2559
|
+
if (state.transfers?.[id]) continue;
|
|
2560
|
+
let record;
|
|
2561
|
+
try {
|
|
2562
|
+
record = await stored(id);
|
|
2563
|
+
} catch {
|
|
2564
|
+
continue;
|
|
2565
|
+
}
|
|
2566
|
+
if (!record) {
|
|
2567
|
+
this.seen.get(UNDERWAY)?.delete(id);
|
|
2568
|
+
this.persist(UNDERWAY, [[id, null]]);
|
|
2569
|
+
continue;
|
|
2501
2570
|
}
|
|
2502
|
-
|
|
2571
|
+
const transfer = record.transfer;
|
|
2572
|
+
if (transfer?.state !== "done" && transfer?.state !== "failed") continue;
|
|
2573
|
+
this.transferChanged(id, {
|
|
2574
|
+
...transfer,
|
|
2575
|
+
...record.direction ? { direction: record.direction } : {}
|
|
2576
|
+
}, state, true);
|
|
2503
2577
|
}
|
|
2504
|
-
this.state = state;
|
|
2505
|
-
for (const listener of this.stateListeners) try {
|
|
2506
|
-
listener(state);
|
|
2507
|
-
} catch {}
|
|
2508
2578
|
}
|
|
2509
2579
|
/**
|
|
2510
2580
|
* Someone else pinned a message, or unpinned it (WISP 400 § Pinned message): `chat.pinned` or `group.pinned`, with
|
|
@@ -2801,6 +2871,8 @@ var FORMAT = "format:";
|
|
|
2801
2871
|
var MENTIONS_NOTED = "mentions";
|
|
2802
2872
|
/** The seen set's mark that its notes carry their time. */
|
|
2803
2873
|
var AGES_NOTED = "ages";
|
|
2874
|
+
/** The seen set's notes of the transfers seen under way whose end was not told yet, by file id. */
|
|
2875
|
+
var UNDERWAY = "files:";
|
|
2804
2876
|
/**
|
|
2805
2877
|
* A note: what the seen set keeps of a message (or a reaction's number), then `@` and the time of its last activity in
|
|
2806
2878
|
* base 36 (`received+p#e2@mg3k1x2a`), by which `sweep` drops it. A note from before has no time.
|
|
@@ -3088,6 +3160,145 @@ function journalWindow(path, lineAt = 0) {
|
|
|
3088
3160
|
}
|
|
3089
3161
|
}
|
|
3090
3162
|
//#endregion
|
|
3163
|
+
//#region src/groupAuto.ts
|
|
3164
|
+
var FILE = "groups.json";
|
|
3165
|
+
var GroupAutoJoin = class {
|
|
3166
|
+
host;
|
|
3167
|
+
grants;
|
|
3168
|
+
path;
|
|
3169
|
+
/** Invitations being accepted now. */
|
|
3170
|
+
accepting = /* @__PURE__ */ new Set();
|
|
3171
|
+
/** Per invitation: the last reason its accept failed, said once (it is tried again on the next change). */
|
|
3172
|
+
failed = /* @__PURE__ */ new Map();
|
|
3173
|
+
/** Invitations over a granted chat kept beside a group that is not just an invitation, said once each. */
|
|
3174
|
+
heldSaid = /* @__PURE__ */ new Set();
|
|
3175
|
+
constructor(host) {
|
|
3176
|
+
this.host = host;
|
|
3177
|
+
this.path = join(host.profileDir, FILE);
|
|
3178
|
+
this.grants = readGrants(this.path);
|
|
3179
|
+
}
|
|
3180
|
+
get() {
|
|
3181
|
+
return {
|
|
3182
|
+
on: this.grants.length > 0,
|
|
3183
|
+
from: this.grants.map((g) => g.chat)
|
|
3184
|
+
};
|
|
3185
|
+
}
|
|
3186
|
+
set(next) {
|
|
3187
|
+
if (!next.on) this.grants = [];
|
|
3188
|
+
else {
|
|
3189
|
+
if (!next.from?.length) throw new CliError("bad_request", "Auto-join needs the chats whose invitations it accepts: group auto on --from <chat>");
|
|
3190
|
+
const { links, groups } = this.host.engine.getState();
|
|
3191
|
+
const grants = next.from.map((ref) => findOwnNamedChat(links, ref, groups)).map((link) => ({
|
|
3192
|
+
chat: link.id,
|
|
3193
|
+
contact: link.peerPubKeyZ32
|
|
3194
|
+
}));
|
|
3195
|
+
this.grants = grants.filter((g, i) => grants.findIndex((x) => x.chat === g.chat) === i);
|
|
3196
|
+
}
|
|
3197
|
+
this.save();
|
|
3198
|
+
if (this.host.joins) this.check(this.host.engine.getState());
|
|
3199
|
+
return this.get();
|
|
3200
|
+
}
|
|
3201
|
+
/**
|
|
3202
|
+
* Whether an invitation over this chat is one this profile accepts by itself: the chat is on the list and its contact's
|
|
3203
|
+
* key is still the one named. The engine asks it when 32 invitations wait (`NodeOptions.autoJoins`): such an invitation
|
|
3204
|
+
* then takes the place of the oldest waiting from the chat that holds the most, so the invitations of contacts nobody
|
|
3205
|
+
* answers here cannot keep the owner's out.
|
|
3206
|
+
*/
|
|
3207
|
+
autoJoins(chat) {
|
|
3208
|
+
const grant = this.grants.find((g) => g.chat === chat);
|
|
3209
|
+
return !!grant && this.host.engine.getState().links.find((link) => link.id === chat)?.peerPubKeyZ32 === grant.contact;
|
|
3210
|
+
}
|
|
3211
|
+
/** A chat removed from this device leaves the list; the last one gone turns auto-join off. */
|
|
3212
|
+
forgetChat(chat) {
|
|
3213
|
+
if (!this.grants.some((g) => g.chat === chat)) return;
|
|
3214
|
+
this.grants = this.grants.filter((g) => g.chat !== chat);
|
|
3215
|
+
this.save();
|
|
3216
|
+
}
|
|
3217
|
+
/**
|
|
3218
|
+
* Accepts the invitations that wait over a granted chat: on start (those that came while the daemon was down) and on
|
|
3219
|
+
* every change of the engine's state. One whose accept fails (the contact is not connected yet) is tried again on a
|
|
3220
|
+
* later change. Another contact who knows the group's id may have invited first: the engine then keeps the granted
|
|
3221
|
+
* one beside it (`others`), and it is the one taken (`switchGroup`, which tells the other contact no), as long as the
|
|
3222
|
+
* group held is only an invitation not answered yet. One beside a group joined or accepted waits for the person.
|
|
3223
|
+
*/
|
|
3224
|
+
check(state) {
|
|
3225
|
+
if (!this.host.joins || !this.grants.length) return;
|
|
3226
|
+
const links = new Map(state.links.map((link) => [link.id, link]));
|
|
3227
|
+
const changed = this.grants.filter((g) => {
|
|
3228
|
+
const link = links.get(g.chat);
|
|
3229
|
+
return link && link.peerPubKeyZ32 !== g.contact;
|
|
3230
|
+
});
|
|
3231
|
+
if (changed.length) {
|
|
3232
|
+
for (const g of changed) this.log(`group auto: chat ${g.chat}'s contact key changed: its invitations are no longer accepted by themselves`);
|
|
3233
|
+
this.grants = this.grants.filter((g) => !changed.includes(g));
|
|
3234
|
+
this.save();
|
|
3235
|
+
}
|
|
3236
|
+
const granted = (chat) => this.grants.some((g) => g.chat === chat && links.get(chat)?.peerPubKeyZ32 === g.contact);
|
|
3237
|
+
for (const group of state.groups) {
|
|
3238
|
+
if (this.accepting.has(group.id)) continue;
|
|
3239
|
+
const invitation = waiting(group);
|
|
3240
|
+
if (invitation && granted(invitation.linkId)) {
|
|
3241
|
+
this.accept(group.id, invitation.linkId);
|
|
3242
|
+
continue;
|
|
3243
|
+
}
|
|
3244
|
+
const other = group.others?.find((o) => "linkId" in o && granted(o.linkId));
|
|
3245
|
+
if (!other || !("linkId" in other)) continue;
|
|
3246
|
+
const held = group.invitation;
|
|
3247
|
+
if (group.status === void 0 && held && !held.accepted && !held.viaLink) {
|
|
3248
|
+
this.accept(group.id, other.linkId, true);
|
|
3249
|
+
continue;
|
|
3250
|
+
}
|
|
3251
|
+
const said = `${group.id}:${other.linkId}`;
|
|
3252
|
+
if (this.heldSaid.has(said)) continue;
|
|
3253
|
+
this.heldSaid.add(said);
|
|
3254
|
+
this.log(`group auto: an invitation to group ${group.id} from chat ${other.linkId} is kept beside another group under the same id: it waits for you (ghostly group show ${group.id})`);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
/** `switched`: the invitation is the one kept beside another contact's under its id, which it takes the place of first. */
|
|
3258
|
+
async accept(groupId, chat, switched = false) {
|
|
3259
|
+
this.accepting.add(groupId);
|
|
3260
|
+
try {
|
|
3261
|
+
if (switched) await this.host.engine.switchGroup({
|
|
3262
|
+
groupId,
|
|
3263
|
+
to: chat
|
|
3264
|
+
});
|
|
3265
|
+
await this.host.engine.acceptGroupInvitation({ groupId });
|
|
3266
|
+
this.failed.delete(groupId);
|
|
3267
|
+
this.log(`group auto: accepted the invitation to group ${groupId} from chat ${chat}${switched ? " (another contact's under the same id declined)" : ""}`);
|
|
3268
|
+
} catch (error) {
|
|
3269
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
3270
|
+
if (this.failed.get(groupId) !== why) this.log(`group auto: the invitation to group ${groupId} from chat ${chat} waits: ${why}`);
|
|
3271
|
+
this.failed.set(groupId, why);
|
|
3272
|
+
} finally {
|
|
3273
|
+
this.accepting.delete(groupId);
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
log(line) {
|
|
3277
|
+
(this.host.log ?? ((text) => process.stderr.write(`ghostly: ${text}\n`)))(line);
|
|
3278
|
+
}
|
|
3279
|
+
save() {
|
|
3280
|
+
const tmp = `${this.path}.tmp`;
|
|
3281
|
+
writeFileSync(tmp, JSON.stringify({ autoJoin: { from: this.grants } }, null, 2) + "\n", { mode: 384 });
|
|
3282
|
+
renameSync(tmp, this.path);
|
|
3283
|
+
}
|
|
3284
|
+
};
|
|
3285
|
+
/** An invitation over a contact chat that waits for this side's answer: not accepted yet, not taken back, not a link's. */
|
|
3286
|
+
function waiting(group) {
|
|
3287
|
+
const invitation = group.invitation;
|
|
3288
|
+
if (group.status !== void 0 || !invitation || invitation.accepted || invitation.takenBack || invitation.viaLink) return null;
|
|
3289
|
+
return invitation;
|
|
3290
|
+
}
|
|
3291
|
+
function readGrants(path) {
|
|
3292
|
+
if (!existsSync(path)) return [];
|
|
3293
|
+
try {
|
|
3294
|
+
const saved = JSON.parse(readFileSync(path, "utf8")).autoJoin?.from;
|
|
3295
|
+
if (!Array.isArray(saved)) return [];
|
|
3296
|
+
return saved.filter((g) => !!g && typeof g === "object" && typeof g.chat === "string" && typeof g.contact === "string");
|
|
3297
|
+
} catch {
|
|
3298
|
+
return [];
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
//#endregion
|
|
3091
3302
|
//#region src/joinLog.ts
|
|
3092
3303
|
/**
|
|
3093
3304
|
* A join through a group's link, as a daemon says it in its log (stderr): the steps of the knock and of the entry
|
|
@@ -5201,7 +5412,7 @@ function blobsFromDisk(value, depth = 0) {
|
|
|
5201
5412
|
* A wake republishes every chat with nothing published in the last seconds (on the CLI the DHT copy goes whatever the
|
|
5202
5413
|
* 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,
|
|
5203
5414
|
* a VPN in a reconnect loop) changed the addresses every tick and woke the engine every 10 s for nothing new. A network
|
|
5204
|
-
* wake within this long of the previous wake is held and runs once when the gap is over, the latest change included; each
|
|
5415
|
+
* wake within this long of the previous network wake is held and runs once when the gap is over, the latest change included; each
|
|
5205
5416
|
* 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
|
|
5206
5417
|
* after a quiet spell, and a sleep, still wake at once.
|
|
5207
5418
|
*/
|
|
@@ -5232,6 +5443,7 @@ function watchWake(onWake, options = {}) {
|
|
|
5232
5443
|
const tickMs = options.tickMs ?? 1e4;
|
|
5233
5444
|
const lateMs = options.lateMs ?? 3e4;
|
|
5234
5445
|
const now = options.now ?? Date.now;
|
|
5446
|
+
const monotonic = options.monotonic ?? (() => performance.now());
|
|
5235
5447
|
const addresses = options.addresses ?? (() => addressesKey());
|
|
5236
5448
|
let last = now();
|
|
5237
5449
|
let key = safe(addresses);
|
|
@@ -5240,7 +5452,7 @@ function watchWake(onWake, options = {}) {
|
|
|
5240
5452
|
/** A network change seen within the gap, not woken for yet. */
|
|
5241
5453
|
let held = false;
|
|
5242
5454
|
const wake = (why, at) => {
|
|
5243
|
-
wokeAt = at;
|
|
5455
|
+
if (why === "network") wokeAt = at;
|
|
5244
5456
|
held = false;
|
|
5245
5457
|
try {
|
|
5246
5458
|
onWake(why);
|
|
@@ -5253,17 +5465,18 @@ function watchWake(onWake, options = {}) {
|
|
|
5253
5465
|
const next = safe(addresses);
|
|
5254
5466
|
const moved = next !== "" && next !== key;
|
|
5255
5467
|
key = next;
|
|
5256
|
-
|
|
5257
|
-
if (
|
|
5468
|
+
const mono = monotonic();
|
|
5469
|
+
if (slept) return wake("sleep", mono);
|
|
5470
|
+
if (!(mono - wokeAt >= gap)) {
|
|
5258
5471
|
held ||= moved;
|
|
5259
5472
|
return;
|
|
5260
5473
|
}
|
|
5261
5474
|
if (held) {
|
|
5262
5475
|
gap = Math.min(gap * 2, WAKE_GAP_MAX_MS);
|
|
5263
|
-
return wake("network",
|
|
5476
|
+
return wake("network", mono);
|
|
5264
5477
|
}
|
|
5265
5478
|
gap = WAKE_GAP_MS;
|
|
5266
|
-
if (moved) wake("network",
|
|
5479
|
+
if (moved) wake("network", mono);
|
|
5267
5480
|
}, tickMs);
|
|
5268
5481
|
timer.unref?.();
|
|
5269
5482
|
return () => clearInterval(timer);
|
|
@@ -5477,7 +5690,7 @@ async function startRuntime(paths, options = {}) {
|
|
|
5477
5690
|
const restored = join(paths.dir, RESTORED_MARK);
|
|
5478
5691
|
if (existsSync(restored)) {
|
|
5479
5692
|
try {
|
|
5480
|
-
const rows = await import("./restoredRows-
|
|
5693
|
+
const rows = await import("./restoredRows-C3LcxmOw.js");
|
|
5481
5694
|
await rows.markRestoredWallet();
|
|
5482
5695
|
await rows.markLeftOutFiles(leftOutIn(restored));
|
|
5483
5696
|
await rows.forgetRatchets();
|
|
@@ -5497,15 +5710,15 @@ async function startRuntime(paths, options = {}) {
|
|
|
5497
5710
|
await installEventSource();
|
|
5498
5711
|
await preloadWalletModules();
|
|
5499
5712
|
(await import("./ghostly_iroh_web-BzAXJUYH.js")).initSync({ module: irohWasmBytes() });
|
|
5500
|
-
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-
|
|
5713
|
+
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-BtIyoDF2.js"), import("./fileBytes-B0z9A6Le.js")]);
|
|
5501
5714
|
registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
|
|
5502
|
-
if (await (await import("./blobFiles-
|
|
5503
|
-
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-
|
|
5504
|
-
const mainline = dht.off ? null : new (await (import("./mainline-
|
|
5715
|
+
if (await (await import("./blobFiles-BmsrvZc3.js")).moveBlobFiles()) await store.compact();
|
|
5716
|
+
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-DdtPxkqI.js"), import("./endpoint-DWHkXWVM.js")]);
|
|
5717
|
+
const mainline = dht.off ? null : new (await (import("./mainline-p6HOW7sb.js"))).Mainline({
|
|
5505
5718
|
bootstrap: dht.bootstrap,
|
|
5506
5719
|
host: dht.host
|
|
5507
5720
|
});
|
|
5508
|
-
const transport = mainline || pinned ? new (await (import("./mainline-
|
|
5721
|
+
const transport = mainline || pinned ? new (await (import("./mainline-p6HOW7sb.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
|
|
5509
5722
|
const apps = servedApps(paths.dir).length > 0;
|
|
5510
5723
|
const server = new EngineServer({
|
|
5511
5724
|
...transport ? { transport } : {},
|
|
@@ -5526,9 +5739,11 @@ async function startRuntime(paths, options = {}) {
|
|
|
5526
5739
|
holdFetch: nodeHoldFetch(),
|
|
5527
5740
|
callsSupport: callsUnavailable === null,
|
|
5528
5741
|
...callsUnavailable ? { callsUnavailable } : {},
|
|
5742
|
+
...options.autoJoins ? { autoJoins: options.autoJoins } : {},
|
|
5529
5743
|
...options.deferGroups ? { deferGroups: true } : {},
|
|
5530
5744
|
...options.deferChats ? { deferChats: true } : {},
|
|
5531
5745
|
...options.offline ? { offline: true } : {},
|
|
5746
|
+
...options.keepNewest ? { keepNewest: options.keepNewest } : {},
|
|
5532
5747
|
...process.env.GHOSTLY_TEST_WEBRTC_GROUP_LINKS === "1" ? { webrtcGroupLinks: true } : {}
|
|
5533
5748
|
});
|
|
5534
5749
|
try {
|
|
@@ -5586,11 +5801,15 @@ async function openHost(paths, mode, version, options = {}) {
|
|
|
5586
5801
|
locked();
|
|
5587
5802
|
};
|
|
5588
5803
|
let runtime;
|
|
5804
|
+
let groupAuto;
|
|
5805
|
+
const autoJoins = (chat) => !!groupAuto?.autoJoins(chat);
|
|
5589
5806
|
try {
|
|
5590
|
-
runtime = await startRuntime(paths,
|
|
5807
|
+
runtime = await startRuntime(paths, {
|
|
5591
5808
|
...options,
|
|
5592
|
-
logJoins: true
|
|
5593
|
-
|
|
5809
|
+
...mode === "daemon" ? { logJoins: true } : {},
|
|
5810
|
+
autoJoins,
|
|
5811
|
+
keepNewest: 100
|
|
5812
|
+
});
|
|
5594
5813
|
} catch (error) {
|
|
5595
5814
|
release();
|
|
5596
5815
|
throw error;
|
|
@@ -5605,8 +5824,9 @@ async function openHost(paths, mode, version, options = {}) {
|
|
|
5605
5824
|
const histories = /* @__PURE__ */ new Map(), newest = /* @__PURE__ */ new Map();
|
|
5606
5825
|
const whole = (id) => id.startsWith("group:") ? node.groupMessages({ groupId: id.slice(6) }) : node.getMessages(id);
|
|
5607
5826
|
const closed = !runtime.store.recovered;
|
|
5827
|
+
const kept = runtime.server.takeStartNewest();
|
|
5608
5828
|
for (const id of [...now.links.map((link) => link.id), ...now.groups.map((group) => `group:${group.id}`)]) {
|
|
5609
|
-
const page = closed && !runtime.server.historyChanged(id) ? await node.messagePage({
|
|
5829
|
+
const page = closed && !runtime.server.historyChanged(id) ? kept.get(id) ?? await node.messagePage({
|
|
5610
5830
|
linkId: id,
|
|
5611
5831
|
limit: 100
|
|
5612
5832
|
}) : null;
|
|
@@ -5618,6 +5838,7 @@ async function openHost(paths, mode, version, options = {}) {
|
|
|
5618
5838
|
newest,
|
|
5619
5839
|
whole
|
|
5620
5840
|
});
|
|
5841
|
+
await hub.ended((id) => fileStore.get(id));
|
|
5621
5842
|
announceJoins(hub, node);
|
|
5622
5843
|
calls = new CallManager({
|
|
5623
5844
|
engine: node,
|
|
@@ -5628,10 +5849,18 @@ async function openHost(paths, mode, version, options = {}) {
|
|
|
5628
5849
|
const manager = calls;
|
|
5629
5850
|
hub.onCallSignal((chat, signal) => manager.onSignal(chat, signal));
|
|
5630
5851
|
reportAppFrames(hub, node, paths.dir);
|
|
5852
|
+
const joiner = new GroupAutoJoin({
|
|
5853
|
+
engine: node,
|
|
5854
|
+
profileDir: paths.dir,
|
|
5855
|
+
joins: mode === "daemon"
|
|
5856
|
+
});
|
|
5857
|
+
groupAuto = joiner;
|
|
5858
|
+
hub.onState((s) => joiner.check(s));
|
|
5631
5859
|
runtime.server.attach(hub.sink, {
|
|
5632
5860
|
mark,
|
|
5633
5861
|
ids: [...histories.keys(), ...newest.keys()]
|
|
5634
5862
|
});
|
|
5863
|
+
joiner.check(node.getState());
|
|
5635
5864
|
} catch (error) {
|
|
5636
5865
|
hub.release();
|
|
5637
5866
|
await runtime.close().catch(() => {});
|
|
@@ -5643,7 +5872,8 @@ async function openHost(paths, mode, version, options = {}) {
|
|
|
5643
5872
|
hub,
|
|
5644
5873
|
mode,
|
|
5645
5874
|
version,
|
|
5646
|
-
calls
|
|
5875
|
+
calls,
|
|
5876
|
+
groupAuto
|
|
5647
5877
|
};
|
|
5648
5878
|
resumeHolds(ctx);
|
|
5649
5879
|
let closing = null;
|
|
@@ -5668,10 +5898,13 @@ async function serve(host) {
|
|
|
5668
5898
|
if (existsSync(path)) rmSync(path, { force: true });
|
|
5669
5899
|
const secret = newDaemonSecret(ctx.runtime.paths.dir);
|
|
5670
5900
|
const sockets = /* @__PURE__ */ new Set();
|
|
5901
|
+
const answering = /* @__PURE__ */ new Set();
|
|
5902
|
+
const stopping = new AbortController();
|
|
5903
|
+
ctx.stopping = stopping.signal;
|
|
5671
5904
|
const server = createServer((socket) => {
|
|
5672
5905
|
sockets.add(socket);
|
|
5673
5906
|
socket.on("close", () => sockets.delete(socket));
|
|
5674
|
-
connection(ctx, socket, secret);
|
|
5907
|
+
connection(ctx, socket, secret, answering);
|
|
5675
5908
|
});
|
|
5676
5909
|
await new Promise((resolve, reject) => {
|
|
5677
5910
|
server.once("error", reject);
|
|
@@ -5693,13 +5926,29 @@ async function serve(host) {
|
|
|
5693
5926
|
close: () => closing ??= new Promise((resolve) => {
|
|
5694
5927
|
removeDaemonSecret(ctx.runtime.paths.dir);
|
|
5695
5928
|
server.close(() => resolve());
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
for (const socket of sockets) socket.
|
|
5699
|
-
|
|
5929
|
+
stopping.abort();
|
|
5930
|
+
within(Promise.all(answering), STOP_ANSWERS_MS).then(() => {
|
|
5931
|
+
for (const socket of sockets) socket.end();
|
|
5932
|
+
setTimeout(() => {
|
|
5933
|
+
for (const socket of sockets) socket.destroy();
|
|
5934
|
+
}, 500).unref();
|
|
5935
|
+
});
|
|
5700
5936
|
})
|
|
5701
5937
|
};
|
|
5702
5938
|
}
|
|
5939
|
+
/** How long a stopping daemon gives the calls still open to answer before it ends their connections. */
|
|
5940
|
+
var STOP_ANSWERS_MS = 1e3;
|
|
5941
|
+
/** Settles once `promise` has, or after `ms`. */
|
|
5942
|
+
function within(promise, ms) {
|
|
5943
|
+
return new Promise((resolve) => {
|
|
5944
|
+
const timer = setTimeout(resolve, ms);
|
|
5945
|
+
timer.unref();
|
|
5946
|
+
promise.then(() => {
|
|
5947
|
+
clearTimeout(timer);
|
|
5948
|
+
resolve();
|
|
5949
|
+
});
|
|
5950
|
+
});
|
|
5951
|
+
}
|
|
5703
5952
|
/** Writes the daemon's start mark (`startingDaemon`); the function it returns removes it. A mark it cannot write is none. */
|
|
5704
5953
|
function markStarting(paths) {
|
|
5705
5954
|
try {
|
|
@@ -5751,7 +6000,8 @@ function ownerOnlyUmask() {
|
|
|
5751
6000
|
}
|
|
5752
6001
|
/** A client's nonce: 16 to 64 bytes as lowercase hex, so the proof is over nothing but a nonce. */
|
|
5753
6002
|
var NONCE = /^(?:[0-9a-f]{2}){16,64}$/;
|
|
5754
|
-
|
|
6003
|
+
/** `answering`: the calls of every connection still open, which a stopping daemon answers before it ends them. */
|
|
6004
|
+
function connection(ctx, socket, secret, answering) {
|
|
5755
6005
|
const unsubscribes = [];
|
|
5756
6006
|
let limit = MAX_UNREAD;
|
|
5757
6007
|
const unsubscribe = () => {
|
|
@@ -5826,10 +6076,10 @@ function connection(ctx, socket, secret) {
|
|
|
5826
6076
|
});
|
|
5827
6077
|
return;
|
|
5828
6078
|
}
|
|
5829
|
-
|
|
5830
|
-
const since = typeof params.since === "number" ? params.since : ctx.hub.lastSeq;
|
|
6079
|
+
let since;
|
|
5831
6080
|
let replay;
|
|
5832
6081
|
try {
|
|
6082
|
+
since = sinceSeq(request.params ?? {}, ctx.hub.lastSeq);
|
|
5833
6083
|
replay = ctx.hub.replay(since);
|
|
5834
6084
|
} catch (error) {
|
|
5835
6085
|
write({
|
|
@@ -5861,16 +6111,18 @@ function connection(ctx, socket, secret) {
|
|
|
5861
6111
|
for (const event of queued) if (event.seq > last) write({ event });
|
|
5862
6112
|
return;
|
|
5863
6113
|
}
|
|
5864
|
-
callApi(ctx, request.method, request.params ?? {}).then((result) => write({
|
|
6114
|
+
const answered = callApi(ctx, request.method, request.params ?? {}).then((result) => write({
|
|
5865
6115
|
id,
|
|
5866
6116
|
result: result ?? null
|
|
5867
6117
|
}), (error) => write({
|
|
5868
6118
|
id,
|
|
5869
6119
|
error: asCliError(error).toJSON()
|
|
5870
6120
|
}));
|
|
6121
|
+
answering.add(answered);
|
|
6122
|
+
answered.then(() => answering.delete(answered));
|
|
5871
6123
|
});
|
|
5872
6124
|
}
|
|
5873
6125
|
//#endregion
|
|
5874
|
-
export { BASELINE_NEWEST, MAX_UNREAD, keepServing, openHost, serve };
|
|
6126
|
+
export { BASELINE_NEWEST, MAX_UNREAD, STOP_ANSWERS_MS, keepServing, openHost, serve };
|
|
5875
6127
|
|
|
5876
|
-
//# sourceMappingURL=host-
|
|
6128
|
+
//# sourceMappingURL=host-BlUzZgQL.js.map
|