@serfab/cadre-host 1.13.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +332 -423
- package/dist/bin/host.d.ts +6 -3
- package/dist/bin/host.js +301 -505
- package/dist/bin/host.js.map +1 -1
- package/dist/bin/join-output.d.ts +56 -0
- package/dist/bin/join-output.js +92 -0
- package/dist/bin/join-output.js.map +1 -0
- package/dist/bin/nat-output.d.ts +49 -0
- package/dist/bin/nat-output.js +127 -0
- package/dist/bin/nat-output.js.map +1 -0
- package/dist/hosted/claim-details.d.ts +44 -0
- package/dist/hosted/claim-details.js +66 -0
- package/dist/hosted/claim-details.js.map +1 -0
- package/dist/hosted/hosted-node-service.d.ts +318 -0
- package/dist/hosted/hosted-node-service.js +666 -0
- package/dist/hosted/hosted-node-service.js.map +1 -0
- package/dist/hosted/hosted-node-store.d.ts +40 -0
- package/dist/hosted/hosted-node-store.js +126 -0
- package/dist/hosted/hosted-node-store.js.map +1 -0
- package/dist/{donation/donation-supervisor.d.ts → hosted/hosted-node-supervisor.d.ts} +70 -53
- package/dist/hosted/hosted-node-supervisor.js +396 -0
- package/dist/hosted/hosted-node-supervisor.js.map +1 -0
- package/dist/hosted/hosted-node-watcher.d.ts +83 -0
- package/dist/hosted/hosted-node-watcher.js +224 -0
- package/dist/hosted/hosted-node-watcher.js.map +1 -0
- package/dist/hosted/index.d.ts +16 -0
- package/dist/hosted/index.js +13 -0
- package/dist/hosted/index.js.map +1 -0
- package/dist/hosted/node-status.d.ts +35 -0
- package/dist/hosted/node-status.js +61 -0
- package/dist/hosted/node-status.js.map +1 -0
- package/dist/hosted/types.d.ts +134 -0
- package/dist/hosted/types.js +22 -0
- package/dist/hosted/types.js.map +1 -0
- package/dist/index.d.ts +12 -24
- package/dist/index.js +9 -19
- package/dist/index.js.map +1 -1
- package/dist/installer/config.d.ts +4 -34
- package/dist/installer/config.js +3 -18
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/index.d.ts +7 -19
- package/dist/installer/index.js +14 -69
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/paths.d.ts +0 -2
- package/dist/installer/paths.js +0 -4
- package/dist/installer/paths.js.map +1 -1
- package/dist/installer/wizard.d.ts +0 -7
- package/dist/installer/wizard.js +1 -8
- package/dist/installer/wizard.js.map +1 -1
- package/dist/nat/address-resolver.d.ts +18 -17
- package/dist/nat/address-resolver.js +79 -25
- package/dist/nat/address-resolver.js.map +1 -1
- package/dist/nat/address-watch.d.ts +37 -0
- package/dist/nat/address-watch.js +84 -0
- package/dist/nat/address-watch.js.map +1 -0
- package/dist/nat/ddns/duckdns.d.ts +2 -1
- package/dist/nat/ddns/duckdns.js +5 -1
- package/dist/nat/ddns/duckdns.js.map +1 -1
- package/dist/nat/ddns/index.d.ts +6 -0
- package/dist/nat/ddns/index.js.map +1 -1
- package/dist/nat/index.d.ts +12 -9
- package/dist/nat/index.js +6 -5
- package/dist/nat/index.js.map +1 -1
- package/dist/nat/nat-service.d.ts +203 -77
- package/dist/nat/nat-service.js +602 -237
- package/dist/nat/nat-service.js.map +1 -1
- package/dist/nat/nat-store.d.ts +12 -5
- package/dist/nat/nat-store.js +114 -30
- package/dist/nat/nat-store.js.map +1 -1
- package/dist/nat/port-mapper.d.ts +83 -79
- package/dist/nat/port-mapper.js +148 -189
- package/dist/nat/port-mapper.js.map +1 -1
- package/dist/nat/reachability.d.ts +31 -15
- package/dist/nat/reachability.js +97 -22
- package/dist/nat/reachability.js.map +1 -1
- package/dist/nat/types.d.ts +78 -27
- package/dist/nat/types.js +8 -5
- package/dist/nat/types.js.map +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +29 -71
- package/dist/orchestrator/host-process-orchestrator.js +78 -218
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/{installer/identity.d.ts → orchestrator/identity-file.d.ts} +5 -5
- package/dist/{installer/identity.js → orchestrator/identity-file.js} +6 -6
- package/dist/orchestrator/identity-file.js.map +1 -0
- package/dist/orchestrator/index.d.ts +2 -3
- package/dist/orchestrator/index.js +1 -1
- package/dist/orchestrator/index.js.map +1 -1
- package/dist/orchestrator/node-identity.d.ts +6 -6
- package/dist/orchestrator/node-identity.js +7 -7
- package/dist/orchestrator/node-identity.js.map +1 -1
- package/dist/orchestrator/port-allocator.d.ts +5 -6
- package/dist/orchestrator/port-allocator.js +9 -11
- package/dist/orchestrator/port-allocator.js.map +1 -1
- package/dist/orchestrator/state-store.d.ts +3 -5
- package/dist/orchestrator/state-store.js +2 -10
- package/dist/orchestrator/state-store.js.map +1 -1
- package/dist/orchestrator/types.d.ts +33 -22
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/server/error-handler.d.ts +5 -25
- package/dist/server/error-handler.js +11 -74
- package/dist/server/error-handler.js.map +1 -1
- package/dist/server/events/types.d.ts +7 -11
- package/dist/server/events/types.js +2 -1
- package/dist/server/events/types.js.map +1 -1
- package/dist/server/index.d.ts +11 -37
- package/dist/server/index.js +30 -48
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes/hosted-nodes.d.ts +28 -0
- package/dist/server/routes/hosted-nodes.js +68 -0
- package/dist/server/routes/hosted-nodes.js.map +1 -0
- package/dist/server/routes/nat.d.ts +4 -1
- package/dist/server/routes/nat.js +13 -2
- package/dist/server/routes/nat.js.map +1 -1
- package/dist/server/routes/nodes.d.ts +6 -20
- package/dist/server/routes/nodes.js +7 -86
- package/dist/server/routes/nodes.js.map +1 -1
- package/dist/server/routes/settings.d.ts +2 -7
- package/dist/server/routes/settings.js +3 -7
- package/dist/server/routes/settings.js.map +1 -1
- package/dist/server/routes/status.d.ts +2 -25
- package/dist/server/routes/status.js +1 -11
- package/dist/server/routes/status.js.map +1 -1
- package/dist/server/server.js +8 -8
- package/dist/server/settings-store.d.ts +2 -2
- package/dist/server/settings-store.js +2 -2
- package/dist/server/static.js +1 -2
- package/dist/server/static.js.map +1 -1
- package/dist/ui/assets/index-4FWuU8ye.js +19 -0
- package/dist/ui/assets/index-4FWuU8ye.js.map +1 -0
- package/dist/ui/assets/index-Di9Q4d01.css +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/update/index.d.ts +2 -2
- package/dist/update/index.js +2 -2
- package/dist/update/store.d.ts +1 -1
- package/dist/update/store.js +1 -1
- package/dist/update/types.d.ts +1 -1
- package/dist/update/types.js +1 -1
- package/package.json +5 -6
- package/src/__tests__/cli-nat.smoke.test.ts +219 -212
- package/src/__tests__/cli.smoke.test.ts +1 -1
- package/src/__tests__/global-setup.ts +2 -3
- package/src/__tests__/orchestrator-claim-secret.test.ts +112 -0
- package/src/__tests__/orchestrator-handle-contract.ts +134 -134
- package/src/__tests__/orchestrator-node-identity.test.ts +182 -203
- package/src/__tests__/orchestrator-ports.test.ts +124 -143
- package/src/__tests__/orchestrator-push.test.ts +138 -146
- package/src/__tests__/orchestrator.test.ts +1019 -1063
- package/src/bin/host.ts +368 -553
- package/src/bin/join-output.ts +120 -0
- package/src/bin/nat-output.ts +177 -0
- package/src/{donation → hosted}/__tests__/fake-orchestrator.test.ts +173 -173
- package/src/{donation → hosted}/__tests__/fake-orchestrator.ts +265 -243
- package/src/hosted/__tests__/hosted-node-service.test.ts +609 -0
- package/src/hosted/__tests__/hosted-node-supervisor.test.ts +474 -0
- package/src/hosted/__tests__/test-invitation.ts +33 -0
- package/src/hosted/claim-details.ts +96 -0
- package/src/hosted/hosted-node-service.ts +795 -0
- package/src/hosted/hosted-node-store.ts +144 -0
- package/src/hosted/hosted-node-supervisor.ts +439 -0
- package/src/hosted/hosted-node-watcher.ts +250 -0
- package/src/hosted/index.ts +53 -0
- package/src/hosted/node-status.ts +71 -0
- package/src/hosted/types.ts +153 -0
- package/src/index.ts +72 -91
- package/src/installer/__tests__/config.test.ts +15 -40
- package/src/installer/__tests__/installer.smoke.test.ts +5 -86
- package/src/installer/__tests__/wizard.test.ts +56 -64
- package/src/installer/config.ts +135 -175
- package/src/installer/index.ts +15 -83
- package/src/installer/paths.ts +104 -109
- package/src/installer/wizard.ts +87 -103
- package/src/nat/__tests__/address-resolver.test.ts +107 -82
- package/src/nat/__tests__/nat-service.test.ts +433 -408
- package/src/nat/__tests__/nat-store.test.ts +127 -93
- package/src/nat/__tests__/port-mapper.test.ts +30 -191
- package/src/nat/__tests__/reachability.test.ts +96 -13
- package/src/nat/address-resolver.ts +94 -52
- package/src/nat/address-watch.ts +92 -0
- package/src/nat/ddns/duckdns.ts +5 -1
- package/src/nat/ddns/index.ts +6 -0
- package/src/nat/index.ts +87 -71
- package/src/nat/nat-service.ts +889 -501
- package/src/nat/nat-store.ts +237 -154
- package/src/nat/port-mapper.ts +241 -329
- package/src/nat/reachability.ts +134 -25
- package/src/nat/types.ts +209 -159
- package/src/{installer/__tests__/identity.test.ts → orchestrator/__tests__/identity-file.test.ts} +34 -34
- package/src/orchestrator/__tests__/node-identity.test.ts +62 -62
- package/src/orchestrator/host-process-orchestrator.ts +81 -243
- package/src/{installer/identity.ts → orchestrator/identity-file.ts} +56 -56
- package/src/orchestrator/index.ts +9 -10
- package/src/orchestrator/node-identity.ts +41 -41
- package/src/orchestrator/port-allocator.ts +71 -73
- package/src/orchestrator/state-store.ts +76 -90
- package/src/orchestrator/types.ts +34 -23
- package/src/server/__tests__/bus.test.ts +38 -38
- package/src/server/__tests__/error-handler.test.ts +81 -118
- package/src/server/__tests__/fakes.ts +40 -44
- package/src/server/__tests__/hosted-nodes-route.test.ts +160 -0
- package/src/server/__tests__/nodes-route.test.ts +114 -283
- package/src/server/__tests__/publishers.test.ts +193 -180
- package/src/server/__tests__/server.smoke.test.ts +134 -223
- package/src/server/__tests__/settings-route.test.ts +179 -195
- package/src/server/__tests__/sse-route.test.ts +119 -119
- package/src/server/__tests__/status-route.test.ts +82 -121
- package/src/server/error-handler.ts +112 -178
- package/src/server/events/types.ts +20 -24
- package/src/server/index.ts +223 -267
- package/src/server/routes/hosted-nodes.ts +83 -0
- package/src/server/routes/nat.ts +75 -63
- package/src/server/routes/nodes.ts +96 -188
- package/src/server/routes/settings.ts +115 -123
- package/src/server/routes/status.ts +102 -134
- package/src/server/server.ts +8 -8
- package/src/server/settings-store.ts +2 -2
- package/src/server/static.ts +1 -2
- package/src/update/index.ts +2 -2
- package/src/update/store.ts +1 -1
- package/src/update/types.ts +1 -1
- package/dist/auth/duration.d.ts +0 -1
- package/dist/auth/duration.js +0 -32
- package/dist/auth/duration.js.map +0 -1
- package/dist/auth/index.d.ts +0 -11
- package/dist/auth/index.js +0 -9
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/self-label.d.ts +0 -36
- package/dist/auth/self-label.js +0 -57
- package/dist/auth/self-label.js.map +0 -1
- package/dist/auth/trust-circle-store.d.ts +0 -26
- package/dist/auth/trust-circle-store.js +0 -129
- package/dist/auth/trust-circle-store.js.map +0 -1
- package/dist/auth/trust-circle.d.ts +0 -156
- package/dist/auth/trust-circle.js +0 -307
- package/dist/auth/trust-circle.js.map +0 -1
- package/dist/auth/types.d.ts +0 -84
- package/dist/auth/types.js +0 -24
- package/dist/auth/types.js.map +0 -1
- package/dist/donation/donation-service.d.ts +0 -389
- package/dist/donation/donation-service.js +0 -828
- package/dist/donation/donation-service.js.map +0 -1
- package/dist/donation/donation-store.d.ts +0 -51
- package/dist/donation/donation-store.js +0 -152
- package/dist/donation/donation-store.js.map +0 -1
- package/dist/donation/donation-supervisor.js +0 -364
- package/dist/donation/donation-supervisor.js.map +0 -1
- package/dist/donation/grant-service.d.ts +0 -80
- package/dist/donation/grant-service.js +0 -210
- package/dist/donation/grant-service.js.map +0 -1
- package/dist/donation/grant-store.d.ts +0 -38
- package/dist/donation/grant-store.js +0 -135
- package/dist/donation/grant-store.js.map +0 -1
- package/dist/donation/index.d.ts +0 -20
- package/dist/donation/index.js +0 -17
- package/dist/donation/index.js.map +0 -1
- package/dist/donation/types.d.ts +0 -224
- package/dist/donation/types.js +0 -40
- package/dist/donation/types.js.map +0 -1
- package/dist/installer/identity.js.map +0 -1
- package/dist/owner/index.d.ts +0 -11
- package/dist/owner/index.js +0 -11
- package/dist/owner/index.js.map +0 -1
- package/dist/owner/owner-node-client.d.ts +0 -110
- package/dist/owner/owner-node-client.js +0 -184
- package/dist/owner/owner-node-client.js.map +0 -1
- package/dist/server/routes/bootstrap-node-validation.d.ts +0 -115
- package/dist/server/routes/bootstrap-node-validation.js +0 -197
- package/dist/server/routes/bootstrap-node-validation.js.map +0 -1
- package/dist/server/routes/grants-admin.d.ts +0 -29
- package/dist/server/routes/grants-admin.js +0 -58
- package/dist/server/routes/grants-admin.js.map +0 -1
- package/dist/server/routes/grants.d.ts +0 -28
- package/dist/server/routes/grants.js +0 -165
- package/dist/server/routes/grants.js.map +0 -1
- package/dist/server/routes/provision-request-validation.d.ts +0 -45
- package/dist/server/routes/provision-request-validation.js +0 -97
- package/dist/server/routes/provision-request-validation.js.map +0 -1
- package/dist/server/routes/strands.d.ts +0 -20
- package/dist/server/routes/strands.js +0 -38
- package/dist/server/routes/strands.js.map +0 -1
- package/dist/server/routes/trust-circle.d.ts +0 -17
- package/dist/server/routes/trust-circle.js +0 -35
- package/dist/server/routes/trust-circle.js.map +0 -1
- package/dist/strands/index.d.ts +0 -7
- package/dist/strands/index.js +0 -6
- package/dist/strands/index.js.map +0 -1
- package/dist/strands/strand-service.d.ts +0 -50
- package/dist/strands/strand-service.js +0 -103
- package/dist/strands/strand-service.js.map +0 -1
- package/dist/strands/types.d.ts +0 -93
- package/dist/strands/types.js +0 -23
- package/dist/strands/types.js.map +0 -1
- package/dist/ui/assets/index-C6nELNfC.js +0 -23
- package/dist/ui/assets/index-C6nELNfC.js.map +0 -1
- package/dist/ui/assets/index-TtIYSeZO.css +0 -1
- package/src/__tests__/cli-invite.smoke.test.ts +0 -192
- package/src/__tests__/host-owner.smoke.test.ts +0 -123
- package/src/__tests__/orchestrator-owner.test.ts +0 -234
- package/src/__tests__/orchestrator-pin-keys.test.ts +0 -152
- package/src/auth/__tests__/duration.test.ts +0 -28
- package/src/auth/__tests__/self-label.test.ts +0 -85
- package/src/auth/__tests__/trust-circle-integration.test.ts +0 -152
- package/src/auth/__tests__/trust-circle-store.test.ts +0 -115
- package/src/auth/__tests__/trust-circle.test.ts +0 -445
- package/src/auth/duration.ts +0 -33
- package/src/auth/index.ts +0 -21
- package/src/auth/self-label.ts +0 -74
- package/src/auth/trust-circle-store.ts +0 -155
- package/src/auth/trust-circle.ts +0 -395
- package/src/auth/types.ts +0 -99
- package/src/donation/__tests__/donation-service.test.ts +0 -1193
- package/src/donation/__tests__/donation-supervisor.test.ts +0 -548
- package/src/donation/__tests__/grant-service.test.ts +0 -213
- package/src/donation/__tests__/grant-store.test.ts +0 -113
- package/src/donation/donation-service.ts +0 -1033
- package/src/donation/donation-store.ts +0 -176
- package/src/donation/donation-supervisor.ts +0 -411
- package/src/donation/grant-service.ts +0 -252
- package/src/donation/grant-store.ts +0 -152
- package/src/donation/index.ts +0 -65
- package/src/donation/types.ts +0 -260
- package/src/owner/__tests__/owner-node-client.test.ts +0 -194
- package/src/owner/index.ts +0 -12
- package/src/owner/owner-node-client.ts +0 -259
- package/src/server/__tests__/bootstrap-node-validation.test.ts +0 -138
- package/src/server/__tests__/grants-admin-route.test.ts +0 -171
- package/src/server/__tests__/grants-route.test.ts +0 -394
- package/src/server/__tests__/strands-route.test.ts +0 -234
- package/src/server/routes/bootstrap-node-validation.ts +0 -206
- package/src/server/routes/grants-admin.ts +0 -74
- package/src/server/routes/grants.ts +0 -193
- package/src/server/routes/provision-request-validation.ts +0 -105
- package/src/server/routes/strands.ts +0 -54
- package/src/server/routes/trust-circle.ts +0 -49
- package/src/strands/__tests__/strand-service.test.ts +0 -165
- package/src/strands/index.ts +0 -14
- package/src/strands/strand-service.ts +0 -135
- package/src/strands/types.ts +0 -102
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import { decodeCadreInvitation } from '@serfab/cadre-core';
|
|
3
|
+
import { errorMessage, readNodeStatus, reportsClaim } from './node-status.js';
|
|
4
|
+
const log = debug('cadre:host:hosted-node-watcher');
|
|
5
|
+
/** How often an unclaimed node's `/status` is read for the claim, and a joining node's for its redemption. */
|
|
6
|
+
export const HOSTED_NODE_CLAIM_POLL_MS = 2000;
|
|
7
|
+
/** How often a joined node's `/status` is read for its connection count. */
|
|
8
|
+
export const HOSTED_NODE_CONNECTED_POLL_MS = 15000;
|
|
9
|
+
/** Statuses the watcher reads every tick: a node still on its way into its cadre. */
|
|
10
|
+
const PENDING_STATUSES = new Set(['unclaimed', 'joining']);
|
|
11
|
+
/**
|
|
12
|
+
* Follows each hosted node's `/status`: an `unclaimed` record becomes `joined` when
|
|
13
|
+
* the node reports a finished claim; a `joining` record becomes `joined` when a member
|
|
14
|
+
* accepted its invitation, or `error` when the redemption failed; and a `joined`
|
|
15
|
+
* record's `connected` follows the node's control-connection count. Best-effort: a poll
|
|
16
|
+
* that fails is retried on the next tick, and nothing here throws out of the timer.
|
|
17
|
+
*
|
|
18
|
+
* One timer at the claim cadence drives all three: every tick polls every unclaimed and
|
|
19
|
+
* joining node, and each joined node every {@link HOSTED_NODE_CONNECTED_POLL_MS}, or at once when it
|
|
20
|
+
* was poked — the orchestrator's state change on a respawn pokes the node, and the
|
|
21
|
+
* poke stands until a poll succeeds, so a respawned child is noticed on its first
|
|
22
|
+
* answer rather than at the next 15 s mark. Polls are serialized on one promise
|
|
23
|
+
* tail so a timer pass and a poked pass cannot both write one record.
|
|
24
|
+
*
|
|
25
|
+
* NOTE: the 2 s timer ticks while nothing is unclaimed (one cached store read, no
|
|
26
|
+
* I/O per tick); if it ever shows up in a profile, stop it when no record is
|
|
27
|
+
* unclaimed and restart it from `poke`.
|
|
28
|
+
*/
|
|
29
|
+
export class HostedNodeWatcher {
|
|
30
|
+
constructor(opts) {
|
|
31
|
+
this.tail = Promise.resolve();
|
|
32
|
+
/** When each joined node's `/status` last answered (ms since epoch). */
|
|
33
|
+
this.lastPolledAt = new Map();
|
|
34
|
+
/** Joined nodes to poll on the next pass regardless of cadence. */
|
|
35
|
+
this.due = new Set();
|
|
36
|
+
this.store = opts.store;
|
|
37
|
+
this.orchestrator = opts.orchestrator;
|
|
38
|
+
this.now = opts.now;
|
|
39
|
+
this.emit = opts.emit;
|
|
40
|
+
}
|
|
41
|
+
/** Start the timer and the state-change subscription, and poll once. Idempotent. */
|
|
42
|
+
start() {
|
|
43
|
+
if (this.timer)
|
|
44
|
+
return;
|
|
45
|
+
this.unsubscribe = this.orchestrator.onStateChange?.((info) => { this.poke(info.id); });
|
|
46
|
+
this.timer = setInterval(() => { this.poke(); }, HOSTED_NODE_CLAIM_POLL_MS);
|
|
47
|
+
this.timer.unref();
|
|
48
|
+
this.poke();
|
|
49
|
+
}
|
|
50
|
+
stop() {
|
|
51
|
+
if (this.timer) {
|
|
52
|
+
clearInterval(this.timer);
|
|
53
|
+
this.timer = undefined;
|
|
54
|
+
}
|
|
55
|
+
this.unsubscribe?.();
|
|
56
|
+
this.unsubscribe = undefined;
|
|
57
|
+
}
|
|
58
|
+
/** Ask for a pass now; `id` names a joined node to poll ahead of its cadence. Fire-and-forget. */
|
|
59
|
+
poke(id) {
|
|
60
|
+
if (id)
|
|
61
|
+
this.due.add(id);
|
|
62
|
+
void this.poll().catch((err) => { log('status poll failed: %s', errorMessage(err)); });
|
|
63
|
+
}
|
|
64
|
+
/** One pass over every unclaimed, joining and due joined record, serialized against the others. */
|
|
65
|
+
poll() {
|
|
66
|
+
const next = this.tail.then(() => this.pollOnce(), () => this.pollOnce());
|
|
67
|
+
this.tail = next.then(() => undefined, () => undefined);
|
|
68
|
+
return next;
|
|
69
|
+
}
|
|
70
|
+
async pollOnce() {
|
|
71
|
+
let records;
|
|
72
|
+
try {
|
|
73
|
+
records = this.store.list().filter((n) => PENDING_STATUSES.has(n.status) || n.status === 'joined');
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
// A malformed hosted-nodes.json throws on every load; log rather than let it escape the timer.
|
|
77
|
+
log('poll could not list hosted nodes: %s', errorMessage(err));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.forgetRemoved(new Set(records.map((r) => r.id)));
|
|
81
|
+
for (const record of records) {
|
|
82
|
+
if (this.shouldPoll(record))
|
|
83
|
+
await this.pollOne(record);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Drop the cadence and poke bookkeeping of nodes no longer on record, so neither map grows with removals. */
|
|
87
|
+
forgetRemoved(live) {
|
|
88
|
+
for (const id of this.lastPolledAt.keys())
|
|
89
|
+
if (!live.has(id))
|
|
90
|
+
this.lastPolledAt.delete(id);
|
|
91
|
+
for (const id of this.due)
|
|
92
|
+
if (!live.has(id))
|
|
93
|
+
this.due.delete(id);
|
|
94
|
+
}
|
|
95
|
+
shouldPoll(record) {
|
|
96
|
+
if (PENDING_STATUSES.has(record.status) || this.due.has(record.id))
|
|
97
|
+
return true;
|
|
98
|
+
const last = this.lastPolledAt.get(record.id);
|
|
99
|
+
return last === undefined || this.now().getTime() - last >= HOSTED_NODE_CONNECTED_POLL_MS;
|
|
100
|
+
}
|
|
101
|
+
async pollOne(record) {
|
|
102
|
+
if (!record.statusEndpoint)
|
|
103
|
+
return;
|
|
104
|
+
let status;
|
|
105
|
+
try {
|
|
106
|
+
status = await readNodeStatus(record.statusEndpoint);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
log('hosted node %s did not answer /status (retried next tick): %s', record.id, errorMessage(err));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.lastPolledAt.set(record.id, this.now().getTime());
|
|
113
|
+
this.due.delete(record.id);
|
|
114
|
+
// Re-read: `record` predates the round-trip and `store.put` replaces the whole
|
|
115
|
+
// row, so writing that copy back would resurrect a node removed meanwhile, or
|
|
116
|
+
// undo a respawn's new handles. The store is synchronous, so this read-decide-
|
|
117
|
+
// write is atomic against the event loop as long as no `await` sneaks in.
|
|
118
|
+
const current = this.store.get(record.id);
|
|
119
|
+
if (!current || current.status !== record.status)
|
|
120
|
+
return;
|
|
121
|
+
if (current.status === 'unclaimed') {
|
|
122
|
+
this.applyUnclaimed(current, status);
|
|
123
|
+
}
|
|
124
|
+
else if (current.status === 'joining') {
|
|
125
|
+
await this.applyJoining(current, status);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this.applyJoined(current, status);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** An unclaimed node that reports a finished claim is `joined`, with the party and owner the claim named. */
|
|
132
|
+
applyUnclaimed(current, status) {
|
|
133
|
+
if (!reportsClaim(status))
|
|
134
|
+
return;
|
|
135
|
+
this.store.put({
|
|
136
|
+
...current,
|
|
137
|
+
status: 'joined',
|
|
138
|
+
partyId: status.node.partyId,
|
|
139
|
+
ownerKey: status.node.claimedBy,
|
|
140
|
+
peerId: current.peerId ?? status.peerId,
|
|
141
|
+
connected: status.node.connectionPaths.total > 0,
|
|
142
|
+
updatedAt: this.now().toISOString(),
|
|
143
|
+
});
|
|
144
|
+
log('hosted node %s was claimed by owner %s into cadre %s', current.id, status.node.claimedBy.slice(0, 8), status.node.partyId);
|
|
145
|
+
this.emit({ kind: 'claimed', id: current.id });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A joining node whose redemption settled: `joined` with the member that admitted it and
|
|
149
|
+
* the invitation's issuer as its owner, or `error` with the reason and whether Retry may
|
|
150
|
+
* help. A failed node's child is stopped after the write, as a give-up's is, and kept
|
|
151
|
+
* with its workdir for Retry; the write comes first so the exit the stop raises finds
|
|
152
|
+
* a record the supervisor leaves alone. Still `pending`: nothing.
|
|
153
|
+
*/
|
|
154
|
+
async applyJoining(current, status) {
|
|
155
|
+
const invitation = status.node.invitation;
|
|
156
|
+
if (invitation?.state === 'accepted') {
|
|
157
|
+
const ownerKey = issuerOf(current);
|
|
158
|
+
this.store.put({
|
|
159
|
+
...current,
|
|
160
|
+
status: 'joined',
|
|
161
|
+
...(ownerKey ? { ownerKey } : {}),
|
|
162
|
+
...(invitation.memberPeerId ? { memberPeerId: invitation.memberPeerId } : {}),
|
|
163
|
+
peerId: current.peerId ?? status.peerId,
|
|
164
|
+
connected: status.node.connectionPaths.total > 0,
|
|
165
|
+
updatedAt: this.now().toISOString(),
|
|
166
|
+
});
|
|
167
|
+
log('hosted node %s joined cadre %s at member %s', current.id, current.partyId, invitation.memberPeerId ?? '(unnamed)');
|
|
168
|
+
this.emit({ kind: 'joined', id: current.id });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (invitation?.state !== 'failed')
|
|
172
|
+
return;
|
|
173
|
+
const error = invitation.error ?? 'the invitation could not be redeemed';
|
|
174
|
+
this.store.put({
|
|
175
|
+
...current,
|
|
176
|
+
status: 'error',
|
|
177
|
+
error,
|
|
178
|
+
retryable: invitation.retryable === true,
|
|
179
|
+
peerId: current.peerId ?? status.peerId,
|
|
180
|
+
updatedAt: this.now().toISOString(),
|
|
181
|
+
});
|
|
182
|
+
log('hosted node %s could not join cadre %s (%s): %s', current.id, current.partyId, invitation.retryable ? 'retryable' : 'final', error);
|
|
183
|
+
this.emit({ kind: 'changed', id: current.id });
|
|
184
|
+
if (!current.dockerId)
|
|
185
|
+
return;
|
|
186
|
+
try {
|
|
187
|
+
await this.orchestrator.stopContainer(current.dockerId);
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
log('failed to stop hosted node %s after its invitation failed: %s', current.id, errorMessage(err));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* A joined node's `connected` follows its control-connection count; published only on a
|
|
195
|
+
* change. Its `/status` keeps reporting the invitation for as long as the child that
|
|
196
|
+
* redeemed it runs, and whatever it says there is ignored: the node is a member, and the
|
|
197
|
+
* record says so.
|
|
198
|
+
*/
|
|
199
|
+
applyJoined(current, status) {
|
|
200
|
+
const connected = status.node.connectionPaths.total > 0;
|
|
201
|
+
if (current.connected === connected)
|
|
202
|
+
return;
|
|
203
|
+
this.store.put({ ...current, connected, updatedAt: this.now().toISOString() });
|
|
204
|
+
log('hosted node %s is now %s', current.id, connected ? 'connected' : 'disconnected');
|
|
205
|
+
this.emit({ kind: 'changed', id: current.id });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The owner a joined invitation node is shown under: the issuer of its invitation. The
|
|
210
|
+
* record's bundle decoded at `join`, so this only fails on a hand-edited
|
|
211
|
+
* `hosted-nodes.json`; the node is a member either way, so the record says so without one.
|
|
212
|
+
*/
|
|
213
|
+
function issuerOf(node) {
|
|
214
|
+
if (node.join.kind !== 'invitation')
|
|
215
|
+
return undefined;
|
|
216
|
+
try {
|
|
217
|
+
return decodeCadreInvitation(node.join.encoded).invite.issuerKey;
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
log('hosted node %s carries an invitation that no longer decodes: %s', node.id, errorMessage(err));
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=hosted-node-watcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-node-watcher.js","sourceRoot":"","sources":["../../src/hosted/hosted-node-watcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAI3D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAmB,MAAM,kBAAkB,CAAC;AAG/F,MAAM,GAAG,GAAG,KAAK,CAAC,gCAAgC,CAAC,CAAC;AAEpD,8GAA8G;AAC9G,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAK,CAAC;AAE/C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,6BAA6B,GAAG,KAAM,CAAC;AAWpD,qFAAqF;AACrF,MAAM,gBAAgB,GAAkC,IAAI,GAAG,CAAmB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;AAU5G;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,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xD,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS;YAAE,OAAO;QAC5C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC/E,GAAG,CAAC,0BAA0B,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;QACtF,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;CACF;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAgB;IAChC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,SAAS,CAAC;IACtD,IAAI,CAAC;QACH,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;IACnE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,iEAAiE,EAAE,IAAI,CAAC,EAAE,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;QACnG,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hosted nodes: the host's "Join a cadre" action and what follows from it. See
|
|
3
|
+
* ./types.ts for the record, ./hosted-node-service.ts for the lifecycle,
|
|
4
|
+
* ./hosted-node-watcher.ts for following each node's `/status`, ./claim-details.ts for
|
|
5
|
+
* the QR payload, and ./hosted-node-supervisor.ts for the respawn invariant.
|
|
6
|
+
*/
|
|
7
|
+
export { HostedNodeStore } from './hosted-node-store.js';
|
|
8
|
+
export { HostedNodeService, HOSTED_NODE_SPAWNING_TTL_MS, HOSTED_NODE_REAP_SWEEP_MS, } from './hosted-node-service.js';
|
|
9
|
+
export type { HostedNodeOrchestrator, HostedNodeServiceOptions, JoinOptions, RespawnOptions, RespawnResult, } from './hosted-node-service.js';
|
|
10
|
+
export type { ClaimDetails, HostedNodeAddressSource } from './claim-details.js';
|
|
11
|
+
export { HOSTED_NODE_CLAIM_POLL_MS, HOSTED_NODE_CONNECTED_POLL_MS, } from './hosted-node-watcher.js';
|
|
12
|
+
export { HostedNodeSupervisor, HOSTED_NODE_RESPAWN_BACKOFF_BASE_MS, HOSTED_NODE_RESPAWN_BACKOFF_MAX_MS, HOSTED_NODE_RESPAWN_MAX_ATTEMPTS, HOSTED_NODE_RESPAWN_HEALTHY_MS, HOSTED_NODE_RESPAWN_SWEEP_MS, } from './hosted-node-supervisor.js';
|
|
13
|
+
export type { HostedNodeSupervisorOptions, SupervisedOrchestrator, } from './hosted-node-supervisor.js';
|
|
14
|
+
export { PLACEHOLDER_PARTY } from './node-status.js';
|
|
15
|
+
export { HostedNodeError } from './types.js';
|
|
16
|
+
export type { HostedNode, HostedNodeChange, HostedNodeChangeKind, HostedNodeChangeListener, HostedNodeErrorCode, HostedNodeClaimJoin, HostedNodeFile, HostedNodeInvitationJoin, HostedNodeJoin, HostedNodeJoinView, HostedNodeStatus, HostedNodeView, } from './types.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hosted nodes: the host's "Join a cadre" action and what follows from it. See
|
|
3
|
+
* ./types.ts for the record, ./hosted-node-service.ts for the lifecycle,
|
|
4
|
+
* ./hosted-node-watcher.ts for following each node's `/status`, ./claim-details.ts for
|
|
5
|
+
* the QR payload, and ./hosted-node-supervisor.ts for the respawn invariant.
|
|
6
|
+
*/
|
|
7
|
+
export { HostedNodeStore } from './hosted-node-store.js';
|
|
8
|
+
export { HostedNodeService, HOSTED_NODE_SPAWNING_TTL_MS, HOSTED_NODE_REAP_SWEEP_MS, } from './hosted-node-service.js';
|
|
9
|
+
export { HOSTED_NODE_CLAIM_POLL_MS, HOSTED_NODE_CONNECTED_POLL_MS, } from './hosted-node-watcher.js';
|
|
10
|
+
export { HostedNodeSupervisor, HOSTED_NODE_RESPAWN_BACKOFF_BASE_MS, HOSTED_NODE_RESPAWN_BACKOFF_MAX_MS, HOSTED_NODE_RESPAWN_MAX_ATTEMPTS, HOSTED_NODE_RESPAWN_HEALTHY_MS, HOSTED_NODE_RESPAWN_SWEEP_MS, } from './hosted-node-supervisor.js';
|
|
11
|
+
export { PLACEHOLDER_PARTY } from './node-status.js';
|
|
12
|
+
export { HostedNodeError } from './types.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hosted/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,0BAA0B,CAAC;AASlC,OAAO,EACL,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,mCAAmC,EACnC,kCAAkC,EAClC,gCAAgC,EAChC,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AAKrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a hosted child's `/status` — the one window the host has onto a node it
|
|
3
|
+
* runs: its peer id and addresses before the claim, and the claim itself, the party
|
|
4
|
+
* and the owner key after it. Shared by `HostedNodeService.claimDetails` and the
|
|
5
|
+
* status watcher.
|
|
6
|
+
*/
|
|
7
|
+
import type { HealthStatus } from '@serfab/cadre-cli';
|
|
8
|
+
/** The party an unclaimed child's config names; the claim replaces it. */
|
|
9
|
+
export declare const PLACEHOLDER_PARTY = "unclaimed";
|
|
10
|
+
/** The `/status` URL for a spawn's `/health` URL (same server and port). */
|
|
11
|
+
export declare function statusUrlFor(healthEndpoint: string): string;
|
|
12
|
+
/** A `/status` answer from a node that has its peer identity. */
|
|
13
|
+
export type NodeStatus = HealthStatus & {
|
|
14
|
+
peerId: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The child's `/status`, fresh every call. Throws `node_unavailable` while the child
|
|
18
|
+
* does not answer, answers with an error, or has no peer identity yet — every one of
|
|
19
|
+
* which a caller retries.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readNodeStatus(statusEndpoint: string): Promise<NodeStatus>;
|
|
22
|
+
/**
|
|
23
|
+
* Whether `/status` reports a finished claim: a claim on record AND the party it
|
|
24
|
+
* named. `claim` flips to `claimed` the moment the node records the claim, but the
|
|
25
|
+
* node then restarts in-process into the claimed party, and until that restart
|
|
26
|
+
* finishes `partyId` is still the placeholder (or empty while the node object is
|
|
27
|
+
* being rebuilt). Writing `joined` on the flag alone would record the placeholder
|
|
28
|
+
* as the node's cadre.
|
|
29
|
+
*/
|
|
30
|
+
export declare function reportsClaim(status: NodeStatus): status is NodeStatus & {
|
|
31
|
+
node: {
|
|
32
|
+
claimedBy: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare function errorMessage(err: unknown): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a hosted child's `/status` — the one window the host has onto a node it
|
|
3
|
+
* runs: its peer id and addresses before the claim, and the claim itself, the party
|
|
4
|
+
* and the owner key after it. Shared by `HostedNodeService.claimDetails` and the
|
|
5
|
+
* status watcher.
|
|
6
|
+
*/
|
|
7
|
+
import { HostedNodeError } from './types.js';
|
|
8
|
+
/** The party an unclaimed child's config names; the claim replaces it. */
|
|
9
|
+
export const PLACEHOLDER_PARTY = 'unclaimed';
|
|
10
|
+
/** The `/status` URL for a spawn's `/health` URL (same server and port). */
|
|
11
|
+
export function statusUrlFor(healthEndpoint) {
|
|
12
|
+
const url = new URL(healthEndpoint);
|
|
13
|
+
url.pathname = '/status';
|
|
14
|
+
return url.toString();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The child's `/status`, fresh every call. Throws `node_unavailable` while the child
|
|
18
|
+
* does not answer, answers with an error, or has no peer identity yet — every one of
|
|
19
|
+
* which a caller retries.
|
|
20
|
+
*/
|
|
21
|
+
export async function readNodeStatus(statusEndpoint) {
|
|
22
|
+
let res;
|
|
23
|
+
try {
|
|
24
|
+
res = await fetch(statusEndpoint);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
throw new HostedNodeError('node_unavailable', `Hosted node unreachable: ${errorMessage(err)}`);
|
|
28
|
+
}
|
|
29
|
+
if (!res.ok) {
|
|
30
|
+
throw new HostedNodeError('node_unavailable', `Hosted node /status returned ${res.status}`);
|
|
31
|
+
}
|
|
32
|
+
let status;
|
|
33
|
+
try {
|
|
34
|
+
status = (await res.json());
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw new HostedNodeError('node_unavailable', `Hosted node /status is not JSON: ${errorMessage(err)}`);
|
|
38
|
+
}
|
|
39
|
+
if (!status.peerId || !status.multiaddrs?.length) {
|
|
40
|
+
throw new HostedNodeError('node_unavailable', 'Hosted node has no peer identity yet');
|
|
41
|
+
}
|
|
42
|
+
return status;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether `/status` reports a finished claim: a claim on record AND the party it
|
|
46
|
+
* named. `claim` flips to `claimed` the moment the node records the claim, but the
|
|
47
|
+
* node then restarts in-process into the claimed party, and until that restart
|
|
48
|
+
* finishes `partyId` is still the placeholder (or empty while the node object is
|
|
49
|
+
* being rebuilt). Writing `joined` on the flag alone would record the placeholder
|
|
50
|
+
* as the node's cadre.
|
|
51
|
+
*/
|
|
52
|
+
export function reportsClaim(status) {
|
|
53
|
+
return status.node.claim === 'claimed'
|
|
54
|
+
&& status.node.claimedBy !== undefined
|
|
55
|
+
&& status.node.partyId !== ''
|
|
56
|
+
&& status.node.partyId !== PLACEHOLDER_PARTY;
|
|
57
|
+
}
|
|
58
|
+
export function errorMessage(err) {
|
|
59
|
+
return err instanceof Error ? err.message : String(err);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=node-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-status.js","sourceRoot":"","sources":["../../src/hosted/node-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAE7C,4EAA4E;AAC5E,MAAM,UAAU,YAAY,CAAC,cAAsB;IACjD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;IACpC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC;IACzB,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAKD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,cAAsB;IACzD,IAAI,GAAa,CAAC;IAClB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,eAAe,CAAC,kBAAkB,EAAE,4BAA4B,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,eAAe,CAAC,kBAAkB,EAAE,gCAAgC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,MAAoB,CAAC;IACzB,IAAI,CAAC;QACH,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAiB,CAAC;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,eAAe,CAAC,kBAAkB,EAAE,oCAAoC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzG,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;QACjD,MAAM,IAAI,eAAe,CAAC,kBAAkB,EAAE,sCAAsC,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,MAAoB,CAAC;AAC9B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS;WACjC,MAAM,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS;WACnC,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,EAAE;WAC1B,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,iBAAiB,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hosted-node types for cadre-host.
|
|
3
|
+
*
|
|
4
|
+
* A **hosted node** is a child process the host runs for some cadre. It gets into its
|
|
5
|
+
* cadre one of two ways: the host starts it waiting to be claimed and shows its addresses
|
|
6
|
+
* and claim secret as a QR code, which the owner's phone scans to claim the node
|
|
7
|
+
* (`CadreNode.claimNode`); or the host starts it with a cadre invitation the owner's app
|
|
8
|
+
* minted, which the node redeems at a member of the cadre. Either way the host holds no
|
|
9
|
+
* owner key and is not an owner of any cadre its nodes serve.
|
|
10
|
+
*
|
|
11
|
+
* Records live in `<dataDir>/hosted-nodes.json` (`HostedNodeStore`). A record's id is also
|
|
12
|
+
* its orchestrator container id and the name of its working directory.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Lifecycle of one hosted node:
|
|
16
|
+
* spawning → the record is written, the child not yet spawned.
|
|
17
|
+
* unclaimed → (claim) the child is up with a claim secret, waiting for a phone to claim it.
|
|
18
|
+
* joining → (invitation) the child is up, its redemption of the invitation not yet settled.
|
|
19
|
+
* joined → in its cadre: claimed, or the invitation accepted by a member.
|
|
20
|
+
* error → the supervisor gave up on it, the stuck-`spawning` reap found it, or the
|
|
21
|
+
* invitation was refused or no member could be reached (`retryable` says which).
|
|
22
|
+
*
|
|
23
|
+
* Removal deletes the row; there is no terminal "removed" status. An `error` record keeps
|
|
24
|
+
* its working directory (its identity key) until it is removed or reset.
|
|
25
|
+
*/
|
|
26
|
+
export type HostedNodeStatus = 'spawning' | 'unclaimed' | 'joining' | 'joined' | 'error';
|
|
27
|
+
/**
|
|
28
|
+
* The node was started with a claim secret and waits for a phone to present it.
|
|
29
|
+
*/
|
|
30
|
+
export interface HostedNodeClaimJoin {
|
|
31
|
+
kind: 'claim';
|
|
32
|
+
/** The node's one-time claim secret, base64url. Only `claimDetails` ever returns it. */
|
|
33
|
+
secret: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The node was started with a cadre invitation and redeems it at a member of the cadre.
|
|
37
|
+
* Kept for a respawn while `joining`: the child redeems again, and a member answers a node
|
|
38
|
+
* that already got in as accepted.
|
|
39
|
+
*/
|
|
40
|
+
export interface HostedNodeInvitationJoin {
|
|
41
|
+
kind: 'invitation';
|
|
42
|
+
/**
|
|
43
|
+
* The bundle as the owner's app encoded it (`encodeCadreInvitation`). It carries the
|
|
44
|
+
* invitation's private key, so it is redacted like the claim secret.
|
|
45
|
+
*
|
|
46
|
+
* NOTE: kept on disk after the node joins, though nothing reads it then (a joined node is
|
|
47
|
+
* respawned without it). An invitation with uses left admits whoever reads it; if
|
|
48
|
+
* multi-use invitations get pasted into hosts, drop it at the watcher's `joined` write.
|
|
49
|
+
*/
|
|
50
|
+
encoded: string;
|
|
51
|
+
}
|
|
52
|
+
/** How a node gets into its cadre. */
|
|
53
|
+
export type HostedNodeJoin = HostedNodeClaimJoin | HostedNodeInvitationJoin;
|
|
54
|
+
/** One hosted node, as persisted in `hosted-nodes.json`. */
|
|
55
|
+
export interface HostedNode {
|
|
56
|
+
/** `hn_<base64url of 12 random bytes>` — also the orchestrator container id and workdir name. */
|
|
57
|
+
id: string;
|
|
58
|
+
join: HostedNodeJoin;
|
|
59
|
+
/**
|
|
60
|
+
* A claim node: `unclaimed` (the placeholder party the child's config names) until the
|
|
61
|
+
* claim reports the party; the claimant's party after. An invitation node: the
|
|
62
|
+
* invitation's party from the start.
|
|
63
|
+
*/
|
|
64
|
+
partyId: string;
|
|
65
|
+
/** Hosted nodes run the `storage` profile: they participate in strands and are dialable. */
|
|
66
|
+
profile: 'storage';
|
|
67
|
+
status: HostedNodeStatus;
|
|
68
|
+
/** Orchestrator handle (opaque `pid:token`), set once the child is spawned. */
|
|
69
|
+
dockerId?: string;
|
|
70
|
+
/** The child's loopback `/status` URL, from the spawn result. */
|
|
71
|
+
statusEndpoint?: string;
|
|
72
|
+
/** Read once from `/status`; the claim details need it before the claim. */
|
|
73
|
+
peerId?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Set when the node joins: `/status.node.claimedBy` for a claim, the invitation's issuer
|
|
76
|
+
* key for an invitation. The UI shows its first 8 characters.
|
|
77
|
+
*/
|
|
78
|
+
ownerKey?: string;
|
|
79
|
+
/** An invitation node, once joined: the member that admitted it, when its address named one. */
|
|
80
|
+
memberPeerId?: string;
|
|
81
|
+
/** From the last status poll: the node holds at least one control connection. */
|
|
82
|
+
connected?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Respawn bookkeeping, owned by the supervisor's backoff. Absent until the first
|
|
85
|
+
* respawn attempt. Not secret — it rides along in `HostedNodeView`.
|
|
86
|
+
*/
|
|
87
|
+
respawn?: {
|
|
88
|
+
attempts: number;
|
|
89
|
+
lastAttemptAt: string;
|
|
90
|
+
};
|
|
91
|
+
createdAt: string;
|
|
92
|
+
updatedAt: string;
|
|
93
|
+
/** Failure detail when `status === 'error'`. */
|
|
94
|
+
error?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Set with `error` when an invitation failed: whether Retry may start the node again with
|
|
97
|
+
* the same invitation (no member could be reached), or the invitation itself was refused.
|
|
98
|
+
* Absent on every other `error`.
|
|
99
|
+
*/
|
|
100
|
+
retryable?: boolean;
|
|
101
|
+
}
|
|
102
|
+
/** `join` without its secret: what `list`, `get`, the routes and the events carry. */
|
|
103
|
+
export type HostedNodeJoinView = {
|
|
104
|
+
kind: HostedNodeJoin['kind'];
|
|
105
|
+
};
|
|
106
|
+
/** The wire shape of a hosted node: the record with the claim secret or the invitation stripped. */
|
|
107
|
+
export interface HostedNodeView extends Omit<HostedNode, 'join'> {
|
|
108
|
+
join: HostedNodeJoinView;
|
|
109
|
+
}
|
|
110
|
+
/** On-disk shape of `hosted-nodes.json`. Keyed by node id. */
|
|
111
|
+
export interface HostedNodeFile {
|
|
112
|
+
version: 1;
|
|
113
|
+
nodes: Record<string, Omit<HostedNode, 'id'>>;
|
|
114
|
+
}
|
|
115
|
+
/** Error codes thrown by the hosted-node service, mapped to HTTP status by `server/error-handler.ts`. */
|
|
116
|
+
export type HostedNodeErrorCode = 'not_found' | 'invalid_state' | 'invalid_request' | 'node_unavailable' | 'orchestrator_error' | 'storage_error';
|
|
117
|
+
/** Typed hosted-node error carrying a stable `code` for HTTP mapping. */
|
|
118
|
+
export declare class HostedNodeError extends Error {
|
|
119
|
+
readonly code: HostedNodeErrorCode;
|
|
120
|
+
constructor(code: HostedNodeErrorCode, message: string);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* What changed about a hosted node: `added` (a join started the node), `claimed` (the
|
|
124
|
+
* watcher saw the claim), `joined` (the watcher saw a member accept the invitation),
|
|
125
|
+
* `removed`, or `changed` (anything else: a respawn, a liveness change, a refused
|
|
126
|
+
* invitation, a retry, a give-up). The server publishes each as the `hosted-nodes-changed`
|
|
127
|
+
* SSE event.
|
|
128
|
+
*/
|
|
129
|
+
export type HostedNodeChangeKind = 'added' | 'claimed' | 'joined' | 'removed' | 'changed';
|
|
130
|
+
export interface HostedNodeChange {
|
|
131
|
+
kind: HostedNodeChangeKind;
|
|
132
|
+
id: string;
|
|
133
|
+
}
|
|
134
|
+
export type HostedNodeChangeListener = (change: HostedNodeChange) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hosted-node types for cadre-host.
|
|
3
|
+
*
|
|
4
|
+
* A **hosted node** is a child process the host runs for some cadre. It gets into its
|
|
5
|
+
* cadre one of two ways: the host starts it waiting to be claimed and shows its addresses
|
|
6
|
+
* and claim secret as a QR code, which the owner's phone scans to claim the node
|
|
7
|
+
* (`CadreNode.claimNode`); or the host starts it with a cadre invitation the owner's app
|
|
8
|
+
* minted, which the node redeems at a member of the cadre. Either way the host holds no
|
|
9
|
+
* owner key and is not an owner of any cadre its nodes serve.
|
|
10
|
+
*
|
|
11
|
+
* Records live in `<dataDir>/hosted-nodes.json` (`HostedNodeStore`). A record's id is also
|
|
12
|
+
* its orchestrator container id and the name of its working directory.
|
|
13
|
+
*/
|
|
14
|
+
/** Typed hosted-node error carrying a stable `code` for HTTP mapping. */
|
|
15
|
+
export class HostedNodeError extends Error {
|
|
16
|
+
constructor(code, message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'HostedNodeError';
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/hosted/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAmHH,yEAAyE;AACzE,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAGxC,YAAY,IAAyB,EAAE,OAAe;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,37 +4,25 @@
|
|
|
4
4
|
* This package is the sibling of @serfab/cadre-provider for self-hosted
|
|
5
5
|
* basement-PC deployments. It depends on @serfab/cadre-provider for the
|
|
6
6
|
* orchestration interface and container lifecycle types but ships its own
|
|
7
|
-
* orchestrator (host processes, not Docker),
|
|
8
|
-
*
|
|
7
|
+
* orchestrator (host processes, not Docker), the hosted-node service behind
|
|
8
|
+
* "Join a cadre", installer, NAT layer, and local management UI.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* under src
|
|
13
|
-
*
|
|
14
|
-
* - cadre-host-process-orchestrator [DONE]
|
|
15
|
-
* - cadre-host-trust-circle [DONE]
|
|
16
|
-
* - cadre-host-nat
|
|
17
|
-
* - cadre-host-installer
|
|
18
|
-
* - cadre-host-local-ui
|
|
10
|
+
* HostProcessOrchestrator, the hosted-node layer, the NAT layer, the
|
|
11
|
+
* installer, and the local UI server each live in a sibling subdirectory
|
|
12
|
+
* under src/.
|
|
19
13
|
*/
|
|
20
14
|
export type { Orchestrator, OrchestratorCreateRequest, OrchestratorCreateResult, OrchestratorStats, ContainerStatus, ContainerResources, } from '@serfab/cadre-provider';
|
|
21
|
-
export { HostProcessOrchestrator
|
|
22
|
-
export type { HostProcessConfig, PersistedHandle, ManagedNodeInfo, NodeStateListener, NodePorts,
|
|
23
|
-
export {
|
|
24
|
-
export type {
|
|
25
|
-
export { TrustCircleService, TrustCircleStore, TrustCircleError, createTrustCircleHandlers, parseDuration, ensureSelfLabel, DEFAULT_INVITE_TTL_MS, } from './auth/index.js';
|
|
26
|
-
export type { TrustCircleServiceOptions, CadreNodeLike, TrustCircleMember, PendingInvite, TrustCircleFile, TrustCircleSnapshot, TrustCircleHandlers, TrustCircleErrorCode, } from './auth/index.js';
|
|
27
|
-
export { StrandService, StrandError, createStrandHandlers } from './strands/index.js';
|
|
28
|
-
export type { StrandServiceOptions, CadreNodeLike as StrandCadreNodeLike, StrandSummary, StrandListSnapshot, StrandRemovalResult, StrandHandlers, StrandErrorCode, } from './strands/index.js';
|
|
29
|
-
export { GrantStore, GrantService, createGrantAdminHandlers, GrantError, DEFAULT_MAX_NODES, DonationStore, DonationService, DonationError, } from './donation/index.js';
|
|
30
|
-
export type { Grant, GrantDenyReason, GrantValidation, GrantValidator, GrantFile, GrantAdminHandlers, GrantErrorCode, GrantServiceOptions, Donation, DonationView, DonationStatus, DonationFile, DonationErrorCode, DonationProvisionRequest, DonationSeedResult, DonationPeerInfo, DonationServiceOptions, } from './donation/index.js';
|
|
15
|
+
export { HostProcessOrchestrator } from './orchestrator/index.js';
|
|
16
|
+
export type { HostProcessConfig, HostedSpawnRequest, PersistedHandle, ManagedNodeInfo, NodeStateListener, NodePorts, } from './orchestrator/index.js';
|
|
17
|
+
export { HostedNodeStore, HostedNodeService, HostedNodeSupervisor, HostedNodeError, HOSTED_NODE_SPAWNING_TTL_MS, HOSTED_NODE_REAP_SWEEP_MS, HOSTED_NODE_CLAIM_POLL_MS, HOSTED_NODE_CONNECTED_POLL_MS, HOSTED_NODE_RESPAWN_BACKOFF_BASE_MS, HOSTED_NODE_RESPAWN_BACKOFF_MAX_MS, HOSTED_NODE_RESPAWN_MAX_ATTEMPTS, HOSTED_NODE_RESPAWN_HEALTHY_MS, HOSTED_NODE_RESPAWN_SWEEP_MS, PLACEHOLDER_PARTY, } from './hosted/index.js';
|
|
18
|
+
export type { ClaimDetails, HostedNode, HostedNodeAddressSource, HostedNodeChange, HostedNodeChangeKind, HostedNodeChangeListener, HostedNodeErrorCode, HostedNodeClaimJoin, HostedNodeFile, HostedNodeInvitationJoin, HostedNodeJoin, HostedNodeJoinView, HostedNodeOrchestrator, HostedNodeServiceOptions, HostedNodeStatus, HostedNodeSupervisorOptions, HostedNodeView, JoinOptions, RespawnOptions, RespawnResult, SupervisedOrchestrator, } from './hosted/index.js';
|
|
31
19
|
export { Installer, readHostConfig, updateHostConfig, writeHostConfig } from './installer/index.js';
|
|
32
20
|
export type { InstallOptions, InstallResult, UninstallOptions, InstallerOptions, HostConfigFile, PushSettings, WizardAnswers, WizardDefaults, ServiceHost, ServiceHostContext, ServiceHostStatus, } from './installer/index.js';
|
|
33
21
|
export { resolvePushCredentials, setFcmSecret, setApnsSecret, clearPushSecret, pushAccount, pushStatus, } from './push/index.js';
|
|
34
22
|
export type { FcmSecret, ApnsSecret, PushSecretPlatform, PushStatus, } from './push/index.js';
|
|
35
23
|
export { UpdateService, createUpdateHandlers, UpdateStateStore, UpdateErrorException, applyUpdate, defaultNpmExecutor, fetchManifest, verifyManifest, canonicalJson, signManifest, validateManifestFields, buildManifest, derivePublicKeyBase64, signAndSelfVerify, compareVersions, parseVersion, getReleasePublicKey, getReleasePublicKeyBase64, ed25519FromRaw, isPlaceholderReleaseKey, } from './update/index.js';
|
|
36
24
|
export type { UpdateServiceOptions, UpdateHandlers, UpdateState, SignedManifest, UpdateApplyResult, UpdateSettings, UpdateManifest, UpdateErrorCode, ManifestFields, NpmExecutor, ServiceRestarter, } from './update/index.js';
|
|
37
|
-
export { NatService, NatStore, NatError, createNatHandlers, ExternalIpDetector,
|
|
38
|
-
export type { NatServiceOptions,
|
|
25
|
+
export { NatService, NatStore, NatError, createNatHandlers, NAT_UNMAP_GRACE_MS, NAT_RECONCILE_INTERVAL_MS, NAT_IP_REDETECT_INTERVAL_MS, ExternalIpDetector, UpnpPortMapper, pickLanAddress, evaluateNodeReachability, evaluateHostReachability, buildPublicAddresses, isPublicIpv4, BUILTIN_PROVIDERS, getProvider, listProviders, duckDnsProvider, DdnsUpdater, KeytarSecretsStore, FileSecretsStore, createSecretsStore, ddnsAccount, KEYTAR_SERVICE, DEFAULT_LEASE_TTL_MS, DEFAULT_REFRESH_MS, GATEWAY_DISCOVERY_TIMEOUT_MS, isPlausibleIp, } from './nat/index.js';
|
|
26
|
+
export type { NatServiceOptions, NatNodeSource, NatChangeListener, NodeAddressesStaleListener, NatStatusSnapshot, NatGatewayStatus, NatDdnsStatus, NatSettingsFile, NatDdnsSettings, NatHandlers, NatErrorCode, DirectReachability, NodeReachability, NodeVerdict, PortKind, PortRoute, PortRouteSource, ManualForward, ManualForwardPatch, DdnsProviderInfo, DdnsConfigField, ExternalIpResult, RouterIpProbe, ExternalIpDetectorOptions, PortMapper, GatewayInfo, PortMapRequest, PortMapResult, NodeVerdictInput, NodeVerdictResult, PublicAddressInput, DdnsProvider, DdnsProviderDeps, DdnsUpdaterOptions, DdnsUpdateOutcome, SecretsStore, KeytarLike, } from './nat/index.js';
|
|
39
27
|
export { createLocalUiServer, EventBus, HostSettingsStore, } from './server/index.js';
|
|
40
|
-
export type {
|
|
28
|
+
export type { LocalUiServer, LocalUiServerOptions, LocalUiEvent, LocalUiEventType, LocalUiEventListener, } from './server/index.js';
|