peerbit 4.4.19 → 5.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/libp2p.d.ts +3 -2
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +20 -13
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer.d.ts +14 -1
- package/dist/src/peer.d.ts.map +1 -1
- package/dist/src/peer.js +334 -26
- package/dist/src/peer.js.map +1 -1
- package/package.json +13 -13
- package/src/libp2p.ts +22 -14
- package/src/peer.ts +407 -35
package/dist/src/libp2p.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { CircuitRelayService } from "@libp2p/circuit-relay-v2";
|
|
2
2
|
import { DirectBlock } from "@peerbit/blocks";
|
|
3
3
|
import { type IPeerbitKeychain } from "@peerbit/keychain";
|
|
4
|
-
import {
|
|
4
|
+
import { FanoutTree, TopicControlPlane } from "@peerbit/pubsub";
|
|
5
5
|
import { type Libp2p, type Libp2pOptions, type ServiceFactoryMap } from "libp2p";
|
|
6
6
|
export type Libp2pExtendServices = {
|
|
7
|
-
pubsub:
|
|
7
|
+
pubsub: TopicControlPlane;
|
|
8
|
+
fanout: FanoutTree;
|
|
8
9
|
blocks: DirectBlock;
|
|
9
10
|
keychain: IPeerbitKeychain;
|
|
10
11
|
};
|
package/dist/src/libp2p.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,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libp2p-yamux";
|
|
3
3
|
import { identify } from "@libp2p/identify";
|
|
4
4
|
import { DirectBlock } from "@peerbit/blocks";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { keychain, } from "@peerbit/keychain";
|
|
6
|
+
import { FanoutTree, TopicControlPlane, TopicRootControlPlane } from "@peerbit/pubsub";
|
|
7
7
|
import { createLibp2p, } from "libp2p";
|
|
8
8
|
import { listen, relay, transports } from "./transports.js";
|
|
9
|
-
export const createLibp2pExtended = (opts = {
|
|
10
|
-
|
|
11
|
-
blocks: (c) => new DirectBlock(c),
|
|
12
|
-
pubsub: (c) => new DirectSub(c),
|
|
13
|
-
keychain: keychain(),
|
|
14
|
-
},
|
|
15
|
-
}) => {
|
|
9
|
+
export const createLibp2pExtended = (opts = {}) => {
|
|
10
|
+
const topicRootControlPlane = new TopicRootControlPlane();
|
|
16
11
|
let extraServices = {};
|
|
12
|
+
let fanoutInstance;
|
|
13
|
+
const configuredFanoutFactory = opts.services?.fanout ||
|
|
14
|
+
((c) => new FanoutTree(c, { connectionManager: false, topicRootControlPlane }));
|
|
15
|
+
const getOrCreateFanout = (c) => {
|
|
16
|
+
if (!fanoutInstance) {
|
|
17
|
+
fanoutInstance = configuredFanoutFactory(c);
|
|
18
|
+
}
|
|
19
|
+
return fanoutInstance;
|
|
20
|
+
};
|
|
17
21
|
if (opts.services?.["relay"] === null) {
|
|
18
22
|
delete opts.services?.["relay"];
|
|
19
23
|
}
|
|
@@ -48,17 +52,20 @@ export const createLibp2pExtended = (opts = {
|
|
|
48
52
|
connectionEncrypters: opts.connectionEncrypters || [noise()],
|
|
49
53
|
streamMuxers: opts.streamMuxers || [yamux()],
|
|
50
54
|
services: {
|
|
55
|
+
...opts.services,
|
|
51
56
|
pubsub: opts.services?.pubsub ||
|
|
52
|
-
((c) => new
|
|
57
|
+
((c) => new TopicControlPlane(c, {
|
|
53
58
|
canRelayMessage: true,
|
|
59
|
+
topicRootControlPlane,
|
|
60
|
+
fanout: getOrCreateFanout(c),
|
|
54
61
|
// auto dial true
|
|
55
62
|
// auto prune true
|
|
56
63
|
})),
|
|
64
|
+
fanout: (c) => getOrCreateFanout(c),
|
|
57
65
|
blocks: opts.services?.blocks || ((c) => new DirectBlock(c)),
|
|
58
|
-
keychain: opts.services?.keychain || (
|
|
59
|
-
...opts.services,
|
|
66
|
+
keychain: opts.services?.keychain || keychain(),
|
|
60
67
|
...extraServices,
|
|
61
68
|
},
|
|
62
|
-
});
|
|
69
|
+
}).then((libp2p) => libp2p);
|
|
63
70
|
};
|
|
64
71
|
//# sourceMappingURL=libp2p.js.map
|
package/dist/src/libp2p.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAEN,QAAQ,GACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAIN,YAAY,GACZ,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAA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 +4,7 @@ import { type AnyStore } from "@peerbit/any-store";
|
|
|
4
4
|
import { Ed25519Keypair, PublicSignKey } from "@peerbit/crypto";
|
|
5
5
|
import type { Indices } from "@peerbit/indexer-interface";
|
|
6
6
|
import { type Address, type ExtractArgs, type OpenOptions, type Program, type ProgramClient, ProgramHandler } from "@peerbit/program";
|
|
7
|
+
import { FanoutChannel, type FanoutTreeChannelOptions, type FanoutTreeJoinOptions } from "@peerbit/pubsub";
|
|
7
8
|
import { type Libp2pExtended, type PartialLibp2pCreateOptions } from "./libp2p.js";
|
|
8
9
|
export declare const logger: import("@libp2p/interface").Logger;
|
|
9
10
|
export type OptionalCreateOptions = {
|
|
@@ -27,6 +28,13 @@ export type CreateInstanceOptions = (SimpleLibp2pOptions | Libp2pOptions) & {
|
|
|
27
28
|
directory?: string;
|
|
28
29
|
indexer?: (directory?: string) => Promise<Indices> | Indices;
|
|
29
30
|
} & OptionalCreateOptions;
|
|
31
|
+
export type DialReadiness = "connection" | "services" | "services-and-fanout";
|
|
32
|
+
export type DialOptions = {
|
|
33
|
+
dialTimeoutMs?: number;
|
|
34
|
+
serviceWaitTimeoutMs?: number;
|
|
35
|
+
readiness?: DialReadiness;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
};
|
|
30
38
|
export declare class Peerbit implements ProgramClient {
|
|
31
39
|
_libp2p: Libp2pExtended;
|
|
32
40
|
directory?: string;
|
|
@@ -49,7 +57,7 @@ export declare class Peerbit implements ProgramClient {
|
|
|
49
57
|
/**
|
|
50
58
|
* Dial a peer with an Ed25519 peerId
|
|
51
59
|
*/
|
|
52
|
-
dial(address: string | Multiaddr | Multiaddr[] | ProgramClient): Promise<boolean>;
|
|
60
|
+
dial(address: string | Multiaddr | Multiaddr[] | ProgramClient, options?: DialOptions): Promise<boolean>;
|
|
53
61
|
hangUp(address: PeerId | PublicSignKey | string | Multiaddr): Promise<void>;
|
|
54
62
|
start(): Promise<void>;
|
|
55
63
|
stop(): Promise<void>;
|
|
@@ -62,6 +70,11 @@ export declare class Peerbit implements ProgramClient {
|
|
|
62
70
|
* @returns
|
|
63
71
|
*/
|
|
64
72
|
open<S extends Program<ExtractArgs<S>>>(storeOrAddress: S | Address | string, options?: OpenOptions<S>): Promise<S>;
|
|
73
|
+
fanoutChannel(topic: string, root?: string): FanoutChannel;
|
|
74
|
+
fanoutResolveRoot(topic: string): Promise<string>;
|
|
75
|
+
fanoutOpenAsRoot(topic: string, options: Omit<FanoutTreeChannelOptions, "role">): import("@peerbit/pubsub").FanoutTreeChannelId;
|
|
76
|
+
fanoutJoin(topic: string, root: string, options: Omit<FanoutTreeChannelOptions, "role">, joinOpts?: FanoutTreeJoinOptions): Promise<void>;
|
|
77
|
+
fanoutJoinAuto(topic: string, options: Omit<FanoutTreeChannelOptions, "role">, joinOpts?: FanoutTreeJoinOptions): Promise<void>;
|
|
65
78
|
get storage(): AnyStore;
|
|
66
79
|
get indexer(): Indices;
|
|
67
80
|
}
|
package/dist/src/peer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../../src/peer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACN,KAAK,SAAS,EAGd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EACN,cAAc,EAEd,aAAa,
|
|
1
|
+
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../../src/peer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACN,KAAK,SAAS,EAGd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EACN,cAAc,EAEd,aAAa,EAIb,MAAM,iBAAiB,CAA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AAC,CAAC,CAAM,GAC1B,OAAO,CAAC,CAAC,CAAC;IAMN,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAA2C;IAOxE,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAcvD,gBAAgB,CACtB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAKzC,UAAU,CAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,EAC/C,QAAQ,CAAC,EAAE,qBAAqB;IAKpB,cAAc,CAC1B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,EAC/C,QAAQ,CAAC,EAAE,qBAAqB;IAMjC,IAAI,OAAO,aAEV;IAED,IAAI,OAAO,YAEV;CACD"}
|
package/dist/src/peer.js
CHANGED
|
@@ -3,12 +3,11 @@ import { keys } from "@libp2p/crypto";
|
|
|
3
3
|
import { isMultiaddr, multiaddr, } from "@multiformats/multiaddr";
|
|
4
4
|
import { createStore } from "@peerbit/any-store";
|
|
5
5
|
import { DirectBlock } from "@peerbit/blocks";
|
|
6
|
-
import { Ed25519Keypair, Ed25519PublicKey, PublicSignKey, Secp256k1Keypair, getKeypairFromPrivateKey, } from "@peerbit/crypto";
|
|
7
|
-
import { create as createSQLiteIndexer } from "@peerbit/indexer-sqlite3";
|
|
6
|
+
import { Ed25519Keypair, Ed25519PublicKey, PublicSignKey, Secp256k1Keypair, getPublicKeyFromPeerId, getKeypairFromPrivateKey, } from "@peerbit/crypto";
|
|
8
7
|
import { DefaultCryptoKeychain, keychain } from "@peerbit/keychain";
|
|
9
8
|
import { logger as loggerFn } from "@peerbit/logger";
|
|
10
9
|
import { ProgramHandler, } from "@peerbit/program";
|
|
11
|
-
import {
|
|
10
|
+
import { FanoutChannel, FanoutTree, TopicControlPlane, TopicRootControlPlane, } from "@peerbit/pubsub";
|
|
12
11
|
import sodium from "libsodium-wrappers";
|
|
13
12
|
import path from "path-browserify";
|
|
14
13
|
import { concat } from "uint8arrays";
|
|
@@ -64,7 +63,12 @@ export class Peerbit {
|
|
|
64
63
|
const directory = options.directory;
|
|
65
64
|
const hasDir = directory != null;
|
|
66
65
|
const storage = await createCache(directory != null ? path.join(directory, "/cache") : undefined);
|
|
67
|
-
const indexerFn = options.indexer ||
|
|
66
|
+
const indexerFn = options.indexer ||
|
|
67
|
+
(async (directory) => {
|
|
68
|
+
// Lazy-import to avoid loading sqlite-wasm in browser-like runtimes/tests
|
|
69
|
+
const { create } = await import("@peerbit/indexer-sqlite3");
|
|
70
|
+
return create(directory);
|
|
71
|
+
});
|
|
68
72
|
const indexer = directory != null
|
|
69
73
|
? await indexerFn(path.join(directory, "/index"))
|
|
70
74
|
: await indexerFn();
|
|
@@ -103,13 +107,109 @@ export class Peerbit {
|
|
|
103
107
|
]))
|
|
104
108
|
: undefined;
|
|
105
109
|
}
|
|
110
|
+
const topicRootControlPlane = new TopicRootControlPlane();
|
|
111
|
+
// Keep a single FanoutTree instance per peer so pubsub sharding + provider
|
|
112
|
+
// discovery share the same overlay.
|
|
113
|
+
let fanoutInstance;
|
|
114
|
+
const configuredFanoutFactory = extendedOptions?.services?.fanout ||
|
|
115
|
+
((c) => new FanoutTree(c, {
|
|
116
|
+
connectionManager: false,
|
|
117
|
+
topicRootControlPlane,
|
|
118
|
+
}));
|
|
119
|
+
const getOrCreateFanout = (c) => {
|
|
120
|
+
if (!fanoutInstance) {
|
|
121
|
+
fanoutInstance = configuredFanoutFactory(c);
|
|
122
|
+
}
|
|
123
|
+
return fanoutInstance;
|
|
124
|
+
};
|
|
125
|
+
const blockProviderNamespace = (cid) => `cid:${cid}`;
|
|
106
126
|
const services = {
|
|
107
127
|
keychain: (components) => keychain({ libp2p: {}, crypto: cryptoKeychain })(components),
|
|
108
|
-
|
|
128
|
+
fanout: (c) => getOrCreateFanout(c),
|
|
129
|
+
blocks: (c) => {
|
|
130
|
+
let blocksService;
|
|
131
|
+
const fanout = (() => {
|
|
132
|
+
try {
|
|
133
|
+
return getOrCreateFanout(c);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
const fallbackConnectedPeers = () => {
|
|
140
|
+
const out = [];
|
|
141
|
+
const push = (hash) => {
|
|
142
|
+
if (!hash)
|
|
143
|
+
return;
|
|
144
|
+
if (hash === blocksService?.publicKeyHash)
|
|
145
|
+
return;
|
|
146
|
+
// Small bounded list; avoid Set allocations on hot paths.
|
|
147
|
+
if (out.includes(hash))
|
|
148
|
+
return;
|
|
149
|
+
out.push(hash);
|
|
150
|
+
};
|
|
151
|
+
// Prefer peers we've already negotiated `/peerbit/direct-block` streams with.
|
|
152
|
+
for (const h of blocksService?.peers.keys() ?? []) {
|
|
153
|
+
push(h);
|
|
154
|
+
if (out.length >= 32)
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
// Fall back to currently connected libp2p peers.
|
|
158
|
+
for (const conn of c.connectionManager.getConnections()) {
|
|
159
|
+
try {
|
|
160
|
+
push(getPublicKeyFromPeerId(conn.remotePeer).hashcode());
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// ignore unexpected key types
|
|
164
|
+
}
|
|
165
|
+
if (out.length >= 32)
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
};
|
|
170
|
+
const resolveProviders = async (cid, options) => {
|
|
171
|
+
// 1) tracker-backed provider directory (best-effort, bounded)
|
|
172
|
+
try {
|
|
173
|
+
const providers = await fanout?.queryProviders(blockProviderNamespace(cid), {
|
|
174
|
+
want: 8,
|
|
175
|
+
timeoutMs: 2_000,
|
|
176
|
+
queryTimeoutMs: 500,
|
|
177
|
+
bootstrapMaxPeers: 2,
|
|
178
|
+
signal: options?.signal,
|
|
179
|
+
});
|
|
180
|
+
if (providers && providers.length > 0)
|
|
181
|
+
return providers;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// ignore discovery failures
|
|
185
|
+
}
|
|
186
|
+
// 2) fallback to currently connected peers (keeps local/small nets working without trackers)
|
|
187
|
+
return fallbackConnectedPeers();
|
|
188
|
+
};
|
|
189
|
+
blocksService = new DirectBlock(c, {
|
|
190
|
+
canRelayMessage: asRelay,
|
|
191
|
+
directory: blocksDirectory,
|
|
192
|
+
resolveProviders,
|
|
193
|
+
onPut: async (cid) => {
|
|
194
|
+
// Best-effort directory announce for "get without remote.from" workflows.
|
|
195
|
+
try {
|
|
196
|
+
await fanout?.announceProvider(blockProviderNamespace(cid), {
|
|
197
|
+
ttlMs: 120_000,
|
|
198
|
+
bootstrapMaxPeers: 2,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// ignore announce failures
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
return blocksService;
|
|
207
|
+
},
|
|
208
|
+
pubsub: (c) => new TopicControlPlane(c, {
|
|
109
209
|
canRelayMessage: asRelay,
|
|
110
|
-
|
|
210
|
+
topicRootControlPlane,
|
|
211
|
+
fanout: getOrCreateFanout(c),
|
|
111
212
|
}),
|
|
112
|
-
pubsub: (c) => new DirectSub(c, { canRelayMessage: asRelay }),
|
|
113
213
|
...extendedOptions?.services,
|
|
114
214
|
};
|
|
115
215
|
if (!asRelay) {
|
|
@@ -188,32 +288,78 @@ export class Peerbit {
|
|
|
188
288
|
/**
|
|
189
289
|
* Dial a peer with an Ed25519 peerId
|
|
190
290
|
*/
|
|
191
|
-
async dial(address) {
|
|
291
|
+
async dial(address, options) {
|
|
192
292
|
const maddress = typeof address === "string"
|
|
193
293
|
? multiaddr(address)
|
|
194
294
|
: isMultiaddr(address) || Array.isArray(address)
|
|
195
295
|
? address
|
|
196
296
|
: address.getMultiaddrs();
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
297
|
+
let dialSignal = options?.signal;
|
|
298
|
+
let dialAbortController;
|
|
299
|
+
let dialTimeout;
|
|
300
|
+
let onAbort;
|
|
301
|
+
if (options?.dialTimeoutMs != null) {
|
|
302
|
+
dialAbortController = new AbortController();
|
|
303
|
+
const abort = (reason) => {
|
|
304
|
+
if (dialAbortController?.signal.aborted)
|
|
305
|
+
return;
|
|
306
|
+
dialAbortController?.abort(reason);
|
|
307
|
+
};
|
|
308
|
+
dialTimeout = setTimeout(() => {
|
|
309
|
+
abort(new Error(`Dial timeout after ${options.dialTimeoutMs}ms`));
|
|
310
|
+
}, options.dialTimeoutMs);
|
|
311
|
+
if (dialSignal) {
|
|
312
|
+
if (dialSignal.aborted) {
|
|
313
|
+
abort(dialSignal.reason);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
onAbort = () => abort(dialSignal?.reason);
|
|
317
|
+
dialSignal.addEventListener("abort", onAbort, { once: true });
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
dialSignal = dialAbortController.signal;
|
|
207
321
|
}
|
|
208
322
|
try {
|
|
209
|
-
await this.libp2p.
|
|
210
|
-
|
|
211
|
-
|
|
323
|
+
const connection = await this.libp2p.dial(maddress, dialSignal ? { signal: dialSignal } : undefined);
|
|
324
|
+
const publicKey = Ed25519PublicKey.fromPeerId(connection.remotePeer);
|
|
325
|
+
const peerHash = publicKey.hashcode();
|
|
326
|
+
const resolvedReadiness = options?.readiness ??
|
|
327
|
+
(this.libp2p.services.fanout ? "services-and-fanout" : "services");
|
|
328
|
+
const serviceWaitTimeoutMs = options?.serviceWaitTimeoutMs ?? options?.dialTimeoutMs;
|
|
329
|
+
if (resolvedReadiness === "connection") {
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
const waitForNeighbor = async (label, service) => {
|
|
333
|
+
try {
|
|
334
|
+
await service.waitFor(peerHash, {
|
|
335
|
+
target: "neighbor",
|
|
336
|
+
timeout: serviceWaitTimeoutMs,
|
|
337
|
+
signal: dialSignal,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
catch (_error) {
|
|
341
|
+
throw new Error(`Failed to dial peer. Not available on ${label}`);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
// TODO, do this as a promise instead using the onPeerConnected vents in pubsub and blocks
|
|
345
|
+
await waitForNeighbor("Pubsub", this.libp2p.services.pubsub);
|
|
346
|
+
await waitForNeighbor("Blocks", this.libp2p.services.blocks);
|
|
347
|
+
if (resolvedReadiness === "services-and-fanout") {
|
|
348
|
+
const fanoutService = this.libp2p.services.fanout;
|
|
349
|
+
if (!fanoutService?.waitFor) {
|
|
350
|
+
throw new Error("Failed to dial peer. Not available on Fanout (service missing)");
|
|
351
|
+
}
|
|
352
|
+
await waitForNeighbor("Fanout", fanoutService);
|
|
353
|
+
}
|
|
354
|
+
return true;
|
|
212
355
|
}
|
|
213
|
-
|
|
214
|
-
|
|
356
|
+
finally {
|
|
357
|
+
if (dialTimeout)
|
|
358
|
+
clearTimeout(dialTimeout);
|
|
359
|
+
if (onAbort && options?.signal) {
|
|
360
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
361
|
+
}
|
|
215
362
|
}
|
|
216
|
-
return true;
|
|
217
363
|
}
|
|
218
364
|
async hangUp(address) {
|
|
219
365
|
await this.libp2p.hangUp(address instanceof PublicSignKey
|
|
@@ -246,7 +392,73 @@ export class Peerbit {
|
|
|
246
392
|
if (_addresses.length === 0) {
|
|
247
393
|
throw new Error("Failed to find any addresses to dial");
|
|
248
394
|
}
|
|
249
|
-
const
|
|
395
|
+
const extractPeerId = (a) => {
|
|
396
|
+
const s = typeof a === "string" ? a : a.toString();
|
|
397
|
+
const m = s.match(/\/(?:p2p|ipfs)\/([^/]+)(?:\/|$)/);
|
|
398
|
+
return m?.[1];
|
|
399
|
+
};
|
|
400
|
+
// Keep fanout bootstrap config aligned with peer bootstrap config so fanout
|
|
401
|
+
// channels can join via the same rendezvous nodes.
|
|
402
|
+
try {
|
|
403
|
+
this.libp2p.services.fanout.setBootstraps(_addresses);
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
// ignore if fanout service is not present/overridden
|
|
407
|
+
}
|
|
408
|
+
// Avoid dialing the same peer multiple times concurrently (multiaddrs often come
|
|
409
|
+
// with both `/tcp` and `/ws` addresses for the same peer). Concurrent dials to
|
|
410
|
+
// the same peer can race internal stream readiness, causing waits to stall.
|
|
411
|
+
const byPeerId = new Map();
|
|
412
|
+
const unknown = [];
|
|
413
|
+
for (const a of _addresses) {
|
|
414
|
+
const pid = extractPeerId(a);
|
|
415
|
+
if (!pid) {
|
|
416
|
+
unknown.push(a);
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const list = byPeerId.get(pid) ?? [];
|
|
420
|
+
list.push(a);
|
|
421
|
+
byPeerId.set(pid, list);
|
|
422
|
+
}
|
|
423
|
+
const dialTimeoutMs = 30_000;
|
|
424
|
+
const scoreBootstrapAddr = (a) => {
|
|
425
|
+
const s = a.toString();
|
|
426
|
+
const isCircuit = s.includes("p2p-circuit");
|
|
427
|
+
const isWs = s.includes("/ws") || s.includes("/wss");
|
|
428
|
+
return (isCircuit ? 2 : 0) + (isWs ? 1 : 0);
|
|
429
|
+
};
|
|
430
|
+
const dialPeer = async (list) => {
|
|
431
|
+
const maddrs = list
|
|
432
|
+
.map((x) => (typeof x === "string" ? multiaddr(x) : x))
|
|
433
|
+
.sort((a, b) => scoreBootstrapAddr(a) - scoreBootstrapAddr(b));
|
|
434
|
+
let lastError;
|
|
435
|
+
for (const ma of maddrs) {
|
|
436
|
+
try {
|
|
437
|
+
await this.dial(ma, { dialTimeoutMs });
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
catch (e) {
|
|
441
|
+
lastError = e;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
throw lastError ?? new Error("Failed to dial bootstrap peer");
|
|
445
|
+
};
|
|
446
|
+
const dialTasks = [];
|
|
447
|
+
for (const list of byPeerId.values()) {
|
|
448
|
+
dialTasks.push({
|
|
449
|
+
label: list.map((x) => (typeof x === "string" ? x : x.toString())),
|
|
450
|
+
promise: dialPeer(list),
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
for (const a of unknown) {
|
|
454
|
+
dialTasks.push({
|
|
455
|
+
label: [typeof a === "string" ? a : a.toString()],
|
|
456
|
+
promise: this.dial(typeof a === "string" ? multiaddr(a) : a, {
|
|
457
|
+
dialTimeoutMs,
|
|
458
|
+
}),
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
const settled = await Promise.allSettled(dialTasks.map((t) => t.promise));
|
|
250
462
|
let once = false;
|
|
251
463
|
for (const [i, result] of settled.entries()) {
|
|
252
464
|
if (result.status === "fulfilled") {
|
|
@@ -254,7 +466,7 @@ export class Peerbit {
|
|
|
254
466
|
}
|
|
255
467
|
else {
|
|
256
468
|
logger.error("Failed to dial bootstrap address(s): " +
|
|
257
|
-
JSON.stringify(
|
|
469
|
+
JSON.stringify(dialTasks[i]?.label ?? []) +
|
|
258
470
|
". Reason: " +
|
|
259
471
|
result.reason);
|
|
260
472
|
}
|
|
@@ -262,6 +474,76 @@ export class Peerbit {
|
|
|
262
474
|
if (!once) {
|
|
263
475
|
throw new Error("Failed to succefully dial any bootstrap node");
|
|
264
476
|
}
|
|
477
|
+
// Seed deterministic topic-root candidates for shard root resolution.
|
|
478
|
+
//
|
|
479
|
+
// IMPORTANT: this set must be stable across peers, otherwise different nodes
|
|
480
|
+
// will resolve different roots for the same shard and the overlay will partition.
|
|
481
|
+
//
|
|
482
|
+
// We therefore constrain candidates to the bootstrap peerIds we were asked
|
|
483
|
+
// to dial (and that we successfully connected to).
|
|
484
|
+
const servicesAny = this.libp2p.services;
|
|
485
|
+
const fanoutPlane = servicesAny?.fanout?.topicRootControlPlane;
|
|
486
|
+
const pubsubPlane = servicesAny?.pubsub?.topicRootControlPlane;
|
|
487
|
+
const planes = [...new Set([fanoutPlane, pubsubPlane].filter(Boolean))];
|
|
488
|
+
if (planes.length > 0) {
|
|
489
|
+
const bootstrapPeerIds = new Set();
|
|
490
|
+
for (const a of _addresses) {
|
|
491
|
+
const pid = extractPeerId(a);
|
|
492
|
+
if (pid)
|
|
493
|
+
bootstrapPeerIds.add(pid);
|
|
494
|
+
}
|
|
495
|
+
const candidates = new Set();
|
|
496
|
+
for (const connection of this.libp2p.getConnections()) {
|
|
497
|
+
if (bootstrapPeerIds.size > 0) {
|
|
498
|
+
const remoteId = connection.remotePeer?.toString?.();
|
|
499
|
+
if (!remoteId || !bootstrapPeerIds.has(remoteId))
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
try {
|
|
503
|
+
candidates.add(getPublicKeyFromPeerId(connection.remotePeer).hashcode());
|
|
504
|
+
}
|
|
505
|
+
catch {
|
|
506
|
+
// ignore peers without a resolvable public key
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
// If this node is itself one of the bootstraps, it won't show up among
|
|
510
|
+
// remote connections; add it explicitly so shard mapping matches other peers.
|
|
511
|
+
try {
|
|
512
|
+
if (bootstrapPeerIds.has(this.libp2p.peerId.toString())) {
|
|
513
|
+
candidates.add(this.services.pubsub.publicKeyHash);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
catch {
|
|
517
|
+
// ignore
|
|
518
|
+
}
|
|
519
|
+
if (candidates.size > 0) {
|
|
520
|
+
const list = [...candidates];
|
|
521
|
+
// Prefer the pubsub helper so we also disable its auto-candidate mode.
|
|
522
|
+
try {
|
|
523
|
+
this.services.pubsub?.setTopicRootCandidates?.(list);
|
|
524
|
+
}
|
|
525
|
+
catch {
|
|
526
|
+
// ignore
|
|
527
|
+
}
|
|
528
|
+
for (const plane of planes) {
|
|
529
|
+
try {
|
|
530
|
+
plane.setTopicRootCandidates(list);
|
|
531
|
+
}
|
|
532
|
+
catch {
|
|
533
|
+
// ignore
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
// Open shard roots this node is responsible for (no-op for non-candidates).
|
|
537
|
+
try {
|
|
538
|
+
if (list.includes(this.services.pubsub.publicKeyHash)) {
|
|
539
|
+
await this.services.pubsub.hostShardRootsNow();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
catch {
|
|
543
|
+
// ignore
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
265
547
|
}
|
|
266
548
|
/**
|
|
267
549
|
* Default behaviour of a store is only to accept heads that are forks (new roots) with some probability
|
|
@@ -273,6 +555,32 @@ export class Peerbit {
|
|
|
273
555
|
async open(storeOrAddress, options = {}) {
|
|
274
556
|
return (this._handler || (this._handler = new ProgramHandler({ client: this }))).open(storeOrAddress, options);
|
|
275
557
|
}
|
|
558
|
+
fanoutChannel(topic, root = this.services.fanout.publicKeyHash) {
|
|
559
|
+
if (root === this.services.fanout.publicKeyHash) {
|
|
560
|
+
return FanoutChannel.fromSelf(this.services.fanout, topic);
|
|
561
|
+
}
|
|
562
|
+
return new FanoutChannel(this.services.fanout, { topic, root });
|
|
563
|
+
}
|
|
564
|
+
async fanoutResolveRoot(topic) {
|
|
565
|
+
const servicesAny = this.services;
|
|
566
|
+
const topicRootControlPlane = servicesAny?.fanout?.topicRootControlPlane ||
|
|
567
|
+
servicesAny?.pubsub?.topicRootControlPlane;
|
|
568
|
+
const resolved = await topicRootControlPlane?.resolveTopicRoot?.(topic);
|
|
569
|
+
if (!resolved) {
|
|
570
|
+
throw new Error(`Failed to resolve fanout root for topic ${topic}. Configure topic-root candidates/resolver (Peerbit.bootstrap() does this automatically) or pass root explicitly.`);
|
|
571
|
+
}
|
|
572
|
+
return resolved;
|
|
573
|
+
}
|
|
574
|
+
fanoutOpenAsRoot(topic, options) {
|
|
575
|
+
return this.fanoutChannel(topic).openAsRoot(options);
|
|
576
|
+
}
|
|
577
|
+
fanoutJoin(topic, root, options, joinOpts) {
|
|
578
|
+
return this.fanoutChannel(topic, root).join(options, joinOpts);
|
|
579
|
+
}
|
|
580
|
+
async fanoutJoinAuto(topic, options, joinOpts) {
|
|
581
|
+
const root = await this.fanoutResolveRoot(topic);
|
|
582
|
+
return this.fanoutJoin(topic, root, options, joinOpts);
|
|
583
|
+
}
|
|
276
584
|
get storage() {
|
|
277
585
|
return this._storage;
|
|
278
586
|
}
|
package/dist/src/peer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer.js","sourceRoot":"","sources":["../../src/peer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC,OAAO,EAEN,WAAW,EACX,SAAS,GACT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAiB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,wBAAwB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,MAAM,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAMN,cAAc,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,g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C,CAAC;IAChE,CAAC;IAEM,KAAK,CAAC,cAAc,CAC1B,KAAa,EACb,OAA+C,EAC/C,QAAgC;QAEhC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peerbit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Peerbit client",
|
|
5
5
|
"author": "dao.xyz",
|
|
6
6
|
"license": "MIT",
|
|
@@ -83,20 +83,20 @@
|
|
|
83
83
|
"p-queue": "^8.0.1",
|
|
84
84
|
"uint8arrays": "^5.1.0",
|
|
85
85
|
"libsodium-wrappers": "0.7.15",
|
|
86
|
-
"@peerbit/any-store": "2.2.
|
|
87
|
-
"@peerbit/any-store-opfs": "1.1.
|
|
88
|
-
"@peerbit/
|
|
86
|
+
"@peerbit/any-store": "2.2.5",
|
|
87
|
+
"@peerbit/any-store-opfs": "1.1.4",
|
|
88
|
+
"@peerbit/crypto": "3.0.0",
|
|
89
|
+
"@peerbit/indexer-interface": "3.0.0",
|
|
89
90
|
"@peerbit/logger": "2.0.0",
|
|
90
|
-
"@peerbit/time": "
|
|
91
|
-
"@peerbit/crypto": "2.4.1",
|
|
91
|
+
"@peerbit/time": "3.0.0",
|
|
92
92
|
"@peerbit/build-assets": "1.1.0",
|
|
93
|
-
"@peerbit/keychain": "1.2.
|
|
94
|
-
"@peerbit/indexer-simple": "1.2.
|
|
95
|
-
"@peerbit/indexer-sqlite3": "
|
|
96
|
-
"@peerbit/program": "
|
|
97
|
-
"@peerbit/blocks": "
|
|
98
|
-
"@peerbit/pubsub": "
|
|
99
|
-
"@peerbit/stream-interface": "
|
|
93
|
+
"@peerbit/keychain": "1.2.5",
|
|
94
|
+
"@peerbit/indexer-simple": "1.2.3",
|
|
95
|
+
"@peerbit/indexer-sqlite3": "3.0.0",
|
|
96
|
+
"@peerbit/program": "6.0.0",
|
|
97
|
+
"@peerbit/blocks": "4.0.0",
|
|
98
|
+
"@peerbit/pubsub": "5.0.0",
|
|
99
|
+
"@peerbit/stream-interface": "6.0.0"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@types/libsodium-wrappers": "^0.7.14",
|
package/src/libp2p.ts
CHANGED
|
@@ -4,11 +4,10 @@ import type { CircuitRelayService } from "@libp2p/circuit-relay-v2";
|
|
|
4
4
|
import { identify } from "@libp2p/identify";
|
|
5
5
|
import { DirectBlock } from "@peerbit/blocks";
|
|
6
6
|
import {
|
|
7
|
-
DefaultCryptoKeychain,
|
|
8
7
|
type IPeerbitKeychain,
|
|
9
8
|
keychain,
|
|
10
9
|
} from "@peerbit/keychain";
|
|
11
|
-
import {
|
|
10
|
+
import { FanoutTree, TopicControlPlane, TopicRootControlPlane } from "@peerbit/pubsub";
|
|
12
11
|
import {
|
|
13
12
|
type Libp2p,
|
|
14
13
|
type Libp2pOptions,
|
|
@@ -18,7 +17,8 @@ import {
|
|
|
18
17
|
import { listen, relay, transports } from "./transports.js";
|
|
19
18
|
|
|
20
19
|
export type Libp2pExtendServices = {
|
|
21
|
-
pubsub:
|
|
20
|
+
pubsub: TopicControlPlane;
|
|
21
|
+
fanout: FanoutTree;
|
|
22
22
|
blocks: DirectBlock;
|
|
23
23
|
keychain: IPeerbitKeychain;
|
|
24
24
|
};
|
|
@@ -39,15 +39,20 @@ export type Libp2pCreateOptionsWithServices = Libp2pCreateOptions & {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export const createLibp2pExtended = (
|
|
42
|
-
opts: PartialLibp2pCreateOptions = {
|
|
43
|
-
services: {
|
|
44
|
-
blocks: (c: any) => new DirectBlock(c),
|
|
45
|
-
pubsub: (c: any) => new DirectSub(c),
|
|
46
|
-
keychain: keychain(),
|
|
47
|
-
},
|
|
48
|
-
},
|
|
42
|
+
opts: PartialLibp2pCreateOptions = {},
|
|
49
43
|
): Promise<Libp2pExtended> => {
|
|
44
|
+
const topicRootControlPlane = new TopicRootControlPlane();
|
|
50
45
|
let extraServices: any = {};
|
|
46
|
+
let fanoutInstance: FanoutTree | undefined;
|
|
47
|
+
const configuredFanoutFactory =
|
|
48
|
+
opts.services?.fanout ||
|
|
49
|
+
((c) => new FanoutTree(c, { connectionManager: false, topicRootControlPlane }));
|
|
50
|
+
const getOrCreateFanout = (c: any) => {
|
|
51
|
+
if (!fanoutInstance) {
|
|
52
|
+
fanoutInstance = configuredFanoutFactory(c) as FanoutTree;
|
|
53
|
+
}
|
|
54
|
+
return fanoutInstance;
|
|
55
|
+
};
|
|
51
56
|
|
|
52
57
|
if (opts.services?.["relay"] === null) {
|
|
53
58
|
delete opts.services?.["relay"];
|
|
@@ -85,18 +90,21 @@ export const createLibp2pExtended = (
|
|
|
85
90
|
connectionEncrypters: opts.connectionEncrypters || [noise()],
|
|
86
91
|
streamMuxers: opts.streamMuxers || [yamux()],
|
|
87
92
|
services: {
|
|
93
|
+
...opts.services,
|
|
88
94
|
pubsub:
|
|
89
95
|
opts.services?.pubsub ||
|
|
90
96
|
((c) =>
|
|
91
|
-
new
|
|
97
|
+
new TopicControlPlane(c, {
|
|
92
98
|
canRelayMessage: true,
|
|
99
|
+
topicRootControlPlane,
|
|
100
|
+
fanout: getOrCreateFanout(c),
|
|
93
101
|
// auto dial true
|
|
94
102
|
// auto prune true
|
|
95
103
|
})),
|
|
104
|
+
fanout: (c) => getOrCreateFanout(c),
|
|
96
105
|
blocks: opts.services?.blocks || ((c) => new DirectBlock(c)),
|
|
97
|
-
keychain: opts.services?.keychain || (
|
|
98
|
-
...opts.services,
|
|
106
|
+
keychain: opts.services?.keychain || keychain(),
|
|
99
107
|
...extraServices,
|
|
100
108
|
},
|
|
101
|
-
});
|
|
109
|
+
}).then((libp2p) => libp2p as Libp2pExtended);
|
|
102
110
|
};
|
package/src/peer.ts
CHANGED
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
Ed25519PublicKey,
|
|
15
15
|
PublicSignKey,
|
|
16
16
|
Secp256k1Keypair,
|
|
17
|
+
getPublicKeyFromPeerId,
|
|
17
18
|
getKeypairFromPrivateKey,
|
|
18
19
|
} from "@peerbit/crypto";
|
|
19
20
|
import type { Indices } from "@peerbit/indexer-interface";
|
|
20
|
-
import { create as createSQLiteIndexer } from "@peerbit/indexer-sqlite3";
|
|
21
21
|
import { DefaultCryptoKeychain, keychain } from "@peerbit/keychain";
|
|
22
22
|
import { logger as loggerFn } from "@peerbit/logger";
|
|
23
23
|
import {
|
|
@@ -28,7 +28,14 @@ import {
|
|
|
28
28
|
type ProgramClient,
|
|
29
29
|
ProgramHandler,
|
|
30
30
|
} from "@peerbit/program";
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
FanoutChannel,
|
|
33
|
+
FanoutTree,
|
|
34
|
+
TopicControlPlane,
|
|
35
|
+
TopicRootControlPlane,
|
|
36
|
+
type FanoutTreeChannelOptions,
|
|
37
|
+
type FanoutTreeJoinOptions,
|
|
38
|
+
} from "@peerbit/pubsub";
|
|
32
39
|
import type { Libp2p } from "libp2p";
|
|
33
40
|
import sodium from "libsodium-wrappers";
|
|
34
41
|
import path from "path-browserify";
|
|
@@ -61,6 +68,18 @@ export type CreateInstanceOptions = (SimpleLibp2pOptions | Libp2pOptions) & {
|
|
|
61
68
|
indexer?: (directory?: string) => Promise<Indices> | Indices;
|
|
62
69
|
} & OptionalCreateOptions;
|
|
63
70
|
|
|
71
|
+
export type DialReadiness =
|
|
72
|
+
| "connection"
|
|
73
|
+
| "services"
|
|
74
|
+
| "services-and-fanout";
|
|
75
|
+
|
|
76
|
+
export type DialOptions = {
|
|
77
|
+
dialTimeoutMs?: number;
|
|
78
|
+
serviceWaitTimeoutMs?: number;
|
|
79
|
+
readiness?: DialReadiness;
|
|
80
|
+
signal?: AbortSignal;
|
|
81
|
+
};
|
|
82
|
+
|
|
64
83
|
const isLibp2pInstance = (libp2p: Libp2pExtended | ClientCreateOptions) =>
|
|
65
84
|
!!(libp2p as Libp2p).getMultiaddrs;
|
|
66
85
|
|
|
@@ -132,7 +151,13 @@ export class Peerbit implements ProgramClient {
|
|
|
132
151
|
const storage = await createCache(
|
|
133
152
|
directory != null ? path.join(directory, "/cache") : undefined,
|
|
134
153
|
);
|
|
135
|
-
const indexerFn =
|
|
154
|
+
const indexerFn =
|
|
155
|
+
options.indexer ||
|
|
156
|
+
(async (directory?: string) => {
|
|
157
|
+
// Lazy-import to avoid loading sqlite-wasm in browser-like runtimes/tests
|
|
158
|
+
const { create } = await import("@peerbit/indexer-sqlite3");
|
|
159
|
+
return create(directory);
|
|
160
|
+
});
|
|
136
161
|
const indexer =
|
|
137
162
|
directory != null
|
|
138
163
|
? await indexerFn(path.join(directory, "/index"))
|
|
@@ -186,19 +211,123 @@ export class Peerbit implements ProgramClient {
|
|
|
186
211
|
]),
|
|
187
212
|
)
|
|
188
213
|
: undefined;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const topicRootControlPlane = new TopicRootControlPlane();
|
|
217
|
+
|
|
218
|
+
// Keep a single FanoutTree instance per peer so pubsub sharding + provider
|
|
219
|
+
// discovery share the same overlay.
|
|
220
|
+
let fanoutInstance: FanoutTree | undefined;
|
|
221
|
+
const configuredFanoutFactory =
|
|
222
|
+
extendedOptions?.services?.fanout ||
|
|
223
|
+
((c: any) =>
|
|
224
|
+
new FanoutTree(c, {
|
|
225
|
+
connectionManager: false,
|
|
226
|
+
topicRootControlPlane,
|
|
227
|
+
}));
|
|
228
|
+
const getOrCreateFanout = (c: any) => {
|
|
229
|
+
if (!fanoutInstance) {
|
|
230
|
+
fanoutInstance = configuredFanoutFactory(c) as FanoutTree;
|
|
231
|
+
}
|
|
232
|
+
return fanoutInstance;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const blockProviderNamespace = (cid: string) => `cid:${cid}`;
|
|
236
|
+
|
|
237
|
+
const services: any = {
|
|
238
|
+
keychain: (components: KeychainComponents) =>
|
|
239
|
+
keychain({ libp2p: {}, crypto: cryptoKeychain })(components),
|
|
240
|
+
fanout: (c: any) => getOrCreateFanout(c),
|
|
241
|
+
blocks: (c: any) => {
|
|
242
|
+
let blocksService: DirectBlock | undefined;
|
|
243
|
+
const fanout = (() => {
|
|
244
|
+
try {
|
|
245
|
+
return getOrCreateFanout(c);
|
|
246
|
+
} catch {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
})();
|
|
250
|
+
|
|
251
|
+
const fallbackConnectedPeers = () => {
|
|
252
|
+
const out: string[] = [];
|
|
253
|
+
const push = (hash?: string) => {
|
|
254
|
+
if (!hash) return;
|
|
255
|
+
if (hash === blocksService?.publicKeyHash) return;
|
|
256
|
+
// Small bounded list; avoid Set allocations on hot paths.
|
|
257
|
+
if (out.includes(hash)) return;
|
|
258
|
+
out.push(hash);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// Prefer peers we've already negotiated `/peerbit/direct-block` streams with.
|
|
262
|
+
for (const h of blocksService?.peers.keys() ?? []) {
|
|
263
|
+
push(h);
|
|
264
|
+
if (out.length >= 32) return out;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Fall back to currently connected libp2p peers.
|
|
268
|
+
for (const conn of c.connectionManager.getConnections()) {
|
|
269
|
+
try {
|
|
270
|
+
push(getPublicKeyFromPeerId(conn.remotePeer).hashcode());
|
|
271
|
+
} catch {
|
|
272
|
+
// ignore unexpected key types
|
|
273
|
+
}
|
|
274
|
+
if (out.length >= 32) break;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return out;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const resolveProviders = async (
|
|
281
|
+
cid: string,
|
|
282
|
+
options?: { signal?: AbortSignal },
|
|
283
|
+
) => {
|
|
284
|
+
// 1) tracker-backed provider directory (best-effort, bounded)
|
|
285
|
+
try {
|
|
286
|
+
const providers = await fanout?.queryProviders(
|
|
287
|
+
blockProviderNamespace(cid),
|
|
288
|
+
{
|
|
289
|
+
want: 8,
|
|
290
|
+
timeoutMs: 2_000,
|
|
291
|
+
queryTimeoutMs: 500,
|
|
292
|
+
bootstrapMaxPeers: 2,
|
|
293
|
+
signal: options?.signal,
|
|
294
|
+
},
|
|
295
|
+
);
|
|
296
|
+
if (providers && providers.length > 0) return providers;
|
|
297
|
+
} catch {
|
|
298
|
+
// ignore discovery failures
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 2) fallback to currently connected peers (keeps local/small nets working without trackers)
|
|
302
|
+
return fallbackConnectedPeers();
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
blocksService = new DirectBlock(c, {
|
|
306
|
+
canRelayMessage: asRelay,
|
|
307
|
+
directory: blocksDirectory,
|
|
308
|
+
resolveProviders,
|
|
309
|
+
onPut: async (cid) => {
|
|
310
|
+
// Best-effort directory announce for "get without remote.from" workflows.
|
|
311
|
+
try {
|
|
312
|
+
await fanout?.announceProvider(blockProviderNamespace(cid), {
|
|
313
|
+
ttlMs: 120_000,
|
|
314
|
+
bootstrapMaxPeers: 2,
|
|
315
|
+
});
|
|
316
|
+
} catch {
|
|
317
|
+
// ignore announce failures
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
return blocksService;
|
|
322
|
+
},
|
|
323
|
+
pubsub: (c: any) =>
|
|
324
|
+
new TopicControlPlane(c, {
|
|
325
|
+
canRelayMessage: asRelay,
|
|
326
|
+
topicRootControlPlane,
|
|
327
|
+
fanout: getOrCreateFanout(c),
|
|
328
|
+
}),
|
|
329
|
+
...extendedOptions?.services,
|
|
330
|
+
};
|
|
202
331
|
|
|
203
332
|
if (!asRelay) {
|
|
204
333
|
services.relay = null;
|
|
@@ -294,6 +423,7 @@ export class Peerbit implements ProgramClient {
|
|
|
294
423
|
*/
|
|
295
424
|
async dial(
|
|
296
425
|
address: string | Multiaddr | Multiaddr[] | ProgramClient,
|
|
426
|
+
options?: DialOptions,
|
|
297
427
|
): Promise<boolean> {
|
|
298
428
|
const maddress =
|
|
299
429
|
typeof address === "string"
|
|
@@ -301,27 +431,89 @@ export class Peerbit implements ProgramClient {
|
|
|
301
431
|
: isMultiaddr(address) || Array.isArray(address)
|
|
302
432
|
? address
|
|
303
433
|
: address.getMultiaddrs();
|
|
304
|
-
const connection = await this.libp2p.dial(maddress);
|
|
305
434
|
|
|
306
|
-
|
|
435
|
+
let dialSignal: AbortSignal | undefined = options?.signal;
|
|
436
|
+
let dialAbortController: AbortController | undefined;
|
|
437
|
+
let dialTimeout: ReturnType<typeof setTimeout> | undefined;
|
|
438
|
+
let onAbort: (() => void) | undefined;
|
|
307
439
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
440
|
+
if (options?.dialTimeoutMs != null) {
|
|
441
|
+
dialAbortController = new AbortController();
|
|
442
|
+
const abort = (reason?: unknown) => {
|
|
443
|
+
if (dialAbortController?.signal.aborted) return;
|
|
444
|
+
dialAbortController?.abort(reason);
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
dialTimeout = setTimeout(() => {
|
|
448
|
+
abort(new Error(`Dial timeout after ${options.dialTimeoutMs}ms`));
|
|
449
|
+
}, options.dialTimeoutMs);
|
|
450
|
+
|
|
451
|
+
if (dialSignal) {
|
|
452
|
+
if (dialSignal.aborted) {
|
|
453
|
+
abort(dialSignal.reason);
|
|
454
|
+
} else {
|
|
455
|
+
onAbort = () => abort(dialSignal?.reason);
|
|
456
|
+
dialSignal.addEventListener("abort", onAbort, { once: true });
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
dialSignal = dialAbortController.signal;
|
|
315
461
|
}
|
|
316
462
|
|
|
317
463
|
try {
|
|
318
|
-
await this.libp2p.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
464
|
+
const connection = await this.libp2p.dial(
|
|
465
|
+
maddress as any,
|
|
466
|
+
dialSignal ? ({ signal: dialSignal } as any) : undefined,
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
const publicKey = Ed25519PublicKey.fromPeerId(connection.remotePeer);
|
|
470
|
+
const peerHash = publicKey.hashcode();
|
|
471
|
+
|
|
472
|
+
const resolvedReadiness: DialReadiness =
|
|
473
|
+
options?.readiness ??
|
|
474
|
+
(this.libp2p.services.fanout ? "services-and-fanout" : "services");
|
|
475
|
+
const serviceWaitTimeoutMs =
|
|
476
|
+
options?.serviceWaitTimeoutMs ?? options?.dialTimeoutMs;
|
|
477
|
+
if (resolvedReadiness === "connection") {
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const waitForNeighbor = async (
|
|
482
|
+
label: "Pubsub" | "Blocks" | "Fanout",
|
|
483
|
+
service: { waitFor: (peer: string, options?: any) => Promise<any> },
|
|
484
|
+
) => {
|
|
485
|
+
try {
|
|
486
|
+
await service.waitFor(peerHash, {
|
|
487
|
+
target: "neighbor",
|
|
488
|
+
timeout: serviceWaitTimeoutMs,
|
|
489
|
+
signal: dialSignal,
|
|
490
|
+
});
|
|
491
|
+
} catch (_error) {
|
|
492
|
+
throw new Error(`Failed to dial peer. Not available on ${label}`);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// TODO, do this as a promise instead using the onPeerConnected vents in pubsub and blocks
|
|
497
|
+
await waitForNeighbor("Pubsub", this.libp2p.services.pubsub);
|
|
498
|
+
await waitForNeighbor("Blocks", this.libp2p.services.blocks);
|
|
499
|
+
|
|
500
|
+
if (resolvedReadiness === "services-and-fanout") {
|
|
501
|
+
const fanoutService = (this.libp2p.services as any).fanout;
|
|
502
|
+
if (!fanoutService?.waitFor) {
|
|
503
|
+
throw new Error(
|
|
504
|
+
"Failed to dial peer. Not available on Fanout (service missing)",
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
await waitForNeighbor("Fanout", fanoutService);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return true;
|
|
511
|
+
} finally {
|
|
512
|
+
if (dialTimeout) clearTimeout(dialTimeout);
|
|
513
|
+
if (onAbort && options?.signal) {
|
|
514
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
515
|
+
}
|
|
323
516
|
}
|
|
324
|
-
return true;
|
|
325
517
|
}
|
|
326
518
|
|
|
327
519
|
async hangUp(address: PeerId | PublicSignKey | string | Multiaddr) {
|
|
@@ -361,9 +553,78 @@ export class Peerbit implements ProgramClient {
|
|
|
361
553
|
if (_addresses.length === 0) {
|
|
362
554
|
throw new Error("Failed to find any addresses to dial");
|
|
363
555
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
556
|
+
|
|
557
|
+
const extractPeerId = (a: string | Multiaddr): string | undefined => {
|
|
558
|
+
const s = typeof a === "string" ? a : a.toString();
|
|
559
|
+
const m = s.match(/\/(?:p2p|ipfs)\/([^/]+)(?:\/|$)/);
|
|
560
|
+
return m?.[1];
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
// Keep fanout bootstrap config aligned with peer bootstrap config so fanout
|
|
564
|
+
// channels can join via the same rendezvous nodes.
|
|
565
|
+
try {
|
|
566
|
+
this.libp2p.services.fanout.setBootstraps(_addresses);
|
|
567
|
+
} catch {
|
|
568
|
+
// ignore if fanout service is not present/overridden
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// Avoid dialing the same peer multiple times concurrently (multiaddrs often come
|
|
572
|
+
// with both `/tcp` and `/ws` addresses for the same peer). Concurrent dials to
|
|
573
|
+
// the same peer can race internal stream readiness, causing waits to stall.
|
|
574
|
+
const byPeerId = new Map<string, (string | Multiaddr)[]>();
|
|
575
|
+
const unknown: (string | Multiaddr)[] = [];
|
|
576
|
+
for (const a of _addresses) {
|
|
577
|
+
const pid = extractPeerId(a as any);
|
|
578
|
+
if (!pid) {
|
|
579
|
+
unknown.push(a);
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
const list = byPeerId.get(pid) ?? [];
|
|
583
|
+
list.push(a);
|
|
584
|
+
byPeerId.set(pid, list);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const dialTimeoutMs = 30_000;
|
|
588
|
+
const scoreBootstrapAddr = (a: Multiaddr) => {
|
|
589
|
+
const s = a.toString();
|
|
590
|
+
const isCircuit = s.includes("p2p-circuit");
|
|
591
|
+
const isWs = s.includes("/ws") || s.includes("/wss");
|
|
592
|
+
return (isCircuit ? 2 : 0) + (isWs ? 1 : 0);
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
const dialPeer = async (list: (string | Multiaddr)[]) => {
|
|
596
|
+
const maddrs = list
|
|
597
|
+
.map((x) => (typeof x === "string" ? multiaddr(x) : x))
|
|
598
|
+
.sort((a, b) => scoreBootstrapAddr(a) - scoreBootstrapAddr(b));
|
|
599
|
+
let lastError: unknown;
|
|
600
|
+
for (const ma of maddrs) {
|
|
601
|
+
try {
|
|
602
|
+
await this.dial(ma, { dialTimeoutMs });
|
|
603
|
+
return true;
|
|
604
|
+
} catch (e) {
|
|
605
|
+
lastError = e;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
throw lastError ?? new Error("Failed to dial bootstrap peer");
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
const dialTasks: Array<{ label: string[]; promise: Promise<boolean> }> = [];
|
|
612
|
+
for (const list of byPeerId.values()) {
|
|
613
|
+
dialTasks.push({
|
|
614
|
+
label: list.map((x) => (typeof x === "string" ? x : x.toString())),
|
|
615
|
+
promise: dialPeer(list),
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
for (const a of unknown) {
|
|
619
|
+
dialTasks.push({
|
|
620
|
+
label: [typeof a === "string" ? a : a.toString()],
|
|
621
|
+
promise: this.dial(typeof a === "string" ? multiaddr(a) : a, {
|
|
622
|
+
dialTimeoutMs,
|
|
623
|
+
}),
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const settled = await Promise.allSettled(dialTasks.map((t) => t.promise));
|
|
367
628
|
let once = false;
|
|
368
629
|
for (const [i, result] of settled.entries()) {
|
|
369
630
|
if (result.status === "fulfilled") {
|
|
@@ -371,7 +632,7 @@ export class Peerbit implements ProgramClient {
|
|
|
371
632
|
} else {
|
|
372
633
|
logger.error(
|
|
373
634
|
"Failed to dial bootstrap address(s): " +
|
|
374
|
-
JSON.stringify(
|
|
635
|
+
JSON.stringify(dialTasks[i]?.label ?? []) +
|
|
375
636
|
". Reason: " +
|
|
376
637
|
result.reason,
|
|
377
638
|
);
|
|
@@ -380,6 +641,71 @@ export class Peerbit implements ProgramClient {
|
|
|
380
641
|
if (!once) {
|
|
381
642
|
throw new Error("Failed to succefully dial any bootstrap node");
|
|
382
643
|
}
|
|
644
|
+
|
|
645
|
+
// Seed deterministic topic-root candidates for shard root resolution.
|
|
646
|
+
//
|
|
647
|
+
// IMPORTANT: this set must be stable across peers, otherwise different nodes
|
|
648
|
+
// will resolve different roots for the same shard and the overlay will partition.
|
|
649
|
+
//
|
|
650
|
+
// We therefore constrain candidates to the bootstrap peerIds we were asked
|
|
651
|
+
// to dial (and that we successfully connected to).
|
|
652
|
+
const servicesAny: any = this.libp2p.services as any;
|
|
653
|
+
const fanoutPlane = servicesAny?.fanout?.topicRootControlPlane;
|
|
654
|
+
const pubsubPlane = servicesAny?.pubsub?.topicRootControlPlane;
|
|
655
|
+
const planes = [...new Set([fanoutPlane, pubsubPlane].filter(Boolean))];
|
|
656
|
+
if (planes.length > 0) {
|
|
657
|
+
const bootstrapPeerIds = new Set<string>();
|
|
658
|
+
for (const a of _addresses) {
|
|
659
|
+
const pid = extractPeerId(a as any);
|
|
660
|
+
if (pid) bootstrapPeerIds.add(pid);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const candidates = new Set<string>();
|
|
664
|
+
for (const connection of this.libp2p.getConnections()) {
|
|
665
|
+
if (bootstrapPeerIds.size > 0) {
|
|
666
|
+
const remoteId = connection.remotePeer?.toString?.();
|
|
667
|
+
if (!remoteId || !bootstrapPeerIds.has(remoteId)) continue;
|
|
668
|
+
}
|
|
669
|
+
try {
|
|
670
|
+
candidates.add(getPublicKeyFromPeerId(connection.remotePeer).hashcode());
|
|
671
|
+
} catch {
|
|
672
|
+
// ignore peers without a resolvable public key
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
// If this node is itself one of the bootstraps, it won't show up among
|
|
676
|
+
// remote connections; add it explicitly so shard mapping matches other peers.
|
|
677
|
+
try {
|
|
678
|
+
if (bootstrapPeerIds.has(this.libp2p.peerId.toString())) {
|
|
679
|
+
candidates.add(this.services.pubsub.publicKeyHash);
|
|
680
|
+
}
|
|
681
|
+
} catch {
|
|
682
|
+
// ignore
|
|
683
|
+
}
|
|
684
|
+
if (candidates.size > 0) {
|
|
685
|
+
const list = [...candidates];
|
|
686
|
+
// Prefer the pubsub helper so we also disable its auto-candidate mode.
|
|
687
|
+
try {
|
|
688
|
+
(this.services.pubsub as any)?.setTopicRootCandidates?.(list);
|
|
689
|
+
} catch {
|
|
690
|
+
// ignore
|
|
691
|
+
}
|
|
692
|
+
for (const plane of planes) {
|
|
693
|
+
try {
|
|
694
|
+
plane.setTopicRootCandidates(list);
|
|
695
|
+
} catch {
|
|
696
|
+
// ignore
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
// Open shard roots this node is responsible for (no-op for non-candidates).
|
|
700
|
+
try {
|
|
701
|
+
if (list.includes(this.services.pubsub.publicKeyHash)) {
|
|
702
|
+
await this.services.pubsub.hostShardRootsNow();
|
|
703
|
+
}
|
|
704
|
+
} catch {
|
|
705
|
+
// ignore
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
383
709
|
}
|
|
384
710
|
|
|
385
711
|
/**
|
|
@@ -399,6 +725,52 @@ export class Peerbit implements ProgramClient {
|
|
|
399
725
|
).open(storeOrAddress, options);
|
|
400
726
|
}
|
|
401
727
|
|
|
728
|
+
public fanoutChannel(topic: string, root: string = this.services.fanout.publicKeyHash) {
|
|
729
|
+
if (root === this.services.fanout.publicKeyHash) {
|
|
730
|
+
return FanoutChannel.fromSelf(this.services.fanout, topic);
|
|
731
|
+
}
|
|
732
|
+
return new FanoutChannel(this.services.fanout, { topic, root });
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
public async fanoutResolveRoot(topic: string): Promise<string> {
|
|
736
|
+
const servicesAny: any = this.services as any;
|
|
737
|
+
const topicRootControlPlane =
|
|
738
|
+
servicesAny?.fanout?.topicRootControlPlane ||
|
|
739
|
+
servicesAny?.pubsub?.topicRootControlPlane;
|
|
740
|
+
const resolved = await topicRootControlPlane?.resolveTopicRoot?.(topic);
|
|
741
|
+
if (!resolved) {
|
|
742
|
+
throw new Error(
|
|
743
|
+
`Failed to resolve fanout root for topic ${topic}. Configure topic-root candidates/resolver (Peerbit.bootstrap() does this automatically) or pass root explicitly.`,
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
return resolved;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
public fanoutOpenAsRoot(
|
|
750
|
+
topic: string,
|
|
751
|
+
options: Omit<FanoutTreeChannelOptions, "role">,
|
|
752
|
+
) {
|
|
753
|
+
return this.fanoutChannel(topic).openAsRoot(options);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
public fanoutJoin(
|
|
757
|
+
topic: string,
|
|
758
|
+
root: string,
|
|
759
|
+
options: Omit<FanoutTreeChannelOptions, "role">,
|
|
760
|
+
joinOpts?: FanoutTreeJoinOptions,
|
|
761
|
+
) {
|
|
762
|
+
return this.fanoutChannel(topic, root).join(options, joinOpts);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
public async fanoutJoinAuto(
|
|
766
|
+
topic: string,
|
|
767
|
+
options: Omit<FanoutTreeChannelOptions, "role">,
|
|
768
|
+
joinOpts?: FanoutTreeJoinOptions,
|
|
769
|
+
) {
|
|
770
|
+
const root = await this.fanoutResolveRoot(topic);
|
|
771
|
+
return this.fanoutJoin(topic, root, options, joinOpts);
|
|
772
|
+
}
|
|
773
|
+
|
|
402
774
|
get storage() {
|
|
403
775
|
return this._storage;
|
|
404
776
|
}
|