libp2p 1.1.0 → 1.1.1
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 +22 -22
- package/dist/src/connection-manager/auto-dial.d.ts +2 -1
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +8 -6
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +11 -16
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +142 -257
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +5 -3
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +15 -9
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/utils.d.ts +0 -2
- package/dist/src/connection-manager/utils.d.ts.map +1 -1
- package/dist/src/connection-manager/utils.js +0 -15
- package/dist/src/connection-manager/utils.js.map +1 -1
- package/dist/src/content-routing.d.ts +0 -1
- package/dist/src/content-routing.d.ts.map +1 -1
- package/dist/src/content-routing.js +6 -31
- package/dist/src/content-routing.js.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +12 -14
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +30 -31
- package/src/connection-manager/auto-dial.ts +11 -8
- package/src/connection-manager/dial-queue.ts +161 -290
- package/src/connection-manager/index.ts +22 -12
- package/src/connection-manager/utils.ts +0 -20
- package/src/content-routing.ts +8 -37
- package/src/peer-routing.ts +12 -15
- package/src/version.ts +1 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { setMaxListeners } from '@libp2p/interface'
|
|
2
1
|
import { type AbortOptions, multiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
3
|
-
import { type ClearableSignal, anySignal } from 'any-signal'
|
|
4
2
|
import type { LoggerOptions } from '@libp2p/interface'
|
|
5
3
|
|
|
6
4
|
/**
|
|
@@ -47,21 +45,3 @@ async function resolveRecord (ma: Multiaddr, options: AbortOptions & LoggerOptio
|
|
|
47
45
|
return []
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
export function combineSignals (...signals: Array<AbortSignal | undefined>): ClearableSignal {
|
|
52
|
-
const sigs: AbortSignal[] = []
|
|
53
|
-
|
|
54
|
-
for (const sig of signals) {
|
|
55
|
-
if (sig != null) {
|
|
56
|
-
setMaxListeners(Infinity, sig)
|
|
57
|
-
sigs.push(sig)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// let any signal abort the dial
|
|
62
|
-
const signal = anySignal(sigs)
|
|
63
|
-
|
|
64
|
-
setMaxListeners(Infinity, signal)
|
|
65
|
-
|
|
66
|
-
return signal
|
|
67
|
-
}
|
package/src/content-routing.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface'
|
|
2
2
|
import { PeerSet } from '@libp2p/peer-collections'
|
|
3
3
|
import merge from 'it-merge'
|
|
4
|
-
import parallel from 'it-parallel'
|
|
5
4
|
import { codes, messages } from './errors.js'
|
|
6
|
-
import type { AbortOptions, ComponentLogger, ContentRouting,
|
|
5
|
+
import type { AbortOptions, ComponentLogger, ContentRouting, PeerInfo, PeerRouting, PeerStore, RoutingOptions, Startable } from '@libp2p/interface'
|
|
7
6
|
import type { CID } from 'multiformats/cid'
|
|
8
7
|
|
|
9
8
|
export interface CompoundContentRoutingInit {
|
|
@@ -17,13 +16,11 @@ export interface CompoundContentRoutingComponents {
|
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export class CompoundContentRouting implements ContentRouting, Startable {
|
|
20
|
-
private readonly log: Logger
|
|
21
19
|
private readonly routers: ContentRouting[]
|
|
22
20
|
private started: boolean
|
|
23
21
|
private readonly components: CompoundContentRoutingComponents
|
|
24
22
|
|
|
25
23
|
constructor (components: CompoundContentRoutingComponents, init: CompoundContentRoutingInit) {
|
|
26
|
-
this.log = components.logger.forComponent('libp2p:content-routing')
|
|
27
24
|
this.routers = init.routers ?? []
|
|
28
25
|
this.started = false
|
|
29
26
|
this.components = components
|
|
@@ -52,31 +49,8 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
52
49
|
const self = this
|
|
53
50
|
const seen = new PeerSet()
|
|
54
51
|
|
|
55
|
-
for await (const peer of
|
|
56
|
-
|
|
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
|
-
}()
|
|
52
|
+
for await (const peer of merge(
|
|
53
|
+
...self.routers.map(router => router.findProviders(key, options))
|
|
80
54
|
)) {
|
|
81
55
|
// the peer was yielded by a content router without multiaddrs and we
|
|
82
56
|
// failed to load them
|
|
@@ -84,16 +58,13 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
84
58
|
continue
|
|
85
59
|
}
|
|
86
60
|
|
|
87
|
-
//
|
|
88
|
-
if (peer.multiaddrs.length
|
|
89
|
-
|
|
61
|
+
// store the addresses for the peer if found
|
|
62
|
+
if (peer.multiaddrs.length > 0) {
|
|
63
|
+
await this.components.peerStore.merge(peer.id, {
|
|
64
|
+
multiaddrs: peer.multiaddrs
|
|
65
|
+
})
|
|
90
66
|
}
|
|
91
67
|
|
|
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
68
|
// deduplicate peers
|
|
98
69
|
if (seen.has(peer.id)) {
|
|
99
70
|
continue
|
package/src/peer-routing.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
22
22
|
private readonly peerStore: PeerStore
|
|
23
23
|
private readonly routers: PeerRouting[]
|
|
24
24
|
|
|
25
|
-
constructor (components: DefaultPeerRoutingComponents, init: PeerRoutingInit) {
|
|
25
|
+
constructor (components: DefaultPeerRoutingComponents, init: PeerRoutingInit = {}) {
|
|
26
26
|
this.log = components.logger.forComponent('libp2p:peer-routing')
|
|
27
27
|
this.peerId = components.peerId
|
|
28
28
|
this.peerStore = components.peerStore
|
|
@@ -57,10 +57,12 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
57
57
|
continue
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
// store the addresses for the peer if found
|
|
61
|
+
if (peer.multiaddrs.length > 0) {
|
|
62
|
+
await this.peerStore.merge(peer.id, {
|
|
63
|
+
multiaddrs: peer.multiaddrs
|
|
64
|
+
})
|
|
65
|
+
}
|
|
64
66
|
|
|
65
67
|
return peer
|
|
66
68
|
}
|
|
@@ -105,22 +107,17 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
105
107
|
}
|
|
106
108
|
}()
|
|
107
109
|
)) {
|
|
108
|
-
// the peer was yielded by a content router without multiaddrs and we
|
|
109
|
-
// failed to load them
|
|
110
110
|
if (peer == null) {
|
|
111
111
|
continue
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
//
|
|
115
|
-
if (peer.multiaddrs.length
|
|
116
|
-
|
|
114
|
+
// store the addresses for the peer if found
|
|
115
|
+
if (peer.multiaddrs.length > 0) {
|
|
116
|
+
await this.peerStore.merge(peer.id, {
|
|
117
|
+
multiaddrs: peer.multiaddrs
|
|
118
|
+
})
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
// ensure we have the addresses for a given peer
|
|
120
|
-
await this.peerStore.merge(peer.id, {
|
|
121
|
-
multiaddrs: peer.multiaddrs
|
|
122
|
-
})
|
|
123
|
-
|
|
124
121
|
// deduplicate peers
|
|
125
122
|
if (seen.has(peer.id)) {
|
|
126
123
|
continue
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '1.1.
|
|
1
|
+
export const version = '1.1.1'
|
|
2
2
|
export const name = 'libp2p'
|