@serfab/cadre-core 1.21.0 → 1.22.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 +294 -294
- package/dist/cadre-node.d.ts +329 -53
- package/dist/cadre-node.js +767 -85
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-authorization.d.ts +32 -2
- package/dist/control-authorization.js +19 -0
- package/dist/control-authorization.js.map +1 -1
- package/dist/control-database.d.ts +236 -23
- package/dist/control-database.js +587 -173
- package/dist/control-database.js.map +1 -1
- package/dist/control-schema.d.ts +3 -3
- package/dist/control-schema.js +71 -7
- package/dist/control-schema.js.map +1 -1
- package/dist/ed25519-key.d.ts +8 -0
- package/dist/ed25519-key.js +11 -1
- package/dist/ed25519-key.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/machine-removal.d.ts +51 -1
- package/dist/machine-removal.js +42 -1
- package/dist/machine-removal.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +8 -0
- package/dist/membership-connection-gater.js +13 -1
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/owner-keys.js +2 -1
- package/dist/owner-keys.js.map +1 -1
- package/dist/owner-signer.js +3 -4
- package/dist/owner-signer.js.map +1 -1
- package/dist/peer-authorization.d.ts +14 -2
- package/dist/peer-authorization.js +24 -1
- package/dist/peer-authorization.js.map +1 -1
- package/dist/sealed-party-key.d.ts +32 -0
- package/dist/sealed-party-key.js +162 -0
- package/dist/sealed-party-key.js.map +1 -0
- package/dist/seed-bootstrap.d.ts +10 -3
- package/dist/seed-bootstrap.js +12 -0
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +56 -6
- package/dist/strand-addr-protocol.js +57 -5
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-commit-durability.d.ts +33 -2
- package/dist/strand-commit-durability.js +44 -4
- package/dist/strand-commit-durability.js.map +1 -1
- package/dist/strand-database.d.ts +35 -5
- package/dist/strand-database.js +34 -10
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +133 -9
- package/dist/strand-instance-manager.js +266 -42
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.d.ts +250 -51
- package/dist/strand-membership-reconciler.js +410 -66
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +7 -0
- package/dist/strand-membership-writer.js +9 -0
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-party-key-rotation.d.ts +177 -0
- package/dist/strand-party-key-rotation.js +340 -0
- package/dist/strand-party-key-rotation.js.map +1 -0
- package/dist/strand-party-machines.d.ts +111 -0
- package/dist/strand-party-machines.js +258 -0
- package/dist/strand-party-machines.js.map +1 -0
- package/dist/strand-party-peers.d.ts +101 -0
- package/dist/strand-party-peers.js +49 -0
- package/dist/strand-party-peers.js.map +1 -0
- package/dist/strand-peer-redial.d.ts +34 -7
- package/dist/strand-peer-redial.js +46 -13
- package/dist/strand-peer-redial.js.map +1 -1
- package/dist/strand-revocation-enforcer.d.ts +15 -1
- package/dist/strand-revocation-enforcer.js +16 -9
- package/dist/strand-revocation-enforcer.js.map +1 -1
- package/dist/strand-transport-key.js +3 -0
- package/dist/strand-transport-key.js.map +1 -1
- package/dist/strand-watcher.d.ts +7 -4
- package/dist/strand-watcher.js +12 -7
- package/dist/strand-watcher.js.map +1 -1
- package/dist/types.d.ts +160 -13
- package/dist/types.js.map +1 -1
- package/package.json +9 -8
- package/src/cadre-node.ts +12252 -11528
- package/src/control-authorization.ts +41 -1
- package/src/control-database.ts +6123 -5603
- package/src/control-schema.ts +71 -7
- package/src/ed25519-key.ts +12 -1
- package/src/index.ts +957 -924
- package/src/machine-removal.ts +80 -1
- package/src/membership-connection-gater.ts +13 -1
- package/src/owner-keys.ts +2 -1
- package/src/owner-signer.ts +92 -94
- package/src/peer-authorization.ts +27 -3
- package/src/sealed-party-key.ts +190 -0
- package/src/seed-bootstrap.ts +17 -3
- package/src/strand-addr-protocol.ts +67 -6
- package/src/strand-commit-durability.ts +54 -5
- package/src/strand-database.ts +47 -11
- package/src/strand-instance-manager.ts +330 -42
- package/src/strand-membership-reconciler.ts +1310 -942
- package/src/strand-membership-writer.ts +10 -0
- package/src/strand-party-key-rotation.ts +436 -0
- package/src/strand-party-machines.ts +293 -0
- package/src/strand-party-peers.ts +129 -0
- package/src/strand-peer-redial.ts +61 -14
- package/src/strand-revocation-enforcer.ts +27 -9
- package/src/strand-transport-key.ts +3 -0
- package/src/strand-watcher.ts +12 -7
- package/src/types.ts +3112 -2963
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The party's other machines known to hold one strand, and the offline queue's gate that waits
|
|
3
|
+
* for them (`docs/strands.md` → Waiting for the party's own machines).
|
|
4
|
+
*
|
|
5
|
+
* Why. Optimystic's own reachability gate (`KeyNetworkCohortReachability` in db-p2p) knows only
|
|
6
|
+
* the peers this strand node has itself met and seen serve the network. A sibling of the party
|
|
7
|
+
* that this node has never connected to is not among them, so with the sibling's port blocked
|
|
8
|
+
* the gate answers "genuinely alone" and a queued transaction is committed by this machine
|
|
9
|
+
* alone. The party's control database knows better: every machine that runs the strand has
|
|
10
|
+
* written a `CadreControl.StrandPeer` row for it (`strand-party-peers.ts`), so the machines a
|
|
11
|
+
* queued transaction must not be committed without are the live, trusted machines with such a
|
|
12
|
+
* row.
|
|
13
|
+
*
|
|
14
|
+
* What it does. {@link StrandPartyMachines} keeps the last good read of those machines, read
|
|
15
|
+
* through the launch's `PartyStrandPeerSource` at bring-up and again whenever the control
|
|
16
|
+
* database's party tables change (`StrandInstanceManager.notifyPartyPeersChanged`).
|
|
17
|
+
* {@link cohortGateWaitingForMachines} composes the node's gate with it: a block whose cohort
|
|
18
|
+
* names nobody but this node is unreachable while the party has a machine holding the strand.
|
|
19
|
+
* The composed gate is registered with the strand connection's collection factory
|
|
20
|
+
* (`StrandConnectionOptions.cohortReachability`), where the queue and the offline live-read
|
|
21
|
+
* path both ask it. Only a node offering offline mode builds either.
|
|
22
|
+
*
|
|
23
|
+
* Removal. The same read names the machines removed from the cadre. Optimystic's own gate, which
|
|
24
|
+
* runs first, keeps waiting for a machine its strand node remembers or was seeded with, so
|
|
25
|
+
* `StrandInstanceManager` refuses a removed machine's peer id as a member, and
|
|
26
|
+
* {@link watchRemovedMachinesInSeed} asks for a rebuild when one is in the running node's seed.
|
|
27
|
+
*/
|
|
28
|
+
import debug from 'debug';
|
|
29
|
+
import { routingKeyForBlock } from '@optimystic/db-core';
|
|
30
|
+
import { describeThrown } from './describe-thrown.js';
|
|
31
|
+
const log = debug('sereus:cadre:strand-party-machines');
|
|
32
|
+
/**
|
|
33
|
+
* The party's other machines known to hold one strand, from the last good read of the control
|
|
34
|
+
* database. Built per runtime build, before the strand's node, and stopped with the runtime.
|
|
35
|
+
*
|
|
36
|
+
* NOTE: a machine that stops running the strand but stays in the cadre (its filter changed, its
|
|
37
|
+
* app was removed, `stopStrand`) keeps its `StrandPeer` row, so it keeps counting here until it
|
|
38
|
+
* is removed from the cadre, as a peer that never returns keeps counting in Optimystic's own
|
|
39
|
+
* gate. If operators hit this, add a strand-address reply saying the filter excludes the strand,
|
|
40
|
+
* and drop a machine that answers so.
|
|
41
|
+
*
|
|
42
|
+
* NOTE: {@link settled} waits on the first control read, and the gate waits on it, so a stalled
|
|
43
|
+
* read would stall the queue and offline live reads with it. The read is the local one
|
|
44
|
+
* `connectedSiblingTargets`' NOTE in `cadre-node.ts` measured in milliseconds; if a control read
|
|
45
|
+
* ever can stall, bound this one and answer "no machines" past the bound.
|
|
46
|
+
*/
|
|
47
|
+
export class StrandPartyMachines {
|
|
48
|
+
constructor(deps) {
|
|
49
|
+
this.deps = deps;
|
|
50
|
+
this.last = [];
|
|
51
|
+
this.lastRemoved = new Set();
|
|
52
|
+
this.failed = false;
|
|
53
|
+
this.inFlight = null;
|
|
54
|
+
/** A refresh asked while a read was in flight: one more read follows, so no change is missed. */
|
|
55
|
+
this.again = false;
|
|
56
|
+
this.stopped = false;
|
|
57
|
+
/** One entry per `onChange` call, so a listener subscribed twice is two subscriptions. */
|
|
58
|
+
this.listeners = new Set();
|
|
59
|
+
this.settleFirstRead = null;
|
|
60
|
+
this.firstRead = new Promise((resolve) => {
|
|
61
|
+
this.settleFirstRead = resolve;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** Read again now: coalesced, one read in flight. A failed read logs and keeps the last answer. */
|
|
65
|
+
refresh() {
|
|
66
|
+
if (this.stopped) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (this.inFlight !== null) {
|
|
70
|
+
this.again = true;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.inFlight = this.read().finally(() => {
|
|
74
|
+
this.inFlight = null;
|
|
75
|
+
this.settleFirstRead?.();
|
|
76
|
+
this.settleFirstRead = null;
|
|
77
|
+
if (this.again) {
|
|
78
|
+
this.again = false;
|
|
79
|
+
this.refresh();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Settles once the first read has finished, either way. */
|
|
84
|
+
settled() {
|
|
85
|
+
return this.firstRead;
|
|
86
|
+
}
|
|
87
|
+
/** The last good read's live machines; empty before one. */
|
|
88
|
+
machines() {
|
|
89
|
+
return this.last;
|
|
90
|
+
}
|
|
91
|
+
/** The strand peer ids of machines removed from the cadre, from the last good read; empty before one. */
|
|
92
|
+
removed() {
|
|
93
|
+
return this.lastRemoved;
|
|
94
|
+
}
|
|
95
|
+
/** Whether the most recent read failed, so the answer in {@link machines} may be stale. */
|
|
96
|
+
lastReadFailed() {
|
|
97
|
+
return this.failed;
|
|
98
|
+
}
|
|
99
|
+
/** Called only when the live machines or the removed ids change. Returns an idempotent unsubscribe. */
|
|
100
|
+
onChange(listener) {
|
|
101
|
+
if (this.stopped) {
|
|
102
|
+
return () => undefined;
|
|
103
|
+
}
|
|
104
|
+
const subscription = { listener };
|
|
105
|
+
this.listeners.add(subscription);
|
|
106
|
+
return () => {
|
|
107
|
+
this.listeners.delete(subscription);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Drops every listener; a read in flight keeps nothing. */
|
|
111
|
+
stop() {
|
|
112
|
+
this.stopped = true;
|
|
113
|
+
this.listeners.clear();
|
|
114
|
+
// A gate waiting on a tracker that never read must not wait forever.
|
|
115
|
+
this.settleFirstRead?.();
|
|
116
|
+
this.settleFirstRead = null;
|
|
117
|
+
}
|
|
118
|
+
async read() {
|
|
119
|
+
let peers;
|
|
120
|
+
try {
|
|
121
|
+
peers = await this.deps.source.read();
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
this.failed = true;
|
|
125
|
+
log('strand %s: the party\'s machines could not be read (keeping %d known): %s', this.deps.label, this.last.length, describeThrown(error));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.failed = false;
|
|
129
|
+
if (this.stopped || (sameMachines(this.last, peers.live) && sameIds(this.lastRemoved, peers.removed))) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.last = peers.live;
|
|
133
|
+
this.lastRemoved = new Set(peers.removed);
|
|
134
|
+
log('strand %s: the party has %d other machine(s) holding the strand and %d removed', this.deps.label, peers.live.length, peers.removed.length);
|
|
135
|
+
for (const { listener } of [...this.listeners]) {
|
|
136
|
+
try {
|
|
137
|
+
listener();
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
log('strand %s: a machines listener threw: %o', this.deps.label, error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function sameMachines(a, b) {
|
|
146
|
+
if (a.length !== b.length) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const keys = new Set(a.map(machineKey));
|
|
150
|
+
return b.every((machine) => keys.has(machineKey(machine)));
|
|
151
|
+
}
|
|
152
|
+
function machineKey(machine) {
|
|
153
|
+
return `${machine.peerId}/${machine.strandPeerId}`;
|
|
154
|
+
}
|
|
155
|
+
function sameIds(known, ids) {
|
|
156
|
+
return known.size === ids.length && ids.every((id) => known.has(id));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Call `onFound` when `machines` names a removed machine that is in `seedPeers`, the peers of the
|
|
160
|
+
* launch seed this runtime's node was built with, so that the node is rebuilt from a fresh seed.
|
|
161
|
+
* A rebuild is the only remedy: the node's seed is frozen, and Optimystic reads a refused seed peer
|
|
162
|
+
* that serves the network as not yet heard from for the node's whole life (`heardFromBootstrapPeer`).
|
|
163
|
+
*
|
|
164
|
+
* `announced` is the strand's memory across its runtimes of the ids a rebuild was asked for, so an
|
|
165
|
+
* id still in the rebuilt node's seed asks once and not on every build. Ids this seed does not name
|
|
166
|
+
* are forgotten, so a machine removed, re-added, seeded again and removed again asks again.
|
|
167
|
+
*
|
|
168
|
+
* NOTE: a fresh seed should never name a removed machine: its sources are the answers of live
|
|
169
|
+
* siblings and a formation's addresses, which are another party's. The exception is a removed
|
|
170
|
+
* machine still configured as this node's relay and still answering the strand-addr RPC. The hold
|
|
171
|
+
* then stays and the log says why; the remedy is to take it out of `network.relayAddrs`.
|
|
172
|
+
*/
|
|
173
|
+
export function watchRemovedMachinesInSeed(machines, seedPeers, announced, onFound, label) {
|
|
174
|
+
for (const peerId of announced) {
|
|
175
|
+
if (!seedPeers.has(peerId)) {
|
|
176
|
+
announced.delete(peerId);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
machines.onChange(() => {
|
|
180
|
+
const inSeed = [...machines.removed()].filter((peerId) => seedPeers.has(peerId));
|
|
181
|
+
const unannounced = inSeed.filter((peerId) => !announced.has(peerId));
|
|
182
|
+
if (unannounced.length > 0) {
|
|
183
|
+
unannounced.forEach((peerId) => announced.add(peerId));
|
|
184
|
+
onFound();
|
|
185
|
+
}
|
|
186
|
+
else if (inSeed.length > 0) {
|
|
187
|
+
log('strand %s: the seed still names removed machine(s) %o after a rebuild, so the queue stays held', label, inSeed);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* `inner` (the node's gate), closed also while this node is alone in a block's cohort and the
|
|
193
|
+
* party has machines holding the strand. In order: `inner` closed answers closed and nothing
|
|
194
|
+
* further is read; then the first machine read is awaited, and a failed last read is asked again
|
|
195
|
+
* (the retry rides the asker's own re-check, so no timer here); no machines answers open;
|
|
196
|
+
* otherwise every distinct block's cohort is read from the key network, and one naming nobody
|
|
197
|
+
* but this node, or one whose lookup throws, answers closed.
|
|
198
|
+
*
|
|
199
|
+
* The test is "alone in the cohort", not "a machine is unconnected": with one sibling connected
|
|
200
|
+
* and another blocked the cohort has two members, the commit runs on it, and nothing is held.
|
|
201
|
+
* The same goes for another party's member being connected. `onChange` forwards both the node
|
|
202
|
+
* gate's wakes and a change of the machines.
|
|
203
|
+
*/
|
|
204
|
+
export function cohortGateWaitingForMachines(inner, keyNetwork, selfId, machines) {
|
|
205
|
+
/** The previous answer, so the log marks each change rather than each ask. */
|
|
206
|
+
let lastAnswer;
|
|
207
|
+
const answer = (open, why) => {
|
|
208
|
+
if (open !== lastAnswer) {
|
|
209
|
+
lastAnswer = open;
|
|
210
|
+
log('gate %s: %s', open ? 'open' : 'closed', why);
|
|
211
|
+
}
|
|
212
|
+
return open;
|
|
213
|
+
};
|
|
214
|
+
const aloneInCohort = async (blockId) => {
|
|
215
|
+
try {
|
|
216
|
+
const cohort = Object.keys(await keyNetwork.findCluster(routingKeyForBlock(blockId)));
|
|
217
|
+
return !cohort.some((peerId) => peerId !== selfId);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
log('gate: the cohort of block %s could not be read: %s', blockId, describeThrown(error));
|
|
221
|
+
return 'lookup-failed';
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
return {
|
|
225
|
+
async reachable(blockIds) {
|
|
226
|
+
if (!(await inner.reachable(blockIds))) {
|
|
227
|
+
return answer(false, 'the node\'s own gate is closed');
|
|
228
|
+
}
|
|
229
|
+
await machines.settled();
|
|
230
|
+
if (machines.lastReadFailed()) {
|
|
231
|
+
machines.refresh();
|
|
232
|
+
}
|
|
233
|
+
const known = machines.machines();
|
|
234
|
+
if (known.length === 0) {
|
|
235
|
+
return answer(true, 'the party has no other machine holding the strand');
|
|
236
|
+
}
|
|
237
|
+
for (const blockId of new Set(blockIds)) {
|
|
238
|
+
const alone = await aloneInCohort(blockId);
|
|
239
|
+
if (alone === 'lookup-failed') {
|
|
240
|
+
return answer(false, `block ${blockId}'s cohort could not be read`);
|
|
241
|
+
}
|
|
242
|
+
if (alone) {
|
|
243
|
+
return answer(false, `alone in block ${blockId}'s cohort while ${known.length} party machine(s) hold the strand`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return answer(true, 'another member is in every cohort');
|
|
247
|
+
},
|
|
248
|
+
onChange(listener) {
|
|
249
|
+
const releaseInner = inner.onChange?.(listener);
|
|
250
|
+
const releaseMachines = machines.onChange(listener);
|
|
251
|
+
return () => {
|
|
252
|
+
releaseInner?.();
|
|
253
|
+
releaseMachines();
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=strand-party-machines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strand-party-machines.js","sourceRoot":"","sources":["../src/strand-party-machines.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,MAAM,GAAG,GAAG,KAAK,CAAC,oCAAoC,CAAC,CAAC;AAQxD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,mBAAmB;IAa9B,YAA6B,IAA6B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;YACrB,CAAC;YACD,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAClC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,OAAO,MAAM,CAAC,IAAI,EAAE,mDAAmD,CAAC,CAAC;YAC3E,CAAC;YACD,KAAK,MAAM,OAAO,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACxC,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;gBAC3C,IAAI,KAAK,KAAK,eAAe,EAAE,CAAC;oBAC9B,OAAO,MAAM,CAAC,KAAK,EAAE,SAAS,OAAO,6BAA6B,CAAC,CAAC;gBACtE,CAAC;gBACD,IAAI,KAAK,EAAE,CAAC;oBACV,OAAO,MAAM,CAAC,KAAK,EAAE,kBAAkB,OAAO,mBAAmB,KAAK,CAAC,MAAM,mCAAmC,CAAC,CAAC;gBACpH,CAAC;YACH,CAAC;YACD,OAAO,MAAM,CAAC,IAAI,EAAE,mCAAmC,CAAC,CAAC;QAC3D,CAAC;QACD,QAAQ,CAAC,QAAQ;YACf,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;YAChD,MAAM,eAAe,GAAG,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACpD,OAAO,GAAG,EAAE;gBACV,YAAY,EAAE,EAAE,CAAC;gBACjB,eAAe,EAAE,CAAC;YACpB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A party's machines as one strand sees them: which strand peer ids belong to the party's live
|
|
3
|
+
* machines and which to machines removed from the cadre, projected from the control database.
|
|
4
|
+
* The inputs are the strand's `CadreControl.StrandPeer` rows (each machine's own signed
|
|
5
|
+
* statement of its peer id in the strand), the live `CadrePeer` rows judged by this node's
|
|
6
|
+
* membership predicate, and the `CadrePeer` tombstones.
|
|
7
|
+
*
|
|
8
|
+
* Two readers. The closed-strand membership reconciler (`strand-membership-reconciler.ts`)
|
|
9
|
+
* binds every live sibling under the party's current member key and clears a removed
|
|
10
|
+
* machine's binding, so a sibling that was offline when the party's key changed is already
|
|
11
|
+
* bound when it returns, and a machine wrongly bound under a key is cleared. Who binds whom is
|
|
12
|
+
* stated in `docs/strands.md` → Closed-Strand Member Key Handling. The same loop reads the
|
|
13
|
+
* party's pending key through this seam ({@link PartyStrandPeerSource.pendingKey}): while the
|
|
14
|
+
* party is moving to another key in the strand, a staged invitation is redeemed under that key
|
|
15
|
+
* rather than the current one (`docs/strands.md` → Replacing the party's key). On a node
|
|
16
|
+
* offering offline mode, `strand-party-machines.ts` reads the live machines of every strand,
|
|
17
|
+
* open or closed, as the machines a queued transaction must not be committed without
|
|
18
|
+
* (`docs/strands.md` → Waiting for the party's own machines).
|
|
19
|
+
*/
|
|
20
|
+
import type { OpenedPendingPartyKey } from './strand-party-key-rotation.js';
|
|
21
|
+
import type { CadreMachine, RevocationRow, StrandPeerRow } from './types.js';
|
|
22
|
+
/**
|
|
23
|
+
* The party's pending key in one strand, as this machine can read it
|
|
24
|
+
* ({@link PartyStrandPeerSource.pendingKey}). `pending: true` means a `PendingStrandPartyKey`
|
|
25
|
+
* row exists for the strand; its `key` is the row opened under this machine's identity key, or
|
|
26
|
+
* null when the row is sealed to other machines (a machine admitted after the removal) or this
|
|
27
|
+
* node runs on an ephemeral identity and can open nothing.
|
|
28
|
+
*/
|
|
29
|
+
export type PendingPartyKeyState = {
|
|
30
|
+
pending: false;
|
|
31
|
+
} | {
|
|
32
|
+
pending: true;
|
|
33
|
+
key: OpenedPendingPartyKey | null;
|
|
34
|
+
};
|
|
35
|
+
/** One of the party's other machines in one strand, as its `StrandPeer` row states it. */
|
|
36
|
+
export interface PartyStrandPeer {
|
|
37
|
+
/** The machine's control peer id (`CadrePeer.PeerId`, what `listMachines` and `removeMachine` use). */
|
|
38
|
+
readonly peerId: string;
|
|
39
|
+
/** Its peer id in this strand's network. */
|
|
40
|
+
readonly strandPeerId: string;
|
|
41
|
+
}
|
|
42
|
+
/** The party's machines' peer ids in one strand, as {@link partitionPartyStrandPeers} sorts them. */
|
|
43
|
+
export interface PartyStrandPeers {
|
|
44
|
+
/**
|
|
45
|
+
* The party's live machines other than this one: each has a `StrandPeer` row and a live
|
|
46
|
+
* `CadrePeer` row that passes the membership predicate (`CadreMachine.trusted`, which is false
|
|
47
|
+
* for this node itself). One entry per strand peer id.
|
|
48
|
+
*/
|
|
49
|
+
live: readonly PartyStrandPeer[];
|
|
50
|
+
/**
|
|
51
|
+
* Strand peer ids of machines removed from the cadre: each has a `StrandPeer` row, a
|
|
52
|
+
* `CadrePeer` tombstone naming its peer id, and no live `CadrePeer` row. Never an id that is
|
|
53
|
+
* also in {@link live}: a removed machine can state any id as its own (nothing but the
|
|
54
|
+
* machine itself can derive its id, so nothing checks the statement), and a removed machine's
|
|
55
|
+
* row must never clear a live machine's binding.
|
|
56
|
+
*/
|
|
57
|
+
removed: readonly string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The control-database seam of one strand's party machines, scoped to one strand as
|
|
61
|
+
* `PendingMembershipInviteSource` is. `CadreNode` builds one per strand launch
|
|
62
|
+
* (`StartStrandConfig.partyPeers`); the instance manager publishes through it at bring-up and
|
|
63
|
+
* hands it to the reconciler and to the offline-mode machine tracker, each of which reads
|
|
64
|
+
* through it.
|
|
65
|
+
*/
|
|
66
|
+
export interface PartyStrandPeerSource {
|
|
67
|
+
/**
|
|
68
|
+
* Record this machine's own peer id in the strand in the party's control database (its
|
|
69
|
+
* `StrandPeer` row), signed by the machine's identity key. Insert-if-absent, and a no-op once
|
|
70
|
+
* the row is known present. A write deferred while it could fork the party, or refused
|
|
71
|
+
* because this machine's own `CadrePeer` row has not reached this node, is retried by the
|
|
72
|
+
* control-sibling growth drain and by the next call. Never rejects.
|
|
73
|
+
*/
|
|
74
|
+
publishOwn(strandPeerId: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* The party's machines' peer ids in this strand, read now. Rejects when the rows cannot be
|
|
77
|
+
* read (on a party whose store was migrated to the `StrandPeer` table, a read can fail while
|
|
78
|
+
* the other machines are offline: `ControlDatabase.queryStrandPeers`), and never answers
|
|
79
|
+
* "no machines" for a failed read.
|
|
80
|
+
*/
|
|
81
|
+
read(): Promise<PartyStrandPeers>;
|
|
82
|
+
/**
|
|
83
|
+
* Whether the party is moving to another member key in this strand (a
|
|
84
|
+
* `PendingStrandPartyKey` row), and that key opened for this machine when it can be
|
|
85
|
+
* ({@link PendingPartyKeyState}). Rejects when the row cannot be read or does not decode,
|
|
86
|
+
* which a caller treats as `{ pending: true, key: null }`: while a rotation may be pending, a
|
|
87
|
+
* removed machine's binding under the current key is the orphan the rotation is about to
|
|
88
|
+
* leave, and clearing it would hand the removed machine a clean slate; and nothing may be
|
|
89
|
+
* seated under the current key, which the removed machine holds.
|
|
90
|
+
*/
|
|
91
|
+
pendingKey(): Promise<PendingPartyKeyState>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sort a strand's `StrandPeer` rows into the party's live siblings and its removed machines
|
|
95
|
+
* ({@link PartyStrandPeers}). A row whose machine has a live `CadrePeer` row is a live sibling
|
|
96
|
+
* when that row passes the membership predicate and is ignored otherwise (this node's own row,
|
|
97
|
+
* or a machine this node's anchor does not trust). A row whose machine has no live `CadrePeer`
|
|
98
|
+
* row is a removed machine only when a `CadrePeer` tombstone names it; otherwise the machine's
|
|
99
|
+
* row has simply not replicated here yet, and the row is ignored.
|
|
100
|
+
*/
|
|
101
|
+
export declare function partitionPartyStrandPeers(rows: readonly StrandPeerRow[], machines: readonly CadreMachine[], tombstones: readonly RevocationRow[]): PartyStrandPeers;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A party's machines as one strand sees them: which strand peer ids belong to the party's live
|
|
3
|
+
* machines and which to machines removed from the cadre, projected from the control database.
|
|
4
|
+
* The inputs are the strand's `CadreControl.StrandPeer` rows (each machine's own signed
|
|
5
|
+
* statement of its peer id in the strand), the live `CadrePeer` rows judged by this node's
|
|
6
|
+
* membership predicate, and the `CadrePeer` tombstones.
|
|
7
|
+
*
|
|
8
|
+
* Two readers. The closed-strand membership reconciler (`strand-membership-reconciler.ts`)
|
|
9
|
+
* binds every live sibling under the party's current member key and clears a removed
|
|
10
|
+
* machine's binding, so a sibling that was offline when the party's key changed is already
|
|
11
|
+
* bound when it returns, and a machine wrongly bound under a key is cleared. Who binds whom is
|
|
12
|
+
* stated in `docs/strands.md` → Closed-Strand Member Key Handling. The same loop reads the
|
|
13
|
+
* party's pending key through this seam ({@link PartyStrandPeerSource.pendingKey}): while the
|
|
14
|
+
* party is moving to another key in the strand, a staged invitation is redeemed under that key
|
|
15
|
+
* rather than the current one (`docs/strands.md` → Replacing the party's key). On a node
|
|
16
|
+
* offering offline mode, `strand-party-machines.ts` reads the live machines of every strand,
|
|
17
|
+
* open or closed, as the machines a queued transaction must not be committed without
|
|
18
|
+
* (`docs/strands.md` → Waiting for the party's own machines).
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Sort a strand's `StrandPeer` rows into the party's live siblings and its removed machines
|
|
22
|
+
* ({@link PartyStrandPeers}). A row whose machine has a live `CadrePeer` row is a live sibling
|
|
23
|
+
* when that row passes the membership predicate and is ignored otherwise (this node's own row,
|
|
24
|
+
* or a machine this node's anchor does not trust). A row whose machine has no live `CadrePeer`
|
|
25
|
+
* row is a removed machine only when a `CadrePeer` tombstone names it; otherwise the machine's
|
|
26
|
+
* row has simply not replicated here yet, and the row is ignored.
|
|
27
|
+
*/
|
|
28
|
+
export function partitionPartyStrandPeers(rows, machines, tombstones) {
|
|
29
|
+
const liveMachines = new Map(machines.map((machine) => [machine.peerId, machine]));
|
|
30
|
+
const removedMachines = new Set(tombstones.filter((tombstone) => tombstone.tableName === 'CadrePeer').map((tombstone) => tombstone.rowKey));
|
|
31
|
+
const live = new Map();
|
|
32
|
+
const removed = new Set();
|
|
33
|
+
for (const row of rows) {
|
|
34
|
+
const machine = liveMachines.get(row.peerId);
|
|
35
|
+
if (machine !== undefined) {
|
|
36
|
+
if (machine.trusted && !live.has(row.strandPeerId)) {
|
|
37
|
+
live.set(row.strandPeerId, { peerId: row.peerId, strandPeerId: row.strandPeerId });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (removedMachines.has(row.peerId)) {
|
|
41
|
+
removed.add(row.strandPeerId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const id of live.keys()) {
|
|
45
|
+
removed.delete(id);
|
|
46
|
+
}
|
|
47
|
+
return { live: [...live.values()], removed: [...removed] };
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=strand-party-peers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strand-party-peers.js","sourceRoot":"","sources":["../src/strand-party-peers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA6EH;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CACvC,IAA8B,EAC9B,QAAiC,EACjC,UAAoC;IAEpC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnF,MAAM,eAAe,GAAG,IAAI,GAAG,CAC7B,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAC3G,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,GAAG,EAA2B,CAAC;IAChD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;gBACnD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;YACrF,CAAC;QACH,CAAC;aAAM,IAAI,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7B,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
* cut off part-way through the handshake, from both sides, for as long as the link stays that
|
|
14
14
|
* slow. And after a restart nothing else dials a strand peer: a cross-party strand's launch
|
|
15
15
|
* seed is empty, and cadre-core's address passes only fill the address book. Two phones that
|
|
16
|
-
* restarted then never reconnect, and a write either made alone never reaches the other.
|
|
16
|
+
* restarted then never reconnect, and a write either made alone never reaches the other. The
|
|
17
|
+
* same holds for a sibling of the party this node has never connected to (its strand port
|
|
18
|
+
* blocked when the strand launched here): its address reaches the address book through the
|
|
19
|
+
* strand-addr RPC and nothing dials it, so a port that opens later is never reached.
|
|
17
20
|
*
|
|
18
21
|
* What it does. One loop per strand runtime, started in `StrandInstanceManager`'s runtime
|
|
19
22
|
* build and stopped with the runtime (stop, quiesce, failed build), so a hibernating strand
|
|
@@ -30,11 +33,14 @@
|
|
|
30
33
|
*
|
|
31
34
|
* Who is known: every peer the node's FRET table holds a verified signed address record for
|
|
32
35
|
* (`strand-fret-addrs.ts`), plus the launch seed (sibling strand addresses and a formation's
|
|
33
|
-
* carried addresses)
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* peer,
|
|
36
|
+
* carried addresses), plus the party's own machines known to hold the strand
|
|
37
|
+
* ({@link StrandRedialDeps.partyMachines}, from the control database) at whatever addresses
|
|
38
|
+
* the node's address book holds for them, a machine with none skipped. Who counts as
|
|
39
|
+
* connected: a peer FRET labels `'member'` (it has seen it speak this strand's protocols), a
|
|
40
|
+
* seed peer, or a party machine. None ever includes a configured relay, a peer FRET labels
|
|
41
|
+
* `'foreign'`, or a peer the revocation gate refuses. The relay matters most: the strand node
|
|
42
|
+
* is connected to it throughout and FRET files it with a record like any peer, so counting it
|
|
43
|
+
* would leave this loop idle exactly when it is needed.
|
|
38
44
|
*
|
|
39
45
|
* NOTE: this compensates for FRET's 2 000 ms maintenance dial limit, which cannot open a
|
|
40
46
|
* relayed connection on a slow link (upstream half:
|
|
@@ -42,6 +48,8 @@
|
|
|
42
48
|
* dial ever takes a limit derived from the declared link, this loop becomes a backstop and
|
|
43
49
|
* may be deleted, as `peer-join-backfill.ts` says of itself.
|
|
44
50
|
*/
|
|
51
|
+
import type { PeerId } from '@libp2p/interface';
|
|
52
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
45
53
|
import { type AddrDialer, type PeerDialBudget } from './peer-dial.js';
|
|
46
54
|
import { type FretAddrHost } from './strand-fret-addrs.js';
|
|
47
55
|
import { type TimeoutScheduler } from './timeout-scheduler.js';
|
|
@@ -77,6 +85,17 @@ export declare function strandRedialTimings(linkRoundTripMs?: number): StrandRed
|
|
|
77
85
|
/** The slice of a strand's libp2p node the loop uses. Structurally satisfied by db-p2p's node. */
|
|
78
86
|
export interface RedialNode extends AddrDialer {
|
|
79
87
|
services?: FretAddrHost['services'];
|
|
88
|
+
/**
|
|
89
|
+
* The node's address book, read for the party's machines ({@link StrandRedialDeps.partyMachines});
|
|
90
|
+
* libp2p's `get` throws a `NotFoundError` for a peer it holds nothing for.
|
|
91
|
+
*/
|
|
92
|
+
peerStore: {
|
|
93
|
+
get(peerId: PeerId): Promise<{
|
|
94
|
+
addresses: ReadonlyArray<{
|
|
95
|
+
multiaddr: Multiaddr;
|
|
96
|
+
}>;
|
|
97
|
+
}>;
|
|
98
|
+
};
|
|
80
99
|
getConnections(): ReadonlyArray<{
|
|
81
100
|
remotePeer: {
|
|
82
101
|
toString(): string;
|
|
@@ -99,8 +118,16 @@ export interface StrandRedialDeps {
|
|
|
99
118
|
seed: readonly string[];
|
|
100
119
|
/** Peer ids never dialed nor counted as members: the relays the node reserves on. */
|
|
101
120
|
excluded: ReadonlySet<string>;
|
|
102
|
-
/**
|
|
121
|
+
/** Whether a peer, or this node itself, is cut off: the revocation gate's verdict and the party's removed machines. Absent when neither applies. */
|
|
103
122
|
isRevoked?: (peerId: string) => boolean;
|
|
123
|
+
/**
|
|
124
|
+
* The strand peer ids of the party's other machines known to hold the strand
|
|
125
|
+
* (`strand-party-machines.ts`), read at every look. Each is a member whether or not FRET has
|
|
126
|
+
* met it, dialed at the addresses the node's address book holds for it (cadre-core's
|
|
127
|
+
* strand-addr passes fill it) and skipped while it holds none. Absent on a node that tracks
|
|
128
|
+
* no party machines.
|
|
129
|
+
*/
|
|
130
|
+
partyMachines?: () => readonly string[];
|
|
104
131
|
/** Omit for real (unref'd) timers. */
|
|
105
132
|
scheduler?: TimeoutScheduler;
|
|
106
133
|
}
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
* cut off part-way through the handshake, from both sides, for as long as the link stays that
|
|
14
14
|
* slow. And after a restart nothing else dials a strand peer: a cross-party strand's launch
|
|
15
15
|
* seed is empty, and cadre-core's address passes only fill the address book. Two phones that
|
|
16
|
-
* restarted then never reconnect, and a write either made alone never reaches the other.
|
|
16
|
+
* restarted then never reconnect, and a write either made alone never reaches the other. The
|
|
17
|
+
* same holds for a sibling of the party this node has never connected to (its strand port
|
|
18
|
+
* blocked when the strand launched here): its address reaches the address book through the
|
|
19
|
+
* strand-addr RPC and nothing dials it, so a port that opens later is never reached.
|
|
17
20
|
*
|
|
18
21
|
* What it does. One loop per strand runtime, started in `StrandInstanceManager`'s runtime
|
|
19
22
|
* build and stopped with the runtime (stop, quiesce, failed build), so a hibernating strand
|
|
@@ -30,11 +33,14 @@
|
|
|
30
33
|
*
|
|
31
34
|
* Who is known: every peer the node's FRET table holds a verified signed address record for
|
|
32
35
|
* (`strand-fret-addrs.ts`), plus the launch seed (sibling strand addresses and a formation's
|
|
33
|
-
* carried addresses)
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* peer,
|
|
36
|
+
* carried addresses), plus the party's own machines known to hold the strand
|
|
37
|
+
* ({@link StrandRedialDeps.partyMachines}, from the control database) at whatever addresses
|
|
38
|
+
* the node's address book holds for them, a machine with none skipped. Who counts as
|
|
39
|
+
* connected: a peer FRET labels `'member'` (it has seen it speak this strand's protocols), a
|
|
40
|
+
* seed peer, or a party machine. None ever includes a configured relay, a peer FRET labels
|
|
41
|
+
* `'foreign'`, or a peer the revocation gate refuses. The relay matters most: the strand node
|
|
42
|
+
* is connected to it throughout and FRET files it with a record like any peer, so counting it
|
|
43
|
+
* would leave this loop idle exactly when it is needed.
|
|
38
44
|
*
|
|
39
45
|
* NOTE: this compensates for FRET's 2 000 ms maintenance dial limit, which cannot open a
|
|
40
46
|
* relayed connection on a slow link (upstream half:
|
|
@@ -43,6 +49,7 @@
|
|
|
43
49
|
* may be deleted, as `peer-join-backfill.ts` says of itself.
|
|
44
50
|
*/
|
|
45
51
|
import debug from 'debug';
|
|
52
|
+
import { peerIdFromString } from '@libp2p/peer-id';
|
|
46
53
|
import { relayedDialBudgetMs } from './link-budget.js';
|
|
47
54
|
import { CONTROL_COHORT_DIAL_ADDRESS_ATTEMPTS, SelfRelayOnlyError, dialPeerAddrs } from './peer-dial.js';
|
|
48
55
|
import { groupAddrsByPeerId } from './peer-addr-book.js';
|
|
@@ -145,10 +152,11 @@ class StrandPeerRedialLoop {
|
|
|
145
152
|
return 'watch';
|
|
146
153
|
}
|
|
147
154
|
const membership = strandFretMembership(this.deps.node);
|
|
148
|
-
|
|
155
|
+
const partyMachines = new Set(this.deps.partyMachines?.() ?? []);
|
|
156
|
+
if (this.memberConnected(membership, partyMachines)) {
|
|
149
157
|
return 'watch';
|
|
150
158
|
}
|
|
151
|
-
const known = await this.knownMembers(membership);
|
|
159
|
+
const known = await this.knownMembers(membership, partyMachines);
|
|
152
160
|
if (known.size === 0 || this.stopped) {
|
|
153
161
|
return 'watch';
|
|
154
162
|
}
|
|
@@ -189,15 +197,18 @@ class StrandPeerRedialLoop {
|
|
|
189
197
|
eligible(peerId) {
|
|
190
198
|
return peerId !== this.selfId && !this.deps.excluded.has(peerId) && this.deps.isRevoked?.(peerId) !== true;
|
|
191
199
|
}
|
|
192
|
-
/** Whether an open connection reaches a peer FRET has seen speak this strand's protocols, or a
|
|
193
|
-
memberConnected(membership) {
|
|
200
|
+
/** Whether an open connection reaches a peer FRET has seen speak this strand's protocols, a seed peer, or a party machine. */
|
|
201
|
+
memberConnected(membership, partyMachines) {
|
|
194
202
|
return this.deps.node.getConnections().some((connection) => {
|
|
195
203
|
const peerId = connection.remotePeer.toString();
|
|
196
|
-
return this.eligible(peerId) && (membership.get(peerId) === 'member' || this.seed.has(peerId));
|
|
204
|
+
return this.eligible(peerId) && (membership.get(peerId) === 'member' || this.seed.has(peerId) || partyMachines.has(peerId));
|
|
197
205
|
});
|
|
198
206
|
}
|
|
199
|
-
/**
|
|
200
|
-
|
|
207
|
+
/**
|
|
208
|
+
* The members to dial, each with its candidate addresses: verified FRET records first, then the
|
|
209
|
+
* seed's, then the address book's for a party machine neither names.
|
|
210
|
+
*/
|
|
211
|
+
async knownMembers(membership, partyMachines) {
|
|
201
212
|
const { peers } = await strandFretPeerAddrs(this.deps.node);
|
|
202
213
|
const known = new Map();
|
|
203
214
|
for (const [peerId, addrs] of [...peers, ...this.seed]) {
|
|
@@ -206,8 +217,30 @@ class StrandPeerRedialLoop {
|
|
|
206
217
|
}
|
|
207
218
|
known.set(peerId, unionAddrs(known.get(peerId) ?? [], addrs));
|
|
208
219
|
}
|
|
220
|
+
for (const peerId of partyMachines) {
|
|
221
|
+
if (known.has(peerId) || !this.eligible(peerId) || membership.get(peerId) === 'foreign') {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const addrs = await this.addressBookAddrs(peerId);
|
|
225
|
+
if (addrs.length > 0) {
|
|
226
|
+
known.set(peerId, addrs);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
209
229
|
return known;
|
|
210
230
|
}
|
|
231
|
+
/** The address book's addresses for `peerId`: none for a peer it holds nothing for, and none, logged, when it cannot be read. */
|
|
232
|
+
async addressBookAddrs(peerId) {
|
|
233
|
+
try {
|
|
234
|
+
const peer = await this.deps.node.peerStore.get(peerIdFromString(peerId));
|
|
235
|
+
return peer.addresses.map((address) => address.multiaddr);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
if (error.name !== 'NotFoundError') {
|
|
239
|
+
log('strand %s: the address book could not be read for party machine %s: %o', this.deps.label, peerId, error);
|
|
240
|
+
}
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
211
244
|
/** Dial every member in `known` at once; resolves to whether any connected. */
|
|
212
245
|
async dialAny(known) {
|
|
213
246
|
const members = [...known];
|