@ghostlytools/cli 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -13
- package/dist/assets/{api-CHD8_kcJ.js → api-ButrHieZ.js} +2 -2
- package/dist/assets/{api-CMohP9Pw.js → api-DDmune9b.js} +352 -120
- package/dist/assets/api-DDmune9b.js.map +1 -0
- package/dist/assets/{apiKit-CfwVtBcw.js → apiKit-DfFlJhXO.js} +4 -4
- package/dist/assets/apiKit-DfFlJhXO.js.map +1 -0
- package/dist/assets/{apps-733nXRBy.js → apps-BVnNpB2f.js} +1 -1
- package/dist/assets/{apps-LG-QOIxs.js → apps-CpQVuYqT.js} +17 -16
- package/dist/assets/apps-CpQVuYqT.js.map +1 -0
- package/dist/assets/{arkade-C8x3Efyj.js → arkade-C9Ne-zJb.js} +12 -5
- package/dist/assets/arkade-C9Ne-zJb.js.map +1 -0
- package/dist/assets/{backup-nCbNWJ7-.js → backup-DavZrUf6.js} +1 -1
- package/dist/assets/{backup-CfJenOQo.js → backup-MN2sZQeW.js} +11 -8
- package/dist/assets/backup-MN2sZQeW.js.map +1 -0
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/{blobFiles-1wUBd8ZD.js → blobFiles-B6nf0gCG.js} +3 -3
- package/dist/assets/{blobFiles-1wUBd8ZD.js.map → blobFiles-B6nf0gCG.js.map} +1 -1
- package/dist/assets/buttons-DC20Q2no.js +2 -0
- package/dist/assets/{buttons-BC0stvPg.js → buttons-DIWDW2n5.js} +23 -6
- package/dist/assets/buttons-DIWDW2n5.js.map +1 -0
- package/dist/assets/{daemonProof-CWTVNUmr.js → daemonProof-ui8jtIw0.js} +19 -37
- package/dist/assets/daemonProof-ui8jtIw0.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-BbvUBjc5.js → envelope-ByeUit1N.js} +2 -2
- package/dist/assets/{envelope-BbvUBjc5.js.map → envelope-ByeUit1N.js.map} +1 -1
- package/dist/assets/{errors-BLSPp0tK.js → errors-CzXgR8Cc.js} +39 -4
- package/dist/assets/errors-CzXgR8Cc.js.map +1 -0
- package/dist/assets/{fileBytes-B8eTZfAT.js → fileBytes-BMEBas7S.js} +3 -3
- package/dist/assets/{fileBytes-B8eTZfAT.js.map → fileBytes-BMEBas7S.js.map} +1 -1
- package/dist/assets/{fileBytes-uRqLyxa0.js → fileBytes-CFNrRfcl.js} +2 -2
- package/dist/assets/{fileBytes-uRqLyxa0.js.map → fileBytes-CFNrRfcl.js.map} +1 -1
- package/dist/assets/{fileBytes-gTd_8l-P.js → fileBytes-CtwagJ8h.js} +1 -1
- package/dist/assets/{fileBytesIdb-BIFKtgln.js → fileBytesIdb-BXAN7i-N.js} +7 -7
- package/dist/assets/fileBytesIdb-BXAN7i-N.js.map +1 -0
- package/dist/assets/fileBytesIdb-C20oXDdr.js +2 -0
- package/dist/assets/{fileBytesOpfs-ChrHcCVV.js → fileBytesOpfs-Do1Vpkis.js} +3 -3
- package/dist/assets/{fileBytesOpfs-ChrHcCVV.js.map → fileBytesOpfs-Do1Vpkis.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-Bmo-SkVQ.js → groupFiles-DVxX0O1g.js} +61 -17
- package/dist/assets/groupFiles-DVxX0O1g.js.map +1 -0
- package/dist/assets/{host-DxDRCRKD.js → host-AB2Cr46b.js} +127 -48
- package/dist/assets/host-AB2Cr46b.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CZfsPfT9.js → hyperdhtRelay-BcrwJRtb.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CZfsPfT9.js.map → hyperdhtRelay-BcrwJRtb.js.map} +1 -1
- package/dist/assets/{idb-BJARz3Qi.js → idb-BlH8-O3R.js} +35 -5
- package/dist/assets/idb-BlH8-O3R.js.map +1 -0
- package/dist/assets/{irohWeb-BUvaADop.js → irohWeb-B5j2rgWj.js} +3 -3
- package/dist/assets/{irohWeb-BUvaADop.js.map → irohWeb-B5j2rgWj.js.map} +1 -1
- package/dist/assets/{main-BIXIs84L.js → main-AHz1dbsm.js} +227 -62
- package/dist/assets/main-AHz1dbsm.js.map +1 -0
- package/dist/assets/{mainline-HQVJ5ukA.js → mainline-afyQ77bv.js} +46 -16
- package/dist/assets/mainline-afyQ77bv.js.map +1 -0
- package/dist/assets/{networkReason-CKBiFTwt.js → networkReason-DWzsMN8E.js} +3 -3
- package/dist/assets/{networkReason-CKBiFTwt.js.map → networkReason-DWzsMN8E.js.map} +1 -1
- package/dist/assets/{nwc-Dm4RSvvF.js → nwc-DYXTp8UX.js} +3 -3
- package/dist/assets/{nwc-Dm4RSvvF.js.map → nwc-DYXTp8UX.js.map} +1 -1
- package/dist/assets/{nwcProvider-yQdL-DfC.js → nwcProvider-B4k6mYJl.js} +2 -2
- package/dist/assets/{nwcProvider-yQdL-DfC.js.map → nwcProvider-B4k6mYJl.js.map} +1 -1
- package/dist/assets/{profiles-BehWURA9.js → profiles-CEnZfN78.js} +74 -13
- package/dist/assets/profiles-CEnZfN78.js.map +1 -0
- package/dist/assets/{registry-CHVZ0Jzl.js → registry-Ccru6KBP.js} +1 -1
- package/dist/assets/{registry-C9f2Ogff.js → registry-wSZHgbsv.js} +3 -3
- package/dist/assets/{registry-C9f2Ogff.js.map → registry-wSZHgbsv.js.map} +1 -1
- package/dist/assets/{resolve-Cqj1jjK2.js → resolve-BPJnMtLC.js} +2 -2
- package/dist/assets/{resolve-Cqj1jjK2.js.map → resolve-BPJnMtLC.js.map} +1 -1
- package/dist/assets/{restoredRows-DGuKtIBz.js → restoredRows-Fv-MuY45.js} +2 -2
- package/dist/assets/{restoredRows-DGuKtIBz.js.map → restoredRows-Fv-MuY45.js.map} +1 -1
- package/dist/assets/{server-CcAs54Yb.js → server-DPzt5V2x.js} +993 -283
- package/dist/assets/server-DPzt5V2x.js.map +1 -0
- package/dist/assets/{src-BLHey3Q1.js → src-CFeRBeHz.js} +518 -134
- package/dist/assets/src-CFeRBeHz.js.map +1 -0
- package/dist/assets/{usdt-DMKpMhdM.js → usdt-CBh78JVF.js} +3 -3
- package/dist/assets/{usdt-DMKpMhdM.js.map → usdt-CBh78JVF.js.map} +1 -1
- package/dist/assets/{words-DUlvkoUT.js → words-DC8BQvPO.js} +4 -4
- package/dist/assets/words-DC8BQvPO.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/payment-bot.mjs +5 -2
- package/package.json +1 -1
- package/dist/assets/api-CMohP9Pw.js.map +0 -1
- package/dist/assets/apiKit-CfwVtBcw.js.map +0 -1
- package/dist/assets/apps-LG-QOIxs.js.map +0 -1
- package/dist/assets/arkade-C8x3Efyj.js.map +0 -1
- package/dist/assets/backup-CfJenOQo.js.map +0 -1
- package/dist/assets/buttons-BC0stvPg.js.map +0 -1
- package/dist/assets/buttons-BDKeKyKw.js +0 -2
- 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-Bmo-SkVQ.js.map +0 -1
- package/dist/assets/host-DxDRCRKD.js.map +0 -1
- package/dist/assets/idb-BJARz3Qi.js.map +0 -1
- package/dist/assets/main-BIXIs84L.js.map +0 -1
- package/dist/assets/mainline-HQVJ5ukA.js.map +0 -1
- package/dist/assets/profiles-BehWURA9.js.map +0 -1
- package/dist/assets/server-CcAs54Yb.js.map +0 -1
- package/dist/assets/src-BLHey3Q1.js.map +0 -1
- package/dist/assets/words-DUlvkoUT.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
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, c as findOwnNamedChat } 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-CFeRBeHz.js";
|
|
2
|
+
import { a as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-B5j2rgWj.js";
|
|
3
|
+
import { r as asCliError, t as CliError } from "./errors-CzXgR8Cc.js";
|
|
4
|
+
import { a as findChat, c as findOwnNamedChat } from "./apiKit-DfFlJhXO.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-DDmune9b.js";
|
|
6
|
+
import { g as ownFolder, n as RESTORED_MARK, r as acquireLock, v as privateFolder, y as runtimePath } from "./profiles-CEnZfN78.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-ui8jtIw0.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";
|
|
@@ -49,14 +49,14 @@ function announceJoins(hub, node) {
|
|
|
49
49
|
//#region src/calls/audioSocket.ts
|
|
50
50
|
/**
|
|
51
51
|
* A call's audio socket (WISP 1100 § Calls): `<profile>/calls/<call>.sock`, 0600, in a folder only the owner may
|
|
52
|
-
* open. When that path is too long for a Unix socket:
|
|
53
|
-
* 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.
|
|
54
54
|
*/
|
|
55
55
|
function audioSocketPath(profileDir, callId) {
|
|
56
56
|
const inside = join(profileDir, "calls", `${callId}.sock`);
|
|
57
57
|
if (process.platform === "win32") return `\\\\.\\pipe\\ghostly-call-${createHash("sha256").update(inside).digest("hex").slice(0, 24)}`;
|
|
58
58
|
if (Buffer.byteLength(inside) <= 100) return inside;
|
|
59
|
-
return
|
|
59
|
+
return runtimePath("ghostly-calls", profileDir, `${callId}.sock`);
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Removes the call sockets a daemon that died during a call left in this profile's folder (`audioSocketPath`; call
|
|
@@ -288,6 +288,8 @@ var CallAudio = class {
|
|
|
288
288
|
lastQuiet = null;
|
|
289
289
|
same = 0;
|
|
290
290
|
quiet = null;
|
|
291
|
+
/** Whether the encoder's FEC is on (`OpusCodec.fec`); unknown until the first frame. */
|
|
292
|
+
fecOn;
|
|
291
293
|
stopped = false;
|
|
292
294
|
/** Frames sent and received, for `call list`. */
|
|
293
295
|
sent = 0;
|
|
@@ -328,6 +330,12 @@ var CallAudio = class {
|
|
|
328
330
|
let payload;
|
|
329
331
|
if (still && this.quiet) payload = this.quiet;
|
|
330
332
|
else {
|
|
333
|
+
if (this.fecOn !== !still) {
|
|
334
|
+
this.fecOn = !still;
|
|
335
|
+
try {
|
|
336
|
+
this.options.encoder.fec?.(!still);
|
|
337
|
+
} catch {}
|
|
338
|
+
}
|
|
331
339
|
try {
|
|
332
340
|
payload = this.options.encoder.encode(frame, this.samples);
|
|
333
341
|
} catch {
|
|
@@ -464,10 +472,30 @@ var CallAudio = class {
|
|
|
464
472
|
}
|
|
465
473
|
};
|
|
466
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
|
|
467
493
|
//#region src/calls/media.ts
|
|
468
494
|
var loading = null;
|
|
469
495
|
var OPUS_APPLICATION_VOIP = 2048;
|
|
470
496
|
var OPUS_SET_BITRATE = 4002;
|
|
497
|
+
var OPUS_SET_INBAND_FEC = 4012;
|
|
498
|
+
var OPUS_SET_PACKET_LOSS_PERC = 4014;
|
|
471
499
|
/** The largest packet a codec reads or writes (opusscript's MAX_PACKET_SIZE). */
|
|
472
500
|
var MAX_PACKET_BYTES = 3828;
|
|
473
501
|
/**
|
|
@@ -503,6 +531,10 @@ function opusCodec(native, rate) {
|
|
|
503
531
|
if (samples < 0) throw new Error(`Decode error: ${samples}`);
|
|
504
532
|
return Buffer.from(native.HEAPU16.subarray(pcm / 2, pcm / 2 + Math.min(samples * 2, MAX_PCM_OUT)));
|
|
505
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
|
+
},
|
|
506
538
|
delete() {
|
|
507
539
|
if (deleted) return;
|
|
508
540
|
deleted = true;
|
|
@@ -511,7 +543,7 @@ function opusCodec(native, rate) {
|
|
|
511
543
|
native._free(packet);
|
|
512
544
|
}
|
|
513
545
|
};
|
|
514
|
-
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) {
|
|
515
547
|
codec.delete?.();
|
|
516
548
|
throw new Error("Encoder CTL error");
|
|
517
549
|
}
|
|
@@ -520,7 +552,11 @@ function opusCodec(native, rate) {
|
|
|
520
552
|
/** The media stack, or why calls are not available here (the reason the call buttons of the contact's app show). */
|
|
521
553
|
function loadCallStack() {
|
|
522
554
|
return loading ??= (async () => {
|
|
523
|
-
|
|
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
|
+
}
|
|
524
560
|
try {
|
|
525
561
|
const ndc = await import("node-datachannel");
|
|
526
562
|
const lib = ndc.PeerConnection ? ndc : ndc.default;
|
|
@@ -542,7 +578,7 @@ function loadCallStack() {
|
|
|
542
578
|
* apps' calls use them.
|
|
543
579
|
*/
|
|
544
580
|
function callIceServers(extra = [], env = process.env) {
|
|
545
|
-
const out =
|
|
581
|
+
const out = !envSwitch("GHOSTLY_STUN", true, env) ? [] : (RTC_CONFIG.iceServers ?? []).flatMap((server) => [server.urls].flat()).slice(0, 2);
|
|
546
582
|
for (const server of callRtcConfig(extra).iceServers?.slice(RTC_CONFIG.iceServers?.length ?? 0) ?? []) for (const url of [server.urls].flat()) {
|
|
547
583
|
const m = /^(stun|turns?):([^:?\s]+)(?::(\d+))?(?:\?transport=(udp|tcp))?$/i.exec(url);
|
|
548
584
|
if (!m) continue;
|
|
@@ -1395,7 +1431,7 @@ var CallManager = class {
|
|
|
1395
1431
|
this.stopEarly(call);
|
|
1396
1432
|
call.early?.close();
|
|
1397
1433
|
call.early = null;
|
|
1398
|
-
|
|
1434
|
+
const closing = call.socket?.close();
|
|
1399
1435
|
if (tell) {
|
|
1400
1436
|
await this.send(call.chat, {
|
|
1401
1437
|
t: "h",
|
|
@@ -1417,6 +1453,7 @@ var CallManager = class {
|
|
|
1417
1453
|
reason,
|
|
1418
1454
|
...call.connectedAt !== null ? { duration: this.now - call.connectedAt } : {}
|
|
1419
1455
|
});
|
|
1456
|
+
if (this.stopping) await closing;
|
|
1420
1457
|
}
|
|
1421
1458
|
/** Refuses a call placed too soon after this side's last unanswered one in the chat (`CALL_PACE_MS`). */
|
|
1422
1459
|
paced(chat) {
|
|
@@ -2946,6 +2983,15 @@ function thaw(bytes) {
|
|
|
2946
2983
|
function handOut(value) {
|
|
2947
2984
|
return value && typeof value === "object" && fresh.delete(value) ? value : structuredClone(value);
|
|
2948
2985
|
}
|
|
2986
|
+
/**
|
|
2987
|
+
* Ends a SQLite transaction that failed. SQLite rolls one back itself on some errors (a full disk): the ROLLBACK then
|
|
2988
|
+
* throws "cannot rollback - no transaction is active", which hid the error that mattered (ENOSPC) from the log.
|
|
2989
|
+
*/
|
|
2990
|
+
function rollback(db) {
|
|
2991
|
+
try {
|
|
2992
|
+
db.exec("ROLLBACK");
|
|
2993
|
+
} catch {}
|
|
2994
|
+
}
|
|
2949
2995
|
/** rows.db's trees: the stores kept on disk and their indexes, each a tree id in `entries`. */
|
|
2950
2996
|
var TreeFile = class {
|
|
2951
2997
|
db;
|
|
@@ -3010,7 +3056,7 @@ var TreeFile = class {
|
|
|
3010
3056
|
this.db.prepare("INSERT OR REPLACE INTO meta (name, value) VALUES ('applied', max(?, coalesce((SELECT value FROM meta WHERE name = 'applied'), 0)))").run(top);
|
|
3011
3057
|
this.db.exec("COMMIT");
|
|
3012
3058
|
} catch (error) {
|
|
3013
|
-
this.db
|
|
3059
|
+
rollback(this.db);
|
|
3014
3060
|
throw error;
|
|
3015
3061
|
}
|
|
3016
3062
|
for (const tree of due) tree.settle(upTo);
|
|
@@ -3035,7 +3081,7 @@ var TreeFile = class {
|
|
|
3035
3081
|
}
|
|
3036
3082
|
this.db.exec("COMMIT");
|
|
3037
3083
|
} catch (error) {
|
|
3038
|
-
this.db
|
|
3084
|
+
rollback(this.db);
|
|
3039
3085
|
throw error;
|
|
3040
3086
|
}
|
|
3041
3087
|
for (const tree of this.live) if (!keep.has(tree.id)) this.live.delete(tree);
|
|
@@ -3578,9 +3624,8 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3578
3624
|
} else {
|
|
3579
3625
|
const ops = pending.get(this._rollbackLog);
|
|
3580
3626
|
if (ops?.length) {
|
|
3581
|
-
const
|
|
3582
|
-
|
|
3583
|
-
append(ops, this.durability === "relaxed", entry);
|
|
3627
|
+
const refused = append(ops, this.durability === "relaxed", ++seq, this._rollbackLog);
|
|
3628
|
+
if (refused) return refuse(this, refused.error, event);
|
|
3584
3629
|
}
|
|
3585
3630
|
}
|
|
3586
3631
|
pending.delete(this._rollbackLog);
|
|
@@ -3602,8 +3647,12 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3602
3647
|
});
|
|
3603
3648
|
return request;
|
|
3604
3649
|
};
|
|
3605
|
-
/**
|
|
3606
|
-
|
|
3650
|
+
/**
|
|
3651
|
+
* A committed transaction's entry, numbered `entry` (its first op says so, where there are trees), from the
|
|
3652
|
+
* transaction whose rollback log is `owner`. Written at once, it may fail (a full disk): the reason is given back,
|
|
3653
|
+
* and the transaction is to be refused, not completed.
|
|
3654
|
+
*/
|
|
3655
|
+
function append(ops, lazy, entry, owner) {
|
|
3607
3656
|
if (trees) ops = [{
|
|
3608
3657
|
db: SEQ,
|
|
3609
3658
|
store: "",
|
|
@@ -3611,15 +3660,42 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3611
3660
|
seq: entry
|
|
3612
3661
|
}, ...ops];
|
|
3613
3662
|
if (queued === 0 && !ops.some((op) => op.kind === "put" && hasBlob(op.value))) {
|
|
3614
|
-
|
|
3615
|
-
|
|
3663
|
+
let done;
|
|
3664
|
+
try {
|
|
3665
|
+
done = writeEntry(serialize(ops), lazy);
|
|
3666
|
+
} catch (error) {
|
|
3667
|
+
return { error };
|
|
3668
|
+
}
|
|
3669
|
+
trees?.complete(owner, entry);
|
|
3670
|
+
if (done) written(entry);
|
|
3671
|
+
return null;
|
|
3616
3672
|
}
|
|
3673
|
+
trees?.complete(owner, entry);
|
|
3617
3674
|
enqueue(async () => {
|
|
3618
3675
|
if (writeEntry(serialize(await Promise.all(ops.map(async (op) => op.kind === "put" ? {
|
|
3619
3676
|
...op,
|
|
3620
3677
|
value: await blobsToDisk(op.value)
|
|
3621
3678
|
} : op))), lazy)) written(entry);
|
|
3622
3679
|
});
|
|
3680
|
+
return null;
|
|
3681
|
+
}
|
|
3682
|
+
/**
|
|
3683
|
+
* A transaction whose entry the disk did not take: what it wrote is undone (as fake-indexeddb's own abort does), and
|
|
3684
|
+
* it ends with an `abort` in place of its `complete`, with a QuotaExceededError, as a browser's out of room does. It
|
|
3685
|
+
* completed, before: the engine answered done for a change that was held but not on disk (a full disk under a
|
|
3686
|
+
* daemon), and a restart lost it.
|
|
3687
|
+
*/
|
|
3688
|
+
function refuse(transaction, error, complete) {
|
|
3689
|
+
failed(error);
|
|
3690
|
+
for (const undo of transaction._rollbackLog.reverse()) undo();
|
|
3691
|
+
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}`;
|
|
3692
|
+
transaction.error = Object.assign(new DOMException(reason, "QuotaExceededError"), { cause: error });
|
|
3693
|
+
const abort = new complete.constructor("abort", {
|
|
3694
|
+
bubbles: true,
|
|
3695
|
+
cancelable: false
|
|
3696
|
+
});
|
|
3697
|
+
abort.eventPath = [transaction.db];
|
|
3698
|
+
return transaction.dispatchEvent(abort);
|
|
3623
3699
|
}
|
|
3624
3700
|
/**
|
|
3625
3701
|
* The journal has entry `entry`: the trees' layers up to it go to SQLite. One that fails stays in memory, where reads
|
|
@@ -3664,7 +3740,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3664
3740
|
indexes.forEach((index, at) => trees.load(ids[at], index.records.values(), true, index.records.keysAreUnique));
|
|
3665
3741
|
trees.db.exec("COMMIT");
|
|
3666
3742
|
} catch (error) {
|
|
3667
|
-
trees.db
|
|
3743
|
+
rollback(trees.db);
|
|
3668
3744
|
throw error;
|
|
3669
3745
|
}
|
|
3670
3746
|
attachTree(store.records, trees.tree(id, true, false), false);
|
|
@@ -3698,20 +3774,24 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3698
3774
|
*/
|
|
3699
3775
|
function writeEntry(entry, lazy = false) {
|
|
3700
3776
|
if (!writing) return false;
|
|
3777
|
+
let whole = -1;
|
|
3701
3778
|
try {
|
|
3702
|
-
if (journalFd === null)
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
}
|
|
3779
|
+
if (journalFd === null) journalFd = openSync(journalPath, "a", 384);
|
|
3780
|
+
whole = fstatSync(journalFd).size;
|
|
3781
|
+
if (snapshotName !== void 0 && whole === 0) writeAll(journalFd, framed(serialize([{
|
|
3782
|
+
db: FOLLOWS,
|
|
3783
|
+
store: "",
|
|
3784
|
+
kind: "clear",
|
|
3785
|
+
snapshot: snapshotName
|
|
3786
|
+
}])));
|
|
3711
3787
|
marked = false;
|
|
3712
3788
|
writeAll(journalFd, framed(entry));
|
|
3789
|
+
if (!lazy) sync();
|
|
3713
3790
|
} catch (error) {
|
|
3714
3791
|
unsaved = true;
|
|
3792
|
+
if (journalFd !== null && whole >= 0) try {
|
|
3793
|
+
ftruncateSync(journalFd, whole);
|
|
3794
|
+
} catch {}
|
|
3715
3795
|
throw error;
|
|
3716
3796
|
}
|
|
3717
3797
|
if (lazy) relaxed ??= setTimeout(() => {
|
|
@@ -3721,7 +3801,6 @@ async function openPersistentIndexedDb(dir, options = {}) {
|
|
|
3721
3801
|
failed(error);
|
|
3722
3802
|
}
|
|
3723
3803
|
}, RELAXED_SYNC_MS).unref();
|
|
3724
|
-
else sync();
|
|
3725
3804
|
if (statSync(journalPath).size > COMPACT_BYTES) enqueue(writeSnapshot);
|
|
3726
3805
|
return true;
|
|
3727
3806
|
}
|
|
@@ -4286,7 +4365,7 @@ function recordsToDisk(trees, db, store, saved, cmp) {
|
|
|
4286
4365
|
}
|
|
4287
4366
|
trees.db.exec("COMMIT");
|
|
4288
4367
|
} catch (error) {
|
|
4289
|
-
trees.db
|
|
4368
|
+
rollback(trees.db);
|
|
4290
4369
|
throw error;
|
|
4291
4370
|
}
|
|
4292
4371
|
}
|
|
@@ -4560,7 +4639,7 @@ function irohRelays(env = process.env) {
|
|
|
4560
4639
|
* profile's own `iceServers` stay.
|
|
4561
4640
|
*/
|
|
4562
4641
|
function publicStun(env = process.env) {
|
|
4563
|
-
return
|
|
4642
|
+
return envSwitch("GHOSTLY_STUN", true, env);
|
|
4564
4643
|
}
|
|
4565
4644
|
/** An RTC configuration without the apps' public STUN servers. */
|
|
4566
4645
|
function withoutPublicStun(config) {
|
|
@@ -4582,7 +4661,7 @@ function withoutPublicStun(config) {
|
|
|
4582
4661
|
* public DHT.
|
|
4583
4662
|
*/
|
|
4584
4663
|
function mainlineNetwork(env = process.env) {
|
|
4585
|
-
if (
|
|
4664
|
+
if (!envSwitch("GHOSTLY_DHT", true, env)) return { off: true };
|
|
4586
4665
|
const bootstrap = (env.GHOSTLY_DHT_BOOTSTRAP ?? "").split(",").map((node) => node.trim()).filter(Boolean);
|
|
4587
4666
|
if (!bootstrap.length && pkarrRelays(env)) return { off: true };
|
|
4588
4667
|
if (!bootstrap.length) return { off: false };
|
|
@@ -4598,7 +4677,7 @@ function mainlineNetwork(env = process.env) {
|
|
|
4598
4677
|
* `GHOSTLY_WEBRTC=0`, the CLI runs without WebRTC and says so.
|
|
4599
4678
|
*/
|
|
4600
4679
|
async function installWebRtc() {
|
|
4601
|
-
if (
|
|
4680
|
+
if (!envSwitch("GHOSTLY_WEBRTC", true)) return false;
|
|
4602
4681
|
try {
|
|
4603
4682
|
const polyfill = await import("node-datachannel/polyfill");
|
|
4604
4683
|
const scope = globalThis;
|
|
@@ -4700,7 +4779,7 @@ async function startRuntime(paths, options = {}) {
|
|
|
4700
4779
|
const restored = join(paths.dir, RESTORED_MARK);
|
|
4701
4780
|
if (existsSync(restored)) {
|
|
4702
4781
|
try {
|
|
4703
|
-
const rows = await import("./restoredRows-
|
|
4782
|
+
const rows = await import("./restoredRows-Fv-MuY45.js");
|
|
4704
4783
|
await rows.markRestoredWallet();
|
|
4705
4784
|
await rows.markLeftOutFiles(leftOutIn(restored));
|
|
4706
4785
|
await store.compact();
|
|
@@ -4718,18 +4797,18 @@ async function startRuntime(paths, options = {}) {
|
|
|
4718
4797
|
if (testMints) (await import("./mints-CqTdA4Gk.js")).declareTestMints(testMints.split(","));
|
|
4719
4798
|
await installEventSource();
|
|
4720
4799
|
await preloadWalletModules();
|
|
4721
|
-
(await import("./ghostly_iroh_web-
|
|
4722
|
-
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-
|
|
4800
|
+
(await import("./ghostly_iroh_web-BXCsSxxo.js")).initSync({ module: irohWasmBytes() });
|
|
4801
|
+
const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-CtwagJ8h.js"), import("./fileBytes-CFNrRfcl.js")]);
|
|
4723
4802
|
registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
|
|
4724
|
-
if (await (await import("./blobFiles-
|
|
4725
|
-
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-
|
|
4803
|
+
if (await (await import("./blobFiles-B6nf0gCG.js")).moveBlobFiles()) await store.compact();
|
|
4804
|
+
const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-DPzt5V2x.js"), import("./endpoint-BdaeBw2L.js")]);
|
|
4726
4805
|
const network = hyperdhtNetwork();
|
|
4727
4806
|
const dht = mainlineNetwork();
|
|
4728
|
-
const mainline = dht.off ? null : new (await (import("./mainline-
|
|
4807
|
+
const mainline = dht.off ? null : new (await (import("./mainline-afyQ77bv.js"))).Mainline({
|
|
4729
4808
|
bootstrap: dht.bootstrap,
|
|
4730
4809
|
host: dht.host
|
|
4731
4810
|
});
|
|
4732
|
-
const transport = mainline || pinned ? new (await (import("./mainline-
|
|
4811
|
+
const transport = mainline || pinned ? new (await (import("./mainline-afyQ77bv.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
|
|
4733
4812
|
const apps = servedApps(paths.dir).length > 0;
|
|
4734
4813
|
const server = new EngineServer({
|
|
4735
4814
|
...transport ? { transport } : {},
|
|
@@ -4741,7 +4820,7 @@ async function startRuntime(paths, options = {}) {
|
|
|
4741
4820
|
fedimintSdk: nodeFedimintSdk(join(paths.dir, "fedimint")),
|
|
4742
4821
|
servicesSupport: true,
|
|
4743
4822
|
apps: apps ? "wire" : false,
|
|
4744
|
-
staysOnline:
|
|
4823
|
+
staysOnline: envSwitch("GHOSTLY_HUB", true),
|
|
4745
4824
|
localFetch: nodeLocalFetch,
|
|
4746
4825
|
pushSend: (request) => nodePushSend(request),
|
|
4747
4826
|
holdFetch: nodeHoldFetch(),
|
|
@@ -5070,4 +5149,4 @@ function connection(ctx, socket, secret) {
|
|
|
5070
5149
|
//#endregion
|
|
5071
5150
|
export { BASELINE_NEWEST, MAX_LINE, MAX_UNREAD, keepServing, openHost, serve };
|
|
5072
5151
|
|
|
5073
|
-
//# sourceMappingURL=host-
|
|
5152
|
+
//# sourceMappingURL=host-AB2Cr46b.js.map
|