@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
|
@@ -85,7 +85,10 @@
|
|
|
85
85
|
* infra outright, and admits peers it cannot place only within a bounded
|
|
86
86
|
* budget ({@link UnauthorizedReservationBudget}) — a member whose row is in
|
|
87
87
|
* flight always finds a slot under any sane cap, while outsiders cannot
|
|
88
|
-
* annex the party's relay capacity.
|
|
88
|
+
* annex the party's relay capacity. COUNT and lifetime are the only bounds
|
|
89
|
+
* on such a peer: a party-run relay forwards without libp2p's per-connection
|
|
90
|
+
* data and duration limit by default (`relay-server.ts`), so what a granted
|
|
91
|
+
* slot carries is not capped.
|
|
89
92
|
* - An `'admit-for-relay'` connection that is NOT reserving is dropped: it has
|
|
90
93
|
* {@link RELAY_ADMISSION_RESERVE_DEADLINE_MS} to get a reservation ADMITTED
|
|
91
94
|
* at that hook, after which the gate CLOSES the underlying connection so
|
|
@@ -170,21 +173,6 @@ export declare const STRANGER_OPEN_PROTOCOLS: readonly string[];
|
|
|
170
173
|
* caller re-opens the window via `CadreNode.openEnrollmentWindow`).
|
|
171
174
|
*/
|
|
172
175
|
export declare const DEFAULT_ENROLLMENT_WINDOW_MS: number;
|
|
173
|
-
/**
|
|
174
|
-
* Deadline for one admission decision, after which the fail-open outcome is
|
|
175
|
-
* used (connection admitted / reservation admitted).
|
|
176
|
-
*
|
|
177
|
-
* libp2p awaits `denyInboundEncryptedConnection` inside the inbound upgrade
|
|
178
|
-
* WITHOUT racing its inbound-upgrade timeout signal (unlike the pre-encryption
|
|
179
|
-
* `denyInboundConnection` hook), so a decision that never settles wedges that
|
|
180
|
-
* upgrade forever — the connection-manager's inbound-upgrade slot is taken by
|
|
181
|
-
* `acceptIncomingConnection` and released in the `finally` that never runs. The
|
|
182
|
-
* real policy reads the control DB (`listAuthorizedMembers`), which can pull
|
|
183
|
-
* over the network, so "never settles" is reachable. Bounding it here keeps the
|
|
184
|
-
* fail-open contract honest: a slow decision admits rather than silently
|
|
185
|
-
* failing closed (or not at all).
|
|
186
|
-
*/
|
|
187
|
-
export declare const ADMISSION_DECISION_TIMEOUT_MS = 2000;
|
|
188
176
|
/**
|
|
189
177
|
* How long an `'admit-for-relay'` connection may exist without a relay
|
|
190
178
|
* reservation being ADMITTED at the `denyInboundRelayReservation` hook, after
|
|
@@ -193,8 +181,13 @@ export declare const ADMISSION_DECISION_TIMEOUT_MS = 2000;
|
|
|
193
181
|
* dials and requests in one drive; a strand node's configured circuit listener
|
|
194
182
|
* does the same from inside its own `listen()`), so a connection idle past this
|
|
195
183
|
* deadline is not reserving.
|
|
184
|
+
*
|
|
185
|
+
* Derived from the link ({@link relayAdmissionReserveDeadlineMs}): one link round trip for the
|
|
186
|
+
* request to arrive plus one admission decision on it. This is the value at the default
|
|
187
|
+
* declaration; `CadreNode` passes the one derived from the relay's OWN declaration, because the
|
|
188
|
+
* relay is the machine that decides.
|
|
196
189
|
*/
|
|
197
|
-
export declare const RELAY_ADMISSION_RESERVE_DEADLINE_MS
|
|
190
|
+
export declare const RELAY_ADMISSION_RESERVE_DEADLINE_MS: number;
|
|
198
191
|
/**
|
|
199
192
|
* Bound on the graceful close of an expired relay-only connection. It exists
|
|
200
193
|
* because `AbstractMultiaddrConnection.close()` awaits an `idle`/`drain` event
|
|
@@ -215,29 +208,16 @@ export declare const RELAY_ADMISSION_CLOSE_TIMEOUT_MS = 2000;
|
|
|
215
208
|
* `network.unauthorizedRelayReservationCap` (0 refuses every unauthorized
|
|
216
209
|
* reservation — the strict pre-seam posture).
|
|
217
210
|
*
|
|
218
|
-
* NOTE: this cap shares the relay server's own reservation store, whose
|
|
219
|
-
* size is
|
|
220
|
-
* unplaced peers may therefore occupy up to this many of
|
|
221
|
-
* rest are what members and delegates compete for.
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
211
|
+
* NOTE: this cap shares the relay server's own reservation store, whose
|
|
212
|
+
* party-run default size is `PARTY_RELAY_MAX_RESERVATIONS` (128,
|
|
213
|
+
* `relay-server.ts`); unplaced peers may therefore occupy up to this many of
|
|
214
|
+
* those slots, and the rest are what members and delegates compete for. The two
|
|
215
|
+
* are kept apart by hand — if this is raised, or an embedder shrinks the store
|
|
216
|
+
* through `network.relayServerInit.reservations.maxReservations`, keep this one
|
|
217
|
+
* well under the store's, or a fleet of unplaceable peers can crowd genuine
|
|
218
|
+
* members out of the server's own store (which the gate cannot override).
|
|
225
219
|
*/
|
|
226
220
|
export declare const MAX_UNAUTHORIZED_RELAY_RESERVATIONS = 8;
|
|
227
|
-
/**
|
|
228
|
-
* How long one {@link UnauthorizedReservationBudget} entry occupies a slot
|
|
229
|
-
* without a refresh. Mirrors the relay server's own default reservation TTL
|
|
230
|
-
* (`@libp2p/circuit-relay-v2`'s `DEFAULT_MAX_RESERVATION_TTL`, 2 h): the server
|
|
231
|
-
* holds an unrefreshed reservation exactly that long, and a live reserver
|
|
232
|
-
* re-requests (re-hitting the admission hook, refreshing its entry) well before
|
|
233
|
-
* expiry — so the live entry count tracks the server's own occupancy without
|
|
234
|
-
* this module reaching into the server's reservation store.
|
|
235
|
-
*
|
|
236
|
-
* NOTE: a mirror, not a live coupling — if the relay server is ever configured
|
|
237
|
-
* with a non-default `reservationTtl` (db-p2p's `relayServerInit`), update this
|
|
238
|
-
* constant alongside it or the budget's occupancy drifts from the server's.
|
|
239
|
-
*/
|
|
240
|
-
export declare const UNAUTHORIZED_RESERVATION_TTL_MS: number;
|
|
241
221
|
/**
|
|
242
222
|
* The connection-level outcome of the admission policy:
|
|
243
223
|
* - `'admit'` — a peer with a legitimate claim on the connection (member,
|
|
@@ -278,19 +258,26 @@ export interface InboundAdmissionPolicy {
|
|
|
278
258
|
* Bounded budget of concurrent relay reservations for peers the membership
|
|
279
259
|
* check could not place. `tryAdmit` is the whole surface: an already-admitted
|
|
280
260
|
* peer refreshes its entry (a reservation refresh never double-counts), a new
|
|
281
|
-
* peer takes a free slot or is refused. Entries expire after `ttlMs
|
|
282
|
-
*
|
|
283
|
-
* server
|
|
261
|
+
* peer takes a free slot or is refused. Entries expire after `ttlMs`, which
|
|
262
|
+
* `CadreNode` passes as the relay server's own resolved `reservationTtl`
|
|
263
|
+
* (`relay-server.ts`): the server holds an unrefreshed reservation exactly that
|
|
264
|
+
* long, and a live reserver re-requests (re-hitting the admission hook,
|
|
265
|
+
* refreshing its entry) well before expiry — so the live entry count tracks the
|
|
266
|
+
* server's own occupancy without this module reaching into the server's
|
|
267
|
+
* reservation store. Injectable `now` keeps expiry testable without fake
|
|
284
268
|
* timers. Authorized members and delegates are never run through this — the
|
|
285
269
|
* policy admits them before consulting the budget, and `release`s the slot such
|
|
286
270
|
* a peer took while it was still unplaceable, so the boot-ordering window a
|
|
287
271
|
* member passes through costs the budget nothing once its row lands.
|
|
288
272
|
*/
|
|
289
273
|
export declare class UnauthorizedReservationBudget {
|
|
290
|
-
|
|
274
|
+
/** Most peers admitted at once — `network.unauthorizedRelayReservationCap`, resolved. */
|
|
275
|
+
readonly cap: number;
|
|
291
276
|
private readonly ttlMs;
|
|
292
277
|
private readonly admitted;
|
|
293
|
-
constructor(
|
|
278
|
+
constructor(
|
|
279
|
+
/** Most peers admitted at once — `network.unauthorizedRelayReservationCap`, resolved. */
|
|
280
|
+
cap?: number, ttlMs?: number);
|
|
294
281
|
/** Number of live (unexpired at last prune) entries — test/diagnostic surface. */
|
|
295
282
|
get size(): number;
|
|
296
283
|
/** Admit (or refresh) `remotePeerId` if a slot is free; false when the cap is spent. */
|
|
@@ -85,7 +85,10 @@
|
|
|
85
85
|
* infra outright, and admits peers it cannot place only within a bounded
|
|
86
86
|
* budget ({@link UnauthorizedReservationBudget}) — a member whose row is in
|
|
87
87
|
* flight always finds a slot under any sane cap, while outsiders cannot
|
|
88
|
-
* annex the party's relay capacity.
|
|
88
|
+
* annex the party's relay capacity. COUNT and lifetime are the only bounds
|
|
89
|
+
* on such a peer: a party-run relay forwards without libp2p's per-connection
|
|
90
|
+
* data and duration limit by default (`relay-server.ts`), so what a granted
|
|
91
|
+
* slot carries is not capped.
|
|
89
92
|
* - An `'admit-for-relay'` connection that is NOT reserving is dropped: it has
|
|
90
93
|
* {@link RELAY_ADMISSION_RESERVE_DEADLINE_MS} to get a reservation ADMITTED
|
|
91
94
|
* at that hook, after which the gate CLOSES the underlying connection so
|
|
@@ -158,6 +161,8 @@ import debug from 'debug';
|
|
|
158
161
|
import { SEED_PROTOCOL } from './seed-bootstrap.js';
|
|
159
162
|
import { FORMATION_PROTOCOL } from './strand-formation-protocol.js';
|
|
160
163
|
import { withDeadline } from './control-stream.js';
|
|
164
|
+
import { PARTY_RELAY_RESERVATION_TTL_MS } from './relay-server.js';
|
|
165
|
+
import { ADMISSION_DECISION_TIMEOUT_MS, relayAdmissionReserveDeadlineMs } from './link-budget.js';
|
|
161
166
|
const log = debug('sereus:cadre:connection-gater');
|
|
162
167
|
/**
|
|
163
168
|
* The protocols a not-yet-authorized peer may legitimately speak on a control
|
|
@@ -174,21 +179,6 @@ export const STRANGER_OPEN_PROTOCOLS = [SEED_PROTOCOL, FORMATION_PROTOCOL];
|
|
|
174
179
|
* caller re-opens the window via `CadreNode.openEnrollmentWindow`).
|
|
175
180
|
*/
|
|
176
181
|
export const DEFAULT_ENROLLMENT_WINDOW_MS = 30 * 60 * 1000;
|
|
177
|
-
/**
|
|
178
|
-
* Deadline for one admission decision, after which the fail-open outcome is
|
|
179
|
-
* used (connection admitted / reservation admitted).
|
|
180
|
-
*
|
|
181
|
-
* libp2p awaits `denyInboundEncryptedConnection` inside the inbound upgrade
|
|
182
|
-
* WITHOUT racing its inbound-upgrade timeout signal (unlike the pre-encryption
|
|
183
|
-
* `denyInboundConnection` hook), so a decision that never settles wedges that
|
|
184
|
-
* upgrade forever — the connection-manager's inbound-upgrade slot is taken by
|
|
185
|
-
* `acceptIncomingConnection` and released in the `finally` that never runs. The
|
|
186
|
-
* real policy reads the control DB (`listAuthorizedMembers`), which can pull
|
|
187
|
-
* over the network, so "never settles" is reachable. Bounding it here keeps the
|
|
188
|
-
* fail-open contract honest: a slow decision admits rather than silently
|
|
189
|
-
* failing closed (or not at all).
|
|
190
|
-
*/
|
|
191
|
-
export const ADMISSION_DECISION_TIMEOUT_MS = 2000;
|
|
192
182
|
/**
|
|
193
183
|
* How long an `'admit-for-relay'` connection may exist without a relay
|
|
194
184
|
* reservation being ADMITTED at the `denyInboundRelayReservation` hook, after
|
|
@@ -197,8 +187,13 @@ export const ADMISSION_DECISION_TIMEOUT_MS = 2000;
|
|
|
197
187
|
* dials and requests in one drive; a strand node's configured circuit listener
|
|
198
188
|
* does the same from inside its own `listen()`), so a connection idle past this
|
|
199
189
|
* deadline is not reserving.
|
|
190
|
+
*
|
|
191
|
+
* Derived from the link ({@link relayAdmissionReserveDeadlineMs}): one link round trip for the
|
|
192
|
+
* request to arrive plus one admission decision on it. This is the value at the default
|
|
193
|
+
* declaration; `CadreNode` passes the one derived from the relay's OWN declaration, because the
|
|
194
|
+
* relay is the machine that decides.
|
|
200
195
|
*/
|
|
201
|
-
export const RELAY_ADMISSION_RESERVE_DEADLINE_MS =
|
|
196
|
+
export const RELAY_ADMISSION_RESERVE_DEADLINE_MS = relayAdmissionReserveDeadlineMs();
|
|
202
197
|
/**
|
|
203
198
|
* Bound on the graceful close of an expired relay-only connection. It exists
|
|
204
199
|
* because `AbstractMultiaddrConnection.close()` awaits an `idle`/`drain` event
|
|
@@ -210,6 +205,7 @@ export const RELAY_ADMISSION_RESERVE_DEADLINE_MS = 5000;
|
|
|
210
205
|
* Applied through {@link withDeadline}, not `AbortSignal.timeout`: the latter is
|
|
211
206
|
* not reliably present on React Native/Hermes, which loads this same module.
|
|
212
207
|
*/
|
|
208
|
+
// eslint-disable-next-line no-restricted-syntax -- link-independent: bounds a local connection close inside a timer callback, and expiry aborts the connection instead
|
|
213
209
|
export const RELAY_ADMISSION_CLOSE_TIMEOUT_MS = 2000;
|
|
214
210
|
/**
|
|
215
211
|
* Default cap on concurrent relay reservations held by peers the membership
|
|
@@ -219,43 +215,36 @@ export const RELAY_ADMISSION_CLOSE_TIMEOUT_MS = 2000;
|
|
|
219
215
|
* `network.unauthorizedRelayReservationCap` (0 refuses every unauthorized
|
|
220
216
|
* reservation — the strict pre-seam posture).
|
|
221
217
|
*
|
|
222
|
-
* NOTE: this cap shares the relay server's own reservation store, whose
|
|
223
|
-
* size is
|
|
224
|
-
* unplaced peers may therefore occupy up to this many of
|
|
225
|
-
* rest are what members and delegates compete for.
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
218
|
+
* NOTE: this cap shares the relay server's own reservation store, whose
|
|
219
|
+
* party-run default size is `PARTY_RELAY_MAX_RESERVATIONS` (128,
|
|
220
|
+
* `relay-server.ts`); unplaced peers may therefore occupy up to this many of
|
|
221
|
+
* those slots, and the rest are what members and delegates compete for. The two
|
|
222
|
+
* are kept apart by hand — if this is raised, or an embedder shrinks the store
|
|
223
|
+
* through `network.relayServerInit.reservations.maxReservations`, keep this one
|
|
224
|
+
* well under the store's, or a fleet of unplaceable peers can crowd genuine
|
|
225
|
+
* members out of the server's own store (which the gate cannot override).
|
|
229
226
|
*/
|
|
230
227
|
export const MAX_UNAUTHORIZED_RELAY_RESERVATIONS = 8;
|
|
231
|
-
/**
|
|
232
|
-
* How long one {@link UnauthorizedReservationBudget} entry occupies a slot
|
|
233
|
-
* without a refresh. Mirrors the relay server's own default reservation TTL
|
|
234
|
-
* (`@libp2p/circuit-relay-v2`'s `DEFAULT_MAX_RESERVATION_TTL`, 2 h): the server
|
|
235
|
-
* holds an unrefreshed reservation exactly that long, and a live reserver
|
|
236
|
-
* re-requests (re-hitting the admission hook, refreshing its entry) well before
|
|
237
|
-
* expiry — so the live entry count tracks the server's own occupancy without
|
|
238
|
-
* this module reaching into the server's reservation store.
|
|
239
|
-
*
|
|
240
|
-
* NOTE: a mirror, not a live coupling — if the relay server is ever configured
|
|
241
|
-
* with a non-default `reservationTtl` (db-p2p's `relayServerInit`), update this
|
|
242
|
-
* constant alongside it or the budget's occupancy drifts from the server's.
|
|
243
|
-
*/
|
|
244
|
-
export const UNAUTHORIZED_RESERVATION_TTL_MS = 2 * 60 * 60 * 1000;
|
|
245
228
|
/**
|
|
246
229
|
* Bounded budget of concurrent relay reservations for peers the membership
|
|
247
230
|
* check could not place. `tryAdmit` is the whole surface: an already-admitted
|
|
248
231
|
* peer refreshes its entry (a reservation refresh never double-counts), a new
|
|
249
|
-
* peer takes a free slot or is refused. Entries expire after `ttlMs
|
|
250
|
-
*
|
|
251
|
-
* server
|
|
232
|
+
* peer takes a free slot or is refused. Entries expire after `ttlMs`, which
|
|
233
|
+
* `CadreNode` passes as the relay server's own resolved `reservationTtl`
|
|
234
|
+
* (`relay-server.ts`): the server holds an unrefreshed reservation exactly that
|
|
235
|
+
* long, and a live reserver re-requests (re-hitting the admission hook,
|
|
236
|
+
* refreshing its entry) well before expiry — so the live entry count tracks the
|
|
237
|
+
* server's own occupancy without this module reaching into the server's
|
|
238
|
+
* reservation store. Injectable `now` keeps expiry testable without fake
|
|
252
239
|
* timers. Authorized members and delegates are never run through this — the
|
|
253
240
|
* policy admits them before consulting the budget, and `release`s the slot such
|
|
254
241
|
* a peer took while it was still unplaceable, so the boot-ordering window a
|
|
255
242
|
* member passes through costs the budget nothing once its row lands.
|
|
256
243
|
*/
|
|
257
244
|
export class UnauthorizedReservationBudget {
|
|
258
|
-
constructor(
|
|
245
|
+
constructor(
|
|
246
|
+
/** Most peers admitted at once — `network.unauthorizedRelayReservationCap`, resolved. */
|
|
247
|
+
cap = MAX_UNAUTHORIZED_RELAY_RESERVATIONS, ttlMs = PARTY_RELAY_RESERVATION_TTL_MS) {
|
|
259
248
|
this.cap = cap;
|
|
260
249
|
this.ttlMs = ttlMs;
|
|
261
250
|
this.admitted = new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membership-connection-gater.js","sourceRoot":"","sources":["../src/membership-connection-gater.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"membership-connection-gater.js","sourceRoot":"","sources":["../src/membership-connection-gater.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8JG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAC;AAElG,MAAM,GAAG,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAsB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAE9F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3D;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,+BAA+B,EAAE,CAAC;AAErF;;;;;;;;;;GAUG;AACH,uKAAuK;AACvK,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAK,CAAC;AAEtD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAwCrD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,6BAA6B;IAGxC;IACE,yFAAyF;IAChF,MAAc,mCAAmC,EACzC,QAAgB,8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E;QAClE,IAAI,CAAC;YACH,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,sEAAsE,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;QACrH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,8DAA8D,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;CACF"}
|
|
@@ -34,10 +34,10 @@ export interface DurableSlot {
|
|
|
34
34
|
* in full is not an anchor. Trusting a *subset* of the keys a file claims is
|
|
35
35
|
* a silent, security-relevant downgrade, so the whole record is discarded
|
|
36
36
|
* and the node trusts no one until re-seeded out of band.
|
|
37
|
-
* - `'drop-entry'` (the bootstrap-peer store and the strand
|
|
38
|
-
* record is a best-effort dial list and nothing in
|
|
39
|
-
* junk entry must not discard a stranded node's
|
|
40
|
-
* its party or its strand's peers.
|
|
37
|
+
* - `'drop-entry'` (the bootstrap-peer store and the strand network state):
|
|
38
|
+
* the record is a best-effort dial list and nothing in
|
|
39
|
+
* it is trust-bearing, so one junk entry must not discard a stranded node's
|
|
40
|
+
* only remaining way back to its party or its strand's peers.
|
|
41
41
|
*/
|
|
42
42
|
export type UnusableEntryPolicy = 'discard-all' | 'drop-entry';
|
|
43
43
|
/** What a particular node-local record persists, and how it validates it. */
|
|
@@ -96,6 +96,8 @@ export declare class NodeLocalSnapshot<E> {
|
|
|
96
96
|
*/
|
|
97
97
|
static open<E>(slot: DurableSlot, partyId: string, spec: NodeLocalSnapshotSpec<E>): Promise<NodeLocalSnapshot<E>>;
|
|
98
98
|
has(key: string): boolean;
|
|
99
|
+
/** The entry held for `key`, if any. Needs no copy: {@link put} replaces an entry, never mutates it. */
|
|
100
|
+
get(key: string): E | undefined;
|
|
99
101
|
/** Fresh copy of the keys — a snapshot decoupled from later {@link put} / {@link remove} calls. */
|
|
100
102
|
keySnapshot(): Set<string>;
|
|
101
103
|
/**
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* - the trusted-owner anchor (`trusted-owner-store.ts`),
|
|
7
7
|
* - the cold-start bootstrap-peer store (`bootstrap-peer-store.ts`),
|
|
8
|
-
* - the strand
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* - the strand network state (`strand-network-state.ts`): per strand, the state
|
|
9
|
+
* Optimystic's db-p2p saved for the strand node, opaque here past a structural
|
|
10
|
+
* check.
|
|
11
11
|
*
|
|
12
12
|
* ANOTHER node-local record — the enrolled-machine count
|
|
13
13
|
* (`enrolled-machine-store.ts`) — reuses {@link DurableSlot} but deliberately
|
|
@@ -78,6 +78,10 @@ export class NodeLocalSnapshot {
|
|
|
78
78
|
has(key) {
|
|
79
79
|
return this.entries.has(key);
|
|
80
80
|
}
|
|
81
|
+
/** The entry held for `key`, if any. Needs no copy: {@link put} replaces an entry, never mutates it. */
|
|
82
|
+
get(key) {
|
|
83
|
+
return this.entries.get(key);
|
|
84
|
+
}
|
|
81
85
|
/** Fresh copy of the keys — a snapshot decoupled from later {@link put} / {@link remove} calls. */
|
|
82
86
|
keySnapshot() {
|
|
83
87
|
return new Set(this.entries.keys());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-local-snapshot.js","sourceRoot":"","sources":["../src/node-local-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,GAAG,GAAG,KAAK,CAAC,kCAAkC,CAAC,CAAC;AA+BtD,kFAAkF;AAClF,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAiC3B;;;;;;;;;;GAUG;AACH,MAAM,OAAO,iBAAiB;IAQ7B,YACkB,IAAiB,EACzB,OAAe,EACP,IAA8B,EAC9B,OAAuB;QAHvB,SAAI,GAAJ,IAAI,CAAa;QACzB,YAAO,GAAP,OAAO,CAAQ;QACP,SAAI,GAAJ,IAAI,CAA0B;QAC9B,YAAO,GAAP,O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O,CAAC,CAAC;IAC/E,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CACvB,KAAc,EACd,OAAe,EACf,UAAkB;IAElB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvC,2EAA2E;IAC3E,oDAAoD;IACpD,IAAI,KAAK,CAAC,OAAO,KAAK,gBAAgB,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IACtF,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC"}
|
package/dist/peer-dial.d.ts
CHANGED
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
* Dependency-free apart from `control-stream.ts`, so any module may import it
|
|
23
23
|
* without creating an import cycle.
|
|
24
24
|
*/
|
|
25
|
-
import type { Connection } from '@libp2p/interface';
|
|
25
|
+
import type { Connection, PeerId } from '@libp2p/interface';
|
|
26
26
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
27
27
|
/**
|
|
28
28
|
* Default limit on ONE address's dial attempt, in ms, at the DEFAULT declared link round trip:
|
|
29
|
-
* `RELAYED_DIAL_ROUND_TRIPS` (4) x `DECLARED_LINK_ROUND_TRIP_MS` (3500 ms)
|
|
30
|
-
*
|
|
29
|
+
* `RELAYED_DIAL_ROUND_TRIPS` (4) x `DECLARED_LINK_ROUND_TRIP_MS` (3500 ms) plus the called
|
|
30
|
+
* machine's `ADMISSION_DECISION_TIMEOUT_MS` (2000 ms) = 16 000 ms (`relayedDialBudgetMs`). It
|
|
31
|
+
* was a fixed 8000 ms before it was derived.
|
|
31
32
|
*
|
|
32
33
|
* It has to cover the slowest address that should succeed, because an attempt
|
|
33
34
|
* that needs longer fails the same way on every retry. That is a relayed dial on
|
|
@@ -101,20 +102,39 @@ export interface PeerDialBudget {
|
|
|
101
102
|
export declare const DEFAULT_PEER_DIAL_BUDGET: Readonly<PeerDialBudget>;
|
|
102
103
|
/** The slice of a libp2p node {@link dialPeerAddrs} uses. */
|
|
103
104
|
export interface AddrDialer {
|
|
105
|
+
/** This node's id, to recognise an address that relays through this node ({@link relaysThrough}). */
|
|
106
|
+
readonly peerId: PeerId;
|
|
104
107
|
dial(addr: Multiaddr, options: {
|
|
105
108
|
signal: AbortSignal;
|
|
106
109
|
}): Promise<Connection>;
|
|
107
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Thrown by {@link dialPeerAddrs} when it was given addresses but every one reaches the peer by
|
|
113
|
+
* relaying through this node, so none was dialed.
|
|
114
|
+
*
|
|
115
|
+
* This is where a relay lands for a peer that holds a reservation on it (a phone, or any node that
|
|
116
|
+
* cannot listen): the address that peer publishes is `/<relay transport>/p2p/<relay>/p2p-circuit/p2p/<peer>`,
|
|
117
|
+
* and dialing it from the relay itself fails with libp2p's `Can not dial self`. Nothing this node
|
|
118
|
+
* does can repair it; once the peer's connection drops, only the peer can reconnect. Callers log it
|
|
119
|
+
* as that rather than as a dial failure.
|
|
120
|
+
*/
|
|
121
|
+
export declare class SelfRelayOnlyError extends Error {
|
|
122
|
+
constructor(label: string);
|
|
123
|
+
}
|
|
108
124
|
/**
|
|
109
125
|
* Dial one peer from `addrs`, one address per `dial()` call, and return the
|
|
110
126
|
* first connection that forms. Direct addresses are tried before relayed ones
|
|
111
127
|
* ({@link directBeforeRelayed}); otherwise the given order is kept.
|
|
112
128
|
*
|
|
129
|
+
* Addresses that relay through this node are dropped first ({@link relaysThrough}):
|
|
130
|
+
* dialing one could only fail with `Can not dial self`. When that leaves nothing
|
|
131
|
+
* of a non-empty list, this throws {@link SelfRelayOnlyError} without dialing.
|
|
132
|
+
*
|
|
113
133
|
* Addresses naming a transport this node lacks are not filtered out first: a
|
|
114
134
|
* one-address `dial()` rejects those at once (`NoValidAddressesError`), so they
|
|
115
135
|
* cost a log line, not time.
|
|
116
136
|
*
|
|
117
|
-
*
|
|
137
|
+
* Otherwise throws when no address connects — see {@link tryAddrsInTurn} for the error.
|
|
118
138
|
*
|
|
119
139
|
* @param label Names the dial in timeout messages and logs, e.g.
|
|
120
140
|
* `reconcileControlCohort dial of sibling <peerId>`; each attempt reads
|
package/dist/peer-dial.js
CHANGED
|
@@ -23,13 +23,15 @@
|
|
|
23
23
|
* without creating an import cycle.
|
|
24
24
|
*/
|
|
25
25
|
import debug from 'debug';
|
|
26
|
+
import { peerIdFromString } from '@libp2p/peer-id';
|
|
26
27
|
import { withDeadline } from './control-stream.js';
|
|
27
28
|
import { relayedDialBudgetMs } from './link-budget.js';
|
|
28
29
|
const log = debug('sereus:cadre:peer-dial');
|
|
29
30
|
/**
|
|
30
31
|
* Default limit on ONE address's dial attempt, in ms, at the DEFAULT declared link round trip:
|
|
31
|
-
* `RELAYED_DIAL_ROUND_TRIPS` (4) x `DECLARED_LINK_ROUND_TRIP_MS` (3500 ms)
|
|
32
|
-
*
|
|
32
|
+
* `RELAYED_DIAL_ROUND_TRIPS` (4) x `DECLARED_LINK_ROUND_TRIP_MS` (3500 ms) plus the called
|
|
33
|
+
* machine's `ADMISSION_DECISION_TIMEOUT_MS` (2000 ms) = 16 000 ms (`relayedDialBudgetMs`). It
|
|
34
|
+
* was a fixed 8000 ms before it was derived.
|
|
33
35
|
*
|
|
34
36
|
* It has to cover the slowest address that should succeed, because an attempt
|
|
35
37
|
* that needs longer fails the same way on every retry. That is a relayed dial on
|
|
@@ -97,23 +99,47 @@ export const DEFAULT_PEER_DIAL_BUDGET = {
|
|
|
97
99
|
perAddressMs: DEFAULT_CONTROL_COHORT_PER_ADDRESS_DIAL_TIMEOUT_MS,
|
|
98
100
|
totalMs: DEFAULT_CONTROL_COHORT_DIAL_TIMEOUT_MS,
|
|
99
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* Thrown by {@link dialPeerAddrs} when it was given addresses but every one reaches the peer by
|
|
104
|
+
* relaying through this node, so none was dialed.
|
|
105
|
+
*
|
|
106
|
+
* This is where a relay lands for a peer that holds a reservation on it (a phone, or any node that
|
|
107
|
+
* cannot listen): the address that peer publishes is `/<relay transport>/p2p/<relay>/p2p-circuit/p2p/<peer>`,
|
|
108
|
+
* and dialing it from the relay itself fails with libp2p's `Can not dial self`. Nothing this node
|
|
109
|
+
* does can repair it; once the peer's connection drops, only the peer can reconnect. Callers log it
|
|
110
|
+
* as that rather than as a dial failure.
|
|
111
|
+
*/
|
|
112
|
+
export class SelfRelayOnlyError extends Error {
|
|
113
|
+
constructor(label) {
|
|
114
|
+
super(`${label}: every candidate address relays through this node; only the peer can reconnect`);
|
|
115
|
+
this.name = 'SelfRelayOnlyError';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
100
118
|
/**
|
|
101
119
|
* Dial one peer from `addrs`, one address per `dial()` call, and return the
|
|
102
120
|
* first connection that forms. Direct addresses are tried before relayed ones
|
|
103
121
|
* ({@link directBeforeRelayed}); otherwise the given order is kept.
|
|
104
122
|
*
|
|
123
|
+
* Addresses that relay through this node are dropped first ({@link relaysThrough}):
|
|
124
|
+
* dialing one could only fail with `Can not dial self`. When that leaves nothing
|
|
125
|
+
* of a non-empty list, this throws {@link SelfRelayOnlyError} without dialing.
|
|
126
|
+
*
|
|
105
127
|
* Addresses naming a transport this node lacks are not filtered out first: a
|
|
106
128
|
* one-address `dial()` rejects those at once (`NoValidAddressesError`), so they
|
|
107
129
|
* cost a log line, not time.
|
|
108
130
|
*
|
|
109
|
-
*
|
|
131
|
+
* Otherwise throws when no address connects — see {@link tryAddrsInTurn} for the error.
|
|
110
132
|
*
|
|
111
133
|
* @param label Names the dial in timeout messages and logs, e.g.
|
|
112
134
|
* `reconcileControlCohort dial of sibling <peerId>`; each attempt reads
|
|
113
135
|
* `<label> via <addr>`.
|
|
114
136
|
*/
|
|
115
|
-
export function dialPeerAddrs(dialer, addrs, budget, label) {
|
|
116
|
-
|
|
137
|
+
export async function dialPeerAddrs(dialer, addrs, budget, label) {
|
|
138
|
+
const dialable = withoutSelfRelayed(dialer, addrs, label);
|
|
139
|
+
if (addrs.length > 0 && dialable.length === 0) {
|
|
140
|
+
throw new SelfRelayOnlyError(label);
|
|
141
|
+
}
|
|
142
|
+
return tryAddrsInTurn(directBeforeRelayed(dialable), budget, label, (addr, signal) => dialer.dial(addr, { signal }));
|
|
117
143
|
}
|
|
118
144
|
/**
|
|
119
145
|
* Run `attempt` against each address in the given order until one succeeds, and
|
|
@@ -180,6 +206,49 @@ export function directBeforeRelayed(addrs) {
|
|
|
180
206
|
const relayed = (addr) => addr.getComponents().some((c) => c.name === 'p2p-circuit');
|
|
181
207
|
return [...addrs.filter((addr) => !relayed(addr)), ...addrs.filter(relayed)];
|
|
182
208
|
}
|
|
209
|
+
/** `addrs` without those that relay through `dialer` itself, each dropped one logged. */
|
|
210
|
+
function withoutSelfRelayed(dialer, addrs, label) {
|
|
211
|
+
return addrs.filter((addr) => {
|
|
212
|
+
if (!relaysThrough(addr, dialer.peerId)) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
log('%s: skipping %s — it relays through this node', label, addr.toString());
|
|
216
|
+
return false;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Whether `addr` reaches its target by relaying through `relay` at any hop.
|
|
221
|
+
*
|
|
222
|
+
* A circuit address names its relay in the `p2p` component immediately before
|
|
223
|
+
* the `p2p-circuit` marker (`/<transport>/p2p/<relay>/p2p-circuit/p2p/<target>`),
|
|
224
|
+
* so the components are walked rather than the text searched: the target's id
|
|
225
|
+
* after the marker, a bare `/p2p-circuit` naming no relay, and a multi-hop chain
|
|
226
|
+
* each read correctly that way. Same rule as db-p2p's `routesThroughRelay`, which
|
|
227
|
+
* its package does not export.
|
|
228
|
+
*/
|
|
229
|
+
function relaysThrough(addr, relay) {
|
|
230
|
+
const components = addr.getComponents();
|
|
231
|
+
return components.some((component, i) => component.name === 'p2p-circuit' && namesPeer(components[i - 1], relay));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Whether `component` is a `p2p` component naming `peer`. Compared as canonical
|
|
235
|
+
* strings because a multiaddr keeps a peer id in whichever form it was written
|
|
236
|
+
* (base58 or CIDv1). `PeerId.equals` is avoided because test doubles supply the
|
|
237
|
+
* dialer's `peerId` with `toString` only.
|
|
238
|
+
*/
|
|
239
|
+
function namesPeer(component, peer) {
|
|
240
|
+
if (component?.name !== 'p2p' || component.value === undefined) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const expected = peer.toString();
|
|
244
|
+
try {
|
|
245
|
+
return peerIdFromString(component.value).toString() === expected;
|
|
246
|
+
}
|
|
247
|
+
catch (err) {
|
|
248
|
+
log('cannot read %s as a peer id; treating it as not this node: %o', component.value, err);
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
183
252
|
function allAttemptsFailed(label, failures) {
|
|
184
253
|
if (failures.length === 0) {
|
|
185
254
|
return new Error(`${label}: no candidate addresses`);
|
package/dist/peer-dial.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer-dial.js","sourceRoot":"","sources":["../src/peer-dial.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"peer-dial.js","sourceRoot":"","sources":["../src/peer-dial.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAA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AmB,QAAQ,CAAC,MAAM,yBAAyB,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AAC7H,CAAC;AAED,SAAS,aAAa;IACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -8,15 +8,6 @@ import { BlockTransferClient, type IRawStorage } from '@optimystic/db-p2p';
|
|
|
8
8
|
* changes it or starts exporting it.
|
|
9
9
|
*/
|
|
10
10
|
export declare const MAX_BLOCK_MESSAGE_BYTES: number;
|
|
11
|
-
/**
|
|
12
|
-
* Whether an identified peer's protocol list names this network's own block-transfer
|
|
13
|
-
* protocol — the one gate that decides whether {@link PeerJoinBackfill} schedules a peer at
|
|
14
|
-
* all. A peer that lacks it (a bare circuit relay, a bootstrap node, a stranger the control
|
|
15
|
-
* network's inbound gate admitted without membership) cannot receive a push no matter how
|
|
16
|
-
* long it is dialed, since the protocol id is namespaced per network. Exported because a
|
|
17
|
-
* later strand peer-address ticket's identify-driven observation needs the identical test.
|
|
18
|
-
*/
|
|
19
|
-
export declare function speaksBlockTransfer(protocols: readonly string[], protocolPrefix: string): boolean;
|
|
20
11
|
/**
|
|
21
12
|
* Consecutive failed catch-up runs against ONE peer before the module says so on
|
|
22
13
|
* `console.warn` rather than only in its DEBUG log. At the default backoff that is reached
|
|
@@ -38,7 +29,8 @@ export interface PeerJoinBackfillConfig {
|
|
|
38
29
|
maxChunkBlocks?: number;
|
|
39
30
|
/**
|
|
40
31
|
* Per-push dial deadline, ms. Default {@link peerJoinPushBudget}'s `dialTimeoutMs` — four link
|
|
41
|
-
* round trips at the declared link
|
|
32
|
+
* round trips at the declared link plus the called machine's admission decision, 16 000 ms as
|
|
33
|
+
* shipped. NOT a fixed number: a relayed dial
|
|
42
34
|
* costs a fixed number of exchanges, so a host on a slower link moves this (and every other
|
|
43
35
|
* cadre dial budget) by declaring `NetworkConfig.linkRoundTripMs`. Naming it here still wins
|
|
44
36
|
* over the derived value — `link-budget.ts` has the counts and the measurement.
|
|
@@ -60,11 +60,12 @@ import { peerJoinPushBudget } from './link-budget.js';
|
|
|
60
60
|
// `packages/integration-tests/src/scenarios/relayed-dial-cost-by-latency.integration.ts`.
|
|
61
61
|
//
|
|
62
62
|
// It does NOT work at every speed. Above the declared link, libp2p's own dial and
|
|
63
|
-
// inbound-upgrade limits —
|
|
64
|
-
// any deadline here is consulted, and the listener's one makes that failure
|
|
65
|
-
// peer rather than a timeout. That is also what happens when the machine
|
|
66
|
-
// declared a FASTER link than this one, since its limit is the listener's. See
|
|
67
|
-
// `link-budget.ts` ("
|
|
63
|
+
// inbound-upgrade limits — which Optimystic derives from the same declaration — abandon the
|
|
64
|
+
// connection before any deadline here is consulted, and the listener's one makes that failure
|
|
65
|
+
// look like an absent peer rather than a timeout. That is also what happens when the machine
|
|
66
|
+
// being caught up declared a FASTER link than this one, since its limit is the listener's. See
|
|
67
|
+
// `link-budget.ts` ("Optimystic's deadlines, from the same declaration", "What still fails at
|
|
68
|
+
// the supported link").
|
|
68
69
|
//
|
|
69
70
|
// RETRY, and why it backs off. A run whose PUSH FAILED — the transport threw, which is what
|
|
70
71
|
// a dial or response deadline expiring looks like here — re-arms on a doubling backoff
|
|
@@ -141,10 +142,9 @@ export const MAX_BLOCK_MESSAGE_BYTES = 8 * 1024 * 1024;
|
|
|
141
142
|
* protocol — the one gate that decides whether {@link PeerJoinBackfill} schedules a peer at
|
|
142
143
|
* all. A peer that lacks it (a bare circuit relay, a bootstrap node, a stranger the control
|
|
143
144
|
* network's inbound gate admitted without membership) cannot receive a push no matter how
|
|
144
|
-
* long it is dialed, since the protocol id is namespaced per network.
|
|
145
|
-
* later strand peer-address ticket's identify-driven observation needs the identical test.
|
|
145
|
+
* long it is dialed, since the protocol id is namespaced per network.
|
|
146
146
|
*/
|
|
147
|
-
|
|
147
|
+
function speaksBlockTransfer(protocols, protocolPrefix) {
|
|
148
148
|
return protocols.includes(buildBlockTransferProtocol(protocolPrefix));
|
|
149
149
|
}
|
|
150
150
|
/**
|