@optimystic/db-p2p 1.0.0-beta.3 → 1.0.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/src/cluster/block-transfer-service.d.ts +73 -1
- package/dist/src/cluster/block-transfer-service.d.ts.map +1 -1
- package/dist/src/cluster/block-transfer-service.js +70 -3
- package/dist/src/cluster/block-transfer-service.js.map +1 -1
- package/dist/src/cluster/block-transfer.d.ts +16 -1
- package/dist/src/cluster/block-transfer.d.ts.map +1 -1
- package/dist/src/cluster/block-transfer.js +73 -72
- package/dist/src/cluster/block-transfer.js.map +1 -1
- package/dist/src/cluster/client.d.ts +4 -6
- package/dist/src/cluster/client.d.ts.map +1 -1
- package/dist/src/cluster/client.js +8 -13
- package/dist/src/cluster/client.js.map +1 -1
- package/dist/src/cluster/cluster-policy.d.ts +2 -1
- package/dist/src/cluster/cluster-policy.d.ts.map +1 -1
- package/dist/src/cluster/cluster-policy.js.map +1 -1
- package/dist/src/cluster/cluster-repo.d.ts +126 -6
- package/dist/src/cluster/cluster-repo.d.ts.map +1 -1
- package/dist/src/cluster/cluster-repo.js +378 -50
- package/dist/src/cluster/cluster-repo.js.map +1 -1
- package/dist/src/cluster/commit-proof.js +2 -2
- package/dist/src/cluster/race-resolution.d.ts +51 -7
- package/dist/src/cluster/race-resolution.d.ts.map +1 -1
- package/dist/src/cluster/race-resolution.js +71 -7
- package/dist/src/cluster/race-resolution.js.map +1 -1
- package/dist/src/cluster/rebalance-monitor.d.ts +67 -5
- package/dist/src/cluster/rebalance-monitor.d.ts.map +1 -1
- package/dist/src/cluster/rebalance-monitor.js +120 -26
- package/dist/src/cluster/rebalance-monitor.js.map +1 -1
- package/dist/src/cluster/spread-on-churn.d.ts.map +1 -1
- package/dist/src/cluster/spread-on-churn.js +34 -47
- package/dist/src/cluster/spread-on-churn.js.map +1 -1
- package/dist/src/cohort-topic/host.d.ts.map +1 -1
- package/dist/src/cohort-topic/host.js +8 -6
- package/dist/src/cohort-topic/host.js.map +1 -1
- package/dist/src/cohort-topic/membership-source.js +1 -1
- package/dist/src/cohort-topic/membership-source.js.map +1 -1
- package/dist/src/cohort-topic/peer-codec.d.ts.map +1 -1
- package/dist/src/cohort-topic/peer-codec.js +5 -2
- package/dist/src/cohort-topic/peer-codec.js.map +1 -1
- package/dist/src/cohort-topic/stream-util.d.ts +24 -3
- package/dist/src/cohort-topic/stream-util.d.ts.map +1 -1
- package/dist/src/cohort-topic/stream-util.js +36 -3
- package/dist/src/cohort-topic/stream-util.js.map +1 -1
- package/dist/src/cohort-topic/topic-router.d.ts +9 -0
- package/dist/src/cohort-topic/topic-router.d.ts.map +1 -1
- package/dist/src/cohort-topic/topic-router.js +12 -2
- package/dist/src/cohort-topic/topic-router.js.map +1 -1
- package/dist/src/dispute/client.d.ts.map +1 -1
- package/dist/src/dispute/client.js +15 -3
- package/dist/src/dispute/client.js.map +1 -1
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p-key-network.d.ts +78 -17
- package/dist/src/libp2p-key-network.d.ts.map +1 -1
- package/dist/src/libp2p-key-network.js +234 -147
- package/dist/src/libp2p-key-network.js.map +1 -1
- package/dist/src/libp2p-node-base.d.ts +35 -1
- package/dist/src/libp2p-node-base.d.ts.map +1 -1
- package/dist/src/libp2p-node-base.js +151 -26
- package/dist/src/libp2p-node-base.js.map +1 -1
- package/dist/src/libp2p-node-rn.d.ts +2 -2
- package/dist/src/libp2p-node-rn.d.ts.map +1 -1
- package/dist/src/libp2p-node-rn.js.map +1 -1
- package/dist/src/libp2p-node.d.ts +2 -2
- package/dist/src/libp2p-node.d.ts.map +1 -1
- package/dist/src/libp2p-node.js.map +1 -1
- package/dist/src/logger.d.ts.map +1 -1
- package/dist/src/logger.js +6 -1
- package/dist/src/logger.js.map +1 -1
- package/dist/src/matchmaking/query-transport.d.ts +3 -4
- package/dist/src/matchmaking/query-transport.d.ts.map +1 -1
- package/dist/src/matchmaking/query-transport.js +9 -9
- package/dist/src/matchmaking/query-transport.js.map +1 -1
- package/dist/src/network/network-manager-service.d.ts +10 -5
- package/dist/src/network/network-manager-service.d.ts.map +1 -1
- package/dist/src/network/network-manager-service.js +11 -2
- package/dist/src/network/network-manager-service.js.map +1 -1
- package/dist/src/network/relay-reservation.d.ts +170 -0
- package/dist/src/network/relay-reservation.d.ts.map +1 -0
- package/dist/src/network/relay-reservation.js +527 -0
- package/dist/src/network/relay-reservation.js.map +1 -0
- package/dist/src/pend-validation.d.ts +3 -2
- package/dist/src/pend-validation.d.ts.map +1 -1
- package/dist/src/pend-validation.js +3 -2
- package/dist/src/pend-validation.js.map +1 -1
- package/dist/src/protocol-client.d.ts +8 -1
- package/dist/src/protocol-client.d.ts.map +1 -1
- package/dist/src/protocol-client.js +11 -0
- package/dist/src/protocol-client.js.map +1 -1
- package/dist/src/reactivity/forwarder-host.d.ts +2 -1
- package/dist/src/reactivity/forwarder-host.d.ts.map +1 -1
- package/dist/src/reactivity/forwarder-host.js +2 -1
- package/dist/src/reactivity/forwarder-host.js.map +1 -1
- package/dist/src/reactivity/origination-manager.d.ts +3 -3
- package/dist/src/reactivity/origination-manager.js +3 -3
- package/dist/src/reactivity/recover-transport.d.ts +22 -14
- package/dist/src/reactivity/recover-transport.d.ts.map +1 -1
- package/dist/src/reactivity/recover-transport.js +32 -19
- package/dist/src/reactivity/recover-transport.js.map +1 -1
- package/dist/src/reactivity/subscription-manager.d.ts +2 -2
- package/dist/src/reactivity/topic-bytes.d.ts +6 -7
- package/dist/src/reactivity/topic-bytes.d.ts.map +1 -1
- package/dist/src/reactivity/topic-bytes.js +8 -9
- package/dist/src/reactivity/topic-bytes.js.map +1 -1
- package/dist/src/repo/client.d.ts +5 -2
- package/dist/src/repo/client.d.ts.map +1 -1
- package/dist/src/repo/client.js +49 -40
- package/dist/src/repo/client.js.map +1 -1
- package/dist/src/repo/cluster-coordinator.d.ts +77 -5
- package/dist/src/repo/cluster-coordinator.d.ts.map +1 -1
- package/dist/src/repo/cluster-coordinator.js +131 -20
- package/dist/src/repo/cluster-coordinator.js.map +1 -1
- package/dist/src/repo/coordinator-repo.d.ts +238 -122
- package/dist/src/repo/coordinator-repo.d.ts.map +1 -1
- package/dist/src/repo/coordinator-repo.js +625 -472
- package/dist/src/repo/coordinator-repo.js.map +1 -1
- package/dist/src/repo/i-under-replication-ledger.d.ts +87 -0
- package/dist/src/repo/i-under-replication-ledger.d.ts.map +1 -0
- package/dist/src/repo/i-under-replication-ledger.js +2 -0
- package/dist/src/repo/i-under-replication-ledger.js.map +1 -0
- package/dist/src/repo/kv-under-replication-ledger.d.ts +91 -0
- package/dist/src/repo/kv-under-replication-ledger.d.ts.map +1 -0
- package/dist/src/repo/kv-under-replication-ledger.js +287 -0
- package/dist/src/repo/kv-under-replication-ledger.js.map +1 -0
- package/dist/src/repo/responsibility.d.ts +37 -0
- package/dist/src/repo/responsibility.d.ts.map +1 -0
- package/dist/src/repo/responsibility.js +37 -0
- package/dist/src/repo/responsibility.js.map +1 -0
- package/dist/src/repo/service.d.ts +44 -15
- package/dist/src/repo/service.d.ts.map +1 -1
- package/dist/src/repo/service.js +64 -27
- package/dist/src/repo/service.js.map +1 -1
- package/dist/src/repo/stuck-reservation.d.ts +127 -0
- package/dist/src/repo/stuck-reservation.d.ts.map +1 -0
- package/dist/src/repo/stuck-reservation.js +179 -0
- package/dist/src/repo/stuck-reservation.js.map +1 -0
- package/dist/src/repo/under-replication-drain.d.ts +208 -0
- package/dist/src/repo/under-replication-drain.d.ts.map +1 -0
- package/dist/src/repo/under-replication-drain.js +461 -0
- package/dist/src/repo/under-replication-drain.js.map +1 -0
- package/dist/src/rn.d.ts +5 -0
- package/dist/src/rn.d.ts.map +1 -1
- package/dist/src/rn.js +5 -0
- package/dist/src/rn.js.map +1 -1
- package/dist/src/storage/block-latch.d.ts +3 -2
- package/dist/src/storage/block-latch.d.ts.map +1 -1
- package/dist/src/storage/block-latch.js +7 -4
- package/dist/src/storage/block-latch.js.map +1 -1
- package/dist/src/storage/block-storage.d.ts +45 -3
- package/dist/src/storage/block-storage.d.ts.map +1 -1
- package/dist/src/storage/block-storage.js +156 -9
- package/dist/src/storage/block-storage.js.map +1 -1
- package/dist/src/storage/i-block-storage.d.ts +57 -5
- package/dist/src/storage/i-block-storage.d.ts.map +1 -1
- package/dist/src/storage/i-block-storage.js.map +1 -1
- package/dist/src/storage/pending-claim.d.ts +167 -0
- package/dist/src/storage/pending-claim.d.ts.map +1 -0
- package/dist/src/storage/pending-claim.js +156 -0
- package/dist/src/storage/pending-claim.js.map +1 -0
- package/dist/src/storage/raw-store-codec.d.ts +13 -0
- package/dist/src/storage/raw-store-codec.d.ts.map +1 -1
- package/dist/src/storage/raw-store-codec.js +24 -3
- package/dist/src/storage/raw-store-codec.js.map +1 -1
- package/dist/src/storage/restoration-coordinator.d.ts.map +1 -1
- package/dist/src/storage/restoration-coordinator.js +2 -1
- package/dist/src/storage/restoration-coordinator.js.map +1 -1
- package/dist/src/storage/ring-shift-coordinator.d.ts.map +1 -1
- package/dist/src/storage/ring-shift-coordinator.js +3 -3
- package/dist/src/storage/ring-shift-coordinator.js.map +1 -1
- package/dist/src/storage/storage-repo.d.ts +122 -5
- package/dist/src/storage/storage-repo.d.ts.map +1 -1
- package/dist/src/storage/storage-repo.js +245 -68
- package/dist/src/storage/storage-repo.js.map +1 -1
- package/dist/src/storage/struct.d.ts +58 -0
- package/dist/src/storage/struct.d.ts.map +1 -1
- package/dist/src/testing/mesh-harness.d.ts +77 -11
- package/dist/src/testing/mesh-harness.d.ts.map +1 -1
- package/dist/src/testing/mesh-harness.js +226 -100
- package/dist/src/testing/mesh-harness.js.map +1 -1
- package/package.json +2 -2
- package/readme.md +27 -3
- package/src/cluster/block-transfer-service.ts +132 -4
- package/src/cluster/block-transfer.ts +79 -84
- package/src/cluster/client.ts +115 -119
- package/src/cluster/cluster-policy.ts +2 -1
- package/src/cluster/cluster-repo.ts +422 -56
- package/src/cluster/commit-proof.ts +2 -2
- package/src/cluster/race-resolution.ts +76 -7
- package/src/cluster/rebalance-monitor.ts +677 -539
- package/src/cluster/spread-on-churn.ts +34 -54
- package/src/cohort-topic/host.ts +8 -6
- package/src/cohort-topic/membership-source.ts +1 -1
- package/src/cohort-topic/peer-codec.ts +34 -31
- package/src/cohort-topic/stream-util.ts +39 -4
- package/src/cohort-topic/topic-router.ts +12 -2
- package/src/dispute/client.ts +17 -7
- package/src/index.ts +64 -59
- package/src/libp2p-key-network.ts +1377 -1260
- package/src/libp2p-node-base.ts +186 -27
- package/src/libp2p-node-rn.ts +31 -30
- package/src/libp2p-node.ts +37 -36
- package/src/logger.ts +6 -1
- package/src/matchmaking/query-transport.ts +9 -9
- package/src/network/network-manager-service.ts +16 -5
- package/src/network/relay-reservation.ts +636 -0
- package/src/pend-validation.ts +3 -2
- package/src/protocol-client.ts +13 -1
- package/src/reactivity/forwarder-host.ts +2 -1
- package/src/reactivity/origination-manager.ts +3 -3
- package/src/reactivity/recover-transport.ts +39 -22
- package/src/reactivity/subscription-manager.ts +2 -2
- package/src/reactivity/topic-bytes.ts +35 -37
- package/src/repo/client.ts +172 -173
- package/src/repo/cluster-coordinator.ts +145 -19
- package/src/repo/coordinator-repo.ts +652 -505
- package/src/repo/i-under-replication-ledger.ts +89 -0
- package/src/repo/kv-under-replication-ledger.ts +302 -0
- package/src/repo/responsibility.ts +48 -0
- package/src/repo/service.ts +76 -39
- package/src/repo/stuck-reservation.ts +224 -0
- package/src/repo/under-replication-drain.ts +582 -0
- package/src/rn.ts +74 -69
- package/src/storage/block-latch.ts +7 -4
- package/src/storage/block-storage.ts +161 -10
- package/src/storage/i-block-storage.ts +60 -5
- package/src/storage/pending-claim.ts +200 -0
- package/src/storage/raw-store-codec.ts +26 -3
- package/src/storage/restoration-coordinator.ts +212 -211
- package/src/storage/ring-shift-coordinator.ts +271 -271
- package/src/storage/storage-repo.ts +280 -72
- package/src/storage/struct.ts +58 -0
- package/src/testing/mesh-harness.ts +293 -112
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { Libp2p } from 'libp2p';
|
|
2
|
+
import type { PeerId } from '@libp2p/interface';
|
|
3
|
+
/** The bare "search" circuit listen address: one pending slot, filled by whoever asks for it. */
|
|
4
|
+
export declare const CIRCUIT_SEARCH_LISTEN_ADDR = "/p2p-circuit";
|
|
5
|
+
/** A relay this node must keep a reservation on itself. */
|
|
6
|
+
export interface SupervisedRelay {
|
|
7
|
+
/** Where to dial the relay: the listen entry without its trailing `/p2p-circuit`. */
|
|
8
|
+
readonly dialAddr: string;
|
|
9
|
+
/** The relay's peer id in the form `PeerId.toString()` produces, whatever spelling the listen entry used. */
|
|
10
|
+
readonly peerId: string;
|
|
11
|
+
}
|
|
12
|
+
/** What {@link planRelayListenAddrs} hands back: the addresses libp2p listens on, and the relays to supervise. */
|
|
13
|
+
export interface RelayListenPlan {
|
|
14
|
+
readonly listenAddrs: string[];
|
|
15
|
+
readonly supervisedRelays: SupervisedRelay[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Split a node's listen addresses into what libp2p should listen on and which relays this node
|
|
19
|
+
* must supervise.
|
|
20
|
+
*
|
|
21
|
+
* A relay-naming circuit listen address — exactly one `p2p-circuit` component, last, with a `p2p`
|
|
22
|
+
* component (the relay's peer id) immediately before it — becomes one bare
|
|
23
|
+
* {@link CIRCUIT_SEARCH_LISTEN_ADDR} entry plus one supervised relay. libp2p keeps listen addresses
|
|
24
|
+
* as a plain array with no de-duplication, so N such entries give N bare listeners and N pending
|
|
25
|
+
* slots. Two entries naming one relay (by peer id, whatever the spelling) give one of each; the
|
|
26
|
+
* first entry's dial address wins. Everything else passes through untouched: a host's own bare
|
|
27
|
+
* `/p2p-circuit` (the host owns that reservation), TCP and WebSocket entries, and anything
|
|
28
|
+
* malformed or multi-hop, which libp2p rejects itself.
|
|
29
|
+
*/
|
|
30
|
+
export declare function planRelayListenAddrs(listenAddrs: readonly string[]): RelayListenPlan;
|
|
31
|
+
/**
|
|
32
|
+
* The slice of `@libp2p/utils`' cuckoo `Filter` the reservation store remembers failed relays in.
|
|
33
|
+
* `remove` is optional on that interface, so its absence must degrade, never throw.
|
|
34
|
+
*/
|
|
35
|
+
export interface RelayFilterLike {
|
|
36
|
+
has(item: Uint8Array): boolean;
|
|
37
|
+
remove?(item: Uint8Array): boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The slice of `@libp2p/circuit-relay-v2`'s transport-side `ReservationStore` this module drives.
|
|
41
|
+
* Structural, because the class is internal to that package: naming only the members used keeps
|
|
42
|
+
* the coupling small and greppable, and lets {@link findCircuitRelayTransport} duck-type it.
|
|
43
|
+
*/
|
|
44
|
+
export interface RelayReservationStoreLike {
|
|
45
|
+
addRelay(peerId: PeerId, type: 'discovered' | 'configured'): Promise<unknown>;
|
|
46
|
+
hasReservation(peerId: PeerId): boolean;
|
|
47
|
+
relayFilter?: RelayFilterLike;
|
|
48
|
+
}
|
|
49
|
+
/** The slice of libp2p's circuit-relay transport that owns the reservation store. */
|
|
50
|
+
export interface CircuitRelayTransportLike {
|
|
51
|
+
reservationStore: RelayReservationStoreLike;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The running node's circuit-relay transport, or `null` when it has none.
|
|
55
|
+
*
|
|
56
|
+
* NOTE: the ONE place this package reaches libp2p internals for relay reservations, pinned against
|
|
57
|
+
* `libp2p` 3.1.3 and `@libp2p/circuit-relay-v2` 4.1.3 by `test/relay-reservation-seam.spec.ts`,
|
|
58
|
+
* which must fail loudly if an upgrade moves any of it. There is no public route: the `Libp2p`
|
|
59
|
+
* interface has no `listen`, and nothing public exposes the reservation store. `node.components`
|
|
60
|
+
* is a real public field on libp2p's node class, just not on the interface; `transportManager`
|
|
61
|
+
* is a component; the circuit-relay transport is the one whose `reservationStore` has `addRelay`
|
|
62
|
+
* and `hasReservation`. What the store does on 4.1.3, read from
|
|
63
|
+
* `node_modules/@libp2p/circuit-relay-v2/src/transport/`: `listener.ts` publishes a `configured`
|
|
64
|
+
* reservation only from inside `listen()` and ignores it on `relay:created-reservation`, while a
|
|
65
|
+
* bare listener publishes any `discovered` reservation carrying its pending id; and
|
|
66
|
+
* `reservation-store.ts` drops a reservation on `connection:close`, re-queues the pending id only
|
|
67
|
+
* for `discovered` ones, removes-then-recreates on refresh, and adds a relay whose request failed
|
|
68
|
+
* with `DialError` or `UnsupportedProtocolError` to the private `relayFilter`, refusing it
|
|
69
|
+
* afterwards with "The relay was previously invalid" until the filter is reset.
|
|
70
|
+
*/
|
|
71
|
+
export declare function findCircuitRelayTransport(node: Libp2p): CircuitRelayTransportLike | null;
|
|
72
|
+
/**
|
|
73
|
+
* Fail node creation, before anything starts, when a listen address names a relay but no transport
|
|
74
|
+
* could ever reserve on it. libp2p would reject the bare `/p2p-circuit` entry itself during
|
|
75
|
+
* `start()`, with a generic unsupported-listen-address error; this names the actual omission.
|
|
76
|
+
*/
|
|
77
|
+
export declare function assertCircuitRelayTransport(node: Libp2p, relays: readonly SupervisedRelay[]): void;
|
|
78
|
+
/**
|
|
79
|
+
* Fail node creation, before anything is built, when a listen address names a relay but
|
|
80
|
+
* `announceAddrs` is set. libp2p advertises ONLY the announce set then (the readme's "replaces the
|
|
81
|
+
* advertised set entirely"), so the circuit address through the relay could never appear in
|
|
82
|
+
* `node.getMultiaddrs()`, nobody could learn it, and every supervisor drive would time out waiting
|
|
83
|
+
* for it: node creation would reject after a full drive deadline with a message about publishing
|
|
84
|
+
* rather than about the configuration. `appendAnnounceAddrs` keeps the listener addresses and is fine.
|
|
85
|
+
*/
|
|
86
|
+
export declare function assertRelayAddrsAdvertisable(relays: readonly SupervisedRelay[], announceAddrs: readonly string[] | undefined): void;
|
|
87
|
+
/**
|
|
88
|
+
* Forget that a relay ever failed a reservation request, so the next request is actually made
|
|
89
|
+
* rather than refused with "The relay was previously invalid".
|
|
90
|
+
*
|
|
91
|
+
* The store resets its filter when a reservation is removed while a pending slot exists, which a
|
|
92
|
+
* bare listener always has, so this is a belt-and-braces step: the poisoning path this guards is a
|
|
93
|
+
* failed request from libp2p's own relay discovery while the relay was down. Fails soft in every
|
|
94
|
+
* direction; returns whether an entry was actually removed (for specs).
|
|
95
|
+
*/
|
|
96
|
+
export declare function clearRelayFilterEntry(store: RelayReservationStoreLike, relayPeerId: PeerId): boolean;
|
|
97
|
+
/** Deadline for one drive: dial, reservation request and the wait for the address share it. */
|
|
98
|
+
export declare const DEFAULT_RELAY_DRIVE_TIMEOUT_MS = 10000;
|
|
99
|
+
/** Gap between liveness checks while the reservation is held; a fallback in case an event is missed. */
|
|
100
|
+
export declare const DEFAULT_RELAY_CHECK_MS = 5000;
|
|
101
|
+
/** Backoff before the first retry after a failed drive. */
|
|
102
|
+
export declare const DEFAULT_RELAY_MIN_BACKOFF_MS = 1000;
|
|
103
|
+
/**
|
|
104
|
+
* Backoff ceiling. It bounds recovery time after a long relay outage, because nothing else
|
|
105
|
+
* reconnects a lone phone to its relay; a WebSocket dial every 30 s during an outage is cheap.
|
|
106
|
+
*/
|
|
107
|
+
export declare const DEFAULT_RELAY_MAX_BACKOFF_MS = 30000;
|
|
108
|
+
/** How often a drive re-reads the address list while waiting for the address to be published. */
|
|
109
|
+
export declare const DEFAULT_RELAY_POLL_MS = 100;
|
|
110
|
+
export interface RelayReservationSupervisorOptions {
|
|
111
|
+
/** Default {@link DEFAULT_RELAY_DRIVE_TIMEOUT_MS}. */
|
|
112
|
+
driveTimeoutMs?: number;
|
|
113
|
+
/** Default {@link DEFAULT_RELAY_CHECK_MS}. */
|
|
114
|
+
checkMs?: number;
|
|
115
|
+
/** Default {@link DEFAULT_RELAY_MIN_BACKOFF_MS}. */
|
|
116
|
+
minBackoffMs?: number;
|
|
117
|
+
/** Default {@link DEFAULT_RELAY_MAX_BACKOFF_MS}. */
|
|
118
|
+
maxBackoffMs?: number;
|
|
119
|
+
/** Default {@link DEFAULT_RELAY_POLL_MS}. */
|
|
120
|
+
pollMs?: number;
|
|
121
|
+
}
|
|
122
|
+
/** A running supervisor for one node and one relay. Obtained from {@link superviseRelayReservation}. */
|
|
123
|
+
export interface RelayReservationSupervisor {
|
|
124
|
+
readonly relay: SupervisedRelay;
|
|
125
|
+
/**
|
|
126
|
+
* Settles once the first drive has: `null` when the reservation was held, otherwise the reason
|
|
127
|
+
* it was not. Also settles on {@link stop}, so an awaiting caller is never left hanging.
|
|
128
|
+
*/
|
|
129
|
+
readonly firstDrive: Promise<string | null>;
|
|
130
|
+
/** Whether the node currently advertises a circuit address through this relay. Read live. */
|
|
131
|
+
readonly held: boolean;
|
|
132
|
+
/** True while a drive is in flight. */
|
|
133
|
+
readonly driving: boolean;
|
|
134
|
+
/** Epoch ms of the next scheduled check or retry; `null` while driving or once stopped. */
|
|
135
|
+
readonly retryAtMs: number | null;
|
|
136
|
+
/** Reason the last drive produced no reservation; `null` once one is held. */
|
|
137
|
+
readonly lastError: string | null;
|
|
138
|
+
/**
|
|
139
|
+
* Idempotent. Clears the pending timer, removes both event listeners, aborts an in-flight dial,
|
|
140
|
+
* and discards the result of an in-flight reservation request without starting anything after it.
|
|
141
|
+
*/
|
|
142
|
+
stop(): void;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Keep asking `relay` for a reservation until one is held, then keep watching that it still is.
|
|
146
|
+
*
|
|
147
|
+
* Drives run on: the first tick, right away; libp2p's `self:peer:update` (the listener withdrew or
|
|
148
|
+
* added addresses); `peer:connect` for this relay (a dial by anything on this node reconnected it,
|
|
149
|
+
* which turns a partner's dial through the relay into an immediate re-reserve, and resets the
|
|
150
|
+
* backoff); a liveness poll every `checkMs` while held; and a doubling backoff from `minBackoffMs`
|
|
151
|
+
* to `maxBackoffMs` after a failed drive. Drives are serialized per relay: a trigger that arrives
|
|
152
|
+
* mid-drive does nothing by itself, because every drive ends with the same re-check and reschedule.
|
|
153
|
+
*
|
|
154
|
+
* `HadEnoughRelaysError` from the reservation store means this node's pending slot was already
|
|
155
|
+
* filled with a reservation on a different relay (libp2p's relay discovery, see the accepted
|
|
156
|
+
* tradeoff in `libp2p-node-base.ts`); it is logged once per episode and retried at the backoff cap, since it
|
|
157
|
+
* recovers on its own only if that other reservation drops.
|
|
158
|
+
*/
|
|
159
|
+
export declare function superviseRelayReservation(node: Libp2p, relay: SupervisedRelay, opts?: RelayReservationSupervisorOptions): RelayReservationSupervisor;
|
|
160
|
+
/** Every supervisor a node runs, with the two operations the node factory needs. */
|
|
161
|
+
export interface RelayReservationSupervisors {
|
|
162
|
+
readonly supervisors: readonly RelayReservationSupervisor[];
|
|
163
|
+
/** Resolves once every first drive held its reservation; rejects naming every relay that did not. */
|
|
164
|
+
awaitFirstDrives(): Promise<void>;
|
|
165
|
+
/** Stops every supervisor. Idempotent. */
|
|
166
|
+
stop(): void;
|
|
167
|
+
}
|
|
168
|
+
/** One {@link superviseRelayReservation} per relay, started immediately. */
|
|
169
|
+
export declare function superviseRelayReservations(node: Libp2p, relays: readonly SupervisedRelay[], opts?: RelayReservationSupervisorOptions): RelayReservationSupervisors;
|
|
170
|
+
//# sourceMappingURL=relay-reservation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay-reservation.d.ts","sourceRoot":"","sources":["../../../src/network/relay-reservation.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAMhD,iGAAiG;AACjG,eAAO,MAAM,0BAA0B,iBAAiB,CAAC;AAEzD,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC/B,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,6GAA6G;IAC7G,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,kHAAkH;AAClH,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,E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