@ghostlytools/cli 1.5.1 → 1.5.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 +16 -11
- package/dist/assets/{api-oUpBfryK.js → api-BIg0Msax.js} +2 -2
- package/dist/assets/{api-Dy_05gaq.js → api-d2aXkbM5.js} +343 -116
- package/dist/assets/api-d2aXkbM5.js.map +1 -0
- package/dist/assets/{apiKit-B-PUYkXH.js → apiKit-Ba_t7MZO.js} +18 -4
- package/dist/assets/apiKit-Ba_t7MZO.js.map +1 -0
- package/dist/assets/{apps-C6MBfO-I.js → apps-B_F3gEI4.js} +1 -1
- package/dist/assets/{apps-ejb6H1lT.js → apps-CJo1MmSY.js} +17 -16
- package/dist/assets/apps-CJo1MmSY.js.map +1 -0
- package/dist/assets/{arkade-DXyOeKEI.js → arkade-DTne0O3Q.js} +12 -5
- package/dist/assets/arkade-DTne0O3Q.js.map +1 -0
- package/dist/assets/{backup-DRIIguzE.js → backup-BY88aZr5.js} +11 -8
- package/dist/assets/backup-BY88aZr5.js.map +1 -0
- package/dist/assets/{backup-Bt6UjCiM.js → backup-CqpDAZZG.js} +1 -1
- package/dist/assets/{blobFiles-1wUBd8ZD.js → blobFiles-B1lX6iGy.js} +3 -3
- package/dist/assets/{blobFiles-1wUBd8ZD.js.map → blobFiles-B1lX6iGy.js.map} +1 -1
- package/dist/assets/{buttons-DoccJ_cK.js → buttons-B5EnA2nh.js} +23 -6
- package/dist/assets/buttons-B5EnA2nh.js.map +1 -0
- package/dist/assets/buttons-azvbN6xn.js +2 -0
- package/dist/assets/{daemonProof-CWTVNUmr.js → daemonProof-Dx3N_DLC.js} +19 -37
- package/dist/assets/daemonProof-Dx3N_DLC.js.map +1 -0
- package/dist/assets/{endpoint-Cl3cgAYl.js → endpoint-BdaeBw2L.js} +3 -3
- package/dist/assets/endpoint-BdaeBw2L.js.map +1 -0
- package/dist/assets/{envelope-hJ0SfbAh.js → envelope-BU-BB1wR.js} +2 -2
- package/dist/assets/{envelope-hJ0SfbAh.js.map → envelope-BU-BB1wR.js.map} +1 -1
- package/dist/assets/{errors-BLSPp0tK.js → errors-DI6Z3jTH.js} +26 -1
- package/dist/assets/errors-DI6Z3jTH.js.map +1 -0
- package/dist/assets/{fileBytes-gTd_8l-P.js → fileBytes-BMlLVdfg.js} +1 -1
- package/dist/assets/{fileBytes-uRqLyxa0.js → fileBytes-D0CYuRwZ.js} +2 -2
- package/dist/assets/{fileBytes-uRqLyxa0.js.map → fileBytes-D0CYuRwZ.js.map} +1 -1
- package/dist/assets/{fileBytes-B8eTZfAT.js → fileBytes-D85lBh-Q.js} +3 -3
- package/dist/assets/{fileBytes-B8eTZfAT.js.map → fileBytes-D85lBh-Q.js.map} +1 -1
- package/dist/assets/fileBytesIdb-Dn9levD1.js +2 -0
- package/dist/assets/{fileBytesIdb-BIFKtgln.js → fileBytesIdb-LAhH7kY2.js} +7 -7
- package/dist/assets/fileBytesIdb-LAhH7kY2.js.map +1 -0
- package/dist/assets/{fileBytesOpfs-ChrHcCVV.js → fileBytesOpfs-DjBBghvq.js} +3 -3
- package/dist/assets/{fileBytesOpfs-ChrHcCVV.js.map → fileBytesOpfs-DjBBghvq.js.map} +1 -1
- package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js → ghostly_iroh_web-BXCsSxxo.js} +29 -29
- package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js.map → ghostly_iroh_web-BXCsSxxo.js.map} +1 -1
- package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
- package/dist/assets/{groupFiles-BXPINkVJ.js → groupFiles-D9k6fyhf.js} +61 -17
- package/dist/assets/groupFiles-D9k6fyhf.js.map +1 -0
- package/dist/assets/{host-CzgYwupN.js → host-DrL7FPG4.js} +157 -49
- package/dist/assets/host-DrL7FPG4.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CJBqsS_e.js → hyperdhtRelay-C-BsT6_V.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CJBqsS_e.js.map → hyperdhtRelay-C-BsT6_V.js.map} +1 -1
- package/dist/assets/{idb-BJARz3Qi.js → idb-CWvq4HKc.js} +25 -3
- package/dist/assets/{idb-BJARz3Qi.js.map → idb-CWvq4HKc.js.map} +1 -1
- package/dist/assets/{irohWeb-CrGOD-OD.js → irohWeb-DdHXEwgj.js} +3 -3
- package/dist/assets/{irohWeb-CrGOD-OD.js.map → irohWeb-DdHXEwgj.js.map} +1 -1
- package/dist/assets/{main-BDOIJ_ls.js → main-xeoX7yLM.js} +160 -50
- package/dist/assets/main-xeoX7yLM.js.map +1 -0
- package/dist/assets/{mainline-Cw7rnEWM.js → mainline-CEqGvRYJ.js} +46 -16
- package/dist/assets/mainline-CEqGvRYJ.js.map +1 -0
- package/dist/assets/{networkReason-C0VY94cG.js → networkReason-RGRU5xoa.js} +3 -3
- package/dist/assets/{networkReason-C0VY94cG.js.map → networkReason-RGRU5xoa.js.map} +1 -1
- package/dist/assets/{nwc-lpGWvzYU.js → nwc-s5xHLqNf.js} +3 -3
- package/dist/assets/{nwc-lpGWvzYU.js.map → nwc-s5xHLqNf.js.map} +1 -1
- package/dist/assets/{nwcProvider-CAGRn2ly.js → nwcProvider-CfAFO5Fr.js} +2 -2
- package/dist/assets/{nwcProvider-CAGRn2ly.js.map → nwcProvider-CfAFO5Fr.js.map} +1 -1
- package/dist/assets/{profiles-BehWURA9.js → profiles-gZdQPyaz.js} +74 -13
- package/dist/assets/profiles-gZdQPyaz.js.map +1 -0
- package/dist/assets/{registry-D2bK-k1T.js → registry-BUhSjM-J.js} +1 -1
- package/dist/assets/{registry-DWkkBN57.js → registry-CVUdD4bJ.js} +3 -3
- package/dist/assets/{registry-DWkkBN57.js.map → registry-CVUdD4bJ.js.map} +1 -1
- package/dist/assets/{resolve-CvYK0Lbt.js → resolve-uZECJ3f7.js} +2 -2
- package/dist/assets/{resolve-CvYK0Lbt.js.map → resolve-uZECJ3f7.js.map} +1 -1
- package/dist/assets/{restoredRows-DGuKtIBz.js → restoredRows-D6WZUA2U.js} +2 -2
- package/dist/assets/{restoredRows-DGuKtIBz.js.map → restoredRows-D6WZUA2U.js.map} +1 -1
- package/dist/assets/{server-BktMmp7L.js → server-DOtUKoYR.js} +797 -251
- package/dist/assets/server-DOtUKoYR.js.map +1 -0
- package/dist/assets/{src-Bpy99Z2K.js → src-Dd_7Ew1X.js} +512 -141
- package/dist/assets/src-Dd_7Ew1X.js.map +1 -0
- package/dist/assets/{usdt-DFusiw8x.js → usdt-C2Anx8p7.js} +3 -3
- package/dist/assets/{usdt-DFusiw8x.js.map → usdt-C2Anx8p7.js.map} +1 -1
- package/dist/assets/{words-Z-izzDBN.js → words-DoLU6p8H.js} +4 -4
- package/dist/assets/words-DoLU6p8H.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-Dy_05gaq.js.map +0 -1
- package/dist/assets/apiKit-B-PUYkXH.js.map +0 -1
- package/dist/assets/apps-ejb6H1lT.js.map +0 -1
- package/dist/assets/arkade-DXyOeKEI.js.map +0 -1
- package/dist/assets/backup-DRIIguzE.js.map +0 -1
- package/dist/assets/buttons-B3bi6p_d.js +0 -2
- package/dist/assets/buttons-DoccJ_cK.js.map +0 -1
- package/dist/assets/daemonProof-CWTVNUmr.js.map +0 -1
- package/dist/assets/endpoint-Cl3cgAYl.js.map +0 -1
- package/dist/assets/errors-BLSPp0tK.js.map +0 -1
- package/dist/assets/fileBytesIdb-BIFKtgln.js.map +0 -1
- package/dist/assets/fileBytesIdb-BVVr_rWX.js +0 -2
- package/dist/assets/groupFiles-BXPINkVJ.js.map +0 -1
- package/dist/assets/host-CzgYwupN.js.map +0 -1
- package/dist/assets/main-BDOIJ_ls.js.map +0 -1
- package/dist/assets/mainline-Cw7rnEWM.js.map +0 -1
- package/dist/assets/profiles-BehWURA9.js.map +0 -1
- package/dist/assets/server-BktMmp7L.js.map +0 -1
- package/dist/assets/src-Bpy99Z2K.js.map +0 -1
- package/dist/assets/words-Z-izzDBN.js.map +0 -1
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-
|
|
3
|
-
import { r as asCliError, t as CliError } from "./errors-
|
|
4
|
-
import { a 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 { n as RESTORED_MARK, r as acquireLock } from "./profiles-
|
|
7
|
-
import { _ as
|
|
1
|
+
import { Fo as RTC_CONFIG, Ho as parseCallSignal, Io as answersOffer, Jl as setLinkTraceSink, Lo as buildSdpFromSignal, Po as CALL_SIGNAL_MAX_AGE_MS, Qr as checkPushEndpoint, Ro as callRtcConfig, Uo as signalHasVideo, Vo as extractParamsFromSdp, mu as fromBase64Url, wi as isPublicAddress, zo as callSignalHeardAt } from "./src-Dd_7Ew1X.js";
|
|
2
|
+
import { a as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-DdHXEwgj.js";
|
|
3
|
+
import { r as asCliError, t as CliError } from "./errors-DI6Z3jTH.js";
|
|
4
|
+
import { a as findChat, c as findOwnNamedChat } from "./apiKit-Ba_t7MZO.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-d2aXkbM5.js";
|
|
6
|
+
import { g as ownFolder, n as RESTORED_MARK, r as acquireLock, v as privateFolder, y as runtimePath } from "./profiles-gZdQPyaz.js";
|
|
7
|
+
import { _ as isCallRate, f as DEFAULT_RATE, g as frameSamples, h as frameBytes, i as newDaemonSecret, m as bytesToMs, o as proof, p as PlaybackQueue, r as greeting, u as removeDaemonSecret } from "./daemonProof-Dx3N_DLC.js";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
|
-
import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
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
12
|
import { createHash, randomBytes } from "node:crypto";
|
|
13
|
+
import { Readable } from "node:stream";
|
|
13
14
|
import { createServer, isIP } from "node:net";
|
|
14
15
|
import { createInterface } from "node:readline";
|
|
15
16
|
import { lookup } from "node:dns/promises";
|
|
16
17
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
18
|
import { Worker } from "node:worker_threads";
|
|
18
|
-
import { lookup as lookup$1 } from "node:dns";
|
|
19
19
|
import { request } from "node:https";
|
|
20
|
+
import { lookup as lookup$1 } from "node:dns";
|
|
20
21
|
import { deserialize, serialize } from "node:v8";
|
|
21
22
|
import { IDBFactory, IDBKeyRange, IDBTransaction } from "fake-indexeddb";
|
|
22
23
|
//#region src/announce.ts
|
|
@@ -48,14 +49,14 @@ function announceJoins(hub, node) {
|
|
|
48
49
|
//#region src/calls/audioSocket.ts
|
|
49
50
|
/**
|
|
50
51
|
* A call's audio socket (WISP 1100 § Calls): `<profile>/calls/<call>.sock`, 0600, in a folder only the owner may
|
|
51
|
-
* open. When that path is too long for a Unix socket:
|
|
52
|
-
* folder of the owner's, 0700, checked as such before use. A named pipe on Windows.
|
|
52
|
+
* open. When that path is too long for a Unix socket: `ghostly-calls-<hash of the profile>/<call>.sock` in the user's
|
|
53
|
+
* runtime folder (`runtimePath`), a folder of the owner's, 0700, checked as such before use. A named pipe on Windows.
|
|
53
54
|
*/
|
|
54
55
|
function audioSocketPath(profileDir, callId) {
|
|
55
56
|
const inside = join(profileDir, "calls", `${callId}.sock`);
|
|
56
57
|
if (process.platform === "win32") return `\\\\.\\pipe\\ghostly-call-${createHash("sha256").update(inside).digest("hex").slice(0, 24)}`;
|
|
57
58
|
if (Buffer.byteLength(inside) <= 100) return inside;
|
|
58
|
-
return
|
|
59
|
+
return runtimePath("ghostly-calls", profileDir, `${callId}.sock`);
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
61
62
|
* Removes the call sockets a daemon that died during a call left in this profile's folder (`audioSocketPath`; call
|
|
@@ -287,6 +288,8 @@ var CallAudio = class {
|
|
|
287
288
|
lastQuiet = null;
|
|
288
289
|
same = 0;
|
|
289
290
|
quiet = null;
|
|
291
|
+
/** Whether the encoder's FEC is on (`OpusCodec.fec`); unknown until the first frame. */
|
|
292
|
+
fecOn;
|
|
290
293
|
stopped = false;
|
|
291
294
|
/** Frames sent and received, for `call list`. */
|
|
292
295
|
sent = 0;
|
|
@@ -327,6 +330,12 @@ var CallAudio = class {
|
|
|
327
330
|
let payload;
|
|
328
331
|
if (still && this.quiet) payload = this.quiet;
|
|
329
332
|
else {
|
|
333
|
+
if (this.fecOn !== !still) {
|
|
334
|
+
this.fecOn = !still;
|
|
335
|
+
try {
|
|
336
|
+
this.options.encoder.fec?.(!still);
|
|
337
|
+
} catch {}
|
|
338
|
+
}
|
|
330
339
|
try {
|
|
331
340
|
payload = this.options.encoder.encode(frame, this.samples);
|
|
332
341
|
} catch {
|
|
@@ -463,10 +472,30 @@ var CallAudio = class {
|
|
|
463
472
|
}
|
|
464
473
|
};
|
|
465
474
|
//#endregion
|
|
475
|
+
//#region src/envSwitch.ts
|
|
476
|
+
var OFF = /^(0|false|off|no)$/i;
|
|
477
|
+
var ON = /^(1|true|on|yes)$/i;
|
|
478
|
+
/**
|
|
479
|
+
* An on/off environment switch (`GHOSTLY_DHT`, `GHOSTLY_STUN`, `GHOSTLY_WEBRTC`, `GHOSTLY_HUB`): unset or empty is
|
|
480
|
+
* `fallback`; 0/false/off/no and 1/true/on/yes, in any case and trimmed, say it; anything else is a usage error naming
|
|
481
|
+
* the variable. Before, only the exact "0" turned one off: `GHOSTLY_DHT=false` kept the profile on the public Mainline
|
|
482
|
+
* DHT, and `GHOSTLY_STUN=off` kept asking Google's STUN servers, with no word (agents#1756). A privacy switch never
|
|
483
|
+
* fails open in silence.
|
|
484
|
+
*/
|
|
485
|
+
function envSwitch(name, fallback, env = process.env) {
|
|
486
|
+
const value = env[name];
|
|
487
|
+
if (value === void 0 || value.trim() === "") return fallback;
|
|
488
|
+
if (OFF.test(value.trim())) return false;
|
|
489
|
+
if (ON.test(value.trim())) return true;
|
|
490
|
+
throw new CliError("usage", `${name} takes 0 or 1 (or false/true, off/on, no/yes), not ${JSON.stringify(value)}`);
|
|
491
|
+
}
|
|
492
|
+
//#endregion
|
|
466
493
|
//#region src/calls/media.ts
|
|
467
494
|
var loading = null;
|
|
468
495
|
var OPUS_APPLICATION_VOIP = 2048;
|
|
469
496
|
var OPUS_SET_BITRATE = 4002;
|
|
497
|
+
var OPUS_SET_INBAND_FEC = 4012;
|
|
498
|
+
var OPUS_SET_PACKET_LOSS_PERC = 4014;
|
|
470
499
|
/** The largest packet a codec reads or writes (opusscript's MAX_PACKET_SIZE). */
|
|
471
500
|
var MAX_PACKET_BYTES = 3828;
|
|
472
501
|
/**
|
|
@@ -502,6 +531,10 @@ function opusCodec(native, rate) {
|
|
|
502
531
|
if (samples < 0) throw new Error(`Decode error: ${samples}`);
|
|
503
532
|
return Buffer.from(native.HEAPU16.subarray(pcm / 2, pcm / 2 + Math.min(samples * 2, MAX_PCM_OUT)));
|
|
504
533
|
},
|
|
534
|
+
fec(on) {
|
|
535
|
+
if (deleted) return;
|
|
536
|
+
if (handler._encoder_ctl(OPUS_SET_INBAND_FEC, on ? 1 : 0) < 0 || handler._encoder_ctl(OPUS_SET_PACKET_LOSS_PERC, on ? 10 : 0) < 0) throw new Error("Encoder CTL error");
|
|
537
|
+
},
|
|
505
538
|
delete() {
|
|
506
539
|
if (deleted) return;
|
|
507
540
|
deleted = true;
|
|
@@ -510,7 +543,7 @@ function opusCodec(native, rate) {
|
|
|
510
543
|
native._free(packet);
|
|
511
544
|
}
|
|
512
545
|
};
|
|
513
|
-
if (handler._encoder_ctl(OPUS_SET_BITRATE, 32e3) < 0) {
|
|
546
|
+
if (handler._encoder_ctl(OPUS_SET_BITRATE, 32e3) < 0 || handler._encoder_ctl(OPUS_SET_INBAND_FEC, 1) < 0 || handler._encoder_ctl(OPUS_SET_PACKET_LOSS_PERC, 10) < 0) {
|
|
514
547
|
codec.delete?.();
|
|
515
548
|
throw new Error("Encoder CTL error");
|
|
516
549
|
}
|
|
@@ -519,7 +552,11 @@ function opusCodec(native, rate) {
|
|
|
519
552
|
/** The media stack, or why calls are not available here (the reason the call buttons of the contact's app show). */
|
|
520
553
|
function loadCallStack() {
|
|
521
554
|
return loading ??= (async () => {
|
|
522
|
-
|
|
555
|
+
try {
|
|
556
|
+
if (!envSwitch("GHOSTLY_WEBRTC", true)) return "Calls are off on this headless Ghostly (GHOSTLY_WEBRTC=0)";
|
|
557
|
+
} catch (error) {
|
|
558
|
+
return error.message;
|
|
559
|
+
}
|
|
523
560
|
try {
|
|
524
561
|
const ndc = await import("node-datachannel");
|
|
525
562
|
const lib = ndc.PeerConnection ? ndc : ndc.default;
|
|
@@ -541,7 +578,7 @@ function loadCallStack() {
|
|
|
541
578
|
* apps' calls use them.
|
|
542
579
|
*/
|
|
543
580
|
function callIceServers(extra = [], env = process.env) {
|
|
544
|
-
const out =
|
|
581
|
+
const out = !envSwitch("GHOSTLY_STUN", true, env) ? [] : (RTC_CONFIG.iceServers ?? []).flatMap((server) => [server.urls].flat()).slice(0, 2);
|
|
545
582
|
for (const server of callRtcConfig(extra).iceServers?.slice(RTC_CONFIG.iceServers?.length ?? 0) ?? []) for (const url of [server.urls].flat()) {
|
|
546
583
|
const m = /^(stun|turns?):([^:?\s]+)(?::(\d+))?(?:\?transport=(udp|tcp))?$/i.exec(url);
|
|
547
584
|
if (!m) continue;
|
|
@@ -1212,7 +1249,7 @@ var CallManager = class {
|
|
|
1212
1249
|
};
|
|
1213
1250
|
}
|
|
1214
1251
|
setAuto(next) {
|
|
1215
|
-
const from = (next.from ?? []).map((ref) => this.
|
|
1252
|
+
const from = (next.from ?? []).map((ref) => findOwnNamedChat(this.host.engine.getState().links, ref).id);
|
|
1216
1253
|
this.auto = {
|
|
1217
1254
|
on: next.on,
|
|
1218
1255
|
from: next.on ? from : [],
|
|
@@ -2766,6 +2803,34 @@ async function nodePushSend(push, lookup = publicOnlyLookup) {
|
|
|
2766
2803
|
});
|
|
2767
2804
|
}
|
|
2768
2805
|
//#endregion
|
|
2806
|
+
//#region src/runtime/holdFetch.ts
|
|
2807
|
+
/**
|
|
2808
|
+
* How the CLI reads a held item or manifest (WISP 404): a GET to the address the contact chose, only
|
|
2809
|
+
* at a name whose every address is public, checked when the connection is made (so a name that changes its answer
|
|
2810
|
+
* in between is refused too). No redirect is followed, no proxy, no credentials. The engine bounds the size and time.
|
|
2811
|
+
*/
|
|
2812
|
+
function nodeHoldFetch(lookup = publicOnlyLookup) {
|
|
2813
|
+
return (input, init) => new Promise((resolve, reject) => {
|
|
2814
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
2815
|
+
const req = request(url, {
|
|
2816
|
+
method: "GET",
|
|
2817
|
+
lookup,
|
|
2818
|
+
agent: false,
|
|
2819
|
+
signal: init?.signal ?? void 0
|
|
2820
|
+
}, (res) => {
|
|
2821
|
+
const headers = new Headers();
|
|
2822
|
+
for (const [name, value] of Object.entries(res.headers)) if (typeof value === "string") headers.set(name, value);
|
|
2823
|
+
const status = res.statusCode ?? 0;
|
|
2824
|
+
resolve(new Response(status === 204 || status === 304 ? null : Readable.toWeb(res), {
|
|
2825
|
+
status,
|
|
2826
|
+
headers
|
|
2827
|
+
}));
|
|
2828
|
+
});
|
|
2829
|
+
req.on("error", reject);
|
|
2830
|
+
req.end();
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
//#endregion
|
|
2769
2834
|
//#region src/runtime/rows.ts
|
|
2770
2835
|
/** The warning `node:sqlite` gives as it loads (experimental on Node 22 and 23): said once for every command, it is noise. */
|
|
2771
2836
|
var SQLITE_WARNING = /^SQLite is an experimental feature/;
|
|
@@ -2917,6 +2982,15 @@ function thaw(bytes) {
|
|
|
2917
2982
|
function handOut(value) {
|
|
2918
2983
|
return value && typeof value === "object" && fresh.delete(value) ? value : structuredClone(value);
|
|
2919
2984
|
}
|
|
2985
|
+
/**
|
|
2986
|
+
* Ends a SQLite transaction that failed. SQLite rolls one back itself on some errors (a full disk): the ROLLBACK then
|
|
2987
|
+
* throws "cannot rollback - no transaction is active", which hid the error that mattered (ENOSPC) from the log.
|
|
2988
|
+
*/
|
|
2989
|
+
function rollback(db) {
|
|
2990
|
+
try {
|
|
2991
|
+
db.exec("ROLLBACK");
|
|
2992
|
+
} catch {}
|
|
2993
|
+
}
|
|
2920
2994
|
/** rows.db's trees: the stores kept on disk and their indexes, each a tree id in `entries`. */
|
|
2921
2995
|
var TreeFile = class {
|
|
2922
2996
|
db;
|
|
@@ -2981,7 +3055,7 @@ var TreeFile = class {
|
|
|
2981
3055
|
this.db.prepare("INSERT OR REPLACE INTO meta (name, value) VALUES ('applied', max(?, coalesce((SELECT value FROM meta WHERE name = 'applied'), 0)))").run(top);
|
|
2982
3056
|
this.db.exec("COMMIT");
|
|
2983
3057
|
} catch (error) {
|
|
2984
|
-
this.db
|
|
3058
|
+
rollback(this.db);
|
|
2985
3059
|
throw error;
|
|
2986
3060
|
}
|
|
2987
3061
|
for (const tree of due) tree.settle(upTo);
|
|
@@ -3006,7 +3080,7 @@ var TreeFile = class {
|
|
|
3006
3080
|
}
|
|
3007
3081
|
this.db.exec("COMMIT");
|
|
3008
3082
|
} catch (error) {
|
|
3009
|
-
this.db
|
|
3083
|
+
rollback(this.db);
|
|
3010
3084
|
throw error;
|
|
3011
3085
|
}
|
|
3012
3086
|
for (const tree of this.live) if (!keep.has(tree.id)) this.live.delete(tree);
|
|
@@ -3549,9 +3623,8 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3549
3623
|
} else {
|
|
3550
3624
|
const ops = pending.get(this._rollbackLog);
|
|
3551
3625
|
if (ops?.length) {
|
|
3552
|
-
const
|
|
3553
|
-
|
|
3554
|
-
append(ops, this.durability === "relaxed", entry);
|
|
3626
|
+
const refused = append(ops, this.durability === "relaxed", ++seq, this._rollbackLog);
|
|
3627
|
+
if (refused) return refuse(this, refused.error, event);
|
|
3555
3628
|
}
|
|
3556
3629
|
}
|
|
3557
3630
|
pending.delete(this._rollbackLog);
|
|
@@ -3573,8 +3646,12 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3573
3646
|
});
|
|
3574
3647
|
return request;
|
|
3575
3648
|
};
|
|
3576
|
-
/**
|
|
3577
|
-
|
|
3649
|
+
/**
|
|
3650
|
+
* A committed transaction's entry, numbered `entry` (its first op says so, where there are trees), from the
|
|
3651
|
+
* transaction whose rollback log is `owner`. Written at once, it may fail (a full disk): the reason is given back,
|
|
3652
|
+
* and the transaction is to be refused, not completed.
|
|
3653
|
+
*/
|
|
3654
|
+
function append(ops, lazy, entry, owner) {
|
|
3578
3655
|
if (trees) ops = [{
|
|
3579
3656
|
db: SEQ,
|
|
3580
3657
|
store: "",
|
|
@@ -3582,15 +3659,42 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3582
3659
|
seq: entry
|
|
3583
3660
|
}, ...ops];
|
|
3584
3661
|
if (queued === 0 && !ops.some((op) => op.kind === "put" && hasBlob(op.value))) {
|
|
3585
|
-
|
|
3586
|
-
|
|
3662
|
+
let done;
|
|
3663
|
+
try {
|
|
3664
|
+
done = writeEntry(serialize(ops), lazy);
|
|
3665
|
+
} catch (error) {
|
|
3666
|
+
return { error };
|
|
3667
|
+
}
|
|
3668
|
+
trees?.complete(owner, entry);
|
|
3669
|
+
if (done) written(entry);
|
|
3670
|
+
return null;
|
|
3587
3671
|
}
|
|
3672
|
+
trees?.complete(owner, entry);
|
|
3588
3673
|
enqueue(async () => {
|
|
3589
3674
|
if (writeEntry(serialize(await Promise.all(ops.map(async (op) => op.kind === "put" ? {
|
|
3590
3675
|
...op,
|
|
3591
3676
|
value: await blobsToDisk(op.value)
|
|
3592
3677
|
} : op))), lazy)) written(entry);
|
|
3593
3678
|
});
|
|
3679
|
+
return null;
|
|
3680
|
+
}
|
|
3681
|
+
/**
|
|
3682
|
+
* A transaction whose entry the disk did not take: what it wrote is undone (as fake-indexeddb's own abort does), and
|
|
3683
|
+
* it ends with an `abort` in place of its `complete`, with a QuotaExceededError, as a browser's out of room does. It
|
|
3684
|
+
* completed, before: the engine answered done for a change that was held but not on disk (a full disk under a
|
|
3685
|
+
* daemon), and a restart lost it.
|
|
3686
|
+
*/
|
|
3687
|
+
function refuse(transaction, error, complete) {
|
|
3688
|
+
failed(error);
|
|
3689
|
+
for (const undo of transaction._rollbackLog.reverse()) undo();
|
|
3690
|
+
const reason = error?.code === "ENOSPC" ? `No room left on the disk of ${dir}: free some space, then try again` : `This change could not be saved in ${dir}`;
|
|
3691
|
+
transaction.error = Object.assign(new DOMException(reason, "QuotaExceededError"), { cause: error });
|
|
3692
|
+
const abort = new complete.constructor("abort", {
|
|
3693
|
+
bubbles: true,
|
|
3694
|
+
cancelable: false
|
|
3695
|
+
});
|
|
3696
|
+
abort.eventPath = [transaction.db];
|
|
3697
|
+
return transaction.dispatchEvent(abort);
|
|
3594
3698
|
}
|
|
3595
3699
|
/**
|
|
3596
3700
|
* The journal has entry `entry`: the trees' layers up to it go to SQLite. One that fails stays in memory, where reads
|
|
@@ -3635,7 +3739,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3635
3739
|
indexes.forEach((index, at) => trees.load(ids[at], index.records.values(), true, index.records.keysAreUnique));
|
|
3636
3740
|
trees.db.exec("COMMIT");
|
|
3637
3741
|
} catch (error) {
|
|
3638
|
-
trees.db
|
|
3742
|
+
rollback(trees.db);
|
|
3639
3743
|
throw error;
|
|
3640
3744
|
}
|
|
3641
3745
|
attachTree(store.records, trees.tree(id, true, false), false);
|
|
@@ -3669,20 +3773,24 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3669
3773
|
*/
|
|
3670
3774
|
function writeEntry(entry, lazy = false) {
|
|
3671
3775
|
if (!writing) return false;
|
|
3776
|
+
let whole = -1;
|
|
3672
3777
|
try {
|
|
3673
|
-
if (journalFd === null)
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
}
|
|
3778
|
+
if (journalFd === null) journalFd = openSync(journalPath, "a", 384);
|
|
3779
|
+
whole = fstatSync(journalFd).size;
|
|
3780
|
+
if (snapshotName !== void 0 && whole === 0) writeAll(journalFd, framed(serialize([{
|
|
3781
|
+
db: FOLLOWS,
|
|
3782
|
+
store: "",
|
|
3783
|
+
kind: "clear",
|
|
3784
|
+
snapshot: snapshotName
|
|
3785
|
+
}])));
|
|
3682
3786
|
marked = false;
|
|
3683
3787
|
writeAll(journalFd, framed(entry));
|
|
3788
|
+
if (!lazy) sync();
|
|
3684
3789
|
} catch (error) {
|
|
3685
3790
|
unsaved = true;
|
|
3791
|
+
if (journalFd !== null && whole >= 0) try {
|
|
3792
|
+
ftruncateSync(journalFd, whole);
|
|
3793
|
+
} catch {}
|
|
3686
3794
|
throw error;
|
|
3687
3795
|
}
|
|
3688
3796
|
if (lazy) relaxed ??= setTimeout(() => {
|
|
@@ -3692,7 +3800,6 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3692
3800
|
failed(error);
|
|
3693
3801
|
}
|
|
3694
3802
|
}, RELAXED_SYNC_MS).unref();
|
|
3695
|
-
else sync();
|
|
3696
3803
|
if (statSync(journalPath).size > COMPACT_BYTES) enqueue(writeSnapshot);
|
|
3697
3804
|
return true;
|
|
3698
3805
|
}
|
|
@@ -4257,7 +4364,7 @@ function recordsToDisk(trees, db, store, saved, cmp) {
|
|
|
4257
4364
|
}
|
|
4258
4365
|
trees.db.exec("COMMIT");
|
|
4259
4366
|
} catch (error) {
|
|
4260
|
-
trees.db
|
|
4367
|
+
rollback(trees.db);
|
|
4261
4368
|
throw error;
|
|
4262
4369
|
}
|
|
4263
4370
|
}
|
|
@@ -4531,7 +4638,7 @@ function irohRelays(env = process.env) {
|
|
|
4531
4638
|
* profile's own `iceServers` stay.
|
|
4532
4639
|
*/
|
|
4533
4640
|
function publicStun(env = process.env) {
|
|
4534
|
-
return
|
|
4641
|
+
return envSwitch("GHOSTLY_STUN", true, env);
|
|
4535
4642
|
}
|
|
4536
4643
|
/** An RTC configuration without the apps' public STUN servers. */
|
|
4537
4644
|
function withoutPublicStun(config) {
|
|
@@ -4553,7 +4660,7 @@ function withoutPublicStun(config) {
|
|
|
4553
4660
|
* public DHT.
|
|
4554
4661
|
*/
|
|
4555
4662
|
function mainlineNetwork(env = process.env) {
|
|
4556
|
-
if (
|
|
4663
|
+
if (!envSwitch("GHOSTLY_DHT", true, env)) return { off: true };
|
|
4557
4664
|
const bootstrap = (env.GHOSTLY_DHT_BOOTSTRAP ?? "").split(",").map((node) => node.trim()).filter(Boolean);
|
|
4558
4665
|
if (!bootstrap.length && pkarrRelays(env)) return { off: true };
|
|
4559
4666
|
if (!bootstrap.length) return { off: false };
|
|
@@ -4569,7 +4676,7 @@ function mainlineNetwork(env = process.env) {
|
|
|
4569
4676
|
* `GHOSTLY_WEBRTC=0`, the CLI runs without WebRTC and says so.
|
|
4570
4677
|
*/
|
|
4571
4678
|
async function installWebRtc() {
|
|
4572
|
-
if (
|
|
4679
|
+
if (!envSwitch("GHOSTLY_WEBRTC", true)) return false;
|
|
4573
4680
|
try {
|
|
4574
4681
|
const polyfill = await import("node-datachannel/polyfill");
|
|
4575
4682
|
const scope = globalThis;
|
|
@@ -4671,7 +4778,7 @@ async function startRuntime(paths, options = {}) {
|
|
|
4671
4778
|
const restored = join(paths.dir, RESTORED_MARK);
|
|
4672
4779
|
if (existsSync(restored)) {
|
|
4673
4780
|
try {
|
|
4674
|
-
const rows = await import("./restoredRows-
|
|
4781
|
+
const rows = await import("./restoredRows-D6WZUA2U.js");
|
|
4675
4782
|
await rows.markRestoredWallet();
|
|
4676
4783
|
await rows.markLeftOutFiles(leftOutIn(restored));
|
|
4677
4784
|
await store.compact();
|
|
@@ -4689,18 +4796,18 @@ async function startRuntime(paths, options = {}) {
|
|
|
4689
4796
|
if (testMints) (await import("./mints-CqTdA4Gk.js")).declareTestMints(testMints.split(","));
|
|
4690
4797
|
await installEventSource();
|
|
4691
4798
|
await preloadWalletModules();
|
|
4692
|
-
(await import("./ghostly_iroh_web-
|
|
4693
|
-
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-
|
|
4799
|
+
(await import("./ghostly_iroh_web-BXCsSxxo.js")).initSync({ module: irohWasmBytes() });
|
|
4800
|
+
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-BMlLVdfg.js"), import("./fileBytes-D0CYuRwZ.js")]);
|
|
4694
4801
|
registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
|
|
4695
|
-
if (await (await import("./blobFiles-
|
|
4696
|
-
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-
|
|
4802
|
+
if (await (await import("./blobFiles-B1lX6iGy.js")).moveBlobFiles()) await store.compact();
|
|
4803
|
+
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-DOtUKoYR.js"), import("./endpoint-BdaeBw2L.js")]);
|
|
4697
4804
|
const network = hyperdhtNetwork();
|
|
4698
4805
|
const dht = mainlineNetwork();
|
|
4699
|
-
const mainline = dht.off ? null : new (await (import("./mainline-
|
|
4806
|
+
const mainline = dht.off ? null : new (await (import("./mainline-CEqGvRYJ.js"))).Mainline({
|
|
4700
4807
|
bootstrap: dht.bootstrap,
|
|
4701
4808
|
host: dht.host
|
|
4702
4809
|
});
|
|
4703
|
-
const transport = mainline || pinned ? new (await (import("./mainline-
|
|
4810
|
+
const transport = mainline || pinned ? new (await (import("./mainline-CEqGvRYJ.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
|
|
4704
4811
|
const apps = servedApps(paths.dir).length > 0;
|
|
4705
4812
|
const server = new EngineServer({
|
|
4706
4813
|
...transport ? { transport } : {},
|
|
@@ -4712,9 +4819,10 @@ async function startRuntime(paths, options = {}) {
|
|
|
4712
4819
|
fedimintSdk: nodeFedimintSdk(join(paths.dir, "fedimint")),
|
|
4713
4820
|
servicesSupport: true,
|
|
4714
4821
|
apps: apps ? "wire" : false,
|
|
4715
|
-
staysOnline:
|
|
4822
|
+
staysOnline: envSwitch("GHOSTLY_HUB", true),
|
|
4716
4823
|
localFetch: nodeLocalFetch,
|
|
4717
4824
|
pushSend: (request) => nodePushSend(request),
|
|
4825
|
+
holdFetch: nodeHoldFetch(),
|
|
4718
4826
|
callsSupport: callsUnavailable === null,
|
|
4719
4827
|
...callsUnavailable ? { callsUnavailable } : {},
|
|
4720
4828
|
...options.deferGroups ? { deferGroups: true } : {},
|
|
@@ -5040,4 +5148,4 @@ function connection(ctx, socket, secret) {
|
|
|
5040
5148
|
//#endregion
|
|
5041
5149
|
export { BASELINE_NEWEST, MAX_LINE, MAX_UNREAD, keepServing, openHost, serve };
|
|
5042
5150
|
|
|
5043
|
-
//# sourceMappingURL=host-
|
|
5151
|
+
//# sourceMappingURL=host-DrL7FPG4.js.map
|