@helia/utils 2.4.2-080e4f91 → 2.4.2-11802dd6
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/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/abstract-session.d.ts +1 -1
- package/dist/src/abstract-session.d.ts.map +1 -1
- package/dist/src/routing.d.ts +10 -9
- package/dist/src/routing.d.ts.map +1 -1
- package/dist/src/routing.js +79 -1
- package/dist/src/routing.js.map +1 -1
- package/package.json +2 -2
- package/src/abstract-session.ts +1 -1
- package/src/routing.ts +100 -11
|
@@ -42,7 +42,7 @@ export declare abstract class AbstractSession<Provider, RetrieveBlockProgressEve
|
|
|
42
42
|
/**
|
|
43
43
|
* This method should search for new providers and yield them.
|
|
44
44
|
*/
|
|
45
|
-
abstract findNewProviders(cid: CID, options:
|
|
45
|
+
abstract findNewProviders(cid: CID, options: BlockRetrievalOptions<RetrieveBlockProgressEvents>): AsyncGenerator<Provider>;
|
|
46
46
|
/**
|
|
47
47
|
* The subclass should contact the provider and request the block from it.
|
|
48
48
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-session.d.ts","sourceRoot":"","sources":["../../src/abstract-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,iBAAiB,EAAmB,MAAM,mBAAmB,CAAA;AAKlF,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAChG,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAEtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,WAAW,yBAAyB;IACxC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,CAAC;IAE/I;;OAEG;IACH,QAAQ,CAAC,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAqB,CAAC,2BAA2B,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC;IAE3H;;;;;;OAMG;IACH,QAAQ,CAAC,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAEjG;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAE,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM;IAE9D;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,GAAG,OAAO;IAEnE;;OAEG;IACH,QAAQ,CAAC,8BAA8B,CAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,CAAC,2BAA2B,CAAC,GAAG,IAAI;CAC1I"}
|
package/dist/src/routing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Routing as RoutingInterface, Provider, RoutingOptions } from '@helia/interface';
|
|
2
|
-
import type {
|
|
1
|
+
import type { Routing as RoutingInterface, Provider, RoutingOptions, RoutingFindProvidersProgressEvents, RoutingProvideProgressEvents, RoutingPutProgressEvents, RoutingGetProgressEvents, RoutingFindPeerProgressEvents, RoutingGetClosestPeersProgressEvents, RoutingCancelReprovideProgressEvents } from '@helia/interface';
|
|
2
|
+
import type { ComponentLogger, Metrics, PeerId, PeerInfo, Startable } from '@libp2p/interface';
|
|
3
3
|
import type { CID } from 'multiformats/cid';
|
|
4
4
|
export interface RoutingInit {
|
|
5
5
|
routers: Array<Partial<RoutingInterface>>;
|
|
@@ -10,6 +10,7 @@ export interface RoutingComponents {
|
|
|
10
10
|
metrics?: Metrics;
|
|
11
11
|
}
|
|
12
12
|
export declare class Routing implements RoutingInterface, Startable {
|
|
13
|
+
name: string;
|
|
13
14
|
private readonly log;
|
|
14
15
|
private readonly routers;
|
|
15
16
|
private readonly providerLookupConcurrency;
|
|
@@ -20,29 +21,29 @@ export declare class Routing implements RoutingInterface, Startable {
|
|
|
20
21
|
* Iterates over all content routers in parallel to find providers of the
|
|
21
22
|
* given key
|
|
22
23
|
*/
|
|
23
|
-
findProviders(key: CID, options?: RoutingOptions): AsyncIterable<Provider>;
|
|
24
|
+
findProviders(key: CID, options?: RoutingOptions<RoutingFindProvidersProgressEvents>): AsyncIterable<Provider>;
|
|
24
25
|
/**
|
|
25
26
|
* Iterates over all content routers in parallel to notify it is
|
|
26
27
|
* a provider of the given key
|
|
27
28
|
*/
|
|
28
|
-
provide(key: CID, options?:
|
|
29
|
-
cancelReprovide(key: CID, options?:
|
|
29
|
+
provide(key: CID, options?: RoutingOptions<RoutingProvideProgressEvents>): Promise<void>;
|
|
30
|
+
cancelReprovide(key: CID, options?: RoutingOptions<RoutingCancelReprovideProgressEvents>): Promise<void>;
|
|
30
31
|
/**
|
|
31
32
|
* Store the given key/value pair in the available content routings
|
|
32
33
|
*/
|
|
33
|
-
put(key: Uint8Array, value: Uint8Array, options?:
|
|
34
|
+
put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void>;
|
|
34
35
|
/**
|
|
35
36
|
* Get the value to the given key. The first value offered by any configured
|
|
36
37
|
* router will be returned.
|
|
37
38
|
*/
|
|
38
|
-
get(key: Uint8Array, options?:
|
|
39
|
+
get(key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array>;
|
|
39
40
|
/**
|
|
40
41
|
* Iterates over all peer routers in parallel to find the given peer
|
|
41
42
|
*/
|
|
42
|
-
findPeer(id: PeerId, options?: RoutingOptions): Promise<PeerInfo>;
|
|
43
|
+
findPeer(id: PeerId, options?: RoutingOptions<RoutingFindPeerProgressEvents>): Promise<PeerInfo>;
|
|
43
44
|
/**
|
|
44
45
|
* Attempt to find the closest peers on the network to the given key
|
|
45
46
|
*/
|
|
46
|
-
getClosestPeers(key: Uint8Array, options?: RoutingOptions): AsyncIterable<PeerInfo>;
|
|
47
|
+
getClosestPeers(key: Uint8Array, options?: RoutingOptions<RoutingGetClosestPeersProgressEvents>): AsyncIterable<PeerInfo>;
|
|
47
48
|
}
|
|
48
49
|
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,IAAI,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,kCAAkC,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,oCAAoC,EAAE,oCAAoC,EAAE,MAAM,kBAAkB,CAAA;AAC9T,OAAO,KAAK,EAAE,eAAe,EAAU,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACtG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAI3C,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAA;IACzC,yBAAyB,CAAC,EAAE,MAAM,CAAA;CACnC;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,qBAAa,OAAQ,YAAW,gBAAgB,EAAE,SAAS;IAClD,IAAI,EAAE,MAAM,CAAA;IAEnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;IAC1D,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAQ;gBAErC,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,WAAW;IA6BvD,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAIvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAI5B;;;OAGG;IACK,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,cAAc,CAAC,kCAAkC,CAAM,GAAG,aAAa,CAAC,QAAQ,CAAC;IAmH3H;;;OAGG;IACG,OAAO,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,cAAc,CAAC,4BAA4B,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB7F,eAAe,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,cAAc,CAAC,oCAAoC,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBnH;;OAEG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBjH;;;OAGG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAqCpG;;OAEG;IACG,QAAQ,CAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,6BAA6B,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;IAsCvG;;OAEG;IACK,eAAe,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,GAAE,cAAc,CAAC,oCAAoC,CAAM,GAAG,aAAa,CAAC,QAAQ,CAAC;CA8BvI"}
|
package/dist/src/routing.js
CHANGED
|
@@ -2,14 +2,17 @@ import { NoRoutersAvailableError } from '@helia/interface';
|
|
|
2
2
|
import { NotFoundError, start, stop } from '@libp2p/interface';
|
|
3
3
|
import { PeerQueue } from '@libp2p/utils';
|
|
4
4
|
import merge from 'it-merge';
|
|
5
|
+
import { CustomProgressEvent } from 'progress-events';
|
|
5
6
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
6
7
|
import { GetFailedError } from "./errors.js";
|
|
7
8
|
const DEFAULT_PROVIDER_LOOKUP_CONCURRENCY = 5;
|
|
8
9
|
export class Routing {
|
|
10
|
+
name;
|
|
9
11
|
log;
|
|
10
12
|
routers;
|
|
11
13
|
providerLookupConcurrency;
|
|
12
14
|
constructor(components, init) {
|
|
15
|
+
this.name = 'helia';
|
|
13
16
|
this.log = components.logger.forComponent('helia:routing');
|
|
14
17
|
this.routers = init.routers ?? [];
|
|
15
18
|
this.providerLookupConcurrency = init.providerLookupConcurrency ?? DEFAULT_PROVIDER_LOOKUP_CONCURRENCY;
|
|
@@ -64,9 +67,19 @@ export class Routing {
|
|
|
64
67
|
const routers = supports(this.routers, 'findProviders')
|
|
65
68
|
.map(async function* (router) {
|
|
66
69
|
let foundProviders = 0;
|
|
70
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:start', {
|
|
71
|
+
routing: router.name,
|
|
72
|
+
cid: key
|
|
73
|
+
}));
|
|
67
74
|
try {
|
|
68
75
|
for await (const prov of router.findProviders(key, options)) {
|
|
69
76
|
foundProviders++;
|
|
77
|
+
// @ts-expect-error router.name is a string, needs to be specific
|
|
78
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:provider', {
|
|
79
|
+
routing: router.name,
|
|
80
|
+
cid: key,
|
|
81
|
+
provider: prov
|
|
82
|
+
}));
|
|
70
83
|
yield prov;
|
|
71
84
|
}
|
|
72
85
|
}
|
|
@@ -75,6 +88,11 @@ export class Routing {
|
|
|
75
88
|
}
|
|
76
89
|
finally {
|
|
77
90
|
self.log('router %s found %d providers for %c', router, foundProviders, key);
|
|
91
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:end', {
|
|
92
|
+
routing: router.name,
|
|
93
|
+
cid: key,
|
|
94
|
+
found: foundProviders
|
|
95
|
+
}));
|
|
78
96
|
routersFinished++;
|
|
79
97
|
// if all routers have finished and there are no jobs to find updated
|
|
80
98
|
// peer multiaddres running or queued, cause the generator to exit
|
|
@@ -135,13 +153,29 @@ export class Routing {
|
|
|
135
153
|
}
|
|
136
154
|
await Promise.all(supports(this.routers, 'provide')
|
|
137
155
|
.map(async (router) => {
|
|
156
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:provide:start', {
|
|
157
|
+
routing: router.name,
|
|
158
|
+
cid: key
|
|
159
|
+
}));
|
|
138
160
|
await router.provide(key, options);
|
|
161
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:provide:end', {
|
|
162
|
+
routing: router.name,
|
|
163
|
+
cid: key
|
|
164
|
+
}));
|
|
139
165
|
}));
|
|
140
166
|
}
|
|
141
167
|
async cancelReprovide(key, options = {}) {
|
|
142
168
|
await Promise.all(supports(this.routers, 'cancelReprovide')
|
|
143
169
|
.map(async (router) => {
|
|
170
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:cancel-reprovide:start', {
|
|
171
|
+
routing: router.name,
|
|
172
|
+
cid: key
|
|
173
|
+
}));
|
|
144
174
|
await router.cancelReprovide(key, options);
|
|
175
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:cancel-reprovide:end', {
|
|
176
|
+
routing: router.name,
|
|
177
|
+
cid: key
|
|
178
|
+
}));
|
|
145
179
|
}));
|
|
146
180
|
}
|
|
147
181
|
/**
|
|
@@ -150,7 +184,17 @@ export class Routing {
|
|
|
150
184
|
async put(key, value, options) {
|
|
151
185
|
await Promise.all(supports(this.routers, 'put')
|
|
152
186
|
.map(async (router) => {
|
|
187
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:put:start', {
|
|
188
|
+
routing: router.name,
|
|
189
|
+
key,
|
|
190
|
+
value
|
|
191
|
+
}));
|
|
153
192
|
await router.put(key, value, options);
|
|
193
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:put:end', {
|
|
194
|
+
routing: router.name,
|
|
195
|
+
key,
|
|
196
|
+
value
|
|
197
|
+
}));
|
|
154
198
|
}));
|
|
155
199
|
}
|
|
156
200
|
/**
|
|
@@ -163,6 +207,10 @@ export class Routing {
|
|
|
163
207
|
try {
|
|
164
208
|
result = await Promise.any(supports(this.routers, 'get')
|
|
165
209
|
.map(async (router) => {
|
|
210
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get:start', {
|
|
211
|
+
routing: router.name,
|
|
212
|
+
key
|
|
213
|
+
}));
|
|
166
214
|
try {
|
|
167
215
|
return await router.get(key, options);
|
|
168
216
|
}
|
|
@@ -170,6 +218,12 @@ export class Routing {
|
|
|
170
218
|
this.log('router %s failed with %e', router, err);
|
|
171
219
|
errors.push(err);
|
|
172
220
|
}
|
|
221
|
+
finally {
|
|
222
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get:end', {
|
|
223
|
+
routing: router.name,
|
|
224
|
+
key
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
173
227
|
}));
|
|
174
228
|
}
|
|
175
229
|
catch {
|
|
@@ -190,12 +244,22 @@ export class Routing {
|
|
|
190
244
|
const self = this;
|
|
191
245
|
const source = merge(...supports(this.routers, 'findPeer')
|
|
192
246
|
.map(router => (async function* () {
|
|
247
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-peer:start', {
|
|
248
|
+
routing: router.name,
|
|
249
|
+
peerId: id
|
|
250
|
+
}));
|
|
193
251
|
try {
|
|
194
252
|
yield await router.findPeer(id, options);
|
|
195
253
|
}
|
|
196
254
|
catch (err) {
|
|
197
255
|
self.log.error(err);
|
|
198
256
|
}
|
|
257
|
+
finally {
|
|
258
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-peer:end', {
|
|
259
|
+
routing: router.name,
|
|
260
|
+
peerId: id
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
199
263
|
})()));
|
|
200
264
|
for await (const peer of source) {
|
|
201
265
|
if (peer == null) {
|
|
@@ -213,7 +277,21 @@ export class Routing {
|
|
|
213
277
|
throw new NoRoutersAvailableError('No peer routers available');
|
|
214
278
|
}
|
|
215
279
|
for await (const peer of merge(...supports(this.routers, 'getClosestPeers')
|
|
216
|
-
.map(
|
|
280
|
+
.map(async function* (router) {
|
|
281
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get-closest-peers:start', {
|
|
282
|
+
routing: router.name,
|
|
283
|
+
key
|
|
284
|
+
}));
|
|
285
|
+
try {
|
|
286
|
+
yield* router.getClosestPeers(key, options);
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get-closest-peers:end', {
|
|
290
|
+
routing: router.name,
|
|
291
|
+
key
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
}))) {
|
|
217
295
|
if (peer == null) {
|
|
218
296
|
continue;
|
|
219
297
|
}
|
package/dist/src/routing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAK5C,MAAM,mCAAmC,GAAG,CAAC,CAAA;AAY7C,MAAM,OAAO,OAAO;
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,a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AAI,CAAA;QACZ,CAAC;IACH,CAAC;CACF;AAED,SAAS,QAAQ,CAAoC,OAAc,EAAE,GAAc;IACjF,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAA;AACtD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/utils",
|
|
3
|
-
"version": "2.4.2-
|
|
3
|
+
"version": "2.4.2-11802dd6",
|
|
4
4
|
"description": "Shared code that implements the Helia API",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/utils#readme",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"test:electron-main": "aegir test -t electron-main"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@helia/interface": "6.1.1-
|
|
50
|
+
"@helia/interface": "6.1.1-11802dd6",
|
|
51
51
|
"@ipld/dag-cbor": "^9.2.5",
|
|
52
52
|
"@ipld/dag-json": "^10.2.5",
|
|
53
53
|
"@ipld/dag-pb": "^4.1.5",
|
package/src/abstract-session.ts
CHANGED
|
@@ -406,7 +406,7 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
|
|
|
406
406
|
/**
|
|
407
407
|
* This method should search for new providers and yield them.
|
|
408
408
|
*/
|
|
409
|
-
abstract findNewProviders (cid: CID, options:
|
|
409
|
+
abstract findNewProviders (cid: CID, options: BlockRetrievalOptions<RetrieveBlockProgressEvents>): AsyncGenerator<Provider>
|
|
410
410
|
|
|
411
411
|
/**
|
|
412
412
|
* The subclass should contact the provider and request the block from it.
|
package/src/routing.ts
CHANGED
|
@@ -2,10 +2,11 @@ import { NoRoutersAvailableError } from '@helia/interface'
|
|
|
2
2
|
import { NotFoundError, start, stop } from '@libp2p/interface'
|
|
3
3
|
import { PeerQueue } from '@libp2p/utils'
|
|
4
4
|
import merge from 'it-merge'
|
|
5
|
+
import { CustomProgressEvent } from 'progress-events'
|
|
5
6
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
6
7
|
import { GetFailedError } from './errors.ts'
|
|
7
|
-
import type { Routing as RoutingInterface, Provider, RoutingOptions } from '@helia/interface'
|
|
8
|
-
import type {
|
|
8
|
+
import type { Routing as RoutingInterface, Provider, RoutingOptions, RoutingFindProvidersProgressEvents, RoutingProvideProgressEvents, RoutingPutProgressEvents, RoutingGetProgressEvents, RoutingFindPeerProgressEvents, RoutingGetClosestPeersProgressEvents, RoutingCancelReprovideProgressEvents } from '@helia/interface'
|
|
9
|
+
import type { ComponentLogger, Logger, Metrics, PeerId, PeerInfo, Startable } from '@libp2p/interface'
|
|
9
10
|
import type { CID } from 'multiformats/cid'
|
|
10
11
|
|
|
11
12
|
const DEFAULT_PROVIDER_LOOKUP_CONCURRENCY = 5
|
|
@@ -21,11 +22,14 @@ export interface RoutingComponents {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export class Routing implements RoutingInterface, Startable {
|
|
25
|
+
public name: string
|
|
26
|
+
|
|
24
27
|
private readonly log: Logger
|
|
25
28
|
private readonly routers: Array<Partial<RoutingInterface>>
|
|
26
29
|
private readonly providerLookupConcurrency: number
|
|
27
30
|
|
|
28
31
|
constructor (components: RoutingComponents, init: RoutingInit) {
|
|
32
|
+
this.name = 'helia'
|
|
29
33
|
this.log = components.logger.forComponent('helia:routing')
|
|
30
34
|
this.routers = init.routers ?? []
|
|
31
35
|
this.providerLookupConcurrency = init.providerLookupConcurrency ?? DEFAULT_PROVIDER_LOOKUP_CONCURRENCY
|
|
@@ -65,7 +69,7 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
65
69
|
* Iterates over all content routers in parallel to find providers of the
|
|
66
70
|
* given key
|
|
67
71
|
*/
|
|
68
|
-
async * findProviders (key: CID, options: RoutingOptions = {}): AsyncIterable<Provider> {
|
|
72
|
+
async * findProviders (key: CID, options: RoutingOptions<RoutingFindProvidersProgressEvents> = {}): AsyncIterable<Provider> {
|
|
69
73
|
if (this.routers.length === 0) {
|
|
70
74
|
throw new NoRoutersAvailableError('No content routers available')
|
|
71
75
|
}
|
|
@@ -89,9 +93,22 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
89
93
|
.map(async function * (router) {
|
|
90
94
|
let foundProviders = 0
|
|
91
95
|
|
|
96
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:start', {
|
|
97
|
+
routing: router.name,
|
|
98
|
+
cid: key
|
|
99
|
+
}))
|
|
100
|
+
|
|
92
101
|
try {
|
|
93
102
|
for await (const prov of router.findProviders(key, options)) {
|
|
94
103
|
foundProviders++
|
|
104
|
+
|
|
105
|
+
// @ts-expect-error router.name is a string, needs to be specific
|
|
106
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:provider', {
|
|
107
|
+
routing: router.name,
|
|
108
|
+
cid: key,
|
|
109
|
+
provider: prov
|
|
110
|
+
}))
|
|
111
|
+
|
|
95
112
|
yield prov
|
|
96
113
|
}
|
|
97
114
|
} catch (err: any) {
|
|
@@ -99,6 +116,12 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
99
116
|
} finally {
|
|
100
117
|
self.log('router %s found %d providers for %c', router, foundProviders, key)
|
|
101
118
|
|
|
119
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:end', {
|
|
120
|
+
routing: router.name,
|
|
121
|
+
cid: key,
|
|
122
|
+
found: foundProviders
|
|
123
|
+
}))
|
|
124
|
+
|
|
102
125
|
routersFinished++
|
|
103
126
|
|
|
104
127
|
// if all routers have finished and there are no jobs to find updated
|
|
@@ -165,7 +188,7 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
165
188
|
* Iterates over all content routers in parallel to notify it is
|
|
166
189
|
* a provider of the given key
|
|
167
190
|
*/
|
|
168
|
-
async provide (key: CID, options:
|
|
191
|
+
async provide (key: CID, options: RoutingOptions<RoutingProvideProgressEvents> = {}): Promise<void> {
|
|
169
192
|
if (this.routers.length === 0) {
|
|
170
193
|
throw new NoRoutersAvailableError('No content routers available')
|
|
171
194
|
}
|
|
@@ -173,16 +196,36 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
173
196
|
await Promise.all(
|
|
174
197
|
supports(this.routers, 'provide')
|
|
175
198
|
.map(async (router) => {
|
|
199
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:provide:start', {
|
|
200
|
+
routing: router.name,
|
|
201
|
+
cid: key
|
|
202
|
+
}))
|
|
203
|
+
|
|
176
204
|
await router.provide(key, options)
|
|
205
|
+
|
|
206
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:provide:end', {
|
|
207
|
+
routing: router.name,
|
|
208
|
+
cid: key
|
|
209
|
+
}))
|
|
177
210
|
})
|
|
178
211
|
)
|
|
179
212
|
}
|
|
180
213
|
|
|
181
|
-
async cancelReprovide (key: CID, options:
|
|
214
|
+
async cancelReprovide (key: CID, options: RoutingOptions<RoutingCancelReprovideProgressEvents> = {}): Promise<void> {
|
|
182
215
|
await Promise.all(
|
|
183
216
|
supports(this.routers, 'cancelReprovide')
|
|
184
217
|
.map(async (router) => {
|
|
218
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:cancel-reprovide:start', {
|
|
219
|
+
routing: router.name,
|
|
220
|
+
cid: key
|
|
221
|
+
}))
|
|
222
|
+
|
|
185
223
|
await router.cancelReprovide(key, options)
|
|
224
|
+
|
|
225
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:cancel-reprovide:end', {
|
|
226
|
+
routing: router.name,
|
|
227
|
+
cid: key
|
|
228
|
+
}))
|
|
186
229
|
})
|
|
187
230
|
)
|
|
188
231
|
}
|
|
@@ -190,11 +233,23 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
190
233
|
/**
|
|
191
234
|
* Store the given key/value pair in the available content routings
|
|
192
235
|
*/
|
|
193
|
-
async put (key: Uint8Array, value: Uint8Array, options?:
|
|
236
|
+
async put (key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void> {
|
|
194
237
|
await Promise.all(
|
|
195
238
|
supports(this.routers, 'put')
|
|
196
239
|
.map(async (router) => {
|
|
240
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:put:start', {
|
|
241
|
+
routing: router.name,
|
|
242
|
+
key,
|
|
243
|
+
value
|
|
244
|
+
}))
|
|
245
|
+
|
|
197
246
|
await router.put(key, value, options)
|
|
247
|
+
|
|
248
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:put:end', {
|
|
249
|
+
routing: router.name,
|
|
250
|
+
key,
|
|
251
|
+
value
|
|
252
|
+
}))
|
|
198
253
|
})
|
|
199
254
|
)
|
|
200
255
|
}
|
|
@@ -203,7 +258,7 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
203
258
|
* Get the value to the given key. The first value offered by any configured
|
|
204
259
|
* router will be returned.
|
|
205
260
|
*/
|
|
206
|
-
async get (key: Uint8Array, options?:
|
|
261
|
+
async get (key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array> {
|
|
207
262
|
const errors: Error[] = []
|
|
208
263
|
let result: Uint8Array | undefined
|
|
209
264
|
|
|
@@ -211,11 +266,21 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
211
266
|
result = await Promise.any(
|
|
212
267
|
supports(this.routers, 'get')
|
|
213
268
|
.map(async (router) => {
|
|
269
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get:start', {
|
|
270
|
+
routing: router.name,
|
|
271
|
+
key
|
|
272
|
+
}))
|
|
273
|
+
|
|
214
274
|
try {
|
|
215
275
|
return await router.get(key, options)
|
|
216
276
|
} catch (err: any) {
|
|
217
277
|
this.log('router %s failed with %e', router, err)
|
|
218
278
|
errors.push(err)
|
|
279
|
+
} finally {
|
|
280
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get:end', {
|
|
281
|
+
routing: router.name,
|
|
282
|
+
key
|
|
283
|
+
}))
|
|
219
284
|
}
|
|
220
285
|
})
|
|
221
286
|
)
|
|
@@ -233,7 +298,7 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
233
298
|
/**
|
|
234
299
|
* Iterates over all peer routers in parallel to find the given peer
|
|
235
300
|
*/
|
|
236
|
-
async findPeer (id: PeerId, options?: RoutingOptions): Promise<PeerInfo> {
|
|
301
|
+
async findPeer (id: PeerId, options?: RoutingOptions<RoutingFindPeerProgressEvents>): Promise<PeerInfo> {
|
|
237
302
|
if (this.routers.length === 0) {
|
|
238
303
|
throw new NoRoutersAvailableError('No peer routers available')
|
|
239
304
|
}
|
|
@@ -242,10 +307,20 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
242
307
|
const source = merge(
|
|
243
308
|
...supports(this.routers, 'findPeer')
|
|
244
309
|
.map(router => (async function * () {
|
|
310
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-peer:start', {
|
|
311
|
+
routing: router.name,
|
|
312
|
+
peerId: id
|
|
313
|
+
}))
|
|
314
|
+
|
|
245
315
|
try {
|
|
246
316
|
yield await router.findPeer(id, options)
|
|
247
317
|
} catch (err) {
|
|
248
318
|
self.log.error(err)
|
|
319
|
+
} finally {
|
|
320
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:find-peer:end', {
|
|
321
|
+
routing: router.name,
|
|
322
|
+
peerId: id
|
|
323
|
+
}))
|
|
249
324
|
}
|
|
250
325
|
})())
|
|
251
326
|
)
|
|
@@ -264,14 +339,28 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
264
339
|
/**
|
|
265
340
|
* Attempt to find the closest peers on the network to the given key
|
|
266
341
|
*/
|
|
267
|
-
async * getClosestPeers (key: Uint8Array, options: RoutingOptions = {}): AsyncIterable<PeerInfo> {
|
|
342
|
+
async * getClosestPeers (key: Uint8Array, options: RoutingOptions<RoutingGetClosestPeersProgressEvents> = {}): AsyncIterable<PeerInfo> {
|
|
268
343
|
if (this.routers.length === 0) {
|
|
269
344
|
throw new NoRoutersAvailableError('No peer routers available')
|
|
270
345
|
}
|
|
271
346
|
|
|
272
347
|
for await (const peer of merge(
|
|
273
348
|
...supports(this.routers, 'getClosestPeers')
|
|
274
|
-
.map(
|
|
349
|
+
.map(async function * (router) {
|
|
350
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get-closest-peers:start', {
|
|
351
|
+
routing: router.name,
|
|
352
|
+
key
|
|
353
|
+
}))
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
yield * router.getClosestPeers(key, options)
|
|
357
|
+
} finally {
|
|
358
|
+
options?.onProgress?.(new CustomProgressEvent('helia:routing:get-closest-peers:end', {
|
|
359
|
+
routing: router.name,
|
|
360
|
+
key
|
|
361
|
+
}))
|
|
362
|
+
}
|
|
363
|
+
})
|
|
275
364
|
)) {
|
|
276
365
|
if (peer == null) {
|
|
277
366
|
continue
|
|
@@ -282,6 +371,6 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
282
371
|
}
|
|
283
372
|
}
|
|
284
373
|
|
|
285
|
-
function supports <Operation extends keyof Routing> (routers: any[], key: Operation): Array<Pick<Routing, Operation>> {
|
|
374
|
+
function supports <Operation extends keyof Routing> (routers: any[], key: Operation): Array<Pick<Routing, Operation | 'name'>> {
|
|
286
375
|
return routers.filter(router => router[key] != null)
|
|
287
376
|
}
|