@ghostlytools/cli 1.8.1 → 1.10.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 +34 -23
- package/SKILL.md +9 -4
- package/dist/assets/{api-BpQC8dAw.js → api-BF_KwecF.js} +115 -45
- package/dist/assets/api-BF_KwecF.js.map +1 -0
- package/dist/assets/{api-CttDF-S5.js → api-DdrA86Ur.js} +2 -2
- package/dist/assets/{apiKit-CSMeHKgo.js → apiKit-Du1u2l4x.js} +8 -8
- package/dist/assets/apiKit-Du1u2l4x.js.map +1 -0
- package/dist/assets/{apps-DzFMdVt6.js → apps-Bti9fDoW.js} +1 -1
- package/dist/assets/{apps-DqTyZ40T.js → apps-DwPfp54I.js} +5 -3
- package/dist/assets/apps-DwPfp54I.js.map +1 -0
- package/dist/assets/{arkade-Cu3TbPxC.js → arkade-DOWpA2Kr.js} +2 -2
- package/dist/assets/{arkade-Cu3TbPxC.js.map → arkade-DOWpA2Kr.js.map} +1 -1
- package/dist/assets/{backup-CLZOORFC.js → backup-CeRckyl2.js} +1 -1
- package/dist/assets/{backup-CyTZhu28.js → backup-DZ_Q1eSu.js} +6 -6
- package/dist/assets/{backup-CyTZhu28.js.map → backup-DZ_Q1eSu.js.map} +1 -1
- package/dist/assets/{blobFiles-DOQDRdDI.js → blobFiles-BnjN_Vrz.js} +3 -3
- package/dist/assets/{blobFiles-DOQDRdDI.js.map → blobFiles-BnjN_Vrz.js.map} +1 -1
- package/dist/assets/buttons-BxIThdg9.js +332 -0
- package/dist/assets/buttons-BxIThdg9.js.map +1 -0
- package/dist/assets/buttons-D9QBHS9Y.js +2 -0
- package/dist/assets/client-D5E1RQYB.js +473 -0
- package/dist/assets/client-D5E1RQYB.js.map +1 -0
- package/dist/assets/{endpoint-BdaeBw2L.js → endpoint-DWHkXWVM.js} +101 -16
- package/dist/assets/endpoint-DWHkXWVM.js.map +1 -0
- package/dist/assets/{envelope-CGfUsR1m.js → envelope-CugS9qwQ.js} +2 -2
- package/dist/assets/{envelope-CGfUsR1m.js.map → envelope-CugS9qwQ.js.map} +1 -1
- package/dist/assets/{fileBytes-BPDKufla.js → fileBytes-DMzrIdCu.js} +1 -1
- package/dist/assets/{fileBytes-DNgrRL0R.js → fileBytes-DjBYYyXT.js} +3 -3
- package/dist/assets/{fileBytes-DNgrRL0R.js.map → fileBytes-DjBYYyXT.js.map} +1 -1
- package/dist/assets/{fileBytes-Q3ehcEr8.js → fileBytes-Douk1yOp.js} +2 -2
- package/dist/assets/{fileBytes-Q3ehcEr8.js.map → fileBytes-Douk1yOp.js.map} +1 -1
- package/dist/assets/fileBytesIdb-CD5Uv490.js +2 -0
- package/dist/assets/{fileBytesIdb-Dm1EyEbT.js → fileBytesIdb-CkClu9YI.js} +3 -3
- package/dist/assets/{fileBytesIdb-Dm1EyEbT.js.map → fileBytesIdb-CkClu9YI.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js → fileBytesOpfs-WryQuOgK.js} +3 -3
- package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js.map → fileBytesOpfs-WryQuOgK.js.map} +1 -1
- package/dist/assets/{fixedHosts-BiukTsd9.js → fixedHosts-B4E4VrYE.js} +4 -4
- package/dist/assets/{fixedHosts-BiukTsd9.js.map → fixedHosts-B4E4VrYE.js.map} +1 -1
- package/dist/assets/{groupFiles-CeF9nPv9.js → groupFiles-NonOYBKN.js} +380 -650
- package/dist/assets/groupFiles-NonOYBKN.js.map +1 -0
- package/dist/assets/{host-CKAehWP6.js → host-DvcVt5YI.js} +144 -33
- package/dist/assets/host-DvcVt5YI.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-B8Pdykhg.js → hyperdhtRelay-Ce42sR8x.js} +2 -2
- package/dist/assets/{hyperdhtRelay-B8Pdykhg.js.map → hyperdhtRelay-Ce42sR8x.js.map} +1 -1
- package/dist/assets/{idb-BkOJES5_.js → idb-BHsAqENE.js} +37 -6
- package/dist/assets/idb-BHsAqENE.js.map +1 -0
- package/dist/assets/{irohWeb-D6tAPHZa.js → irohWeb-C9ChbD-c.js} +71 -4
- package/dist/assets/{irohWeb-D6tAPHZa.js.map → irohWeb-C9ChbD-c.js.map} +1 -1
- package/dist/assets/{main-BDY-pfpz.js → main-4qE381KM.js} +226 -280
- package/dist/assets/main-4qE381KM.js.map +1 -0
- package/dist/assets/{mainline-3ueXpFQL.js → mainline-DOwZDHVy.js} +2 -2
- package/dist/assets/{mainline-3ueXpFQL.js.map → mainline-DOwZDHVy.js.map} +1 -1
- package/dist/assets/{networkReason-DhJYOomu.js → networkReason-MInk1Y63.js} +3 -3
- package/dist/assets/{networkReason-DhJYOomu.js.map → networkReason-MInk1Y63.js.map} +1 -1
- package/dist/assets/{nwc-B1Quqda-.js → nwc-CHLWFV1R.js} +3 -3
- package/dist/assets/{nwc-B1Quqda-.js.map → nwc-CHLWFV1R.js.map} +1 -1
- package/dist/assets/{nwcProvider-DUB6xO-b.js → nwcProvider-BlkPOJen.js} +2 -2
- package/dist/assets/{nwcProvider-DUB6xO-b.js.map → nwcProvider-BlkPOJen.js.map} +1 -1
- package/dist/assets/{ownDid-BfqHJdA6.js → ownDid-yXtY_1B5.js} +3 -3
- package/dist/assets/ownDid-yXtY_1B5.js.map +1 -0
- package/dist/assets/{profiles-MFtCmJwK.js → profiles-vbXHs0Mq.js} +40 -3
- package/dist/assets/profiles-vbXHs0Mq.js.map +1 -0
- package/dist/assets/{registry-CZTmtSws.js → registry-BN9r2pR4.js} +1 -1
- package/dist/assets/{registry-DwlTNQjr.js → registry-chCD0KWS.js} +5 -5
- package/dist/assets/registry-chCD0KWS.js.map +1 -0
- package/dist/assets/{resolve-BVwhiYjj.js → resolve-Dtzogt2W.js} +2 -2
- package/dist/assets/{resolve-BVwhiYjj.js.map → resolve-Dtzogt2W.js.map} +1 -1
- package/dist/assets/{restoredRows-BCRCjhdF.js → restoredRows-CRYwIx3g.js} +2 -2
- package/dist/assets/{restoredRows-BCRCjhdF.js.map → restoredRows-CRYwIx3g.js.map} +1 -1
- package/dist/assets/secretGuard-CSVNxXVW.js +1081 -0
- package/dist/assets/secretGuard-CSVNxXVW.js.map +1 -0
- package/dist/assets/secretGuard-Q2BKq0q0.js +2 -0
- package/dist/assets/{server-Br3XPwFG.js → server-BZnsm5X5.js} +2510 -569
- package/dist/assets/server-BZnsm5X5.js.map +1 -0
- package/dist/assets/{src-C4sOH4zH.js → src-DZagapGt.js} +2015 -161
- package/dist/assets/src-DZagapGt.js.map +1 -0
- package/dist/assets/{sshForges-CQQomStK.js → sshForges-BkTgy5rx.js} +16 -9
- package/dist/assets/{sshForges-CQQomStK.js.map → sshForges-BkTgy5rx.js.map} +1 -1
- package/dist/assets/{translate-C2aNyUkR.js → translate-B9SMd6uf.js} +15 -8
- package/dist/assets/translate-B9SMd6uf.js.map +1 -0
- package/dist/assets/{usdt-CMwatDnQ.js → usdt-BU4ezonh.js} +3 -3
- package/dist/assets/{usdt-CMwatDnQ.js.map → usdt-BU4ezonh.js.map} +1 -1
- package/dist/assets/{waitNotice-Ck3el3_Z.js → waitNotice-B8D8WhbE.js} +2 -2
- package/dist/assets/waitNotice-B8D8WhbE.js.map +1 -0
- package/dist/assets/{words-CqN2KG1r.js → words-jYy7lTcb.js} +5 -2
- package/dist/assets/words-jYy7lTcb.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/call-echo.mjs +7 -5
- package/package.json +1 -1
- package/dist/assets/api-BpQC8dAw.js.map +0 -1
- package/dist/assets/apiKit-CSMeHKgo.js.map +0 -1
- package/dist/assets/apps-DqTyZ40T.js.map +0 -1
- package/dist/assets/buttons-Bd9fR31r.js +0 -698
- package/dist/assets/buttons-Bd9fR31r.js.map +0 -1
- package/dist/assets/buttons-c4CJnL6i.js +0 -2
- package/dist/assets/daemonProof-DtrL5lE5.js +0 -236
- package/dist/assets/daemonProof-DtrL5lE5.js.map +0 -1
- package/dist/assets/endpoint-BdaeBw2L.js.map +0 -1
- package/dist/assets/fileBytesIdb-DZcESfTt.js +0 -2
- package/dist/assets/groupFiles-CeF9nPv9.js.map +0 -1
- package/dist/assets/host-CKAehWP6.js.map +0 -1
- package/dist/assets/idb-BkOJES5_.js.map +0 -1
- package/dist/assets/main-BDY-pfpz.js.map +0 -1
- package/dist/assets/ownDid-BfqHJdA6.js.map +0 -1
- package/dist/assets/profiles-MFtCmJwK.js.map +0 -1
- package/dist/assets/registry-DwlTNQjr.js.map +0 -1
- package/dist/assets/server-Br3XPwFG.js.map +0 -1
- package/dist/assets/src-C4sOH4zH.js.map +0 -1
- package/dist/assets/translate-C2aNyUkR.js.map +0 -1
- package/dist/assets/waitNotice-Ck3el3_Z.js.map +0 -1
- package/dist/assets/words-CqN2KG1r.js.map +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Fi as isPublicAddress, Hu as fromBase64Url, Su as setLinkTraceSink, as as buildSdpFromSignal, ds as signalHasVideo, is as answersOffer, li as checkPushEndpoint, ls as extractParamsFromSdp, ns as CALL_SIGNAL_MAX_AGE_MS, os as callRtcConfig, rs as RTC_CONFIG, ss as callSignalHeardAt, us as parseCallSignal } from "./src-DZagapGt.js";
|
|
2
|
+
import { o as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-C9ChbD-c.js";
|
|
3
3
|
import { r as asCliError, t as CliError } from "./errors-R4S2SAEM.js";
|
|
4
|
-
import { l as findOwnNamedChat, o as findChat } from "./apiKit-
|
|
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-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { l as findOwnNamedChat, o as findChat } from "./apiKit-Du1u2l4x.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-BF_KwecF.js";
|
|
6
|
+
import { S as runtimePath, g as startingPath, n as RESTORED_MARK, r as acquireLock, v as ownFolder, x as privateFolder, y as ownProfile } from "./profiles-vbXHs0Mq.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-D5E1RQYB.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, writeFileSync, writeSync } from "node:fs";
|
|
10
10
|
import { readFile } from "node:fs/promises";
|
|
11
11
|
import { dirname, join } from "node:path";
|
|
12
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
12
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
13
13
|
import { Readable } from "node:stream";
|
|
14
14
|
import { createServer, isIP } from "node:net";
|
|
15
15
|
import { createInterface } from "node:readline";
|
|
@@ -76,27 +76,40 @@ function clearAudioSockets(profileDir) {
|
|
|
76
76
|
* Serves one call's audio to one program at a time: what the program writes is handed to `onAudio` as it comes (raw
|
|
77
77
|
* PCM, any amount); `write` gives it the caller's audio. A second connection replaces the first. `close` ends the
|
|
78
78
|
* program's connection (it reads EOF) and removes the socket.
|
|
79
|
+
*
|
|
80
|
+
* Each call has a token (`token`, 32 random bytes as hex, given to the daemon's clients with the socket's path). A
|
|
81
|
+
* program sends it first, then a line feed. With `requireToken` (the default on Windows, whose named pipe any account
|
|
82
|
+
* of the machine may open and read), a connection is nobody's until it has: it hears nothing and replaces nobody, it is
|
|
83
|
+
* closed when what it sent is not the token, and when `proveMs` pass without it. On an owner-only Unix socket the token
|
|
84
|
+
* is optional: a connection is the program at once, and a token line it sends first is kept out of the call's audio.
|
|
79
85
|
*/
|
|
80
86
|
var AudioSocket = class AudioSocket {
|
|
81
87
|
path;
|
|
82
88
|
server;
|
|
83
89
|
rate;
|
|
90
|
+
requireToken;
|
|
91
|
+
proveMs;
|
|
84
92
|
client = null;
|
|
93
|
+
/** Connections that have not sent the token yet. */
|
|
94
|
+
unproven = /* @__PURE__ */ new Set();
|
|
85
95
|
closed = false;
|
|
86
96
|
/** Frames the program did not read in time, since the start. */
|
|
87
97
|
dropped = 0;
|
|
88
|
-
|
|
98
|
+
token = randomBytes(32).toString("hex");
|
|
99
|
+
constructor(path, server, rate, requireToken, proveMs) {
|
|
89
100
|
this.path = path;
|
|
90
101
|
this.server = server;
|
|
91
102
|
this.rate = rate;
|
|
103
|
+
this.requireToken = requireToken;
|
|
104
|
+
this.proveMs = proveMs;
|
|
92
105
|
}
|
|
93
|
-
static async open(path, rate, handlers) {
|
|
106
|
+
static async open(path, rate, handlers, options = {}) {
|
|
94
107
|
if (process.platform !== "win32") {
|
|
95
108
|
privateFolder(join(path, ".."), "calls will not put their audio there");
|
|
96
109
|
if (existsSync(path)) rmSync(path, { force: true });
|
|
97
110
|
}
|
|
98
111
|
let self = null;
|
|
99
|
-
const server = createServer((socket) => self.accept(socket, handlers));
|
|
112
|
+
const server = createServer((socket) => self ? self.accept(socket, handlers) : socket.destroy());
|
|
100
113
|
await new Promise((resolve, reject) => {
|
|
101
114
|
server.once("error", reject);
|
|
102
115
|
server.listen(path, () => {
|
|
@@ -105,7 +118,7 @@ var AudioSocket = class AudioSocket {
|
|
|
105
118
|
});
|
|
106
119
|
});
|
|
107
120
|
if (process.platform !== "win32") chmodSync(path, 384);
|
|
108
|
-
self = new AudioSocket(path, server, rate);
|
|
121
|
+
self = new AudioSocket(path, server, rate, options.requireToken ?? process.platform === "win32", options.proveMs ?? 5e3);
|
|
109
122
|
return self;
|
|
110
123
|
}
|
|
111
124
|
get connected() {
|
|
@@ -116,20 +129,57 @@ var AudioSocket = class AudioSocket {
|
|
|
116
129
|
socket.destroy();
|
|
117
130
|
return;
|
|
118
131
|
}
|
|
119
|
-
const before = this.client;
|
|
120
|
-
this.client = socket;
|
|
121
|
-
before?.end();
|
|
122
132
|
socket.setNoDelay?.(true);
|
|
133
|
+
socket.on("error", () => {});
|
|
134
|
+
const line = Buffer.from(`${this.token}\n`);
|
|
135
|
+
let head = Buffer.alloc(0);
|
|
136
|
+
const take = () => {
|
|
137
|
+
this.unproven.delete(socket);
|
|
138
|
+
const before = this.client;
|
|
139
|
+
this.client = socket;
|
|
140
|
+
before?.end();
|
|
141
|
+
handlers.onClient?.(true);
|
|
142
|
+
};
|
|
143
|
+
let timer = null;
|
|
144
|
+
if (this.requireToken) {
|
|
145
|
+
this.unproven.add(socket);
|
|
146
|
+
timer = setTimeout(() => socket.destroy(), this.proveMs);
|
|
147
|
+
timer.unref?.();
|
|
148
|
+
} else take();
|
|
123
149
|
socket.on("data", (chunk) => {
|
|
150
|
+
if (head) {
|
|
151
|
+
head = Buffer.concat([head, chunk]);
|
|
152
|
+
if (this.requireToken) {
|
|
153
|
+
if (head.length < line.length) return;
|
|
154
|
+
if (!timingSafeEqual(head.subarray(0, line.length), line)) {
|
|
155
|
+
socket.destroy();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (timer) clearTimeout(timer);
|
|
159
|
+
take();
|
|
160
|
+
} else {
|
|
161
|
+
const seen = Math.min(head.length, line.length);
|
|
162
|
+
if (!head.subarray(0, seen).equals(line.subarray(0, seen))) {
|
|
163
|
+
chunk = head;
|
|
164
|
+
head = null;
|
|
165
|
+
if (this.client === socket) handlers.onAudio(chunk);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (head.length < line.length) return;
|
|
169
|
+
}
|
|
170
|
+
chunk = head.subarray(line.length);
|
|
171
|
+
head = null;
|
|
172
|
+
if (!chunk.length) return;
|
|
173
|
+
}
|
|
124
174
|
if (this.client === socket) handlers.onAudio(chunk);
|
|
125
175
|
});
|
|
126
|
-
socket.on("error", () => {});
|
|
127
176
|
socket.on("close", () => {
|
|
177
|
+
if (timer) clearTimeout(timer);
|
|
178
|
+
this.unproven.delete(socket);
|
|
128
179
|
if (this.client !== socket) return;
|
|
129
180
|
this.client = null;
|
|
130
181
|
handlers.onClient?.(false);
|
|
131
182
|
});
|
|
132
|
-
handlers.onClient?.(true);
|
|
133
183
|
}
|
|
134
184
|
/** One frame of the caller's audio for the program; dropped when nobody listens or the program stopped reading. */
|
|
135
185
|
write(frame) {
|
|
@@ -149,6 +199,8 @@ var AudioSocket = class AudioSocket {
|
|
|
149
199
|
this.client = null;
|
|
150
200
|
client?.end();
|
|
151
201
|
if (client) setTimeout(() => client.destroy(), 2e3).unref();
|
|
202
|
+
for (const socket of this.unproven) socket.destroy();
|
|
203
|
+
this.unproven.clear();
|
|
152
204
|
return new Promise((resolve) => {
|
|
153
205
|
this.server.close(() => resolve());
|
|
154
206
|
if (process.platform !== "win32") rmSync(this.path, { force: true });
|
|
@@ -1525,6 +1577,7 @@ var CallManager = class {
|
|
|
1525
1577
|
audioInfo(call) {
|
|
1526
1578
|
return call.socket ? {
|
|
1527
1579
|
socket: call.socket.path,
|
|
1580
|
+
token: call.socket.token,
|
|
1528
1581
|
rate: call.rate,
|
|
1529
1582
|
channels: 1,
|
|
1530
1583
|
format: "s16le",
|
|
@@ -1636,7 +1689,10 @@ var SEEN_KEEP_MS = 2592e6;
|
|
|
1636
1689
|
var SWEEP_EVERY_MS = 216e5;
|
|
1637
1690
|
/** How long a `file.*` event waits for the message that carries its file. */
|
|
1638
1691
|
var FILE_MESSAGE_WAIT_MS = 2e3;
|
|
1639
|
-
/**
|
|
1692
|
+
/**
|
|
1693
|
+
* The notice an app sends when a chat first goes live (apps/ui/src/hooks/useChat.ts): shown as a line, not a message.
|
|
1694
|
+
* The contact's only on the row the engine took as their joined line (`StoredMessage.joinLine`).
|
|
1695
|
+
*/
|
|
1640
1696
|
var JOIN_NOTICE = /^👋 (?:(.+) )?joined$/;
|
|
1641
1697
|
/**
|
|
1642
1698
|
* Turns the engine's events into the stream, keeps the journal, and remembers which messages it already reported
|
|
@@ -1648,6 +1704,13 @@ var EventHub = class {
|
|
|
1648
1704
|
now;
|
|
1649
1705
|
seenDb;
|
|
1650
1706
|
seq = 0;
|
|
1707
|
+
/**
|
|
1708
|
+
* The last seq the journal dropped (a trim, a journal set aside), kept in `<journal>.dropped`: a replay from before it
|
|
1709
|
+
* starts with `events.gap`. What the person removed (`forget`) leaves holes after it, which are none.
|
|
1710
|
+
*/
|
|
1711
|
+
dropped = 0;
|
|
1712
|
+
/** Whether `<journal>.dropped` is written: before `forget` first takes a journal's first events, it must be. */
|
|
1713
|
+
marked = false;
|
|
1651
1714
|
journalLines = 0;
|
|
1652
1715
|
journalBytes = 0;
|
|
1653
1716
|
listeners = /* @__PURE__ */ new Set();
|
|
@@ -1687,13 +1750,16 @@ var EventHub = class {
|
|
|
1687
1750
|
/** Loads the journal's last seq and the seen set; call before `sink` is attached. */
|
|
1688
1751
|
async open() {
|
|
1689
1752
|
try {
|
|
1753
|
+
const dropped = readDropped(this.journalPath + ".dropped");
|
|
1690
1754
|
if (existsSync(this.journalPath)) {
|
|
1691
|
-
const { seq, lines, size } = journalEnd(this.journalPath);
|
|
1755
|
+
const { seq, first, lines, size } = journalEnd(this.journalPath);
|
|
1692
1756
|
this.journalLines = lines;
|
|
1693
1757
|
this.journalBytes = size;
|
|
1694
1758
|
this.seq = seq;
|
|
1759
|
+
this.dropped = dropped ?? (first === void 0 ? seq : first - 1);
|
|
1760
|
+
this.marked = dropped !== void 0;
|
|
1695
1761
|
if (size > 33554432 || lines > 2e4) this.trimJournal();
|
|
1696
|
-
}
|
|
1762
|
+
} else if (dropped !== void 0) rmSync(this.journalPath + ".dropped", { force: true });
|
|
1697
1763
|
} catch (error) {
|
|
1698
1764
|
process.stderr.write(`ghostly: the event journal could not be read, a new one begins: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1699
1765
|
try {
|
|
@@ -1701,6 +1767,7 @@ var EventHub = class {
|
|
|
1701
1767
|
} catch {}
|
|
1702
1768
|
this.journalLines = 0;
|
|
1703
1769
|
this.journalBytes = 0;
|
|
1770
|
+
this.markDropped(this.seq);
|
|
1704
1771
|
}
|
|
1705
1772
|
this.db = await new Promise((resolve, reject) => {
|
|
1706
1773
|
const request = indexedDB.open(this.seenDb, 1);
|
|
@@ -1821,7 +1888,10 @@ var EventHub = class {
|
|
|
1821
1888
|
this.appListeners.add(listener);
|
|
1822
1889
|
return () => this.appListeners.delete(listener);
|
|
1823
1890
|
}
|
|
1824
|
-
/**
|
|
1891
|
+
/**
|
|
1892
|
+
* Events after `since` still in the journal; a gap event first when older ones were dropped (`dropped`). The events of
|
|
1893
|
+
* what the person removed (`forget`) are no gap: they are not here on purpose.
|
|
1894
|
+
*/
|
|
1825
1895
|
replay(since) {
|
|
1826
1896
|
if (!existsSync(this.journalPath) || since >= this.seq) return [];
|
|
1827
1897
|
const out = [];
|
|
@@ -1829,16 +1899,29 @@ var EventHub = class {
|
|
|
1829
1899
|
const event = JSON.parse(line);
|
|
1830
1900
|
if (event.seq > since) out.push(event);
|
|
1831
1901
|
} catch {}
|
|
1832
|
-
if (out.length && out[0].seq > since + 1) out.unshift({
|
|
1902
|
+
if (out.length && out[0].seq > since + 1 && since < this.dropped) out.unshift({
|
|
1833
1903
|
seq: since,
|
|
1834
1904
|
id: `events.gap:${since}:${out[0].seq}`,
|
|
1835
1905
|
type: "events.gap",
|
|
1836
1906
|
at: this.now(),
|
|
1837
1907
|
from: since + 1,
|
|
1838
|
-
to: out[0].seq - 1
|
|
1908
|
+
to: Math.min(this.dropped, out[0].seq - 1)
|
|
1839
1909
|
});
|
|
1840
1910
|
return out;
|
|
1841
1911
|
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Notes that the journal no longer holds the events up to `seq`. Written before the journal is: a stop in between
|
|
1914
|
+
* leaves the mark ahead of the journal (a gap said where none was), never behind it (a gap not said).
|
|
1915
|
+
*/
|
|
1916
|
+
markDropped(seq) {
|
|
1917
|
+
this.dropped = seq;
|
|
1918
|
+
try {
|
|
1919
|
+
writeFileSync(this.journalPath + ".dropped", String(seq), { mode: 384 });
|
|
1920
|
+
this.marked = true;
|
|
1921
|
+
} catch (error) {
|
|
1922
|
+
process.stderr.write(`ghostly: event journal error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1842
1925
|
get lastSeq() {
|
|
1843
1926
|
return this.seq;
|
|
1844
1927
|
}
|
|
@@ -1890,6 +1973,8 @@ var EventHub = class {
|
|
|
1890
1973
|
let start = lines.length, bytes = 0;
|
|
1891
1974
|
while (start > 0 && bytes + Buffer.byteLength(lines[start - 1]) + 1 <= 16777216) bytes += Buffer.byteLength(lines[--start]) + 1;
|
|
1892
1975
|
const kept = lines.slice(start);
|
|
1976
|
+
const first = firstSeq(kept);
|
|
1977
|
+
this.markDropped(Math.max(this.dropped, first === void 0 ? this.seq : first - 1));
|
|
1893
1978
|
writeFileSync(this.journalPath + ".tmp", kept.length ? kept.join("\n") + "\n" : "", { mode: 384 });
|
|
1894
1979
|
renameSync(this.journalPath + ".tmp", this.journalPath);
|
|
1895
1980
|
this.journalLines = kept.length;
|
|
@@ -1938,6 +2023,7 @@ var EventHub = class {
|
|
|
1938
2023
|
return [JSON.stringify(written)];
|
|
1939
2024
|
});
|
|
1940
2025
|
if (!changed) return;
|
|
2026
|
+
if (!this.marked) this.markDropped(this.dropped);
|
|
1941
2027
|
const tail = kept.length ? kept.join("\n") + "\n" : "";
|
|
1942
2028
|
writeFileSync(this.journalPath + ".tmp", Buffer.concat([bytes.subarray(start, from), Buffer.from(tail)]), { mode: 384 });
|
|
1943
2029
|
renameSync(this.journalPath + ".tmp", this.journalPath);
|
|
@@ -2289,7 +2375,7 @@ var EventHub = class {
|
|
|
2289
2375
|
message: json()
|
|
2290
2376
|
});
|
|
2291
2377
|
} else {
|
|
2292
|
-
const notice = JOIN_NOTICE.exec(message.text);
|
|
2378
|
+
const notice = message.sender === "me" || message.joinLine ? JOIN_NOTICE.exec(message.text) : null;
|
|
2293
2379
|
const type = notice ? message.sender === "peer" ? "chat.joined" : "chat.announced" : message.sender === "peer" ? "message.received" : "message.sent";
|
|
2294
2380
|
this.emit(type, `${type}:${chat}:${message.id}`, {
|
|
2295
2381
|
chat,
|
|
@@ -2553,6 +2639,13 @@ function journalEnd(path) {
|
|
|
2553
2639
|
if (stop > from) lines++;
|
|
2554
2640
|
from = stop + 1;
|
|
2555
2641
|
}
|
|
2642
|
+
let first;
|
|
2643
|
+
for (let from = start; from < bytes.length && first === void 0;) {
|
|
2644
|
+
const end = bytes.indexOf(10, from);
|
|
2645
|
+
const stop = end === -1 ? bytes.length : end;
|
|
2646
|
+
if (stop > from) first = firstSeq([bytes.toString("utf8", from, stop)]);
|
|
2647
|
+
from = stop + 1;
|
|
2648
|
+
}
|
|
2556
2649
|
let seq = 0;
|
|
2557
2650
|
for (let stop = bytes.length; stop > start;) {
|
|
2558
2651
|
const from = Math.max(start, bytes.lastIndexOf(10, stop - 1) + 1);
|
|
@@ -2564,10 +2657,27 @@ function journalEnd(path) {
|
|
|
2564
2657
|
}
|
|
2565
2658
|
return {
|
|
2566
2659
|
seq,
|
|
2660
|
+
first,
|
|
2567
2661
|
lines,
|
|
2568
2662
|
size
|
|
2569
2663
|
};
|
|
2570
2664
|
}
|
|
2665
|
+
/** The seq of the first of these lines that can be read. */
|
|
2666
|
+
function firstSeq(lines) {
|
|
2667
|
+
for (const line of lines) try {
|
|
2668
|
+
const { seq } = JSON.parse(line);
|
|
2669
|
+
if (typeof seq === "number") return seq;
|
|
2670
|
+
} catch {}
|
|
2671
|
+
}
|
|
2672
|
+
/** The journal's dropped mark (`EventHub.dropped`), or undefined when there is none (a journal from before it). */
|
|
2673
|
+
function readDropped(path) {
|
|
2674
|
+
try {
|
|
2675
|
+
const seq = Number(readFileSync(path, "utf8").trim());
|
|
2676
|
+
return Number.isSafeInteger(seq) && seq >= 0 ? seq : void 0;
|
|
2677
|
+
} catch {
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2571
2681
|
/** The bytes of the journal's last `JOURNAL_MAX_BYTES`, `start` where its first whole line begins in them, and its size. */
|
|
2572
2682
|
function journalWindow(path) {
|
|
2573
2683
|
const fd = openSync(path, "r");
|
|
@@ -2613,6 +2723,8 @@ var SAID = {
|
|
|
2613
2723
|
"link.native": "entry session: WebRTC connected nothing, going on over a native transport",
|
|
2614
2724
|
"invite.sent": "invitation sent on the entry session",
|
|
2615
2725
|
"invite.received": "invitation received on the entry session: accepting",
|
|
2726
|
+
"full.sent": "the group is full: told the joiner on the entry session",
|
|
2727
|
+
"full.received": "the group is full: knocking on until there is room",
|
|
2616
2728
|
"welcome.sent": "welcome sent",
|
|
2617
2729
|
"welcome.received": "welcome received: in the group"
|
|
2618
2730
|
};
|
|
@@ -4881,7 +4993,7 @@ async function startRuntime(paths, options = {}) {
|
|
|
4881
4993
|
const restored = join(paths.dir, RESTORED_MARK);
|
|
4882
4994
|
if (existsSync(restored)) {
|
|
4883
4995
|
try {
|
|
4884
|
-
const rows = await import("./restoredRows-
|
|
4996
|
+
const rows = await import("./restoredRows-CRYwIx3g.js");
|
|
4885
4997
|
await rows.markRestoredWallet();
|
|
4886
4998
|
await rows.markLeftOutFiles(leftOutIn(restored));
|
|
4887
4999
|
await rows.forgetRatchets();
|
|
@@ -4901,15 +5013,15 @@ async function startRuntime(paths, options = {}) {
|
|
|
4901
5013
|
await installEventSource();
|
|
4902
5014
|
await preloadWalletModules();
|
|
4903
5015
|
(await import("./ghostly_iroh_web-BzAXJUYH.js")).initSync({ module: irohWasmBytes() });
|
|
4904
|
-
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-
|
|
5016
|
+
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-DMzrIdCu.js"), import("./fileBytes-Douk1yOp.js")]);
|
|
4905
5017
|
registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
|
|
4906
|
-
if (await (await import("./blobFiles-
|
|
4907
|
-
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-
|
|
4908
|
-
const mainline = dht.off ? null : new (await (import("./mainline-
|
|
5018
|
+
if (await (await import("./blobFiles-BnjN_Vrz.js")).moveBlobFiles()) await store.compact();
|
|
5019
|
+
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-BZnsm5X5.js"), import("./endpoint-DWHkXWVM.js")]);
|
|
5020
|
+
const mainline = dht.off ? null : new (await (import("./mainline-DOwZDHVy.js"))).Mainline({
|
|
4909
5021
|
bootstrap: dht.bootstrap,
|
|
4910
5022
|
host: dht.host
|
|
4911
5023
|
});
|
|
4912
|
-
const transport = mainline || pinned ? new (await (import("./mainline-
|
|
5024
|
+
const transport = mainline || pinned ? new (await (import("./mainline-DOwZDHVy.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
|
|
4913
5025
|
const apps = servedApps(paths.dir).length > 0;
|
|
4914
5026
|
const server = new EngineServer({
|
|
4915
5027
|
...transport ? { transport } : {},
|
|
@@ -4956,8 +5068,6 @@ async function startRuntime(paths, options = {}) {
|
|
|
4956
5068
|
}
|
|
4957
5069
|
//#endregion
|
|
4958
5070
|
//#region src/host.ts
|
|
4959
|
-
/** The longest request line the daemon reads (WISP 1100 § Framing). */
|
|
4960
|
-
var MAX_LINE = 16777216;
|
|
4961
5071
|
/**
|
|
4962
5072
|
* The most a connection may leave unread (answers and events the daemon wrote that its client has not taken): past
|
|
4963
5073
|
* it, the connection ends. A `listen` stopped with Ctrl+Z, or a client that stops reading, kept every later event in
|
|
@@ -4977,6 +5087,7 @@ var BASELINE_NEWEST = 100;
|
|
|
4977
5087
|
* `deferGroups`: the groups' sessions would spend the relays' budget its message needs.
|
|
4978
5088
|
*/
|
|
4979
5089
|
async function openHost(paths, mode, version, options = {}) {
|
|
5090
|
+
ownProfile(paths.dir);
|
|
4980
5091
|
const locked = acquireLock(paths);
|
|
4981
5092
|
const unmark = mode === "daemon" ? markStarting(paths) : () => {};
|
|
4982
5093
|
const release = () => {
|
|
@@ -5267,6 +5378,6 @@ function connection(ctx, socket, secret) {
|
|
|
5267
5378
|
});
|
|
5268
5379
|
}
|
|
5269
5380
|
//#endregion
|
|
5270
|
-
export { BASELINE_NEWEST,
|
|
5381
|
+
export { BASELINE_NEWEST, MAX_UNREAD, keepServing, openHost, serve };
|
|
5271
5382
|
|
|
5272
|
-
//# sourceMappingURL=host-
|
|
5383
|
+
//# sourceMappingURL=host-DvcVt5YI.js.map
|