@serfab/cadre-core 0.11.0 → 0.12.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/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 +281 -30
- package/dist/cadre-node.js +513 -103
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-database.d.ts +155 -23
- package/dist/control-database.js +272 -104
- 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 +20 -4
- 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/index.d.ts +6 -4
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +211 -25
- package/dist/membership-connection-gater.js +309 -29
- package/dist/membership-connection-gater.js.map +1 -1
- 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 +76 -26
- package/dist/relay-addrs.js +115 -27
- 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-backfill.js +13 -4
- package/dist/strand-backfill.js.map +1 -1
- package/dist/strand-formation-manager.d.ts +10 -9
- package/dist/strand-formation-manager.js +10 -9
- package/dist/strand-formation-manager.js.map +1 -1
- package/dist/strand-formation-protocol.d.ts +7 -7
- package/dist/strand-formation-protocol.js +8 -8
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +4 -3
- package/dist/strand-instance-manager.js +31 -6
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +106 -14
- package/dist/strand-membership-writer.js +180 -14
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-solicitation.d.ts +3 -3
- package/dist/strand-solicitation.js +4 -5
- 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/types.d.ts +74 -29
- package/dist/types.js.map +1 -1
- package/package.json +8 -8
- package/src/announce-addrs.ts +93 -0
- package/src/cadre-node.ts +5603 -5158
- package/src/control-database.ts +2584 -2406
- package/src/control-read-retry.ts +167 -0
- package/src/control-retry.ts +190 -0
- package/src/control-schema.ts +20 -4
- package/src/control-write-retry.ts +30 -130
- package/src/delegate-admission.ts +17 -15
- package/src/index.ts +435 -407
- package/src/membership-connection-gater.ts +533 -204
- package/src/peer-record.ts +33 -0
- package/src/relay-addrs.ts +218 -111
- package/src/relay-reservation.ts +828 -823
- package/src/strand-addr-protocol.ts +17 -0
- package/src/strand-backfill.ts +389 -366
- package/src/strand-formation-manager.ts +492 -491
- package/src/strand-formation-protocol.ts +8 -8
- package/src/strand-instance-manager.ts +636 -611
- package/src/strand-membership-writer.ts +209 -14
- package/src/strand-solicitation.ts +6 -7
- package/src/strand-wake-protocol.ts +94 -8
- package/src/types.ts +74 -29
package/src/peer-record.ts
CHANGED
|
@@ -135,6 +135,39 @@ export function trailingPeerId(addr: Multiaddr): string | null {
|
|
|
135
135
|
return p2p.length > 0 ? (p2p[p2p.length - 1].value ?? null) : null;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* `addr` guaranteed to terminate in `/p2p/<peerId>` — the shape every dial path
|
|
140
|
+
* needs — or `null` when it cannot, because the address already terminates in a
|
|
141
|
+
* DIFFERENT peer id and therefore does not reach `peerId` at all.
|
|
142
|
+
*
|
|
143
|
+
* Three input shapes, matching what a `CadrePeer` record can legitimately carry:
|
|
144
|
+
*
|
|
145
|
+
* - no `/p2p/` component (`/ip4/1.2.3.4/tcp/4001`) — the suffix is appended;
|
|
146
|
+
* - a relay hop with the destination missing (`…/p2p/<relay>/p2p-circuit`) — the
|
|
147
|
+
* last component is the circuit, not a peer id, so the suffix is appended and
|
|
148
|
+
* the address becomes the full `…/p2p/<relay>/p2p-circuit/p2p/<peerId>`;
|
|
149
|
+
* - already terminating in `/p2p/<X>` — returned untouched when `X` is `peerId`,
|
|
150
|
+
* dropped otherwise.
|
|
151
|
+
*
|
|
152
|
+
* This is deliberately the same rule libp2p applies internally in
|
|
153
|
+
* `calculateMultiaddrs` (append when the LAST component is not `p2p`) followed by
|
|
154
|
+
* its wrong-peer-id filter, so a normalized list matches what libp2p would have
|
|
155
|
+
* built anyway. Normalizing before the dial is what keeps a list from mixing
|
|
156
|
+
* suffixed and unsuffixed entries, which `getPeerAddress` rejects outright
|
|
157
|
+
* ("Multiaddrs must all have the same peer id or have no peer id") — taking the
|
|
158
|
+
* whole peer down with it, not just the odd address.
|
|
159
|
+
*
|
|
160
|
+
* Never use before signature verification: verification runs against the
|
|
161
|
+
* original on-record strings.
|
|
162
|
+
*/
|
|
163
|
+
export function withTrailingPeerId(addr: Multiaddr, peerId: string): Multiaddr | null {
|
|
164
|
+
const components = addr.getComponents();
|
|
165
|
+
if (components[components.length - 1]?.name !== 'p2p') {
|
|
166
|
+
return addr.encapsulate(`/p2p/${peerId}`);
|
|
167
|
+
}
|
|
168
|
+
return trailingPeerId(addr) === peerId ? addr : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
138
171
|
/**
|
|
139
172
|
* Return `addrs` with signaling (`/p2p-circuit`) addrs first, otherwise stable.
|
|
140
173
|
* Used to present the WebRTC dial input ahead of direct addrs. Does NOT mutate
|
package/src/relay-addrs.ts
CHANGED
|
@@ -1,111 +1,218 @@
|
|
|
1
|
-
/**
|
|
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
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* and
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Translate `network.relayAddrs` — the operator-facing "use these relay servers"
|
|
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`.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
import { multiaddr, type Component } from '@multiformats/multiaddr';
|
|
44
|
+
import { circuitRelayTargetOrThrow } from './delegate-admission.js';
|
|
45
|
+
import type { NetworkConfig } from './types.js';
|
|
46
|
+
import type { RelayReservationState } from './relay-reservation.js';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The direct listener a node keeps when it configures `relayAddrs` but no
|
|
50
|
+
* `listenAddrs`. Without this, naming a relay would silently REPLACE the node's
|
|
51
|
+
* direct TCP listener with a circuit-only one.
|
|
52
|
+
*
|
|
53
|
+
* NOTE: mirrors `createLibp2pNode`'s own default listen addr in
|
|
54
|
+
* `../optimystic/packages/db-p2p/src/libp2p-node.ts` (`/ip4/0.0.0.0/tcp/<port>`,
|
|
55
|
+
* and `CadreNode` passes `port: 0`) — that file is the source of truth. If it
|
|
56
|
+
* ever changes its default, this constant has to follow.
|
|
57
|
+
*/
|
|
58
|
+
const DEFAULT_DIRECT_LISTEN_ADDR = '/ip4/0.0.0.0/tcp/0';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* libp2p's relay SEARCH listener: registers one pending reservation and dials
|
|
62
|
+
* nothing. One entry covers every configured relay — the pending reservation is
|
|
63
|
+
* per-listener, not per-relay, and `relay-reservation.ts` fills it with whichever
|
|
64
|
+
* relay answers first.
|
|
65
|
+
*/
|
|
66
|
+
export const RELAY_SEARCH_LISTEN_ADDR = '/p2p-circuit';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Which listener shape `network.relayAddrs` resolves to for this caller — see the
|
|
70
|
+
* table in the module doc. Defaults to `'configured'` everywhere except the
|
|
71
|
+
* control node's own libp2p options.
|
|
72
|
+
*/
|
|
73
|
+
export type RelayListenRoute = 'configured' | 'search';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The circuit-listen multiaddr for each configured relay: `<relayAddr>/p2p-circuit`.
|
|
77
|
+
* An entry that already carries `/p2p-circuit` is passed through unchanged.
|
|
78
|
+
* Throws on an entry that is unparsable or names no relay peerId — this is
|
|
79
|
+
* operator configuration, so a typo must fail loudly at start rather than
|
|
80
|
+
* silently costing the node its reachability.
|
|
81
|
+
*
|
|
82
|
+
* Deliberately unlike `extractCircuitRelayTargets` (`delegate-admission.ts`), which
|
|
83
|
+
* SKIPS a bad entry: that one reads addresses discovered at runtime from peers, where
|
|
84
|
+
* one bad entry must not be fatal.
|
|
85
|
+
*/
|
|
86
|
+
export function relayCircuitAddrs(relayAddrs: readonly string[]): string[] {
|
|
87
|
+
return dedupe(relayAddrs.map(circuitListenAddr));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The listen multiaddrs a node actually binds: configured `listenAddrs` plus the
|
|
92
|
+
* relay listen entry `route` calls for, deduplicated, order-stable (configured
|
|
93
|
+
* entries first). Returns `undefined` when neither field is set, so callers keep
|
|
94
|
+
* omitting `listenAddrs` and inherit db-p2p's default.
|
|
95
|
+
*
|
|
96
|
+
* Every `relayAddrs` entry is validated on BOTH routes — the `'search'` route
|
|
97
|
+
* discards the resolved circuit addrs, but an operator typo must fail at config
|
|
98
|
+
* resolution either way.
|
|
99
|
+
*/
|
|
100
|
+
export function resolveListenAddrs(
|
|
101
|
+
network: NetworkConfig | undefined,
|
|
102
|
+
route: RelayListenRoute = 'configured'
|
|
103
|
+
): string[] | undefined {
|
|
104
|
+
const configured = relayCircuitAddrs(network?.relayAddrs ?? []);
|
|
105
|
+
const relayEntries = route === 'search'
|
|
106
|
+
? (configured.length > 0 ? [RELAY_SEARCH_LISTEN_ADDR] : [])
|
|
107
|
+
: configured;
|
|
108
|
+
const listenAddrs = network?.listenAddrs;
|
|
109
|
+
if (route === 'search') {
|
|
110
|
+
rejectConfiguredCircuitListenAddrs(listenAddrs ?? []);
|
|
111
|
+
}
|
|
112
|
+
if (!listenAddrs && relayEntries.length === 0) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
// An explicitly empty `listenAddrs` (the React Native "cannot listen" case) stays
|
|
116
|
+
// empty — but a relay named alongside it still gets its listen entry, since
|
|
117
|
+
// acquiring a slot is the whole point of configuring a relay.
|
|
118
|
+
return dedupe([...(listenAddrs ?? [DEFAULT_DIRECT_LISTEN_ADDR]), ...relayEntries]);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Thrown out of `CadreNode.start()` when the boot-path reservation drive for
|
|
123
|
+
* `network.relayAddrs` produces no `/p2p-circuit` address on its FIRST attempt.
|
|
124
|
+
*
|
|
125
|
+
* This is what keeps `network.relayAddrs` fail-fast now that the control node
|
|
126
|
+
* takes the `'search'` route: libp2p's own `UnsupportedListenAddressesError` used
|
|
127
|
+
* to abort start from inside `listen()`, and an operator who names a relay is
|
|
128
|
+
* telling the node it has no other reachability — coming up undialable is worse
|
|
129
|
+
* than not coming up. Names the relays and the reservation's own reason, both of
|
|
130
|
+
* which the libp2p error omitted.
|
|
131
|
+
*/
|
|
132
|
+
export class RelayReservationFailedError extends Error {
|
|
133
|
+
constructor(
|
|
134
|
+
readonly relayAddrs: readonly string[],
|
|
135
|
+
readonly state: RelayReservationState
|
|
136
|
+
) {
|
|
137
|
+
super(
|
|
138
|
+
`network.relayAddrs reservation failed (status: ${state.status}): ` +
|
|
139
|
+
`${state.error ?? 'no /p2p-circuit address appeared'} — relays: ${relayAddrs.join(', ')}`
|
|
140
|
+
);
|
|
141
|
+
this.name = 'RelayReservationFailedError';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A hand-written `<relay>/p2p-circuit` entry in `network.listenAddrs` is the
|
|
147
|
+
* CONFIGURED listener shape, and it is unusable on the `'search'` route: libp2p
|
|
148
|
+
* dials that relay from inside `listen()`, the bring-up quiet period
|
|
149
|
+
* (`membership-connection-gater.ts`) denies exactly that dial, `listen()` fails, and
|
|
150
|
+
* the transport manager's default `FATAL_ALL` aborts `libp2p.start()`. The operator
|
|
151
|
+
* would see `UnsupportedListenAddressesError` from deep inside bring-up with nothing
|
|
152
|
+
* naming the cause, so name it here instead.
|
|
153
|
+
*
|
|
154
|
+
* `network.relayAddrs` is the exact replacement — same relay, and the reservation is
|
|
155
|
+
* driven after bring-up, which is the whole point of the route.
|
|
156
|
+
*/
|
|
157
|
+
function rejectConfiguredCircuitListenAddrs(listenAddrs: readonly string[]): void {
|
|
158
|
+
const configured = listenAddrs.filter(isConfiguredCircuitListenAddr);
|
|
159
|
+
if (configured.length > 0) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
'network.listenAddrs names a relay directly ' +
|
|
162
|
+
`(${configured.join(', ')}), which a control node cannot listen on: libp2p would ` +
|
|
163
|
+
'dial that relay during control-database bring-up, when the node accepts no ' +
|
|
164
|
+
'connections. Move the relay to network.relayAddrs, which reserves after bring-up.'
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** `<something>/p2p-circuit` — the configured shape, as opposed to the bare search addr. */
|
|
170
|
+
function isConfiguredCircuitListenAddr(listenAddr: string): boolean {
|
|
171
|
+
if (listenAddr === RELAY_SEARCH_LISTEN_ADDR) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
return multiaddr(listenAddr).getComponents().some((c) => c.name === 'p2p-circuit');
|
|
176
|
+
} catch {
|
|
177
|
+
// Not our error to raise: libp2p reports an unparsable listen addr itself, and
|
|
178
|
+
// this helper only ever ADDS a denial.
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* One entry of {@link relayCircuitAddrs}: the addr the node listens on for this relay.
|
|
185
|
+
*
|
|
186
|
+
* NOTE: an entry carrying components AFTER `/p2p-circuit` — a full relayed DIAL addr,
|
|
187
|
+
* `…/p2p/<relay>/p2p-circuit/p2p/<someone else>` — is passed through as written and
|
|
188
|
+
* would be listened on verbatim. It validates (the relay it names is real), so only an
|
|
189
|
+
* operator who pastes a peer's relayed address into `relayAddrs` hits it; if that turns
|
|
190
|
+
* out to be a common paste, truncate at the `/p2p-circuit` component here.
|
|
191
|
+
*/
|
|
192
|
+
function circuitListenAddr(relayAddr: string): string {
|
|
193
|
+
const alreadyCircuit = parseComponents(relayAddr).some((c) => c.name === 'p2p-circuit');
|
|
194
|
+
const listenAddr = alreadyCircuit ? relayAddr : `${relayAddr}/p2p-circuit`;
|
|
195
|
+
try {
|
|
196
|
+
circuitRelayTargetOrThrow(listenAddr); // validates the relay peerId
|
|
197
|
+
} catch (err) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
`network.relayAddrs entry names no relay peerId (expected <dial addr>/p2p/<relayPeerId>): ${relayAddr}`,
|
|
200
|
+
{ cause: err }
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
return listenAddr;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Multiaddr components of `relayAddr`, with the config field named on a parse failure. */
|
|
207
|
+
function parseComponents(relayAddr: string): Component[] {
|
|
208
|
+
try {
|
|
209
|
+
return multiaddr(relayAddr).getComponents();
|
|
210
|
+
} catch (err) {
|
|
211
|
+
throw new Error(`network.relayAddrs entry is not a valid multiaddr: ${relayAddr}`, { cause: err });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Exact-string dedupe, first occurrence wins, so the list is stable across restarts. */
|
|
216
|
+
function dedupe(addrs: readonly string[]): string[] {
|
|
217
|
+
return [...new Set(addrs)];
|
|
218
|
+
}
|