@serfab/cadre-core 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/cadre-node.d.ts +527 -206
- package/dist/cadre-node.js +1084 -528
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-authorization.d.ts +2 -2
- package/dist/control-authorization.js +1 -0
- package/dist/control-authorization.js.map +1 -1
- package/dist/control-cohort.d.ts +6 -0
- package/dist/control-cohort.js +6 -0
- package/dist/control-cohort.js.map +1 -1
- package/dist/control-database.d.ts +46 -8
- package/dist/control-database.js +97 -18
- package/dist/control-database.js.map +1 -1
- package/dist/control-formation-recorder.d.ts +37 -14
- package/dist/control-formation-recorder.js +60 -10
- package/dist/control-formation-recorder.js.map +1 -1
- package/dist/control-read-retry.d.ts +13 -12
- package/dist/control-read-retry.js +14 -12
- package/dist/control-read-retry.js.map +1 -1
- package/dist/control-schema.d.ts +1 -1
- package/dist/control-schema.js +67 -5
- package/dist/control-schema.js.map +1 -1
- package/dist/control-stream.d.ts +9 -1
- package/dist/control-stream.js +24 -1
- package/dist/control-stream.js.map +1 -1
- package/dist/control-write-retry.d.ts +12 -2
- package/dist/control-write-retry.js +13 -2
- package/dist/control-write-retry.js.map +1 -1
- package/dist/delegate-admission.d.ts +11 -8
- package/dist/delegate-admission.js +19 -11
- package/dist/delegate-admission.js.map +1 -1
- package/dist/diagnostics/connection-path.d.ts +0 -7
- package/dist/diagnostics/connection-path.js +0 -7
- package/dist/diagnostics/connection-path.js.map +1 -1
- package/dist/formation-approval.d.ts +7 -0
- package/dist/formation-approval.js +9 -3
- package/dist/formation-approval.js.map +1 -1
- package/dist/fs-atomic.d.ts +11 -2
- package/dist/fs-atomic.js +13 -3
- package/dist/fs-atomic.js.map +1 -1
- package/dist/hibernation-manager.d.ts +111 -8
- package/dist/hibernation-manager.js +234 -49
- package/dist/hibernation-manager.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +25 -20
- package/dist/index.js.map +1 -1
- package/dist/joined-strand-store.d.ts +90 -25
- package/dist/joined-strand-store.js +223 -55
- package/dist/joined-strand-store.js.map +1 -1
- package/dist/key-store-file.js +14 -5
- package/dist/key-store-file.js.map +1 -1
- package/dist/link-budget.d.ts +367 -69
- package/dist/link-budget.js +375 -72
- package/dist/link-budget.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +30 -43
- package/dist/membership-connection-gater.js +31 -42
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/node-local-snapshot.d.ts +6 -4
- package/dist/node-local-snapshot.js +7 -3
- package/dist/node-local-snapshot.js.map +1 -1
- package/dist/peer-dial.d.ts +24 -4
- package/dist/peer-dial.js +74 -5
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.d.ts +2 -10
- package/dist/peer-join-backfill.js +8 -8
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/push-fanout.d.ts +6 -0
- package/dist/push-fanout.js +6 -0
- package/dist/push-fanout.js.map +1 -1
- package/dist/relay-reservation.d.ts +3 -1
- package/dist/relay-reservation.js +3 -1
- package/dist/relay-reservation.js.map +1 -1
- package/dist/relay-server.d.ts +79 -0
- package/dist/relay-server.js +74 -0
- package/dist/relay-server.js.map +1 -0
- package/dist/seed-bootstrap.d.ts +57 -4
- package/dist/seed-bootstrap.js +107 -83
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/storage-scope.d.ts +33 -17
- package/dist/storage-scope.js +44 -23
- package/dist/storage-scope.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +58 -21
- package/dist/strand-addr-protocol.js +133 -85
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-database.d.ts +20 -2
- package/dist/strand-database.js +42 -5
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.d.ts +59 -21
- package/dist/strand-first-sync-gate.js +58 -19
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-deadlines.d.ts +151 -0
- package/dist/strand-formation-deadlines.js +171 -0
- package/dist/strand-formation-deadlines.js.map +1 -0
- package/dist/strand-formation-manager.d.ts +63 -30
- package/dist/strand-formation-manager.js +67 -41
- package/dist/strand-formation-manager.js.map +1 -1
- package/dist/strand-formation-protocol.d.ts +45 -46
- package/dist/strand-formation-protocol.js +62 -126
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-fret-addrs.d.ts +54 -0
- package/dist/strand-fret-addrs.js +108 -0
- package/dist/strand-fret-addrs.js.map +1 -0
- package/dist/strand-instance-manager.d.ts +122 -44
- package/dist/strand-instance-manager.js +270 -114
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +6 -0
- package/dist/strand-membership-writer.js +11 -0
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-network-state-file.d.ts +12 -0
- package/dist/strand-network-state-file.js +38 -0
- package/dist/strand-network-state-file.js.map +1 -0
- package/dist/strand-network-state.d.ts +111 -0
- package/dist/strand-network-state.js +191 -0
- package/dist/strand-network-state.js.map +1 -0
- package/dist/strand-revocation-enforcer.js +2 -1
- package/dist/strand-revocation-enforcer.js.map +1 -1
- package/dist/strand-solicitation.d.ts +36 -20
- package/dist/strand-solicitation.js +4 -4
- package/dist/strand-solicitation.js.map +1 -1
- package/dist/strand-wake-protocol.d.ts +80 -23
- package/dist/strand-wake-protocol.js +89 -64
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/types.d.ts +148 -61
- package/dist/types.js +4 -3
- package/dist/types.js.map +1 -1
- package/package.json +11 -10
- package/src/cadre-node.ts +8400 -7776
- package/src/control-authorization.ts +2 -1
- package/src/control-cohort.ts +6 -0
- package/src/control-database.ts +122 -18
- package/src/control-formation-recorder.ts +354 -305
- package/src/control-read-retry.ts +14 -12
- package/src/control-schema.ts +67 -5
- package/src/control-stream.ts +25 -1
- package/src/control-write-retry.ts +13 -2
- package/src/delegate-admission.ts +23 -13
- package/src/diagnostics/connection-path.ts +0 -7
- package/src/formation-approval.ts +610 -604
- package/src/fs-atomic.ts +14 -4
- package/src/hibernation-manager.ts +638 -437
- package/src/index.ts +43 -65
- package/src/joined-strand-store.ts +247 -57
- package/src/key-store-file.ts +14 -5
- package/src/link-budget.ts +393 -74
- package/src/membership-connection-gater.ts +31 -45
- package/src/node-local-snapshot.ts +12 -7
- package/src/peer-dial.ts +81 -7
- package/src/peer-join-backfill.ts +10 -9
- package/src/push-fanout.ts +6 -0
- package/src/relay-reservation.ts +3 -1
- package/src/relay-server.ts +98 -0
- package/src/seed-bootstrap.ts +133 -91
- package/src/storage-scope.ts +44 -23
- package/src/strand-addr-protocol.ts +547 -458
- package/src/strand-database.ts +287 -242
- package/src/strand-first-sync-gate.ts +58 -19
- package/src/strand-formation-deadlines.ts +227 -0
- package/src/strand-formation-manager.ts +700 -647
- package/src/strand-formation-protocol.ts +106 -154
- package/src/strand-fret-addrs.ts +145 -0
- package/src/strand-instance-manager.ts +307 -140
- package/src/strand-membership-writer.ts +12 -0
- package/src/strand-network-state-file.ts +40 -0
- package/src/strand-network-state.ts +243 -0
- package/src/strand-revocation-enforcer.ts +2 -1
- package/src/strand-solicitation.ts +519 -500
- package/src/strand-wake-protocol.ts +401 -355
- package/src/types.ts +150 -61
- package/dist/strand-peer-book-file.d.ts +0 -12
- package/dist/strand-peer-book-file.js +0 -37
- package/dist/strand-peer-book-file.js.map +0 -1
- package/dist/strand-peer-book-protocol.d.ts +0 -159
- package/dist/strand-peer-book-protocol.js +0 -360
- package/dist/strand-peer-book-protocol.js.map +0 -1
- package/dist/strand-peer-book-swap.d.ts +0 -104
- package/dist/strand-peer-book-swap.js +0 -284
- package/dist/strand-peer-book-swap.js.map +0 -1
- package/dist/strand-peer-book.d.ts +0 -159
- package/dist/strand-peer-book.js +0 -354
- package/dist/strand-peer-book.js.map +0 -1
- package/dist/strand-peer-observer.d.ts +0 -88
- package/dist/strand-peer-observer.js +0 -180
- package/dist/strand-peer-observer.js.map +0 -1
- package/src/strand-peer-book-file.ts +0 -39
- package/src/strand-peer-book-protocol.ts +0 -463
- package/src/strand-peer-book-swap.ts +0 -338
- package/src/strand-peer-book.ts +0 -468
- package/src/strand-peer-observer.ts +0 -235
package/dist/strand-peer-book.js
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node-local, NON-replicated **strand peer book**: for each strand this node runs,
|
|
3
|
-
* the strand peers it knows an address for — the other parties' strand transport
|
|
4
|
-
* peers, learned at formation and observed on every connection — with their
|
|
5
|
-
* last-known strand-network addresses and when this node last held a connection
|
|
6
|
-
* to them. Read on every launch, hibernation resume and periodic address refresh,
|
|
7
|
-
* so a machine that restarts dials the peers it was talking to BEFORE it does
|
|
8
|
-
* anything else, instead of coming back up alone.
|
|
9
|
-
*
|
|
10
|
-
* Why it exists (gotchoices/sereus#18): a cross-party strand learned the other
|
|
11
|
-
* party's strand addresses exactly once, at formation, into an in-memory map, and
|
|
12
|
-
* the strand-addr RPC answers own-party siblings only. After a restart neither
|
|
13
|
-
* relay-only party had any address for the other: the FRET ring and the Optimystic
|
|
14
|
-
* cohort each held only self, the strand reported `active`, local writes
|
|
15
|
-
* succeeded, nothing replicated.
|
|
16
|
-
*
|
|
17
|
-
* NOTE: accepted design boundary (maintainer decision, 2026-09-27) — this is a
|
|
18
|
-
* per-machine record in the machine's own storage, NOT a registry inside the
|
|
19
|
-
* strand database. An in-strand registry (`Strand.MemberPeer` rows carrying
|
|
20
|
-
* addresses) would let a member reach peers it has never connected to while they
|
|
21
|
-
* are offline; nothing needs that today, and it is ruled out for now. Revisit only
|
|
22
|
-
* if a case needs addresses to reach members that are offline.
|
|
23
|
-
*
|
|
24
|
-
* Three implementations mirroring `bootstrap-peer-store.ts` (read that first —
|
|
25
|
-
* same "must outlive the process, storage differs per platform" problem, both
|
|
26
|
-
* persistent forms share `node-local-snapshot.ts`):
|
|
27
|
-
* - {@link MemoryStrandPeerBookStore} (this module, cross-platform) — ephemeral;
|
|
28
|
-
* the default when no store is injected via `CadreNodeConfig.strandPeers`. A
|
|
29
|
-
* node using it is exactly the pre-#18 shape after a restart.
|
|
30
|
-
* - {@link PersistentStrandPeerBookStore} (this module, cross-platform) — durable
|
|
31
|
-
* over any `DurableSlot` the embedding app supplies.
|
|
32
|
-
* - `FileStrandPeerBookStore` — the above over a Node file in the node's state
|
|
33
|
-
* directory; Node-only, behind the subpath
|
|
34
|
-
* `@serfab/cadre-core/strand-peer-book-file` (same isolation pattern as
|
|
35
|
-
* `bootstrap-peer-store-file`) so `node:fs` never lands in the RN/browser graph.
|
|
36
|
-
*
|
|
37
|
-
* One store per NODE holding every strand, rather than one slot per strand: the
|
|
38
|
-
* snapshot machinery writes one slot whole, and a node runs a handful of strands
|
|
39
|
-
* with at most {@link MAX_STRAND_PEERS} peers each — a few KB. The embedder
|
|
40
|
-
* therefore wires one slot, like the other node-local stores.
|
|
41
|
-
*
|
|
42
|
-
* **Nothing here is trust-bearing.** An address grants no authority: the dialed
|
|
43
|
-
* peer authenticates by peer id at the handshake, and every address is bound to
|
|
44
|
-
* the peer id it is filed under (see {@link StrandPeerEntry.addrs}), so a dial
|
|
45
|
-
* cannot be redirected to whoever answers. A junk address costs one failed dial per
|
|
46
|
-
* launch until it ages out or the peer's next connection replaces the entry. What a
|
|
47
|
-
* persistent backend's loader DOES owe is dropping structurally junk entries rather
|
|
48
|
-
* than carrying them into the dial loop.
|
|
49
|
-
*/
|
|
50
|
-
import debug from 'debug';
|
|
51
|
-
import { peerIdFromString } from '@libp2p/peer-id';
|
|
52
|
-
import { NodeLocalSnapshot } from './node-local-snapshot.js';
|
|
53
|
-
import { groupAddrsByPeerId } from './peer-addr-book.js';
|
|
54
|
-
import { orderSignalingFirst } from './peer-record.js';
|
|
55
|
-
import { MAX_STRAND_ADDRS } from './strand-formation-protocol.js';
|
|
56
|
-
const log = debug('sereus:cadre:strand-peer-book');
|
|
57
|
-
/**
|
|
58
|
-
* Cap on the peers remembered per strand. When full, the entry with the smallest
|
|
59
|
-
* `max(issuedAt, lastSeenAt)` is evicted. Sixteen is generous for the parties a
|
|
60
|
-
* strand has today (two, occasionally a few), and it bounds the worst case of a
|
|
61
|
-
* launch dialing dead entries: a failed relayed dial costs up to 14 s at the
|
|
62
|
-
* declared link, so the cap — with aging — is what keeps a stale book from
|
|
63
|
-
* stalling bring-up for minutes.
|
|
64
|
-
*/
|
|
65
|
-
export const MAX_STRAND_PEERS = 16;
|
|
66
|
-
/**
|
|
67
|
-
* Default age after which an entry nobody has refreshed is dropped: 14 days from
|
|
68
|
-
* `max(issuedAt, lastSeenAt)`. A live peer refreshes its entry on every connection,
|
|
69
|
-
* so only a peer this node has not reached in two weeks ages out. Overridable per
|
|
70
|
-
* store via {@link StrandPeerBookOptions.maxAgeMs}.
|
|
71
|
-
*/
|
|
72
|
-
export const STRAND_PEER_MAX_AGE_MS = 14 * 24 * 60 * 60 * 1000;
|
|
73
|
-
function resolveOptions(options) {
|
|
74
|
-
return { maxAgeMs: options?.maxAgeMs ?? STRAND_PEER_MAX_AGE_MS, now: options?.now ?? Date.now };
|
|
75
|
-
}
|
|
76
|
-
/** The moment an entry was last vouched for, by whichever clock spoke last. */
|
|
77
|
-
export function strandPeerFreshness(entry) {
|
|
78
|
-
return Math.max(entry.issuedAt, entry.lastSeenAt);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* The merge rule, in one place. Returns the entry to hold for `incoming.peerId`
|
|
82
|
-
* given what is already held — always a NEW object, so a held entry is never mutated
|
|
83
|
-
* in place (the persistent backend's snapshot `put` replaces rather than patches).
|
|
84
|
-
* `incoming` is assumed sanitized ({@link sanitizeStrandPeerEntry}).
|
|
85
|
-
*
|
|
86
|
-
* - A signed entry never yields to an unsigned one for the same peer: the peer's own
|
|
87
|
-
* statement outranks this node's observation of it.
|
|
88
|
-
* - Between two signed entries the greater `issuedAt` wins; between two unsigned
|
|
89
|
-
* entries the greater `lastSeenAt` wins. A tie goes to `incoming`.
|
|
90
|
-
* - `lastSeenAt` is always the max of old and new whichever entry wins, because it
|
|
91
|
-
* is this node's own observation and no remote statement can lower it.
|
|
92
|
-
*/
|
|
93
|
-
export function mergeStrandPeerEntry(existing, incoming) {
|
|
94
|
-
const winner = existing === undefined || incomingWins(existing, incoming) ? incoming : existing;
|
|
95
|
-
return {
|
|
96
|
-
...winner,
|
|
97
|
-
addrs: [...winner.addrs],
|
|
98
|
-
lastSeenAt: Math.max(existing?.lastSeenAt ?? 0, incoming.lastSeenAt)
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function incomingWins(existing, incoming) {
|
|
102
|
-
if (existing.sig !== undefined && incoming.sig === undefined)
|
|
103
|
-
return false;
|
|
104
|
-
if (existing.sig === undefined && incoming.sig !== undefined)
|
|
105
|
-
return true;
|
|
106
|
-
return existing.sig !== undefined
|
|
107
|
-
? incoming.issuedAt >= existing.issuedAt
|
|
108
|
-
: incoming.lastSeenAt >= existing.lastSeenAt;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Shape an entry for storage: the peer id must parse (else `undefined` — not a dial
|
|
112
|
-
* target at all), and `addrs` is reduced to the entries that attribute to `peerId`
|
|
113
|
-
* under `groupAddrsByPeerId`'s rule, de-duplicated, capped at `MAX_STRAND_ADDRS`, and
|
|
114
|
-
* — for an UNSIGNED entry only — reordered signaling-first. A signed entry keeps the
|
|
115
|
-
* signer's order: its signature covers the address list as signed, and the swap
|
|
116
|
-
* forwards the stored copy, so any reordering here would make every forwarded entry
|
|
117
|
-
* fail verification at the next peer (every signer already orders signaling-first). An
|
|
118
|
-
* entry may legitimately end up with NO addresses — a signed "not reachable right
|
|
119
|
-
* now" from the swap protocol is truthful and displaces a stale reachable list — so
|
|
120
|
-
* an empty list is kept, not rejected.
|
|
121
|
-
*/
|
|
122
|
-
export function sanitizeStrandPeerEntry(entry) {
|
|
123
|
-
try {
|
|
124
|
-
peerIdFromString(entry.peerId);
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
log('dropping entry for unparsable peer id %s: %o', entry.peerId, error);
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
const attributed = (groupAddrsByPeerId([...entry.addrs]).get(entry.peerId) ?? []).map((ma) => ma.toString());
|
|
131
|
-
const addrs = (entry.sig === undefined ? orderSignalingFirst(attributed) : attributed).slice(0, MAX_STRAND_ADDRS);
|
|
132
|
-
if (addrs.length < entry.addrs.length) {
|
|
133
|
-
log('peer %s: kept %d of %d addr(s) — the rest do not attribute to it or exceed the cap', entry.peerId, addrs.length, entry.addrs.length);
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
peerId: entry.peerId,
|
|
137
|
-
addrs,
|
|
138
|
-
issuedAt: entry.issuedAt,
|
|
139
|
-
...(entry.sig !== undefined && { sig: entry.sig }),
|
|
140
|
-
lastSeenAt: entry.lastSeenAt
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Apply {@link mergeStrandPeerEntry} to one strand's map and re-bound it: aged-out
|
|
145
|
-
* entries dropped, then the stalest evicted past {@link MAX_STRAND_PEERS}. Returns a
|
|
146
|
-
* NEW map (the persistent backend's snapshot `put` replaces rather than mutates),
|
|
147
|
-
* or `undefined` when the incoming entry was unusable and nothing changed.
|
|
148
|
-
*
|
|
149
|
-
* NOTE: aging is time-based only. The book cannot see dial outcomes (dials happen
|
|
150
|
-
* inside libp2p and Optimystic), so a dead entry is re-dialed on every launch and
|
|
151
|
-
* refresh until it ages out or the peer's next connection replaces it — bounded by
|
|
152
|
-
* the peer cap and the 14-day age. If a case ever shows a dead entry re-dialed every
|
|
153
|
-
* tick for two weeks, the lever is observing `connection:close` / dial failures
|
|
154
|
-
* here, not a shorter age.
|
|
155
|
-
*/
|
|
156
|
-
function mergeIntoStrand(strand, incoming, options) {
|
|
157
|
-
const entry = sanitizeStrandPeerEntry(incoming);
|
|
158
|
-
if (!entry)
|
|
159
|
-
return undefined;
|
|
160
|
-
const merged = mergeStrandPeerEntry(strand?.[entry.peerId], entry);
|
|
161
|
-
// Pruned AFTER the insert, so an incoming entry that is already past the age
|
|
162
|
-
// (a swap forwarding a months-old statement) never lands at all.
|
|
163
|
-
return evictPastCap(pruneAged({ ...strand, [entry.peerId]: merged }, options));
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* The strand's map without the entries older than `maxAgeMs` (a new object only when
|
|
167
|
-
* something dropped).
|
|
168
|
-
*
|
|
169
|
-
* Nothing is exempt, the node's OWN entry included: the book swap
|
|
170
|
-
* (`strand-peer-book-swap.ts`) keeps the entry it SENDS in memory and re-signs it on
|
|
171
|
-
* every address change and every launch, so the stored copy is a record for
|
|
172
|
-
* diagnostics and the seed's self-skip, and losing it to age costs nothing. That is
|
|
173
|
-
* why the store need not tell self from a peer.
|
|
174
|
-
*/
|
|
175
|
-
function pruneAged(strand, options) {
|
|
176
|
-
const cutoff = options.now() - options.maxAgeMs;
|
|
177
|
-
const live = Object.values(strand).filter((entry) => strandPeerFreshness(entry) >= cutoff);
|
|
178
|
-
return live.length === Object.keys(strand).length ? strand : Object.fromEntries(live.map((e) => [e.peerId, e]));
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Drop the stalest entries until the strand holds at most {@link MAX_STRAND_PEERS}.
|
|
182
|
-
*
|
|
183
|
-
* NOTE: freshness ranks a forwarded statement (signer's `issuedAt`, up to five minutes
|
|
184
|
-
* ahead of this clock) above a peer this node has itself connected to, so one swap
|
|
185
|
-
* frame of sixteen fresh self-signed entries evicts every met peer — see
|
|
186
|
-
* `backlog/debt-strand-peer-book-remote-write-bounds`.
|
|
187
|
-
*/
|
|
188
|
-
function evictPastCap(strand) {
|
|
189
|
-
const entries = Object.values(strand);
|
|
190
|
-
if (entries.length <= MAX_STRAND_PEERS)
|
|
191
|
-
return strand;
|
|
192
|
-
const kept = sortFreshestFirst(entries).slice(0, MAX_STRAND_PEERS);
|
|
193
|
-
log('evicting %d stalest peer(s) past the %d-peer cap', entries.length - kept.length, MAX_STRAND_PEERS);
|
|
194
|
-
return Object.fromEntries(kept.map((e) => [e.peerId, e]));
|
|
195
|
-
}
|
|
196
|
-
function sortFreshestFirst(entries) {
|
|
197
|
-
return [...entries].sort((a, b) => strandPeerFreshness(b) - strandPeerFreshness(a));
|
|
198
|
-
}
|
|
199
|
-
/** The live entries of one strand, freshest first, copied. */
|
|
200
|
-
function liveEntries(strand, options) {
|
|
201
|
-
if (!strand)
|
|
202
|
-
return [];
|
|
203
|
-
return sortFreshestFirst(Object.values(pruneAged(strand, options)))
|
|
204
|
-
.map((entry) => ({ ...entry, addrs: [...entry.addrs] }));
|
|
205
|
-
}
|
|
206
|
-
/** The strand's map without `peerId`, or `undefined` when that leaves nothing (or nothing was there). */
|
|
207
|
-
function withoutPeer(strand, peerId) {
|
|
208
|
-
if (!strand || !(peerId in strand))
|
|
209
|
-
return strand;
|
|
210
|
-
const { [peerId]: _dropped, ...rest } = strand;
|
|
211
|
-
return Object.keys(rest).length === 0 ? undefined : rest;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Ephemeral in-memory book for nodes without durable storage (tests, and the
|
|
215
|
-
* default when nothing is injected). Same contract, no disk: a node using this
|
|
216
|
-
* forgets every strand peer on restart — the #18 shape.
|
|
217
|
-
*/
|
|
218
|
-
export class MemoryStrandPeerBookStore {
|
|
219
|
-
constructor(partyId, options) {
|
|
220
|
-
this.partyId = partyId;
|
|
221
|
-
this.strands = new Map();
|
|
222
|
-
this.options = resolveOptions(options);
|
|
223
|
-
}
|
|
224
|
-
entries(strandId) {
|
|
225
|
-
return liveEntries(this.strands.get(strandId), this.options);
|
|
226
|
-
}
|
|
227
|
-
async merge(strandId, entry) {
|
|
228
|
-
const next = mergeIntoStrand(this.strands.get(strandId), entry, this.options);
|
|
229
|
-
if (next) {
|
|
230
|
-
this.strands.set(strandId, next);
|
|
231
|
-
log('strand %s: peer %s merged (party=%s, addrs=%d)', strandId, entry.peerId, this.partyId, entry.addrs.length);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
async forget(strandId, peerId) {
|
|
235
|
-
if (peerId === undefined) {
|
|
236
|
-
if (this.strands.delete(strandId)) {
|
|
237
|
-
log('strand %s: book forgotten (party=%s)', strandId, this.partyId);
|
|
238
|
-
}
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
const next = withoutPeer(this.strands.get(strandId), peerId);
|
|
242
|
-
if (next === undefined) {
|
|
243
|
-
this.strands.delete(strandId);
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
this.strands.set(strandId, next);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* What the store persists: `strands` maps strandId -> (peerId -> {@link StrandPeerEntry}).
|
|
252
|
-
*
|
|
253
|
-
* A structurally junk PEER entry is dropped and its siblings retained; a strand
|
|
254
|
-
* whose value is not a record, or that holds no usable peer, is dropped as a whole
|
|
255
|
-
* (`drop-entry`) — nothing here is trust-bearing (see the module comment) and the
|
|
256
|
-
* book is a restarted node's only way back to the other parties, so discarding the
|
|
257
|
-
* whole set over one bad entry would be strictly worse. What "junk" means: a peer id
|
|
258
|
-
* that does not parse, a non-array or non-string address list, a non-number
|
|
259
|
-
* `issuedAt` / `lastSeenAt`, or a non-string `sig`. Aged-out entries are dropped at
|
|
260
|
-
* load too, so a slot last written months ago yields nothing to dial.
|
|
261
|
-
*/
|
|
262
|
-
function strandPeerBookSnapshotSpec(options) {
|
|
263
|
-
return {
|
|
264
|
-
label: 'strand peer book',
|
|
265
|
-
payloadKey: 'strands',
|
|
266
|
-
unusableEntry: 'drop-entry',
|
|
267
|
-
acceptEntry: (strandId, raw) => {
|
|
268
|
-
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
269
|
-
return undefined;
|
|
270
|
-
let strand = {};
|
|
271
|
-
for (const [peerId, value] of Object.entries(raw)) {
|
|
272
|
-
const entry = acceptPeerEntry(peerId, value);
|
|
273
|
-
if (!entry) {
|
|
274
|
-
log('strand %s: dropping unusable persisted entry for %s', strandId, peerId);
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
strand[peerId] = entry;
|
|
278
|
-
}
|
|
279
|
-
strand = pruneAged(strand, options);
|
|
280
|
-
return Object.keys(strand).length === 0 ? undefined : strand;
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
function acceptPeerEntry(peerId, value) {
|
|
285
|
-
if (typeof value !== 'object' || value === null)
|
|
286
|
-
return undefined;
|
|
287
|
-
const { addrs, issuedAt, sig, lastSeenAt } = value;
|
|
288
|
-
if (!Array.isArray(addrs) || addrs.some((addr) => typeof addr !== 'string' || addr.length === 0))
|
|
289
|
-
return undefined;
|
|
290
|
-
if (typeof issuedAt !== 'number' || typeof lastSeenAt !== 'number')
|
|
291
|
-
return undefined;
|
|
292
|
-
if (sig !== undefined && typeof sig !== 'string')
|
|
293
|
-
return undefined;
|
|
294
|
-
return sanitizeStrandPeerEntry({
|
|
295
|
-
peerId,
|
|
296
|
-
addrs: addrs,
|
|
297
|
-
issuedAt,
|
|
298
|
-
...(sig !== undefined && { sig }),
|
|
299
|
-
lastSeenAt
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Durable {@link StrandPeerBookStore} over an app-supplied {@link DurableSlot} —
|
|
304
|
-
* the cross-platform half of every persistent backend (the Node
|
|
305
|
-
* `FileStrandPeerBookStore` is this class over a file slot).
|
|
306
|
-
*
|
|
307
|
-
* Construct via {@link open}. Load and persist policy — what an absent, corrupt,
|
|
308
|
-
* foreign-party or unreadable slot does (the last one THROWS, as
|
|
309
|
-
* `PersistentBootstrapPeerStore.open` does), and what a failed persist does — is
|
|
310
|
-
* documented once on `NodeLocalSnapshot`; this class only supplies the payload shape
|
|
311
|
-
* and the drop-the-bad-entry policy above. Writes are serialised in-process by the
|
|
312
|
-
* snapshot's write chain, so several strands' identify handlers merging at once
|
|
313
|
-
* cannot interleave partial snapshots.
|
|
314
|
-
*/
|
|
315
|
-
export class PersistentStrandPeerBookStore {
|
|
316
|
-
constructor(snapshot, options) {
|
|
317
|
-
this.snapshot = snapshot;
|
|
318
|
-
this.options = options;
|
|
319
|
-
}
|
|
320
|
-
/** Load (or cold-start) the party's book from `slot`. */
|
|
321
|
-
static async open(slot, partyId, options) {
|
|
322
|
-
const resolved = resolveOptions(options);
|
|
323
|
-
return new PersistentStrandPeerBookStore(await NodeLocalSnapshot.open(slot, partyId, strandPeerBookSnapshotSpec(resolved)), resolved);
|
|
324
|
-
}
|
|
325
|
-
get partyId() {
|
|
326
|
-
return this.snapshot.partyId;
|
|
327
|
-
}
|
|
328
|
-
entries(strandId) {
|
|
329
|
-
return liveEntries(this.snapshot.entrySnapshot().get(strandId), this.options);
|
|
330
|
-
}
|
|
331
|
-
/** Merge, visible via {@link entries} synchronously, then the full snapshot is persisted. */
|
|
332
|
-
merge(strandId, entry) {
|
|
333
|
-
const next = mergeIntoStrand(this.snapshot.entrySnapshot().get(strandId), entry, this.options);
|
|
334
|
-
if (!next)
|
|
335
|
-
return Promise.resolve();
|
|
336
|
-
log('strand %s: peer %s merged (party=%s, addrs=%d); persisting', strandId, entry.peerId, this.partyId, entry.addrs.length);
|
|
337
|
-
return this.snapshot.put(strandId, next);
|
|
338
|
-
}
|
|
339
|
-
/** Forget, gone from {@link entries} synchronously, then persisted — unless nothing was there. */
|
|
340
|
-
forget(strandId, peerId) {
|
|
341
|
-
if (peerId === undefined) {
|
|
342
|
-
if (this.snapshot.has(strandId)) {
|
|
343
|
-
log('strand %s: book forgotten (party=%s); persisting', strandId, this.partyId);
|
|
344
|
-
}
|
|
345
|
-
return this.snapshot.remove(strandId);
|
|
346
|
-
}
|
|
347
|
-
const current = this.snapshot.entrySnapshot().get(strandId);
|
|
348
|
-
const next = withoutPeer(current, peerId);
|
|
349
|
-
if (next === current)
|
|
350
|
-
return Promise.resolve();
|
|
351
|
-
return next === undefined ? this.snapshot.remove(strandId) : this.snapshot.put(strandId, next);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
//# sourceMappingURL=strand-peer-book.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strand-peer-book.js","sourceRoot":"","sources":["../src/strand-peer-book.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAgD,MAAM,0BAA0B,CAAC;AAC3G,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,MAAM,GAAG,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAyF/D,SAAS,cAAc,CAAC,OAA+B;IACtD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,sBAAsB,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AACjG,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,mBAAmB,CAAC,KAAsB;IACzD,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CACnC,QAAqC,EACrC,QAAyB;IAEzB,MAAM,MAAM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OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QACpC,GAAG,CAAC,4DAA4D,EAC/D,QAAQ,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,kGAAkG;IAClG,MAAM,CAAC,QAAgB,EAAE,MAAe;QACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACjC,GAAG,CAAC,kDAAkD,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACjF,CAAC;YACD,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACvC,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5D,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAI,IAAI,KAAK,OAAO;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC/C,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAChG,CAAC;CACD"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { Connection, Libp2p, PeerId } from '@libp2p/interface';
|
|
2
|
-
/** Minimum gap between two reports of ONE peer with an unchanged address set. */
|
|
3
|
-
export declare const STRAND_PEER_OBSERVE_THROTTLE_MS: number;
|
|
4
|
-
/** One strand peer seen live: its strand transport peer id and the addresses it is dialable at. */
|
|
5
|
-
export interface StrandPeerObservation {
|
|
6
|
-
peerId: string;
|
|
7
|
-
/** Bound to `peerId`, signaling-first, at most `MAX_STRAND_ADDRS`. */
|
|
8
|
-
addrs: string[];
|
|
9
|
-
}
|
|
10
|
-
export interface StrandPeerObserverDeps {
|
|
11
|
-
/** For logs (the strand id). */
|
|
12
|
-
label: string;
|
|
13
|
-
/** The strand's libp2p node. */
|
|
14
|
-
libp2p: Libp2p;
|
|
15
|
-
/** This strand network's `/optimystic/<networkName>` prefix — the block-transfer gate. */
|
|
16
|
-
protocolPrefix: string;
|
|
17
|
-
/** Called for every (throttled) observation; must not throw. */
|
|
18
|
-
onObserved: (observation: StrandPeerObservation) => void;
|
|
19
|
-
}
|
|
20
|
-
export interface StrandPeerObserverOptions {
|
|
21
|
-
/** Default {@link STRAND_PEER_OBSERVE_THROTTLE_MS}. */
|
|
22
|
-
throttleMs?: number;
|
|
23
|
-
/** Clock, for tests. Default `Date.now`. */
|
|
24
|
-
now?: () => number;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Anything that prints as a multiaddr. libp2p's identify result and peer store hand
|
|
28
|
-
* back its nested `@multiformats/multiaddr` copy, a structurally different type from
|
|
29
|
-
* this package's, so addresses are taken by their string form and re-parsed here.
|
|
30
|
-
*/
|
|
31
|
-
export interface AddrLike {
|
|
32
|
-
toString(): string;
|
|
33
|
-
}
|
|
34
|
-
/** One connected peer as the peer store knows it: what identify recorded, plus its open connections. */
|
|
35
|
-
export interface ConnectedIdentifiedPeer {
|
|
36
|
-
peerId: PeerId;
|
|
37
|
-
protocols: string[];
|
|
38
|
-
/** The stored addresses: identify-announced, plus whatever else was merged in. */
|
|
39
|
-
addrs: AddrLike[];
|
|
40
|
-
connections: Connection[];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Every peer `libp2p` holds a connection to AND has already identified (it is in the
|
|
44
|
-
* peer store), grouped per peer. A connected peer whose identify has not finished is
|
|
45
|
-
* left out: its `peer:identify` event is still to come, and every listener that walks
|
|
46
|
-
* this list at start subscribes to that event too. Shared by the peer-book observer
|
|
47
|
-
* and the book swap (`strand-peer-book-swap.ts`), which both arm right after the
|
|
48
|
-
* node exists and may already have missed an early peer's identify.
|
|
49
|
-
*/
|
|
50
|
-
export declare function connectedIdentifiedPeers(libp2p: Libp2p, label: string): Promise<ConnectedIdentifiedPeer[]>;
|
|
51
|
-
export declare class StrandPeerObserver {
|
|
52
|
-
private readonly deps;
|
|
53
|
-
private readonly throttleMs;
|
|
54
|
-
private readonly now;
|
|
55
|
-
private readonly lastReports;
|
|
56
|
-
private readonly onPeerIdentify;
|
|
57
|
-
private started;
|
|
58
|
-
private stopped;
|
|
59
|
-
constructor(deps: StrandPeerObserverDeps, options?: StrandPeerObserverOptions);
|
|
60
|
-
/** Subscribe to `peer:identify` and report the peers already connected and identified. */
|
|
61
|
-
start(): void;
|
|
62
|
-
/** Unsubscribe; later identify results are ignored. */
|
|
63
|
-
stop(): void;
|
|
64
|
-
/**
|
|
65
|
-
* Report every connected peer the peer store already knows speaks this strand's
|
|
66
|
-
* protocol, with its stored addresses. A peer not yet in the store (identify has
|
|
67
|
-
* not finished) is left to the `peer:identify` handler. Returns the number of
|
|
68
|
-
* identified peers considered.
|
|
69
|
-
*
|
|
70
|
-
* NOTE: the stored addresses include what `CadreNode.mergeStrandPeerAddrs` merged
|
|
71
|
-
* INTO the peer store from the book, so this walk can re-vouch a dead address the
|
|
72
|
-
* book already held, until the peer's next `peer:identify` replaces the set with
|
|
73
|
-
* what it announces now. Bounded by the address cap; if a dead address ever shows
|
|
74
|
-
* up surviving across resumes, read only the peer store's identify-sourced
|
|
75
|
-
* addresses here rather than shortening the age.
|
|
76
|
-
*/
|
|
77
|
-
private observeConnectedPeers;
|
|
78
|
-
/** Shape, throttle and report one peer. Never throws. */
|
|
79
|
-
private observe;
|
|
80
|
-
/** One report per peer per throttle window, unless the address set changed. */
|
|
81
|
-
private shouldReport;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The addresses to file for `peerId`: its announced listen addrs plus every relayed
|
|
85
|
-
* connection addr, each bound to `peerId`, de-duplicated, signaling-first, capped.
|
|
86
|
-
* Re-parsed through this package's own `multiaddr` (see {@link AddrLike}).
|
|
87
|
-
*/
|
|
88
|
-
export declare function dialableAddrs(peerId: string, listenAddrs: AddrLike[], connections: Connection[]): string[];
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The strand peer book's OBSERVATION writer: on one strand libp2p node, every peer
|
|
3
|
-
* whose identify result names this strand's block-transfer protocol — a strand peer,
|
|
4
|
-
* never the circuit relay or a bootstrap node ({@link speaksBlockTransfer}, the
|
|
5
|
-
* same gate `PeerJoinBackfill` schedules on) — is reported with its dialable
|
|
6
|
-
* addresses, so `CadreNode` can merge an unsigned book entry for it
|
|
7
|
-
* (`strand-peer-book.ts`). That is what lets a restarted machine dial the peers it
|
|
8
|
-
* was talking to, instead of only the ones a formation once carried back.
|
|
9
|
-
*
|
|
10
|
-
* Dialable addresses are the peer's announced `listenAddrs` from the identify
|
|
11
|
-
* result, plus the open connection's `remoteAddr` when it is relayed
|
|
12
|
-
* (`/p2p-circuit`) — a relay-only peer announces its circuit listener, but the
|
|
13
|
-
* address this node actually reached it on is the one proven to work. Every
|
|
14
|
-
* address is bound to the peer id (`withTrailingPeerId`), ordered signaling-first
|
|
15
|
-
* and capped like a formation's list, so the book files it under the right peer.
|
|
16
|
-
*
|
|
17
|
-
* Throttled to one report per peer per {@link STRAND_PEER_OBSERVE_THROTTLE_MS}
|
|
18
|
-
* unless the address set changed, so a flapping relayed connection — identify
|
|
19
|
-
* fires on every reconnect, every 14 s at worst — does not rewrite the node-local
|
|
20
|
-
* slot each time. Best-effort throughout: nothing here throws into a libp2p event
|
|
21
|
-
* handler.
|
|
22
|
-
*
|
|
23
|
-
* Lifecycle: one observer per running strand, armed in
|
|
24
|
-
* `StrandInstanceManager.buildStrandRuntime` right after the libp2p node exists
|
|
25
|
-
* (the bootstrap dials that follow `libp2p.start()` are exactly the peers worth
|
|
26
|
-
* observing) and stopped in `releaseRuntime`, so a hibernation wake re-arms it on
|
|
27
|
-
* the rebuilt node. `start` also walks the peers already connected, because
|
|
28
|
-
* identify may have completed for an early peer before this object existed.
|
|
29
|
-
*/
|
|
30
|
-
import debug from 'debug';
|
|
31
|
-
import { multiaddr } from '@multiformats/multiaddr';
|
|
32
|
-
import { speaksBlockTransfer } from './peer-join-backfill.js';
|
|
33
|
-
import { isSignalingAddr, orderSignalingFirst, withTrailingPeerId } from './peer-record.js';
|
|
34
|
-
import { MAX_STRAND_ADDRS } from './strand-formation-protocol.js';
|
|
35
|
-
const log = debug('sereus:cadre:strand-peer-observer');
|
|
36
|
-
/** Minimum gap between two reports of ONE peer with an unchanged address set. */
|
|
37
|
-
export const STRAND_PEER_OBSERVE_THROTTLE_MS = 10 * 60 * 1000;
|
|
38
|
-
/**
|
|
39
|
-
* Every peer `libp2p` holds a connection to AND has already identified (it is in the
|
|
40
|
-
* peer store), grouped per peer. A connected peer whose identify has not finished is
|
|
41
|
-
* left out: its `peer:identify` event is still to come, and every listener that walks
|
|
42
|
-
* this list at start subscribes to that event too. Shared by the peer-book observer
|
|
43
|
-
* and the book swap (`strand-peer-book-swap.ts`), which both arm right after the
|
|
44
|
-
* node exists and may already have missed an early peer's identify.
|
|
45
|
-
*/
|
|
46
|
-
export async function connectedIdentifiedPeers(libp2p, label) {
|
|
47
|
-
const byPeer = new Map();
|
|
48
|
-
for (const connection of libp2p.getConnections()) {
|
|
49
|
-
const key = connection.remotePeer.toString();
|
|
50
|
-
const group = byPeer.get(key) ?? { peerId: connection.remotePeer, connections: [] };
|
|
51
|
-
group.connections.push(connection);
|
|
52
|
-
byPeer.set(key, group);
|
|
53
|
-
}
|
|
54
|
-
const identified = await Promise.all([...byPeer.values()].map(async ({ peerId, connections }) => {
|
|
55
|
-
try {
|
|
56
|
-
const peer = await libp2p.peerStore.get(peerId);
|
|
57
|
-
return { peerId, protocols: peer.protocols, addrs: peer.addresses.map((a) => a.multiaddr), connections };
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
// NotFoundError: identify has not finished; the event handler will see it.
|
|
61
|
-
if (error.name !== 'NotFoundError') {
|
|
62
|
-
log('[%s] peer store read for %s failed — skipping it: %o', label, peerId.toString(), error);
|
|
63
|
-
}
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
}));
|
|
67
|
-
return identified.filter((peer) => peer !== undefined);
|
|
68
|
-
}
|
|
69
|
-
export class StrandPeerObserver {
|
|
70
|
-
constructor(deps, options) {
|
|
71
|
-
this.deps = deps;
|
|
72
|
-
this.lastReports = new Map();
|
|
73
|
-
this.started = false;
|
|
74
|
-
this.stopped = false;
|
|
75
|
-
this.throttleMs = options?.throttleMs ?? STRAND_PEER_OBSERVE_THROTTLE_MS;
|
|
76
|
-
this.now = options?.now ?? Date.now;
|
|
77
|
-
this.onPeerIdentify = (evt) => {
|
|
78
|
-
const { peerId, protocols, listenAddrs, connection } = evt.detail;
|
|
79
|
-
if (speaksBlockTransfer(protocols, this.deps.protocolPrefix)) {
|
|
80
|
-
this.observe(peerId, listenAddrs, [connection]);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
/** Subscribe to `peer:identify` and report the peers already connected and identified. */
|
|
85
|
-
start() {
|
|
86
|
-
if (this.started || this.stopped)
|
|
87
|
-
return;
|
|
88
|
-
this.started = true;
|
|
89
|
-
this.deps.libp2p.addEventListener('peer:identify', this.onPeerIdentify);
|
|
90
|
-
void this.observeConnectedPeers().then((seen) => {
|
|
91
|
-
log('[%s] started (%d peer(s) already connected)', this.deps.label, seen);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/** Unsubscribe; later identify results are ignored. */
|
|
95
|
-
stop() {
|
|
96
|
-
if (this.stopped)
|
|
97
|
-
return;
|
|
98
|
-
this.stopped = true;
|
|
99
|
-
if (this.started) {
|
|
100
|
-
this.deps.libp2p.removeEventListener('peer:identify', this.onPeerIdentify);
|
|
101
|
-
}
|
|
102
|
-
this.lastReports.clear();
|
|
103
|
-
log('[%s] stopped', this.deps.label);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Report every connected peer the peer store already knows speaks this strand's
|
|
107
|
-
* protocol, with its stored addresses. A peer not yet in the store (identify has
|
|
108
|
-
* not finished) is left to the `peer:identify` handler. Returns the number of
|
|
109
|
-
* identified peers considered.
|
|
110
|
-
*
|
|
111
|
-
* NOTE: the stored addresses include what `CadreNode.mergeStrandPeerAddrs` merged
|
|
112
|
-
* INTO the peer store from the book, so this walk can re-vouch a dead address the
|
|
113
|
-
* book already held, until the peer's next `peer:identify` replaces the set with
|
|
114
|
-
* what it announces now. Bounded by the address cap; if a dead address ever shows
|
|
115
|
-
* up surviving across resumes, read only the peer store's identify-sourced
|
|
116
|
-
* addresses here rather than shortening the age.
|
|
117
|
-
*/
|
|
118
|
-
async observeConnectedPeers() {
|
|
119
|
-
const peers = await connectedIdentifiedPeers(this.deps.libp2p, this.deps.label);
|
|
120
|
-
for (const { peerId, protocols, addrs, connections } of peers) {
|
|
121
|
-
if (!this.stopped && speaksBlockTransfer(protocols, this.deps.protocolPrefix)) {
|
|
122
|
-
this.observe(peerId, addrs, connections);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return peers.length;
|
|
126
|
-
}
|
|
127
|
-
/** Shape, throttle and report one peer. Never throws. */
|
|
128
|
-
observe(peerId, listenAddrs, connections) {
|
|
129
|
-
if (this.stopped)
|
|
130
|
-
return;
|
|
131
|
-
const id = peerId.toString();
|
|
132
|
-
// Identify is about remotes, so self never arrives here; belt and braces, since
|
|
133
|
-
// a node must never file its own addresses as a peer to dial.
|
|
134
|
-
if (id === this.deps.libp2p.peerId.toString())
|
|
135
|
-
return;
|
|
136
|
-
try {
|
|
137
|
-
const addrs = dialableAddrs(id, listenAddrs, connections);
|
|
138
|
-
if (!this.shouldReport(id, addrs))
|
|
139
|
-
return;
|
|
140
|
-
log('[%s] observed strand peer %s at %d addr(s)', this.deps.label, id, addrs.length);
|
|
141
|
-
this.deps.onObserved({ peerId: id, addrs });
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
log('[%s] observing %s failed (ignored): %o', this.deps.label, id, error);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/** One report per peer per throttle window, unless the address set changed. */
|
|
148
|
-
shouldReport(peerId, addrs) {
|
|
149
|
-
const now = this.now();
|
|
150
|
-
const key = [...addrs].sort().join('\n');
|
|
151
|
-
const last = this.lastReports.get(peerId);
|
|
152
|
-
if (last && last.key === key && now - last.at < this.throttleMs) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
this.lastReports.set(peerId, { at: now, key });
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* The addresses to file for `peerId`: its announced listen addrs plus every relayed
|
|
161
|
-
* connection addr, each bound to `peerId`, de-duplicated, signaling-first, capped.
|
|
162
|
-
* Re-parsed through this package's own `multiaddr` (see {@link AddrLike}).
|
|
163
|
-
*/
|
|
164
|
-
export function dialableAddrs(peerId, listenAddrs, connections) {
|
|
165
|
-
const candidates = [
|
|
166
|
-
...listenAddrs.map((ma) => ma.toString()),
|
|
167
|
-
...connections.map((c) => c.remoteAddr.toString()).filter(isSignalingAddr)
|
|
168
|
-
];
|
|
169
|
-
const bound = new Set();
|
|
170
|
-
for (const candidate of candidates) {
|
|
171
|
-
const addr = withTrailingPeerId(multiaddr(candidate), peerId);
|
|
172
|
-
if (addr === null) {
|
|
173
|
-
log('dropping addr %s — it names a peer other than %s', candidate, peerId);
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
bound.add(addr.toString());
|
|
177
|
-
}
|
|
178
|
-
return orderSignalingFirst([...bound]).slice(0, MAX_STRAND_ADDRS);
|
|
179
|
-
}
|
|
180
|
-
//# sourceMappingURL=strand-peer-observer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strand-peer-observer.js","sourceRoot":"","sources":["../src/strand-peer-observer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,MAAM,GAAG,GAAG,KAAK,CAAC,mCAAmC,CAAC,CAAC;AAEvD,iFAAiF;AACjF,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAmD9D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,MAAc,EAAE,KAAa;IAC3E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyD,CAAC;IAChF,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,cAAc,EAAE,EAAE,CAAC;QAClD,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;QACpF,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,C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