libp2p 0.46.21 → 1.0.0-551622a96
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 +51 -47
- package/dist/index.min.js +40 -28
- package/dist/src/address-manager/index.d.ts +4 -5
- 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 +4 -15
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +2 -2
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +1 -1
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -1
- package/dist/src/config/connection-gater.browser.js.map +1 -1
- package/dist/src/config/connection-gater.d.ts +1 -1
- package/dist/src/config/connection-gater.d.ts.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +1 -2
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection/index.d.ts +4 -6
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +11 -13
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +3 -6
- 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 +3 -5
- 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 +3 -10
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +30 -38
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +3 -18
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +17 -18
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/utils.js +1 -1
- package/dist/src/connection-manager/utils.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +1 -5
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +2 -2
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts +1 -2
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +1 -1
- package/dist/src/content-routing/utils.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 +1 -1
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +1 -5
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/index.d.ts +5 -16
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +4 -12
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +31 -65
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +6 -6
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +12 -9
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/registrar.d.ts +5 -7
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +4 -4
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +5 -9
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +12 -13
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +8 -19
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +75 -38
- 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 +37 -106
- package/src/address-manager/index.ts +6 -9
- package/src/components.ts +5 -16
- package/src/config/connection-gater.browser.ts +1 -1
- package/src/config/connection-gater.ts +1 -1
- package/src/config.ts +1 -2
- package/src/connection/index.ts +12 -17
- package/src/connection-manager/auto-dial.ts +23 -26
- package/src/connection-manager/connection-pruner.ts +10 -12
- package/src/connection-manager/constants.defaults.ts +0 -5
- package/src/connection-manager/dial-queue.ts +31 -46
- package/src/connection-manager/index.ts +19 -36
- package/src/connection-manager/utils.ts +1 -1
- package/src/content-routing/index.ts +3 -7
- package/src/content-routing/utils.ts +2 -3
- package/src/errors.ts +0 -2
- package/src/get-peer.ts +2 -7
- package/src/index.ts +6 -17
- package/src/libp2p.ts +32 -80
- package/src/peer-routing.ts +16 -15
- package/src/registrar.ts +8 -12
- package/src/transport-manager.ts +15 -22
- package/src/upgrader.ts +110 -64
- 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,9 +1,7 @@
|
|
|
1
1
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
2
2
|
import { MAX_CONNECTIONS } from './constants.js'
|
|
3
|
-
import type { Libp2pEvents, Logger, ComponentLogger } from '@libp2p/interface'
|
|
4
|
-
import type {
|
|
5
|
-
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
6
|
-
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
3
|
+
import type { Libp2pEvents, Logger, ComponentLogger, TypedEventTarget, PeerStore } from '@libp2p/interface'
|
|
4
|
+
import type { ConnectionManager } from '@libp2p/interface-internal'
|
|
7
5
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
8
6
|
|
|
9
7
|
interface ConnectionPrunerInit {
|
|
@@ -32,7 +30,7 @@ export class ConnectionPruner {
|
|
|
32
30
|
private readonly peerStore: PeerStore
|
|
33
31
|
private readonly allow: Multiaddr[]
|
|
34
32
|
private readonly events: TypedEventTarget<Libp2pEvents>
|
|
35
|
-
readonly
|
|
33
|
+
private readonly log: Logger
|
|
36
34
|
|
|
37
35
|
constructor (components: ConnectionPrunerComponents, init: ConnectionPrunerInit = {}) {
|
|
38
36
|
this.maxConnections = init.maxConnections ?? defaultOptions.maxConnections
|
|
@@ -40,13 +38,13 @@ export class ConnectionPruner {
|
|
|
40
38
|
this.connectionManager = components.connectionManager
|
|
41
39
|
this.peerStore = components.peerStore
|
|
42
40
|
this.events = components.events
|
|
43
|
-
this
|
|
41
|
+
this.log = components.logger.forComponent('libp2p:connection-manager:connection-pruner')
|
|
44
42
|
|
|
45
43
|
// check the max connection limit whenever a peer connects
|
|
46
44
|
components.events.addEventListener('connection:open', () => {
|
|
47
45
|
this.maybePruneConnections()
|
|
48
46
|
.catch(err => {
|
|
49
|
-
this
|
|
47
|
+
this.log.error(err)
|
|
50
48
|
})
|
|
51
49
|
})
|
|
52
50
|
}
|
|
@@ -60,12 +58,12 @@ export class ConnectionPruner {
|
|
|
60
58
|
const numConnections = connections.length
|
|
61
59
|
const toPrune = Math.max(numConnections - this.maxConnections, 0)
|
|
62
60
|
|
|
63
|
-
this
|
|
61
|
+
this.log('checking max connections limit %d/%d', numConnections, this.maxConnections)
|
|
64
62
|
if (numConnections <= this.maxConnections) {
|
|
65
63
|
return
|
|
66
64
|
}
|
|
67
65
|
|
|
68
|
-
this
|
|
66
|
+
this.log('max connections limit exceeded %d/%d, pruning %d connection(s)', numConnections, this.maxConnections, toPrune)
|
|
69
67
|
const peerValues = new PeerMap<number>()
|
|
70
68
|
|
|
71
69
|
// work out peer values
|
|
@@ -87,7 +85,7 @@ export class ConnectionPruner {
|
|
|
87
85
|
}, 0))
|
|
88
86
|
} catch (err: any) {
|
|
89
87
|
if (err.code !== 'ERR_NOT_FOUND') {
|
|
90
|
-
this
|
|
88
|
+
this.log.error('error loading peer tags', err)
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
}
|
|
@@ -124,7 +122,7 @@ export class ConnectionPruner {
|
|
|
124
122
|
const toClose = []
|
|
125
123
|
|
|
126
124
|
for (const connection of sortedConnections) {
|
|
127
|
-
this
|
|
125
|
+
this.log('too many connections open - closing a connection to %p', connection.remotePeer)
|
|
128
126
|
// check allow list
|
|
129
127
|
const connectionInAllowList = this.allow.some((ma) => {
|
|
130
128
|
return connection.remoteAddr.toString().startsWith(ma.toString())
|
|
@@ -146,7 +144,7 @@ export class ConnectionPruner {
|
|
|
146
144
|
try {
|
|
147
145
|
await connection.close()
|
|
148
146
|
} catch (err) {
|
|
149
|
-
this
|
|
147
|
+
this.log.error(err)
|
|
150
148
|
}
|
|
151
149
|
})
|
|
152
150
|
)
|
|
@@ -13,11 +13,6 @@ export const INBOUND_UPGRADE_TIMEOUT = 30e3
|
|
|
13
13
|
*/
|
|
14
14
|
export const MAX_PEER_ADDRS_TO_DIAL = 25
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDialsPerPeer
|
|
18
|
-
*/
|
|
19
|
-
export const MAX_PARALLEL_DIALS_PER_PEER = 1
|
|
20
|
-
|
|
21
16
|
/**
|
|
22
17
|
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialInterval
|
|
23
18
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AbortError, CodeError } from '@libp2p/interface
|
|
2
|
-
import { setMaxListeners } from '@libp2p/interface/events'
|
|
1
|
+
import { AbortError, CodeError, ERR_TIMEOUT, setMaxListeners } from '@libp2p/interface'
|
|
3
2
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
4
3
|
import { defaultAddressSort } from '@libp2p/utils/address-sort'
|
|
5
4
|
import { type Multiaddr, type Resolver, resolvers } from '@multiformats/multiaddr'
|
|
@@ -12,19 +11,13 @@ import { codes } from '../errors.js'
|
|
|
12
11
|
import { getPeerAddress } from '../get-peer.js'
|
|
13
12
|
import {
|
|
14
13
|
DIAL_TIMEOUT,
|
|
15
|
-
MAX_PARALLEL_DIALS_PER_PEER,
|
|
16
14
|
MAX_PARALLEL_DIALS,
|
|
17
15
|
MAX_PEER_ADDRS_TO_DIAL,
|
|
18
16
|
LAST_DIAL_FAILURE_KEY
|
|
19
17
|
} from './constants.js'
|
|
20
18
|
import { combineSignals, resolveMultiaddrs } from './utils.js'
|
|
21
|
-
import type { AddressSorter, AbortOptions, PendingDial, ComponentLogger, Logger } from '@libp2p/interface'
|
|
22
|
-
import type {
|
|
23
|
-
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
24
|
-
import type { Metric, Metrics } from '@libp2p/interface/metrics'
|
|
25
|
-
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
26
|
-
import type { Address, PeerStore } from '@libp2p/interface/peer-store'
|
|
27
|
-
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
|
19
|
+
import type { AddressSorter, AbortOptions, PendingDial, ComponentLogger, Logger, Connection, ConnectionGater, Metric, Metrics, PeerId, Address, PeerStore } from '@libp2p/interface'
|
|
20
|
+
import type { TransportManager } from '@libp2p/interface-internal'
|
|
28
21
|
|
|
29
22
|
export interface PendingDialTarget {
|
|
30
23
|
resolve(value: any): void
|
|
@@ -44,7 +37,6 @@ interface DialerInit {
|
|
|
44
37
|
addressSorter?: AddressSorter
|
|
45
38
|
maxParallelDials?: number
|
|
46
39
|
maxPeerAddrsToDial?: number
|
|
47
|
-
maxParallelDialsPerPeer?: number
|
|
48
40
|
dialTimeout?: number
|
|
49
41
|
resolvers?: Record<string, Resolver>
|
|
50
42
|
connections?: PeerMap<Connection[]>
|
|
@@ -54,7 +46,6 @@ const defaultOptions = {
|
|
|
54
46
|
addressSorter: defaultAddressSort,
|
|
55
47
|
maxParallelDials: MAX_PARALLEL_DIALS,
|
|
56
48
|
maxPeerAddrsToDial: MAX_PEER_ADDRS_TO_DIAL,
|
|
57
|
-
maxParallelDialsPerPeer: MAX_PARALLEL_DIALS_PER_PEER,
|
|
58
49
|
dialTimeout: DIAL_TIMEOUT,
|
|
59
50
|
resolvers: {
|
|
60
51
|
dnsaddr: dnsaddrResolver
|
|
@@ -79,21 +70,19 @@ export class DialQueue {
|
|
|
79
70
|
private readonly transportManager: TransportManager
|
|
80
71
|
private readonly addressSorter: AddressSorter
|
|
81
72
|
private readonly maxPeerAddrsToDial: number
|
|
82
|
-
private readonly maxParallelDialsPerPeer: number
|
|
83
73
|
private readonly dialTimeout: number
|
|
84
74
|
private readonly inProgressDialCount?: Metric
|
|
85
75
|
private readonly pendingDialCount?: Metric
|
|
86
76
|
private readonly shutDownController: AbortController
|
|
87
77
|
private readonly connections: PeerMap<Connection[]>
|
|
88
|
-
readonly
|
|
78
|
+
private readonly log: Logger
|
|
89
79
|
|
|
90
80
|
constructor (components: DialQueueComponents, init: DialerInit = {}) {
|
|
91
81
|
this.addressSorter = init.addressSorter ?? defaultOptions.addressSorter
|
|
92
82
|
this.maxPeerAddrsToDial = init.maxPeerAddrsToDial ?? defaultOptions.maxPeerAddrsToDial
|
|
93
|
-
this.maxParallelDialsPerPeer = init.maxParallelDialsPerPeer ?? defaultOptions.maxParallelDialsPerPeer
|
|
94
83
|
this.dialTimeout = init.dialTimeout ?? defaultOptions.dialTimeout
|
|
95
84
|
this.connections = init.connections ?? new PeerMap()
|
|
96
|
-
this
|
|
85
|
+
this.log = components.logger.forComponent('libp2p:connection-manager:dial-queue')
|
|
97
86
|
|
|
98
87
|
this.peerId = components.peerId
|
|
99
88
|
this.peerStore = components.peerStore
|
|
@@ -103,8 +92,8 @@ export class DialQueue {
|
|
|
103
92
|
|
|
104
93
|
setMaxListeners(Infinity, this.shutDownController.signal)
|
|
105
94
|
|
|
106
|
-
this.pendingDialCount = components.metrics?.registerMetric('
|
|
107
|
-
this.inProgressDialCount = components.metrics?.registerMetric('
|
|
95
|
+
this.pendingDialCount = components.metrics?.registerMetric('libp2p_dial_queue_pending_dials')
|
|
96
|
+
this.inProgressDialCount = components.metrics?.registerMetric('libp2p_dial_queue_in_progress_dials')
|
|
108
97
|
this.pendingDials = []
|
|
109
98
|
|
|
110
99
|
for (const [key, value] of Object.entries(init.resolvers ?? {})) {
|
|
@@ -133,7 +122,7 @@ export class DialQueue {
|
|
|
133
122
|
})
|
|
134
123
|
// a started job errored
|
|
135
124
|
this.queue.on('error', (err) => {
|
|
136
|
-
this
|
|
125
|
+
this.log.error('error in dial queue', err)
|
|
137
126
|
this.pendingDialCount?.update(this.queue.size)
|
|
138
127
|
this.inProgressDialCount?.update(this.queue.pending)
|
|
139
128
|
})
|
|
@@ -205,7 +194,7 @@ export class DialQueue {
|
|
|
205
194
|
})
|
|
206
195
|
|
|
207
196
|
if (existingConnection != null) {
|
|
208
|
-
this
|
|
197
|
+
this.log('already connected to %a', existingConnection.remoteAddr)
|
|
209
198
|
return existingConnection
|
|
210
199
|
}
|
|
211
200
|
|
|
@@ -226,12 +215,12 @@ export class DialQueue {
|
|
|
226
215
|
})
|
|
227
216
|
|
|
228
217
|
if (existingDial != null) {
|
|
229
|
-
this
|
|
218
|
+
this.log('joining existing dial target for %p', peerId)
|
|
230
219
|
signal.clear()
|
|
231
220
|
return existingDial.promise
|
|
232
221
|
}
|
|
233
222
|
|
|
234
|
-
this
|
|
223
|
+
this.log('creating dial target for', addrsToDial.map(({ multiaddr }) => multiaddr.toString()))
|
|
235
224
|
// @ts-expect-error .promise property is set below
|
|
236
225
|
const pendingDial: PendingDialInternal = {
|
|
237
226
|
id: randomId(),
|
|
@@ -252,7 +241,7 @@ export class DialQueue {
|
|
|
252
241
|
signal.clear()
|
|
253
242
|
})
|
|
254
243
|
.catch(async err => {
|
|
255
|
-
this
|
|
244
|
+
this.log.error('dial failed to %s', pendingDial.multiaddrs.map(ma => ma.toString()).join(', '), err)
|
|
256
245
|
|
|
257
246
|
if (peerId != null) {
|
|
258
247
|
// record the last failed dial
|
|
@@ -263,13 +252,13 @@ export class DialQueue {
|
|
|
263
252
|
}
|
|
264
253
|
})
|
|
265
254
|
} catch (err: any) {
|
|
266
|
-
this
|
|
255
|
+
this.log.error('could not update last dial failure key for %p', peerId, err)
|
|
267
256
|
}
|
|
268
257
|
}
|
|
269
258
|
|
|
270
259
|
// Error is a timeout
|
|
271
260
|
if (signal.aborted) {
|
|
272
|
-
const error = new CodeError(err.message,
|
|
261
|
+
const error = new CodeError(err.message, ERR_TIMEOUT)
|
|
273
262
|
throw error
|
|
274
263
|
}
|
|
275
264
|
|
|
@@ -294,12 +283,12 @@ export class DialQueue {
|
|
|
294
283
|
})
|
|
295
284
|
|
|
296
285
|
if (existingConnection != null) {
|
|
297
|
-
this
|
|
286
|
+
this.log('already connected to %a', existingConnection.remoteAddr)
|
|
298
287
|
await connection.close()
|
|
299
288
|
return existingConnection
|
|
300
289
|
}
|
|
301
290
|
|
|
302
|
-
this
|
|
291
|
+
this.log('connection opened to %a', connection.remoteAddr)
|
|
303
292
|
return connection
|
|
304
293
|
}
|
|
305
294
|
|
|
@@ -334,11 +323,11 @@ export class DialQueue {
|
|
|
334
323
|
|
|
335
324
|
// if just a peer id was passed, load available multiaddrs for this peer from the address book
|
|
336
325
|
if (addrs.length === 0) {
|
|
337
|
-
this
|
|
326
|
+
this.log('loading multiaddrs for %p', peerId)
|
|
338
327
|
try {
|
|
339
328
|
const peer = await this.peerStore.get(peerId)
|
|
340
329
|
addrs.push(...peer.addresses)
|
|
341
|
-
this
|
|
330
|
+
this.log('loaded multiaddrs for %p', peerId, addrs.map(({ multiaddr }) => multiaddr.toString()))
|
|
342
331
|
} catch (err: any) {
|
|
343
332
|
if (err.code !== codes.ERR_NOT_FOUND) {
|
|
344
333
|
throw err
|
|
@@ -352,7 +341,7 @@ export class DialQueue {
|
|
|
352
341
|
addrs.map(async addr => {
|
|
353
342
|
const result = await resolveMultiaddrs(addr.multiaddr, {
|
|
354
343
|
...options,
|
|
355
|
-
log: this
|
|
344
|
+
log: this.log
|
|
356
345
|
})
|
|
357
346
|
|
|
358
347
|
if (result.length === 1 && result[0].equals(addr.multiaddr)) {
|
|
@@ -425,8 +414,8 @@ export class DialQueue {
|
|
|
425
414
|
const dedupedMultiaddrs = [...dedupedAddrs.values()]
|
|
426
415
|
|
|
427
416
|
if (dedupedMultiaddrs.length === 0 || dedupedMultiaddrs.length > this.maxPeerAddrsToDial) {
|
|
428
|
-
this
|
|
429
|
-
this
|
|
417
|
+
this.log('addresses for %p before filtering', peerId ?? 'unknown peer', resolvedAddresses.map(({ multiaddr }) => multiaddr.toString()))
|
|
418
|
+
this.log('addresses for %p after filtering', peerId ?? 'unknown peer', dedupedMultiaddrs.map(({ multiaddr }) => multiaddr.toString()))
|
|
430
419
|
}
|
|
431
420
|
|
|
432
421
|
// make sure we actually have some addresses to dial
|
|
@@ -463,14 +452,10 @@ export class DialQueue {
|
|
|
463
452
|
const dialAbortControllers: Array<(AbortController | undefined)> = pendingDial.multiaddrs.map(() => new AbortController())
|
|
464
453
|
|
|
465
454
|
try {
|
|
466
|
-
// internal peer dial queue
|
|
467
|
-
|
|
468
|
-
// the dial queue
|
|
469
|
-
const peerDialQueue = new PQueue({
|
|
470
|
-
concurrency: this.maxParallelDialsPerPeer
|
|
471
|
-
})
|
|
455
|
+
// internal peer dial queue - only one dial per peer at a time
|
|
456
|
+
const peerDialQueue = new PQueue({ concurrency: 1 })
|
|
472
457
|
peerDialQueue.on('error', (err) => {
|
|
473
|
-
this
|
|
458
|
+
this.log.error('error dialing %s %o', pendingDial.multiaddrs, err)
|
|
474
459
|
})
|
|
475
460
|
|
|
476
461
|
const conn = await Promise.any(pendingDial.multiaddrs.map(async (addr, i) => {
|
|
@@ -483,13 +468,13 @@ export class DialQueue {
|
|
|
483
468
|
// let any signal abort the dial
|
|
484
469
|
const signal = combineSignals(controller.signal, options.signal)
|
|
485
470
|
signal.addEventListener('abort', () => {
|
|
486
|
-
this
|
|
471
|
+
this.log('dial to %a aborted', addr)
|
|
487
472
|
})
|
|
488
473
|
const deferred = pDefer<Connection>()
|
|
489
474
|
|
|
490
475
|
await peerDialQueue.add(async () => {
|
|
491
476
|
if (signal.aborted) {
|
|
492
|
-
this
|
|
477
|
+
this.log('dial to %a was aborted before reaching the head of the peer dial queue', addr)
|
|
493
478
|
deferred.reject(new AbortError())
|
|
494
479
|
return
|
|
495
480
|
}
|
|
@@ -498,7 +483,7 @@ export class DialQueue {
|
|
|
498
483
|
await this.queue.add(async () => {
|
|
499
484
|
try {
|
|
500
485
|
if (signal.aborted) {
|
|
501
|
-
this
|
|
486
|
+
this.log('dial to %a was aborted before reaching the head of the dial queue', addr)
|
|
502
487
|
deferred.reject(new AbortError())
|
|
503
488
|
return
|
|
504
489
|
}
|
|
@@ -513,10 +498,10 @@ export class DialQueue {
|
|
|
513
498
|
|
|
514
499
|
if (controller.signal.aborted) {
|
|
515
500
|
// another dial succeeded faster than this one
|
|
516
|
-
this
|
|
501
|
+
this.log('multiple dials succeeded, closing superfluous connection')
|
|
517
502
|
|
|
518
503
|
conn.close().catch(err => {
|
|
519
|
-
this
|
|
504
|
+
this.log.error('error closing superfluous connection', err)
|
|
520
505
|
})
|
|
521
506
|
|
|
522
507
|
deferred.reject(new AbortError())
|
|
@@ -533,13 +518,13 @@ export class DialQueue {
|
|
|
533
518
|
}
|
|
534
519
|
})
|
|
535
520
|
|
|
536
|
-
this
|
|
521
|
+
this.log('dial to %a succeeded', addr)
|
|
537
522
|
|
|
538
523
|
// resolve the connection promise
|
|
539
524
|
deferred.resolve(conn)
|
|
540
525
|
} catch (err: any) {
|
|
541
526
|
// something only went wrong if our signal was not aborted
|
|
542
|
-
this
|
|
527
|
+
this.log.error('error during dial of %a', addr, err)
|
|
543
528
|
deferred.reject(err)
|
|
544
529
|
}
|
|
545
530
|
}, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface
|
|
1
|
+
import { CodeError } from '@libp2p/interface'
|
|
2
2
|
import { KEEP_ALIVE } from '@libp2p/interface/peer-store/tags'
|
|
3
3
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
4
4
|
import { defaultAddressSort } from '@libp2p/utils/address-sort'
|
|
@@ -9,18 +9,10 @@ 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
|
-
import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions, ComponentLogger, Logger } from '@libp2p/interface'
|
|
15
|
-
import type {
|
|
16
|
-
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
17
|
-
import type { TypedEventTarget } from '@libp2p/interface/events'
|
|
18
|
-
import type { Metrics } from '@libp2p/interface/metrics'
|
|
19
|
-
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
20
|
-
import type { Peer, PeerStore } from '@libp2p/interface/peer-store'
|
|
21
|
-
import type { Startable } from '@libp2p/interface/startable'
|
|
22
|
-
import type { ConnectionManager, OpenConnectionOptions } from '@libp2p/interface-internal/connection-manager'
|
|
23
|
-
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
|
14
|
+
import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions, ComponentLogger, Logger, Connection, MultiaddrConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, Peer, PeerStore, Startable } from '@libp2p/interface'
|
|
15
|
+
import type { ConnectionManager, OpenConnectionOptions, TransportManager } from '@libp2p/interface-internal'
|
|
24
16
|
|
|
25
17
|
const DEFAULT_DIAL_PRIORITY = 50
|
|
26
18
|
|
|
@@ -89,14 +81,6 @@ export interface ConnectionManagerInit {
|
|
|
89
81
|
*/
|
|
90
82
|
maxParallelDials?: number
|
|
91
83
|
|
|
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
84
|
/**
|
|
101
85
|
* Maximum number of addresses allowed for a given peer - if a peer has more
|
|
102
86
|
* addresses than this then the dial will fail. (default: 25)
|
|
@@ -186,7 +170,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
186
170
|
private readonly peerStore: PeerStore
|
|
187
171
|
private readonly metrics?: Metrics
|
|
188
172
|
private readonly events: TypedEventTarget<Libp2pEvents>
|
|
189
|
-
readonly
|
|
173
|
+
private readonly log: Logger
|
|
190
174
|
|
|
191
175
|
constructor (components: DefaultConnectionManagerComponents, init: ConnectionManagerInit = {}) {
|
|
192
176
|
this.maxConnections = init.maxConnections ?? defaultOptions.maxConnections
|
|
@@ -205,7 +189,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
205
189
|
this.peerStore = components.peerStore
|
|
206
190
|
this.metrics = components.metrics
|
|
207
191
|
this.events = components.events
|
|
208
|
-
this
|
|
192
|
+
this.log = components.logger.forComponent('libp2p:connection-manager')
|
|
209
193
|
|
|
210
194
|
this.onConnect = this.onConnect.bind(this)
|
|
211
195
|
this.onDisconnect = this.onDisconnect.bind(this)
|
|
@@ -260,7 +244,6 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
260
244
|
addressSorter: init.addressSorter ?? defaultAddressSort,
|
|
261
245
|
maxParallelDials: init.maxParallelDials ?? MAX_PARALLEL_DIALS,
|
|
262
246
|
maxPeerAddrsToDial: init.maxPeerAddrsToDial ?? MAX_PEER_ADDRS_TO_DIAL,
|
|
263
|
-
maxParallelDialsPerPeer: init.maxParallelDialsPerPeer ?? MAX_PARALLEL_DIALS_PER_PEER,
|
|
264
247
|
dialTimeout: init.dialTimeout ?? DIAL_TIMEOUT,
|
|
265
248
|
resolvers: init.resolvers ?? {
|
|
266
249
|
dnsaddr: dnsaddrResolver
|
|
@@ -359,7 +342,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
359
342
|
this.autoDial.start()
|
|
360
343
|
|
|
361
344
|
this.started = true
|
|
362
|
-
this
|
|
345
|
+
this.log('started')
|
|
363
346
|
}
|
|
364
347
|
|
|
365
348
|
async afterStart (): Promise<void> {
|
|
@@ -376,13 +359,13 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
376
359
|
keepAlivePeers.map(async peer => {
|
|
377
360
|
await this.openConnection(peer.id)
|
|
378
361
|
.catch(err => {
|
|
379
|
-
this
|
|
362
|
+
this.log.error(err)
|
|
380
363
|
})
|
|
381
364
|
})
|
|
382
365
|
)
|
|
383
366
|
})
|
|
384
367
|
.catch(err => {
|
|
385
|
-
this
|
|
368
|
+
this.log.error(err)
|
|
386
369
|
})
|
|
387
370
|
|
|
388
371
|
this.autoDial.afterStart()
|
|
@@ -403,22 +386,22 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
403
386
|
try {
|
|
404
387
|
await connection.close()
|
|
405
388
|
} catch (err) {
|
|
406
|
-
this
|
|
389
|
+
this.log.error(err)
|
|
407
390
|
}
|
|
408
391
|
})())
|
|
409
392
|
}
|
|
410
393
|
}
|
|
411
394
|
|
|
412
|
-
this
|
|
395
|
+
this.log('closing %d connections', tasks.length)
|
|
413
396
|
await Promise.all(tasks)
|
|
414
397
|
this.connections.clear()
|
|
415
398
|
|
|
416
|
-
this
|
|
399
|
+
this.log('stopped')
|
|
417
400
|
}
|
|
418
401
|
|
|
419
402
|
onConnect (evt: CustomEvent<Connection>): void {
|
|
420
403
|
void this._onConnect(evt).catch(err => {
|
|
421
|
-
this
|
|
404
|
+
this.log.error(err)
|
|
422
405
|
})
|
|
423
406
|
}
|
|
424
407
|
|
|
@@ -508,12 +491,12 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
508
491
|
const { peerId } = getPeerAddress(peerIdOrMultiaddr)
|
|
509
492
|
|
|
510
493
|
if (peerId != null && options.force !== true) {
|
|
511
|
-
this
|
|
494
|
+
this.log('dial %p', peerId)
|
|
512
495
|
const existingConnection = this.getConnections(peerId)
|
|
513
496
|
.find(conn => !conn.transient)
|
|
514
497
|
|
|
515
498
|
if (existingConnection != null) {
|
|
516
|
-
this
|
|
499
|
+
this.log('had an existing non-transient connection to %p', peerId)
|
|
517
500
|
|
|
518
501
|
return existingConnection
|
|
519
502
|
}
|
|
@@ -569,7 +552,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
569
552
|
})
|
|
570
553
|
|
|
571
554
|
if (denyConnection) {
|
|
572
|
-
this
|
|
555
|
+
this.log('connection from %a refused - connection remote address was in deny list', maConn.remoteAddr)
|
|
573
556
|
return false
|
|
574
557
|
}
|
|
575
558
|
|
|
@@ -586,7 +569,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
586
569
|
|
|
587
570
|
// check pending connections
|
|
588
571
|
if (this.incomingPendingConnections === this.maxIncomingPendingConnections) {
|
|
589
|
-
this
|
|
572
|
+
this.log('connection from %a refused - incomingPendingConnections exceeded by host', maConn.remoteAddr)
|
|
590
573
|
return false
|
|
591
574
|
}
|
|
592
575
|
|
|
@@ -596,7 +579,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
596
579
|
try {
|
|
597
580
|
await this.inboundConnectionRateLimiter.consume(host, 1)
|
|
598
581
|
} catch {
|
|
599
|
-
this
|
|
582
|
+
this.log('connection from %a refused - inboundConnectionThreshold exceeded by host %s', maConn.remoteAddr, host)
|
|
600
583
|
return false
|
|
601
584
|
}
|
|
602
585
|
}
|
|
@@ -607,7 +590,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
607
590
|
return true
|
|
608
591
|
}
|
|
609
592
|
|
|
610
|
-
this
|
|
593
|
+
this.log('connection from %a refused - maxConnections exceeded', maConn.remoteAddr)
|
|
611
594
|
return false
|
|
612
595
|
}
|
|
613
596
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setMaxListeners } from '@libp2p/interface
|
|
1
|
+
import { setMaxListeners } from '@libp2p/interface'
|
|
2
2
|
import { type AbortOptions, multiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import { type ClearableSignal, anySignal } from 'any-signal'
|
|
4
4
|
import type { LoggerOptions } from '@libp2p/interface'
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface
|
|
1
|
+
import { CodeError } from '@libp2p/interface'
|
|
2
2
|
import merge from 'it-merge'
|
|
3
3
|
import { pipe } from 'it-pipe'
|
|
4
|
-
import {
|
|
4
|
+
import { codes, messages } from '../errors.js'
|
|
5
5
|
import {
|
|
6
6
|
storeAddresses,
|
|
7
7
|
uniquePeers,
|
|
8
8
|
requirePeers
|
|
9
9
|
} from './utils.js'
|
|
10
|
-
import type { AbortOptions } from '@libp2p/interface'
|
|
11
|
-
import type { ContentRouting } from '@libp2p/interface/content-routing'
|
|
12
|
-
import type { PeerInfo } from '@libp2p/interface/peer-info'
|
|
13
|
-
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
14
|
-
import type { Startable } from '@libp2p/interface/startable'
|
|
10
|
+
import type { AbortOptions, ContentRouting, PeerInfo, PeerStore, Startable } from '@libp2p/interface'
|
|
15
11
|
import type { CID } from 'multiformats/cid'
|
|
16
12
|
|
|
17
13
|
export interface CompoundContentRoutingInit {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface
|
|
1
|
+
import { CodeError } from '@libp2p/interface'
|
|
2
2
|
import filter from 'it-filter'
|
|
3
3
|
import map from 'it-map'
|
|
4
|
-
import type { PeerInfo } from '@libp2p/interface
|
|
5
|
-
import type { PeerStore } from '@libp2p/interface/peer-store'
|
|
4
|
+
import type { PeerInfo, PeerStore } from '@libp2p/interface'
|
|
6
5
|
import type { Source } from 'it-stream-types'
|
|
7
6
|
|
|
8
7
|
/**
|
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,10 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface
|
|
2
|
-
import { isPeerId } from '@libp2p/interface/peer-id'
|
|
3
|
-
import { logger } from '@libp2p/logger'
|
|
1
|
+
import { CodeError, isPeerId } from '@libp2p/interface'
|
|
4
2
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
5
3
|
import { isMultiaddr } from '@multiformats/multiaddr'
|
|
6
4
|
import { codes } from './errors.js'
|
|
7
|
-
import type { PeerId } from '@libp2p/interface
|
|
5
|
+
import type { PeerId } from '@libp2p/interface'
|
|
8
6
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
9
7
|
|
|
10
|
-
const log = logger('libp2p:get-peer')
|
|
11
|
-
|
|
12
8
|
export interface PeerAddress {
|
|
13
9
|
peerId?: PeerId
|
|
14
10
|
multiaddrs: Multiaddr[]
|
|
@@ -35,7 +31,6 @@ export function getPeerAddress (peer: PeerId | Multiaddr | Multiaddr[]): PeerAdd
|
|
|
35
31
|
// ensure PeerId is either not set or is consistent
|
|
36
32
|
peer.forEach(ma => {
|
|
37
33
|
if (!isMultiaddr(ma)) {
|
|
38
|
-
log.error('multiaddr %s was invalid', ma)
|
|
39
34
|
throw new CodeError('Invalid Multiaddr', codes.ERR_INVALID_MULTIADDR)
|
|
40
35
|
}
|
|
41
36
|
|
package/src/index.ts
CHANGED
|
@@ -19,18 +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'
|
|
23
|
-
import type { ConnectionProtector } from '@libp2p/interface/connection'
|
|
24
|
-
import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter'
|
|
25
|
-
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
26
|
-
import type { ContentRouting } from '@libp2p/interface/content-routing'
|
|
27
|
-
import type { Metrics } from '@libp2p/interface/metrics'
|
|
28
|
-
import type { PeerDiscovery } from '@libp2p/interface/peer-discovery'
|
|
29
|
-
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
30
|
-
import type { PeerRouting } from '@libp2p/interface/peer-routing'
|
|
31
|
-
import type { StreamMuxerFactory } from '@libp2p/interface/stream-muxer'
|
|
32
|
-
import type { Transport } from '@libp2p/interface/transport'
|
|
33
|
-
import type { KeyChainInit } from '@libp2p/keychain'
|
|
22
|
+
import type { Libp2p, ServiceMap, RecursivePartial, ComponentLogger, NodeInfo, ConnectionProtector, ConnectionEncrypter, ConnectionGater, ContentRouting, Metrics, PeerDiscovery, PeerId, PeerRouting, StreamMuxerFactory, Transport } from '@libp2p/interface'
|
|
34
23
|
import type { PersistentPeerStoreInit } from '@libp2p/peer-store'
|
|
35
24
|
import type { Datastore } from 'interface-datastore'
|
|
36
25
|
|
|
@@ -47,6 +36,11 @@ export interface Libp2pInit<T extends ServiceMap = { x: Record<string, unknown>
|
|
|
47
36
|
*/
|
|
48
37
|
peerId: PeerId
|
|
49
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Metadata about the node - implementation name, version number, etc
|
|
41
|
+
*/
|
|
42
|
+
nodeInfo: NodeInfo
|
|
43
|
+
|
|
50
44
|
/**
|
|
51
45
|
* Addresses for transport listening and to advertise to the network
|
|
52
46
|
*/
|
|
@@ -79,11 +73,6 @@ export interface Libp2pInit<T extends ServiceMap = { x: Record<string, unknown>
|
|
|
79
73
|
*/
|
|
80
74
|
peerStore: PersistentPeerStoreInit
|
|
81
75
|
|
|
82
|
-
/**
|
|
83
|
-
* keychain configuration
|
|
84
|
-
*/
|
|
85
|
-
keychain: KeyChainInit
|
|
86
|
-
|
|
87
76
|
/**
|
|
88
77
|
* An array that must include at least 1 compliant transport
|
|
89
78
|
*/
|