libp2p 0.46.20 → 0.46.21-0b4a2ee79
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 +53 -40
- package/dist/index.min.js +40 -28
- package/dist/src/address-manager/index.d.ts +3 -1
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +3 -3
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/components.d.ts +3 -1
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js.map +1 -1
- package/dist/src/connection/index.d.ts +2 -2
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +9 -9
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +21 -21
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +8 -8
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/constants.defaults.d.ts +0 -4
- package/dist/src/connection-manager/constants.defaults.d.ts.map +1 -1
- package/dist/src/connection-manager/constants.defaults.js +0 -4
- package/dist/src/connection-manager/constants.defaults.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +1 -3
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +30 -37
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -8
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +16 -17
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/content-routing/index.js +1 -1
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/errors.d.ts +0 -2
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +0 -2
- package/dist/src/errors.js.map +1 -1
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +0 -3
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/index.d.ts +5 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +1 -2
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +23 -54
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +5 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +11 -8
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/registrar.d.ts +3 -0
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +3 -3
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +3 -1
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +10 -10
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +2 -2
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +75 -37
- package/dist/src/upgrader.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 +34 -106
- package/src/address-manager/index.ts +5 -5
- package/src/components.ts +3 -1
- package/src/connection/index.ts +9 -10
- package/src/connection-manager/auto-dial.ts +21 -21
- package/src/connection-manager/connection-pruner.ts +8 -8
- package/src/connection-manager/constants.defaults.ts +0 -5
- package/src/connection-manager/dial-queue.ts +29 -38
- package/src/connection-manager/index.ts +16 -25
- package/src/content-routing/index.ts +1 -1
- package/src/errors.ts +0 -2
- package/src/get-peer.ts +0 -4
- package/src/index.ts +6 -7
- package/src/libp2p.ts +23 -61
- package/src/peer-routing.ts +15 -10
- package/src/registrar.ts +6 -5
- package/src/transport-manager.ts +12 -12
- package/src/upgrader.ts +100 -40
- package/src/version.ts +1 -1
- package/dist/src/autonat/constants.d.ts +0 -18
- package/dist/src/autonat/constants.d.ts.map +0 -1
- package/dist/src/autonat/constants.js +0 -18
- package/dist/src/autonat/constants.js.map +0 -1
- package/dist/src/autonat/index.d.ts +0 -62
- package/dist/src/autonat/index.d.ts.map +0 -1
- package/dist/src/autonat/index.js +0 -447
- package/dist/src/autonat/index.js.map +0 -1
- package/dist/src/autonat/pb/index.d.ts +0 -57
- package/dist/src/autonat/pb/index.d.ts.map +0 -1
- package/dist/src/autonat/pb/index.js +0 -250
- package/dist/src/autonat/pb/index.js.map +0 -1
- package/dist/src/circuit-relay/constants.d.ts +0 -50
- package/dist/src/circuit-relay/constants.d.ts.map +0 -1
- package/dist/src/circuit-relay/constants.js +0 -56
- package/dist/src/circuit-relay/constants.js.map +0 -1
- package/dist/src/circuit-relay/index.d.ts +0 -55
- package/dist/src/circuit-relay/index.d.ts.map +0 -1
- package/dist/src/circuit-relay/index.js +0 -38
- package/dist/src/circuit-relay/index.js.map +0 -1
- package/dist/src/circuit-relay/pb/index.d.ts +0 -93
- package/dist/src/circuit-relay/pb/index.d.ts.map +0 -1
- package/dist/src/circuit-relay/pb/index.js +0 -425
- package/dist/src/circuit-relay/pb/index.js.map +0 -1
- package/dist/src/circuit-relay/server/advert-service.d.ts +0 -43
- package/dist/src/circuit-relay/server/advert-service.d.ts.map +0 -1
- package/dist/src/circuit-relay/server/advert-service.js +0 -73
- package/dist/src/circuit-relay/server/advert-service.js.map +0 -1
- package/dist/src/circuit-relay/server/index.d.ts +0 -65
- package/dist/src/circuit-relay/server/index.d.ts.map +0 -1
- package/dist/src/circuit-relay/server/index.js +0 -312
- package/dist/src/circuit-relay/server/index.js.map +0 -1
- package/dist/src/circuit-relay/server/reservation-store.d.ts +0 -49
- package/dist/src/circuit-relay/server/reservation-store.d.ts.map +0 -1
- package/dist/src/circuit-relay/server/reservation-store.js +0 -65
- package/dist/src/circuit-relay/server/reservation-store.js.map +0 -1
- package/dist/src/circuit-relay/server/reservation-voucher.d.ts +0 -18
- package/dist/src/circuit-relay/server/reservation-voucher.d.ts.map +0 -1
- package/dist/src/circuit-relay/server/reservation-voucher.js +0 -36
- package/dist/src/circuit-relay/server/reservation-voucher.js.map +0 -1
- package/dist/src/circuit-relay/transport/discovery.d.ts +0 -45
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +0 -1
- package/dist/src/circuit-relay/transport/discovery.js +0 -97
- package/dist/src/circuit-relay/transport/discovery.js.map +0 -1
- package/dist/src/circuit-relay/transport/index.d.ts +0 -57
- package/dist/src/circuit-relay/transport/index.d.ts.map +0 -1
- package/dist/src/circuit-relay/transport/index.js +0 -276
- package/dist/src/circuit-relay/transport/index.js.map +0 -1
- package/dist/src/circuit-relay/transport/listener.d.ts +0 -9
- package/dist/src/circuit-relay/transport/listener.d.ts.map +0 -1
- package/dist/src/circuit-relay/transport/listener.js +0 -66
- package/dist/src/circuit-relay/transport/listener.js.map +0 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +0 -72
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +0 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +0 -209
- package/dist/src/circuit-relay/transport/reservation-store.js.map +0 -1
- package/dist/src/circuit-relay/utils.d.ts +0 -13
- package/dist/src/circuit-relay/utils.d.ts.map +0 -1
- package/dist/src/circuit-relay/utils.js +0 -108
- package/dist/src/circuit-relay/utils.js.map +0 -1
- package/dist/src/dcutr/dcutr.d.ts +0 -43
- package/dist/src/dcutr/dcutr.d.ts.map +0 -1
- package/dist/src/dcutr/dcutr.js +0 -313
- package/dist/src/dcutr/dcutr.js.map +0 -1
- package/dist/src/dcutr/index.d.ts +0 -92
- package/dist/src/dcutr/index.d.ts.map +0 -1
- package/dist/src/dcutr/index.js +0 -63
- package/dist/src/dcutr/index.js.map +0 -1
- package/dist/src/dcutr/pb/message.d.ts +0 -20
- package/dist/src/dcutr/pb/message.d.ts.map +0 -1
- package/dist/src/dcutr/pb/message.js +0 -77
- package/dist/src/dcutr/pb/message.js.map +0 -1
- package/dist/src/dcutr/utils.d.ts +0 -8
- package/dist/src/dcutr/utils.d.ts.map +0 -1
- package/dist/src/dcutr/utils.js +0 -27
- package/dist/src/dcutr/utils.js.map +0 -1
- package/dist/src/fetch/constants.d.ts +0 -3
- package/dist/src/fetch/constants.d.ts.map +0 -1
- package/dist/src/fetch/constants.js +0 -4
- package/dist/src/fetch/constants.js.map +0 -1
- package/dist/src/fetch/index.d.ts +0 -61
- package/dist/src/fetch/index.d.ts.map +0 -1
- package/dist/src/fetch/index.js +0 -205
- package/dist/src/fetch/index.js.map +0 -1
- package/dist/src/fetch/pb/proto.d.ts +0 -28
- package/dist/src/fetch/pb/proto.d.ts.map +0 -1
- package/dist/src/fetch/pb/proto.js +0 -120
- package/dist/src/fetch/pb/proto.js.map +0 -1
- package/dist/src/identify/consts.d.ts +0 -10
- package/dist/src/identify/consts.d.ts.map +0 -1
- package/dist/src/identify/consts.js +0 -11
- package/dist/src/identify/consts.js.map +0 -1
- package/dist/src/identify/identify.d.ts +0 -54
- package/dist/src/identify/identify.d.ts.map +0 -1
- package/dist/src/identify/identify.js +0 -447
- package/dist/src/identify/identify.js.map +0 -1
- package/dist/src/identify/index.d.ts +0 -72
- package/dist/src/identify/index.d.ts.map +0 -1
- package/dist/src/identify/index.js +0 -15
- package/dist/src/identify/index.js.map +0 -1
- package/dist/src/identify/pb/message.d.ts +0 -17
- package/dist/src/identify/pb/message.d.ts.map +0 -1
- package/dist/src/identify/pb/message.js +0 -98
- package/dist/src/identify/pb/message.js.map +0 -1
- package/dist/src/insecure/index.d.ts +0 -26
- package/dist/src/insecure/index.d.ts.map +0 -1
- package/dist/src/insecure/index.js +0 -110
- package/dist/src/insecure/index.js.map +0 -1
- package/dist/src/insecure/pb/proto.d.ts +0 -30
- package/dist/src/insecure/pb/proto.d.ts.map +0 -1
- package/dist/src/insecure/pb/proto.js +0 -127
- package/dist/src/insecure/pb/proto.js.map +0 -1
- package/dist/src/ping/constants.d.ts +0 -9
- package/dist/src/ping/constants.d.ts.map +0 -1
- package/dist/src/ping/constants.js +0 -15
- package/dist/src/ping/constants.js.map +0 -1
- package/dist/src/ping/index.d.ts +0 -24
- package/dist/src/ping/index.d.ts.map +0 -1
- package/dist/src/ping/index.js +0 -115
- package/dist/src/ping/index.js.map +0 -1
- package/dist/src/pnet/crypto.d.ts +0 -18
- package/dist/src/pnet/crypto.d.ts.map +0 -1
- package/dist/src/pnet/crypto.js +0 -60
- package/dist/src/pnet/crypto.js.map +0 -1
- package/dist/src/pnet/errors.d.ts +0 -6
- package/dist/src/pnet/errors.d.ts.map +0 -1
- package/dist/src/pnet/errors.js +0 -6
- package/dist/src/pnet/errors.js.map +0 -1
- package/dist/src/pnet/index.d.ts +0 -31
- package/dist/src/pnet/index.d.ts.map +0 -1
- package/dist/src/pnet/index.js +0 -97
- package/dist/src/pnet/index.js.map +0 -1
- package/dist/src/pnet/key-generator.d.ts +0 -11
- package/dist/src/pnet/key-generator.d.ts.map +0 -1
- package/dist/src/pnet/key-generator.js +0 -22
- package/dist/src/pnet/key-generator.js.map +0 -1
- package/dist/src/upnp-nat/index.d.ts +0 -71
- package/dist/src/upnp-nat/index.d.ts.map +0 -1
- package/dist/src/upnp-nat/index.js +0 -136
- package/dist/src/upnp-nat/index.js.map +0 -1
- package/dist/src/utils/peer-job-queue.d.ts +0 -33
- package/dist/src/utils/peer-job-queue.d.ts.map +0 -1
- package/dist/src/utils/peer-job-queue.js +0 -82
- package/dist/src/utils/peer-job-queue.js.map +0 -1
- package/dist/typedoc-urls.json +0 -71
- package/src/autonat/constants.ts +0 -19
- package/src/autonat/index.ts +0 -597
- package/src/autonat/pb/index.proto +0 -35
- package/src/autonat/pb/index.ts +0 -320
- package/src/circuit-relay/constants.ts +0 -72
- package/src/circuit-relay/index.ts +0 -59
- package/src/circuit-relay/pb/index.proto +0 -67
- package/src/circuit-relay/pb/index.ts +0 -539
- package/src/circuit-relay/server/advert-service.ts +0 -108
- package/src/circuit-relay/server/index.ts +0 -443
- package/src/circuit-relay/server/reservation-store.ts +0 -116
- package/src/circuit-relay/server/reservation-voucher.ts +0 -51
- package/src/circuit-relay/transport/discovery.ts +0 -136
- package/src/circuit-relay/transport/index.ts +0 -396
- package/src/circuit-relay/transport/listener.ts +0 -97
- package/src/circuit-relay/transport/reservation-store.ts +0 -312
- package/src/circuit-relay/utils.ts +0 -136
- package/src/dcutr/dcutr.ts +0 -378
- package/src/dcutr/index.ts +0 -102
- package/src/dcutr/pb/message.proto +0 -12
- package/src/dcutr/pb/message.ts +0 -96
- package/src/dcutr/utils.ts +0 -33
- package/src/fetch/README.md +0 -41
- package/src/fetch/constants.ts +0 -3
- package/src/fetch/index.ts +0 -315
- package/src/fetch/pb/proto.proto +0 -15
- package/src/fetch/pb/proto.ts +0 -153
- package/src/identify/README.md +0 -13
- package/src/identify/consts.ts +0 -12
- package/src/identify/identify.ts +0 -561
- package/src/identify/index.ts +0 -90
- package/src/identify/pb/message.proto +0 -30
- package/src/identify/pb/message.ts +0 -126
- package/src/insecure/index.ts +0 -138
- package/src/insecure/pb/proto.proto +0 -18
- package/src/insecure/pb/proto.ts +0 -161
- package/src/ping/constants.ts +0 -15
- package/src/ping/index.ts +0 -170
- package/src/pnet/README.md +0 -68
- package/src/pnet/crypto.ts +0 -67
- package/src/pnet/errors.ts +0 -5
- package/src/pnet/index.ts +0 -126
- package/src/pnet/key-generator.ts +0 -23
- package/src/upnp-nat/index.ts +0 -212
- package/src/utils/peer-job-queue.ts +0 -119
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbortError, CodeError } from '@libp2p/interface/errors'
|
|
1
|
+
import { AbortError, CodeError, ERR_TIMEOUT } from '@libp2p/interface/errors'
|
|
2
2
|
import { setMaxListeners } from '@libp2p/interface/events'
|
|
3
3
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
4
4
|
import { defaultAddressSort } from '@libp2p/utils/address-sort'
|
|
@@ -12,7 +12,6 @@ import { codes } from '../errors.js'
|
|
|
12
12
|
import { getPeerAddress } from '../get-peer.js'
|
|
13
13
|
import {
|
|
14
14
|
DIAL_TIMEOUT,
|
|
15
|
-
MAX_PARALLEL_DIALS_PER_PEER,
|
|
16
15
|
MAX_PARALLEL_DIALS,
|
|
17
16
|
MAX_PEER_ADDRS_TO_DIAL,
|
|
18
17
|
LAST_DIAL_FAILURE_KEY
|
|
@@ -44,7 +43,6 @@ interface DialerInit {
|
|
|
44
43
|
addressSorter?: AddressSorter
|
|
45
44
|
maxParallelDials?: number
|
|
46
45
|
maxPeerAddrsToDial?: number
|
|
47
|
-
maxParallelDialsPerPeer?: number
|
|
48
46
|
dialTimeout?: number
|
|
49
47
|
resolvers?: Record<string, Resolver>
|
|
50
48
|
connections?: PeerMap<Connection[]>
|
|
@@ -54,7 +52,6 @@ const defaultOptions = {
|
|
|
54
52
|
addressSorter: defaultAddressSort,
|
|
55
53
|
maxParallelDials: MAX_PARALLEL_DIALS,
|
|
56
54
|
maxPeerAddrsToDial: MAX_PEER_ADDRS_TO_DIAL,
|
|
57
|
-
maxParallelDialsPerPeer: MAX_PARALLEL_DIALS_PER_PEER,
|
|
58
55
|
dialTimeout: DIAL_TIMEOUT,
|
|
59
56
|
resolvers: {
|
|
60
57
|
dnsaddr: dnsaddrResolver
|
|
@@ -79,21 +76,19 @@ export class DialQueue {
|
|
|
79
76
|
private readonly transportManager: TransportManager
|
|
80
77
|
private readonly addressSorter: AddressSorter
|
|
81
78
|
private readonly maxPeerAddrsToDial: number
|
|
82
|
-
private readonly maxParallelDialsPerPeer: number
|
|
83
79
|
private readonly dialTimeout: number
|
|
84
80
|
private readonly inProgressDialCount?: Metric
|
|
85
81
|
private readonly pendingDialCount?: Metric
|
|
86
82
|
private readonly shutDownController: AbortController
|
|
87
83
|
private readonly connections: PeerMap<Connection[]>
|
|
88
|
-
readonly
|
|
84
|
+
private readonly log: Logger
|
|
89
85
|
|
|
90
86
|
constructor (components: DialQueueComponents, init: DialerInit = {}) {
|
|
91
87
|
this.addressSorter = init.addressSorter ?? defaultOptions.addressSorter
|
|
92
88
|
this.maxPeerAddrsToDial = init.maxPeerAddrsToDial ?? defaultOptions.maxPeerAddrsToDial
|
|
93
|
-
this.maxParallelDialsPerPeer = init.maxParallelDialsPerPeer ?? defaultOptions.maxParallelDialsPerPeer
|
|
94
89
|
this.dialTimeout = init.dialTimeout ?? defaultOptions.dialTimeout
|
|
95
90
|
this.connections = init.connections ?? new PeerMap()
|
|
96
|
-
this
|
|
91
|
+
this.log = components.logger.forComponent('libp2p:connection-manager:dial-queue')
|
|
97
92
|
|
|
98
93
|
this.peerId = components.peerId
|
|
99
94
|
this.peerStore = components.peerStore
|
|
@@ -103,8 +98,8 @@ export class DialQueue {
|
|
|
103
98
|
|
|
104
99
|
setMaxListeners(Infinity, this.shutDownController.signal)
|
|
105
100
|
|
|
106
|
-
this.pendingDialCount = components.metrics?.registerMetric('
|
|
107
|
-
this.inProgressDialCount = components.metrics?.registerMetric('
|
|
101
|
+
this.pendingDialCount = components.metrics?.registerMetric('libp2p_dial_queue_pending_dials')
|
|
102
|
+
this.inProgressDialCount = components.metrics?.registerMetric('libp2p_dial_queue_in_progress_dials')
|
|
108
103
|
this.pendingDials = []
|
|
109
104
|
|
|
110
105
|
for (const [key, value] of Object.entries(init.resolvers ?? {})) {
|
|
@@ -133,7 +128,7 @@ export class DialQueue {
|
|
|
133
128
|
})
|
|
134
129
|
// a started job errored
|
|
135
130
|
this.queue.on('error', (err) => {
|
|
136
|
-
this
|
|
131
|
+
this.log.error('error in dial queue', err)
|
|
137
132
|
this.pendingDialCount?.update(this.queue.size)
|
|
138
133
|
this.inProgressDialCount?.update(this.queue.pending)
|
|
139
134
|
})
|
|
@@ -205,7 +200,7 @@ export class DialQueue {
|
|
|
205
200
|
})
|
|
206
201
|
|
|
207
202
|
if (existingConnection != null) {
|
|
208
|
-
this
|
|
203
|
+
this.log('already connected to %a', existingConnection.remoteAddr)
|
|
209
204
|
return existingConnection
|
|
210
205
|
}
|
|
211
206
|
|
|
@@ -226,12 +221,12 @@ export class DialQueue {
|
|
|
226
221
|
})
|
|
227
222
|
|
|
228
223
|
if (existingDial != null) {
|
|
229
|
-
this
|
|
224
|
+
this.log('joining existing dial target for %p', peerId)
|
|
230
225
|
signal.clear()
|
|
231
226
|
return existingDial.promise
|
|
232
227
|
}
|
|
233
228
|
|
|
234
|
-
this
|
|
229
|
+
this.log('creating dial target for', addrsToDial.map(({ multiaddr }) => multiaddr.toString()))
|
|
235
230
|
// @ts-expect-error .promise property is set below
|
|
236
231
|
const pendingDial: PendingDialInternal = {
|
|
237
232
|
id: randomId(),
|
|
@@ -252,7 +247,7 @@ export class DialQueue {
|
|
|
252
247
|
signal.clear()
|
|
253
248
|
})
|
|
254
249
|
.catch(async err => {
|
|
255
|
-
this
|
|
250
|
+
this.log.error('dial failed to %s', pendingDial.multiaddrs.map(ma => ma.toString()).join(', '), err)
|
|
256
251
|
|
|
257
252
|
if (peerId != null) {
|
|
258
253
|
// record the last failed dial
|
|
@@ -263,13 +258,13 @@ export class DialQueue {
|
|
|
263
258
|
}
|
|
264
259
|
})
|
|
265
260
|
} catch (err: any) {
|
|
266
|
-
this
|
|
261
|
+
this.log.error('could not update last dial failure key for %p', peerId, err)
|
|
267
262
|
}
|
|
268
263
|
}
|
|
269
264
|
|
|
270
265
|
// Error is a timeout
|
|
271
266
|
if (signal.aborted) {
|
|
272
|
-
const error = new CodeError(err.message,
|
|
267
|
+
const error = new CodeError(err.message, ERR_TIMEOUT)
|
|
273
268
|
throw error
|
|
274
269
|
}
|
|
275
270
|
|
|
@@ -294,12 +289,12 @@ export class DialQueue {
|
|
|
294
289
|
})
|
|
295
290
|
|
|
296
291
|
if (existingConnection != null) {
|
|
297
|
-
this
|
|
292
|
+
this.log('already connected to %a', existingConnection.remoteAddr)
|
|
298
293
|
await connection.close()
|
|
299
294
|
return existingConnection
|
|
300
295
|
}
|
|
301
296
|
|
|
302
|
-
this
|
|
297
|
+
this.log('connection opened to %a', connection.remoteAddr)
|
|
303
298
|
return connection
|
|
304
299
|
}
|
|
305
300
|
|
|
@@ -334,11 +329,11 @@ export class DialQueue {
|
|
|
334
329
|
|
|
335
330
|
// if just a peer id was passed, load available multiaddrs for this peer from the address book
|
|
336
331
|
if (addrs.length === 0) {
|
|
337
|
-
this
|
|
332
|
+
this.log('loading multiaddrs for %p', peerId)
|
|
338
333
|
try {
|
|
339
334
|
const peer = await this.peerStore.get(peerId)
|
|
340
335
|
addrs.push(...peer.addresses)
|
|
341
|
-
this
|
|
336
|
+
this.log('loaded multiaddrs for %p', peerId, addrs.map(({ multiaddr }) => multiaddr.toString()))
|
|
342
337
|
} catch (err: any) {
|
|
343
338
|
if (err.code !== codes.ERR_NOT_FOUND) {
|
|
344
339
|
throw err
|
|
@@ -352,7 +347,7 @@ export class DialQueue {
|
|
|
352
347
|
addrs.map(async addr => {
|
|
353
348
|
const result = await resolveMultiaddrs(addr.multiaddr, {
|
|
354
349
|
...options,
|
|
355
|
-
log: this
|
|
350
|
+
log: this.log
|
|
356
351
|
})
|
|
357
352
|
|
|
358
353
|
if (result.length === 1 && result[0].equals(addr.multiaddr)) {
|
|
@@ -425,8 +420,8 @@ export class DialQueue {
|
|
|
425
420
|
const dedupedMultiaddrs = [...dedupedAddrs.values()]
|
|
426
421
|
|
|
427
422
|
if (dedupedMultiaddrs.length === 0 || dedupedMultiaddrs.length > this.maxPeerAddrsToDial) {
|
|
428
|
-
this
|
|
429
|
-
this
|
|
423
|
+
this.log('addresses for %p before filtering', peerId ?? 'unknown peer', resolvedAddresses.map(({ multiaddr }) => multiaddr.toString()))
|
|
424
|
+
this.log('addresses for %p after filtering', peerId ?? 'unknown peer', dedupedMultiaddrs.map(({ multiaddr }) => multiaddr.toString()))
|
|
430
425
|
}
|
|
431
426
|
|
|
432
427
|
// make sure we actually have some addresses to dial
|
|
@@ -463,14 +458,10 @@ export class DialQueue {
|
|
|
463
458
|
const dialAbortControllers: Array<(AbortController | undefined)> = pendingDial.multiaddrs.map(() => new AbortController())
|
|
464
459
|
|
|
465
460
|
try {
|
|
466
|
-
// internal peer dial queue
|
|
467
|
-
|
|
468
|
-
// the dial queue
|
|
469
|
-
const peerDialQueue = new PQueue({
|
|
470
|
-
concurrency: this.maxParallelDialsPerPeer
|
|
471
|
-
})
|
|
461
|
+
// internal peer dial queue - only one dial per peer at a time
|
|
462
|
+
const peerDialQueue = new PQueue({ concurrency: 1 })
|
|
472
463
|
peerDialQueue.on('error', (err) => {
|
|
473
|
-
this
|
|
464
|
+
this.log.error('error dialing %s %o', pendingDial.multiaddrs, err)
|
|
474
465
|
})
|
|
475
466
|
|
|
476
467
|
const conn = await Promise.any(pendingDial.multiaddrs.map(async (addr, i) => {
|
|
@@ -483,13 +474,13 @@ export class DialQueue {
|
|
|
483
474
|
// let any signal abort the dial
|
|
484
475
|
const signal = combineSignals(controller.signal, options.signal)
|
|
485
476
|
signal.addEventListener('abort', () => {
|
|
486
|
-
this
|
|
477
|
+
this.log('dial to %a aborted', addr)
|
|
487
478
|
})
|
|
488
479
|
const deferred = pDefer<Connection>()
|
|
489
480
|
|
|
490
481
|
await peerDialQueue.add(async () => {
|
|
491
482
|
if (signal.aborted) {
|
|
492
|
-
this
|
|
483
|
+
this.log('dial to %a was aborted before reaching the head of the peer dial queue', addr)
|
|
493
484
|
deferred.reject(new AbortError())
|
|
494
485
|
return
|
|
495
486
|
}
|
|
@@ -498,7 +489,7 @@ export class DialQueue {
|
|
|
498
489
|
await this.queue.add(async () => {
|
|
499
490
|
try {
|
|
500
491
|
if (signal.aborted) {
|
|
501
|
-
this
|
|
492
|
+
this.log('dial to %a was aborted before reaching the head of the dial queue', addr)
|
|
502
493
|
deferred.reject(new AbortError())
|
|
503
494
|
return
|
|
504
495
|
}
|
|
@@ -513,10 +504,10 @@ export class DialQueue {
|
|
|
513
504
|
|
|
514
505
|
if (controller.signal.aborted) {
|
|
515
506
|
// another dial succeeded faster than this one
|
|
516
|
-
this
|
|
507
|
+
this.log('multiple dials succeeded, closing superfluous connection')
|
|
517
508
|
|
|
518
509
|
conn.close().catch(err => {
|
|
519
|
-
this
|
|
510
|
+
this.log.error('error closing superfluous connection', err)
|
|
520
511
|
})
|
|
521
512
|
|
|
522
513
|
deferred.reject(new AbortError())
|
|
@@ -533,13 +524,13 @@ export class DialQueue {
|
|
|
533
524
|
}
|
|
534
525
|
})
|
|
535
526
|
|
|
536
|
-
this
|
|
527
|
+
this.log('dial to %a succeeded', addr)
|
|
537
528
|
|
|
538
529
|
// resolve the connection promise
|
|
539
530
|
deferred.resolve(conn)
|
|
540
531
|
} catch (err: any) {
|
|
541
532
|
// something only went wrong if our signal was not aborted
|
|
542
|
-
this
|
|
533
|
+
this.log.error('error during dial of %a', addr, err)
|
|
543
534
|
deferred.reject(err)
|
|
544
535
|
}
|
|
545
536
|
}, {
|
|
@@ -9,7 +9,7 @@ import { codes } from '../errors.js'
|
|
|
9
9
|
import { getPeerAddress } from '../get-peer.js'
|
|
10
10
|
import { AutoDial } from './auto-dial.js'
|
|
11
11
|
import { ConnectionPruner } from './connection-pruner.js'
|
|
12
|
-
import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_MAX_QUEUE_LENGTH, AUTO_DIAL_PRIORITY, DIAL_TIMEOUT, INBOUND_CONNECTION_THRESHOLD, MAX_CONNECTIONS, MAX_INCOMING_PENDING_CONNECTIONS, MAX_PARALLEL_DIALS,
|
|
12
|
+
import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_MAX_QUEUE_LENGTH, AUTO_DIAL_PRIORITY, DIAL_TIMEOUT, INBOUND_CONNECTION_THRESHOLD, MAX_CONNECTIONS, MAX_INCOMING_PENDING_CONNECTIONS, MAX_PARALLEL_DIALS, MAX_PEER_ADDRS_TO_DIAL, MIN_CONNECTIONS } from './constants.js'
|
|
13
13
|
import { DialQueue } from './dial-queue.js'
|
|
14
14
|
import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions, ComponentLogger, Logger } from '@libp2p/interface'
|
|
15
15
|
import type { Connection, MultiaddrConnection } from '@libp2p/interface/connection'
|
|
@@ -89,14 +89,6 @@ export interface ConnectionManagerInit {
|
|
|
89
89
|
*/
|
|
90
90
|
maxParallelDials?: number
|
|
91
91
|
|
|
92
|
-
/**
|
|
93
|
-
* To prevent individual peers with large amounts of multiaddrs swamping the
|
|
94
|
-
* dial queue, this value controls how many addresses to dial in parallel per
|
|
95
|
-
* peer. So for example if two peers have 10 addresses and this value is set
|
|
96
|
-
* at 5, we will dial 5 addresses from each at a time. (default: 1)
|
|
97
|
-
*/
|
|
98
|
-
maxParallelDialsPerPeer?: number
|
|
99
|
-
|
|
100
92
|
/**
|
|
101
93
|
* Maximum number of addresses allowed for a given peer - if a peer has more
|
|
102
94
|
* addresses than this then the dial will fail. (default: 25)
|
|
@@ -186,7 +178,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
186
178
|
private readonly peerStore: PeerStore
|
|
187
179
|
private readonly metrics?: Metrics
|
|
188
180
|
private readonly events: TypedEventTarget<Libp2pEvents>
|
|
189
|
-
readonly
|
|
181
|
+
private readonly log: Logger
|
|
190
182
|
|
|
191
183
|
constructor (components: DefaultConnectionManagerComponents, init: ConnectionManagerInit = {}) {
|
|
192
184
|
this.maxConnections = init.maxConnections ?? defaultOptions.maxConnections
|
|
@@ -205,7 +197,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
205
197
|
this.peerStore = components.peerStore
|
|
206
198
|
this.metrics = components.metrics
|
|
207
199
|
this.events = components.events
|
|
208
|
-
this
|
|
200
|
+
this.log = components.logger.forComponent('libp2p:connection-manager')
|
|
209
201
|
|
|
210
202
|
this.onConnect = this.onConnect.bind(this)
|
|
211
203
|
this.onDisconnect = this.onDisconnect.bind(this)
|
|
@@ -260,7 +252,6 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
260
252
|
addressSorter: init.addressSorter ?? defaultAddressSort,
|
|
261
253
|
maxParallelDials: init.maxParallelDials ?? MAX_PARALLEL_DIALS,
|
|
262
254
|
maxPeerAddrsToDial: init.maxPeerAddrsToDial ?? MAX_PEER_ADDRS_TO_DIAL,
|
|
263
|
-
maxParallelDialsPerPeer: init.maxParallelDialsPerPeer ?? MAX_PARALLEL_DIALS_PER_PEER,
|
|
264
255
|
dialTimeout: init.dialTimeout ?? DIAL_TIMEOUT,
|
|
265
256
|
resolvers: init.resolvers ?? {
|
|
266
257
|
dnsaddr: dnsaddrResolver
|
|
@@ -359,7 +350,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
359
350
|
this.autoDial.start()
|
|
360
351
|
|
|
361
352
|
this.started = true
|
|
362
|
-
this
|
|
353
|
+
this.log('started')
|
|
363
354
|
}
|
|
364
355
|
|
|
365
356
|
async afterStart (): Promise<void> {
|
|
@@ -376,13 +367,13 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
376
367
|
keepAlivePeers.map(async peer => {
|
|
377
368
|
await this.openConnection(peer.id)
|
|
378
369
|
.catch(err => {
|
|
379
|
-
this
|
|
370
|
+
this.log.error(err)
|
|
380
371
|
})
|
|
381
372
|
})
|
|
382
373
|
)
|
|
383
374
|
})
|
|
384
375
|
.catch(err => {
|
|
385
|
-
this
|
|
376
|
+
this.log.error(err)
|
|
386
377
|
})
|
|
387
378
|
|
|
388
379
|
this.autoDial.afterStart()
|
|
@@ -403,22 +394,22 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
403
394
|
try {
|
|
404
395
|
await connection.close()
|
|
405
396
|
} catch (err) {
|
|
406
|
-
this
|
|
397
|
+
this.log.error(err)
|
|
407
398
|
}
|
|
408
399
|
})())
|
|
409
400
|
}
|
|
410
401
|
}
|
|
411
402
|
|
|
412
|
-
this
|
|
403
|
+
this.log('closing %d connections', tasks.length)
|
|
413
404
|
await Promise.all(tasks)
|
|
414
405
|
this.connections.clear()
|
|
415
406
|
|
|
416
|
-
this
|
|
407
|
+
this.log('stopped')
|
|
417
408
|
}
|
|
418
409
|
|
|
419
410
|
onConnect (evt: CustomEvent<Connection>): void {
|
|
420
411
|
void this._onConnect(evt).catch(err => {
|
|
421
|
-
this
|
|
412
|
+
this.log.error(err)
|
|
422
413
|
})
|
|
423
414
|
}
|
|
424
415
|
|
|
@@ -508,12 +499,12 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
508
499
|
const { peerId } = getPeerAddress(peerIdOrMultiaddr)
|
|
509
500
|
|
|
510
501
|
if (peerId != null && options.force !== true) {
|
|
511
|
-
this
|
|
502
|
+
this.log('dial %p', peerId)
|
|
512
503
|
const existingConnection = this.getConnections(peerId)
|
|
513
504
|
.find(conn => !conn.transient)
|
|
514
505
|
|
|
515
506
|
if (existingConnection != null) {
|
|
516
|
-
this
|
|
507
|
+
this.log('had an existing non-transient connection to %p', peerId)
|
|
517
508
|
|
|
518
509
|
return existingConnection
|
|
519
510
|
}
|
|
@@ -569,7 +560,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
569
560
|
})
|
|
570
561
|
|
|
571
562
|
if (denyConnection) {
|
|
572
|
-
this
|
|
563
|
+
this.log('connection from %a refused - connection remote address was in deny list', maConn.remoteAddr)
|
|
573
564
|
return false
|
|
574
565
|
}
|
|
575
566
|
|
|
@@ -586,7 +577,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
586
577
|
|
|
587
578
|
// check pending connections
|
|
588
579
|
if (this.incomingPendingConnections === this.maxIncomingPendingConnections) {
|
|
589
|
-
this
|
|
580
|
+
this.log('connection from %a refused - incomingPendingConnections exceeded by host', maConn.remoteAddr)
|
|
590
581
|
return false
|
|
591
582
|
}
|
|
592
583
|
|
|
@@ -596,7 +587,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
596
587
|
try {
|
|
597
588
|
await this.inboundConnectionRateLimiter.consume(host, 1)
|
|
598
589
|
} catch {
|
|
599
|
-
this
|
|
590
|
+
this.log('connection from %a refused - inboundConnectionThreshold exceeded by host %s', maConn.remoteAddr, host)
|
|
600
591
|
return false
|
|
601
592
|
}
|
|
602
593
|
}
|
|
@@ -607,7 +598,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
607
598
|
return true
|
|
608
599
|
}
|
|
609
600
|
|
|
610
|
-
this
|
|
601
|
+
this.log('connection from %a refused - maxConnections exceeded', maConn.remoteAddr)
|
|
611
602
|
return false
|
|
612
603
|
}
|
|
613
604
|
|
package/src/errors.ts
CHANGED
|
@@ -37,7 +37,6 @@ export enum codes {
|
|
|
37
37
|
ERR_INVALID_PEER = 'ERR_INVALID_PEER',
|
|
38
38
|
ERR_MUXER_UNAVAILABLE = 'ERR_MUXER_UNAVAILABLE',
|
|
39
39
|
ERR_NOT_FOUND = 'ERR_NOT_FOUND',
|
|
40
|
-
ERR_TIMEOUT = 'ERR_TIMEOUT',
|
|
41
40
|
ERR_TRANSPORT_UNAVAILABLE = 'ERR_TRANSPORT_UNAVAILABLE',
|
|
42
41
|
ERR_TRANSPORT_DIAL_FAILED = 'ERR_TRANSPORT_DIAL_FAILED',
|
|
43
42
|
ERR_UNSUPPORTED_PROTOCOL = 'ERR_UNSUPPORTED_PROTOCOL',
|
|
@@ -48,7 +47,6 @@ export enum codes {
|
|
|
48
47
|
ERR_NO_ROUTERS_AVAILABLE = 'ERR_NO_ROUTERS_AVAILABLE',
|
|
49
48
|
ERR_CONNECTION_NOT_MULTIPLEXED = 'ERR_CONNECTION_NOT_MULTIPLEXED',
|
|
50
49
|
ERR_NO_DIAL_TOKENS = 'ERR_NO_DIAL_TOKENS',
|
|
51
|
-
ERR_KEYCHAIN_REQUIRED = 'ERR_KEYCHAIN_REQUIRED',
|
|
52
50
|
ERR_INVALID_CMS = 'ERR_INVALID_CMS',
|
|
53
51
|
ERR_MISSING_KEYS = 'ERR_MISSING_KEYS',
|
|
54
52
|
ERR_NO_KEY = 'ERR_NO_KEY',
|
package/src/get-peer.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
2
2
|
import { isPeerId } from '@libp2p/interface/peer-id'
|
|
3
|
-
import { logger } from '@libp2p/logger'
|
|
4
3
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
5
4
|
import { isMultiaddr } from '@multiformats/multiaddr'
|
|
6
5
|
import { codes } from './errors.js'
|
|
7
6
|
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
8
7
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
9
8
|
|
|
10
|
-
const log = logger('libp2p:get-peer')
|
|
11
|
-
|
|
12
9
|
export interface PeerAddress {
|
|
13
10
|
peerId?: PeerId
|
|
14
11
|
multiaddrs: Multiaddr[]
|
|
@@ -35,7 +32,6 @@ export function getPeerAddress (peer: PeerId | Multiaddr | Multiaddr[]): PeerAdd
|
|
|
35
32
|
// ensure PeerId is either not set or is consistent
|
|
36
33
|
peer.forEach(ma => {
|
|
37
34
|
if (!isMultiaddr(ma)) {
|
|
38
|
-
log.error('multiaddr %s was invalid', ma)
|
|
39
35
|
throw new CodeError('Invalid Multiaddr', codes.ERR_INVALID_MULTIADDR)
|
|
40
36
|
}
|
|
41
37
|
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ import type { AddressManagerInit } from './address-manager/index.js'
|
|
|
19
19
|
import type { Components } from './components.js'
|
|
20
20
|
import type { ConnectionManagerInit } from './connection-manager/index.js'
|
|
21
21
|
import type { TransportManagerInit } from './transport-manager.js'
|
|
22
|
-
import type { Libp2p, ServiceMap, RecursivePartial, ComponentLogger } from '@libp2p/interface'
|
|
22
|
+
import type { Libp2p, ServiceMap, RecursivePartial, ComponentLogger, NodeInfo } from '@libp2p/interface'
|
|
23
23
|
import type { ConnectionProtector } from '@libp2p/interface/connection'
|
|
24
24
|
import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter'
|
|
25
25
|
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
@@ -30,7 +30,6 @@ import type { PeerId } from '@libp2p/interface/peer-id'
|
|
|
30
30
|
import type { PeerRouting } from '@libp2p/interface/peer-routing'
|
|
31
31
|
import type { StreamMuxerFactory } from '@libp2p/interface/stream-muxer'
|
|
32
32
|
import type { Transport } from '@libp2p/interface/transport'
|
|
33
|
-
import type { KeyChainInit } from '@libp2p/keychain'
|
|
34
33
|
import type { PersistentPeerStoreInit } from '@libp2p/peer-store'
|
|
35
34
|
import type { Datastore } from 'interface-datastore'
|
|
36
35
|
|
|
@@ -47,6 +46,11 @@ export interface Libp2pInit<T extends ServiceMap = { x: Record<string, unknown>
|
|
|
47
46
|
*/
|
|
48
47
|
peerId: PeerId
|
|
49
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Metadata about the node - implementation name, version number, etc
|
|
51
|
+
*/
|
|
52
|
+
nodeInfo: NodeInfo
|
|
53
|
+
|
|
50
54
|
/**
|
|
51
55
|
* Addresses for transport listening and to advertise to the network
|
|
52
56
|
*/
|
|
@@ -79,11 +83,6 @@ export interface Libp2pInit<T extends ServiceMap = { x: Record<string, unknown>
|
|
|
79
83
|
*/
|
|
80
84
|
peerStore: PersistentPeerStoreInit
|
|
81
85
|
|
|
82
|
-
/**
|
|
83
|
-
* keychain configuration
|
|
84
|
-
*/
|
|
85
|
-
keychain: KeyChainInit
|
|
86
|
-
|
|
87
86
|
/**
|
|
88
87
|
* An array that must include at least 1 compliant transport
|
|
89
88
|
*/
|