@serfab/cadre-core 0.11.0 → 0.13.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 +3 -2
- package/dist/announce-addrs.d.ts +49 -0
- package/dist/announce-addrs.js +78 -0
- package/dist/announce-addrs.js.map +1 -0
- package/dist/cadre-node.d.ts +607 -53
- package/dist/cadre-node.js +1268 -157
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-database.d.ts +174 -23
- package/dist/control-database.js +317 -107
- package/dist/control-database.js.map +1 -1
- package/dist/control-read-retry.d.ts +103 -0
- package/dist/control-read-retry.js +145 -0
- package/dist/control-read-retry.js.map +1 -0
- package/dist/control-retry.d.ts +101 -0
- package/dist/control-retry.js +108 -0
- package/dist/control-retry.js.map +1 -0
- package/dist/control-schema.d.ts +1 -1
- package/dist/control-schema.js +50 -6
- package/dist/control-schema.js.map +1 -1
- package/dist/control-write-retry.d.ts +59 -35
- package/dist/control-write-retry.js +21 -92
- package/dist/control-write-retry.js.map +1 -1
- package/dist/delegate-admission.d.ts +17 -15
- package/dist/delegate-admission.js +17 -15
- package/dist/delegate-admission.js.map +1 -1
- package/dist/enrolled-machine-store-file.d.ts +13 -0
- package/dist/enrolled-machine-store-file.js +41 -0
- package/dist/enrolled-machine-store-file.js.map +1 -0
- package/dist/enrolled-machine-store.d.ts +81 -0
- package/dist/enrolled-machine-store.js +225 -0
- package/dist/enrolled-machine-store.js.map +1 -0
- package/dist/file-durable-slot.js +5 -3
- package/dist/file-durable-slot.js.map +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.js +39 -12
- package/dist/index.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +226 -26
- package/dist/membership-connection-gater.js +316 -30
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/node-local-snapshot.d.ts +6 -0
- package/dist/node-local-snapshot.js +7 -1
- package/dist/node-local-snapshot.js.map +1 -1
- package/dist/{strand-backfill.d.ts → peer-join-backfill.d.ts} +49 -20
- package/dist/{strand-backfill.js → peer-join-backfill.js} +146 -56
- package/dist/peer-join-backfill.js.map +1 -0
- package/dist/peer-record.d.ts +26 -0
- package/dist/peer-record.js +32 -0
- package/dist/peer-record.js.map +1 -1
- package/dist/relay-addrs.d.ts +145 -22
- package/dist/relay-addrs.js +314 -31
- package/dist/relay-addrs.js.map +1 -1
- package/dist/relay-reservation.d.ts +20 -15
- package/dist/relay-reservation.js +18 -14
- package/dist/relay-reservation.js.map +1 -1
- package/dist/strand-addr-protocol.js +16 -0
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-database.d.ts +12 -0
- package/dist/strand-database.js +16 -0
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-formation-manager.d.ts +22 -9
- package/dist/strand-formation-manager.js +20 -12
- package/dist/strand-formation-manager.js.map +1 -1
- package/dist/strand-formation-protocol.d.ts +83 -9
- package/dist/strand-formation-protocol.js +86 -10
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +151 -17
- package/dist/strand-instance-manager.js +237 -32
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +118 -14
- package/dist/strand-membership-writer.js +203 -15
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-network-config.d.ts +84 -0
- package/dist/strand-network-config.js +136 -0
- package/dist/strand-network-config.js.map +1 -0
- package/dist/strand-revocation-enforcer.d.ts +392 -0
- package/dist/strand-revocation-enforcer.js +533 -0
- package/dist/strand-revocation-enforcer.js.map +1 -0
- package/dist/strand-solicitation.d.ts +10 -3
- package/dist/strand-solicitation.js +12 -7
- package/dist/strand-solicitation.js.map +1 -1
- package/dist/strand-wake-protocol.d.ts +47 -2
- package/dist/strand-wake-protocol.js +76 -6
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/strand-watcher.js +6 -1
- package/dist/strand-watcher.js.map +1 -1
- package/dist/types.d.ts +282 -43
- package/dist/types.js +7 -1
- package/dist/types.js.map +1 -1
- package/package.json +16 -8
- package/src/announce-addrs.ts +93 -0
- package/src/cadre-node.ts +1366 -171
- package/src/control-database.ts +2628 -2406
- package/src/control-read-retry.ts +167 -0
- package/src/control-retry.ts +190 -0
- package/src/control-schema.ts +50 -6
- package/src/control-write-retry.ts +30 -130
- package/src/delegate-admission.ts +17 -15
- package/src/enrolled-machine-store-file.ts +43 -0
- package/src/enrolled-machine-store.ts +280 -0
- package/src/file-durable-slot.ts +5 -3
- package/src/index.ts +477 -407
- package/src/membership-connection-gater.ts +539 -204
- package/src/node-local-snapshot.ts +13 -1
- package/src/peer-addr-book.ts +251 -250
- package/src/{strand-backfill.ts → peer-join-backfill.ts} +187 -75
- package/src/peer-record.ts +33 -0
- package/src/relay-addrs.ts +436 -111
- package/src/relay-reservation.ts +828 -823
- package/src/strand-addr-protocol.ts +17 -0
- package/src/strand-database.ts +17 -0
- package/src/strand-formation-manager.ts +511 -491
- package/src/strand-formation-protocol.ts +808 -692
- package/src/strand-instance-manager.ts +899 -611
- package/src/strand-membership-writer.ts +232 -15
- package/src/strand-network-config.ts +172 -0
- package/src/strand-revocation-enforcer.ts +653 -0
- package/src/strand-solicitation.ts +484 -472
- package/src/strand-wake-protocol.ts +94 -8
- package/src/strand-watcher.ts +319 -314
- package/src/types.ts +1554 -1309
- package/dist/strand-backfill.js.map +0 -1
package/dist/relay-addrs.d.ts
CHANGED
|
@@ -1,29 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Translate `network.relayAddrs` — the operator-facing "use these relay servers"
|
|
3
|
-
* setting — into the
|
|
4
|
-
* slot
|
|
3
|
+
* setting — into the listen entry a node needs before it can hold a circuit-relay
|
|
4
|
+
* slot, and validate the operator's entries while doing it.
|
|
5
5
|
*
|
|
6
|
-
* `@libp2p/circuit-relay-v2`'s
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* that relay and hold a reservation. Everything downstream of the listen list —
|
|
10
|
-
* the reservation itself, `CadreNode.circuitRelayTargets()` picking delegate-announce
|
|
11
|
-
* targets, strand nodes inheriting the listen addrs, the `/p2p-circuit`-first address
|
|
12
|
-
* publishing in `registerSelf` — then works unchanged.
|
|
6
|
+
* `@libp2p/circuit-relay-v2`'s listener branches on the SHAPE of the listen addr,
|
|
7
|
+
* and the same `relayAddrs` list resolves to either shape depending on WHO is
|
|
8
|
+
* listening ({@link RelayListenRoute}):
|
|
13
9
|
*
|
|
14
|
-
*
|
|
10
|
+
* | route | listen entry | libp2p behaviour |
|
|
11
|
+
* | -------------- | ------------------------------------------- | --------------------------------------------------------- |
|
|
12
|
+
* | `'configured'` | `<relayAddr>/p2p-circuit`, one per relay | dial that relay from inside `listen()` and reserve, or throw |
|
|
13
|
+
* | `'search'` | a single bare `/p2p-circuit` | register a pending reservation; open no connection |
|
|
15
14
|
*
|
|
16
|
-
*
|
|
15
|
+
* The CONTROL node takes the `'search'` route, and `CadreNode.start()` drives the
|
|
16
|
+
* reservation explicitly (`relay-reservation.ts`) once the control database is up.
|
|
17
|
+
* That ordering is the point: a configured circuit listener dials the relay from
|
|
18
|
+
* inside `libp2p.start()`, so the control database was being built while a sibling
|
|
19
|
+
* relay was already in this node's cohort — and a sibling that has not yet
|
|
20
|
+
* replicated this node's `CadrePeer` row correctly refuses its control-DB streams,
|
|
21
|
+
* which killed `start()` outright. See `cadre-node.ts` → `start()`.
|
|
17
22
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* STRAND nodes keep the `'configured'` route (`strand-instance-manager.ts`): they
|
|
24
|
+
* inherit the control node's `NetworkConfig`, nothing drives an explicit
|
|
25
|
+
* reservation for them, and their relay connection cannot disturb a control-DB
|
|
26
|
+
* bring-up (a strand node's protocol ids are namespaced `/optimystic/strand-<id>/…`,
|
|
27
|
+
* so the relay is never in its cohort).
|
|
28
|
+
*
|
|
29
|
+
* `network.relayAddrs` is FAIL-FAST for the operator on both routes, just from
|
|
30
|
+
* different places: a malformed entry throws here at config resolution, and on the
|
|
31
|
+
* control node a first reservation attempt that does not land throws out of
|
|
32
|
+
* `start()` (`RelayReservationFailedError`). Naming a relay that is down still
|
|
33
|
+
* means the node does not come up.
|
|
34
|
+
*
|
|
35
|
+
* The bare `/p2p-circuit` search listener cannot open a connection on its own:
|
|
36
|
+
* libp2p fills a pending reservation from `RelayDiscovery`, which nominates a peer
|
|
37
|
+
* only once the relay-hop protocol id is in that peer's peer-store protocol list,
|
|
38
|
+
* and that list is written exclusively by IDENTIFY — which `@optimystic/db-p2p`
|
|
39
|
+
* namespaces per network, so a cadre node and a stock relay never identify each
|
|
40
|
+
* other. See `relay-reservation.ts`'s module doc and `docs/architecture.md`.
|
|
25
41
|
*/
|
|
26
42
|
import type { NetworkConfig } from './types.js';
|
|
43
|
+
import type { RelayReservationState } from './relay-reservation.js';
|
|
44
|
+
/**
|
|
45
|
+
* libp2p's relay SEARCH listener: registers one pending reservation and dials
|
|
46
|
+
* nothing. One entry covers every configured relay — the pending reservation is
|
|
47
|
+
* per-listener, not per-relay, and `relay-reservation.ts` fills it with whichever
|
|
48
|
+
* relay answers first.
|
|
49
|
+
*/
|
|
50
|
+
export declare const RELAY_SEARCH_LISTEN_ADDR = "/p2p-circuit";
|
|
51
|
+
/**
|
|
52
|
+
* Which listener shape `network.relayAddrs` resolves to for this caller — see the
|
|
53
|
+
* table in the module doc. Defaults to `'configured'` everywhere except the
|
|
54
|
+
* control node's own libp2p options.
|
|
55
|
+
*/
|
|
56
|
+
export type RelayListenRoute = 'configured' | 'search';
|
|
27
57
|
/**
|
|
28
58
|
* The circuit-listen multiaddr for each configured relay: `<relayAddr>/p2p-circuit`.
|
|
29
59
|
* An entry that already carries `/p2p-circuit` is passed through unchanged.
|
|
@@ -38,8 +68,101 @@ import type { NetworkConfig } from './types.js';
|
|
|
38
68
|
export declare function relayCircuitAddrs(relayAddrs: readonly string[]): string[];
|
|
39
69
|
/**
|
|
40
70
|
* The listen multiaddrs a node actually binds: configured `listenAddrs` plus the
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
71
|
+
* relay listen entry `route` calls for, deduplicated, order-stable (configured
|
|
72
|
+
* entries first). Returns `undefined` when neither field is set, so callers keep
|
|
73
|
+
* omitting `listenAddrs` and inherit db-p2p's default.
|
|
74
|
+
*
|
|
75
|
+
* Every `relayAddrs` entry is validated on BOTH routes — the `'search'` route
|
|
76
|
+
* discards the resolved circuit addrs, but an operator typo must fail at config
|
|
77
|
+
* resolution either way.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveListenAddrs(network: NetworkConfig | undefined, route?: RelayListenRoute): string[] | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* The transport-derived `createLibp2pNode` options a resolved listen set implies —
|
|
82
|
+
* see {@link resolveTransportOptions}.
|
|
83
|
+
*/
|
|
84
|
+
export interface ListenTransportOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Present when some listen entry names WebSocket. Its VALUE is never bound; it is
|
|
87
|
+
* the switch that makes `@optimystic/db-p2p` add `webSockets()` — see
|
|
88
|
+
* {@link WS_TRANSPORT_SWITCH_PORT}.
|
|
89
|
+
*/
|
|
90
|
+
wsPort?: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The transport-derived libp2p options `listenAddrs` implies, and the gate that stops a
|
|
94
|
+
* listen address the node has no transport for from being SILENTLY dropped.
|
|
95
|
+
*
|
|
96
|
+
* libp2p's transport manager sorts configured listen addresses by which transport claims
|
|
97
|
+
* them, discards the unclaimed ones, and raises `UnsupportedListenAddressesError` only
|
|
98
|
+
* when EVERY address was discarded. Pair a TCP address with a WebSocket one — which is
|
|
99
|
+
* exactly what the shipped configs do — and the TCP address carries the start while the
|
|
100
|
+
* missing WebSocket listener is never reported. Two halves of `NetworkConfig` that have
|
|
101
|
+
* to agree (`listenAddrs`, and the transports the node will actually have) were never
|
|
102
|
+
* checked against each other; this is that check, and it covers both node kinds because
|
|
103
|
+
* both resolve their listen set through {@link resolveListenAddrs}.
|
|
104
|
+
*
|
|
105
|
+
* The two transport classes are handled differently, on purpose:
|
|
106
|
+
*
|
|
107
|
+
* - **WebSocket is DERIVED.** It is the one non-TCP transport the shipped configs need
|
|
108
|
+
* (the React Native reference app's companion drone; `cadre start --ws-port`), and
|
|
109
|
+
* `@optimystic/db-p2p` already knows how to add it. `cadre-core` grows no dependency
|
|
110
|
+
* and decides no transport policy — it flips db-p2p's own switch
|
|
111
|
+
* ({@link WS_TRANSPORT_SWITCH_PORT}).
|
|
112
|
+
* - **Everything else is REFUSED.** Deriving `/quic-v1`, `/webrtc` or `/webtransport`
|
|
113
|
+
* would mean importing transport packages into every `cadre-core` consumer including
|
|
114
|
+
* the React Native and browser bundles (against the cross-platform rule in
|
|
115
|
+
* `AGENTS.md`) and duplicating policy `libp2p-node.ts` owns. So name the address, name
|
|
116
|
+
* the transport it needs, and refuse to start — matching how `network.relayAddrs` and
|
|
117
|
+
* `network.announceAddrs` already treat an operator typo.
|
|
118
|
+
*
|
|
119
|
+
* Returns `{}` unconditionally when `network.transports` is set: a programmatic embedder
|
|
120
|
+
* supplying transport factories owns the policy, and the factories are opaque — nothing
|
|
121
|
+
* can be inferred from them. That is what keeps the RN phone, the web app, and the
|
|
122
|
+
* integration-test harness unaffected.
|
|
123
|
+
*
|
|
124
|
+
* NOTE: pairing this with {@link resolveListenAddrs} is a CONVENTION, not a structure —
|
|
125
|
+
* a third libp2p-node build site could resolve listen addrs and forget to call this,
|
|
126
|
+
* putting the original bug back on that path. Both existing sites are covered
|
|
127
|
+
* (`cadre-node.ts` → `buildControlNodeOptions`, `strand-network-config.ts` →
|
|
128
|
+
* `strandNodeAddrs`), and they are the only two `createLibp2pNode` callers in this repo
|
|
129
|
+
* that derive their listen set from a `NetworkConfig` — the other callers
|
|
130
|
+
* (`integration-tests/src/harness/test-party.ts`, `quereus-plugin-sereus`'s `connect.ts`
|
|
131
|
+
* and `connect-browser.ts`) pass no `listenAddrs` at all, or pass their own transports
|
|
132
|
+
* with it. If a third CONFIG-derived site appears, fold the two functions into one that
|
|
133
|
+
* returns listen addrs and transport options together, so forgetting becomes impossible
|
|
134
|
+
* rather than merely unlikely.
|
|
135
|
+
*
|
|
136
|
+
* @param listenAddrs the ALREADY-resolved listen set — the output of
|
|
137
|
+
* {@link resolveListenAddrs} after any per-node rewriting — so the check reads what
|
|
138
|
+
* this node will actually bind.
|
|
139
|
+
* @throws {UnbindableListenAddressError} when a listen entry names a transport outside
|
|
140
|
+
* {tcp, ws/wss, p2p-circuit}.
|
|
141
|
+
*/
|
|
142
|
+
export declare function resolveTransportOptions(network: NetworkConfig | undefined, listenAddrs: readonly string[] | undefined): ListenTransportOptions;
|
|
143
|
+
/**
|
|
144
|
+
* Thrown at config resolution when `network.listenAddrs` names an address none of the
|
|
145
|
+
* default transports can bind. Names each offending address alongside the libp2p
|
|
146
|
+
* transport package it would need — what the operator has without this is a node that
|
|
147
|
+
* starts and silently never listens there.
|
|
148
|
+
*/
|
|
149
|
+
export declare class UnbindableListenAddressError extends Error {
|
|
150
|
+
readonly listenAddrs: readonly string[];
|
|
151
|
+
constructor(listenAddrs: readonly string[]);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Thrown out of `CadreNode.start()` when the boot-path reservation drive for
|
|
155
|
+
* `network.relayAddrs` produces no `/p2p-circuit` address on its FIRST attempt.
|
|
156
|
+
*
|
|
157
|
+
* This is what keeps `network.relayAddrs` fail-fast now that the control node
|
|
158
|
+
* takes the `'search'` route: libp2p's own `UnsupportedListenAddressesError` used
|
|
159
|
+
* to abort start from inside `listen()`, and an operator who names a relay is
|
|
160
|
+
* telling the node it has no other reachability — coming up undialable is worse
|
|
161
|
+
* than not coming up. Names the relays and the reservation's own reason, both of
|
|
162
|
+
* which the libp2p error omitted.
|
|
44
163
|
*/
|
|
45
|
-
export declare
|
|
164
|
+
export declare class RelayReservationFailedError extends Error {
|
|
165
|
+
readonly relayAddrs: readonly string[];
|
|
166
|
+
readonly state: RelayReservationState;
|
|
167
|
+
constructor(relayAddrs: readonly string[], state: RelayReservationState);
|
|
168
|
+
}
|
package/dist/relay-addrs.js
CHANGED
|
@@ -1,27 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Translate `network.relayAddrs` — the operator-facing "use these relay servers"
|
|
3
|
-
* setting — into the
|
|
4
|
-
* slot
|
|
5
|
-
*
|
|
6
|
-
* `@libp2p/circuit-relay-v2`'s
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
3
|
+
* setting — into the listen entry a node needs before it can hold a circuit-relay
|
|
4
|
+
* slot, and validate the operator's entries while doing it.
|
|
5
|
+
*
|
|
6
|
+
* `@libp2p/circuit-relay-v2`'s listener branches on the SHAPE of the listen addr,
|
|
7
|
+
* and the same `relayAddrs` list resolves to either shape depending on WHO is
|
|
8
|
+
* listening ({@link RelayListenRoute}):
|
|
9
|
+
*
|
|
10
|
+
* | route | listen entry | libp2p behaviour |
|
|
11
|
+
* | -------------- | ------------------------------------------- | --------------------------------------------------------- |
|
|
12
|
+
* | `'configured'` | `<relayAddr>/p2p-circuit`, one per relay | dial that relay from inside `listen()` and reserve, or throw |
|
|
13
|
+
* | `'search'` | a single bare `/p2p-circuit` | register a pending reservation; open no connection |
|
|
14
|
+
*
|
|
15
|
+
* The CONTROL node takes the `'search'` route, and `CadreNode.start()` drives the
|
|
16
|
+
* reservation explicitly (`relay-reservation.ts`) once the control database is up.
|
|
17
|
+
* That ordering is the point: a configured circuit listener dials the relay from
|
|
18
|
+
* inside `libp2p.start()`, so the control database was being built while a sibling
|
|
19
|
+
* relay was already in this node's cohort — and a sibling that has not yet
|
|
20
|
+
* replicated this node's `CadrePeer` row correctly refuses its control-DB streams,
|
|
21
|
+
* which killed `start()` outright. See `cadre-node.ts` → `start()`.
|
|
22
|
+
*
|
|
23
|
+
* STRAND nodes keep the `'configured'` route (`strand-instance-manager.ts`): they
|
|
24
|
+
* inherit the control node's `NetworkConfig`, nothing drives an explicit
|
|
25
|
+
* reservation for them, and their relay connection cannot disturb a control-DB
|
|
26
|
+
* bring-up (a strand node's protocol ids are namespaced `/optimystic/strand-<id>/…`,
|
|
27
|
+
* so the relay is never in its cohort).
|
|
28
|
+
*
|
|
29
|
+
* `network.relayAddrs` is FAIL-FAST for the operator on both routes, just from
|
|
30
|
+
* different places: a malformed entry throws here at config resolution, and on the
|
|
31
|
+
* control node a first reservation attempt that does not land throws out of
|
|
32
|
+
* `start()` (`RelayReservationFailedError`). Naming a relay that is down still
|
|
33
|
+
* means the node does not come up.
|
|
34
|
+
*
|
|
35
|
+
* The bare `/p2p-circuit` search listener cannot open a connection on its own:
|
|
36
|
+
* libp2p fills a pending reservation from `RelayDiscovery`, which nominates a peer
|
|
37
|
+
* only once the relay-hop protocol id is in that peer's peer-store protocol list,
|
|
38
|
+
* and that list is written exclusively by IDENTIFY — which `@optimystic/db-p2p`
|
|
39
|
+
* namespaces per network, so a cadre node and a stock relay never identify each
|
|
40
|
+
* other. See `relay-reservation.ts`'s module doc and `docs/architecture.md`.
|
|
25
41
|
*/
|
|
26
42
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
27
43
|
import { circuitRelayTargetOrThrow } from './delegate-admission.js';
|
|
@@ -36,6 +52,13 @@ import { circuitRelayTargetOrThrow } from './delegate-admission.js';
|
|
|
36
52
|
* ever changes its default, this constant has to follow.
|
|
37
53
|
*/
|
|
38
54
|
const DEFAULT_DIRECT_LISTEN_ADDR = '/ip4/0.0.0.0/tcp/0';
|
|
55
|
+
/**
|
|
56
|
+
* libp2p's relay SEARCH listener: registers one pending reservation and dials
|
|
57
|
+
* nothing. One entry covers every configured relay — the pending reservation is
|
|
58
|
+
* per-listener, not per-relay, and `relay-reservation.ts` fills it with whichever
|
|
59
|
+
* relay answers first.
|
|
60
|
+
*/
|
|
61
|
+
export const RELAY_SEARCH_LISTEN_ADDR = '/p2p-circuit';
|
|
39
62
|
/**
|
|
40
63
|
* The circuit-listen multiaddr for each configured relay: `<relayAddr>/p2p-circuit`.
|
|
41
64
|
* An entry that already carries `/p2p-circuit` is passed through unchanged.
|
|
@@ -52,20 +75,280 @@ export function relayCircuitAddrs(relayAddrs) {
|
|
|
52
75
|
}
|
|
53
76
|
/**
|
|
54
77
|
* The listen multiaddrs a node actually binds: configured `listenAddrs` plus the
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
78
|
+
* relay listen entry `route` calls for, deduplicated, order-stable (configured
|
|
79
|
+
* entries first). Returns `undefined` when neither field is set, so callers keep
|
|
80
|
+
* omitting `listenAddrs` and inherit db-p2p's default.
|
|
81
|
+
*
|
|
82
|
+
* Every `relayAddrs` entry is validated on BOTH routes — the `'search'` route
|
|
83
|
+
* discards the resolved circuit addrs, but an operator typo must fail at config
|
|
84
|
+
* resolution either way.
|
|
58
85
|
*/
|
|
59
|
-
export function resolveListenAddrs(network) {
|
|
60
|
-
const
|
|
86
|
+
export function resolveListenAddrs(network, route = 'configured') {
|
|
87
|
+
const configured = relayCircuitAddrs(network?.relayAddrs ?? []);
|
|
88
|
+
const relayEntries = route === 'search'
|
|
89
|
+
? (configured.length > 0 ? [RELAY_SEARCH_LISTEN_ADDR] : [])
|
|
90
|
+
: configured;
|
|
61
91
|
const listenAddrs = network?.listenAddrs;
|
|
62
|
-
if (
|
|
92
|
+
if (route === 'search') {
|
|
93
|
+
rejectConfiguredCircuitListenAddrs(listenAddrs ?? []);
|
|
94
|
+
}
|
|
95
|
+
if (!listenAddrs && relayEntries.length === 0) {
|
|
63
96
|
return undefined;
|
|
64
97
|
}
|
|
65
98
|
// An explicitly empty `listenAddrs` (the React Native "cannot listen" case) stays
|
|
66
|
-
// empty — but a relay named alongside it still gets its
|
|
67
|
-
// acquiring
|
|
68
|
-
return dedupe([...(listenAddrs ?? [DEFAULT_DIRECT_LISTEN_ADDR]), ...
|
|
99
|
+
// empty — but a relay named alongside it still gets its listen entry, since
|
|
100
|
+
// acquiring a slot is the whole point of configuring a relay.
|
|
101
|
+
return dedupe([...(listenAddrs ?? [DEFAULT_DIRECT_LISTEN_ADDR]), ...relayEntries]);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The `wsPort` value passed purely to turn `@optimystic/db-p2p`'s WebSocket transport
|
|
105
|
+
* ON. It is never bound, so it is deliberately `0` rather than a port scraped from a
|
|
106
|
+
* listen entry.
|
|
107
|
+
*
|
|
108
|
+
* WHY it is a switch and not a port: `createLibp2pNode`
|
|
109
|
+
* (`../optimystic/packages/db-p2p/src/libp2p-node.ts`) feeds `wsPort` into BOTH its
|
|
110
|
+
* default transports and its default listen addrs, and `createLibp2pNodeBase`
|
|
111
|
+
* (`libp2p-node-base.ts:490-491`) falls back to those two defaults INDEPENDENTLY:
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* const listenAddrs = options.listenAddrs ?? defaults.listenAddrs;
|
|
115
|
+
* const transports = options.transports ?? defaults.transports;
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* `cadre-core` always supplies explicit `listenAddrs` alongside it, so the synthesized
|
|
119
|
+
* `/ip4/<wsHost>/tcp/<wsPort>/ws` default ADDRESS is discarded while the `webSockets()`
|
|
120
|
+
* transport it added survives. A scraped port would also be a lie whenever a config
|
|
121
|
+
* names several WebSocket addresses on different ports, and the strand path rewrites
|
|
122
|
+
* fixed ports to `0` regardless (`strand-network-config.ts`).
|
|
123
|
+
*
|
|
124
|
+
* NOTE: db-p2p's own doc comment on `wsPort` (`libp2p-node-base.ts:170-172`) says it is
|
|
125
|
+
* "Ignored when `transports`/`listenAddrs` are explicitly provided" — true of the
|
|
126
|
+
* address half, NOT of the transport half, which is the half this depends on. Re-verify
|
|
127
|
+
* empirically rather than trusting that comment: `test/listen-transport-options.spec.ts`
|
|
128
|
+
* boots a real node and asserts a `/ws` multiaddr appears. If db-p2p ever makes the
|
|
129
|
+
* comment true of both halves, it needs an explicit `enableWebSockets` switch and this
|
|
130
|
+
* constant becomes unusable.
|
|
131
|
+
*/
|
|
132
|
+
const WS_TRANSPORT_SWITCH_PORT = 0;
|
|
133
|
+
/**
|
|
134
|
+
* The transport-derived libp2p options `listenAddrs` implies, and the gate that stops a
|
|
135
|
+
* listen address the node has no transport for from being SILENTLY dropped.
|
|
136
|
+
*
|
|
137
|
+
* libp2p's transport manager sorts configured listen addresses by which transport claims
|
|
138
|
+
* them, discards the unclaimed ones, and raises `UnsupportedListenAddressesError` only
|
|
139
|
+
* when EVERY address was discarded. Pair a TCP address with a WebSocket one — which is
|
|
140
|
+
* exactly what the shipped configs do — and the TCP address carries the start while the
|
|
141
|
+
* missing WebSocket listener is never reported. Two halves of `NetworkConfig` that have
|
|
142
|
+
* to agree (`listenAddrs`, and the transports the node will actually have) were never
|
|
143
|
+
* checked against each other; this is that check, and it covers both node kinds because
|
|
144
|
+
* both resolve their listen set through {@link resolveListenAddrs}.
|
|
145
|
+
*
|
|
146
|
+
* The two transport classes are handled differently, on purpose:
|
|
147
|
+
*
|
|
148
|
+
* - **WebSocket is DERIVED.** It is the one non-TCP transport the shipped configs need
|
|
149
|
+
* (the React Native reference app's companion drone; `cadre start --ws-port`), and
|
|
150
|
+
* `@optimystic/db-p2p` already knows how to add it. `cadre-core` grows no dependency
|
|
151
|
+
* and decides no transport policy — it flips db-p2p's own switch
|
|
152
|
+
* ({@link WS_TRANSPORT_SWITCH_PORT}).
|
|
153
|
+
* - **Everything else is REFUSED.** Deriving `/quic-v1`, `/webrtc` or `/webtransport`
|
|
154
|
+
* would mean importing transport packages into every `cadre-core` consumer including
|
|
155
|
+
* the React Native and browser bundles (against the cross-platform rule in
|
|
156
|
+
* `AGENTS.md`) and duplicating policy `libp2p-node.ts` owns. So name the address, name
|
|
157
|
+
* the transport it needs, and refuse to start — matching how `network.relayAddrs` and
|
|
158
|
+
* `network.announceAddrs` already treat an operator typo.
|
|
159
|
+
*
|
|
160
|
+
* Returns `{}` unconditionally when `network.transports` is set: a programmatic embedder
|
|
161
|
+
* supplying transport factories owns the policy, and the factories are opaque — nothing
|
|
162
|
+
* can be inferred from them. That is what keeps the RN phone, the web app, and the
|
|
163
|
+
* integration-test harness unaffected.
|
|
164
|
+
*
|
|
165
|
+
* NOTE: pairing this with {@link resolveListenAddrs} is a CONVENTION, not a structure —
|
|
166
|
+
* a third libp2p-node build site could resolve listen addrs and forget to call this,
|
|
167
|
+
* putting the original bug back on that path. Both existing sites are covered
|
|
168
|
+
* (`cadre-node.ts` → `buildControlNodeOptions`, `strand-network-config.ts` →
|
|
169
|
+
* `strandNodeAddrs`), and they are the only two `createLibp2pNode` callers in this repo
|
|
170
|
+
* that derive their listen set from a `NetworkConfig` — the other callers
|
|
171
|
+
* (`integration-tests/src/harness/test-party.ts`, `quereus-plugin-sereus`'s `connect.ts`
|
|
172
|
+
* and `connect-browser.ts`) pass no `listenAddrs` at all, or pass their own transports
|
|
173
|
+
* with it. If a third CONFIG-derived site appears, fold the two functions into one that
|
|
174
|
+
* returns listen addrs and transport options together, so forgetting becomes impossible
|
|
175
|
+
* rather than merely unlikely.
|
|
176
|
+
*
|
|
177
|
+
* @param listenAddrs the ALREADY-resolved listen set — the output of
|
|
178
|
+
* {@link resolveListenAddrs} after any per-node rewriting — so the check reads what
|
|
179
|
+
* this node will actually bind.
|
|
180
|
+
* @throws {UnbindableListenAddressError} when a listen entry names a transport outside
|
|
181
|
+
* {tcp, ws/wss, p2p-circuit}.
|
|
182
|
+
*/
|
|
183
|
+
export function resolveTransportOptions(network, listenAddrs) {
|
|
184
|
+
if (network?.transports) {
|
|
185
|
+
return {};
|
|
186
|
+
}
|
|
187
|
+
const kinds = (listenAddrs ?? []).map((addr) => [addr, listenTransportKind(addr)]);
|
|
188
|
+
const unsupported = kinds.filter(([, kind]) => kind === 'unsupported').map(([addr]) => addr);
|
|
189
|
+
if (unsupported.length > 0) {
|
|
190
|
+
throw new UnbindableListenAddressError(unsupported);
|
|
191
|
+
}
|
|
192
|
+
return kinds.some(([, kind]) => kind === 'websockets') ? { wsPort: WS_TRANSPORT_SWITCH_PORT } : {};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Thrown at config resolution when `network.listenAddrs` names an address none of the
|
|
196
|
+
* default transports can bind. Names each offending address alongside the libp2p
|
|
197
|
+
* transport package it would need — what the operator has without this is a node that
|
|
198
|
+
* starts and silently never listens there.
|
|
199
|
+
*/
|
|
200
|
+
export class UnbindableListenAddressError extends Error {
|
|
201
|
+
constructor(listenAddrs) {
|
|
202
|
+
super('network.listenAddrs names an address this node has no transport for: ' +
|
|
203
|
+
`${listenAddrs.map((a) => `${a} — ${unbindableReason(a)}`).join('; ')}. ` +
|
|
204
|
+
'Default transports bind TCP (including /unix/<path>), WebSocket (/ws, /wss) and circuit-relay addresses only. ' +
|
|
205
|
+
'Either drop the address, or supply the transport programmatically via network.transports.');
|
|
206
|
+
this.listenAddrs = listenAddrs;
|
|
207
|
+
this.name = 'UnbindableListenAddressError';
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Which default transport claims `listenAddr`, or `'unsupported'` when none does.
|
|
212
|
+
*
|
|
213
|
+
* Classification is a multiaddr COMPONENT question, not a string question, so this
|
|
214
|
+
* parses and reads the transport stack — the component names left once the addressing
|
|
215
|
+
* and security layers are dropped. That stack is outermost-LAST
|
|
216
|
+
* (`/ip4/…/tcp/443/tls/ws` → `['tcp', 'ws']`), which is why its terminal entry decides.
|
|
217
|
+
*
|
|
218
|
+
* An unparsable entry is `'ignored'` and passes through untouched, following
|
|
219
|
+
* `isConfiguredCircuitListenAddr` below and `ephemeralPortListenAddr`
|
|
220
|
+
* (`strand-network-config.ts`): libp2p reports a bad listen addr itself, and this check
|
|
221
|
+
* must only ever ADD a denial.
|
|
222
|
+
*/
|
|
223
|
+
function listenTransportKind(listenAddr) {
|
|
224
|
+
let stack;
|
|
225
|
+
try {
|
|
226
|
+
stack = transportStack(listenAddr);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return 'ignored';
|
|
230
|
+
}
|
|
231
|
+
const outermost = stack.at(-1);
|
|
232
|
+
if (outermost === undefined) {
|
|
233
|
+
// Nothing but addressing components — a bare `/ip4/1.2.3.4`. No transport claims
|
|
234
|
+
// it, so it is dropped by exactly the same silent path this check exists to close.
|
|
235
|
+
return 'unsupported';
|
|
236
|
+
}
|
|
237
|
+
if (outermost === 'p2p-circuit') {
|
|
238
|
+
return 'circuit';
|
|
239
|
+
}
|
|
240
|
+
if (outermost === 'ws' || outermost === 'wss') {
|
|
241
|
+
return 'websockets';
|
|
242
|
+
}
|
|
243
|
+
// Only a BARE tcp or unix stack is TCP. `@libp2p/tcp` binds both — its `listenFilter`
|
|
244
|
+
// accepts an exact TCP match OR a `/unix/<path>` address (a named pipe on Windows) —
|
|
245
|
+
// and nothing layered on top of either, which is why `/tcp/<port>/<anything else>` is
|
|
246
|
+
// NOT waved through merely because a `tcp` component happens to appear.
|
|
247
|
+
return stack.length === 1 && (outermost === 'tcp' || outermost === 'unix') ? 'tcp' : 'unsupported';
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Component names of `listenAddr` with the addressing and security layers removed, so
|
|
251
|
+
* what remains names transports. Host components (`ip4`, `dns4`, …) and the layers that
|
|
252
|
+
* ride inside a transport without being one (`tls`, `sni`, `certhash`, `p2p`) say
|
|
253
|
+
* nothing about which transport has to be configured.
|
|
254
|
+
*/
|
|
255
|
+
function transportStack(listenAddr) {
|
|
256
|
+
return multiaddr(listenAddr).getComponents()
|
|
257
|
+
.map((component) => component.name)
|
|
258
|
+
.filter((name) => !NON_TRANSPORT_COMPONENTS.has(name));
|
|
259
|
+
}
|
|
260
|
+
/** Components that address or secure a connection rather than name its transport. */
|
|
261
|
+
const NON_TRANSPORT_COMPONENTS = new Set([
|
|
262
|
+
'ip4', 'ip6', 'ip6zone', 'dns', 'dns4', 'dns6', 'dnsaddr',
|
|
263
|
+
'tls', 'sni', 'certhash', 'p2p', 'noise'
|
|
264
|
+
]);
|
|
265
|
+
/**
|
|
266
|
+
* Why `listenAddr` cannot be bound, phrased for the operator: the libp2p package that
|
|
267
|
+
* would make it bindable where one is known, and otherwise what is wrong with it.
|
|
268
|
+
*
|
|
269
|
+
* Read OUTERMOST-first (`/udp/…/quic-v1/webtransport` needs `@libp2p/webtransport`,
|
|
270
|
+
* not the `@libp2p/quic` it rides on), matching how `listenTransportKind` decides.
|
|
271
|
+
*/
|
|
272
|
+
function unbindableReason(listenAddr) {
|
|
273
|
+
let stack;
|
|
274
|
+
try {
|
|
275
|
+
stack = transportStack(listenAddr);
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
return 'not a parsable multiaddr';
|
|
279
|
+
}
|
|
280
|
+
if (stack.length === 0) {
|
|
281
|
+
return 'it names no transport component';
|
|
282
|
+
}
|
|
283
|
+
const pkg = [...stack].reverse().map((name) => TRANSPORT_PACKAGES[name]).find((p) => p !== undefined);
|
|
284
|
+
return pkg === undefined ? 'needs an unrecognized transport' : `needs ${pkg}`;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The libp2p package each unbindable transport component comes from. Naming the package
|
|
288
|
+
* is the actionable half of the refusal — the operator either drops the address or wires
|
|
289
|
+
* that package in through `network.transports`.
|
|
290
|
+
*/
|
|
291
|
+
const TRANSPORT_PACKAGES = {
|
|
292
|
+
'quic': '@libp2p/quic',
|
|
293
|
+
'quic-v1': '@libp2p/quic',
|
|
294
|
+
'webtransport': '@libp2p/webtransport',
|
|
295
|
+
'webrtc': '@libp2p/webrtc',
|
|
296
|
+
'webrtc-direct': '@libp2p/webrtc'
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Thrown out of `CadreNode.start()` when the boot-path reservation drive for
|
|
300
|
+
* `network.relayAddrs` produces no `/p2p-circuit` address on its FIRST attempt.
|
|
301
|
+
*
|
|
302
|
+
* This is what keeps `network.relayAddrs` fail-fast now that the control node
|
|
303
|
+
* takes the `'search'` route: libp2p's own `UnsupportedListenAddressesError` used
|
|
304
|
+
* to abort start from inside `listen()`, and an operator who names a relay is
|
|
305
|
+
* telling the node it has no other reachability — coming up undialable is worse
|
|
306
|
+
* than not coming up. Names the relays and the reservation's own reason, both of
|
|
307
|
+
* which the libp2p error omitted.
|
|
308
|
+
*/
|
|
309
|
+
export class RelayReservationFailedError extends Error {
|
|
310
|
+
constructor(relayAddrs, state) {
|
|
311
|
+
super(`network.relayAddrs reservation failed (status: ${state.status}): ` +
|
|
312
|
+
`${state.error ?? 'no /p2p-circuit address appeared'} — relays: ${relayAddrs.join(', ')}`);
|
|
313
|
+
this.relayAddrs = relayAddrs;
|
|
314
|
+
this.state = state;
|
|
315
|
+
this.name = 'RelayReservationFailedError';
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* A hand-written `<relay>/p2p-circuit` entry in `network.listenAddrs` is the
|
|
320
|
+
* CONFIGURED listener shape, and it is unusable on the `'search'` route: libp2p
|
|
321
|
+
* dials that relay from inside `listen()`, the bring-up quiet period
|
|
322
|
+
* (`membership-connection-gater.ts`) denies exactly that dial, `listen()` fails, and
|
|
323
|
+
* the transport manager's default `FATAL_ALL` aborts `libp2p.start()`. The operator
|
|
324
|
+
* would see `UnsupportedListenAddressesError` from deep inside bring-up with nothing
|
|
325
|
+
* naming the cause, so name it here instead.
|
|
326
|
+
*
|
|
327
|
+
* `network.relayAddrs` is the exact replacement — same relay, and the reservation is
|
|
328
|
+
* driven after bring-up, which is the whole point of the route.
|
|
329
|
+
*/
|
|
330
|
+
function rejectConfiguredCircuitListenAddrs(listenAddrs) {
|
|
331
|
+
const configured = listenAddrs.filter(isConfiguredCircuitListenAddr);
|
|
332
|
+
if (configured.length > 0) {
|
|
333
|
+
throw new Error('network.listenAddrs names a relay directly ' +
|
|
334
|
+
`(${configured.join(', ')}), which a control node cannot listen on: libp2p would ` +
|
|
335
|
+
'dial that relay during control-database bring-up, when the node accepts no ' +
|
|
336
|
+
'connections. Move the relay to network.relayAddrs, which reserves after bring-up.');
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** `<something>/p2p-circuit` — the configured shape, as opposed to the bare search addr. */
|
|
340
|
+
function isConfiguredCircuitListenAddr(listenAddr) {
|
|
341
|
+
if (listenAddr === RELAY_SEARCH_LISTEN_ADDR) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
return multiaddr(listenAddr).getComponents().some((c) => c.name === 'p2p-circuit');
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
// Not our error to raise: libp2p reports an unparsable listen addr itself, and
|
|
349
|
+
// this helper only ever ADDS a denial.
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
69
352
|
}
|
|
70
353
|
/**
|
|
71
354
|
* One entry of {@link relayCircuitAddrs}: the addr the node listens on for this relay.
|
package/dist/relay-addrs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay-addrs.js","sourceRoot":"","sources":["../src/relay-addrs.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"relay-addrs.js","sourceRoot":"","sources":["../src/relay-addrs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,SAAS,EAAkB,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAIpE;;;;;;;;;GASG;AACH,MAAM,0BAA0B,GAAG,oBAAoB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,C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AAO,SAAS,CAAC,SAAS,CAAC,CAAC,aAAa,EAAE,CAAC;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sDAAsD,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACrG,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,SAAS,MAAM,CAAC,KAAwB;IACtC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -4,28 +4,32 @@
|
|
|
4
4
|
* (live) status derivation.
|
|
5
5
|
*
|
|
6
6
|
* `@libp2p/circuit-relay-v2`'s listener branches on the SHAPE of the listen
|
|
7
|
-
* address
|
|
7
|
+
* address:
|
|
8
8
|
*
|
|
9
9
|
* | listen addr | libp2p behaviour | unreachable relay |
|
|
10
10
|
* | ------------------------------------------------- | ------------------------------------------------------------------------------------ | -------------------------- |
|
|
11
11
|
* | `<dial addr>/p2p/<relayPeerId>/p2p-circuit` | CONFIGURED reservation: dial that exact relay and reserve, or fail | `listen()` throws |
|
|
12
12
|
* | bare `/p2p-circuit` | SEARCH mode: register a pending reservation, to be filled by relay discovery | nothing throws, no reserve |
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* listen under the default `FATAL_ALL` fault tolerance, so naming a relay that is
|
|
18
|
-
* down means the node does not start. Good for a server; wrong for a browser tab,
|
|
19
|
-
* which must still boot (solo, undialable) when its relay is down.
|
|
14
|
+
* A search listener needs someone to (a) dial the relay and (b) fill the pending
|
|
15
|
+
* reservation it created, then report whether one actually landed. That is this
|
|
16
|
+
* module. It is **fail-soft by construction**: nothing here throws.
|
|
20
17
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
18
|
+
* EVERY cadre CONTROL node now takes that route — `network.relayAddrs` resolves
|
|
19
|
+
* to the bare search entry (`relay-addrs.ts` → `RelayListenRoute`) and
|
|
20
|
+
* `CadreNode.start()` drives this module once the control database is up. The
|
|
21
|
+
* configured shape would dial the relay from inside `libp2p.start()`, putting a
|
|
22
|
+
* sibling in this node's cohort before its own control database existed, and a
|
|
23
|
+
* sibling that has not yet replicated this node's `CadrePeer` row correctly
|
|
24
|
+
* refuses its control-DB streams — which killed `start()` outright.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* So the two shapes are no longer alternative ROUTES, only alternative failure
|
|
27
|
+
* postures on top of the same drive: a node that names `network.relayAddrs` gets
|
|
28
|
+
* a `RelayReservationFailedError` out of `start()` when the first attempt lands
|
|
29
|
+
* nothing (fail-fast, the operator asked for this relay), while a node that calls
|
|
30
|
+
* `CadreNode.reserveRelays()` itself gets a non-`reserved` status and stays up
|
|
31
|
+
* (fail-soft, the browser-tab posture). Configuring both is now redundant, not
|
|
32
|
+
* fatal. STRAND nodes still take the configured shape — see `relay-addrs.ts`.
|
|
29
33
|
*
|
|
30
34
|
* ⚠️ WHY THE RESERVATION IS REQUESTED EXPLICITLY RATHER THAN LEFT TO DISCOVERY.
|
|
31
35
|
* libp2p fills a search listener's pending reservation from `RelayDiscovery`,
|
|
@@ -60,7 +64,8 @@
|
|
|
60
64
|
import type { Libp2p, PeerId } from '@libp2p/interface';
|
|
61
65
|
/**
|
|
62
66
|
* Relay-reservation posture for a node that reserves through the SEARCH listen
|
|
63
|
-
* addr (bare `/p2p-circuit`)
|
|
67
|
+
* addr (bare `/p2p-circuit`) — every cadre control node, whether its relays came
|
|
68
|
+
* from `network.relayAddrs` or from an explicit `CadreNode.reserveRelays()` call.
|
|
64
69
|
* - `none` — no relay addrs supplied; the node is undialable by design.
|
|
65
70
|
* - `dialing` — a drive is in flight.
|
|
66
71
|
* - `reserved` — the node currently holds at least one `/p2p-circuit` addr.
|