@serfab/cadre-core 0.9.0 → 0.10.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 (162) hide show
  1. package/README.md +4 -2
  2. package/dist/bootstrap-peer-store-file.d.ts +13 -0
  3. package/dist/bootstrap-peer-store-file.js +42 -0
  4. package/dist/bootstrap-peer-store-file.js.map +1 -0
  5. package/dist/bootstrap-peer-store.d.ts +73 -0
  6. package/dist/bootstrap-peer-store.js +128 -0
  7. package/dist/bootstrap-peer-store.js.map +1 -0
  8. package/dist/cadre-node.d.ts +918 -53
  9. package/dist/cadre-node.js +1843 -190
  10. package/dist/cadre-node.js.map +1 -1
  11. package/dist/control-authorization.d.ts +93 -0
  12. package/dist/control-authorization.js +57 -0
  13. package/dist/control-authorization.js.map +1 -0
  14. package/dist/control-database.d.ts +990 -50
  15. package/dist/control-database.js +1459 -108
  16. package/dist/control-database.js.map +1 -1
  17. package/dist/control-formation-recorder.d.ts +89 -10
  18. package/dist/control-formation-recorder.js +129 -14
  19. package/dist/control-formation-recorder.js.map +1 -1
  20. package/dist/control-schema.d.ts +1 -1
  21. package/dist/control-schema.js +774 -210
  22. package/dist/control-schema.js.map +1 -1
  23. package/dist/control-stream.d.ts +38 -4
  24. package/dist/control-stream.js +70 -4
  25. package/dist/control-stream.js.map +1 -1
  26. package/dist/control-write-retry.d.ts +151 -0
  27. package/dist/control-write-retry.js +411 -0
  28. package/dist/control-write-retry.js.map +1 -0
  29. package/dist/delegate-admission.d.ts +134 -0
  30. package/dist/delegate-admission.js +244 -0
  31. package/dist/delegate-admission.js.map +1 -0
  32. package/dist/device-token.d.ts +11 -11
  33. package/dist/device-token.js +14 -13
  34. package/dist/device-token.js.map +1 -1
  35. package/dist/ed25519-key.d.ts +26 -0
  36. package/dist/ed25519-key.js +56 -1
  37. package/dist/ed25519-key.js.map +1 -1
  38. package/dist/file-durable-slot.d.ts +20 -0
  39. package/dist/file-durable-slot.js +53 -0
  40. package/dist/file-durable-slot.js.map +1 -0
  41. package/dist/formation-approval.d.ts +157 -0
  42. package/dist/formation-approval.js +375 -0
  43. package/dist/formation-approval.js.map +1 -0
  44. package/dist/fs-atomic.d.ts +38 -0
  45. package/dist/fs-atomic.js +97 -0
  46. package/dist/fs-atomic.js.map +1 -0
  47. package/dist/identity-key.d.ts +49 -0
  48. package/dist/identity-key.js +81 -0
  49. package/dist/identity-key.js.map +1 -0
  50. package/dist/index.d.ts +16 -6
  51. package/dist/index.js +39 -5
  52. package/dist/index.js.map +1 -1
  53. package/dist/key-store-file.d.ts +2 -24
  54. package/dist/key-store-file.js +10 -77
  55. package/dist/key-store-file.js.map +1 -1
  56. package/dist/membership-connection-gater.d.ts +146 -0
  57. package/dist/membership-connection-gater.js +180 -0
  58. package/dist/membership-connection-gater.js.map +1 -0
  59. package/dist/node-local-snapshot.d.ts +109 -0
  60. package/dist/node-local-snapshot.js +182 -0
  61. package/dist/node-local-snapshot.js.map +1 -0
  62. package/dist/peer-authorization.d.ts +135 -18
  63. package/dist/peer-authorization.js +152 -21
  64. package/dist/peer-authorization.js.map +1 -1
  65. package/dist/peer-record.d.ts +21 -8
  66. package/dist/peer-record.js +26 -10
  67. package/dist/peer-record.js.map +1 -1
  68. package/dist/relay-addrs.d.ts +45 -0
  69. package/dist/relay-addrs.js +103 -0
  70. package/dist/relay-addrs.js.map +1 -0
  71. package/dist/relay-reservation.d.ts +266 -0
  72. package/dist/relay-reservation.js +613 -0
  73. package/dist/relay-reservation.js.map +1 -0
  74. package/dist/seed-bootstrap.d.ts +221 -56
  75. package/dist/seed-bootstrap.js +328 -188
  76. package/dist/seed-bootstrap.js.map +1 -1
  77. package/dist/seed-trust-policy.d.ts +47 -21
  78. package/dist/seed-trust-policy.js +24 -15
  79. package/dist/seed-trust-policy.js.map +1 -1
  80. package/dist/strand-addr-protocol.d.ts +42 -13
  81. package/dist/strand-addr-protocol.js +58 -52
  82. package/dist/strand-addr-protocol.js.map +1 -1
  83. package/dist/strand-backfill.d.ts +109 -0
  84. package/dist/strand-backfill.js +279 -0
  85. package/dist/strand-backfill.js.map +1 -0
  86. package/dist/strand-formation-manager.d.ts +38 -9
  87. package/dist/strand-formation-manager.js +120 -17
  88. package/dist/strand-formation-manager.js.map +1 -1
  89. package/dist/strand-formation-protocol.d.ts +103 -4
  90. package/dist/strand-formation-protocol.js +232 -4
  91. package/dist/strand-formation-protocol.js.map +1 -1
  92. package/dist/strand-instance-manager.d.ts +39 -1
  93. package/dist/strand-instance-manager.js +92 -14
  94. package/dist/strand-instance-manager.js.map +1 -1
  95. package/dist/strand-member-registry.d.ts +5 -5
  96. package/dist/strand-member-registry.js +18 -10
  97. package/dist/strand-member-registry.js.map +1 -1
  98. package/dist/strand-membership-writer.d.ts +482 -88
  99. package/dist/strand-membership-writer.js +757 -136
  100. package/dist/strand-membership-writer.js.map +1 -1
  101. package/dist/strand-solicitation.d.ts +99 -33
  102. package/dist/strand-solicitation.js +100 -52
  103. package/dist/strand-solicitation.js.map +1 -1
  104. package/dist/strand-transport-key.d.ts +40 -0
  105. package/dist/strand-transport-key.js +56 -0
  106. package/dist/strand-transport-key.js.map +1 -0
  107. package/dist/strand-wake-protocol.d.ts +9 -7
  108. package/dist/strand-wake-protocol.js +22 -46
  109. package/dist/strand-wake-protocol.js.map +1 -1
  110. package/dist/strand-watcher.d.ts +17 -2
  111. package/dist/strand-watcher.js +47 -3
  112. package/dist/strand-watcher.js.map +1 -1
  113. package/dist/trusted-owner-store-file.d.ts +12 -0
  114. package/dist/trusted-owner-store-file.js +39 -0
  115. package/dist/trusted-owner-store-file.js.map +1 -0
  116. package/dist/trusted-owner-store.d.ts +64 -0
  117. package/dist/trusted-owner-store.js +126 -0
  118. package/dist/trusted-owner-store.js.map +1 -0
  119. package/dist/types.d.ts +275 -20
  120. package/dist/types.js +13 -0
  121. package/dist/types.js.map +1 -1
  122. package/package.json +19 -8
  123. package/src/bootstrap-peer-store-file.ts +44 -0
  124. package/src/bootstrap-peer-store.ts +172 -0
  125. package/src/cadre-node.ts +1992 -202
  126. package/src/control-authorization.ts +114 -0
  127. package/src/control-database.ts +1704 -146
  128. package/src/control-formation-recorder.ts +172 -19
  129. package/src/control-schema.ts +786 -222
  130. package/src/control-stream.ts +81 -4
  131. package/src/control-write-retry.ts +473 -0
  132. package/src/delegate-admission.ts +302 -0
  133. package/src/device-token.ts +18 -13
  134. package/src/ed25519-key.ts +134 -69
  135. package/src/file-durable-slot.ts +61 -0
  136. package/src/formation-approval.ts +604 -0
  137. package/src/fs-atomic.ts +107 -0
  138. package/src/identity-key.ts +109 -0
  139. package/src/index.ts +136 -5
  140. package/src/key-store-file.ts +10 -81
  141. package/src/membership-connection-gater.ts +204 -0
  142. package/src/node-local-snapshot.ts +260 -0
  143. package/src/peer-authorization.ts +199 -21
  144. package/src/peer-record.ts +28 -10
  145. package/src/relay-addrs.ts +111 -0
  146. package/src/relay-reservation.ts +823 -0
  147. package/src/seed-bootstrap.ts +397 -197
  148. package/src/seed-trust-policy.ts +58 -25
  149. package/src/strand-addr-protocol.ts +84 -53
  150. package/src/strand-backfill.ts +366 -0
  151. package/src/strand-formation-manager.ts +145 -19
  152. package/src/strand-formation-protocol.ts +309 -8
  153. package/src/strand-instance-manager.ts +111 -14
  154. package/src/strand-member-registry.ts +18 -13
  155. package/src/strand-membership-writer.ts +1430 -640
  156. package/src/strand-solicitation.ts +155 -90
  157. package/src/strand-transport-key.ts +58 -0
  158. package/src/strand-wake-protocol.ts +29 -46
  159. package/src/strand-watcher.ts +66 -3
  160. package/src/trusted-owner-store-file.ts +41 -0
  161. package/src/trusted-owner-store.ts +171 -0
  162. package/src/types.ts +292 -21
package/README.md CHANGED
@@ -169,7 +169,9 @@ The main entry point for cadre participation.
169
169
  | `getStrands()` | Get all active strand instances |
170
170
  | `getStrand(id)` | Get a specific strand instance |
171
171
  | `addStrand(row)` | Manually add a strand (testing/direct API) |
172
- | `removeStrand(id)` | Manually remove a strand |
172
+ | `stopStrand(id)` | Stop a strand on this node only (the shared `Strand` row stays; rediscovered on restart) |
173
+ | `publishStrand(id, type?, memberKey?)` | Owner-signed `Strand` row insert — makes the strand visible cadre-wide |
174
+ | `unpublishStrand(id)` | Owner-signed party-wide removal — deletes this party's `Strand` row; every node stops the strand. Destroys a closed strand's `MemberPrivateKey` |
173
175
  | `getEnrollmentService()` | Access peer enrollment API |
174
176
 
175
177
  ### Events
@@ -180,7 +182,7 @@ The main entry point for cadre participation.
180
182
  | `control:disconnected` | - | Disconnected from control network |
181
183
  | `strand:started` | `{ strandId }` | Strand instance started |
182
184
  | `strand:stopped` | `{ strandId }` | Strand instance stopped |
183
- | `strand:error` | `{ strandId, error }` | Error in strand instance |
185
+ | `strand:error` | `{ strandId, error }` | Error in strand instance. A failed launch re-emits this on every retry (backing off up to 5 min), so treat it as a repeating signal, not a one-shot |
184
186
 
185
187
  ## Related Documentation
186
188
 
@@ -0,0 +1,13 @@
1
+ import type { BootstrapPeerStore } from './bootstrap-peer-store.js';
2
+ /**
3
+ * File-backed {@link BootstrapPeerStore}. Open via {@link open}, which loads the
4
+ * existing file and returns the cross-platform store over it; an absent, corrupt, or wrong-party file is a cold
5
+ * start (empty store) and structurally junk entries are dropped, while a
6
+ * present-but-unreadable file throws. Those rules and their reasoning live on
7
+ * `NodeLocalSnapshot.open` — including the in-process-only write serialisation,
8
+ * which two nodes sharing one directory for one party would defeat.
9
+ */
10
+ export declare const FileBootstrapPeerStore: {
11
+ /** Load (or cold-start) the party's retained dial targets from a file in `dir`. */
12
+ open(dir: string, partyId: string): Promise<BootstrapPeerStore>;
13
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Node-only file-backed {@link BootstrapPeerStore}: one JSON file per party under
3
+ * a configured directory (the node's state directory — `cadre-cli` passes
4
+ * `ResolvedConfig.nodeStateDir`), holding the node-local, non-replicated
5
+ * cold-start dial targets a seed nominated.
6
+ *
7
+ * Nothing but the file itself lives here: the envelope, load policy, per-entry
8
+ * validation (shape only — never signatures; see the `bootstrap-peer-store.ts`
9
+ * module comment for why nothing persisted here is trust-bearing) and the
10
+ * serialised snapshot writes are cross-platform in
11
+ * `PersistentBootstrapPeerStore` / `node-local-snapshot.ts`, and the file is a
12
+ * `FileDurableSlot`. This module exists only so the `node:fs` edge stays out of
13
+ * the package's cross-platform default entry (`./index.js`) — import it from the
14
+ * dedicated subpath instead:
15
+ *
16
+ * ```ts
17
+ * import { FileBootstrapPeerStore } from '@serfab/cadre-core/bootstrap-peer-store-file';
18
+ * ```
19
+ *
20
+ * A React Native / browser entry graph never resolves this path, so the
21
+ * `node:fs` edge never reaches a bundler that cannot satisfy it (same isolation
22
+ * pattern as `trusted-owner-store-file.ts` / `key-store-file.ts`).
23
+ */
24
+ import { FileDurableSlot } from './file-durable-slot.js';
25
+ import { PersistentBootstrapPeerStore } from './bootstrap-peer-store.js';
26
+ /** Base name of the store file: `<dir>/bootstrap-peers.<encoded partyId>.json`. */
27
+ const SLOT_NAME = 'bootstrap-peers';
28
+ /**
29
+ * File-backed {@link BootstrapPeerStore}. Open via {@link open}, which loads the
30
+ * existing file and returns the cross-platform store over it; an absent, corrupt, or wrong-party file is a cold
31
+ * start (empty store) and structurally junk entries are dropped, while a
32
+ * present-but-unreadable file throws. Those rules and their reasoning live on
33
+ * `NodeLocalSnapshot.open` — including the in-process-only write serialisation,
34
+ * which two nodes sharing one directory for one party would defeat.
35
+ */
36
+ export const FileBootstrapPeerStore = {
37
+ /** Load (or cold-start) the party's retained dial targets from a file in `dir`. */
38
+ async open(dir, partyId) {
39
+ return PersistentBootstrapPeerStore.open(new FileDurableSlot(dir, SLOT_NAME, partyId), partyId);
40
+ }
41
+ };
42
+ //# sourceMappingURL=bootstrap-peer-store-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-peer-store-file.js","sourceRoot":"","sources":["../src/bootstrap-peer-store-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAGzE,mFAAmF;AACnF,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAEpC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,mFAAmF;IACnF,KAAK,CAAC,IAAI,CAAC,GAAW,EAAE,OAAe;QACtC,OAAO,4BAA4B,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;IACjG,CAAC;CACD,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { type DurableSlot } from './node-local-snapshot.js';
2
+ /** One retained cold-start dial target: an owner peer a seed nominated. */
3
+ export interface BootstrapPeerEntry {
4
+ /** Multiaddr strings exactly as the seed carried them (parsed at dial time). */
5
+ addrs: string[];
6
+ /** Wall-clock ms the entry was last recorded (diagnostics / future eviction). */
7
+ recordedAt: number;
8
+ }
9
+ export interface BootstrapPeerStore {
10
+ /** Party this store is scoped to. */
11
+ readonly partyId: string;
12
+ /**
13
+ * Every retained target, peerId -> entry. Every backend copies the map per call,
14
+ * so the result is a snapshot decoupled from later {@link record} calls and is
15
+ * safe to iterate while recording. The entry objects need no copy: `record`
16
+ * REPLACES an entry rather than mutating it in place.
17
+ */
18
+ all(): ReadonlyMap<string, BootstrapPeerEntry>;
19
+ /**
20
+ * Retain (or REPLACE) a peer's dial addresses. Replace, not merge, so a
21
+ * re-seed after an owner's address changed drops the stale address instead of
22
+ * accumulating dead ones.
23
+ *
24
+ * Implementations MUST reflect the entry in {@link all} SYNCHRONOUSLY; the
25
+ * returned promise tracks durability only. That is what lets the synchronous
26
+ * `CadreNode.recordSeedBootstrapPeers` keep its signature while a file
27
+ * backend persists in the background.
28
+ *
29
+ * NOTE: entries are never evicted, and a persistent backend's file therefore
30
+ * grows across the node's whole lifetime rather than one process. Fine while a
31
+ * seed nominates one or a few owners and entries are keyed by peer id; if a
32
+ * node ever applies seeds naming many distinct owners, add eviction (oldest
33
+ * {@link BootstrapPeerEntry.recordedAt} first, or a cap) rather than letting
34
+ * the file grow unbounded — `recordedAt` exists so eviction has something to
35
+ * sort by.
36
+ */
37
+ record(peerId: string, addrs: readonly string[]): Promise<void>;
38
+ }
39
+ /**
40
+ * Ephemeral in-memory store for nodes without durable storage (tests, browser
41
+ * demos, not-yet-persisted mobile). Same contract, no disk: a node using this
42
+ * loses its retry targets on restart and must be re-seeded to rejoin.
43
+ */
44
+ export declare class MemoryBootstrapPeerStore implements BootstrapPeerStore {
45
+ readonly partyId: string;
46
+ private readonly peers;
47
+ constructor(partyId: string);
48
+ all(): ReadonlyMap<string, BootstrapPeerEntry>;
49
+ record(peerId: string, addrs: readonly string[]): Promise<void>;
50
+ }
51
+ /**
52
+ * Durable {@link BootstrapPeerStore} over an app-supplied {@link DurableSlot} —
53
+ * the cross-platform half of every persistent backend (the Node
54
+ * `FileBootstrapPeerStore` is this class over a file slot).
55
+ *
56
+ * Construct via {@link open}. Load and persist policy — what an absent, corrupt,
57
+ * foreign-party or unreadable slot does, and what a failed persist does — is
58
+ * documented once on `NodeLocalSnapshot`; this class only supplies the payload
59
+ * shape and the drop-the-bad-entry policy above.
60
+ */
61
+ export declare class PersistentBootstrapPeerStore implements BootstrapPeerStore {
62
+ private readonly snapshot;
63
+ private constructor();
64
+ /** Load (or cold-start) the party's retained dial targets from `slot`. */
65
+ static open(slot: DurableSlot, partyId: string): Promise<PersistentBootstrapPeerStore>;
66
+ get partyId(): string;
67
+ all(): ReadonlyMap<string, BootstrapPeerEntry>;
68
+ /**
69
+ * Retain a peer's dial addresses: visible via {@link all} synchronously, then
70
+ * the full snapshot is persisted (see `NodeLocalSnapshot.put`).
71
+ */
72
+ record(peerId: string, addrs: readonly string[]): Promise<void>;
73
+ }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Node-local, NON-replicated cold-start bootstrap-peer store: the dial targets a
3
+ * node keeps so it can retry its way back into a party it has been seeded into
4
+ * but never managed to connect to.
5
+ *
6
+ * A newcomer applies a signed seed nominating the party's owner machines and the
7
+ * addresses they answer on. `SeedBootstrapService.applySeed` dials those owners
8
+ * exactly once, best-effort; when that dial fails (owner briefly down, relay
9
+ * reservation not up, not yet vouched) the node has an empty `CadrePeer` table
10
+ * and no connection, and `CadreNode.reconcileControlCohort`'s cold-start branch
11
+ * is the only way back — it re-dials these retained addresses every pass. Held
12
+ * only in memory, they die with the process and the node is stranded for good,
13
+ * which is what this store exists to prevent.
14
+ *
15
+ * Three implementations, mirroring `trusted-owner-store.ts` (read that first —
16
+ * it solves the same "must outlive the process, storage differs per platform"
17
+ * problem, the two stores are deliberately symmetrical, and both persistent
18
+ * forms share `node-local-snapshot.ts`):
19
+ * - {@link MemoryBootstrapPeerStore} (this module, cross-platform) — ephemeral;
20
+ * the default when no store is injected via `CadreNodeConfig.bootstrapPeers`.
21
+ * - {@link PersistentBootstrapPeerStore} (this module, cross-platform) — durable
22
+ * over any `DurableSlot` the embedding app supplies (IndexedDB, a LevelDB KV,
23
+ * SQLite, …).
24
+ * - `FileBootstrapPeerStore` — the above over a Node file in the node's state
25
+ * directory; Node-only, behind the subpath
26
+ * `@serfab/cadre-core/bootstrap-peer-store-file` (same isolation pattern as
27
+ * `key-store-file`) so `node:fs` never lands in the RN/browser entry graph.
28
+ *
29
+ * **Nothing here is trust-bearing, and a loader must not try to re-verify it.**
30
+ * Only *dial targets* are retained — never a seed, a signature, or an authority
31
+ * claim. The seed was signature-checked against the node-local trusted-owner
32
+ * anchor before its addresses were retained, and a dial grants no authority:
33
+ * `CadreNode.bootstrapDialAddrs` binds every address to the peer id it was
34
+ * retained under, so a dial cannot be redirected to whoever answers. What a
35
+ * persistent backend's loader DOES owe is dropping structurally junk entries
36
+ * (unparseable peer id, empty address list, non-string address) rather than
37
+ * carrying them into the dial loop.
38
+ */
39
+ import debug from 'debug';
40
+ import { peerIdFromString } from '@libp2p/peer-id';
41
+ import { NodeLocalSnapshot } from './node-local-snapshot.js';
42
+ const log = debug('sereus:cadre:bootstrap-peer-store');
43
+ /**
44
+ * Ephemeral in-memory store for nodes without durable storage (tests, browser
45
+ * demos, not-yet-persisted mobile). Same contract, no disk: a node using this
46
+ * loses its retry targets on restart and must be re-seeded to rejoin.
47
+ */
48
+ export class MemoryBootstrapPeerStore {
49
+ constructor(partyId) {
50
+ this.partyId = partyId;
51
+ this.peers = new Map();
52
+ }
53
+ all() {
54
+ return new Map(this.peers);
55
+ }
56
+ async record(peerId, addrs) {
57
+ this.peers.set(peerId, { addrs: [...addrs], recordedAt: Date.now() });
58
+ log('bootstrap peer retained (party=%s, peer=%s, addrs=%d)', this.partyId, peerId, addrs.length);
59
+ }
60
+ }
61
+ /**
62
+ * What the store persists: `peers` maps peerId -> {@link BootstrapPeerEntry}.
63
+ *
64
+ * A structurally junk entry is DROPPED and its siblings retained — nothing here
65
+ * is trust-bearing (see the module comment) and the record is a stranded node's
66
+ * only way back into its party, so discarding the whole set over one bad entry
67
+ * would be strictly worse. What "junk" means: an unparseable peer id (the dial
68
+ * path binds every address to this id, so an id that cannot parse is not a dial
69
+ * target at all), an empty address list, or a non-string address — each would
70
+ * otherwise log a parse failure once per reconcile pass forever.
71
+ */
72
+ const BOOTSTRAP_PEER_SNAPSHOT = {
73
+ label: 'bootstrap-peer store',
74
+ payloadKey: 'peers',
75
+ unusableEntry: 'drop-entry',
76
+ acceptEntry: (peerId, entry) => {
77
+ if (typeof entry !== 'object' || entry === null)
78
+ return undefined;
79
+ const { addrs, recordedAt } = entry;
80
+ if (!Array.isArray(addrs) || addrs.length === 0)
81
+ return undefined;
82
+ if (addrs.some((addr) => typeof addr !== 'string' || addr.length === 0))
83
+ return undefined;
84
+ if (typeof recordedAt !== 'number')
85
+ return undefined;
86
+ try {
87
+ peerIdFromString(peerId);
88
+ }
89
+ catch {
90
+ return undefined;
91
+ }
92
+ return { addrs: [...addrs], recordedAt };
93
+ }
94
+ };
95
+ /**
96
+ * Durable {@link BootstrapPeerStore} over an app-supplied {@link DurableSlot} —
97
+ * the cross-platform half of every persistent backend (the Node
98
+ * `FileBootstrapPeerStore` is this class over a file slot).
99
+ *
100
+ * Construct via {@link open}. Load and persist policy — what an absent, corrupt,
101
+ * foreign-party or unreadable slot does, and what a failed persist does — is
102
+ * documented once on `NodeLocalSnapshot`; this class only supplies the payload
103
+ * shape and the drop-the-bad-entry policy above.
104
+ */
105
+ export class PersistentBootstrapPeerStore {
106
+ constructor(snapshot) {
107
+ this.snapshot = snapshot;
108
+ }
109
+ /** Load (or cold-start) the party's retained dial targets from `slot`. */
110
+ static async open(slot, partyId) {
111
+ return new PersistentBootstrapPeerStore(await NodeLocalSnapshot.open(slot, partyId, BOOTSTRAP_PEER_SNAPSHOT));
112
+ }
113
+ get partyId() {
114
+ return this.snapshot.partyId;
115
+ }
116
+ all() {
117
+ return this.snapshot.entrySnapshot();
118
+ }
119
+ /**
120
+ * Retain a peer's dial addresses: visible via {@link all} synchronously, then
121
+ * the full snapshot is persisted (see `NodeLocalSnapshot.put`).
122
+ */
123
+ record(peerId, addrs) {
124
+ log('bootstrap peer retained (party=%s, peer=%s, addrs=%d); persisting', this.partyId, peerId, addrs.length);
125
+ return this.snapshot.put(peerId, { addrs: [...addrs], recordedAt: Date.now() });
126
+ }
127
+ }
128
+ //# sourceMappingURL=bootstrap-peer-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-peer-store.js","sourceRoot":"","sources":["../src/bootstrap-peer-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAgD,MAAM,0BAA0B,CAAC;AAE3G,MAAM,GAAG,GAAG,KAAK,CAAC,mCAAmC,CAAC,CAAC;AA2CvD;;;;GAIG;AACH,MA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