@ghostlytools/cli 1.13.1 → 1.13.3
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 +15 -12
- package/dist/assets/api-DO0YMLiB.js +3 -0
- package/dist/assets/{api-Dnq86JAA.js → api-Dz2cw7WD.js} +512 -103
- package/dist/assets/api-Dz2cw7WD.js.map +1 -0
- package/dist/assets/{apiKit-nLK4jeTq.js → apiKit-DAFsWtyk.js} +53 -7
- package/dist/assets/apiKit-DAFsWtyk.js.map +1 -0
- package/dist/assets/{appFetch-wqBWi3Ry.js → appFetch-BQO5Pk7W.js} +2 -2
- package/dist/assets/{appFetch-wqBWi3Ry.js.map → appFetch-BQO5Pk7W.js.map} +1 -1
- package/dist/assets/{apps-DBVhKpfe.js → apps-B88rYWRm.js} +51 -23
- package/dist/assets/apps-B88rYWRm.js.map +1 -0
- package/dist/assets/{apps-nLtyhC2f.js → apps-D4KRpZB4.js} +1 -1
- package/dist/assets/{arkade-DryM-q5n.js → arkade-B6UNf5HI.js} +2 -2
- package/dist/assets/{arkade-DryM-q5n.js.map → arkade-B6UNf5HI.js.map} +1 -1
- package/dist/assets/{backup-D6s0LQdg.js → backup-BeXBtbVL.js} +1 -1
- package/dist/assets/{backup-Bczllmzf.js → backup-CNLY905d.js} +15 -8
- package/dist/assets/backup-CNLY905d.js.map +1 -0
- package/dist/assets/bark_ffi_wasm_bg-CjjCN3FD.js +5 -0
- package/dist/assets/{bitcoind-DML_-Xbv.js → bitcoind-BXZdQ1wZ.js} +2 -2
- package/dist/assets/{bitcoind-DML_-Xbv.js.map → bitcoind-BXZdQ1wZ.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-D6IFIaJi.js +5 -0
- package/dist/assets/{buttons-B3C3vdhH.js → buttons-BKojbx0Q.js} +4 -4
- package/dist/assets/{buttons-B3C3vdhH.js.map → buttons-BKojbx0Q.js.map} +1 -1
- package/dist/assets/buttons-_5Fw8uHn.js +1 -0
- package/dist/assets/{client-B7jRrSnb.js → client-BtPhfWjK.js} +2 -2
- package/dist/assets/{client-B7jRrSnb.js.map → client-BtPhfWjK.js.map} +1 -1
- package/dist/assets/{engineErrors--9hfgKlK.js → engineErrors-wWlLy54D.js} +11 -3
- package/dist/assets/engineErrors-wWlLy54D.js.map +1 -0
- package/dist/assets/{fedimintSdk-D-6H9Pe7.js → fedimintSdk-eLXBrj9i.js} +2 -2
- package/dist/assets/{fedimintSdk-D-6H9Pe7.js.map → fedimintSdk-eLXBrj9i.js.map} +1 -1
- package/dist/assets/fedimint_client_wasm_bg-CRQlnJdu.js +5 -0
- package/dist/assets/{fixedHosts-H3i6o9Iy.js → fixedHosts-BJFL8Ell.js} +3 -3
- package/dist/assets/{fixedHosts-H3i6o9Iy.js.map → fixedHosts-BJFL8Ell.js.map} +1 -1
- package/dist/assets/{groupMeta--fxSh792.js → groupMeta-Cz95F6sX.js} +201 -43
- package/dist/assets/groupMeta-Cz95F6sX.js.map +1 -0
- package/dist/assets/{host-CGzVFfMz.js → host-BsBWxTtW.js} +276 -53
- package/dist/assets/host-BsBWxTtW.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-Ce-gWsRY.js → hyperdhtRelay-B34Zhz4P.js} +2 -2
- package/dist/assets/{hyperdhtRelay-Ce-gWsRY.js.map → hyperdhtRelay-B34Zhz4P.js.map} +1 -1
- package/dist/assets/{hyperdhtRelay-B4_wdCtx.js → hyperdhtRelay-DDwU5b4P.js} +2 -2
- package/dist/assets/{hyperdhtRelay-B4_wdCtx.js.map → hyperdhtRelay-DDwU5b4P.js.map} +1 -1
- package/dist/assets/{identityProofs-Cksc_K7_.js → identityProofs-zI_Iy9uI.js} +154 -27
- package/dist/assets/identityProofs-zI_Iy9uI.js.map +1 -0
- package/dist/assets/{irohWeb-Dp1i8v6n.js → irohWeb-BLDcHwYz.js} +10866 -4829
- package/dist/assets/irohWeb-BLDcHwYz.js.map +1 -0
- package/dist/assets/{linkPreview-DdMf-YAc.js → linkPreview-5kHmKUTN.js} +20 -8
- package/dist/assets/linkPreview-5kHmKUTN.js.map +1 -0
- package/dist/assets/{main-C8J53SwH.js → main-D48Ben7C.js} +122 -49
- package/dist/assets/main-D48Ben7C.js.map +1 -0
- package/dist/assets/{mainline-DY95WbuK.js → mainline-CDUXtV-I.js} +2 -2
- package/dist/assets/{mainline-DY95WbuK.js.map → mainline-CDUXtV-I.js.map} +1 -1
- package/dist/assets/{networkReason-Be-hMghr.js → networkReason-DYlPZS5M.js} +2 -2
- package/dist/assets/{networkReason-Be-hMghr.js.map → networkReason-DYlPZS5M.js.map} +1 -1
- package/dist/assets/{ownDid-oa-T2vmZ.js → ownDid-CwxFBzOH.js} +6 -5
- package/dist/assets/ownDid-CwxFBzOH.js.map +1 -0
- package/dist/assets/{ownStatus-Bc08eNJY.js → ownStatus-DjD0sQKF.js} +34 -11
- package/dist/assets/ownStatus-DjD0sQKF.js.map +1 -0
- package/dist/assets/{pairedTransports-Dppn8lUN.js → pairedTransports-DAzupLYo.js} +21 -15
- package/dist/assets/pairedTransports-DAzupLYo.js.map +1 -0
- package/dist/assets/{paymentIntent-DySU3Ajm.js → paymentIntent-Cr3uZa_0.js} +2 -2
- package/dist/assets/{paymentIntent-DySU3Ajm.js.map → paymentIntent-Cr3uZa_0.js.map} +1 -1
- package/dist/assets/{profiles-B2uy04ph.js → profiles-BAJf0c9E.js} +33 -8
- package/dist/assets/profiles-BAJf0c9E.js.map +1 -0
- package/dist/assets/{registry-bLIfG619.js → registry-CHwHTWbK.js} +1 -1
- package/dist/assets/{registry-DbTLLs3y.js → registry-CPuexTle.js} +25 -13
- package/dist/assets/registry-CPuexTle.js.map +1 -0
- package/dist/assets/{relay-CHWg5hpZ.js → relay-gJTOYQJZ.js} +93 -7
- package/dist/assets/relay-gJTOYQJZ.js.map +1 -0
- package/dist/assets/{resolve-DNX-eecG.js → resolve-BqmGXKn4.js} +3 -3
- package/dist/assets/{resolve-DNX-eecG.js.map → resolve-BqmGXKn4.js.map} +1 -1
- package/dist/assets/{server-DWJ4RzJn.js → server-e4oKeNez.js} +901 -6262
- package/dist/assets/server-e4oKeNez.js.map +1 -0
- package/dist/assets/{sshForges-BnvwmNj-.js → sshForges-Cqt3qfWe.js} +2 -2
- package/dist/assets/{sshForges-BnvwmNj-.js.map → sshForges-Cqt3qfWe.js.map} +1 -1
- package/dist/assets/{translate-CHj_PdLg.js → translate-DnuQMfj0.js} +10 -4
- package/dist/assets/translate-DnuQMfj0.js.map +1 -0
- package/dist/assets/{usdt-CBJ4Q5Ji.js → usdt-DLmtf8F9.js} +4 -4
- package/dist/assets/{usdt-CBJ4Q5Ji.js.map → usdt-DLmtf8F9.js.map} +1 -1
- package/dist/assets/{waitNotice-Cvz5CiKR.js → waitNotice-mB0Ym145.js} +2 -2
- package/dist/assets/{waitNotice-Cvz5CiKR.js.map → waitNotice-mB0Ym145.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/assets/api-DF36rBJK.js +0 -3
- package/dist/assets/api-Dnq86JAA.js.map +0 -1
- package/dist/assets/apiKit-nLK4jeTq.js.map +0 -1
- package/dist/assets/apps-DBVhKpfe.js.map +0 -1
- package/dist/assets/backup-Bczllmzf.js.map +0 -1
- package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js +0 -5
- package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js.map +0 -1
- package/dist/assets/bark_ffi_wasm_bg-VNmaJsc9.wasm +0 -0
- package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js +0 -5
- package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js.map +0 -1
- package/dist/assets/bitcoindevkit_bg-DXil67yS.wasm +0 -0
- package/dist/assets/buttons-DaY5FYlV.js +0 -1
- package/dist/assets/engineErrors--9hfgKlK.js.map +0 -1
- package/dist/assets/fedimint_client_wasm_bg-Cr5xGD-w.js +0 -5
- package/dist/assets/fedimint_client_wasm_bg-Cr5xGD-w.js.map +0 -1
- package/dist/assets/fedimint_client_wasm_bg-DeFtkIv6.wasm +0 -0
- package/dist/assets/groupMeta--fxSh792.js.map +0 -1
- package/dist/assets/host-CGzVFfMz.js.map +0 -1
- package/dist/assets/identityProofs-Cksc_K7_.js.map +0 -1
- package/dist/assets/irohWeb-Dp1i8v6n.js.map +0 -1
- package/dist/assets/linkPreview-DdMf-YAc.js.map +0 -1
- package/dist/assets/main-C8J53SwH.js.map +0 -1
- package/dist/assets/ownDid-oa-T2vmZ.js.map +0 -1
- package/dist/assets/ownStatus-Bc08eNJY.js.map +0 -1
- package/dist/assets/pairedTransports-Dppn8lUN.js.map +0 -1
- package/dist/assets/profiles-B2uy04ph.js.map +0 -1
- package/dist/assets/registry-DbTLLs3y.js.map +0 -1
- package/dist/assets/relay-CHWg5hpZ.js.map +0 -1
- package/dist/assets/server-DWJ4RzJn.js.map +0 -1
- package/dist/assets/translate-CHj_PdLg.js.map +0 -1
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { p as fileStore } from "./idb-ewvbqyDI.js";
|
|
2
|
-
import { _ as
|
|
3
|
-
import {
|
|
2
|
+
import { _ as groupJson, b as resumeHolds, d as reportAppFrames, f as servedApps, g as chatMessageJson, h as chatJson, p as nodeLocalFetch, r as callApi, u as paymentJson, v as groupMessageJson, x as flushCardUpdates, y as groupPayTwins } from "./api-Dz2cw7WD.js";
|
|
3
|
+
import { L as sinceSeq, o as dhtOnly, s as findChat, u as findOwnNamedChat } from "./apiKit-DAFsWtyk.js";
|
|
4
4
|
import { o as shownValue, r as asCliError, t as CliError } from "./errors-JVJsO8Iu.js";
|
|
5
|
-
import { C as
|
|
6
|
-
import { _ as frameBytes, b as monotonic, d as proof, f as removeDaemonSecret, g as bytesToMs, h as PlaybackQueue, l as greeting, m as DEFAULT_RATE, u as newDaemonSecret, v as frameSamples, y as isCallRate } from "./client-
|
|
7
|
-
import { Ci as DAEMON_WATCH_PEER_IDLE_MS, Gi as callSignalHeardAt, Hi as answersOffer, Ji as parseCallSignal, Qt as checkPushEndpoint, St as STATUS_IDLE_AFTER_MS, Ui as buildSdpFromSignal, Vi as RTC_CONFIG, Wi as callRtcConfig, Yi as signalHasVideo, _n as ACTIVE_DHT_POLL_MS, qi as extractParamsFromSdp, zi as CALL_SIGNAL_MAX_AGE_MS } from "./groupMeta
|
|
8
|
-
import {
|
|
5
|
+
import { C as dropRuntimeFolder, D as privateFolder, O as runtimePath, T as ownProfile, n as RESTORED_MARK, r as acquireLock, w as ownFolder, x as startingPath } from "./profiles-BAJf0c9E.js";
|
|
6
|
+
import { _ as frameBytes, b as monotonic, d as proof, f as removeDaemonSecret, g as bytesToMs, h as PlaybackQueue, l as greeting, m as DEFAULT_RATE, u as newDaemonSecret, v as frameSamples, y as isCallRate } from "./client-BtPhfWjK.js";
|
|
7
|
+
import { Ci as DAEMON_WATCH_PEER_IDLE_MS, Gi as callSignalHeardAt, Hi as answersOffer, Ji as parseCallSignal, Qt as checkPushEndpoint, St as STATUS_IDLE_AFTER_MS, Ui as buildSdpFromSignal, Vi as RTC_CONFIG, Wi as callRtcConfig, Yi as signalHasVideo, _n as ACTIVE_DHT_POLL_MS, qi as extractParamsFromSdp, zi as CALL_SIGNAL_MAX_AGE_MS } from "./groupMeta-Cz95F6sX.js";
|
|
8
|
+
import { g as parsePayLink, r as irohRelayProblem } from "./irohWeb-BLDcHwYz.js";
|
|
9
9
|
import { i as fromBase64Url } from "./bytes-C1DNGY18.js";
|
|
10
|
-
import { u as setLinkTraceSink } from "./relay-
|
|
10
|
+
import { u as setLinkTraceSink } from "./relay-gJTOYQJZ.js";
|
|
11
11
|
import { b as setPublicKeyFastPath } from "./pkarr-BQo4PcCg.js";
|
|
12
|
-
import { p as nativePublicKey } from "./apps-
|
|
13
|
-
import { n as fedimintSdkOn } from "./fedimintSdk-
|
|
12
|
+
import { p as nativePublicKey } from "./apps-B88rYWRm.js";
|
|
13
|
+
import { n as fedimintSdkOn } from "./fedimintSdk-eLXBrj9i.js";
|
|
14
14
|
import { s as isPublicAddress } from "./domainProofs-b3Y1Gj9g.js";
|
|
15
15
|
import { createRequire } from "node:module";
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
16
17
|
import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, truncateSync, writeFileSync, writeSync } from "node:fs";
|
|
17
18
|
import { open, readFile } from "node:fs/promises";
|
|
18
19
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
@@ -22,7 +23,6 @@ import { Readable } from "node:stream";
|
|
|
22
23
|
import { connect, createServer, isIP } from "node:net";
|
|
23
24
|
import { createInterface } from "node:readline";
|
|
24
25
|
import { createSocket } from "node:dgram";
|
|
25
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
26
26
|
import { Worker } from "node:worker_threads";
|
|
27
27
|
import { request } from "node:https";
|
|
28
28
|
import { lookup } from "node:dns";
|
|
@@ -153,6 +153,72 @@ function feedQueue(queue) {
|
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
|
+
* The most pieces a frame is written in (`kernelShare`): 1.25 ms of audio each. Linux counts its socket buffer per
|
|
157
|
+
* write (~1 KiB each however small, ~200 KiB in all), so it holds 3.6 s of 20 ms frames at 8 or 16 kHz and 1 s at
|
|
158
|
+
* 48 kHz for a program that stopped reading, and ~0.4 s in 16 pieces. macOS counts bytes (8 KiB): one write a frame.
|
|
159
|
+
*/
|
|
160
|
+
var MAX_PIECES = 16;
|
|
161
|
+
var kernelShares = /* @__PURE__ */ new Map();
|
|
162
|
+
/**
|
|
163
|
+
* How many pieces each frame of `rate` is written in, and how much of it the kernel then holds for a program that
|
|
164
|
+
* reads none. Each count, 1, 2, 4, ... `MAX_PIECES`, is measured on the call's own socket before anyone else may open
|
|
165
|
+
* it (`AudioSocket.open`); the first that leaves the kernel half of `MAX_UNREAD_MS` or less is taken, else the one
|
|
166
|
+
* that held least (a count is taken only when it holds 5% less than fewer pieces did: macOS stays at one). Once per
|
|
167
|
+
* rate, since it depends on the system, not on the call. Windows, or no measure (an error): one piece, nothing held,
|
|
168
|
+
* the bound what waits in the daemon, as before; the next call measures again.
|
|
169
|
+
*/
|
|
170
|
+
async function kernelShare(path, rate, onConnection) {
|
|
171
|
+
const known = kernelShares.get(rate);
|
|
172
|
+
if (known) return known;
|
|
173
|
+
const none = {
|
|
174
|
+
pieces: 1,
|
|
175
|
+
heldMs: 0
|
|
176
|
+
};
|
|
177
|
+
if (process.platform === "win32") return none;
|
|
178
|
+
let best = null;
|
|
179
|
+
for (let pieces = 1; pieces <= MAX_PIECES && !(best && best.heldMs <= 500); pieces *= 2) {
|
|
180
|
+
const held = await kernelHolds(path, frameBytes(rate) / pieces, rate * 2 * 3e4 / 1e3, onConnection);
|
|
181
|
+
if (held === null) return none;
|
|
182
|
+
const heldMs = bytesToMs(rate, held);
|
|
183
|
+
if (!best || heldMs < best.heldMs * .95) best = {
|
|
184
|
+
pieces,
|
|
185
|
+
heldMs
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
kernelShares.set(rate, best);
|
|
189
|
+
return best;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Bytes the kernel takes in writes of `piece` bytes, one by one as `AudioSocket` writes them, until it holds one back
|
|
193
|
+
* (or `most`): all in one turn of the event loop, so the reader, this process's own connection, has read none. Null
|
|
194
|
+
* when no connection came.
|
|
195
|
+
*/
|
|
196
|
+
function kernelHolds(path, piece, most, onConnection) {
|
|
197
|
+
return new Promise((resolve) => {
|
|
198
|
+
const reader = connect(path);
|
|
199
|
+
reader.on("error", () => {});
|
|
200
|
+
const done = (held) => {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
onConnection(null);
|
|
203
|
+
reader.destroy();
|
|
204
|
+
resolve(held);
|
|
205
|
+
};
|
|
206
|
+
const timer = setTimeout(() => done(null), 2e3);
|
|
207
|
+
onConnection((writer) => {
|
|
208
|
+
writer.on("error", () => {});
|
|
209
|
+
const bytes = Buffer.alloc(piece);
|
|
210
|
+
let held = 0;
|
|
211
|
+
while (held < most) {
|
|
212
|
+
writer.write(bytes);
|
|
213
|
+
if (writer.writableLength > 0) break;
|
|
214
|
+
held += piece;
|
|
215
|
+
}
|
|
216
|
+
writer.destroy();
|
|
217
|
+
done(held);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
156
222
|
* Serves one call's audio to one program at a time: what the program writes is handed to `onAudio` as it comes (raw
|
|
157
223
|
* PCM, any amount); `write` gives it the caller's audio. A second connection replaces the first. `close` ends the
|
|
158
224
|
* program's connection (it reads EOF) and removes the socket.
|
|
@@ -170,19 +236,28 @@ var AudioSocket = class AudioSocket {
|
|
|
170
236
|
rate;
|
|
171
237
|
requireToken;
|
|
172
238
|
proveMs;
|
|
239
|
+
kernel;
|
|
173
240
|
client = null;
|
|
174
241
|
/** Connections that have not sent the token yet. */
|
|
175
242
|
unproven = /* @__PURE__ */ new Set();
|
|
176
243
|
closed = false;
|
|
244
|
+
/**
|
|
245
|
+
* Audio for the program that waits in the daemon while the kernel holds a write back (it is full: the program reads
|
|
246
|
+
* slower than the call speaks), in the pieces `kernelShare` measured. Handed to the kernel one write at a time:
|
|
247
|
+
* Node's own buffer would join them into one larger write, which the kernel takes more of.
|
|
248
|
+
*/
|
|
249
|
+
backlog = [];
|
|
250
|
+
backlogBytes = 0;
|
|
177
251
|
/** Frames the program did not read in time, since the start. */
|
|
178
252
|
dropped = 0;
|
|
179
253
|
token = randomBytes(32).toString("hex");
|
|
180
|
-
constructor(path, server, rate, requireToken, proveMs) {
|
|
254
|
+
constructor(path, server, rate, requireToken, proveMs, kernel) {
|
|
181
255
|
this.path = path;
|
|
182
256
|
this.server = server;
|
|
183
257
|
this.rate = rate;
|
|
184
258
|
this.requireToken = requireToken;
|
|
185
259
|
this.proveMs = proveMs;
|
|
260
|
+
this.kernel = kernel;
|
|
186
261
|
}
|
|
187
262
|
static async open(path, rate, handlers, options = {}) {
|
|
188
263
|
const shared = !!options.shared && process.platform !== "win32";
|
|
@@ -192,7 +267,8 @@ var AudioSocket = class AudioSocket {
|
|
|
192
267
|
if (existsSync(path)) rmSync(path, { force: true });
|
|
193
268
|
}
|
|
194
269
|
let self = null;
|
|
195
|
-
|
|
270
|
+
let probe = null;
|
|
271
|
+
const server = createServer((socket) => self ? self.accept(socket, handlers) : probe ? probe(socket) : socket.destroy());
|
|
196
272
|
await new Promise((resolve, reject) => {
|
|
197
273
|
server.once("error", reject);
|
|
198
274
|
server.listen(path, () => {
|
|
@@ -200,8 +276,11 @@ var AudioSocket = class AudioSocket {
|
|
|
200
276
|
resolve();
|
|
201
277
|
});
|
|
202
278
|
});
|
|
279
|
+
const kernel = await kernelShare(path, rate, (take) => {
|
|
280
|
+
probe = take;
|
|
281
|
+
});
|
|
203
282
|
if (process.platform !== "win32") chmodSync(path, shared ? 432 : 384);
|
|
204
|
-
self = new AudioSocket(path, server, rate, options.requireToken ?? (shared || process.platform === "win32"), options.proveMs ?? 5e3);
|
|
283
|
+
self = new AudioSocket(path, server, rate, options.requireToken ?? (shared || process.platform === "win32"), options.proveMs ?? 5e3, kernel);
|
|
205
284
|
return self;
|
|
206
285
|
}
|
|
207
286
|
get connected() {
|
|
@@ -220,6 +299,8 @@ var AudioSocket = class AudioSocket {
|
|
|
220
299
|
this.unproven.delete(socket);
|
|
221
300
|
const before = this.client;
|
|
222
301
|
this.client = socket;
|
|
302
|
+
this.backlog = [];
|
|
303
|
+
this.backlogBytes = 0;
|
|
223
304
|
if (before) {
|
|
224
305
|
before.end();
|
|
225
306
|
setTimeout(() => before.destroy(), 2e3).unref();
|
|
@@ -264,25 +345,47 @@ var AudioSocket = class AudioSocket {
|
|
|
264
345
|
this.unproven.delete(socket);
|
|
265
346
|
if (this.client !== socket) return;
|
|
266
347
|
this.client = null;
|
|
348
|
+
this.backlog = [];
|
|
349
|
+
this.backlogBytes = 0;
|
|
267
350
|
handlers.onClient?.(false);
|
|
268
351
|
});
|
|
269
352
|
}
|
|
270
|
-
/**
|
|
353
|
+
/**
|
|
354
|
+
* One frame of the caller's audio for the program; dropped when nobody listens or the program stopped reading. A
|
|
355
|
+
* program that keeps up gets it at once: the kernel takes it, nothing waits. Once the kernel holds one back, it is
|
|
356
|
+
* full (`kernel.heldMs` the program has not read), and what waits in the daemon may make up the rest of
|
|
357
|
+
* `MAX_UNREAD_MS`.
|
|
358
|
+
*/
|
|
271
359
|
write(frame) {
|
|
272
360
|
const client = this.client;
|
|
273
361
|
if (!client || client.destroyed) return;
|
|
274
|
-
if (bytesToMs(this.rate, client.writableLength) > 1e3) {
|
|
362
|
+
if ((client.writableLength > 0 || this.backlog.length) && this.kernel.heldMs + bytesToMs(this.rate, client.writableLength + this.backlogBytes + frame.length) > 1e3) {
|
|
275
363
|
this.dropped++;
|
|
276
364
|
return;
|
|
277
365
|
}
|
|
278
|
-
|
|
366
|
+
const piece = Math.ceil(frame.length / this.kernel.pieces / 2) * 2;
|
|
367
|
+
for (let at = 0; at < frame.length; at += piece) this.backlog.push(frame.subarray(at, at + piece));
|
|
368
|
+
this.backlogBytes += frame.length;
|
|
369
|
+
this.pump();
|
|
279
370
|
}
|
|
371
|
+
/** Hands the kernel what waits, one write a piece, for as long as it takes each whole (`backlog`). */
|
|
372
|
+
pump = () => {
|
|
373
|
+
const client = this.client;
|
|
374
|
+
while (client && !client.destroyed && client.writableLength === 0 && this.backlog.length) {
|
|
375
|
+
const piece = this.backlog.shift();
|
|
376
|
+
this.backlogBytes -= piece.length;
|
|
377
|
+
client.write(piece, this.pump);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
280
380
|
/** Ends the program's connection (EOF once what was written is read) and removes the socket. */
|
|
281
381
|
close() {
|
|
282
382
|
if (this.closed) return Promise.resolve();
|
|
283
383
|
this.closed = true;
|
|
284
384
|
const client = this.client;
|
|
285
385
|
this.client = null;
|
|
386
|
+
if (client && !client.destroyed) for (const piece of this.backlog) client.write(piece);
|
|
387
|
+
this.backlog = [];
|
|
388
|
+
this.backlogBytes = 0;
|
|
286
389
|
client?.end();
|
|
287
390
|
if (client) setTimeout(() => client.destroy(), 2e3).unref();
|
|
288
391
|
for (const socket of this.unproven) socket.destroy();
|
|
@@ -290,6 +393,7 @@ var AudioSocket = class AudioSocket {
|
|
|
290
393
|
return new Promise((resolve) => {
|
|
291
394
|
this.server.close(() => resolve());
|
|
292
395
|
if (process.platform !== "win32") rmSync(this.path, { force: true });
|
|
396
|
+
dropRuntimeFolder(this.path);
|
|
293
397
|
});
|
|
294
398
|
}
|
|
295
399
|
};
|
|
@@ -1289,7 +1393,7 @@ var CallManager = class {
|
|
|
1289
1393
|
this.held.delete(chat);
|
|
1290
1394
|
this.bursts.delete(chat);
|
|
1291
1395
|
const link = this.link(chat);
|
|
1292
|
-
const call = this.add(chat, "in",
|
|
1396
|
+
const call = this.add(chat, "in", DEFAULT_RATE);
|
|
1293
1397
|
call.offer = offer;
|
|
1294
1398
|
call.video = signalHasVideo(offer);
|
|
1295
1399
|
this.arm(call, Math.max(1e3, callSignalHeardAt(offer) + CALL_SIGNAL_MAX_AGE_MS - this.now), "missed", false);
|
|
@@ -1301,7 +1405,7 @@ var CallManager = class {
|
|
|
1301
1405
|
auto: this.autoFor(chat)
|
|
1302
1406
|
});
|
|
1303
1407
|
this.prepare(call);
|
|
1304
|
-
if (this.host.answers !== false && this.autoFor(chat)) this.answer(call.id, {}).catch((error) => process.stderr.write(`ghostly: auto-answer failed: ${error instanceof Error ? error.message : String(error)}\n`));
|
|
1408
|
+
if (this.host.answers !== false && this.autoFor(chat)) this.answer(call.id, { rate: this.auto.rate }).catch((error) => process.stderr.write(`ghostly: auto-answer failed: ${error instanceof Error ? error.message : String(error)}\n`));
|
|
1305
1409
|
}
|
|
1306
1410
|
accepted(call, answer) {
|
|
1307
1411
|
call.offering = false;
|
|
@@ -1464,7 +1568,7 @@ var CallManager = class {
|
|
|
1464
1568
|
throw new CliError("busy", "The contact is calling: their call rings here");
|
|
1465
1569
|
}
|
|
1466
1570
|
this.paced(link.id);
|
|
1467
|
-
const rate = rateOf(options.rate,
|
|
1571
|
+
const rate = rateOf(options.rate, DEFAULT_RATE);
|
|
1468
1572
|
const stack = await this.stack();
|
|
1469
1573
|
if (this.byChat(link.id)) throw new CliError("busy", "A call is already on in this chat");
|
|
1470
1574
|
const call = this.add(link.id, "out", rate);
|
|
@@ -1896,12 +2000,25 @@ var CallManager = class {
|
|
|
1896
2000
|
byChat(chat) {
|
|
1897
2001
|
for (const call of this.calls.values()) if (call.chat === chat) return call;
|
|
1898
2002
|
}
|
|
1899
|
-
/**
|
|
2003
|
+
/**
|
|
2004
|
+
* A call by its id, or by its chat; with no ref, the only call (or the only one `prefer` picks). A ref shaped as a
|
|
2005
|
+
* call's id (`CALL_ID`) that names no call on now and no chat says so as a call: it ended (hung up twice, or a
|
|
2006
|
+
* command racing the call's end) or never was one. It said `No chat "<id>"`, sending a script to the chat list. A
|
|
2007
|
+
* chat whose id or label has that shape is still found as a chat first. An ended call is not kept (`end`), so
|
|
2008
|
+
* whether it ended or never was is not known here.
|
|
2009
|
+
*/
|
|
1900
2010
|
find(ref, prefer) {
|
|
1901
2011
|
if (ref) {
|
|
1902
2012
|
const byId = this.calls.get(ref);
|
|
1903
2013
|
if (byId) return byId;
|
|
1904
|
-
|
|
2014
|
+
let chat;
|
|
2015
|
+
try {
|
|
2016
|
+
chat = this.chatOf(ref);
|
|
2017
|
+
} catch (error) {
|
|
2018
|
+
if (CALL_ID.test(ref) && error instanceof CliError && error.code === "not_found" && !error.details) throw new CliError("not_found", `No call ${ref}: it ended or never existed (ghostly call list)`);
|
|
2019
|
+
throw error;
|
|
2020
|
+
}
|
|
2021
|
+
const call = this.byChat(chat.id);
|
|
1905
2022
|
if (!call) throw new CliError("not_found", `No call in chat ${ref}`);
|
|
1906
2023
|
return call;
|
|
1907
2024
|
}
|
|
@@ -1931,6 +2048,15 @@ var CallManager = class {
|
|
|
1931
2048
|
if (this.host.answers === false) throw new CliError("unavailable", CALLS_NEED_DAEMON);
|
|
1932
2049
|
if (!link.profile) throw new CliError("unavailable", "Calls are in chats made since 0.4 (the chat session): this is a compatibility chat");
|
|
1933
2050
|
if (link.callsUnavailable === CALLS_NEED_LIVE) {
|
|
2051
|
+
try {
|
|
2052
|
+
dhtOnly(link);
|
|
2053
|
+
} catch (error) {
|
|
2054
|
+
if (!(error instanceof CliError)) throw error;
|
|
2055
|
+
throw new CliError("unavailable", `${CALLS_NEED_LIVE}. ${error.message}`, {
|
|
2056
|
+
chat: link.id,
|
|
2057
|
+
...error.details
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
1934
2060
|
const shown = /^[\w.:-]+$/.test(link.label ?? "") ? link.label : link.id;
|
|
1935
2061
|
throw new CliError("unavailable", `${CALLS_NEED_LIVE}, and your contact's app is not connected now: ghostly chat wait ${shown} --until live waits for it, then call again`, { chat: link.id });
|
|
1936
2062
|
}
|
|
@@ -1942,6 +2068,8 @@ var CallManager = class {
|
|
|
1942
2068
|
return this.auto.on && (this.auto.from.length === 0 || this.auto.from.includes(chat));
|
|
1943
2069
|
}
|
|
1944
2070
|
};
|
|
2071
|
+
/** A call's id as `add` makes it: 6 random bytes in lowercase hex. */
|
|
2072
|
+
var CALL_ID = /^[0-9a-f]{12}$/;
|
|
1945
2073
|
var CALLS_NEED_DAEMON = "Calls need the daemon (a call outlives this command): start it with `ghostly daemon --detach`";
|
|
1946
2074
|
/** The engine's `callsUnavailable` for a chat with no live session (ghostlink's, or node.ts's with no link running). */
|
|
1947
2075
|
var CALLS_NEED_LIVE = "Calls need a live connection";
|
|
@@ -4418,15 +4546,25 @@ var TreeFile = class {
|
|
|
4418
4546
|
abort(owner) {
|
|
4419
4547
|
for (const tree of this.live) tree.abort(owner);
|
|
4420
4548
|
}
|
|
4421
|
-
/** The
|
|
4422
|
-
|
|
4549
|
+
/** The name of the snapshot that the last fold's `apply` went with (`storage.ts`). */
|
|
4550
|
+
snapshot() {
|
|
4551
|
+
const row = this.db.prepare("SELECT value FROM meta WHERE name = 'snapshot'").get();
|
|
4552
|
+
return row ? String(row.value) : void 0;
|
|
4553
|
+
}
|
|
4554
|
+
/**
|
|
4555
|
+
* The layers of the journal's entries up to `upTo` into SQLite, in one transaction that says so (`applied`). `snapshot`:
|
|
4556
|
+
* the fold's, written whole before this and put in place after; recorded with them, so a process killed between the
|
|
4557
|
+
* two comes back to it, not to the snapshot before it with these transactions half there.
|
|
4558
|
+
*/
|
|
4559
|
+
apply(upTo, snapshot) {
|
|
4423
4560
|
const due = [...this.live].filter((tree) => tree.due(upTo));
|
|
4424
|
-
if (!due.length) return;
|
|
4561
|
+
if (!due.length && snapshot === void 0) return;
|
|
4425
4562
|
this.db.exec("BEGIN");
|
|
4426
4563
|
try {
|
|
4427
4564
|
let top = 0;
|
|
4428
4565
|
for (const tree of due) top = Math.max(top, tree.write(upTo));
|
|
4429
4566
|
this.db.prepare("INSERT OR REPLACE INTO meta (name, value) VALUES ('applied', max(?, coalesce((SELECT value FROM meta WHERE name = 'applied'), 0)))").run(top);
|
|
4567
|
+
if (snapshot !== void 0) this.db.prepare("INSERT OR REPLACE INTO meta (name, value) VALUES ('snapshot', ?)").run(snapshot);
|
|
4430
4568
|
this.db.exec("COMMIT");
|
|
4431
4569
|
} catch (error) {
|
|
4432
4570
|
rollback(this.db);
|
|
@@ -4948,11 +5086,23 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
4948
5086
|
let holdsRatchet = false;
|
|
4949
5087
|
/** The journal holds a delete of a chat or a message (or a settings write), and what came before it with it. */
|
|
4950
5088
|
let holdsDelete = false;
|
|
5089
|
+
/** The exports under way (a backup's), each holding rows.db as it was when it began (`openTreeReader`). */
|
|
5090
|
+
const exporting = /* @__PURE__ */ new Set();
|
|
5091
|
+
/** The scrub's fold asked for that has not begun yet: a scrub asked meanwhile is that one (`compact`). */
|
|
5092
|
+
let nextScrub = null;
|
|
4951
5093
|
const pending = /* @__PURE__ */ new WeakMap();
|
|
4952
5094
|
const snapshotPath = join(dir, SNAPSHOT);
|
|
4953
5095
|
const journalPath = join(dir, JOURNAL);
|
|
5096
|
+
const temporaryPath = snapshotPath + ".tmp";
|
|
5097
|
+
/** The last entry the snapshot on disk holds: one that waited behind its fold is not written to the journal after it. */
|
|
5098
|
+
let foldedUpTo = 0;
|
|
4954
5099
|
const ratchetDue = () => holdsRatchet && Date.now() - (statSync(snapshotPath, { throwIfNoEntry: false })?.mtimeMs ?? 0) >= RATCHET_FOLD_MS;
|
|
4955
5100
|
const deleteDue = () => holdsDelete && Date.now() - (statSync(snapshotPath, { throwIfNoEntry: false })?.mtimeMs ?? 0) >= DELETE_FOLD_MS;
|
|
5101
|
+
const foldedTo = trees?.snapshot();
|
|
5102
|
+
if (foldedTo !== void 0 && existsSync(temporaryPath) && journalNamed(temporaryPath) === foldedTo) {
|
|
5103
|
+
renameSync(temporaryPath, snapshotPath);
|
|
5104
|
+
rmSync(journalPath, { force: true });
|
|
5105
|
+
}
|
|
4956
5106
|
const snapshotFound = existsSync(snapshotPath), journalFound = existsSync(journalPath);
|
|
4957
5107
|
const saved = snapshotFound ? deserialize(readFileSync(snapshotPath)) : null;
|
|
4958
5108
|
const rows = sqlite && saved?.format === 2 && rowsFound ? openRowFile(sqlite, rowsPath) : null;
|
|
@@ -5128,7 +5278,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5128
5278
|
* A committed transaction's entry, numbered `entry` (its first op says so, where there are trees), from the
|
|
5129
5279
|
* transaction whose rollback log is `owner`. Written at once, it may fail (a full disk): the reason is given back,
|
|
5130
5280
|
* and the transaction is to be refused, not completed. "unsynced": written, and its `complete` waits for a sync.
|
|
5131
|
-
* "queued": written behind what the queue holds (a fold, a Blob's entry), and `complete` called once it
|
|
5281
|
+
* "queued": written behind what the queue holds (a fold, a Blob's entry), and `complete` called once a sync covers it: what
|
|
5132
5282
|
* completed before was on no disk while the fold waited for the sync in flight, and a process killed then lost a
|
|
5133
5283
|
* text the engine had told the contact it held.
|
|
5134
5284
|
*/
|
|
@@ -5155,13 +5305,27 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5155
5305
|
}
|
|
5156
5306
|
trees?.complete(owner, entry);
|
|
5157
5307
|
held++;
|
|
5308
|
+
const done = () => {
|
|
5309
|
+
held--;
|
|
5310
|
+
complete();
|
|
5311
|
+
};
|
|
5312
|
+
let sharing = false;
|
|
5158
5313
|
enqueue(async () => {
|
|
5159
5314
|
try {
|
|
5315
|
+
if (entry <= foldedUpTo) return;
|
|
5160
5316
|
if (writeEntry(serialize(await Promise.all(ops.map(async (op) => op.kind === "put" ? {
|
|
5161
5317
|
...op,
|
|
5162
5318
|
value: await blobsToDisk(op.value)
|
|
5163
|
-
} : op))), lazy ? "lazy" : "
|
|
5319
|
+
} : op))), lazy ? "lazy" : "shared")) {
|
|
5164
5320
|
holdsDelete ||= deleting;
|
|
5321
|
+
if (!lazy) {
|
|
5322
|
+
sharing = true;
|
|
5323
|
+
shareSync(() => {
|
|
5324
|
+
written(entry);
|
|
5325
|
+
done();
|
|
5326
|
+
});
|
|
5327
|
+
return;
|
|
5328
|
+
}
|
|
5165
5329
|
written(entry);
|
|
5166
5330
|
}
|
|
5167
5331
|
} catch (error) {
|
|
@@ -5169,8 +5333,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5169
5333
|
await writeSnapshot().catch(failed);
|
|
5170
5334
|
}
|
|
5171
5335
|
}).then(() => {
|
|
5172
|
-
|
|
5173
|
-
complete();
|
|
5336
|
+
if (!sharing) done();
|
|
5174
5337
|
});
|
|
5175
5338
|
return "queued";
|
|
5176
5339
|
}
|
|
@@ -5384,6 +5547,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5384
5547
|
* holds, the transactions whose layers go to the trees with it.
|
|
5385
5548
|
*/
|
|
5386
5549
|
async function capture(journalName) {
|
|
5550
|
+
await unwritten();
|
|
5387
5551
|
const snapshot = {
|
|
5388
5552
|
format: 1,
|
|
5389
5553
|
journal: journalName,
|
|
@@ -5433,6 +5597,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5433
5597
|
async function exportTo(file) {
|
|
5434
5598
|
const databases = [];
|
|
5435
5599
|
let reader = null;
|
|
5600
|
+
await unwritten();
|
|
5436
5601
|
try {
|
|
5437
5602
|
for (const db of raw._databases.values()) {
|
|
5438
5603
|
if (db.name === PROBE) continue;
|
|
@@ -5480,7 +5645,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5480
5645
|
out.begin("A", count);
|
|
5481
5646
|
let written = 0;
|
|
5482
5647
|
for (const record of Array.isArray(records) ? records : records.getAllRecords()) {
|
|
5483
|
-
let value = Array.isArray(records) ? await blobsToDisk(record.value) : record.value;
|
|
5648
|
+
let value = Array.isArray(records) || hasBlob(record.value) ? await blobsToDisk(record.value) : record.value;
|
|
5484
5649
|
if (meta.name === "links" && value && typeof value === "object" && "ratchetState" in value) {
|
|
5485
5650
|
const { ratchetState: _ratchet, ...link } = value;
|
|
5486
5651
|
value = link;
|
|
@@ -5512,20 +5677,21 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5512
5677
|
const { snapshot, upTo } = await capture(name);
|
|
5513
5678
|
const live = trees ? liveTrees() : null;
|
|
5514
5679
|
unsaved = false;
|
|
5515
|
-
const
|
|
5516
|
-
const file = await open(temporary, "w", 384);
|
|
5680
|
+
const file = await open(temporaryPath, "w", 384);
|
|
5517
5681
|
try {
|
|
5518
5682
|
await writeSnapshotTo(file, snapshot);
|
|
5519
5683
|
await file.sync();
|
|
5520
5684
|
} finally {
|
|
5521
5685
|
await file.close();
|
|
5522
5686
|
}
|
|
5687
|
+
while (scrub && trees && exporting.size) await Promise.allSettled(exporting);
|
|
5523
5688
|
if (trees) {
|
|
5524
|
-
trees.apply(upTo);
|
|
5689
|
+
trees.apply(upTo, name);
|
|
5525
5690
|
if (scrub) trees.scrub();
|
|
5526
5691
|
trees.sync();
|
|
5527
5692
|
}
|
|
5528
|
-
renameSync(
|
|
5693
|
+
renameSync(temporaryPath, snapshotPath);
|
|
5694
|
+
foldedUpTo = upTo;
|
|
5529
5695
|
try {
|
|
5530
5696
|
if (live) trees.sweep(/* @__PURE__ */ new Set([...live, ...liveTrees()]));
|
|
5531
5697
|
} catch (error) {
|
|
@@ -5573,6 +5739,26 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5573
5739
|
quiet = busy() ? 0 : quiet + 1;
|
|
5574
5740
|
}
|
|
5575
5741
|
}
|
|
5742
|
+
/**
|
|
5743
|
+
* Resolves in a turn where no running transaction has written to a store held in memory (or after `CLOSE_WAIT_MS`):
|
|
5744
|
+
* fake-indexeddb puts its writes in the records at once and takes them back if it aborts. A fold read them meanwhile,
|
|
5745
|
+
* and its snapshot kept what the transaction never committed (a refused write, after a restart), or a part of what it
|
|
5746
|
+
* did (its other part in the journal entry a process killed then never wrote). One that commits meanwhile waits behind
|
|
5747
|
+
* the fold in the queue (`append`): the snapshot holds it, whole.
|
|
5748
|
+
*/
|
|
5749
|
+
async function unwritten() {
|
|
5750
|
+
const until = Date.now() + CLOSE_WAIT_MS;
|
|
5751
|
+
while (Date.now() < until && writesHeld()) await new Promise((resolve) => setImmediate(resolve));
|
|
5752
|
+
}
|
|
5753
|
+
function writesHeld() {
|
|
5754
|
+
return [...raw._databases.values()].some((db) => db.transactions.some((transaction) => {
|
|
5755
|
+
const { _state, _rollbackLog } = transaction;
|
|
5756
|
+
return _state !== "finished" && !!pending.get(_rollbackLog)?.some((op) => {
|
|
5757
|
+
const store = db.rawObjectStores.get(op.store);
|
|
5758
|
+
return !store || !disk(store);
|
|
5759
|
+
});
|
|
5760
|
+
}));
|
|
5761
|
+
}
|
|
5576
5762
|
/** Whether a transaction is running or waiting to, or for the sync or the queued write that tells the engine it completed. */
|
|
5577
5763
|
function busy() {
|
|
5578
5764
|
return syncing !== null || held > 0 || [...raw._databases.values()].some((db) => db.transactions.some((transaction) => transaction._state !== "finished"));
|
|
@@ -5586,12 +5772,22 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5586
5772
|
flush: () => queue,
|
|
5587
5773
|
async compact(options) {
|
|
5588
5774
|
await settled();
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5775
|
+
const scrub = options?.scrub === true;
|
|
5776
|
+
if (scrub && nextScrub) return nextScrub;
|
|
5777
|
+
const fold = (async () => {
|
|
5778
|
+
while (scrub && exporting.size) await Promise.allSettled(exporting);
|
|
5779
|
+
let thrown = null;
|
|
5780
|
+
await enqueue(() => {
|
|
5781
|
+
if (scrub) nextScrub = null;
|
|
5782
|
+
return writeSnapshot(scrub).catch((error) => {
|
|
5783
|
+
thrown = { error };
|
|
5784
|
+
throw error;
|
|
5785
|
+
});
|
|
5786
|
+
});
|
|
5787
|
+
if (thrown) throw thrown.error;
|
|
5788
|
+
})();
|
|
5789
|
+
if (scrub) nextScrub = fold;
|
|
5790
|
+
return fold;
|
|
5595
5791
|
},
|
|
5596
5792
|
async close() {
|
|
5597
5793
|
if (!writing) return;
|
|
@@ -5608,12 +5804,20 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
5608
5804
|
journalBytes,
|
|
5609
5805
|
async exportSnapshot(path) {
|
|
5610
5806
|
await settled();
|
|
5611
|
-
const
|
|
5807
|
+
const run = (async () => {
|
|
5808
|
+
const file = await open(path, "w", 384);
|
|
5809
|
+
try {
|
|
5810
|
+
await exportTo(file);
|
|
5811
|
+
await file.sync();
|
|
5812
|
+
} finally {
|
|
5813
|
+
await file.close();
|
|
5814
|
+
}
|
|
5815
|
+
})();
|
|
5816
|
+
exporting.add(run);
|
|
5612
5817
|
try {
|
|
5613
|
-
await
|
|
5614
|
-
await file.sync();
|
|
5818
|
+
await run;
|
|
5615
5819
|
} finally {
|
|
5616
|
-
|
|
5820
|
+
exporting.delete(run);
|
|
5617
5821
|
}
|
|
5618
5822
|
}
|
|
5619
5823
|
};
|
|
@@ -5779,6 +5983,14 @@ function follows(journal) {
|
|
|
5779
5983
|
return;
|
|
5780
5984
|
}
|
|
5781
5985
|
}
|
|
5986
|
+
/** The name a snapshot file gives the journal after it; undefined for one cut short (a fold killed while it wrote it). */
|
|
5987
|
+
function journalNamed(path) {
|
|
5988
|
+
try {
|
|
5989
|
+
return deserialize(readFileSync(path)).journal;
|
|
5990
|
+
} catch {
|
|
5991
|
+
return;
|
|
5992
|
+
}
|
|
5993
|
+
}
|
|
5782
5994
|
/** fake-indexeddb's raw classes, from a throwaway database (they are not exported). */
|
|
5783
5995
|
async function probeClasses(factory) {
|
|
5784
5996
|
const db = await new Promise((resolve, reject) => {
|
|
@@ -6346,6 +6558,7 @@ function keyFromDisk(key) {
|
|
|
6346
6558
|
if (range.upper === void 0) return IDBKeyRange$1.lowerBound(range.lower, range.lowerOpen);
|
|
6347
6559
|
return IDBKeyRange$1.bound(range.lower, range.upper, range.lowerOpen, range.upperOpen);
|
|
6348
6560
|
}
|
|
6561
|
+
/** A Blob, or an object of the app's that has the marker's key itself (`blobsToDisk`): what goes to disk changed. */
|
|
6349
6562
|
function hasBlob(value, depth = 0) {
|
|
6350
6563
|
if (value instanceof Blob) return true;
|
|
6351
6564
|
if (!value || typeof value !== "object" || depth > 32 || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return false;
|
|
@@ -6353,10 +6566,14 @@ function hasBlob(value, depth = 0) {
|
|
|
6353
6566
|
for (const [k, v] of value) if (hasBlob(k, depth + 1) || hasBlob(v, depth + 1)) return true;
|
|
6354
6567
|
return false;
|
|
6355
6568
|
}
|
|
6569
|
+
if (Object.hasOwn(value, BLOB)) return true;
|
|
6356
6570
|
for (const item of Object.values(value)) if (hasBlob(item, depth + 1)) return true;
|
|
6357
6571
|
return false;
|
|
6358
6572
|
}
|
|
6359
|
-
/**
|
|
6573
|
+
/**
|
|
6574
|
+
* v8 cannot serialize a Blob: it goes to disk as its bytes and type, and comes back a Blob. An object of the app's
|
|
6575
|
+
* that has the marker's key itself (a contact's data can) goes in a marker too, as it is, so it never comes back a Blob.
|
|
6576
|
+
*/
|
|
6360
6577
|
async function blobsToDisk(value, depth = 0) {
|
|
6361
6578
|
if (!hasBlob(value, depth)) return value;
|
|
6362
6579
|
if (value instanceof Blob) return { [BLOB]: {
|
|
@@ -6367,17 +6584,20 @@ async function blobsToDisk(value, depth = 0) {
|
|
|
6367
6584
|
if (value instanceof Map) return new Map(await Promise.all([...value].map(async ([k, v]) => [k, await blobsToDisk(v, depth + 1)])));
|
|
6368
6585
|
const out = {};
|
|
6369
6586
|
for (const [k, v] of Object.entries(value)) out[k] = await blobsToDisk(v, depth + 1);
|
|
6370
|
-
return out;
|
|
6587
|
+
return Object.hasOwn(out, BLOB) ? { [BLOB]: { kept: out } } : out;
|
|
6371
6588
|
}
|
|
6589
|
+
/** Only a marker this store wrote is one: its key alone, holding bytes (which no JSON makes) or an object it kept. */
|
|
6372
6590
|
function blobsFromDisk(value, depth = 0) {
|
|
6373
6591
|
if (!value || typeof value !== "object" || depth > 32 || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return value;
|
|
6374
|
-
const blob = value[BLOB];
|
|
6375
|
-
if (blob) return new Blob([blob.bytes], { type: blob.type });
|
|
6376
6592
|
if (Array.isArray(value)) return value.map((item) => blobsFromDisk(item, depth + 1));
|
|
6377
6593
|
if (value instanceof Map) return new Map([...value].map(([k, v]) => [k, blobsFromDisk(v, depth + 1)]));
|
|
6378
6594
|
if (Object.getPrototypeOf(value) !== Object.prototype) return value;
|
|
6595
|
+
const marker = Object.keys(value).length === 1 ? value[BLOB] : void 0;
|
|
6596
|
+
const { type, bytes, kept } = marker && typeof marker === "object" ? marker : {};
|
|
6597
|
+
if (bytes instanceof Uint8Array && typeof type === "string") return new Blob([bytes], { type });
|
|
6598
|
+
const fields = kept && typeof kept === "object" && Object.getPrototypeOf(kept) === Object.prototype ? kept : value;
|
|
6379
6599
|
const out = {};
|
|
6380
|
-
for (const [k, v] of Object.entries(
|
|
6600
|
+
for (const [k, v] of Object.entries(fields)) out[k] = blobsFromDisk(v, depth + 1);
|
|
6381
6601
|
return out;
|
|
6382
6602
|
}
|
|
6383
6603
|
/**
|
|
@@ -6716,8 +6936,8 @@ async function startRuntime(paths, options = {}) {
|
|
|
6716
6936
|
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-CCKbwqG_.js"), import("./fileBytes-tj6-VZcB.js")]);
|
|
6717
6937
|
registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
|
|
6718
6938
|
if (await (await import("./blobFiles-DDs34n0r.js")).moveBlobFiles()) await store.compact();
|
|
6719
|
-
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-
|
|
6720
|
-
const mainline = dht.off ? null : new (await (import("./mainline-
|
|
6939
|
+
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-e4oKeNez.js"), import("./endpoint-Cvu-taMs.js")]);
|
|
6940
|
+
const mainline = dht.off ? null : new (await (import("./mainline-CDUXtV-I.js"))).Mainline({
|
|
6721
6941
|
bootstrap: dht.bootstrap,
|
|
6722
6942
|
host: dht.host
|
|
6723
6943
|
});
|
|
@@ -6725,7 +6945,7 @@ async function startRuntime(paths, options = {}) {
|
|
|
6725
6945
|
...pinned ? { relays: pinned } : {},
|
|
6726
6946
|
...relayBudgetForTests()
|
|
6727
6947
|
};
|
|
6728
|
-
const transport = mainline || pinned ? new (await (import("./mainline-
|
|
6948
|
+
const transport = mainline || pinned ? new (await (import("./mainline-CDUXtV-I.js"))).RelaysAndDht(mainline, relayOptions, !!pinned) : null;
|
|
6729
6949
|
const apps = servedApps(paths.dir).length > 0;
|
|
6730
6950
|
const server = new EngineServer({
|
|
6731
6951
|
...transport ? { transport } : {},
|
|
@@ -6978,7 +7198,10 @@ async function serve(host) {
|
|
|
6978
7198
|
return {
|
|
6979
7199
|
server,
|
|
6980
7200
|
close: () => closing ??= new Promise((resolve) => {
|
|
6981
|
-
server.close(() =>
|
|
7201
|
+
server.close(() => {
|
|
7202
|
+
dropRuntimeFolder(path);
|
|
7203
|
+
resolve();
|
|
7204
|
+
});
|
|
6982
7205
|
removeDaemonSecret(ctx.runtime.paths.dir);
|
|
6983
7206
|
stopping.abort();
|
|
6984
7207
|
within(Promise.all(answering), STOP_ANSWERS_MS).then(() => {
|
|
@@ -7187,4 +7410,4 @@ function connection(ctx, socket, secret, answering) {
|
|
|
7187
7410
|
}
|
|
7188
7411
|
export { BASELINE_NEWEST, MAX_UNREAD, STOP_ANSWERS_MS, keepServing, openHost, serve };
|
|
7189
7412
|
|
|
7190
|
-
//# sourceMappingURL=host-
|
|
7413
|
+
//# sourceMappingURL=host-BsBWxTtW.js.map
|