engine7 7.1.138 → 7.1.141
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 +3 -1
- package/dist/bg-worker.mjs +134 -128
- package/dist/cli.mjs +4908 -3448
- package/dist/cpu-router-worker.mjs +604 -8
- package/dist/device-connectors/reader +0 -0
- package/dist/engine-startup.mjs +9105 -6642
- package/dist/main.mjs +9082 -6618
- package/dist/optional-deps.json +78 -0
- package/dist/recall-worker.mjs +57 -53
- package/dist/sqlite-maintenance-worker.mjs +16 -18
- package/dist/topics-worker.mjs +56 -52
- package/dist/travel-activation-database.mjs +1077 -0
- package/dist/travel-authority.mjs +46 -25
- package/dist/travel-console.mjs +150 -83
- package/dist/travel-controller.mjs +244 -51
- package/dist/travel-data.mjs +972 -578
- package/dist/travel-gateway.mjs +1529 -745
- package/dist/travel-host.mjs +3970 -3068
- package/dist/travel-initial-baseline.mjs +5959 -0
- package/dist/travel-node-data.mjs +751 -324
- package/dist/travel-node.mjs +2489 -1541
- package/dist/travel-pairing.mjs +1570 -779
- package/dist/travel-resource.mjs +23 -16
- package/dist/travel-retire.mjs +52 -37
- package/dist/web-console.mjs +1972 -320
- package/package.json +13 -8
- package/scripts/verify-cpu-router-package.mjs +14 -1
- package/templates/config.template.json +14 -0
package/dist/travel-resource.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require=(await import('node:module')).createRequire(import.meta.url)
|
|
2
2
|
|
|
3
3
|
// src/continuity/resource-main.ts
|
|
4
|
-
import { readFileSync as
|
|
4
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
5
5
|
import { resolve as resolve2 } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
@@ -29,8 +29,8 @@ function readPrivateFile(path, maximumBytes = 65536) {
|
|
|
29
29
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
30
30
|
import { createHash } from "node:crypto";
|
|
31
31
|
import { existsSync } from "node:fs";
|
|
32
|
-
import { lstatSync as lstatSync3, readdirSync, readFileSync as
|
|
33
|
-
import { isAbsolute, join, resolve, relative } from "node:path";
|
|
32
|
+
import { accessSync, constants as constants3, lstatSync as lstatSync3, readdirSync, readFileSync as readFileSync2, readlinkSync, realpathSync as realpathSync2, rmSync } from "node:fs";
|
|
33
|
+
import { dirname, isAbsolute, join, resolve, relative } from "node:path";
|
|
34
34
|
|
|
35
35
|
// src/continuity/publication-objects.ts
|
|
36
36
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
@@ -41,17 +41,13 @@ import {
|
|
|
41
41
|
fstatSync as fstatSync2,
|
|
42
42
|
fsyncSync as fsyncSync2,
|
|
43
43
|
readSync,
|
|
44
|
-
writeSync as writeSync2,
|
|
45
44
|
lstatSync as lstatSync2,
|
|
46
45
|
realpathSync,
|
|
47
|
-
mkdirSync as mkdirSync2
|
|
48
|
-
readFileSync as readFileSync2,
|
|
49
|
-
writeFileSync,
|
|
50
|
-
linkSync,
|
|
51
|
-
unlinkSync as unlinkSync2
|
|
46
|
+
mkdirSync as mkdirSync2
|
|
52
47
|
} from "node:fs";
|
|
53
48
|
var PUBLICATION_CHUNK_BYTES = 1024 * 1024;
|
|
54
49
|
var MAGIC = Buffer.from("E7P1");
|
|
50
|
+
var INLINE_BYTES = 64 * 1024;
|
|
55
51
|
var noFollow = constants2.O_NOFOLLOW ?? 0;
|
|
56
52
|
|
|
57
53
|
// src/continuity/retirement.ts
|
|
@@ -85,19 +81,29 @@ var LocalSeatResource = class {
|
|
|
85
81
|
else if (item.isDirectory()) visit(path);
|
|
86
82
|
else if (item.isFile()) {
|
|
87
83
|
if (item.name === ".travel-seat-resource.json" && identity(JSON.parse(readPrivateFile(path, 65536).toString())) !== identity(this.identity)) throw new Error("TRAVEL_RETIREMENT_IDENTITY");
|
|
88
|
-
result.push({ version, digest: sha(
|
|
84
|
+
result.push({ version, digest: sha(readFileSync2(path)) });
|
|
89
85
|
} else throw new Error("TRAVEL_RETIREMENT_PATH");
|
|
90
86
|
if (result.length > 1e6) throw new Error("TRAVEL_RETIREMENT_BUDGET");
|
|
91
87
|
}
|
|
92
88
|
};
|
|
93
89
|
visit(this.path);
|
|
94
|
-
return result;
|
|
90
|
+
return result.length === 1 && result[0].version === ".travel-seat-resource.json" ? [] : result;
|
|
95
91
|
}
|
|
96
92
|
async purge(expectedInventory) {
|
|
97
93
|
const allowed = new Map(expectedInventory.map((item) => [item.version, item.digest]));
|
|
98
94
|
if (this.inventoryNow().some((item) => allowed.get(item.version) !== item.digest)) throw new Error("TRAVEL_RETIREMENT_RESOURCE_CHANGED");
|
|
99
|
-
if (this.check())
|
|
100
|
-
|
|
95
|
+
if (this.check()) {
|
|
96
|
+
let removeRoot = true;
|
|
97
|
+
try {
|
|
98
|
+
accessSync(dirname(this.path), constants3.W_OK);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error.code !== "EACCES") throw error;
|
|
101
|
+
removeRoot = false;
|
|
102
|
+
}
|
|
103
|
+
if (removeRoot) rmSync(this.path, { recursive: true });
|
|
104
|
+
else for (const name of readdirSync(this.path)) if (name !== ".travel-seat-resource.json") rmSync(join(this.path, name), { recursive: true });
|
|
105
|
+
}
|
|
106
|
+
if (this.inventoryNow().length) throw new Error("TRAVEL_RETIREMENT_PENDING");
|
|
101
107
|
}
|
|
102
108
|
};
|
|
103
109
|
|
|
@@ -108,15 +114,16 @@ async function runSeatResourceCli(args) {
|
|
|
108
114
|
const config = JSON.parse(readPrivateFile(resolve2(args[2]), 65536).toString());
|
|
109
115
|
const resource = new LocalSeatResource(config.directory, config.identity);
|
|
110
116
|
if (args[0] === "inventory") return resource.inventory();
|
|
111
|
-
const input =
|
|
117
|
+
const input = readFileSync3(0);
|
|
112
118
|
if (input.length > 64 * 1024 * 1024) throw new Error("TRAVEL_RETIREMENT_BUDGET");
|
|
113
119
|
const inventory = JSON.parse(input.toString());
|
|
114
120
|
if (!Array.isArray(inventory) || inventory.length > 1e6 || inventory.some((row) => !row || typeof row.version !== "string" || typeof row.digest !== "string" || !/^[a-f0-9]{64}$/.test(row.digest))) throw new Error("TRAVEL_RETIREMENT_REQUEST");
|
|
115
121
|
await resource.purge(inventory);
|
|
116
122
|
return { purged: true };
|
|
117
123
|
}
|
|
118
|
-
if (process.argv[1] && /[\/](resource-main\.ts|travel-resource\.mjs)$/.test(process.argv[1]) && resolve2(process.argv[1]) === fileURLToPath(import.meta.url)) runSeatResourceCli(process.argv.slice(2)).then((value) => process.stdout.write(JSON.stringify(value) + "\n")).catch(() => {
|
|
119
|
-
|
|
124
|
+
if (process.argv[1] && /[\/](resource-main\.ts|travel-resource\.mjs)$/.test(process.argv[1]) && resolve2(process.argv[1]) === fileURLToPath(import.meta.url)) runSeatResourceCli(process.argv.slice(2)).then((value) => process.stdout.write(JSON.stringify(value) + "\n")).catch((error) => {
|
|
125
|
+
const reason = error instanceof Error && /^TRAVEL_[A-Z_]+$/.test(error.message) ? error.message : ["EACCES", "EPERM", "ENOENT", "ENOSPC", "EIO"].includes(error?.code) ? error.code : "REFUSED";
|
|
126
|
+
process.stderr.write("TRAVEL_RETIREMENT_RESOURCE_REFUSED " + reason + "\n");
|
|
120
127
|
process.exitCode = 1;
|
|
121
128
|
});
|
|
122
129
|
export {
|
package/dist/travel-retire.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require=(await import('node:module')).createRequire(import.meta.url)
|
|
2
2
|
|
|
3
3
|
// src/continuity/retirement-main.ts
|
|
4
|
-
import { readFileSync as
|
|
4
|
+
import { readFileSync as readFileSync5, existsSync as existsSync3 } from "node:fs";
|
|
5
5
|
import { isAbsolute as isAbsolute4, resolve as resolve5 } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { execFile } from "node:child_process";
|
|
@@ -27,11 +27,13 @@ var UserSeatResource = class {
|
|
|
27
27
|
return new Promise((done, reject) => {
|
|
28
28
|
const child = spawn("/usr/bin/sudo", ["-n", "/usr/sbin/runuser", "-u", this.config.runAs.user, "--", this.config.runAs.node, this.config.runAs.entry, action, "--config", this.config.runAs.configFile], { stdio: ["pipe", "pipe", "pipe"] });
|
|
29
29
|
const chunks = [];
|
|
30
|
-
let bytes = 0;
|
|
30
|
+
let bytes = 0, stderr = "";
|
|
31
31
|
const timer = setTimeout(() => child.kill("SIGKILL"), 12e4);
|
|
32
32
|
child.stdin.on("error", () => {
|
|
33
33
|
});
|
|
34
|
-
child.stderr.
|
|
34
|
+
child.stderr.on("data", (chunk) => {
|
|
35
|
+
stderr = (stderr + chunk.toString()).slice(-4096);
|
|
36
|
+
});
|
|
35
37
|
child.stdout.on("data", (chunk) => {
|
|
36
38
|
bytes += chunk.length;
|
|
37
39
|
if (bytes > 64 * 1024 * 1024) child.kill("SIGKILL");
|
|
@@ -41,7 +43,9 @@ var UserSeatResource = class {
|
|
|
41
43
|
child.once("close", (code) => {
|
|
42
44
|
clearTimeout(timer);
|
|
43
45
|
if (code !== 0) {
|
|
44
|
-
|
|
46
|
+
const reason = stderr.match(/TRAVEL_RETIREMENT_RESOURCE_REFUSED ([A-Z][A-Z0-9_]{0,95})(?:\s|$)/)?.[1];
|
|
47
|
+
if (reason) process.stderr.write("[travel-retirement-resource] " + JSON.stringify({ action, reason }) + "\n");
|
|
48
|
+
reject(new Error(reason?.startsWith("TRAVEL_") ? reason : "TRAVEL_RETIREMENT_PROVIDER_PENDING"));
|
|
45
49
|
return;
|
|
46
50
|
}
|
|
47
51
|
try {
|
|
@@ -67,8 +71,8 @@ var UserSeatResource = class {
|
|
|
67
71
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
68
72
|
import { createHash as createHash2 } from "node:crypto";
|
|
69
73
|
import { existsSync } from "node:fs";
|
|
70
|
-
import { lstatSync as lstatSync3, readdirSync, readFileSync as
|
|
71
|
-
import { isAbsolute as isAbsolute2, join as join3, resolve as resolve3, relative } from "node:path";
|
|
74
|
+
import { accessSync, constants as constants3, lstatSync as lstatSync3, readdirSync, readFileSync as readFileSync2, readlinkSync, realpathSync as realpathSync2, rmSync } from "node:fs";
|
|
75
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, join as join3, resolve as resolve3, relative } from "node:path";
|
|
72
76
|
|
|
73
77
|
// src/continuity/publication-objects.ts
|
|
74
78
|
import { DatabaseSync } from "node:sqlite";
|
|
@@ -79,18 +83,14 @@ import {
|
|
|
79
83
|
fstatSync,
|
|
80
84
|
fsyncSync,
|
|
81
85
|
readSync,
|
|
82
|
-
writeSync,
|
|
83
86
|
lstatSync,
|
|
84
87
|
realpathSync,
|
|
85
|
-
mkdirSync
|
|
86
|
-
readFileSync,
|
|
87
|
-
writeFileSync,
|
|
88
|
-
linkSync,
|
|
89
|
-
unlinkSync
|
|
88
|
+
mkdirSync
|
|
90
89
|
} from "node:fs";
|
|
91
90
|
import { join, dirname, resolve as resolve2 } from "node:path";
|
|
92
91
|
var PUBLICATION_CHUNK_BYTES = 1024 * 1024;
|
|
93
92
|
var MAGIC = Buffer.from("E7P1");
|
|
93
|
+
var INLINE_BYTES = 64 * 1024;
|
|
94
94
|
var noFollow = constants.O_NOFOLLOW ?? 0;
|
|
95
95
|
function assertPrivateDirectory(path2) {
|
|
96
96
|
const info = lstatSync(path2);
|
|
@@ -155,7 +155,7 @@ function preparePrivateDatabase(path2) {
|
|
|
155
155
|
|
|
156
156
|
// src/continuity/key-service-store.ts
|
|
157
157
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
158
|
-
import { constants as constants2, lstatSync as lstatSync2, mkdirSync as mkdirSync2, openSync as openSync2, closeSync as closeSync2, readFileSync
|
|
158
|
+
import { constants as constants2, lstatSync as lstatSync2, mkdirSync as mkdirSync2, openSync as openSync2, closeSync as closeSync2, readFileSync, writeSync, fstatSync as fstatSync2, fsyncSync as fsyncSync2, unlinkSync } from "node:fs";
|
|
159
159
|
import { join as join2 } from "node:path";
|
|
160
160
|
import { randomUUID } from "node:crypto";
|
|
161
161
|
function validateKeyIdentity(value) {
|
|
@@ -190,7 +190,7 @@ function readPrivateFile(path2, maximumBytes = 65536) {
|
|
|
190
190
|
const stat = fstatSync2(fd);
|
|
191
191
|
assertPrivateStat(stat, false);
|
|
192
192
|
if (stat.size > maximumBytes) throw new Error("KEY_SERVICE_INVALID_FILE_SIZE");
|
|
193
|
-
return
|
|
193
|
+
return readFileSync(fd);
|
|
194
194
|
} finally {
|
|
195
195
|
closeSync2(fd);
|
|
196
196
|
}
|
|
@@ -254,11 +254,11 @@ var KeyServiceStore = class {
|
|
|
254
254
|
const fd = openSync2(path2, constants2.O_WRONLY | constants2.O_CREAT | constants2.O_EXCL, 384);
|
|
255
255
|
try {
|
|
256
256
|
let written = 0;
|
|
257
|
-
while (written < key.byteLength) written +=
|
|
257
|
+
while (written < key.byteLength) written += writeSync(fd, key, written, key.byteLength - written);
|
|
258
258
|
fsyncSync2(fd);
|
|
259
259
|
} catch (error) {
|
|
260
260
|
closeSync2(fd);
|
|
261
|
-
|
|
261
|
+
unlinkSync(path2);
|
|
262
262
|
throw error;
|
|
263
263
|
}
|
|
264
264
|
closeSync2(fd);
|
|
@@ -273,7 +273,7 @@ var KeyServiceStore = class {
|
|
|
273
273
|
try {
|
|
274
274
|
this.db.prepare("INSERT INTO seat_keys(key_id,identity,secret_file,state) VALUES(?,?,?,'active')").run(identity3.keyId, text, filename);
|
|
275
275
|
} catch (error) {
|
|
276
|
-
|
|
276
|
+
unlinkSync(path2);
|
|
277
277
|
throw error;
|
|
278
278
|
}
|
|
279
279
|
});
|
|
@@ -350,7 +350,7 @@ var KeyServiceStore = class {
|
|
|
350
350
|
const file = join2(this.secrets, filename);
|
|
351
351
|
try {
|
|
352
352
|
assertPrivateStat(lstatSync2(file), false);
|
|
353
|
-
|
|
353
|
+
unlinkSync(file);
|
|
354
354
|
} catch (error) {
|
|
355
355
|
if (error.code !== "ENOENT") throw error;
|
|
356
356
|
}
|
|
@@ -411,19 +411,29 @@ var LocalSeatResource = class {
|
|
|
411
411
|
else if (item.isDirectory()) visit(path2);
|
|
412
412
|
else if (item.isFile()) {
|
|
413
413
|
if (item.name === ".travel-seat-resource.json" && identity(JSON.parse(readPrivateFile(path2, 65536).toString())) !== identity(this.identity)) throw new Error("TRAVEL_RETIREMENT_IDENTITY");
|
|
414
|
-
result.push({ version, digest: sha(
|
|
414
|
+
result.push({ version, digest: sha(readFileSync2(path2)) });
|
|
415
415
|
} else throw new Error("TRAVEL_RETIREMENT_PATH");
|
|
416
416
|
if (result.length > 1e6) throw new Error("TRAVEL_RETIREMENT_BUDGET");
|
|
417
417
|
}
|
|
418
418
|
};
|
|
419
419
|
visit(this.path);
|
|
420
|
-
return result;
|
|
420
|
+
return result.length === 1 && result[0].version === ".travel-seat-resource.json" ? [] : result;
|
|
421
421
|
}
|
|
422
422
|
async purge(expectedInventory) {
|
|
423
423
|
const allowed = new Map(expectedInventory.map((item) => [item.version, item.digest]));
|
|
424
424
|
if (this.inventoryNow().some((item) => allowed.get(item.version) !== item.digest)) throw new Error("TRAVEL_RETIREMENT_RESOURCE_CHANGED");
|
|
425
|
-
if (this.check())
|
|
426
|
-
|
|
425
|
+
if (this.check()) {
|
|
426
|
+
let removeRoot = true;
|
|
427
|
+
try {
|
|
428
|
+
accessSync(dirname2(this.path), constants3.W_OK);
|
|
429
|
+
} catch (error) {
|
|
430
|
+
if (error.code !== "EACCES") throw error;
|
|
431
|
+
removeRoot = false;
|
|
432
|
+
}
|
|
433
|
+
if (removeRoot) rmSync(this.path, { recursive: true });
|
|
434
|
+
else for (const name of readdirSync(this.path)) if (name !== ".travel-seat-resource.json") rmSync(join3(this.path, name), { recursive: true });
|
|
435
|
+
}
|
|
436
|
+
if (this.inventoryNow().length) throw new Error("TRAVEL_RETIREMENT_PENDING");
|
|
427
437
|
}
|
|
428
438
|
};
|
|
429
439
|
var TravelRetirement = class {
|
|
@@ -509,7 +519,8 @@ var TravelRetirement = class {
|
|
|
509
519
|
row = this.db.prepare("SELECT * FROM resources WHERE id=?").get(resource.id);
|
|
510
520
|
}
|
|
511
521
|
const original = JSON.parse(String(row.inventory));
|
|
512
|
-
|
|
522
|
+
const allowed = new Map(original.map((item) => [item.version, item.digest]));
|
|
523
|
+
if (current.some((item) => allowed.get(item.version) !== item.digest)) throw new Error("TRAVEL_RETIREMENT_RESOURCE_CHANGED");
|
|
513
524
|
await verifyRecovery(true);
|
|
514
525
|
await resource.purge(original);
|
|
515
526
|
if ((await resource.inventory()).length) throw new Error("TRAVEL_RETIREMENT_PROVIDER_PENDING");
|
|
@@ -535,15 +546,15 @@ var TravelRetirement = class {
|
|
|
535
546
|
};
|
|
536
547
|
|
|
537
548
|
// src/continuity/local-exit.ts
|
|
538
|
-
import { cpSync, existsSync as existsSync2, mkdirSync as mkdirSync5, readFileSync as
|
|
549
|
+
import { cpSync, existsSync as existsSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync4, readdirSync as readdirSync3, realpathSync as realpathSync4, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
539
550
|
import { DatabaseSync as DatabaseSync5 } from "node:sqlite";
|
|
540
|
-
import { isAbsolute as isAbsolute3, join as join6, dirname as
|
|
551
|
+
import { isAbsolute as isAbsolute3, join as join6, dirname as dirname4, resolve as resolve4 } from "node:path";
|
|
541
552
|
import { createHash as createHash5, verify as verify2 } from "node:crypto";
|
|
542
553
|
|
|
543
554
|
// src/continuity/runtime-lock.ts
|
|
544
555
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
545
556
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
546
|
-
import { closeSync as closeSync3, lstatSync as lstatSync4, mkdirSync as mkdirSync3, openSync as openSync3, readFileSync as
|
|
557
|
+
import { closeSync as closeSync3, lstatSync as lstatSync4, mkdirSync as mkdirSync3, openSync as openSync3, readFileSync as readFileSync3, realpathSync as realpathSync3 } from "node:fs";
|
|
547
558
|
import { join as join4 } from "node:path";
|
|
548
559
|
import { createRequire } from "node:module";
|
|
549
560
|
var sqlite;
|
|
@@ -618,7 +629,7 @@ async function withCheckpointLock(stateDir, operation) {
|
|
|
618
629
|
for (const name of [".engine.pid", ".bg-worker.pid"]) {
|
|
619
630
|
let value;
|
|
620
631
|
try {
|
|
621
|
-
value =
|
|
632
|
+
value = readFileSync3(join4(stateDir, name), "utf8").trim();
|
|
622
633
|
} catch (error) {
|
|
623
634
|
if (error.code === "ENOENT") continue;
|
|
624
635
|
throw new Error("WRITER_STATE_UNKNOWN", { cause: error });
|
|
@@ -641,14 +652,14 @@ async function withCheckpointLock(stateDir, operation) {
|
|
|
641
652
|
// src/continuity/local-dedupe.ts
|
|
642
653
|
import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
|
|
643
654
|
import { createHash as createHash3 } from "node:crypto";
|
|
644
|
-
import { dirname as
|
|
655
|
+
import { dirname as dirname3 } from "node:path";
|
|
645
656
|
var sha2 = (value) => createHash3("sha256").update(value).digest("hex");
|
|
646
657
|
var hash = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
647
658
|
var PlatformReceiptStore = class {
|
|
648
659
|
db;
|
|
649
660
|
constructor(file, namespace) {
|
|
650
661
|
if (!namespace || namespace.length > 1024) throw new Error("PLATFORM_RECEIPT_IDENTITY");
|
|
651
|
-
preparePrivateDirectory(
|
|
662
|
+
preparePrivateDirectory(dirname3(file));
|
|
652
663
|
preparePrivateDatabase(file);
|
|
653
664
|
this.db = new DatabaseSync4(file);
|
|
654
665
|
try {
|
|
@@ -709,7 +720,7 @@ var PlatformReceiptStore = class {
|
|
|
709
720
|
|
|
710
721
|
// src/continuity/local-exit-proof.ts
|
|
711
722
|
import { createHash as createHash4, verify } from "node:crypto";
|
|
712
|
-
import { createReadStream, mkdirSync as mkdirSync4, readdirSync as readdirSync2, writeFileSync
|
|
723
|
+
import { createReadStream, mkdirSync as mkdirSync4, readdirSync as readdirSync2, writeFileSync } from "node:fs";
|
|
713
724
|
import { join as join5, relative as relative2 } from "node:path";
|
|
714
725
|
var hash2 = (value) => createHash4("sha256").update(value).digest("hex");
|
|
715
726
|
var equal = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
@@ -798,8 +809,8 @@ function detachReplication(directory) {
|
|
|
798
809
|
}
|
|
799
810
|
async function createOrdinaryLocalRecovery(options) {
|
|
800
811
|
const source = resolve4(options.stateDir), destination = resolve4(options.destination);
|
|
801
|
-
if (!isAbsolute3(options.destination) || source !== options.stateDir || destination !== options.destination || realpathSync4(source) !== source || destination === source || destination.startsWith(source + "/") || source.startsWith(destination + "/") || realpathSync4(
|
|
802
|
-
const activation = JSON.parse(
|
|
812
|
+
if (!isAbsolute3(options.destination) || source !== options.stateDir || destination !== options.destination || realpathSync4(source) !== source || destination === source || destination.startsWith(source + "/") || source.startsWith(destination + "/") || realpathSync4(dirname4(destination)) !== dirname4(destination)) throw new Error("TRAVEL_EXIT_PATH");
|
|
813
|
+
const activation = JSON.parse(readFileSync4(join6(source, ".travel-active.json"), "utf8")), permit = activation.permit, { signature, ...signed } = permit;
|
|
803
814
|
if (activation.format !== "engine7-runtime-activation-v1" || identity2(activation.identity) !== identity2(options.identity) || identity2(permit) !== identity2(options.identity) || permit.nodeId !== options.localNodeId || activation.nodeId !== options.localNodeId || !verify2(null, Buffer.from(JSON.stringify(signed)), options.publicKey, Buffer.from(signature, "base64")) || identity2(options.dedupeReceipt.identity) !== identity2(options.identity) || options.dedupeReceipt.checkpointDigest !== options.checkpointDigest || options.dedupeReceipt.deletionWatermark !== permit.deletionWatermark) throw new Error("TRAVEL_EXIT_RECOVERY_REQUIRED");
|
|
804
815
|
return withCheckpointLock(source, async () => {
|
|
805
816
|
if (!options.authority || !options.principal || options.authority.publicKey !== options.publicKey) throw new Error("TRAVEL_EXIT_RECOVERY_REQUIRED");
|
|
@@ -841,7 +852,7 @@ async function createOrdinaryLocalRecovery(options) {
|
|
|
841
852
|
await proof.check();
|
|
842
853
|
const body = { ...receipt, ordinaryFilesDigest: await localExitFilesDigest(destination, true) };
|
|
843
854
|
const result = { ...body, digest: sha3(JSON.stringify(body)) };
|
|
844
|
-
|
|
855
|
+
writeFileSync2(join6(destination, ".continuity/travel-exit-receipt.json"), JSON.stringify(result), { mode: 384, flag: "wx", flush: true });
|
|
845
856
|
return result;
|
|
846
857
|
} catch (error) {
|
|
847
858
|
if (existsSync2(destination)) rmSync2(destination, { recursive: true });
|
|
@@ -887,9 +898,12 @@ var TravelReportClient = class {
|
|
|
887
898
|
this.timeout = options.timeoutMs ?? 8e3;
|
|
888
899
|
if (!Number.isSafeInteger(this.timeout) || this.timeout < 1 || this.timeout > 6e4) throw new Error("TRAVEL_CONTROL_INVALID_CONFIG");
|
|
889
900
|
this.key = options.key ? Buffer.from(options.key) : void 0;
|
|
890
|
-
|
|
901
|
+
const tls = { ca: options.ca, cert: options.cert, key: this.key, minVersion: "TLSv1.3", rejectUnauthorized: true, maxSockets: 1 };
|
|
902
|
+
this.agent = new Agent({ ...tls, keepAlive: true });
|
|
903
|
+
this.mutationAgent = new Agent({ ...tls, keepAlive: false });
|
|
891
904
|
}
|
|
892
905
|
agent;
|
|
906
|
+
mutationAgent;
|
|
893
907
|
key;
|
|
894
908
|
url;
|
|
895
909
|
timeout;
|
|
@@ -916,7 +930,7 @@ var TravelReportClient = class {
|
|
|
916
930
|
if (error) reject(error);
|
|
917
931
|
else resolve6(value);
|
|
918
932
|
};
|
|
919
|
-
const req = request(this.url, { method: "POST", agent: this.agent, headers: {
|
|
933
|
+
const req = request(this.url, { method: "POST", agent: readActions.has(input?.action) ? this.agent : this.mutationAgent, headers: {
|
|
920
934
|
Authorization: "Bearer " + this.options.credential,
|
|
921
935
|
"X-Engine7-Travel-Node": this.options.nodeId,
|
|
922
936
|
"Content-Type": "application/json",
|
|
@@ -991,6 +1005,7 @@ var TravelReportClient = class {
|
|
|
991
1005
|
this.closed = true;
|
|
992
1006
|
for (const req of this.pending) req.destroy();
|
|
993
1007
|
this.agent.destroy();
|
|
1008
|
+
this.mutationAgent.destroy();
|
|
994
1009
|
this.key?.fill(0);
|
|
995
1010
|
}
|
|
996
1011
|
};
|
|
@@ -1085,7 +1100,7 @@ async function runTravelRetirementCli(args) {
|
|
|
1085
1100
|
if (args.length !== 3 || !["run", "recover-local"].includes(args[0]) || args[1] !== "--config") throw new Error("TRAVEL_RETIREMENT_INVALID_COMMAND");
|
|
1086
1101
|
const config = JSON.parse(readPrivateFile(path(args[2]), 4 * 1024 * 1024).toString());
|
|
1087
1102
|
if (args[0] === "recover-local") {
|
|
1088
|
-
const client2 = new TravelManagementClient({ ...config.control, ca:
|
|
1103
|
+
const client2 = new TravelManagementClient({ ...config.control, ca: readFileSync5(path(config.tls.caFile)), cert: readFileSync5(path(config.tls.certFile)), key: readPrivateFile(path(config.tls.keyFile), 65536) });
|
|
1089
1104
|
try {
|
|
1090
1105
|
const { principal, publicKey } = await client2.retirementStatus();
|
|
1091
1106
|
if (publicKey !== config.publicKey) throw new Error("TRAVEL_EXIT_RECOVERY_REQUIRED");
|
|
@@ -1100,7 +1115,7 @@ async function runTravelRetirementCli(args) {
|
|
|
1100
1115
|
}
|
|
1101
1116
|
if (!Array.isArray(config.resources) || !Array.isArray(config.stopServices) || config.stopServices.some((service) => typeof service !== "string" || !/^engine7-travel[-a-zA-Z0-9_.@]+\.service$/.test(service))) throw new Error("TRAVEL_RETIREMENT_CONFIG");
|
|
1102
1117
|
if (!config.stopServices.length && config.nodesAlreadyStopped !== true) throw new Error("TRAVEL_RETIREMENT_STOP_REQUIRED");
|
|
1103
|
-
const client = new TravelManagementClient({ ...config.control, ca:
|
|
1118
|
+
const client = new TravelManagementClient({ ...config.control, ca: readFileSync5(path(config.tls.caFile)), cert: readFileSync5(path(config.tls.certFile)), key: readPrivateFile(path(config.tls.keyFile), 65536) });
|
|
1104
1119
|
let job, keys;
|
|
1105
1120
|
try {
|
|
1106
1121
|
const control = await client.retirementStatus();
|