libp2p 1.0.9 → 1.0.10-01e9a5fe4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.min.js +35 -35
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +4 -6
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/{content-routing/index.d.ts → content-routing.d.ts} +6 -3
- package/dist/src/content-routing.d.ts.map +1 -0
- package/dist/src/content-routing.js +113 -0
- package/dist/src/content-routing.js.map +1 -0
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +7 -3
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +3 -3
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +57 -10
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +25 -26
- package/src/connection-manager/dial-queue.ts +8 -11
- package/src/{content-routing/index.ts → content-routing.ts} +66 -18
- package/src/libp2p.ts +7 -3
- package/src/peer-routing.ts +78 -35
- package/src/version.ts +1 -1
- package/dist/src/content-routing/index.d.ts.map +0 -1
- package/dist/src/content-routing/index.js +0 -67
- package/dist/src/content-routing/index.js.map +0 -1
- package/dist/src/content-routing/utils.d.ts +0 -15
- package/dist/src/content-routing/utils.d.ts.map +0 -1
- package/dist/src/content-routing/utils.js +0 -44
- package/dist/src/content-routing/utils.js.map +0 -1
- package/dist/typedoc-urls.json +0 -10
- package/src/content-routing/utils.ts +0 -55
|
@@ -294,17 +294,14 @@ export class DialQueue {
|
|
|
294
294
|
|
|
295
295
|
private createDialAbortControllers (userSignal?: AbortSignal): ClearableSignal {
|
|
296
296
|
// let any signal abort the dial
|
|
297
|
-
const signal = anySignal(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// This emitter gets listened to a lot
|
|
306
|
-
setMaxListeners?.(Infinity, signal)
|
|
307
|
-
} catch {}
|
|
297
|
+
const signal = anySignal([
|
|
298
|
+
AbortSignal.timeout(this.dialTimeout),
|
|
299
|
+
this.shutDownController.signal,
|
|
300
|
+
userSignal
|
|
301
|
+
])
|
|
302
|
+
|
|
303
|
+
// This emitter gets listened to a lot
|
|
304
|
+
setMaxListeners(Infinity, signal)
|
|
308
305
|
|
|
309
306
|
return signal
|
|
310
307
|
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface'
|
|
2
|
+
import { PeerSet } from '@libp2p/peer-collections'
|
|
2
3
|
import merge from 'it-merge'
|
|
3
|
-
import
|
|
4
|
-
import { codes, messages } from '
|
|
5
|
-
import {
|
|
6
|
-
storeAddresses,
|
|
7
|
-
uniquePeers,
|
|
8
|
-
requirePeers
|
|
9
|
-
} from './utils.js'
|
|
10
|
-
import type { AbortOptions, ContentRouting, PeerInfo, PeerStore, Startable } from '@libp2p/interface'
|
|
4
|
+
import parallel from 'it-parallel'
|
|
5
|
+
import { codes, messages } from './errors.js'
|
|
6
|
+
import type { AbortOptions, ComponentLogger, ContentRouting, Logger, PeerInfo, PeerRouting, PeerStore, RoutingOptions, Startable } from '@libp2p/interface'
|
|
11
7
|
import type { CID } from 'multiformats/cid'
|
|
12
8
|
|
|
13
9
|
export interface CompoundContentRoutingInit {
|
|
@@ -16,14 +12,18 @@ export interface CompoundContentRoutingInit {
|
|
|
16
12
|
|
|
17
13
|
export interface CompoundContentRoutingComponents {
|
|
18
14
|
peerStore: PeerStore
|
|
15
|
+
peerRouting: PeerRouting
|
|
16
|
+
logger: ComponentLogger
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
export class CompoundContentRouting implements ContentRouting, Startable {
|
|
20
|
+
private readonly log: Logger
|
|
22
21
|
private readonly routers: ContentRouting[]
|
|
23
22
|
private started: boolean
|
|
24
23
|
private readonly components: CompoundContentRoutingComponents
|
|
25
24
|
|
|
26
25
|
constructor (components: CompoundContentRoutingComponents, init: CompoundContentRoutingInit) {
|
|
26
|
+
this.log = components.logger.forComponent('libp2p:content-routing')
|
|
27
27
|
this.routers = init.routers ?? []
|
|
28
28
|
this.started = false
|
|
29
29
|
this.components = components
|
|
@@ -44,19 +44,65 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
44
44
|
/**
|
|
45
45
|
* Iterates over all content routers in parallel to find providers of the given key
|
|
46
46
|
*/
|
|
47
|
-
async * findProviders (key: CID, options:
|
|
47
|
+
async * findProviders (key: CID, options: RoutingOptions = {}): AsyncIterable<PeerInfo> {
|
|
48
48
|
if (this.routers.length === 0) {
|
|
49
49
|
throw new CodeError('No content routers available', codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
const self = this
|
|
53
|
+
const seen = new PeerSet()
|
|
54
|
+
|
|
55
|
+
for await (const peer of parallel(
|
|
56
|
+
async function * () {
|
|
57
|
+
const source = merge(
|
|
58
|
+
...self.routers.map(router => router.findProviders(key, options))
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
for await (let peer of source) {
|
|
62
|
+
yield async () => {
|
|
63
|
+
// find multiaddrs if they are missing
|
|
64
|
+
if (peer.multiaddrs.length === 0) {
|
|
65
|
+
try {
|
|
66
|
+
peer = await self.components.peerRouting.findPeer(peer.id, {
|
|
67
|
+
...options,
|
|
68
|
+
useCache: false
|
|
69
|
+
})
|
|
70
|
+
} catch (err) {
|
|
71
|
+
self.log.error('could not find peer multiaddrs', err)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return peer
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}()
|
|
80
|
+
)) {
|
|
81
|
+
// the peer was yielded by a content router without multiaddrs and we
|
|
82
|
+
// failed to load them
|
|
83
|
+
if (peer == null) {
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// skip peers without addresses
|
|
88
|
+
if (peer.multiaddrs.length === 0) {
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ensure we have the addresses for a given peer
|
|
93
|
+
await this.components.peerStore.merge(peer.id, {
|
|
94
|
+
multiaddrs: peer.multiaddrs
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// deduplicate peers
|
|
98
|
+
if (seen.has(peer.id)) {
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
seen.add(peer.id)
|
|
103
|
+
|
|
104
|
+
yield peer
|
|
105
|
+
}
|
|
60
106
|
}
|
|
61
107
|
|
|
62
108
|
/**
|
|
@@ -68,7 +114,9 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
68
114
|
throw new CodeError('No content routers available', codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
69
115
|
}
|
|
70
116
|
|
|
71
|
-
await Promise.all(this.routers.map(async (router) => {
|
|
117
|
+
await Promise.all(this.routers.map(async (router) => {
|
|
118
|
+
await router.provide(key, options)
|
|
119
|
+
}))
|
|
72
120
|
}
|
|
73
121
|
|
|
74
122
|
/**
|
package/src/libp2p.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { defaultComponents } from './components.js'
|
|
|
14
14
|
import { connectionGater } from './config/connection-gater.js'
|
|
15
15
|
import { validateConfig } from './config.js'
|
|
16
16
|
import { DefaultConnectionManager } from './connection-manager/index.js'
|
|
17
|
-
import { CompoundContentRouting } from './content-routing
|
|
17
|
+
import { CompoundContentRouting } from './content-routing.js'
|
|
18
18
|
import { codes } from './errors.js'
|
|
19
19
|
import { DefaultPeerRouting } from './peer-routing.js'
|
|
20
20
|
import { DefaultRegistrar } from './registrar.js'
|
|
@@ -175,7 +175,7 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
175
175
|
|
|
176
176
|
if (service[peerDiscoverySymbol] != null) {
|
|
177
177
|
this.log('registering service %s for peer discovery', name)
|
|
178
|
-
service[peerDiscoverySymbol].addEventListener('peer', (evt: CustomEvent<PeerInfo>) => {
|
|
178
|
+
service[peerDiscoverySymbol].addEventListener?.('peer', (evt: CustomEvent<PeerInfo>) => {
|
|
179
179
|
this.#onDiscoveryPeer(evt)
|
|
180
180
|
})
|
|
181
181
|
}
|
|
@@ -262,7 +262,11 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
async dial (peer: PeerId | Multiaddr | Multiaddr[], options: AbortOptions = {}): Promise<Connection> {
|
|
265
|
-
return this.components.connectionManager.openConnection(peer,
|
|
265
|
+
return this.components.connectionManager.openConnection(peer, {
|
|
266
|
+
// ensure any userland dials take top priority in the queue
|
|
267
|
+
priority: 75,
|
|
268
|
+
...options
|
|
269
|
+
})
|
|
266
270
|
}
|
|
267
271
|
|
|
268
272
|
async dialProtocol (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options: NewStreamOptions = {}): Promise<Stream> {
|
package/src/peer-routing.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface'
|
|
2
|
-
import
|
|
3
|
-
import first from 'it-first'
|
|
2
|
+
import { PeerSet } from '@libp2p/peer-collections'
|
|
4
3
|
import merge from 'it-merge'
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
storeAddresses,
|
|
8
|
-
uniquePeers,
|
|
9
|
-
requirePeers
|
|
10
|
-
} from './content-routing/utils.js'
|
|
4
|
+
import parallel from 'it-parallel'
|
|
11
5
|
import { codes, messages } from './errors.js'
|
|
12
|
-
import type {
|
|
6
|
+
import type { Logger, PeerId, PeerInfo, PeerRouting, PeerStore, RoutingOptions } from '@libp2p/interface'
|
|
13
7
|
import type { ComponentLogger } from '@libp2p/logger'
|
|
14
8
|
|
|
15
9
|
export interface PeerRoutingInit {
|
|
@@ -38,7 +32,7 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
38
32
|
/**
|
|
39
33
|
* Iterates over all peer routers in parallel to find the given peer
|
|
40
34
|
*/
|
|
41
|
-
async findPeer (id: PeerId, options?:
|
|
35
|
+
async findPeer (id: PeerId, options?: RoutingOptions): Promise<PeerInfo> {
|
|
42
36
|
if (this.routers.length === 0) {
|
|
43
37
|
throw new CodeError('No peer routers available', codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
44
38
|
}
|
|
@@ -48,24 +42,27 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
const self = this
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
})())
|
|
61
|
-
),
|
|
62
|
-
(source) => filter(source, Boolean),
|
|
63
|
-
(source) => storeAddresses(source, this.peerStore),
|
|
64
|
-
async (source) => first(source)
|
|
45
|
+
const source = merge(
|
|
46
|
+
...this.routers.map(router => (async function * () {
|
|
47
|
+
try {
|
|
48
|
+
yield await router.findPeer(id, options)
|
|
49
|
+
} catch (err) {
|
|
50
|
+
self.log.error(err)
|
|
51
|
+
}
|
|
52
|
+
})())
|
|
65
53
|
)
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
for await (const peer of source) {
|
|
56
|
+
if (peer == null) {
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ensure we have the addresses for a given peer
|
|
61
|
+
await this.peerStore.merge(peer.id, {
|
|
62
|
+
multiaddrs: peer.multiaddrs
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
return peer
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
throw new CodeError(messages.NOT_FOUND, codes.ERR_NOT_FOUND)
|
|
@@ -74,18 +71,64 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
74
71
|
/**
|
|
75
72
|
* Attempt to find the closest peers on the network to the given key
|
|
76
73
|
*/
|
|
77
|
-
async * getClosestPeers (key: Uint8Array, options
|
|
74
|
+
async * getClosestPeers (key: Uint8Array, options: RoutingOptions = {}): AsyncIterable<PeerInfo> {
|
|
78
75
|
if (this.routers.length === 0) {
|
|
79
76
|
throw new CodeError('No peer routers available', codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
80
77
|
}
|
|
81
78
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
const self = this
|
|
80
|
+
const seen = new PeerSet()
|
|
81
|
+
|
|
82
|
+
for await (const peer of parallel(
|
|
83
|
+
async function * () {
|
|
84
|
+
const source = merge(
|
|
85
|
+
...self.routers.map(router => router.getClosestPeers(key, options))
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
for await (let peer of source) {
|
|
89
|
+
yield async () => {
|
|
90
|
+
// find multiaddrs if they are missing
|
|
91
|
+
if (peer.multiaddrs.length === 0) {
|
|
92
|
+
try {
|
|
93
|
+
peer = await self.findPeer(peer.id, {
|
|
94
|
+
...options,
|
|
95
|
+
useCache: false
|
|
96
|
+
})
|
|
97
|
+
} catch (err) {
|
|
98
|
+
self.log.error('could not find peer multiaddrs', err)
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return peer
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}()
|
|
107
|
+
)) {
|
|
108
|
+
// the peer was yielded by a content router without multiaddrs and we
|
|
109
|
+
// failed to load them
|
|
110
|
+
if (peer == null) {
|
|
111
|
+
continue
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// skip peers without addresses
|
|
115
|
+
if (peer.multiaddrs.length === 0) {
|
|
116
|
+
continue
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ensure we have the addresses for a given peer
|
|
120
|
+
await this.peerStore.merge(peer.id, {
|
|
121
|
+
multiaddrs: peer.multiaddrs
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// deduplicate peers
|
|
125
|
+
if (seen.has(peer.id)) {
|
|
126
|
+
continue
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
seen.add(peer.id)
|
|
130
|
+
|
|
131
|
+
yield peer
|
|
132
|
+
}
|
|
90
133
|
}
|
|
91
134
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.10-01e9a5fe4'
|
|
2
2
|
export const name = 'libp2p'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/content-routing/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACrG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,cAAc,EAAE,CAAA;CAC1B;AAED,MAAM,WAAW,gCAAgC;IAC/C,SAAS,EAAE,SAAS,CAAA;CACrB;AAED,qBAAa,sBAAuB,YAAW,cAAc,EAAE,SAAS;IACtE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkC;gBAEhD,UAAU,EAAE,gCAAgC,EAAE,IAAI,EAAE,0BAA0B;IAM3F,SAAS,IAAK,OAAO;IAIf,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAIvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACK,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB,GAAG,aAAa,CAAC,QAAQ,CAAC;IAerF;;;OAGG;IACG,OAAO,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQnE;;OAEG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrF;;;OAGG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;CASzE"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface';
|
|
2
|
-
import merge from 'it-merge';
|
|
3
|
-
import { pipe } from 'it-pipe';
|
|
4
|
-
import { codes, messages } from '../errors.js';
|
|
5
|
-
import { storeAddresses, uniquePeers, requirePeers } from './utils.js';
|
|
6
|
-
export class CompoundContentRouting {
|
|
7
|
-
routers;
|
|
8
|
-
started;
|
|
9
|
-
components;
|
|
10
|
-
constructor(components, init) {
|
|
11
|
-
this.routers = init.routers ?? [];
|
|
12
|
-
this.started = false;
|
|
13
|
-
this.components = components;
|
|
14
|
-
}
|
|
15
|
-
isStarted() {
|
|
16
|
-
return this.started;
|
|
17
|
-
}
|
|
18
|
-
async start() {
|
|
19
|
-
this.started = true;
|
|
20
|
-
}
|
|
21
|
-
async stop() {
|
|
22
|
-
this.started = false;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Iterates over all content routers in parallel to find providers of the given key
|
|
26
|
-
*/
|
|
27
|
-
async *findProviders(key, options = {}) {
|
|
28
|
-
if (this.routers.length === 0) {
|
|
29
|
-
throw new CodeError('No content routers available', codes.ERR_NO_ROUTERS_AVAILABLE);
|
|
30
|
-
}
|
|
31
|
-
yield* pipe(merge(...this.routers.map(router => router.findProviders(key, options))), (source) => storeAddresses(source, this.components.peerStore), (source) => uniquePeers(source), (source) => requirePeers(source));
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Iterates over all content routers in parallel to notify it is
|
|
35
|
-
* a provider of the given key
|
|
36
|
-
*/
|
|
37
|
-
async provide(key, options = {}) {
|
|
38
|
-
if (this.routers.length === 0) {
|
|
39
|
-
throw new CodeError('No content routers available', codes.ERR_NO_ROUTERS_AVAILABLE);
|
|
40
|
-
}
|
|
41
|
-
await Promise.all(this.routers.map(async (router) => { await router.provide(key, options); }));
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Store the given key/value pair in the available content routings
|
|
45
|
-
*/
|
|
46
|
-
async put(key, value, options) {
|
|
47
|
-
if (!this.isStarted()) {
|
|
48
|
-
throw new CodeError(messages.NOT_STARTED_YET, codes.ERR_NODE_NOT_STARTED);
|
|
49
|
-
}
|
|
50
|
-
await Promise.all(this.routers.map(async (router) => {
|
|
51
|
-
await router.put(key, value, options);
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get the value to the given key.
|
|
56
|
-
* Times out after 1 minute by default.
|
|
57
|
-
*/
|
|
58
|
-
async get(key, options) {
|
|
59
|
-
if (!this.isStarted()) {
|
|
60
|
-
throw new CodeError(messages.NOT_STARTED_YET, codes.ERR_NODE_NOT_STARTED);
|
|
61
|
-
}
|
|
62
|
-
return Promise.any(this.routers.map(async (router) => {
|
|
63
|
-
return router.get(key, options);
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content-routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAA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;QAC3E,CAAC;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YACnD,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QACjC,CAAC,CAAC,CAAC,CAAA;IACL,CAAC;CACF"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PeerInfo, PeerStore } from '@libp2p/interface';
|
|
2
|
-
import type { Source } from 'it-stream-types';
|
|
3
|
-
/**
|
|
4
|
-
* Store the multiaddrs from every peer in the passed peer store
|
|
5
|
-
*/
|
|
6
|
-
export declare function storeAddresses(source: Source<PeerInfo>, peerStore: PeerStore): AsyncIterable<PeerInfo>;
|
|
7
|
-
/**
|
|
8
|
-
* Filter peers by unique peer id
|
|
9
|
-
*/
|
|
10
|
-
export declare function uniquePeers(source: Source<PeerInfo>): AsyncIterable<PeerInfo>;
|
|
11
|
-
/**
|
|
12
|
-
* Require at least `min` peers to be yielded from `source`
|
|
13
|
-
*/
|
|
14
|
-
export declare function requirePeers(source: Source<PeerInfo>, min?: number): AsyncIterable<PeerInfo>;
|
|
15
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/content-routing/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C;;GAEG;AACH,wBAAwB,cAAc,CAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,GAAG,aAAa,CAAC,QAAQ,CAAC,CAS/G;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAc9E;AAED;;GAEG;AACH,wBAAwB,YAAY,CAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,GAAE,MAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,CAYxG"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface';
|
|
2
|
-
import filter from 'it-filter';
|
|
3
|
-
import map from 'it-map';
|
|
4
|
-
/**
|
|
5
|
-
* Store the multiaddrs from every peer in the passed peer store
|
|
6
|
-
*/
|
|
7
|
-
export async function* storeAddresses(source, peerStore) {
|
|
8
|
-
yield* map(source, async (peer) => {
|
|
9
|
-
// ensure we have the addresses for a given peer
|
|
10
|
-
await peerStore.merge(peer.id, {
|
|
11
|
-
multiaddrs: peer.multiaddrs
|
|
12
|
-
});
|
|
13
|
-
return peer;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Filter peers by unique peer id
|
|
18
|
-
*/
|
|
19
|
-
export function uniquePeers(source) {
|
|
20
|
-
/** @type Set<string> */
|
|
21
|
-
const seen = new Set();
|
|
22
|
-
return filter(source, (peer) => {
|
|
23
|
-
// dedupe by peer id
|
|
24
|
-
if (seen.has(peer.id.toString())) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
seen.add(peer.id.toString());
|
|
28
|
-
return true;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Require at least `min` peers to be yielded from `source`
|
|
33
|
-
*/
|
|
34
|
-
export async function* requirePeers(source, min = 1) {
|
|
35
|
-
let seen = 0;
|
|
36
|
-
for await (const peer of source) {
|
|
37
|
-
seen++;
|
|
38
|
-
yield peer;
|
|
39
|
-
}
|
|
40
|
-
if (seen < min) {
|
|
41
|
-
throw new CodeError(`more peers required, seen: ${seen} min: ${min}`, 'NOT_FOUND');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMapping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,CAAC;QAChC,IAAI,EAAE,CAAA;QAEN,MAAM,IAAI,CAAA;IACZ,CAAC;IAED,IAAI,IAAI,GAAG,GAAG,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CAAC,8BAA8B,IAAI,UAAU,GAAG,EAAE,EAAE,WAAW,CAAC,CAAA;IACrF,CAAC;AACH,CAAC"}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.Libp2pInit.html",
|
|
3
|
-
".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.Libp2pInit.html",
|
|
4
|
-
"Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.Libp2pOptions.html",
|
|
5
|
-
".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.Libp2pOptions.html",
|
|
6
|
-
"ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.ServiceFactoryMap.html",
|
|
7
|
-
".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.ServiceFactoryMap.html",
|
|
8
|
-
"createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.createLibp2p.html",
|
|
9
|
-
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.createLibp2p.html"
|
|
10
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface'
|
|
2
|
-
import filter from 'it-filter'
|
|
3
|
-
import map from 'it-map'
|
|
4
|
-
import type { PeerInfo, PeerStore } from '@libp2p/interface'
|
|
5
|
-
import type { Source } from 'it-stream-types'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Store the multiaddrs from every peer in the passed peer store
|
|
9
|
-
*/
|
|
10
|
-
export async function * storeAddresses (source: Source<PeerInfo>, peerStore: PeerStore): AsyncIterable<PeerInfo> {
|
|
11
|
-
yield * map(source, async (peer) => {
|
|
12
|
-
// ensure we have the addresses for a given peer
|
|
13
|
-
await peerStore.merge(peer.id, {
|
|
14
|
-
multiaddrs: peer.multiaddrs
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
return peer
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Filter peers by unique peer id
|
|
23
|
-
*/
|
|
24
|
-
export function uniquePeers (source: Source<PeerInfo>): AsyncIterable<PeerInfo> {
|
|
25
|
-
/** @type Set<string> */
|
|
26
|
-
const seen = new Set()
|
|
27
|
-
|
|
28
|
-
return filter(source, (peer) => {
|
|
29
|
-
// dedupe by peer id
|
|
30
|
-
if (seen.has(peer.id.toString())) {
|
|
31
|
-
return false
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
seen.add(peer.id.toString())
|
|
35
|
-
|
|
36
|
-
return true
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Require at least `min` peers to be yielded from `source`
|
|
42
|
-
*/
|
|
43
|
-
export async function * requirePeers (source: Source<PeerInfo>, min: number = 1): AsyncIterable<PeerInfo> {
|
|
44
|
-
let seen = 0
|
|
45
|
-
|
|
46
|
-
for await (const peer of source) {
|
|
47
|
-
seen++
|
|
48
|
-
|
|
49
|
-
yield peer
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (seen < min) {
|
|
53
|
-
throw new CodeError(`more peers required, seen: ${seen} min: ${min}`, 'NOT_FOUND')
|
|
54
|
-
}
|
|
55
|
-
}
|