@serfab/cadre-core 0.7.1 → 0.9.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 +11 -10
- package/dist/cadre-node.d.ts +818 -19
- package/dist/cadre-node.js +1952 -99
- package/dist/cadre-node.js.map +1 -1
- package/dist/canonical-datetime.d.ts +33 -0
- package/dist/canonical-datetime.js +38 -0
- package/dist/canonical-datetime.js.map +1 -0
- package/dist/canonical-json.d.ts +12 -0
- package/dist/canonical-json.js +33 -0
- package/dist/canonical-json.js.map +1 -0
- package/dist/control-cohort.d.ts +63 -0
- package/dist/control-cohort.js +80 -0
- package/dist/control-cohort.js.map +1 -0
- package/dist/control-database.d.ts +279 -8
- package/dist/control-database.js +563 -134
- package/dist/control-database.js.map +1 -1
- package/dist/control-formation-recorder.d.ts +89 -0
- package/dist/control-formation-recorder.js +139 -0
- package/dist/control-formation-recorder.js.map +1 -0
- package/dist/control-schema.d.ts +12 -0
- package/dist/control-schema.js +223 -0
- package/dist/control-schema.js.map +1 -0
- package/dist/control-stream.d.ts +54 -0
- package/dist/control-stream.js +104 -0
- package/dist/control-stream.js.map +1 -0
- package/dist/device-token.d.ts +50 -0
- package/dist/device-token.js +66 -0
- package/dist/device-token.js.map +1 -0
- package/dist/diagnostics/connection-path.d.ts +118 -0
- package/dist/diagnostics/connection-path.js +204 -0
- package/dist/diagnostics/connection-path.js.map +1 -0
- package/dist/diagnostics/webrtc-turn-tracker.d.ts +50 -0
- package/dist/diagnostics/webrtc-turn-tracker.js +196 -0
- package/dist/diagnostics/webrtc-turn-tracker.js.map +1 -0
- package/dist/ed25519-key.d.ts +42 -0
- package/dist/ed25519-key.js +51 -0
- package/dist/ed25519-key.js.map +1 -0
- package/dist/hibernation-manager.d.ts +79 -0
- package/dist/hibernation-manager.js +173 -23
- package/dist/hibernation-manager.js.map +1 -1
- package/dist/index.d.ts +25 -4
- package/dist/index.js +59 -4
- package/dist/index.js.map +1 -1
- package/dist/key-store-file.d.ts +52 -0
- package/dist/key-store-file.js +194 -0
- package/dist/key-store-file.js.map +1 -0
- package/dist/key-store.d.ts +75 -0
- package/dist/key-store.js +66 -0
- package/dist/key-store.js.map +1 -0
- package/dist/peer-authorization.d.ts +48 -0
- package/dist/peer-authorization.js +66 -0
- package/dist/peer-authorization.js.map +1 -0
- package/dist/peer-record.d.ts +89 -0
- package/dist/peer-record.js +117 -0
- package/dist/peer-record.js.map +1 -0
- package/dist/push-credentials.d.ts +34 -0
- package/dist/push-credentials.js +81 -0
- package/dist/push-credentials.js.map +1 -0
- package/dist/push-fanout.d.ts +137 -0
- package/dist/push-fanout.js +197 -0
- package/dist/push-fanout.js.map +1 -0
- package/dist/push-node.d.ts +38 -0
- package/dist/push-node.js +48 -0
- package/dist/push-node.js.map +1 -0
- package/dist/push-notifier-apns.d.ts +61 -0
- package/dist/push-notifier-apns.js +199 -0
- package/dist/push-notifier-apns.js.map +1 -0
- package/dist/push-notifier-fcm.d.ts +44 -0
- package/dist/push-notifier-fcm.js +182 -0
- package/dist/push-notifier-fcm.js.map +1 -0
- package/dist/push-notifier-shared.d.ts +18 -0
- package/dist/push-notifier-shared.js +25 -0
- package/dist/push-notifier-shared.js.map +1 -0
- package/dist/push-notifier.d.ts +52 -0
- package/dist/push-notifier.js +22 -0
- package/dist/push-notifier.js.map +1 -0
- package/dist/schema-verification.d.ts +11 -2
- package/dist/schema-verification.js +15 -4
- package/dist/schema-verification.js.map +1 -1
- package/dist/seed-bootstrap.d.ts +228 -21
- package/dist/seed-bootstrap.js +489 -168
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/seed-trust-policy.d.ts +63 -0
- package/dist/seed-trust-policy.js +56 -0
- package/dist/seed-trust-policy.js.map +1 -0
- package/dist/strand-addr-protocol.d.ts +132 -0
- package/dist/strand-addr-protocol.js +313 -0
- package/dist/strand-addr-protocol.js.map +1 -0
- package/dist/strand-cohort.d.ts +54 -0
- package/dist/strand-cohort.js +38 -0
- package/dist/strand-cohort.js.map +1 -0
- package/dist/strand-database.d.ts +54 -6
- package/dist/strand-database.js +88 -100
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-formation-manager.d.ts +79 -19
- package/dist/strand-formation-manager.js +196 -104
- package/dist/strand-formation-manager.js.map +1 -1
- package/dist/strand-formation-protocol.d.ts +162 -0
- package/dist/strand-formation-protocol.js +279 -0
- package/dist/strand-formation-protocol.js.map +1 -0
- package/dist/strand-instance-manager.d.ts +73 -4
- package/dist/strand-instance-manager.js +167 -41
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-member-key.d.ts +29 -0
- package/dist/strand-member-key.js +38 -0
- package/dist/strand-member-key.js.map +1 -0
- package/dist/strand-member-registry.d.ts +98 -0
- package/dist/strand-member-registry.js +129 -0
- package/dist/strand-member-registry.js.map +1 -0
- package/dist/strand-membership-writer.d.ts +361 -0
- package/dist/strand-membership-writer.js +449 -0
- package/dist/strand-membership-writer.js.map +1 -0
- package/dist/strand-solicitation.d.ts +77 -2
- package/dist/strand-solicitation.js +25 -4
- package/dist/strand-solicitation.js.map +1 -1
- package/dist/strand-wake-payload.d.ts +30 -0
- package/dist/strand-wake-payload.js +20 -0
- package/dist/strand-wake-payload.js.map +1 -0
- package/dist/strand-wake-protocol.d.ts +114 -0
- package/dist/strand-wake-protocol.js +257 -0
- package/dist/strand-wake-protocol.js.map +1 -0
- package/dist/strand-watcher.d.ts +6 -2
- package/dist/strand-watcher.js +57 -17
- package/dist/strand-watcher.js.map +1 -1
- package/dist/types.d.ts +436 -33
- package/dist/types.js +22 -5
- package/dist/types.js.map +1 -1
- package/package.json +18 -8
- package/src/cadre-node.ts +2981 -948
- package/src/canonical-datetime.ts +39 -0
- package/src/canonical-json.ts +30 -0
- package/src/control-cohort.ts +103 -0
- package/src/control-database.ts +948 -383
- package/src/control-formation-recorder.ts +151 -0
- package/src/control-schema.ts +222 -0
- package/src/control-stream.ts +128 -0
- package/src/device-token.ts +89 -0
- package/src/diagnostics/connection-path.ts +277 -0
- package/src/diagnostics/webrtc-turn-tracker.ts +222 -0
- package/src/ed25519-key.ts +69 -0
- package/src/hibernation-manager.ts +197 -28
- package/src/index.ts +275 -79
- package/src/key-store-file.ts +203 -0
- package/src/key-store.ts +99 -0
- package/src/peer-authorization.ts +81 -0
- package/src/peer-record.ts +146 -0
- package/src/push-credentials.ts +84 -0
- package/src/push-fanout.ts +272 -0
- package/src/push-node.ts +64 -0
- package/src/push-notifier-apns.ts +247 -0
- package/src/push-notifier-fcm.ts +220 -0
- package/src/push-notifier-shared.ts +28 -0
- package/src/push-notifier.ts +52 -0
- package/src/schema-verification.ts +18 -4
- package/src/seed-bootstrap.ts +563 -223
- package/src/seed-trust-policy.ts +107 -0
- package/src/strand-addr-protocol.ts +410 -0
- package/src/strand-cohort.ts +77 -0
- package/src/strand-database.ts +113 -141
- package/src/strand-formation-manager.ts +233 -142
- package/src/strand-formation-protocol.ts +391 -0
- package/src/strand-instance-manager.ts +207 -56
- package/src/strand-member-key.ts +39 -0
- package/src/strand-member-registry.ts +177 -0
- package/src/strand-membership-writer.ts +640 -0
- package/src/strand-solicitation.ts +93 -4
- package/src/strand-wake-payload.ts +32 -0
- package/src/strand-wake-protocol.ts +331 -0
- package/src/strand-watcher.ts +61 -17
- package/src/types.ts +1032 -582
|
@@ -13,7 +13,20 @@ const log = debug('sereus:cadre:hibernation');
|
|
|
13
13
|
export class HibernationManager {
|
|
14
14
|
constructor(config, callbacks) {
|
|
15
15
|
this.timers = new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Pending check-in timers, one per hibernating strand. Unlike the old fixed
|
|
18
|
+
* `setInterval`, these are single-shot `setTimeout`s rescheduled by
|
|
19
|
+
* {@link runCheckIn} with an escalating delay — so a long-running `onCheckIn`
|
|
20
|
+
* can never overlap the next tick, and the period adapts to the backoff.
|
|
21
|
+
*/
|
|
16
22
|
this.checkInTimers = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* In-flight wake promises keyed by strandId. Coalesces overlapping wake
|
|
25
|
+
* triggers (two near-simultaneous activities, or activity racing a force wake)
|
|
26
|
+
* so `onWake` — and the libp2p-node rebuild it drives — runs at most once per
|
|
27
|
+
* concurrent wake.
|
|
28
|
+
*/
|
|
29
|
+
this.wakePromises = new Map();
|
|
17
30
|
this.running = false;
|
|
18
31
|
this.config = config;
|
|
19
32
|
this.callbacks = callbacks;
|
|
@@ -30,7 +43,9 @@ export class HibernationManager {
|
|
|
30
43
|
return {
|
|
31
44
|
idleTimeout: custom.idleTimeout ?? defaults.idleTimeout,
|
|
32
45
|
hibernateTimeout: custom.hibernateTimeout ?? defaults.hibernateTimeout,
|
|
33
|
-
checkInInterval: custom.checkInInterval ?? defaults.checkInInterval
|
|
46
|
+
checkInInterval: custom.checkInInterval ?? defaults.checkInInterval,
|
|
47
|
+
checkInBackoffFactor: custom.checkInBackoffFactor ?? defaults.checkInBackoffFactor,
|
|
48
|
+
checkInMaxInterval: custom.checkInMaxInterval ?? defaults.checkInMaxInterval
|
|
34
49
|
};
|
|
35
50
|
}
|
|
36
51
|
/**
|
|
@@ -55,11 +70,53 @@ export class HibernationManager {
|
|
|
55
70
|
}
|
|
56
71
|
this.timers.clear();
|
|
57
72
|
for (const timer of this.checkInTimers.values()) {
|
|
58
|
-
|
|
73
|
+
clearTimeout(timer);
|
|
59
74
|
}
|
|
60
75
|
this.checkInTimers.clear();
|
|
76
|
+
// In-flight wakes clean themselves up via their finally; drop the references
|
|
77
|
+
// so a fresh start coalesces cleanly.
|
|
78
|
+
this.wakePromises.clear();
|
|
61
79
|
log('HibernationManager stopped');
|
|
62
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether a strand with this instance's latency hint ever hibernates — `false`
|
|
83
|
+
* for realtime (Infinity idle timeout, see {@link HIBERNATION_TIMEOUTS}), also
|
|
84
|
+
* honouring any per-hint `customTimeouts` override. Imperative callers
|
|
85
|
+
* (`CadreNode.hibernateStrand` / `hibernateAll`) use this as the single source
|
|
86
|
+
* of truth for "skip realtime", consistent with {@link trackStrand} declining
|
|
87
|
+
* to track Infinity-timeout strands.
|
|
88
|
+
*/
|
|
89
|
+
hibernates(instance) {
|
|
90
|
+
return this.getTimeouts(instance.latencyHint).idleTimeout !== Infinity;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Imperatively hibernate a tracked strand now, bypassing the idle/hibernate
|
|
94
|
+
* timers — the mobile background-entry path. Cancels the strand's pending
|
|
95
|
+
* idle/hibernate AND check-in timers so none can later re-fire `onHibernate`
|
|
96
|
+
* on the already-quiesced strand or resurrect one the caller means to keep
|
|
97
|
+
* down, then invokes `onHibernate` (quiesce + mark hibernating).
|
|
98
|
+
*
|
|
99
|
+
* Unlike the timer path ({@link handleHibernateTimeout}) it deliberately does
|
|
100
|
+
* NOT re-arm the check-in chain: a force-hibernate keeps the strand down until
|
|
101
|
+
* the caller drives the next wake on demand (push-delivered on mobile), so a
|
|
102
|
+
* stray check-in timer must not bring it back up.
|
|
103
|
+
*
|
|
104
|
+
* @returns `true` if the strand was hibernated, `false` (no-op) for a realtime
|
|
105
|
+
* strand that never hibernates.
|
|
106
|
+
*/
|
|
107
|
+
async forceHibernate(instance) {
|
|
108
|
+
if (!this.hibernates(instance)) {
|
|
109
|
+
log('forceHibernate: strand %s is realtime; no-op', instance.strandId);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
// Cancel idle/hibernate + check-in timers BEFORE quiescing so nothing fights
|
|
113
|
+
// the imperative hibernate (a stale hibernate timer firing on the quiesced
|
|
114
|
+
// strand, or a check-in resuming a strand the caller wants kept down).
|
|
115
|
+
this.clearTimers(instance.strandId);
|
|
116
|
+
await this.callbacks.onHibernate(instance.strandId);
|
|
117
|
+
log('forceHibernate: strand %s hibernated (timers cancelled, not re-armed)', instance.strandId);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
63
120
|
/**
|
|
64
121
|
* Register a strand for hibernation management
|
|
65
122
|
*/
|
|
@@ -91,11 +148,31 @@ export class HibernationManager {
|
|
|
91
148
|
return;
|
|
92
149
|
const { strandId, status, latencyHint } = instance;
|
|
93
150
|
instance.lastActivity = new Date();
|
|
94
|
-
// If idle or hibernating, wake up
|
|
151
|
+
// If idle or hibernating, wake up. Coalesce so two near-simultaneous
|
|
152
|
+
// activities don't each fire onWake (which would rebuild two libp2p nodes).
|
|
95
153
|
if (status === 'idle' || status === 'hibernating') {
|
|
96
154
|
log('Activity on %s strand %s - waking', status, strandId);
|
|
97
155
|
this.clearTimers(strandId);
|
|
98
|
-
|
|
156
|
+
// Fire-and-forget; force-wake awaiters see errors, so swallow (and log)
|
|
157
|
+
// here to avoid an unhandled rejection on this best-effort path.
|
|
158
|
+
//
|
|
159
|
+
// Once the wake settles (CadreNode rebuilds the runtime and marks the
|
|
160
|
+
// strand `active`), re-arm the idle→hibernate→check-in cycle. Without this
|
|
161
|
+
// a strand that wakes then goes quiet stays `active` forever and never
|
|
162
|
+
// re-hibernates — so the check-in backoff could never restart at base.
|
|
163
|
+
// Guarded on `active` so a wake that did not transition (a coalesced
|
|
164
|
+
// no-op, or a still-mid-flight rebuild) never arms a stray timer.
|
|
165
|
+
void this.beginWake(strandId).then(() => {
|
|
166
|
+
if (this.running && instance.status === 'active') {
|
|
167
|
+
const timeouts = this.getTimeouts(instance.latencyHint);
|
|
168
|
+
if (timeouts.idleTimeout !== Infinity) {
|
|
169
|
+
this.scheduleIdleTransition(instance);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}).catch((err) => {
|
|
173
|
+
log('Activity-driven wake failed for strand %s: %o', strandId, err);
|
|
174
|
+
});
|
|
175
|
+
return;
|
|
99
176
|
}
|
|
100
177
|
// Reschedule idle transition if active
|
|
101
178
|
if (status === 'active') {
|
|
@@ -110,7 +187,29 @@ export class HibernationManager {
|
|
|
110
187
|
*/
|
|
111
188
|
async wakeStrand(strandId) {
|
|
112
189
|
this.clearTimers(strandId);
|
|
113
|
-
await this.
|
|
190
|
+
await this.beginWake(strandId);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Begin a wake for a strand, or coalesce with one already in flight. Ensures
|
|
194
|
+
* `onWake` runs at most once per concurrent wake — the returned promise is
|
|
195
|
+
* shared by all overlapping callers and cleared once it settles. Force-wake
|
|
196
|
+
* callers await it; activity-driven callers fire-and-forget.
|
|
197
|
+
*/
|
|
198
|
+
beginWake(strandId) {
|
|
199
|
+
const existing = this.wakePromises.get(strandId);
|
|
200
|
+
if (existing) {
|
|
201
|
+
return existing;
|
|
202
|
+
}
|
|
203
|
+
const wake = (async () => {
|
|
204
|
+
try {
|
|
205
|
+
await this.callbacks.onWake(strandId);
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
this.wakePromises.delete(strandId);
|
|
209
|
+
}
|
|
210
|
+
})();
|
|
211
|
+
this.wakePromises.set(strandId, wake);
|
|
212
|
+
return wake;
|
|
114
213
|
}
|
|
115
214
|
scheduleIdleTransition(instance) {
|
|
116
215
|
const { strandId, latencyHint } = instance;
|
|
@@ -128,13 +227,16 @@ export class HibernationManager {
|
|
|
128
227
|
if (!this.running)
|
|
129
228
|
return;
|
|
130
229
|
log('Idle timeout for strand %s', strandId);
|
|
131
|
-
// Transition to idle
|
|
230
|
+
// Transition to idle. The callback can reject (e.g. a future idle handler
|
|
231
|
+
// that releases resources); catch so the timer chain never unhandled-rejects.
|
|
132
232
|
void this.callbacks.onIdle(strandId).then(() => {
|
|
133
233
|
// Schedule hibernate transition
|
|
134
234
|
const timeouts = this.getTimeouts(latencyHint);
|
|
135
235
|
if (timeouts.hibernateTimeout !== Infinity) {
|
|
136
236
|
this.scheduleHibernateTransition(instance);
|
|
137
237
|
}
|
|
238
|
+
}).catch((err) => {
|
|
239
|
+
log('onIdle failed for strand %s: %o', strandId, err);
|
|
138
240
|
});
|
|
139
241
|
}
|
|
140
242
|
scheduleHibernateTransition(instance) {
|
|
@@ -153,36 +255,84 @@ export class HibernationManager {
|
|
|
153
255
|
if (!this.running)
|
|
154
256
|
return;
|
|
155
257
|
log('Hibernate timeout for strand %s', strandId);
|
|
156
|
-
// Transition to hibernating
|
|
258
|
+
// Transition to hibernating. onHibernate now releases strand-network
|
|
259
|
+
// resources (quiesce), so its close()/stop() can reject — catch so a failed
|
|
260
|
+
// hibernate logs instead of producing an unhandled rejection.
|
|
157
261
|
void this.callbacks.onHibernate(strandId).then(() => {
|
|
158
262
|
// Schedule periodic check-ins
|
|
159
263
|
const timeouts = this.getTimeouts(latencyHint);
|
|
160
264
|
if (timeouts.checkInInterval !== Infinity) {
|
|
161
265
|
this.scheduleCheckIn(instance);
|
|
162
266
|
}
|
|
267
|
+
}).catch((err) => {
|
|
268
|
+
log('onHibernate failed for strand %s: %o', strandId, err);
|
|
163
269
|
});
|
|
164
270
|
}
|
|
165
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Arm the next check-in for a hibernating strand. Each call is a single-shot
|
|
273
|
+
* `setTimeout` (not a fixed `setInterval`) so the period escalates per
|
|
274
|
+
* {@link runCheckIn} and a slow `onCheckIn` never overlaps the next tick.
|
|
275
|
+
*
|
|
276
|
+
* `delay` is omitted by the chain start ({@link handleHibernateTimeout}),
|
|
277
|
+
* defaulting to the base `checkInInterval` — which is why backoff naturally
|
|
278
|
+
* resets to base each fresh hibernation cycle, with no per-strand counter to
|
|
279
|
+
* clear on wake. Subsequent ticks pass the escalated, capped delay.
|
|
280
|
+
*/
|
|
281
|
+
scheduleCheckIn(instance, delay) {
|
|
166
282
|
const { strandId, latencyHint } = instance;
|
|
167
283
|
const timeouts = this.getTimeouts(latencyHint);
|
|
168
|
-
|
|
284
|
+
const currentDelay = delay ?? timeouts.checkInInterval;
|
|
285
|
+
// Replace any existing check-in timer (no-op if the firing timer rescheduled us).
|
|
169
286
|
const existing = this.checkInTimers.get(strandId);
|
|
170
287
|
if (existing) {
|
|
171
|
-
|
|
288
|
+
clearTimeout(existing);
|
|
172
289
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
clearInterval(timer);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
log('Check-in for hibernating strand %s', strandId);
|
|
180
|
-
instance.nextCheckIn = new Date(Date.now() + timeouts.checkInInterval);
|
|
181
|
-
// In a real implementation, this would query the cohort for pending activity
|
|
182
|
-
// For now, we just update the nextCheckIn timestamp
|
|
183
|
-
}, timeouts.checkInInterval);
|
|
290
|
+
const timer = setTimeout(() => {
|
|
291
|
+
void this.runCheckIn(instance, currentDelay);
|
|
292
|
+
}, currentDelay);
|
|
184
293
|
this.checkInTimers.set(strandId, timer);
|
|
185
|
-
instance.nextCheckIn = new Date(Date.now() +
|
|
294
|
+
instance.nextCheckIn = new Date(Date.now() + currentDelay);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Run a single check-in tick: invoke `onCheckIn` (a real resume → bounded
|
|
298
|
+
* sync window → re-hibernate-if-idle cycle in `CadreNode`) and AWAIT it before
|
|
299
|
+
* deciding the next step.
|
|
300
|
+
*
|
|
301
|
+
* - If the strand woke during the check-in (`onCheckIn` left it non-
|
|
302
|
+
* `hibernating`), stop the chain — the activity path has re-armed the
|
|
303
|
+
* idle/hibernate timers, and the next hibernation restarts the chain at the
|
|
304
|
+
* base delay (backoff reset).
|
|
305
|
+
* - Otherwise escalate the delay by `checkInBackoffFactor`, capped at
|
|
306
|
+
* `checkInMaxInterval`, and reschedule.
|
|
307
|
+
*/
|
|
308
|
+
async runCheckIn(instance, currentDelay) {
|
|
309
|
+
const { strandId, latencyHint } = instance;
|
|
310
|
+
if (!this.running)
|
|
311
|
+
return;
|
|
312
|
+
log('Check-in for hibernating strand %s (delay=%dms)', strandId, currentDelay);
|
|
313
|
+
try {
|
|
314
|
+
await this.callbacks.onCheckIn(strandId);
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
// A failed check-in (e.g. resume threw) must not break the chain — log and
|
|
318
|
+
// fall through to reschedule the next, longer-delayed attempt.
|
|
319
|
+
log('onCheckIn failed for strand %s: %o', strandId, err);
|
|
320
|
+
}
|
|
321
|
+
if (!this.running)
|
|
322
|
+
return;
|
|
323
|
+
// The check-in either woke the strand (CadreNode left it active) or left it
|
|
324
|
+
// hibernating. Inspect the shared instance the callback just mutated.
|
|
325
|
+
if (instance.status !== 'hibernating') {
|
|
326
|
+
log('Check-in woke strand %s; backoff resets on next hibernation', strandId);
|
|
327
|
+
this.checkInTimers.delete(strandId);
|
|
328
|
+
// The chain is stopping; drop the now-stale next-check-in advertisement so
|
|
329
|
+
// `getStrand` doesn't report a phantom check-in for a strand that is awake.
|
|
330
|
+
instance.nextCheckIn = undefined;
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const timeouts = this.getTimeouts(latencyHint);
|
|
334
|
+
const nextDelay = Math.min(currentDelay * timeouts.checkInBackoffFactor, timeouts.checkInMaxInterval);
|
|
335
|
+
this.scheduleCheckIn(instance, nextDelay);
|
|
186
336
|
}
|
|
187
337
|
clearTimer(strandId) {
|
|
188
338
|
const timer = this.timers.get(strandId);
|
|
@@ -195,7 +345,7 @@ export class HibernationManager {
|
|
|
195
345
|
this.clearTimer(strandId);
|
|
196
346
|
const checkInTimer = this.checkInTimers.get(strandId);
|
|
197
347
|
if (checkInTimer) {
|
|
198
|
-
|
|
348
|
+
clearTimeout(checkInTimer);
|
|
199
349
|
this.checkInTimers.delete(strandId);
|
|
200
350
|
}
|
|
201
351
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hibernation-manager.js","sourceRoot":"","sources":["../src/hibernation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,GAAG,GAAG,KAAK,CAAC,0BAA0B,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"hibernation-manager.js","sourceRoot":"","sources":["../src/hibernation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,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B;QAClC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAE1B,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtD,IAAI,YAAY,EAAE,CAAC;YACjB,YAAY,CAAC,YAAY,CAAC,CAAC;YAC3B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;YAC5C,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI;SAC3D,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
+
export { canonicalJson } from './canonical-json.js';
|
|
2
3
|
export { CadreNode } from './cadre-node.js';
|
|
3
|
-
export { ControlDatabase, type ControlDatabaseConfig } from './control-database.js';
|
|
4
|
+
export { ControlDatabase, buildAuthorizationMessage, type ControlDatabaseConfig, type ControlTable } from './control-database.js';
|
|
5
|
+
export { ed25519KeyPairFromLibp2p, ed25519PublicKeyFromPrivate, type Ed25519KeyPair } from './ed25519-key.js';
|
|
6
|
+
export { InMemoryKeyStore, KeyStoreAccessError, DEFAULT_IDENTITY_KEY_ID, type KeyStore, type KeyId } from './key-store.js';
|
|
4
7
|
export { StrandDatabase, type StrandDatabaseConfig } from './strand-database.js';
|
|
5
8
|
export { StrandWatcher, type StrandWatcherCallbacks, type StrandQueryable, type SAppIdLookup, type StrandRowWithApp } from './strand-watcher.js';
|
|
6
|
-
export { StrandInstanceManager, type StartStrandConfig, getStrandStoragePath } from './strand-instance-manager.js';
|
|
9
|
+
export { StrandInstanceManager, type StartStrandConfig, type ResumeStrandOverrides, getStrandStoragePath } from './strand-instance-manager.js';
|
|
7
10
|
export { HibernationManager, type HibernationCallbacks } from './hibernation-manager.js';
|
|
8
11
|
export { ArachnodeStub, createArachnodeStub, type RingConfig } from './arachnode-stub.js';
|
|
9
12
|
export { EnrollmentService, type MemberVerifier, type MemberRegistry } from './enrollment.js';
|
|
10
|
-
export { StrandSolicitationService, type DisclosureValidator, type FormationUsageRecorder, type StrandProvisioner, type FormationSigner, type StrandSolicitationServiceOptions } from './strand-solicitation.js';
|
|
11
|
-
export {
|
|
13
|
+
export { StrandSolicitationService, createDefaultFormationResponseValidator, type DisclosureValidator, type FormationUsageRecorder, type ResolvedHostStrand, type StrandProvisioner, type FormationSigner, type FormationResponseValidator, type StrandSolicitationServiceOptions } from './strand-solicitation.js';
|
|
14
|
+
export { ControlFormationUsageRecorder } from './control-formation-recorder.js';
|
|
15
|
+
export { generateStrandMemberKey, strandMemberKeyPair } from './strand-member-key.js';
|
|
16
|
+
export { signStrandPayload, verifyStrandPayload, bootstrapFounderMembership, issueInvite, consumeInvite, addMemberByManager, registerMemberPeer, addManager, removeManager, STRAND_ENGINE, STRAND_ENGINE_VERSION, type FounderBootstrapParams, type IssueInviteParams, type IssuedInvite, type ConsumeInviteParams, type AddMemberByManagerParams, type RegisterMemberPeerParams, type AddManagerParams, type RemoveManagerParams } from './strand-membership-writer.js';
|
|
17
|
+
export { canonicalDatetime } from './canonical-datetime.js';
|
|
18
|
+
export { StrandMemberRegistry, StrandMemberVerifier, memberRegistrationPayload, type StrandAdmission } from './strand-member-registry.js';
|
|
19
|
+
export { SeedBootstrapService, SEED_PROTOCOL, ed25519PublicKeyB64FromPeerId, type SeedBootstrapConfig, type SeedEventCallbacks } from './seed-bootstrap.js';
|
|
20
|
+
export { peerAuthorizationDigest, cadrePeerVoucherDigest, cadrePeerRemoveDigest, verifyPeerAuthorization } from './peer-authorization.js';
|
|
21
|
+
export { StrandWakeService, dialWake, WAKE_PROTOCOL, type StrandWakeServiceOptions, type DialWakeOptions } from './strand-wake-protocol.js';
|
|
22
|
+
export { StrandAddrService, collectStrandAddrs, STRAND_ADDR_PROTOCOL, type StrandAddrServiceOptions, type StrandAddrPeer, type CollectStrandAddrsOptions } from './strand-addr-protocol.js';
|
|
23
|
+
export { peerRecordSignedPayload, signPeerRecord, verifyPeerRecordSignature, isPeerRecordFresh, isSignalingAddr, orderSignalingFirst, currentMemberTrustPolicy, DEFAULT_PEER_RECORD_MAX_AGE_MS, DEFAULT_PEER_RECORD_HEARTBEAT_MS } from './peer-record.js';
|
|
24
|
+
export { deviceTokenSignedPayload, signDeviceTokenRecord, verifyDeviceTokenSignature, isPushPlatform } from './device-token.js';
|
|
25
|
+
export { STRAND_WAKE_TYPE, type StrandWakePayload } from './strand-wake-payload.js';
|
|
26
|
+
export type { PushNotifier, PushMessage, PushSendResult } from './push-notifier.js';
|
|
27
|
+
export { validatePushCredentials, redactPushCredentials, REDACTED } from './push-credentials.js';
|
|
28
|
+
export { PushFanoutService, DEFAULT_PUSH_COOLDOWN_MS, DEFAULT_PUSH_DEBOUNCE_MS, type PushFanoutOptions, type FanoutMember } from './push-fanout.js';
|
|
29
|
+
export { selectControlCohortDials, DEFAULT_CONTROL_COHORT_RECONCILE_MS, DEFAULT_CONTROL_COHORT_TARGET_DEGREE, type ControlCohortSelection } from './control-cohort.js';
|
|
30
|
+
export { dbAnchoredTrustPolicy, pinnedKeyTrustPolicy, tofuTrustPolicy, type SeedTrustPolicy, type SeedTrustContext, type SeedTrustDecision } from './seed-trust-policy.js';
|
|
12
31
|
export { signSchema, verifySchema, assertSchemaSignature, SchemaVerificationError } from './schema-verification.js';
|
|
32
|
+
export { FormationListener, dialFormation, isValidResponderCreatesResult, FORMATION_PROTOCOL, type FormationParty, type FormationContactMessage, type FormationResultMessage, type FormationProvisionResult, type FormationStrandInfo, type FormationDbConnectionInfo, type FormationListenerOptions, type FormationDialOptions, type ResponderProvisionOutcome } from './strand-formation-protocol.js';
|
|
13
33
|
export { StrandFormationManager, createStrandFormationManager, type StrandFormationManagerConfig, type StrandFormationManagerOptions } from './strand-formation-manager.js';
|
|
34
|
+
export { classifyTransport, classifyConnectionPath, summarizeConnectionPaths, emptyConnectionPathSummary, DEFAULT_SETTLE_WINDOW_MS, type ConnectionPathKind, type ConnectionTransport, type ConnectionPath, type ConnectionPathSummary, type ConnectionLike } from './diagnostics/connection-path.js';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
// Core types
|
|
2
2
|
export * from './types.js';
|
|
3
|
+
// Canonical JSON serialization (shared signing payload format)
|
|
4
|
+
export { canonicalJson } from './canonical-json.js';
|
|
3
5
|
// Main CadreNode class
|
|
4
6
|
export { CadreNode } from './cadre-node.js';
|
|
5
7
|
// Control database
|
|
6
|
-
export { ControlDatabase } from './control-database.js';
|
|
8
|
+
export { ControlDatabase, buildAuthorizationMessage } from './control-database.js';
|
|
9
|
+
// Ed25519 key bridge (libp2p Ed25519 -> base64url keypair)
|
|
10
|
+
export { ed25519KeyPairFromLibp2p, ed25519PublicKeyFromPrivate } from './ed25519-key.js';
|
|
11
|
+
// Pluggable key store (backend-agnostic identity/owner key material seam).
|
|
12
|
+
// Dependency-free: the interface, error, default slot id, and in-memory backend
|
|
13
|
+
// are safe in every (RN/browser/Node) entry graph. The Node FileKeyStore is a
|
|
14
|
+
// separate subpath module ('@serfab/cadre-core/key-store-file') so its node:fs
|
|
15
|
+
// import never lands here.
|
|
16
|
+
export { InMemoryKeyStore, KeyStoreAccessError, DEFAULT_IDENTITY_KEY_ID } from './key-store.js';
|
|
7
17
|
// Strand database
|
|
8
18
|
export { StrandDatabase } from './strand-database.js';
|
|
9
19
|
// Strand management
|
|
@@ -16,11 +26,56 @@ export { ArachnodeStub, createArachnodeStub } from './arachnode-stub.js';
|
|
|
16
26
|
// Enrollment
|
|
17
27
|
export { EnrollmentService } from './enrollment.js';
|
|
18
28
|
// Strand Solicitation
|
|
19
|
-
export { StrandSolicitationService } from './strand-solicitation.js';
|
|
29
|
+
export { StrandSolicitationService, createDefaultFormationResponseValidator } from './strand-solicitation.js';
|
|
30
|
+
// DB-backed FormationUsageRecorder (reads/writes the real CadreControl tables)
|
|
31
|
+
export { ControlFormationUsageRecorder } from './control-formation-recorder.js';
|
|
32
|
+
// Closed-strand member key generation (ed25519 protobuf, base64) + the
|
|
33
|
+
// protobuf->base64url bridge that derives the founding Member/Manager key.
|
|
34
|
+
export { generateStrandMemberKey, strandMemberKeyPair } from './strand-member-key.js';
|
|
35
|
+
// Strand membership writer (founder bootstrap, invite issuance/consumption,
|
|
36
|
+
// manager-admit, member-peer registration, manager rotation, + shared signing
|
|
37
|
+
// primitives reused across the flows).
|
|
38
|
+
export { signStrandPayload, verifyStrandPayload, bootstrapFounderMembership, issueInvite, consumeInvite, addMemberByManager, registerMemberPeer, addManager, removeManager, STRAND_ENGINE, STRAND_ENGINE_VERSION } from './strand-membership-writer.js';
|
|
39
|
+
// Engine-canonical datetime helper (shared by control + strand signed-write flows
|
|
40
|
+
// so a signed timestamp byte-matches the datetime-coerced column the CHECK sees).
|
|
41
|
+
export { canonicalDatetime } from './canonical-datetime.js';
|
|
42
|
+
// Strand-DB-backed EnrollmentService backing: concrete MemberRegistry +
|
|
43
|
+
// MemberVerifier that write/read the real Strand.* membership tables.
|
|
44
|
+
export { StrandMemberRegistry, StrandMemberVerifier, memberRegistrationPayload } from './strand-member-registry.js';
|
|
20
45
|
// Seed Bootstrap
|
|
21
|
-
export { SeedBootstrapService, SEED_PROTOCOL } from './seed-bootstrap.js';
|
|
46
|
+
export { SeedBootstrapService, SEED_PROTOCOL, ed25519PublicKeyB64FromPeerId } from './seed-bootstrap.js';
|
|
47
|
+
// Peer Authorization (shared owner-signature digest + offline verifier)
|
|
48
|
+
export { peerAuthorizationDigest, cadrePeerVoucherDigest, cadrePeerRemoveDigest, verifyPeerAuthorization } from './peer-authorization.js';
|
|
49
|
+
// Strand Wake (control-network push-wake protocol)
|
|
50
|
+
export { StrandWakeService, dialWake, WAKE_PROTOCOL } from './strand-wake-protocol.js';
|
|
51
|
+
// Strand Address (control-network strand-address RPC) — wire types come via
|
|
52
|
+
// `export * from './types.js'` (StrandAddrRequest / StrandAddrResponse).
|
|
53
|
+
export { StrandAddrService, collectStrandAddrs, STRAND_ADDR_PROTOCOL } from './strand-addr-protocol.js';
|
|
54
|
+
// Peer-address record (self-published, signed, freshness-stamped CadrePeer row)
|
|
55
|
+
export { peerRecordSignedPayload, signPeerRecord, verifyPeerRecordSignature, isPeerRecordFresh, isSignalingAddr, orderSignalingFirst, currentMemberTrustPolicy, DEFAULT_PEER_RECORD_MAX_AGE_MS, DEFAULT_PEER_RECORD_HEARTBEAT_MS } from './peer-record.js';
|
|
56
|
+
// Device-token record (self-published, signed FCM/APNs push token — CadrePeer sibling)
|
|
57
|
+
export { deviceTokenSignedPayload, signDeviceTokenRecord, verifyDeviceTokenSignature, isPushPlatform } from './device-token.js';
|
|
58
|
+
// Strand-wake payload contract (canonical; shared by the server sender + RN receiver)
|
|
59
|
+
export { STRAND_WAKE_TYPE } from './strand-wake-payload.js';
|
|
60
|
+
// Push-credential validation + log redaction. Dependency-free (type-only imports),
|
|
61
|
+
// so a provisioner (cadre-host / cadre-provider) can reject a partial credential
|
|
62
|
+
// set and produce a key-safe log view without pulling the FCM/APNs sender graph.
|
|
63
|
+
export { validatePushCredentials, redactPushCredentials, REDACTED } from './push-credentials.js';
|
|
64
|
+
// Server-side push-wake trigger policy + fan-out (who/when to wake). Cross-platform
|
|
65
|
+
// clean — it imports only the PushNotifier *type*, so exporting it as a runtime
|
|
66
|
+
// value pulls no node:http2/node:crypto edge into the RN/browser graph.
|
|
67
|
+
export { PushFanoutService, DEFAULT_PUSH_COOLDOWN_MS, DEFAULT_PUSH_DEBOUNCE_MS } from './push-fanout.js';
|
|
68
|
+
// Control-cohort dial selection (backbone-preferential, bounded out-degree) +
|
|
69
|
+
// the cadence/degree defaults the proactive reconcile routine reads.
|
|
70
|
+
export { selectControlCohortDials, DEFAULT_CONTROL_COHORT_RECONCILE_MS, DEFAULT_CONTROL_COHORT_TARGET_DEGREE } from './control-cohort.js';
|
|
71
|
+
// Seed trust policy (trust anchor for incoming seeds)
|
|
72
|
+
export { dbAnchoredTrustPolicy, pinnedKeyTrustPolicy, tofuTrustPolicy } from './seed-trust-policy.js';
|
|
22
73
|
// Schema Verification
|
|
23
74
|
export { signSchema, verifySchema, assertSchemaSignature, SchemaVerificationError } from './schema-verification.js';
|
|
24
|
-
// Strand Formation (
|
|
75
|
+
// Strand Formation transport (native cadre-core protocol)
|
|
76
|
+
export { FormationListener, dialFormation, isValidResponderCreatesResult, FORMATION_PROTOCOL } from './strand-formation-protocol.js';
|
|
77
|
+
// Strand Formation manager (drives the native transport)
|
|
25
78
|
export { StrandFormationManager, createStrandFormationManager } from './strand-formation-manager.js';
|
|
79
|
+
// Connection-path diagnostics (relayed vs direct classification + summary)
|
|
80
|
+
export { classifyTransport, classifyConnectionPath, summarizeConnectionPaths, emptyConnectionPathSummary, DEFAULT_SETTLE_WINDOW_MS } from './diagnostics/connection-path.js';
|
|
26
81
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAE3B,uBAAuB;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,mBAAmB;AACnB,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAE3B,+DAA+D;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,uBAAuB;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,mBAAmB;AACnB,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAiD,MAAM,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AAE7B,sDAAsD;AACtD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EAIhB,MAAM,wBAAwB,CAAC;AAEhC,sBAAsB;AACtB,OAAO,EACL,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAElC,0DAA0D;AAC1D,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,6BAA6B,EAC7B,kBAAkB,EAUnB,MAAM,gCAAgC,CAAC;AAExC,yDAAyD;AACzD,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAG7B,MAAM,+BAA+B,CAAC;AAEvC,2EAA2E;AAC3E,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EAMzB,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { KeyId, KeyStore } from './key-store.js';
|
|
2
|
+
/**
|
|
3
|
+
* File-backed {@link KeyStore}. Each slot is `<dir>/<encoded keyId>.key`
|
|
4
|
+
* containing the raw material bytes. The directory is created lazily on first
|
|
5
|
+
* {@link set}. Suitable for headless Node cadre nodes and tests; for mobile use
|
|
6
|
+
* a platform secure-enclave backend instead.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FileKeyStore implements KeyStore {
|
|
9
|
+
private readonly dir;
|
|
10
|
+
constructor(dir: string);
|
|
11
|
+
private slotPath;
|
|
12
|
+
/**
|
|
13
|
+
* Sibling path for the temp file written before the atomic rename. The random
|
|
14
|
+
* component makes concurrent {@link set}s to the same slot (and crash-orphaned
|
|
15
|
+
* leftovers) collide-free; it lives in the same directory as the slot so the
|
|
16
|
+
* final {@link rename} stays within one filesystem and is therefore atomic.
|
|
17
|
+
*/
|
|
18
|
+
private tempPath;
|
|
19
|
+
get(keyId: KeyId): Promise<Uint8Array | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Crash-atomic write: a concurrent reader sees either the complete previous
|
|
22
|
+
* bytes or the complete new bytes, never a torn slot. The new material is
|
|
23
|
+
* written to a sibling temp file, fsync'd, then atomically renamed over the
|
|
24
|
+
* slot. A failure at any point removes the temp file and leaves the previous
|
|
25
|
+
* slot untouched.
|
|
26
|
+
*/
|
|
27
|
+
set(keyId: KeyId, keyMaterial: Uint8Array): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Write material to `tmpPath`, durably land it, then atomically swap it onto
|
|
30
|
+
* `finalPath`.
|
|
31
|
+
*
|
|
32
|
+
* Durability bar: the temp file is fsync'd before the rename so a power loss
|
|
33
|
+
* cannot surface a slot whose bytes never reached the platter, and the slot
|
|
34
|
+
* directory is fsync'd afterwards (best-effort — see {@link syncDir}) so the
|
|
35
|
+
* rename itself survives a crash. On POSIX `rename(2)` replaces atomically;
|
|
36
|
+
* Node maps to `MoveFileEx(MOVEFILE_REPLACE_EXISTING)` on Windows, which is
|
|
37
|
+
* also atomic — though it can fail with `EPERM`/`EBUSY` if another process
|
|
38
|
+
* holds the destination open. That cross-process case is out of scope here
|
|
39
|
+
* (the in-process identity path is single-flight); such a failure surfaces
|
|
40
|
+
* to the caller with the previous slot left intact.
|
|
41
|
+
*/
|
|
42
|
+
private writeSlotAtomically;
|
|
43
|
+
/**
|
|
44
|
+
* Best-effort fsync of the slot directory so a fresh slot's directory entry is
|
|
45
|
+
* durable across power loss. Opening a directory for fsync is not portable
|
|
46
|
+
* (unsupported on Windows and some filesystems), and rename atomicity does not
|
|
47
|
+
* depend on it — so a failure here is logged and swallowed, never surfaced.
|
|
48
|
+
*/
|
|
49
|
+
private syncDir;
|
|
50
|
+
delete(keyId: KeyId): Promise<void>;
|
|
51
|
+
list(): Promise<KeyId[]>;
|
|
52
|
+
}
|