@helia/utils 2.4.2 → 2.5.0-ef5363e8
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/abstract-session.js +39 -57
- package/dist/src/abstract-session.js.map +1 -1
- package/dist/src/graph-walker.d.ts +1 -1
- package/dist/src/graph-walker.d.ts.map +1 -1
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.js +8 -8
- 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/dist/src/storage.js +1 -1
- package/dist/src/utils/datastore-version.js +1 -1
- package/dist/src/utils/get-codec.js +1 -1
- package/dist/src/utils/get-hasher.js +1 -1
- package/dist/src/utils/storage.js +1 -1
- package/package.json +33 -32
- package/src/abstract-session.ts +41 -63
- package/src/graph-walker.ts +1 -1
- package/src/index.ts +10 -10
- package/src/routing.ts +100 -11
- package/src/storage.ts +1 -1
- package/src/utils/datastore-version.ts +1 -1
- package/src/utils/get-codec.ts +1 -1
- package/src/utils/get-hasher.ts +1 -1
- package/src/utils/storage.ts +1 -1
- package/dist/typedoc-urls.json +0 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-ef5363e8",
|
|
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",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./dist/src/index.d.ts",
|
|
32
|
-
"import": "./dist/src/index.js"
|
|
32
|
+
"import": "./dist/src/index.js",
|
|
33
|
+
"module-sync": "./dist/src/index.js"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"scripts": {
|
|
@@ -47,45 +48,45 @@
|
|
|
47
48
|
"test:electron-main": "aegir test -t electron-main"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"@helia/interface": "
|
|
51
|
-
"@ipld/dag-cbor": "^9.2.
|
|
52
|
-
"@ipld/dag-json": "^10.2.
|
|
51
|
+
"@helia/interface": "6.2.0-ef5363e8",
|
|
52
|
+
"@ipld/dag-cbor": "^9.2.6",
|
|
53
|
+
"@ipld/dag-json": "^10.2.7",
|
|
53
54
|
"@ipld/dag-pb": "^4.1.5",
|
|
54
|
-
"@libp2p/interface": "^3.
|
|
55
|
-
"@libp2p/keychain": "^6.0.
|
|
56
|
-
"@libp2p/utils": "^7.0.
|
|
57
|
-
"@multiformats/dns": "^1.0.
|
|
55
|
+
"@libp2p/interface": "^3.2.0",
|
|
56
|
+
"@libp2p/keychain": "^6.0.12",
|
|
57
|
+
"@libp2p/utils": "^7.0.15",
|
|
58
|
+
"@multiformats/dns": "^1.0.13",
|
|
58
59
|
"@multiformats/multiaddr": "^13.0.1",
|
|
59
|
-
"any-signal": "^4.
|
|
60
|
-
"blockstore-core": "^6.1.
|
|
61
|
-
"cborg": "^
|
|
62
|
-
"interface-blockstore": "^6.0.
|
|
63
|
-
"interface-datastore": "^9.0.
|
|
64
|
-
"interface-store": "^7.0.
|
|
65
|
-
"it-drain": "^3.0.
|
|
66
|
-
"it-filter": "^3.1.
|
|
67
|
-
"it-foreach": "^2.1.
|
|
68
|
-
"it-merge": "^3.0.
|
|
69
|
-
"it-to-buffer": "^4.0.
|
|
70
|
-
"libp2p": "^3.0
|
|
60
|
+
"any-signal": "^4.2.0",
|
|
61
|
+
"blockstore-core": "^6.1.3",
|
|
62
|
+
"cborg": "^5.1.0",
|
|
63
|
+
"interface-blockstore": "^6.0.2",
|
|
64
|
+
"interface-datastore": "^9.0.3",
|
|
65
|
+
"interface-store": "^7.0.2",
|
|
66
|
+
"it-drain": "^3.0.12",
|
|
67
|
+
"it-filter": "^3.1.5",
|
|
68
|
+
"it-foreach": "^2.1.6",
|
|
69
|
+
"it-merge": "^3.0.13",
|
|
70
|
+
"it-to-buffer": "^4.0.12",
|
|
71
|
+
"libp2p": "^3.2.0",
|
|
71
72
|
"mortice": "^3.3.1",
|
|
72
|
-
"multiformats": "^13.4.
|
|
73
|
+
"multiformats": "^13.4.2",
|
|
73
74
|
"p-defer": "^4.0.1",
|
|
74
|
-
"progress-events": "^1.0
|
|
75
|
+
"progress-events": "^1.1.0",
|
|
75
76
|
"race-signal": "^2.0.0",
|
|
76
77
|
"uint8arrays": "^5.1.0"
|
|
77
78
|
},
|
|
78
79
|
"devDependencies": {
|
|
79
|
-
"@libp2p/crypto": "^5.1.
|
|
80
|
-
"@libp2p/logger": "^6.
|
|
81
|
-
"@libp2p/peer-id": "^6.0.
|
|
82
|
-
"@types/sinon": "^21.0.
|
|
83
|
-
"aegir": "^47.
|
|
84
|
-
"datastore-core": "^11.0.
|
|
80
|
+
"@libp2p/crypto": "^5.1.15",
|
|
81
|
+
"@libp2p/logger": "^6.2.4",
|
|
82
|
+
"@libp2p/peer-id": "^6.0.6",
|
|
83
|
+
"@types/sinon": "^21.0.1",
|
|
84
|
+
"aegir": "^47.1.5",
|
|
85
|
+
"datastore-core": "^11.0.3",
|
|
85
86
|
"delay": "^7.0.0",
|
|
86
|
-
"it-all": "^3.0.
|
|
87
|
-
"it-map": "^3.1.
|
|
88
|
-
"sinon": "^21.
|
|
87
|
+
"it-all": "^3.0.11",
|
|
88
|
+
"it-map": "^3.1.5",
|
|
89
|
+
"sinon": "^21.1.0",
|
|
89
90
|
"sinon-ts": "^2.0.0"
|
|
90
91
|
},
|
|
91
92
|
"browser": {
|
package/src/abstract-session.ts
CHANGED
|
@@ -239,7 +239,7 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
|
|
|
239
239
|
options.signal?.addEventListener('abort', signalAbortedListener)
|
|
240
240
|
|
|
241
241
|
try {
|
|
242
|
-
return await
|
|
242
|
+
return await deferred.promise
|
|
243
243
|
} finally {
|
|
244
244
|
this.removeEventListener('provider', peerAddedToSessionListener)
|
|
245
245
|
options.signal?.removeEventListener('abort', signalAbortedListener)
|
|
@@ -302,90 +302,68 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
|
|
|
302
302
|
.then(async () => {
|
|
303
303
|
this.log('finding %d-%d new provider(s) for %c - %d initial providers', count, this.maxProviders, cid, this.initialProviders.length)
|
|
304
304
|
|
|
305
|
+
const self = this
|
|
306
|
+
|
|
305
307
|
// process any specific providers for this session
|
|
306
|
-
|
|
307
|
-
while (
|
|
308
|
-
const
|
|
308
|
+
const initialProviders = async function * (): AsyncGenerator<Provider> {
|
|
309
|
+
while (self.initialProviders.length > 0) {
|
|
310
|
+
const initialProvider = self.initialProviders.pop()
|
|
309
311
|
|
|
310
|
-
if (
|
|
311
|
-
|
|
312
|
+
if (initialProvider == null) {
|
|
313
|
+
continue
|
|
312
314
|
}
|
|
313
315
|
|
|
314
|
-
const provider = await
|
|
315
|
-
|
|
316
|
-
if (options.signal?.aborted === true) {
|
|
317
|
-
break
|
|
318
|
-
}
|
|
316
|
+
const provider = await self.convertToProvider(initialProvider, 'manual', options)
|
|
319
317
|
|
|
320
318
|
if (provider == null) {
|
|
321
319
|
continue
|
|
322
320
|
}
|
|
323
321
|
|
|
324
|
-
|
|
325
|
-
continue
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
this.log('found %d/%d new providers', found, this.maxProviders)
|
|
329
|
-
this.providers.push(provider)
|
|
330
|
-
|
|
331
|
-
// let the new peer join current queries
|
|
332
|
-
this.safeDispatchEvent('provider', {
|
|
333
|
-
detail: provider
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
found++
|
|
337
|
-
|
|
338
|
-
if (found === count) {
|
|
339
|
-
this.log('session is ready with %d peer(s), only initial peers present', count)
|
|
340
|
-
deferred.resolve()
|
|
341
|
-
// continue finding peers until we reach this.maxProviders
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
if (this.providers.length === this.maxProviders) {
|
|
345
|
-
this.log('found max session peers', found)
|
|
346
|
-
break
|
|
347
|
-
}
|
|
322
|
+
yield provider
|
|
348
323
|
}
|
|
349
324
|
}
|
|
350
325
|
|
|
326
|
+
const providers = async function * (): AsyncGenerator<Provider> {
|
|
327
|
+
yield * initialProviders()
|
|
328
|
+
yield * self.findNewProviders(cid, options)
|
|
329
|
+
}
|
|
330
|
+
|
|
351
331
|
// still not got enough providers, search routing for more
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
332
|
+
for await (const provider of providers()) {
|
|
333
|
+
if (this.providers.length === this.maxProviders || options.signal?.aborted === true) {
|
|
334
|
+
break
|
|
335
|
+
}
|
|
357
336
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
337
|
+
if (this.hasProvider(provider)) {
|
|
338
|
+
continue
|
|
339
|
+
}
|
|
361
340
|
|
|
362
|
-
|
|
363
|
-
|
|
341
|
+
this.log('found %d providers, %d in session', found, this.providers.length)
|
|
342
|
+
this.providers.push(provider)
|
|
364
343
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
344
|
+
// let the new peer join current queries
|
|
345
|
+
this.safeDispatchEvent('provider', {
|
|
346
|
+
detail: provider
|
|
347
|
+
})
|
|
369
348
|
|
|
370
|
-
|
|
349
|
+
found++
|
|
371
350
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
351
|
+
if (this.providers.length === count) {
|
|
352
|
+
this.log('session is ready with %d peer(s), new peers present', this.providers.length)
|
|
353
|
+
deferred.resolve()
|
|
354
|
+
// continue finding peers until we reach this.maxProviders
|
|
355
|
+
}
|
|
377
356
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
357
|
+
if (this.providers.length === this.maxProviders) {
|
|
358
|
+
this.log('found max session peers %d', this.providers.length)
|
|
359
|
+
break
|
|
382
360
|
}
|
|
383
361
|
}
|
|
384
362
|
|
|
385
|
-
this.log('found %d
|
|
363
|
+
this.log('found %d new session peers while trying to find %d, %d in session', found, count, this.providers.length)
|
|
386
364
|
|
|
387
|
-
if (
|
|
388
|
-
throw new InsufficientProvidersError(`Found ${found} of ${count} ${this.name} providers for ${cid}`)
|
|
365
|
+
if (this.providers.length < count) {
|
|
366
|
+
throw new InsufficientProvidersError(`Found ${found} of ${count} ${this.name} providers for ${cid}, ${this.providers.length} in session after evictions`)
|
|
389
367
|
}
|
|
390
368
|
})
|
|
391
369
|
.catch(err => {
|
|
@@ -406,7 +384,7 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
|
|
|
406
384
|
/**
|
|
407
385
|
* This method should search for new providers and yield them.
|
|
408
386
|
*/
|
|
409
|
-
abstract findNewProviders (cid: CID, options:
|
|
387
|
+
abstract findNewProviders (cid: CID, options: BlockRetrievalOptions<RetrieveBlockProgressEvents>): AsyncGenerator<Provider>
|
|
410
388
|
|
|
411
389
|
/**
|
|
412
390
|
* The subclass should contact the provider and request the block from it.
|
package/src/graph-walker.ts
CHANGED
|
@@ -3,8 +3,8 @@ import filter from 'it-filter'
|
|
|
3
3
|
import toBuffer from 'it-to-buffer'
|
|
4
4
|
import { createUnsafe } from 'multiformats/block'
|
|
5
5
|
import type { CodecLoader } from '@helia/interface'
|
|
6
|
+
import type { AbortOptions } from '@libp2p/interface'
|
|
6
7
|
import type { Blockstore } from 'interface-blockstore'
|
|
7
|
-
import type { AbortOptions } from 'interface-store'
|
|
8
8
|
import type { BlockView, CID, Version } from 'multiformats'
|
|
9
9
|
|
|
10
10
|
export interface GraphWalkerComponents {
|
package/src/index.ts
CHANGED
|
@@ -9,14 +9,14 @@ import { contentRoutingSymbol, peerRoutingSymbol, start, stop, TypedEventEmitter
|
|
|
9
9
|
import { dns } from '@multiformats/dns'
|
|
10
10
|
import drain from 'it-drain'
|
|
11
11
|
import { CustomProgressEvent } from 'progress-events'
|
|
12
|
-
import { PinsImpl } from './pins.
|
|
13
|
-
import { Routing as RoutingClass } from './routing.
|
|
14
|
-
import { BlockStorage } from './storage.
|
|
15
|
-
import { assertDatastoreVersionIsCurrent } from './utils/datastore-version.
|
|
16
|
-
import { getCodec } from './utils/get-codec.
|
|
17
|
-
import { getHasher } from './utils/get-hasher.
|
|
18
|
-
import { NetworkedStorage } from './utils/networked-storage.
|
|
19
|
-
import type { BlockStorageInit } from './storage.
|
|
12
|
+
import { PinsImpl } from './pins.ts'
|
|
13
|
+
import { Routing as RoutingClass } from './routing.ts'
|
|
14
|
+
import { BlockStorage } from './storage.ts'
|
|
15
|
+
import { assertDatastoreVersionIsCurrent } from './utils/datastore-version.ts'
|
|
16
|
+
import { getCodec } from './utils/get-codec.ts'
|
|
17
|
+
import { getHasher } from './utils/get-hasher.ts'
|
|
18
|
+
import { NetworkedStorage } from './utils/networked-storage.ts'
|
|
19
|
+
import type { BlockStorageInit } from './storage.ts'
|
|
20
20
|
import type { Await, CodecLoader, GCOptions, HasherLoader, Helia as HeliaInterface, HeliaEvents, Routing } from '@helia/interface'
|
|
21
21
|
import type { BlockBroker } from '@helia/interface/blocks'
|
|
22
22
|
import type { Pins } from '@helia/interface/pins'
|
|
@@ -30,8 +30,8 @@ import type { BlockCodec } from 'multiformats'
|
|
|
30
30
|
import type { CID } from 'multiformats/cid'
|
|
31
31
|
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
32
32
|
|
|
33
|
-
export { AbstractSession } from './abstract-session.
|
|
34
|
-
export type { AbstractCreateSessionOptions, BlockstoreSessionEvents, AbstractSessionComponents } from './abstract-session.
|
|
33
|
+
export { AbstractSession } from './abstract-session.ts'
|
|
34
|
+
export type { AbstractCreateSessionOptions, BlockstoreSessionEvents, AbstractSessionComponents } from './abstract-session.ts'
|
|
35
35
|
|
|
36
36
|
export type { BlockStorage, BlockStorageInit }
|
|
37
37
|
|
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
|
}
|
package/src/storage.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { start, stop } from '@libp2p/interface'
|
|
2
2
|
import createMortice from 'mortice'
|
|
3
|
-
import { BlockPinnedError } from './errors.
|
|
3
|
+
import { BlockPinnedError } from './errors.ts'
|
|
4
4
|
import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, SessionBlockstore } from '@helia/interface/blocks'
|
|
5
5
|
import type { Pins } from '@helia/interface/pins'
|
|
6
6
|
import type { AbortOptions, Startable } from '@libp2p/interface'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Key } from 'interface-datastore'
|
|
2
2
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
3
3
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
4
|
-
import { InvalidDatastoreVersionError } from '../errors.
|
|
4
|
+
import { InvalidDatastoreVersionError } from '../errors.ts'
|
|
5
5
|
import type { Datastore } from 'interface-datastore'
|
|
6
6
|
|
|
7
7
|
const DS_VERSION_KEY = new Key('/version')
|
package/src/utils/get-codec.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as dagJson from '@ipld/dag-json'
|
|
|
6
6
|
import * as dagPb from '@ipld/dag-pb'
|
|
7
7
|
import * as json from 'multiformats/codecs/json'
|
|
8
8
|
import * as raw from 'multiformats/codecs/raw'
|
|
9
|
-
import { isPromise } from './is-promise.
|
|
9
|
+
import { isPromise } from './is-promise.ts'
|
|
10
10
|
import type { Await } from '@helia/interface'
|
|
11
11
|
import type { BlockCodec } from 'multiformats/codecs/interface'
|
|
12
12
|
|
package/src/utils/get-hasher.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UnknownHashAlgorithmError } from '@helia/interface'
|
|
2
2
|
import { identity } from 'multiformats/hashes/identity'
|
|
3
3
|
import { sha256, sha512 } from 'multiformats/hashes/sha2'
|
|
4
|
-
import { isPromise } from './is-promise.
|
|
4
|
+
import { isPromise } from './is-promise.ts'
|
|
5
5
|
import type { Await } from '@helia/interface'
|
|
6
6
|
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
7
7
|
|
package/src/utils/storage.ts
CHANGED
|
@@ -6,7 +6,7 @@ import forEach from 'it-foreach'
|
|
|
6
6
|
import { CustomProgressEvent } from 'progress-events'
|
|
7
7
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
8
8
|
import { BlockNotFoundWhileOfflineError, InvalidConfigurationError, LoadBlockFailedError } from '../errors.ts'
|
|
9
|
-
import { isPromise } from './is-promise.
|
|
9
|
+
import { isPromise } from './is-promise.ts'
|
|
10
10
|
import type { HasherLoader } from '@helia/interface'
|
|
11
11
|
import type { BlockBroker, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, BlockRetrievalOptions } from '@helia/interface/blocks'
|
|
12
12
|
import type { AbortOptions, ComponentLogger, Logger, LoggerOptions } from '@libp2p/interface'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"GraphWalker": "https://ipfs.github.io/helia/interfaces/_helia_car.GraphWalker.html",
|
|
3
|
-
"breadthFirstWalker": "https://ipfs.github.io/helia/functions/_helia_car.breadthFirstWalker.html",
|
|
4
|
-
"depthFirstWalker": "https://ipfs.github.io/helia/functions/_helia_car.depthFirstWalker.html",
|
|
5
|
-
"naturalOrderWalker": "https://ipfs.github.io/helia/functions/_helia_car.naturalOrderWalker.html",
|
|
6
|
-
"AbstractSession": "https://ipfs.github.io/helia/classes/_helia_utils.AbstractSession.html",
|
|
7
|
-
"Helia": "https://ipfs.github.io/helia/classes/_helia_utils.Helia.html",
|
|
8
|
-
".:Helia": "https://ipfs.github.io/helia/classes/_helia_utils.Helia.html",
|
|
9
|
-
"AbstractCreateSessionOptions": "https://ipfs.github.io/helia/interfaces/_helia_utils.AbstractCreateSessionOptions.html",
|
|
10
|
-
"AbstractSessionComponents": "https://ipfs.github.io/helia/interfaces/_helia_utils.AbstractSessionComponents.html",
|
|
11
|
-
"BlockStorage": "https://ipfs.github.io/helia/interfaces/_helia_utils.BlockStorage.html",
|
|
12
|
-
"BlockStorageInit": "https://ipfs.github.io/helia/interfaces/_helia_utils.BlockStorageInit.html",
|
|
13
|
-
"BlockstoreSessionEvents": "https://ipfs.github.io/helia/interfaces/_helia_utils.BlockstoreSessionEvents.html",
|
|
14
|
-
"GraphNode": "https://ipfs.github.io/helia/interfaces/_helia_utils.GraphNode.html",
|
|
15
|
-
"GraphWalkerComponents": "https://ipfs.github.io/helia/interfaces/_helia_utils.GraphWalkerComponents.html",
|
|
16
|
-
"GraphWalkerInit": "https://ipfs.github.io/helia/interfaces/_helia_utils.GraphWalkerInit.html",
|
|
17
|
-
"HeliaInit": "https://ipfs.github.io/helia/interfaces/_helia_utils.HeliaInit.html",
|
|
18
|
-
".:HeliaInit": "https://ipfs.github.io/helia/interfaces/helia.HeliaInit.html"
|
|
19
|
-
}
|