@serfab/cadre-core 1.14.0 → 1.16.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 +293 -274
- package/dist/cadre-invite-protocol.d.ts +64 -29
- package/dist/cadre-invite-protocol.js +207 -38
- package/dist/cadre-invite-protocol.js.map +1 -1
- package/dist/cadre-join-request.d.ts +42 -0
- package/dist/cadre-join-request.js +144 -0
- package/dist/cadre-join-request.js.map +1 -0
- package/dist/cadre-node.d.ts +375 -79
- package/dist/cadre-node.js +758 -186
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-database.d.ts +92 -12
- package/dist/control-database.js +323 -142
- package/dist/control-database.js.map +1 -1
- package/dist/control-schema.d.ts +1 -1
- package/dist/control-schema.js +19 -3
- package/dist/control-schema.js.map +1 -1
- package/dist/ed25519-key.d.ts +7 -9
- package/dist/ed25519-key.js +20 -10
- package/dist/ed25519-key.js.map +1 -1
- package/dist/fetch-impl.d.ts +12 -0
- package/dist/fetch-impl.js +23 -0
- package/dist/fetch-impl.js.map +1 -0
- package/dist/file-durable-slot.js +2 -1
- package/dist/file-durable-slot.js.map +1 -1
- package/dist/file-safe-name.d.ts +25 -0
- package/dist/file-safe-name.js +29 -0
- package/dist/file-safe-name.js.map +1 -0
- package/dist/formation-approval.js +5 -11
- package/dist/formation-approval.js.map +1 -1
- package/dist/fs-atomic.d.ts +0 -19
- package/dist/fs-atomic.js +3 -24
- package/dist/fs-atomic.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.js +31 -6
- package/dist/index.js.map +1 -1
- package/dist/invitation-bootstrap.d.ts +50 -12
- package/dist/invitation-bootstrap.js +76 -13
- package/dist/invitation-bootstrap.js.map +1 -1
- package/dist/joined-strand-store.d.ts +7 -0
- package/dist/joined-strand-store.js +9 -0
- package/dist/joined-strand-store.js.map +1 -1
- package/dist/key-store-file.js +2 -1
- package/dist/key-store-file.js.map +1 -1
- package/dist/link-budget.d.ts +9 -4
- package/dist/link-budget.js +9 -4
- package/dist/link-budget.js.map +1 -1
- package/dist/machine-removal.d.ts +78 -0
- package/dist/machine-removal.js +166 -0
- package/dist/machine-removal.js.map +1 -0
- package/dist/membership-connection-gater.d.ts +6 -5
- package/dist/membership-connection-gater.js +6 -5
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/node-claim-payload.d.ts +55 -0
- package/dist/node-claim-payload.js +108 -4
- package/dist/node-claim-payload.js.map +1 -1
- package/dist/node-default-transports.d.ts +27 -0
- package/dist/node-default-transports.js +35 -0
- package/dist/node-default-transports.js.map +1 -0
- package/dist/node-transports.d.ts +30 -0
- package/dist/node-transports.js +40 -0
- package/dist/node-transports.js.map +1 -0
- package/dist/peer-dial.d.ts +124 -27
- package/dist/peer-dial.js +254 -30
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.js +6 -0
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/peer-record.d.ts +6 -45
- package/dist/peer-record.js +8 -50
- package/dist/peer-record.js.map +1 -1
- package/dist/primary-lan-address.d.ts +8 -0
- package/dist/primary-lan-address.js +46 -0
- package/dist/primary-lan-address.js.map +1 -0
- package/dist/provider/client.d.ts +131 -0
- package/dist/provider/client.js +226 -0
- package/dist/provider/client.js.map +1 -0
- package/dist/provider/descriptor.d.ts +41 -0
- package/dist/provider/descriptor.js +103 -0
- package/dist/provider/descriptor.js.map +1 -0
- package/dist/provider/index.d.ts +9 -0
- package/dist/provider/index.js +10 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/oauth.d.ts +125 -0
- package/dist/provider/oauth.js +199 -0
- package/dist/provider/oauth.js.map +1 -0
- package/dist/provider/rent-node.d.ts +101 -0
- package/dist/provider/rent-node.js +220 -0
- package/dist/provider/rent-node.js.map +1 -0
- package/dist/relay-addrs.d.ts +9 -4
- package/dist/relay-addrs.js +9 -4
- package/dist/relay-addrs.js.map +1 -1
- package/dist/relay-reservation.d.ts +51 -16
- package/dist/relay-reservation.js +107 -24
- package/dist/relay-reservation.js.map +1 -1
- package/dist/seed-bootstrap.d.ts +22 -5
- package/dist/seed-bootstrap.js +48 -25
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/strand-commit-durability.d.ts +54 -0
- package/dist/strand-commit-durability.js +74 -0
- package/dist/strand-commit-durability.js.map +1 -0
- package/dist/strand-database.d.ts +23 -8
- package/dist/strand-database.js +41 -13
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.d.ts +7 -1
- package/dist/strand-first-sync-gate.js +7 -1
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-protocol.js +4 -1
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-fret-addrs.d.ts +19 -1
- package/dist/strand-fret-addrs.js +27 -9
- package/dist/strand-fret-addrs.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +81 -19
- package/dist/strand-instance-manager.js +216 -105
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-move.d.ts +124 -0
- package/dist/strand-move.js +438 -0
- package/dist/strand-move.js.map +1 -0
- package/dist/strand-network-config.js +7 -6
- package/dist/strand-network-config.js.map +1 -1
- package/dist/strand-peer-redial.d.ts +113 -0
- package/dist/strand-peer-redial.js +236 -0
- package/dist/strand-peer-redial.js.map +1 -0
- package/dist/strand-wake-protocol.js +10 -7
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/types.d.ts +212 -4
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -1
- package/package.json +18 -10
- package/src/cadre-invite-protocol.ts +1052 -864
- package/src/cadre-join-request.ts +167 -0
- package/src/cadre-node.ts +10003 -9381
- package/src/control-database.ts +4663 -4451
- package/src/control-schema.ts +19 -3
- package/src/ed25519-key.ts +20 -10
- package/src/fetch-impl.ts +23 -0
- package/src/file-durable-slot.ts +64 -63
- package/src/file-safe-name.ts +32 -0
- package/src/formation-approval.ts +604 -610
- package/src/fs-atomic.ts +92 -117
- package/src/index.ts +71 -4
- package/src/invitation-bootstrap.ts +91 -13
- package/src/joined-strand-store.ts +508 -498
- package/src/key-store-file.ts +142 -141
- package/src/link-budget.ts +9 -4
- package/src/machine-removal.ts +216 -0
- package/src/membership-connection-gater.ts +638 -637
- package/src/node-claim-payload.ts +138 -4
- package/src/node-default-transports.ts +38 -0
- package/src/node-transports.ts +49 -0
- package/src/peer-dial.ts +604 -336
- package/src/peer-join-backfill.ts +6 -0
- package/src/peer-record.ts +159 -202
- package/src/primary-lan-address.ts +47 -0
- package/src/provider/client.ts +326 -0
- package/src/provider/descriptor.ts +129 -0
- package/src/provider/index.ts +59 -0
- package/src/provider/oauth.ts +285 -0
- package/src/provider/rent-node.ts +275 -0
- package/src/relay-addrs.ts +9 -4
- package/src/relay-reservation.ts +1211 -1121
- package/src/seed-bootstrap.ts +1502 -1471
- package/src/strand-commit-durability.ts +116 -0
- package/src/strand-database.ts +46 -14
- package/src/strand-first-sync-gate.ts +7 -1
- package/src/strand-formation-protocol.ts +1039 -1036
- package/src/strand-fret-addrs.ts +179 -145
- package/src/strand-instance-manager.ts +2026 -1883
- package/src/strand-move.ts +585 -0
- package/src/strand-network-config.ts +7 -6
- package/src/strand-peer-redial.ts +307 -0
- package/src/strand-wake-protocol.ts +10 -7
- package/src/types.ts +220 -4
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* `@libp2p/peer-id` and `uint8arrays`, so it loads on React Native and in the browser.
|
|
14
14
|
*/
|
|
15
15
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
16
|
-
import { multiaddr, CODE_P2P, CODE_P2P_CIRCUIT } from '@multiformats/multiaddr';
|
|
16
|
+
import { multiaddr, CODE_DNS, CODE_DNS4, CODE_DNS6, CODE_DNSADDR, CODE_IP4, CODE_IP6, CODE_IP6ZONE, CODE_P2P, CODE_P2P_CIRCUIT, CODE_WS, CODE_WSS, } from '@multiformats/multiaddr';
|
|
17
17
|
import { fromString as uint8ArrayFromString, toString as uint8ArrayToString } from 'uint8arrays';
|
|
18
18
|
import { canonicalJson } from './canonical-json.js';
|
|
19
19
|
import { parseClaimSecret } from './claim-proof.js';
|
|
@@ -57,6 +57,108 @@ export function decodeNodeClaimPayload(text) {
|
|
|
57
57
|
throw new Error('A claim payload must carry the claim secret');
|
|
58
58
|
return requireNodeClaimPayload({ peerId, multiaddrs, secret });
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The addresses a node code should carry, from the ones a node knows it has (`/status`,
|
|
62
|
+
* a NAT layer's public addresses). A phone dials them in turn, each on its own timeout, so
|
|
63
|
+
* every address it cannot reach only delays a failing claim, and makes the QR code bigger.
|
|
64
|
+
*
|
|
65
|
+
* - Each gains `/p2p/<peerId>` when it lacks a destination; loopback, unspecified and
|
|
66
|
+
* unparsable ones are dropped, and so is plain TCP unless `includeTcp`.
|
|
67
|
+
* - Public names (`/dns*`) come first: they work away from home. Public IP addresses are
|
|
68
|
+
* kept only when there is no public name, since they reach the same machine.
|
|
69
|
+
* - Private addresses follow, narrowed by {@link NodeClaimAddressOptions.lan}; relay
|
|
70
|
+
* addresses last.
|
|
71
|
+
*
|
|
72
|
+
* Pure and dependency-light, like the codec beside it, so it loads on React Native too.
|
|
73
|
+
* Finding the LAN address is the caller's (Node: `@serfab/cadre-core/primary-lan-address`).
|
|
74
|
+
*/
|
|
75
|
+
export function selectNodeClaimAddresses(reported, peerId, options = {}) {
|
|
76
|
+
const names = [];
|
|
77
|
+
const publicIps = [];
|
|
78
|
+
const privates = [];
|
|
79
|
+
const relayed = [];
|
|
80
|
+
for (const raw of reported) {
|
|
81
|
+
const classified = classifyClaimAddress(raw.trim(), peerId, options);
|
|
82
|
+
if (!classified)
|
|
83
|
+
continue;
|
|
84
|
+
({ name: names, public: publicIps, private: privates, relay: relayed })[classified.kind].push(classified.addr);
|
|
85
|
+
}
|
|
86
|
+
return [...new Set([...names, ...(names.length > 0 ? [] : publicIps), ...privates, ...relayed])];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* `addr` as a node code carries it: with `/p2p/<peerId>` appended unless it already names a
|
|
90
|
+
* destination. A relay address that ends at its hop (`…/p2p/<relay>/p2p-circuit`) names none,
|
|
91
|
+
* so it gains the node's id too. Throws when `addr` does not parse. For callers that take
|
|
92
|
+
* exact addresses from an operator; {@link selectNodeClaimAddresses} applies it itself.
|
|
93
|
+
*/
|
|
94
|
+
export function withClaimDestination(addr, peerId) {
|
|
95
|
+
const trimmed = addr.trim();
|
|
96
|
+
return destinationPeerIdOf(trimmed) === null ? `${trimmed}/p2p/${peerId}` : trimmed;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Classify `addr` for a phone dialing it, or undefined when no phone can dial it at all: it
|
|
100
|
+
* does not parse, names the unspecified address, or is plain TCP without `includeTcp` (phones
|
|
101
|
+
* dial WebSocket and relay only).
|
|
102
|
+
*/
|
|
103
|
+
export function classifyDialAddress(addr, options = {}) {
|
|
104
|
+
const components = componentsOf(addr);
|
|
105
|
+
return components ? classifyComponents(components, options.includeTcp ?? false)?.kind : undefined;
|
|
106
|
+
}
|
|
107
|
+
function componentsOf(addr) {
|
|
108
|
+
try {
|
|
109
|
+
return multiaddr(addr).getComponents();
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** {@link classifyDialAddress}, keeping the IP for a caller that narrows private addresses by it. */
|
|
116
|
+
function classifyComponents(components, includeTcp) {
|
|
117
|
+
if (components.some((c) => c.code === CODE_P2P_CIRCUIT))
|
|
118
|
+
return { kind: 'relay' };
|
|
119
|
+
if (!includeTcp && !components.some((c) => c.code === CODE_WS || c.code === CODE_WSS))
|
|
120
|
+
return undefined;
|
|
121
|
+
const host = components[0];
|
|
122
|
+
if (!host?.value)
|
|
123
|
+
return undefined;
|
|
124
|
+
if (host.code === CODE_DNS || host.code === CODE_DNS4 || host.code === CODE_DNS6 || host.code === CODE_DNSADDR) {
|
|
125
|
+
return { kind: host.value === 'localhost' ? 'loopback' : 'name' };
|
|
126
|
+
}
|
|
127
|
+
if (host.code !== CODE_IP4 && host.code !== CODE_IP6 && host.code !== CODE_IP6ZONE)
|
|
128
|
+
return undefined;
|
|
129
|
+
const ip = host.code === CODE_IP6ZONE ? components[1]?.value ?? '' : host.value;
|
|
130
|
+
if (ip === '0.0.0.0' || ip === '::')
|
|
131
|
+
return undefined;
|
|
132
|
+
if (ip.startsWith('127.') || ip === '::1')
|
|
133
|
+
return { kind: 'loopback', ip };
|
|
134
|
+
if (host.code !== CODE_IP6ZONE && !isPrivateIp(ip))
|
|
135
|
+
return { kind: 'public', ip };
|
|
136
|
+
return { kind: 'private', ip };
|
|
137
|
+
}
|
|
138
|
+
/** One address's place in {@link selectNodeClaimAddresses}, or undefined to drop it. */
|
|
139
|
+
function classifyClaimAddress(addr, peerId, options) {
|
|
140
|
+
const components = componentsOf(addr);
|
|
141
|
+
if (!components)
|
|
142
|
+
return undefined;
|
|
143
|
+
const classified = classifyComponents(components, options.includeTcp ?? false);
|
|
144
|
+
if (!classified || classified.kind === 'loopback')
|
|
145
|
+
return undefined;
|
|
146
|
+
if (classified.kind === 'private' && (options.lan === null || (options.lan !== undefined && classified.ip !== options.lan))) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
return { kind: classified.kind, addr: destinationIn(components) === null ? `${addr}/p2p/${peerId}` : addr };
|
|
150
|
+
}
|
|
151
|
+
/** RFC 1918, carrier-grade NAT (100.64/10), link-local, and IPv6 unique-local / link-local. */
|
|
152
|
+
function isPrivateIp(ip) {
|
|
153
|
+
if (ip.includes(':'))
|
|
154
|
+
return /^(f[cd]|fe[89ab])/i.test(ip);
|
|
155
|
+
const [a, b] = ip.split('.').map(Number);
|
|
156
|
+
return a === 10
|
|
157
|
+
|| (a === 172 && b >= 16 && b <= 31)
|
|
158
|
+
|| (a === 192 && b === 168)
|
|
159
|
+
|| (a === 169 && b === 254)
|
|
160
|
+
|| (a === 100 && b >= 64 && b <= 127);
|
|
161
|
+
}
|
|
60
162
|
/** The shape rules both directions apply. Returns the payload with its fields trimmed. */
|
|
61
163
|
function requireNodeClaimPayload(payload) {
|
|
62
164
|
const peerId = parsePeerId(payload.peerId);
|
|
@@ -104,10 +206,12 @@ function requireAddressOf(addr, peerId) {
|
|
|
104
206
|
* The peer an address reaches: its last `/p2p/` component. A relayed address
|
|
105
207
|
* (`…/p2p/<relay>/p2p-circuit/p2p/<destination>`) names its destination after the
|
|
106
208
|
* circuit hop; one that ends at the hop names nobody. Same rule as
|
|
107
|
-
* `groupAddrsByPeerId` in `peer-addr-book.ts`.
|
|
209
|
+
* `groupAddrsByPeerId` in `peer-addr-book.ts`. Throws when `addr` does not parse.
|
|
108
210
|
*/
|
|
109
|
-
function destinationPeerIdOf(addr) {
|
|
110
|
-
|
|
211
|
+
export function destinationPeerIdOf(addr) {
|
|
212
|
+
return destinationIn(multiaddr(addr).getComponents());
|
|
213
|
+
}
|
|
214
|
+
function destinationIn(components) {
|
|
111
215
|
for (let i = components.length - 1; i >= 0; i--) {
|
|
112
216
|
const component = components[i];
|
|
113
217
|
if (component.code === CODE_P2P_CIRCUIT)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-claim-payload.js","sourceRoot":"","sources":["../src/node-claim-payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"node-claim-payload.js","sourceRoot":"","sources":["../src/node-claim-payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACN,SAAS,EACT,QAAQ,EACR,SAAS,EACT,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,OAAO,EACP,QAAQ,GACR,MAAM,yBAAyB,CAA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AAC;AACvD,CAAC;AAED,SAAS,aAAa,CAAC,UAA6B;IACnD,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACjD,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAE,CAAC;QACjC,IAAI,SAAS,CAAC,IAAI,KAAK,gBAAgB;YAAE,OAAO,IAAI,CAAC;QACrD,IAAI,SAAS,CAAC,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC,KAAK,CAAC;IAC5E,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-only: `@optimystic/db-p2p`'s default transport list, for `NetworkConfig.defaultTransports`.
|
|
3
|
+
*
|
|
4
|
+
* A node with configured relays is built from an explicit transport list, so that libp2p's relay
|
|
5
|
+
* discovery can be switched off in it (`node-transports.ts`). A Node host that supplies no
|
|
6
|
+
* `network.transports` passes this function so that list still matches what db-p2p would have
|
|
7
|
+
* built. A subpath module (`@serfab/cadre-core/node-default-transports`), like `push-node`,
|
|
8
|
+
* because it names `@libp2p/tcp`: some bundlers (the NativeScript reference app's webpack) take
|
|
9
|
+
* its Node implementation rather than its browser stub, and that needs `net`, `os` and `path`.
|
|
10
|
+
*/
|
|
11
|
+
import type { Libp2pTransports } from '@optimystic/db-p2p';
|
|
12
|
+
import type { ListenTransportOptions } from './relay-addrs.js';
|
|
13
|
+
/**
|
|
14
|
+
* TCP, WebSocket exactly when the node's listen entries switch it on, and the circuit-relay
|
|
15
|
+
* transport.
|
|
16
|
+
*
|
|
17
|
+
* Passing an explicit list makes db-p2p ignore `wsPort` for transports, which is why WebSocket is
|
|
18
|
+
* decided here from the same switch. Its other use of `wsPort`, a default WebSocket listen
|
|
19
|
+
* address, never applies: a node with configured relays always has explicit listen entries.
|
|
20
|
+
*
|
|
21
|
+
* NOTE: mirrors `createLibp2pNode`'s default list in
|
|
22
|
+
* `../optimystic/packages/db-p2p/src/libp2p-node.ts` (cadre never sets its `disableTcp`). That file
|
|
23
|
+
* is the source of truth; if its defaults change, this list has to follow. If db-p2p ever takes an
|
|
24
|
+
* option to build its default list with relay discovery off, use that and drop this module and
|
|
25
|
+
* `NetworkConfig.defaultTransports`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function nodeDefaultTransports({ wsPort }: ListenTransportOptions): Libp2pTransports;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-only: `@optimystic/db-p2p`'s default transport list, for `NetworkConfig.defaultTransports`.
|
|
3
|
+
*
|
|
4
|
+
* A node with configured relays is built from an explicit transport list, so that libp2p's relay
|
|
5
|
+
* discovery can be switched off in it (`node-transports.ts`). A Node host that supplies no
|
|
6
|
+
* `network.transports` passes this function so that list still matches what db-p2p would have
|
|
7
|
+
* built. A subpath module (`@serfab/cadre-core/node-default-transports`), like `push-node`,
|
|
8
|
+
* because it names `@libp2p/tcp`: some bundlers (the NativeScript reference app's webpack) take
|
|
9
|
+
* its Node implementation rather than its browser stub, and that needs `net`, `os` and `path`.
|
|
10
|
+
*/
|
|
11
|
+
import { tcp } from '@libp2p/tcp';
|
|
12
|
+
import { webSockets } from '@libp2p/websockets';
|
|
13
|
+
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
14
|
+
/**
|
|
15
|
+
* TCP, WebSocket exactly when the node's listen entries switch it on, and the circuit-relay
|
|
16
|
+
* transport.
|
|
17
|
+
*
|
|
18
|
+
* Passing an explicit list makes db-p2p ignore `wsPort` for transports, which is why WebSocket is
|
|
19
|
+
* decided here from the same switch. Its other use of `wsPort`, a default WebSocket listen
|
|
20
|
+
* address, never applies: a node with configured relays always has explicit listen entries.
|
|
21
|
+
*
|
|
22
|
+
* NOTE: mirrors `createLibp2pNode`'s default list in
|
|
23
|
+
* `../optimystic/packages/db-p2p/src/libp2p-node.ts` (cadre never sets its `disableTcp`). That file
|
|
24
|
+
* is the source of truth; if its defaults change, this list has to follow. If db-p2p ever takes an
|
|
25
|
+
* option to build its default list with relay discovery off, use that and drop this module and
|
|
26
|
+
* `NetworkConfig.defaultTransports`.
|
|
27
|
+
*/
|
|
28
|
+
export function nodeDefaultTransports({ wsPort }) {
|
|
29
|
+
return [
|
|
30
|
+
tcp(),
|
|
31
|
+
...(wsPort === undefined ? [] : [webSockets()]),
|
|
32
|
+
circuitRelayTransport()
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=node-default-transports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-default-transports.js","sourceRoot":"","sources":["../src/node-default-transports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAIjE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAE,MAAM,EAA0B;IACtE,OAAO;QACL,GAAG,EAAE;QACL,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;QAC/C,qBAAqB,EAAE;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `transports` option for a cadre-built libp2p node, control and strand alike.
|
|
3
|
+
*
|
|
4
|
+
* A node whose bare `/p2p-circuit` search entries cadre generated for configured relays gets its
|
|
5
|
+
* transports through {@link withoutRelayDiscovery}, so libp2p's relay discovery cannot hand those
|
|
6
|
+
* slots to some other relay-capable peer before the per-relay supervisors fill them (see
|
|
7
|
+
* `relay-reservation.ts`, "WHY LIBP2P'S RELAY DISCOVERY IS SWITCHED OFF"). Every other node gets
|
|
8
|
+
* the embedder's list as it was, or no option at all, and `@optimystic/db-p2p` builds its own
|
|
9
|
+
* default list.
|
|
10
|
+
*
|
|
11
|
+
* The wrapper needs a list to wrap. React Native and browser embedders always supply one
|
|
12
|
+
* (`network.transports`); a Node host supplies the default list through
|
|
13
|
+
* `network.defaultTransports` instead, since db-p2p builds its default internally and it names
|
|
14
|
+
* `@libp2p/tcp`, which this module's graph must not reach (`node-default-transports.ts`).
|
|
15
|
+
*/
|
|
16
|
+
import type { Libp2pTransports } from '@optimystic/db-p2p';
|
|
17
|
+
import type { ListenTransportOptions } from './relay-addrs.js';
|
|
18
|
+
import type { NetworkConfig } from './types.js';
|
|
19
|
+
/**
|
|
20
|
+
* The `transports` option to spread into a node's `createLibp2pNode` options.
|
|
21
|
+
*
|
|
22
|
+
* @param listenTransports what the node's resolved listen entries imply (`resolveTransportOptions`
|
|
23
|
+
* in `relay-addrs.ts`), handed to `network.defaultTransports`.
|
|
24
|
+
* @param relaySlotsSupervised whether cadre generated this node's bare `/p2p-circuit` entries for
|
|
25
|
+
* configured relays and runs a supervisor over them — `network.relayAddrs` on the control node,
|
|
26
|
+
* a non-empty relay list from `strandNodeAddrs` on a strand node.
|
|
27
|
+
*/
|
|
28
|
+
export declare function nodeTransportsOption(network: NetworkConfig | undefined, listenTransports: ListenTransportOptions, relaySlotsSupervised: boolean): {
|
|
29
|
+
transports?: Libp2pTransports;
|
|
30
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `transports` option for a cadre-built libp2p node, control and strand alike.
|
|
3
|
+
*
|
|
4
|
+
* A node whose bare `/p2p-circuit` search entries cadre generated for configured relays gets its
|
|
5
|
+
* transports through {@link withoutRelayDiscovery}, so libp2p's relay discovery cannot hand those
|
|
6
|
+
* slots to some other relay-capable peer before the per-relay supervisors fill them (see
|
|
7
|
+
* `relay-reservation.ts`, "WHY LIBP2P'S RELAY DISCOVERY IS SWITCHED OFF"). Every other node gets
|
|
8
|
+
* the embedder's list as it was, or no option at all, and `@optimystic/db-p2p` builds its own
|
|
9
|
+
* default list.
|
|
10
|
+
*
|
|
11
|
+
* The wrapper needs a list to wrap. React Native and browser embedders always supply one
|
|
12
|
+
* (`network.transports`); a Node host supplies the default list through
|
|
13
|
+
* `network.defaultTransports` instead, since db-p2p builds its default internally and it names
|
|
14
|
+
* `@libp2p/tcp`, which this module's graph must not reach (`node-default-transports.ts`).
|
|
15
|
+
*/
|
|
16
|
+
import debug from 'debug';
|
|
17
|
+
import { withoutRelayDiscovery } from './relay-reservation.js';
|
|
18
|
+
const log = debug('sereus:cadre:node-transports');
|
|
19
|
+
/**
|
|
20
|
+
* The `transports` option to spread into a node's `createLibp2pNode` options.
|
|
21
|
+
*
|
|
22
|
+
* @param listenTransports what the node's resolved listen entries imply (`resolveTransportOptions`
|
|
23
|
+
* in `relay-addrs.ts`), handed to `network.defaultTransports`.
|
|
24
|
+
* @param relaySlotsSupervised whether cadre generated this node's bare `/p2p-circuit` entries for
|
|
25
|
+
* configured relays and runs a supervisor over them — `network.relayAddrs` on the control node,
|
|
26
|
+
* a non-empty relay list from `strandNodeAddrs` on a strand node.
|
|
27
|
+
*/
|
|
28
|
+
export function nodeTransportsOption(network, listenTransports, relaySlotsSupervised) {
|
|
29
|
+
if (!relaySlotsSupervised) {
|
|
30
|
+
return network?.transports ? { transports: network.transports } : {};
|
|
31
|
+
}
|
|
32
|
+
const transports = network?.transports ?? network?.defaultTransports?.(listenTransports);
|
|
33
|
+
if (transports === undefined) {
|
|
34
|
+
log('Relays are configured but no transport list was supplied (network.transports or ' +
|
|
35
|
+
'network.defaultTransports); libp2p relay discovery stays on and can take their slots');
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
return { transports: withoutRelayDiscovery(transports) };
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=node-transports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-transports.js","sourceRoot":"","sources":["../src/node-transports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAI/D,MAAM,GAAG,GAAG,KAAK,CAAC,8BAA8B,CAAC,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAkC,EAClC,gBAAwC,EACxC,oBAA6B;IAE7B,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,OAAO,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACvE,CAAC;IACD,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,EAAE,CAAC,gBAAgB,CAAC,CAAC;IACzF,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,GAAG,CAAC,kFAAkF;YACpF,sFAAsF,CAAC,CAAC;QAC1F,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,qBAAqB,CAAC,UAAU,CAAC,EAAE,CAAC;AAC3D,CAAC"}
|
package/dist/peer-dial.d.ts
CHANGED
|
@@ -16,17 +16,60 @@
|
|
|
16
16
|
* borrowing a node from a cadre-host whose only reachable address was the
|
|
17
17
|
* forwarded loopback one never connected for this reason.
|
|
18
18
|
*
|
|
19
|
-
* So the addresses are dialed here, each as its own
|
|
20
|
-
*
|
|
21
|
-
* ({@link PeerDialBudget.totalMs}). One address
|
|
22
|
-
* sorter has nothing to reorder, so the order is
|
|
23
|
-
* ({@link directBeforeRelayed}).
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
19
|
+
* So the addresses are dialed here, each as its own transport-manager dial
|
|
20
|
+
* ({@link dialAddr}) with its own time limit ({@link PeerDialBudget.perAddressMs}),
|
|
21
|
+
* inside a limit for the whole peer ({@link PeerDialBudget.totalMs}). One address
|
|
22
|
+
* per call also means libp2p's sorter has nothing to reorder, so the order is
|
|
23
|
+
* chosen here ({@link directBeforeRelayed}). The dial goes around libp2p's dial
|
|
24
|
+
* queue because the queue joins any dial of a peer to a queued job for that peer
|
|
25
|
+
* id, whatever address the new dial names — see {@link dialAddr}. Every address
|
|
26
|
+
* is bound to the peer the caller expects ({@link withTrailingPeerId}) so the
|
|
27
|
+
* handshake verifies who answered.
|
|
28
|
+
*
|
|
29
|
+
* Dependency-free apart from `control-stream.ts` and `link-budget.ts`, so any
|
|
30
|
+
* module may import it without creating an import cycle. That is why the two
|
|
31
|
+
* address helpers ({@link trailingPeerId}, {@link withTrailingPeerId}) live here
|
|
32
|
+
* rather than in `peer-record.ts`, which pulls in the crypto plugin.
|
|
27
33
|
*/
|
|
28
|
-
import type { Connection, PeerId } from '@libp2p/interface';
|
|
34
|
+
import type { Connection, Libp2pStatus, PeerId } from '@libp2p/interface';
|
|
29
35
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
36
|
+
/**
|
|
37
|
+
* The peer id a multiaddr terminates in, or `null` when it names none.
|
|
38
|
+
*
|
|
39
|
+
* The LAST `/p2p/` component is the dial target: a circuit address
|
|
40
|
+
* (`…/p2p/<relay>/p2p-circuit/p2p/<target>`) names the relay first and the peer
|
|
41
|
+
* being reached last. Replaces the deprecated `Multiaddr.getPeerId()`, which
|
|
42
|
+
* cannot express that distinction.
|
|
43
|
+
*/
|
|
44
|
+
export declare function trailingPeerId(addr: Multiaddr): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* `addr` guaranteed to terminate in `/p2p/<peerId>` — the shape every dial needs,
|
|
47
|
+
* since the upgrader verifies that id during the handshake — or `null` when it
|
|
48
|
+
* cannot, because the address already terminates in a DIFFERENT peer id and
|
|
49
|
+
* therefore does not reach `peerId` at all.
|
|
50
|
+
*
|
|
51
|
+
* Three input shapes, matching what a `CadrePeer` record can legitimately carry:
|
|
52
|
+
*
|
|
53
|
+
* - no `/p2p/` component (`/ip4/1.2.3.4/tcp/4001`) — the suffix is appended;
|
|
54
|
+
* - a relay hop with the destination missing (`…/p2p/<relay>/p2p-circuit`) — the
|
|
55
|
+
* last component is the circuit, not a peer id, so the suffix is appended and
|
|
56
|
+
* the address becomes the full `…/p2p/<relay>/p2p-circuit/p2p/<peerId>`;
|
|
57
|
+
* - already terminating in `/p2p/<X>` — returned untouched when `X` is `peerId`,
|
|
58
|
+
* dropped otherwise.
|
|
59
|
+
*
|
|
60
|
+
* This is deliberately the same rule libp2p applies internally in
|
|
61
|
+
* `calculateMultiaddrs` (append when the LAST component is not `p2p`) followed by
|
|
62
|
+
* its wrong-peer-id filter, so a normalized list matches what libp2p would have
|
|
63
|
+
* built anyway. Normalizing before a list dial is what keeps a list from mixing
|
|
64
|
+
* suffixed and unsuffixed entries, which `getPeerAddress` rejects outright
|
|
65
|
+
* ("Multiaddrs must all have the same peer id or have no peer id") — taking the
|
|
66
|
+
* whole peer down with it, not just the odd address.
|
|
67
|
+
*
|
|
68
|
+
* Throws when `peerId` does not parse as a peer id (the encapsulation validates
|
|
69
|
+
* it). Never use before signature verification: verification runs against the
|
|
70
|
+
* original on-record strings.
|
|
71
|
+
*/
|
|
72
|
+
export declare function withTrailingPeerId(addr: Multiaddr, peerId: string): Multiaddr | null;
|
|
30
73
|
/**
|
|
31
74
|
* Default limit on ONE address's dial attempt, in ms, at the DEFAULT declared link round trip:
|
|
32
75
|
* `RELAYED_DIAL_ROUND_TRIPS` (5) x `DECLARED_LINK_ROUND_TRIP_MS` (3500 ms) plus
|
|
@@ -103,14 +146,60 @@ export interface PeerDialBudget {
|
|
|
103
146
|
}
|
|
104
147
|
/** {@link PeerDialBudget} built from the two defaults above. */
|
|
105
148
|
export declare const DEFAULT_PEER_DIAL_BUDGET: Readonly<PeerDialBudget>;
|
|
149
|
+
/** What {@link dialAddr} reads of a connection the node holds, to decide whether to hand it back instead of dialing. */
|
|
150
|
+
export interface ReusableConnection {
|
|
151
|
+
remotePeer: {
|
|
152
|
+
toString(): string;
|
|
153
|
+
};
|
|
154
|
+
status?: Connection['status'];
|
|
155
|
+
limits?: Connection['limits'];
|
|
156
|
+
/** Whether the connection is direct rather than relayed; absent counts as direct. */
|
|
157
|
+
direct?: boolean;
|
|
158
|
+
}
|
|
106
159
|
/** The slice of a libp2p node {@link dialPeerAddrs} uses. */
|
|
107
160
|
export interface AddrDialer {
|
|
108
161
|
/** This node's id, to recognise an address that relays through this node ({@link relaysThrough}). */
|
|
109
162
|
readonly peerId: PeerId;
|
|
163
|
+
/** libp2p's lifecycle state: {@link dialAddr} refuses to start an attempt once it is not `started`. */
|
|
164
|
+
readonly status?: Libp2pStatus;
|
|
165
|
+
/**
|
|
166
|
+
* The connections this node holds to `peerId`. {@link dialAddr} returns an open one without relay
|
|
167
|
+
* limits rather than opening a second — what libp2p's dial queue did (`findExistingConnection`)
|
|
168
|
+
* and the transport manager does not. Optional so a double need not provide it, and typed by
|
|
169
|
+
* what is read of each connection so the strand redial's node slice (bare `remotePeer`s, which
|
|
170
|
+
* never count as open) satisfies it without a cast.
|
|
171
|
+
*/
|
|
172
|
+
getConnections?(peerId?: PeerId): ReadonlyArray<ReusableConnection>;
|
|
110
173
|
dial(addr: Multiaddr, options: {
|
|
111
174
|
signal: AbortSignal;
|
|
112
175
|
}): Promise<Connection>;
|
|
113
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Dial ONE address outside libp2p's dial queue. The queue joins any new dial to a queued job
|
|
179
|
+
* for the same peer id, whatever address the new dial names, and a joined job ends only when
|
|
180
|
+
* every caller has aborted — so while another caller dials this peer (FRET's membership probe,
|
|
181
|
+
* an Optimystic cluster client), a per-address attempt through the queue waits on whatever
|
|
182
|
+
* address that job is on instead of its own. The transport manager dials exactly the address
|
|
183
|
+
* given; the two gater hooks the queue would have consulted are run here, and the upgrader
|
|
184
|
+
* still runs `denyOutboundConnection` and verifies the peer id the address carries during the
|
|
185
|
+
* Noise handshake, so the address must carry the id of the peer expected to answer
|
|
186
|
+
* ({@link withTrailingPeerId}). An open connection to that peer without relay limits is handed
|
|
187
|
+
* back instead of dialing ({@link reusableConnection}), as the queue would have. A relayed
|
|
188
|
+
* address still passes through the queue for its relay leg (the circuit transport dials the
|
|
189
|
+
* relay by peer id).
|
|
190
|
+
*
|
|
191
|
+
* The queue would also have aborted the attempt at shutdown; here the node's `status` is
|
|
192
|
+
* checked before dialing and its `stop` event aborts an attempt in flight. Without
|
|
193
|
+
* `transportManager.dial` (libp2p internals moved) the attempt goes through the queue, logged.
|
|
194
|
+
*
|
|
195
|
+
* What else the queue did that this does not: record the outcome in the peer store
|
|
196
|
+
* (`LAST_DIAL_SUCCESS_KEY` / `LAST_DIAL_FAILURE_KEY`, read only by libp2p's own address sorter,
|
|
197
|
+
* which these dials do not use); apply `maxParallelDials` and `maxDialQueueLength`; and refuse
|
|
198
|
+
* a dial of this node's own id before touching the network — the upgrader still throws
|
|
199
|
+
* `Can not dial self` after the handshake, `dialPeerAddrs` drops addresses relaying through this
|
|
200
|
+
* node, `applySeed` skips itself, and the reconcile pass never lists itself.
|
|
201
|
+
*/
|
|
202
|
+
export declare function dialAddr(dialer: AddrDialer, addr: Multiaddr, signal: AbortSignal, label: string): Promise<Connection>;
|
|
114
203
|
/**
|
|
115
204
|
* Thrown by {@link dialPeerAddrs} when it was given addresses but every one reaches the peer by
|
|
116
205
|
* relaying through this node, so none was dialed.
|
|
@@ -138,25 +227,33 @@ export declare class PeerUnreachableError extends Error {
|
|
|
138
227
|
constructor(peerId: string, cause: unknown);
|
|
139
228
|
}
|
|
140
229
|
/**
|
|
141
|
-
* Dial
|
|
230
|
+
* Dial `peerId` from `addrs`, one address per {@link dialAddr} call, and return the
|
|
142
231
|
* first connection that forms. Direct addresses are tried before relayed ones
|
|
143
232
|
* ({@link directBeforeRelayed}); otherwise the given order is kept.
|
|
144
233
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
234
|
+
* Every address is first bound to `peerId` ({@link withTrailingPeerId}), so the
|
|
235
|
+
* handshake verifies that the peer expected is the one that answered; an address
|
|
236
|
+
* naming another peer is dropped and logged. When that leaves nothing of a
|
|
237
|
+
* non-empty list — every address names someone else, or `peerId` does not parse —
|
|
238
|
+
* this throws without dialing.
|
|
239
|
+
*
|
|
240
|
+
* Addresses that relay through this node are dropped next ({@link relaysThrough}):
|
|
241
|
+
* dialing one could only fail with `Can not dial self`. When that leaves nothing,
|
|
242
|
+
* this throws {@link SelfRelayOnlyError} without dialing.
|
|
148
243
|
*
|
|
149
|
-
* Addresses naming a transport this node lacks are not filtered out first:
|
|
150
|
-
*
|
|
244
|
+
* Addresses naming a transport this node lacks are not filtered out first: the
|
|
245
|
+
* transport manager rejects those at once (`TransportUnavailableError`), so they
|
|
151
246
|
* cost a log line, not time.
|
|
152
247
|
*
|
|
153
248
|
* Otherwise throws when no address connects — see {@link tryAddrsInTurn} for the error.
|
|
154
249
|
*
|
|
250
|
+
* @param peerId The peer every address must reach, as every caller already holds it
|
|
251
|
+
* (a `CadrePeer` row key, a seed peer's id, a strand member's id).
|
|
155
252
|
* @param label Names the dial in timeout messages and logs, e.g.
|
|
156
253
|
* `reconcileControlCohort dial of sibling <peerId>`; each attempt reads
|
|
157
254
|
* `<label> via <addr>`.
|
|
158
255
|
*/
|
|
159
|
-
export declare function dialPeerAddrs(dialer: AddrDialer, addrs: readonly Multiaddr[], budget: PeerDialBudget, label: string): Promise<Connection>;
|
|
256
|
+
export declare function dialPeerAddrs(dialer: AddrDialer, peerId: string, addrs: readonly Multiaddr[], budget: PeerDialBudget, label: string): Promise<Connection>;
|
|
160
257
|
/**
|
|
161
258
|
* Run `attempt` against each address in the given order until one succeeds, and
|
|
162
259
|
* return its result.
|
|
@@ -171,17 +268,17 @@ export declare function dialPeerAddrs(dialer: AddrDialer, addrs: readonly Multia
|
|
|
171
268
|
* failed, in order, with the first failure as `cause` — so the report shows the
|
|
172
269
|
* address that mattered, not only whichever happened to be tried last.
|
|
173
270
|
*
|
|
174
|
-
* Between attempts this waits for one macrotask (`setTimeout(0)`).
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* queue's
|
|
184
|
-
*
|
|
271
|
+
* Between attempts this waits for one macrotask (`setTimeout(0)`). A direct
|
|
272
|
+
* address is dialed outside libp2p's dial queue ({@link dialAddr}), but a relayed
|
|
273
|
+
* address still passes through it for the relay leg, and the queue lets a new
|
|
274
|
+
* dial join any queued job for the same peer id WITHOUT checking whether that
|
|
275
|
+
* job has already finished: an aborted job leaves the queue a few microtasks
|
|
276
|
+
* after its callers are rejected, so a next attempt through the same relay made
|
|
277
|
+
* at once would join the dying job and be rejected with `AbortError` before it
|
|
278
|
+
* touches the network. All of the queue's cleanup runs as microtasks, so it has
|
|
279
|
+
* finished by the time a macrotask runs. Seen against libp2p 3.1.3, and the
|
|
280
|
+
* queue's join is unchanged in 3.3.11; `test/peer-dial.spec.ts` dials real nodes
|
|
281
|
+
* so an upgrade that changes it shows up there.
|
|
185
282
|
*/
|
|
186
283
|
export declare function tryAddrsInTurn<T>(addrs: readonly Multiaddr[], budget: PeerDialBudget, label: string, attempt: (addr: Multiaddr, signal: AbortSignal, attemptMs: number) => Promise<T>): Promise<T>;
|
|
187
284
|
/**
|