@serfab/cadre-core 1.6.0 → 1.8.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.
Files changed (179) hide show
  1. package/README.md +8 -6
  2. package/dist/cadre-node.d.ts +548 -137
  3. package/dist/cadre-node.js +1208 -383
  4. package/dist/cadre-node.js.map +1 -1
  5. package/dist/control-authorization.d.ts +2 -2
  6. package/dist/control-authorization.js +1 -0
  7. package/dist/control-authorization.js.map +1 -1
  8. package/dist/control-cohort.d.ts +6 -0
  9. package/dist/control-cohort.js +6 -0
  10. package/dist/control-cohort.js.map +1 -1
  11. package/dist/control-database.d.ts +46 -8
  12. package/dist/control-database.js +97 -18
  13. package/dist/control-database.js.map +1 -1
  14. package/dist/control-formation-recorder.d.ts +37 -14
  15. package/dist/control-formation-recorder.js +60 -10
  16. package/dist/control-formation-recorder.js.map +1 -1
  17. package/dist/control-read-retry.d.ts +13 -12
  18. package/dist/control-read-retry.js +14 -12
  19. package/dist/control-read-retry.js.map +1 -1
  20. package/dist/control-schema.d.ts +1 -1
  21. package/dist/control-schema.js +67 -5
  22. package/dist/control-schema.js.map +1 -1
  23. package/dist/control-stream.d.ts +9 -1
  24. package/dist/control-stream.js +24 -1
  25. package/dist/control-stream.js.map +1 -1
  26. package/dist/control-write-retry.d.ts +12 -2
  27. package/dist/control-write-retry.js +13 -2
  28. package/dist/control-write-retry.js.map +1 -1
  29. package/dist/delegate-admission.d.ts +11 -8
  30. package/dist/delegate-admission.js +19 -11
  31. package/dist/delegate-admission.js.map +1 -1
  32. package/dist/diagnostics/connection-path.d.ts +0 -7
  33. package/dist/diagnostics/connection-path.js +0 -7
  34. package/dist/diagnostics/connection-path.js.map +1 -1
  35. package/dist/formation-approval.d.ts +7 -0
  36. package/dist/formation-approval.js +9 -3
  37. package/dist/formation-approval.js.map +1 -1
  38. package/dist/fs-atomic.d.ts +11 -2
  39. package/dist/fs-atomic.js +13 -3
  40. package/dist/fs-atomic.js.map +1 -1
  41. package/dist/hibernation-manager.d.ts +111 -8
  42. package/dist/hibernation-manager.js +234 -49
  43. package/dist/hibernation-manager.js.map +1 -1
  44. package/dist/index.d.ts +13 -6
  45. package/dist/index.js +27 -5
  46. package/dist/index.js.map +1 -1
  47. package/dist/joined-strand-store.d.ts +177 -0
  48. package/dist/joined-strand-store.js +431 -0
  49. package/dist/joined-strand-store.js.map +1 -0
  50. package/dist/key-store-file.js +14 -5
  51. package/dist/key-store-file.js.map +1 -1
  52. package/dist/key-store.d.ts +6 -0
  53. package/dist/key-store.js.map +1 -1
  54. package/dist/link-budget.d.ts +367 -69
  55. package/dist/link-budget.js +375 -72
  56. package/dist/link-budget.js.map +1 -1
  57. package/dist/membership-connection-gater.d.ts +30 -43
  58. package/dist/membership-connection-gater.js +31 -42
  59. package/dist/membership-connection-gater.js.map +1 -1
  60. package/dist/node-local-snapshot.d.ts +5 -4
  61. package/dist/node-local-snapshot.js +6 -3
  62. package/dist/node-local-snapshot.js.map +1 -1
  63. package/dist/peer-dial.d.ts +24 -4
  64. package/dist/peer-dial.js +74 -5
  65. package/dist/peer-dial.js.map +1 -1
  66. package/dist/peer-join-backfill.d.ts +35 -15
  67. package/dist/peer-join-backfill.js +115 -55
  68. package/dist/peer-join-backfill.js.map +1 -1
  69. package/dist/push-fanout.d.ts +6 -0
  70. package/dist/push-fanout.js +6 -0
  71. package/dist/push-fanout.js.map +1 -1
  72. package/dist/relay-reservation.d.ts +3 -1
  73. package/dist/relay-reservation.js +3 -1
  74. package/dist/relay-reservation.js.map +1 -1
  75. package/dist/relay-server.d.ts +79 -0
  76. package/dist/relay-server.js +74 -0
  77. package/dist/relay-server.js.map +1 -0
  78. package/dist/seed-bootstrap.d.ts +57 -4
  79. package/dist/seed-bootstrap.js +107 -83
  80. package/dist/seed-bootstrap.js.map +1 -1
  81. package/dist/storage-scope.d.ts +33 -17
  82. package/dist/storage-scope.js +44 -23
  83. package/dist/storage-scope.js.map +1 -1
  84. package/dist/strand-addr-protocol.d.ts +58 -21
  85. package/dist/strand-addr-protocol.js +133 -85
  86. package/dist/strand-addr-protocol.js.map +1 -1
  87. package/dist/strand-database.d.ts +20 -2
  88. package/dist/strand-database.js +42 -5
  89. package/dist/strand-database.js.map +1 -1
  90. package/dist/strand-first-sync-gate.d.ts +59 -21
  91. package/dist/strand-first-sync-gate.js +58 -19
  92. package/dist/strand-first-sync-gate.js.map +1 -1
  93. package/dist/strand-formation-deadlines.d.ts +151 -0
  94. package/dist/strand-formation-deadlines.js +171 -0
  95. package/dist/strand-formation-deadlines.js.map +1 -0
  96. package/dist/strand-formation-manager.d.ts +63 -30
  97. package/dist/strand-formation-manager.js +67 -41
  98. package/dist/strand-formation-manager.js.map +1 -1
  99. package/dist/strand-formation-protocol.d.ts +45 -35
  100. package/dist/strand-formation-protocol.js +59 -122
  101. package/dist/strand-formation-protocol.js.map +1 -1
  102. package/dist/strand-instance-manager.d.ts +152 -6
  103. package/dist/strand-instance-manager.js +331 -42
  104. package/dist/strand-instance-manager.js.map +1 -1
  105. package/dist/strand-membership-writer.d.ts +6 -0
  106. package/dist/strand-membership-writer.js +11 -0
  107. package/dist/strand-membership-writer.js.map +1 -1
  108. package/dist/strand-peer-book-file.d.ts +12 -0
  109. package/dist/strand-peer-book-file.js +37 -0
  110. package/dist/strand-peer-book-file.js.map +1 -0
  111. package/dist/strand-peer-book-protocol.d.ts +168 -0
  112. package/dist/strand-peer-book-protocol.js +356 -0
  113. package/dist/strand-peer-book-protocol.js.map +1 -0
  114. package/dist/strand-peer-book-swap.d.ts +104 -0
  115. package/dist/strand-peer-book-swap.js +284 -0
  116. package/dist/strand-peer-book-swap.js.map +1 -0
  117. package/dist/strand-peer-book.d.ts +159 -0
  118. package/dist/strand-peer-book.js +361 -0
  119. package/dist/strand-peer-book.js.map +1 -0
  120. package/dist/strand-peer-observer.d.ts +88 -0
  121. package/dist/strand-peer-observer.js +180 -0
  122. package/dist/strand-peer-observer.js.map +1 -0
  123. package/dist/strand-revocation-enforcer.js +2 -1
  124. package/dist/strand-revocation-enforcer.js.map +1 -1
  125. package/dist/strand-solicitation.d.ts +36 -20
  126. package/dist/strand-solicitation.js +4 -4
  127. package/dist/strand-solicitation.js.map +1 -1
  128. package/dist/strand-wake-protocol.d.ts +80 -23
  129. package/dist/strand-wake-protocol.js +89 -64
  130. package/dist/strand-wake-protocol.js.map +1 -1
  131. package/dist/types.d.ts +181 -33
  132. package/dist/types.js +4 -3
  133. package/dist/types.js.map +1 -1
  134. package/package.json +11 -7
  135. package/src/cadre-node.ts +1316 -398
  136. package/src/control-authorization.ts +2 -1
  137. package/src/control-cohort.ts +6 -0
  138. package/src/control-database.ts +122 -18
  139. package/src/control-formation-recorder.ts +354 -305
  140. package/src/control-read-retry.ts +14 -12
  141. package/src/control-schema.ts +67 -5
  142. package/src/control-stream.ts +25 -1
  143. package/src/control-write-retry.ts +13 -2
  144. package/src/delegate-admission.ts +23 -13
  145. package/src/diagnostics/connection-path.ts +0 -7
  146. package/src/formation-approval.ts +610 -604
  147. package/src/fs-atomic.ts +14 -4
  148. package/src/hibernation-manager.ts +638 -437
  149. package/src/index.ts +91 -6
  150. package/src/joined-strand-store.ts +498 -0
  151. package/src/key-store-file.ts +14 -5
  152. package/src/key-store.ts +6 -0
  153. package/src/link-budget.ts +393 -74
  154. package/src/membership-connection-gater.ts +31 -45
  155. package/src/node-local-snapshot.ts +293 -289
  156. package/src/peer-dial.ts +81 -7
  157. package/src/peer-join-backfill.ts +120 -57
  158. package/src/push-fanout.ts +6 -0
  159. package/src/relay-reservation.ts +3 -1
  160. package/src/relay-server.ts +98 -0
  161. package/src/seed-bootstrap.ts +133 -91
  162. package/src/storage-scope.ts +44 -23
  163. package/src/strand-addr-protocol.ts +547 -458
  164. package/src/strand-database.ts +287 -242
  165. package/src/strand-first-sync-gate.ts +58 -19
  166. package/src/strand-formation-deadlines.ts +227 -0
  167. package/src/strand-formation-manager.ts +700 -647
  168. package/src/strand-formation-protocol.ts +103 -150
  169. package/src/strand-instance-manager.ts +387 -45
  170. package/src/strand-membership-writer.ts +12 -0
  171. package/src/strand-peer-book-file.ts +39 -0
  172. package/src/strand-peer-book-protocol.ts +466 -0
  173. package/src/strand-peer-book-swap.ts +338 -0
  174. package/src/strand-peer-book.ts +475 -0
  175. package/src/strand-peer-observer.ts +235 -0
  176. package/src/strand-revocation-enforcer.ts +2 -1
  177. package/src/strand-solicitation.ts +519 -500
  178. package/src/strand-wake-protocol.ts +401 -355
  179. package/src/types.ts +185 -33
@@ -19,13 +19,14 @@
19
19
  */
20
20
  import debug from 'debug';
21
21
  import { multiaddr } from '@multiformats/multiaddr';
22
- import { writeFrame, withTimeout } from './control-stream.js';
22
+ import { writeFrame, withDeadline, withTimeout } from './control-stream.js';
23
23
  import { canonicalJson } from './canonical-json.js';
24
24
  import { requireEd25519PublicKeyB64 } from './ed25519-key.js';
25
25
  import { verifyFormationConsent } from './peer-authorization.js';
26
26
  // seed-bootstrap imports neither this protocol nor the manager/solicitation layers,
27
27
  // so this import introduces no cycle.
28
28
  import { ed25519PublicKeyB64FromPeerId } from './seed-bootstrap.js';
29
+ import { formationDeadlines, resolveProvisionTimeoutMs, responderClampReserveMs, splitProvisionBudget } from './strand-formation-deadlines.js';
29
30
  const log = debug('sereus:cadre:formation-proto');
30
31
  /** Protocol id for the native formation transport (parallel to `/sereus/seed/1.0.0`). */
31
32
  export const FORMATION_PROTOCOL = '/sereus/formation/1.0.0';
@@ -39,66 +40,16 @@ export const FORMATION_PROTOCOL = '/sereus/formation/1.0.0';
39
40
  export const INVALID_TOKEN_REASON = 'Invalid token';
40
41
  /** Maximum formation message size (1MB). */
41
42
  const MAX_FORMATION_MSG_SIZE = 1024 * 1024;
42
- /** Default whole-session timeout (ms). */
43
- const DEFAULT_SESSION_TIMEOUT_MS = 30000;
44
- /** Default per-step (single read/write) timeout (ms). */
45
- const DEFAULT_STEP_TIMEOUT_MS = 5000;
46
- /**
47
- * Default provisioning budget (ms) — distinct from {@link DEFAULT_STEP_TIMEOUT_MS} because
48
- * `provisionStrand` is real work (DB writes, and an outbound approval-hook HTTP call when
49
- * the invite carries a `ValidationUrl`), not a bare wire read/write.
50
- *
51
- * Ordering is deliberate — each layer must be able to fail and report before the layer above
52
- * it gives up:
53
- *
54
- * approval hook (10 s, `formation-approval.ts`)
55
- * < responder provisioning (12 s)
56
- * < initiator await-response (15 s)
57
- * < session (30 s)
58
- *
59
- * The 3 s margin between responder provisioning and initiator await-response is the wire
60
- * latency budget for the result frame to travel back.
61
- *
62
- * The last {@link PROVISION_SETTLE_GRACE_MS} of this budget is a settle grace, so the default
63
- * WORK budget (12 s − 2 s = 10 s) EQUALS the hook's own 10 s: a dead hook races 'Formation
64
- * approval unavailable, retry' against 'Formation provisioning timed out'. Both are retryable
65
- * and both leave the invite unspent, so the race is benign.
66
- */
67
- const DEFAULT_PROVISION_TIMEOUT_MS = 12000;
68
- /**
69
- * Settle grace (ms), carved OUT of `provisionTimeoutMs` — never added on top, so the budget
70
- * ladder above is untouched. The listener aborts the provisioning hook when the work budget
71
- * ({@link splitProvisionBudget}) expires, then waits up to this grace for the work to settle
72
- * anyway: once the `FormationUsage` insert has been issued nothing can un-spend it (the table
73
- * is append-only), so a provisioning that lands late is ADOPTED and reported as a real
74
- * approval rather than lying "timed out" over a spent invite. A hook that observes the
75
- * abort before writing leaves the invite unspent.
76
- */
77
- const PROVISION_SETTLE_GRACE_MS = 2000;
78
- /**
79
- * Wire-latency margin (ms) added to the responder's provisioning budget to get the
80
- * initiator's await-response budget — the travel time for the result frame to come back
81
- * after the responder finishes (see {@link DEFAULT_PROVISION_TIMEOUT_MS}).
82
- * `StrandFormationManager` reuses this constant so a CONFIGURED budget preserves the same
83
- * margin the defaults do, instead of applying the same number to both sides and racing the
84
- * initiator's own timeout against the responder's clean rejection reply. The responder's
85
- * clamp ({@link provisionCeilingMs}) holds the same margin back, so the ordering survives a
86
- * budget large enough that BOTH roles get clamped.
87
- *
88
- * NOTE: 3 s is a fixed assumption about how long the result frame takes to travel back. If
89
- * formation ever runs over paths where that frame can take longer (a slow circuit relay, a
90
- * congested mobile link), the margin is too thin and the initiator's timeout races the
91
- * responder's reply again — raise it, or derive it from an observed round-trip.
92
- */
93
- export const PROVISION_RESPONSE_TRAVEL_MARGIN_MS = 3000;
94
- /** Default initiator await-response budget (ms); see {@link DEFAULT_PROVISION_TIMEOUT_MS}. */
95
- const DEFAULT_INITIATOR_PROVISION_TIMEOUT_MS = DEFAULT_PROVISION_TIMEOUT_MS + PROVISION_RESPONSE_TRAVEL_MARGIN_MS;
96
43
  /**
97
44
  * Default cap on concurrent inbound formation sessions.
98
- * NOTE: a longer provisioning budget holds a session's slot longer, so a slow hook can
99
- * exhaust this cap and make the listener reject fresh joiners with 'Too many concurrent
100
- * formation sessions'. Fine at the current default; revisit if `provisionTimeoutMs` is
101
- * raised well above its default or this cap is lowered.
45
+ *
46
+ * NOTE: a session holds its slot for its whole provisioning budget, 171 s at the default
47
+ * declared link ({@link formationDeadlines}), so a slow hook or commit holds slots for
48
+ * minutes. Only a caller holding a valid token AND a valid consent signature reaches
49
+ * provisioning — a stranger is cut at the contact wait (7 s at the default) or at the first
50
+ * validation read — so the exposure is one invitee opening many sessions with one token. If
51
+ * invitation tokens are ever published where untrusted parties can read them, cap in-flight
52
+ * sessions per token rather than lowering this.
102
53
  */
103
54
  const DEFAULT_MAX_CONCURRENT_SESSIONS = 100;
104
55
  /**
@@ -264,49 +215,6 @@ export function isValidResponderCreatesResult(response) {
264
215
  }
265
216
  return true;
266
217
  }
267
- /**
268
- * Ceiling for a resolved provisioning budget.
269
- *
270
- * The session budget also has to cover the wire step that PRECEDES provisioning (the
271
- * responder's contact read, the initiator's dial-connect), so a whole step is held back
272
- * rather than triggering only on a literal overrun.
273
- *
274
- * `reserveMs` is the EXTRA room only the responder holds back, so its own budget still
275
- * lands strictly before the initiator's larger await-response budget even when both are
276
- * clamped — without it, any configured budget at or above `sessionTimeoutMs -
277
- * stepTimeoutMs` clamps both roles onto the same number and the responder's clean
278
- * rejection races the initiator's timeout again. Capped at half the remaining room (like
279
- * {@link splitProvisionBudget}) so a small session config still spends most of it working.
280
- */
281
- function provisionCeilingMs(sessionTimeoutMs, stepTimeoutMs, reserveMs) {
282
- const roomMs = sessionTimeoutMs - stepTimeoutMs;
283
- return Math.max(1, roomMs - Math.min(reserveMs, Math.floor(roomMs / 2)));
284
- }
285
- /**
286
- * Resolve a caller-supplied provisioning budget: `0`/negative means "unset" (use
287
- * `defaultMs`). If the result would let provisioning outlive the session — no result
288
- * frame is ever sent, exactly the failure this budget exists to prevent — clamp it to
289
- * {@link provisionCeilingMs} and log a warning.
290
- */
291
- function resolveProvisionTimeoutMs(configured, defaultMs, sessionTimeoutMs, stepTimeoutMs, role, reserveMs = 0) {
292
- const requested = configured && configured > 0 ? configured : defaultMs;
293
- const ceilingMs = provisionCeilingMs(sessionTimeoutMs, stepTimeoutMs, reserveMs);
294
- if (requested >= ceilingMs) {
295
- log('%s provisionTimeoutMs %dms leaves no room under sessionTimeoutMs %dms (step %dms, reserve %dms); clamping to %dms', role, requested, sessionTimeoutMs, stepTimeoutMs, reserveMs, ceilingMs);
296
- return ceilingMs;
297
- }
298
- return requested;
299
- }
300
- /**
301
- * Split a resolved provisioning budget into the WORK budget and the trailing settle grace.
302
- *
303
- * The grace is carved OUT of the budget (see {@link PROVISION_SETTLE_GRACE_MS}), and capped at
304
- * half of it so a small configured budget still spends at least half its time doing work.
305
- */
306
- function splitProvisionBudget(provisionTimeoutMs) {
307
- const graceMs = Math.min(PROVISION_SETTLE_GRACE_MS, Math.floor(provisionTimeoutMs / 2));
308
- return { workMs: provisionTimeoutMs - graceMs, graceMs };
309
- }
310
218
  /**
311
219
  * Responder side of the native formation protocol. Registers a libp2p handler and
312
220
  * drives each inbound stream through token + disclosure validation, provisioning,
@@ -319,9 +227,10 @@ export class FormationListener {
319
227
  this.activeSessions = 0;
320
228
  this.sessionCounter = 0;
321
229
  this.options = options;
322
- this.sessionTimeoutMs = options.sessionTimeoutMs ?? DEFAULT_SESSION_TIMEOUT_MS;
323
- this.stepTimeoutMs = options.stepTimeoutMs ?? DEFAULT_STEP_TIMEOUT_MS;
324
- const split = splitProvisionBudget(resolveProvisionTimeoutMs(options.provisionTimeoutMs, DEFAULT_PROVISION_TIMEOUT_MS, this.sessionTimeoutMs, this.stepTimeoutMs, 'FormationListener', PROVISION_RESPONSE_TRAVEL_MARGIN_MS));
230
+ const deadlines = formationDeadlines(options.linkRoundTripMs);
231
+ this.sessionTimeoutMs = options.sessionTimeoutMs ?? deadlines.sessionMs;
232
+ this.awaitContactMs = options.stepTimeoutMs ?? deadlines.awaitContactMs;
233
+ const split = splitProvisionBudget(resolveProvisionTimeoutMs(options.provisionTimeoutMs, deadlines.provisionWorkMs + deadlines.provisionGraceMs, this.sessionTimeoutMs, this.awaitContactMs + deadlines.validationMs, 'FormationListener', responderClampReserveMs(deadlines, this.awaitContactMs)), deadlines.provisionGraceMs);
325
234
  this.provisionWorkMs = split.workMs;
326
235
  this.provisionGraceMs = split.graceMs;
327
236
  this.maxConcurrentSessions = options.maxConcurrentSessions ?? DEFAULT_MAX_CONCURRENT_SESSIONS;
@@ -330,21 +239,22 @@ export class FormationListener {
330
239
  get activeCount() {
331
240
  return this.activeSessions;
332
241
  }
333
- register(node, protocolId = FORMATION_PROTOCOL) {
242
+ /** Register the formation handler on `node`. Rejects when libp2p refuses the registration. */
243
+ async register(node, protocolId = FORMATION_PROTOCOL) {
334
244
  if (this.registered.has(node)) {
335
245
  log('node already registered');
336
246
  return;
337
247
  }
338
- void node.handle(protocolId, async (rawStream, _connection) => {
248
+ await node.handle(protocolId, async (rawStream, _connection) => {
339
249
  await this.handleStream(rawStream);
340
250
  });
341
251
  this.registered.add(node);
342
252
  log('formation listener registered (%s)', protocolId);
343
253
  }
344
- unregister(node, protocolId = FORMATION_PROTOCOL) {
254
+ async unregister(node, protocolId = FORMATION_PROTOCOL) {
345
255
  if (!this.registered.has(node))
346
256
  return;
347
- void node.unhandle(protocolId);
257
+ await node.unhandle(protocolId);
348
258
  this.registered.delete(node);
349
259
  log('formation listener unregistered (%s)', protocolId);
350
260
  }
@@ -378,8 +288,8 @@ export class FormationListener {
378
288
  }
379
289
  }
380
290
  /**
381
- * Run the provisioning hook under its WORK budget — the configured provisioning budget minus
382
- * the trailing settle grace ({@link splitProvisionBudget}, {@link PROVISION_SETTLE_GRACE_MS}).
291
+ * Run the provisioning hook under its WORK budget — the provisioning budget minus the
292
+ * trailing settle grace ({@link splitProvisionBudget}).
383
293
  *
384
294
  * When the work budget expires the hook's signal is aborted, then
385
295
  * {@link settleWithinGrace} waits out the grace for the aborted work to settle anyway.
@@ -412,11 +322,16 @@ export class FormationListener {
412
322
  * inside the grace its outcome is ADOPTED — the joiner is told the truth (approved, or the
413
323
  * hook's own rejection reason) rather than "timed out" over a spent invite.
414
324
  *
415
- * NOTE: one window stays open — a work budget that expires after the `FormationUsage`
416
- * insert was issued AND a commit that outlasts the grace. The joiner is told 'timed out'
417
- * while its one-time invite is in fact spent, and since every retry mints a fresh keypair
418
- * no recovery path can match it. Nothing can un-spend an append-only row, so the late-settle
419
- * logging below is the observability for it; widen the grace only if it is seen in the wild.
325
+ * The grace is derived to contain one seat read plus one commit at the declared link
326
+ * ({@link formationDeadlines}), which is exactly what runs after the insert attempt passes
327
+ * its abort check, so at that link the late outcome lands inside it.
328
+ *
329
+ * NOTE: a commit that outlasts even the derived grace (a link slower than declared, or a
330
+ * configured `provisionTimeoutMs` whose half-cap shrank the grace) still tells the joiner
331
+ * 'timed out' while its one-time invite is in fact spent, and since every retry mints a
332
+ * fresh keypair no recovery path can match it. Nothing can un-spend an append-only row, so
333
+ * the late-settle logging below is the observability for it; if it is seen in the wild,
334
+ * raise the declared link rather than this grace.
420
335
  */
421
336
  async settleWithinGrace(id, pending) {
422
337
  let stillPending = false;
@@ -507,7 +422,7 @@ export class FormationListener {
507
422
  };
508
423
  try {
509
424
  const reader = new FrameReader(stream);
510
- const contact = await withTimeout(this.stepTimeoutMs, `Formation await-contact#${id}`, () => reader.read());
425
+ const contact = await withTimeout(this.awaitContactMs, `Formation await-contact#${id}`, () => reader.read());
511
426
  log('formation session #%d contact: token=%s party=%s', id, contact.token, contact.partyId);
512
427
  if (!this.isJoinerConsentValid(id, contact)) {
513
428
  send({ approved: false, reason: 'Invalid joiner consent' });
@@ -568,6 +483,28 @@ export class FormationListener {
568
483
  }
569
484
  }
570
485
  }
486
+ /**
487
+ * Open the formation stream under the dial deadline, cancelling the dial when it expires.
488
+ *
489
+ * The deadline's signal goes into `dialProtocol`, so an expired dial is abandoned by libp2p
490
+ * rather than left running. A dial that settles in the same tick the deadline fires loses
491
+ * the race to the timeout rejection and would leave its stream open with nobody to close
492
+ * it, so a stream that arrives after the signal aborted is reset here — the same treatment
493
+ * `exchangeFrame` (`control-stream.ts`) gives a stream dialed past its deadline. A late
494
+ * rejection is the abort itself, or reaches the caller through the awaited copy, so the
495
+ * handler below only stops it being reported as unhandled.
496
+ */
497
+ function openFormationStream(node, addr, protocolId, dialTimeoutMs) {
498
+ return withDeadline(dialTimeoutMs, 'Formation dial-connect', (signal) => {
499
+ const pending = node.dialProtocol(addr, protocolId, { signal });
500
+ void pending.then((stream) => {
501
+ if (signal.aborted) {
502
+ stream.abort(new Error('Formation dial-connect resolved after its deadline'));
503
+ }
504
+ }, () => { });
505
+ return pending;
506
+ });
507
+ }
571
508
  /**
572
509
  * Initiator side of the native formation protocol. Dials the responder, sends the
573
510
  * contact (carrying the real disclosure/token/cadre), validates the responder's
@@ -579,13 +516,13 @@ export async function dialFormation(node, options) {
579
516
  throw new Error('No responder addresses available for formation');
580
517
  }
581
518
  const protocolId = options.protocolId ?? FORMATION_PROTOCOL;
582
- const sessionTimeoutMs = options.sessionTimeoutMs ?? DEFAULT_SESSION_TIMEOUT_MS;
583
- const stepTimeoutMs = options.stepTimeoutMs ?? DEFAULT_STEP_TIMEOUT_MS;
584
- const provisionTimeoutMs = resolveProvisionTimeoutMs(options.provisionTimeoutMs, DEFAULT_INITIATOR_PROVISION_TIMEOUT_MS, sessionTimeoutMs, stepTimeoutMs, 'dialFormation');
519
+ const deadlines = formationDeadlines(options.linkRoundTripMs);
520
+ const sessionTimeoutMs = options.sessionTimeoutMs ?? deadlines.sessionMs;
521
+ const dialTimeoutMs = options.dialTimeoutMs ?? deadlines.dialMs;
522
+ const provisionTimeoutMs = resolveProvisionTimeoutMs(options.provisionTimeoutMs, deadlines.initiatorAwaitResponseMs, sessionTimeoutMs, dialTimeoutMs, 'dialFormation');
585
523
  const addr = multiaddr(options.responderAddrs[0]);
586
524
  return withTimeout(sessionTimeoutMs, 'Formation dial', async () => {
587
- const rawStream = await withTimeout(stepTimeoutMs, 'Formation dial-connect', async () => node.dialProtocol(addr, protocolId));
588
- const stream = rawStream;
525
+ const stream = await openFormationStream(node, addr, protocolId, dialTimeoutMs);
589
526
  try {
590
527
  const reader = new FrameReader(stream);
591
528
  writeFrame(stream, options.contact);
@@ -1 +1 @@
1
- {"version":3,"file":"strand-formation-protocol.js","sourceRoot":"","sources":["../src/strand-formation-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,EAAsB,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,oFAAoF;AACpF,sCAAsC;AACtC,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,MAAM,GAAG,GAAG,KAAK,CAAC,8BAA8B,CAAC,CAAC;AAElD,yFAAyF;AACzF,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AAE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CAAC,EAAE,CAAC;QACzG,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC;gBAAC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,5 +1,7 @@
1
1
  import type { PrivateKey } from '@libp2p/interface';
2
2
  import { type PeerJoinBackfillConfig } from './peer-join-backfill.js';
3
+ import { type StrandPeerObservation } from './strand-peer-observer.js';
4
+ import type { StrandPeerBookStore } from './strand-peer-book.js';
3
5
  import { type StrandRevocationEnforcementConfig } from './strand-revocation-enforcer.js';
4
6
  import { type PendingMembershipInviteSource, type StrandMembershipReconciliationConfig } from './strand-membership-reconciler.js';
5
7
  import { type StrandFirstSyncConfig } from './strand-first-sync-gate.js';
@@ -32,8 +34,15 @@ export declare function liveStrandStatus(instance: StrandInstance): 'active' | '
32
34
  */
33
35
  export interface StartStrandConfig {
34
36
  strandRow: StrandRow;
35
- /** sApp configuration provided by the hosting application */
36
- sAppConfig: SAppConfig;
37
+ /**
38
+ * sApp configuration provided by the hosting application. Absent for a **storage
39
+ * replica** — a strand this node stores and serves without the app installed
40
+ * (`CadreNodeConfig.hostUnclaimedStrands`): no schema signature check, no `App`
41
+ * schema, no `sAppInfo` on the instance, and the default latency hint. A replica is
42
+ * always a joiner; `StrandDatabase` refuses to found one. An app that later claims the
43
+ * strand upgrades the running replica in place ({@link StrandInstanceManager.attachSApp}).
44
+ */
45
+ sAppConfig?: SAppConfig;
37
46
  storage?: StorageConfig;
38
47
  network?: NetworkConfig;
39
48
  profile: NodeProfile;
@@ -200,6 +209,26 @@ export interface StartStrandConfig {
200
209
  * hibernation wake's rebuilt supervisors carry it too.
201
210
  */
202
211
  announceDelegateToRelay?: (strandId: string, relayAddr: string, delegatePeerId: string) => Promise<void>;
212
+ /**
213
+ * Called when the strand's libp2p node identifies a STRAND peer — one whose
214
+ * identify result names this strand's block-transfer protocol, so never the
215
+ * circuit relay or a bootstrap node — with the addresses it is dialable at
216
+ * (`strand-peer-observer.ts`). Throttled per peer; must not throw. `CadreNode`
217
+ * wires it to the node-local strand peer book, which is what lets a restarted
218
+ * machine dial the peers it was talking to. Absent ⇒ nothing is observed.
219
+ * Retained with the launch config, so a hibernation wake re-arms it on the
220
+ * rebuilt node.
221
+ */
222
+ onStrandPeerIdentified?: (strandId: string, observation: StrandPeerObservation) => void;
223
+ /**
224
+ * The node-local strand peer book the book SWAP reads and writes
225
+ * (`strand-peer-book-swap.ts`): the strand node signs its own addresses with
226
+ * {@link privateKey}, exchanges signed entries with every strand peer it identifies,
227
+ * and files what verifies. Absent ⇒ no swap runs — a peer that dials this node's
228
+ * swap handler gets no answer. `CadreNode` passes its book store. Retained with the
229
+ * launch config, so a hibernation wake re-arms the swap on the rebuilt node.
230
+ */
231
+ strandPeerBook?: StrandPeerBookStore;
203
232
  }
204
233
  /**
205
234
  * Volatile inputs re-resolved when resuming a quiesced strand — the ones that can
@@ -259,6 +288,23 @@ export declare class StrandInstanceManager {
259
288
  * missed writes).
260
289
  */
261
290
  private backfills;
291
+ /**
292
+ * The per-strand peer-book observation writer (`strand-peer-observer.ts`), keyed
293
+ * by strand id. Same lifecycle rationale as {@link backfills}: started in
294
+ * `buildStrandRuntime` right after the libp2p node exists, stopped and dropped in
295
+ * `releaseRuntime`, so quiesce → resume re-arms it on the rebuilt node. Only
296
+ * present when the launch config supplied `onStrandPeerIdentified`.
297
+ */
298
+ private peerObservers;
299
+ /**
300
+ * Per-strand strand peer book SWAP driver ({@link StrandPeerBookSwap}) — the signed
301
+ * exchange of book entries between strand peers. Same lifetime as the peer-book
302
+ * observer above: armed in `buildStrandRuntime` right after the libp2p node exists
303
+ * (its protocol handler must be registered before an early peer dials it), stopped
304
+ * and dropped in `releaseRuntime`. Only present when the launch config supplied
305
+ * `strandPeerBook`.
306
+ */
307
+ private peerBookSwaps;
262
308
  /**
263
309
  * The per-strand revoked-peer enforcer (closed strands only), keyed by strand
264
310
  * id. Same lifecycle rationale as {@link backfills}: created in
@@ -325,6 +371,23 @@ export declare class StrandInstanceManager {
325
371
  * wake becomes the better trade.
326
372
  */
327
373
  private strandStorages;
374
+ /**
375
+ * The runtime build in flight per strand id (`buildStrandRuntime`, from `startStrand` or
376
+ * `resumeStrand`), present until it settles. The instance is tracked for the whole build,
377
+ * with its database not yet constructed or not yet initialized, so a caller that must act
378
+ * on the FINISHED runtime ({@link attachSApp}, {@link whenRuntimeBuilt}) waits on this instead. A failed build's
379
+ * rejection belongs to the call that started it.
380
+ */
381
+ private runtimeBuilds;
382
+ /**
383
+ * The latest resume or quiesce requested per strand id, present until it settles. Each one
384
+ * starts only once the one requested before it has settled, so a wake that lands during a
385
+ * quiesce rebuilds after it, and a quiesce requested during a rebuild releases what that
386
+ * rebuild finished. The WHOLE operation, not its entry in {@link runtimeBuilds}: that settles
387
+ * before a resume's own catch records `'error'`, so a joiner awaiting it could read a stale
388
+ * status.
389
+ */
390
+ private transitions;
328
391
  private stopping;
329
392
  constructor();
330
393
  /**
@@ -356,6 +419,18 @@ export declare class StrandInstanceManager {
356
419
  * hibernation wake never re-enters the embedder's provider.
357
420
  */
358
421
  startStrand(config: StartStrandConfig): Promise<StrandInstance>;
422
+ /** Hold `build` in {@link runtimeBuilds} until it settles, and settle as it does. */
423
+ private trackRuntimeBuild;
424
+ /**
425
+ * Wait until no runtime build of `strandId` is in flight. Never rejects: a failed build
426
+ * is reported by the call that started it, and the caller re-reads the instance after.
427
+ *
428
+ * NOTE: after a failed launch the re-read sees the instance gone only because
429
+ * `startStrand`'s catch deletes it synchronously, and its continuation is queued before
430
+ * this waiter's. If that cleanup ever awaits before `instances.delete`, a waiter can act
431
+ * on the dying record; move the cleanup inside the tracked promise then.
432
+ */
433
+ private settleRuntimeBuilds;
359
434
  /**
360
435
  * Build (or rebuild) the libp2p node + StrandDatabase for an instance and
361
436
  * attach them, transitioning it to `active`. Shared by `startStrand` (fresh
@@ -470,11 +545,26 @@ export declare class StrandInstanceManager {
470
545
  * Quiesce a strand: release its strand-network resources (stop the libp2p node,
471
546
  * close the StrandDatabase) while RETAINING the instance record — identity,
472
547
  * sAppInfo, keys, latency hint, metadata — and its launch config so it can be
473
- * resumed later. Mechanically this is `stopStrand` minus the instance/config
474
- * deletion. The caller sets the post-quiesce status (e.g. `hibernating`).
475
- * No-ops when the strand is missing or already quiesced.
548
+ * resumed later, then mark it `hibernating`. Mechanically this is `stopStrand` minus
549
+ * the instance/config deletion. A tracked strand with no runtime left (a failed
550
+ * rebuild already released it) is only marked; an untracked one is left alone.
551
+ *
552
+ * Ordered with {@link resumeStrand} (see {@link transitions}): it starts once the resume
553
+ * or launch build before it has settled, so it releases a finished runtime, and the
554
+ * status write is its last step, so a resume requested meanwhile writes after it. A call
555
+ * made while another quiesce is the latest request joins it. A failed release leaves the
556
+ * status as it was and rejects.
476
557
  */
477
558
  quiesceStrand(strandId: string): Promise<void>;
559
+ /** Body of {@link quiesceStrand}. */
560
+ private runQuiesce;
561
+ /**
562
+ * Whether the latest runtime transition requested for `strandId` is a quiesce that has
563
+ * not finished. Its handles may still be attached and its status still live, but it is on
564
+ * its way to `hibernating`, so a caller that needs it up must {@link resumeStrand} it — the
565
+ * resume runs after the quiesce — rather than treat it as live.
566
+ */
567
+ isQuiescing(strandId: string): boolean;
478
568
  /**
479
569
  * Resume a previously-quiesced strand: rebuild its libp2p node + StrandDatabase
480
570
  * from the retained launch config and re-attach them, transitioning it back to
@@ -482,8 +572,22 @@ export declare class StrandInstanceManager {
482
572
  * launch (the cohort `bootstrapNodes` seed and the strand's `servingMachines`
483
573
  * count) and updates the retained config so a later resume reuses the latest
484
574
  * values. Returns the live instance unchanged if it is already running.
575
+ *
576
+ * Overlapping calls share one rebuild: a call made while a resume is the latest request
577
+ * for the strand — a wake landing during a check-in — joins it and settles exactly as it
578
+ * does, `'error'` status included. The joiner's own `overrides` are ignored; the first
579
+ * resume's seed wins, and both callers resolved the cohort seed moments apart. A call made
580
+ * while a quiesce is the latest request runs after that quiesce and rebuilds (see
581
+ * {@link transitions}), and one made while `startStrand` is still building waits for that
582
+ * build rather than starting a second.
485
583
  */
486
584
  resumeStrand(strandId: string, overrides?: ResumeStrandOverrides): Promise<StrandInstance>;
585
+ /** Record `transition` as the latest for `strandId` until it settles. */
586
+ private holdTransition;
587
+ /** Wait for the transition requested before this one. Never rejects: its failure belongs to its caller. */
588
+ private settleTransition;
589
+ /** Body of {@link resumeStrand}; at most one runs per strand at a time. */
590
+ private runResume;
487
591
  /**
488
592
  * Honor a founder request against an ALREADY-TRACKED strand — the seam that
489
593
  * closes the "whoever launches first decides whether the bootstrap runs" gap:
@@ -500,7 +604,8 @@ export declare class StrandInstanceManager {
500
604
  * - `'already-founder'` — the retained config already founds; nothing to do.
501
605
  * - `'bootstrapped'` — config flipped and the live database ran the bootstrap.
502
606
  * - `'needs-resume'` — config flipped, but the instance is quiesced (no live
503
- * database), so the bootstrap could not run here: the CALLER must wake the
607
+ * database) or being quiesced (its database is closing), so the bootstrap could
608
+ * not run here: the CALLER must wake the
504
609
  * strand (`CadreNode.wakeStrand`, which owns the hibernation bookkeeping this
505
610
  * manager does not) so the rebuild — which now founds — runs it.
506
611
  * @param resolvePartyKey - Asked for the party's own membership key when (and only
@@ -516,6 +621,39 @@ export declare class StrandInstanceManager {
516
621
  * whose `'needs-resume'` wake fails owes the same withdrawal.
517
622
  */
518
623
  foundExistingStrand(strandId: string, resolvePartyKey?: () => Promise<string | undefined>): Promise<'already-founder' | 'bootstrapped' | 'needs-resume'>;
624
+ /**
625
+ * Give a tracked storage replica ({@link StartStrandConfig.sAppConfig} absent) the app's
626
+ * schema in place — the seam for an app on this machine claiming a strand this node was
627
+ * already hosting. No runtime rebuild: the libp2p node, its peer id and connections, the
628
+ * store and its warm cache all stay, and the new `App` tables read the blocks the replica
629
+ * already holds. Callers attach BEFORE {@link foundExistingStrand}: the founder bootstrap
630
+ * writes the sApp into `Strand.Header` and refuses a database that has none.
631
+ *
632
+ * A runtime build in flight (the replica's launch, or a hibernation wake) is waited out
633
+ * first, so the attach acts on the database that build produced. Then, in order: the
634
+ * schema signature is checked before anything changes; the retained launch config takes
635
+ * the sApp, so every later rebuild applies it through `composeStrand`; the live database —
636
+ * published, or still held by the first-sync gate — gets the schema; and only then does
637
+ * the instance record `sAppInfo` and the sApp's latency hint. A quiesced instance gets the
638
+ * config alone, and its next resume applies the schema.
639
+ *
640
+ * @returns `'already-attached'` when the instance already runs an sApp — a DIFFERENT one
641
+ * is logged and left as it is, as a second claim of a claimed strand always has been —
642
+ * else `'attached'`.
643
+ * @throws when the strand is not tracked (a caller bug, or a launch that failed while
644
+ * this waited on it); when the schema signature is refused, having changed nothing; and
645
+ * whatever the live apply throws (e.g. a quiesce closed the database mid-apply) — the
646
+ * retained config then still carries the sApp and `sAppInfo` stays unset, so the next
647
+ * claim retries the apply.
648
+ *
649
+ * NOTE: two claims of one replica racing each other both pass the `sAppInfo` check and
650
+ * apply concurrently; the loser of the declarative diff can reject, and its `addStrand`
651
+ * retry then resolves `'already-attached'`. Needs an app calling `addStrand` twice at once
652
+ * (or beside a watcher retry); if it is ever seen, chain attaches per strand id.
653
+ */
654
+ attachSApp(strandId: string, sAppConfig: SAppConfig, options?: {
655
+ requireSignedSchemas?: boolean;
656
+ }): Promise<'attached' | 'already-attached'>;
519
657
  /**
520
658
  * Whether `strandId` is launched but still waiting for its first sync — a joiner whose
521
659
  * runtime is up while its database is withheld (status `'syncing'`, or `'idle'` after
@@ -536,6 +674,14 @@ export declare class StrandInstanceManager {
536
674
  whenWritable(strandId: string, options?: {
537
675
  timeoutMs?: number;
538
676
  }): Promise<StrandInstance>;
677
+ /**
678
+ * The tracked instance once no runtime build of it is in flight, or `undefined` when none
679
+ * is tracked by then — never launched, or the launch waited on failed and dropped its
680
+ * record. For a caller about to hand a tracked instance to an app: until its build settles
681
+ * the instance is `'starting'` with no database, and a failed launch leaves no instance.
682
+ * Never rejects; a failed build is reported by the call that started it.
683
+ */
684
+ whenRuntimeBuilt(strandId: string): Promise<StrandInstance | undefined>;
539
685
  /**
540
686
  * Hand a launch's database to the app: set `instance.database`, retire the gate that
541
687
  * held it, release every {@link whenWritable} waiter, and — when the launch had already