libp2p 0.42.2 → 0.43.0
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 +4 -4
- package/dist/index.min.js +29 -29
- package/dist/src/address-manager/index.d.ts +1 -10
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +46 -29
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/autonat/constants.d.ts +4 -0
- package/dist/src/autonat/constants.d.ts.map +1 -0
- package/dist/src/autonat/constants.js +4 -0
- package/dist/src/autonat/constants.js.map +1 -0
- package/dist/src/autonat/index.d.ts +64 -0
- package/dist/src/autonat/index.d.ts.map +1 -0
- package/dist/src/autonat/index.js +417 -0
- package/dist/src/autonat/index.js.map +1 -0
- package/dist/src/autonat/pb/index.d.ts +57 -0
- package/dist/src/autonat/pb/index.d.ts.map +1 -0
- package/dist/src/autonat/pb/index.js +250 -0
- package/dist/src/autonat/pb/index.js.map +1 -0
- package/dist/src/circuit/constants.d.ts +31 -6
- package/dist/src/circuit/constants.d.ts.map +1 -1
- package/dist/src/circuit/constants.js +37 -7
- package/dist/src/circuit/constants.js.map +1 -1
- package/dist/src/circuit/index.d.ts +16 -61
- package/dist/src/circuit/index.d.ts.map +1 -1
- package/dist/src/circuit/index.js +2 -68
- package/dist/src/circuit/index.js.map +1 -1
- package/dist/src/circuit/pb/index.d.ts +83 -43
- package/dist/src/circuit/pb/index.d.ts.map +1 -1
- package/dist/src/circuit/pb/index.js +363 -127
- package/dist/src/circuit/pb/index.js.map +1 -1
- package/dist/src/circuit/server/advert-service.d.ts +43 -0
- package/dist/src/circuit/server/advert-service.d.ts.map +1 -0
- package/dist/src/circuit/server/advert-service.js +69 -0
- package/dist/src/circuit/server/advert-service.js.map +1 -0
- package/dist/src/circuit/server/index.d.ts +60 -0
- package/dist/src/circuit/server/index.d.ts.map +1 -0
- package/dist/src/circuit/server/index.js +287 -0
- package/dist/src/circuit/server/index.js.map +1 -0
- package/dist/src/circuit/server/reservation-store.d.ts +49 -0
- package/dist/src/circuit/server/reservation-store.d.ts.map +1 -0
- package/dist/src/circuit/server/reservation-store.js +57 -0
- package/dist/src/circuit/server/reservation-store.js.map +1 -0
- package/dist/src/circuit/server/reservation-voucher.d.ts +18 -0
- package/dist/src/circuit/server/reservation-voucher.d.ts.map +1 -0
- package/dist/src/circuit/server/reservation-voucher.js +33 -0
- package/dist/src/circuit/server/reservation-voucher.js.map +1 -0
- package/dist/src/circuit/transport/discovery.d.ts +45 -0
- package/dist/src/circuit/transport/discovery.d.ts.map +1 -0
- package/dist/src/circuit/transport/discovery.js +82 -0
- package/dist/src/circuit/transport/discovery.js.map +1 -0
- package/dist/src/circuit/transport/index.d.ts +33 -0
- package/dist/src/circuit/transport/index.d.ts.map +1 -0
- package/dist/src/circuit/transport/index.js +225 -0
- package/dist/src/circuit/transport/index.js.map +1 -0
- package/dist/src/circuit/transport/listener.d.ts +9 -0
- package/dist/src/circuit/transport/listener.d.ts.map +1 -0
- package/dist/src/circuit/transport/listener.js +76 -0
- package/dist/src/circuit/transport/listener.js.map +1 -0
- package/dist/src/circuit/transport/reservation-store.d.ts +60 -0
- package/dist/src/circuit/transport/reservation-store.d.ts.map +1 -0
- package/dist/src/circuit/transport/reservation-store.js +165 -0
- package/dist/src/circuit/transport/reservation-store.js.map +1 -0
- package/dist/src/circuit/utils.d.ts +7 -0
- package/dist/src/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/utils.js +87 -0
- package/dist/src/circuit/utils.js.map +1 -1
- package/dist/src/components.d.ts +2 -1
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +13 -13
- package/dist/src/components.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +21 -25
- package/dist/src/config.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 +4 -4
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +0 -4
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.js +18 -18
- package/dist/src/connection-manager/auto-dialler.js.map +1 -1
- package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/dial-request.js +13 -6
- package/dist/src/connection-manager/dialer/dial-request.js.map +1 -1
- package/dist/src/connection-manager/dialer/index.d.ts +10 -1
- package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/index.js +24 -9
- package/dist/src/connection-manager/dialer/index.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -4
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +8 -5
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/latency-monitor.d.ts.map +1 -1
- package/dist/src/connection-manager/latency-monitor.js +1 -1
- package/dist/src/connection-manager/latency-monitor.js.map +1 -1
- package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +1 -1
- package/dist/src/content-routing/index.d.ts +6 -4
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +9 -9
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts +3 -3
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +2 -2
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +2 -1
- package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.js +2 -2
- package/dist/src/dht/dht-content-routing.js.map +1 -1
- package/dist/src/dht/dht-peer-routing.d.ts +3 -2
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-peer-routing.js +2 -2
- package/dist/src/dht/dht-peer-routing.js.map +1 -1
- package/dist/src/dht/dummy-dht.d.ts +1 -1
- package/dist/src/dht/dummy-dht.d.ts.map +1 -1
- package/dist/src/dht/dummy-dht.js +12 -12
- package/dist/src/dht/dummy-dht.js.map +1 -1
- package/dist/src/errors.d.ts +2 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +1 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +6 -6
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/fetch/pb/proto.d.ts +3 -3
- package/dist/src/fetch/pb/proto.d.ts.map +1 -1
- package/dist/src/fetch/pb/proto.js +4 -3
- package/dist/src/fetch/pb/proto.js.map +1 -1
- package/dist/src/get-peer.js +2 -2
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/identify/index.d.ts +3 -1
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +19 -14
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/identify/pb/message.d.ts +2 -2
- package/dist/src/identify/pb/message.d.ts.map +1 -1
- package/dist/src/identify/pb/message.js +1 -0
- package/dist/src/identify/pb/message.js.map +1 -1
- package/dist/src/index.d.ts +14 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/insecure/index.d.ts.map +1 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/insecure/pb/proto.d.ts +3 -3
- package/dist/src/insecure/pb/proto.d.ts.map +1 -1
- package/dist/src/insecure/pb/proto.js +4 -5
- package/dist/src/insecure/pb/proto.js.map +1 -1
- package/dist/src/libp2p.d.ts +7 -3
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +35 -35
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/nat-manager.d.ts.map +1 -1
- package/dist/src/nat-manager.js +5 -3
- package/dist/src/nat-manager.js.map +1 -1
- package/dist/src/peer-record-updater.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +5 -5
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +2 -2
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/pnet/crypto.d.ts +1 -1
- package/dist/src/pnet/crypto.d.ts.map +1 -1
- package/dist/src/pnet/crypto.js +1 -1
- package/dist/src/pnet/crypto.js.map +1 -1
- package/dist/src/pnet/index.js +3 -3
- package/dist/src/pnet/index.js.map +1 -1
- package/dist/src/pnet/key-generator.d.ts.map +1 -1
- package/dist/src/pubsub/dummy-pubsub.js +9 -9
- package/dist/src/pubsub/dummy-pubsub.js.map +1 -1
- 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.map +1 -1
- package/dist/src/transport-manager.js +8 -9
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +2 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +38 -33
- package/dist/src/upgrader.js.map +1 -1
- package/dist/typedoc-urls.json +19 -6
- package/package.json +36 -33
- package/src/address-manager/index.ts +62 -35
- package/src/autonat/constants.ts +4 -0
- package/src/autonat/index.ts +567 -0
- package/src/autonat/pb/index.proto +35 -0
- package/src/autonat/pb/index.ts +320 -0
- package/src/circuit/constants.ts +48 -7
- package/src/circuit/index.ts +17 -129
- package/src/circuit/pb/index.proto +57 -32
- package/src/circuit/pb/index.ts +448 -138
- package/src/circuit/server/advert-service.ts +108 -0
- package/src/circuit/server/index.ts +421 -0
- package/src/circuit/server/reservation-store.ts +111 -0
- package/src/circuit/server/reservation-voucher.ts +51 -0
- package/src/circuit/transport/discovery.ts +127 -0
- package/src/circuit/transport/index.ts +325 -0
- package/src/circuit/transport/listener.ts +99 -0
- package/src/circuit/transport/reservation-store.ts +249 -0
- package/src/circuit/utils.ts +108 -0
- package/src/components.ts +22 -21
- package/src/config.ts +21 -25
- package/src/connection/index.ts +10 -10
- package/src/connection-manager/auto-dialler.ts +36 -40
- package/src/connection-manager/dialer/dial-request.ts +13 -6
- package/src/connection-manager/dialer/index.ts +34 -15
- package/src/connection-manager/index.ts +22 -23
- package/src/connection-manager/latency-monitor.ts +9 -9
- package/src/connection-manager/visibility-change-emitter.ts +4 -4
- package/src/content-routing/index.ts +18 -16
- package/src/content-routing/utils.ts +5 -5
- package/src/dht/dht-content-routing.ts +5 -4
- package/src/dht/dht-peer-routing.ts +5 -4
- package/src/dht/dummy-dht.ts +13 -13
- package/src/errors.ts +2 -1
- package/src/fetch/index.ts +13 -13
- package/src/fetch/pb/proto.ts +8 -7
- package/src/get-peer.ts +3 -3
- package/src/identify/index.ts +29 -24
- package/src/identify/pb/message.ts +3 -2
- package/src/index.ts +15 -8
- package/src/insecure/index.ts +2 -1
- package/src/insecure/pb/proto.ts +8 -9
- package/src/libp2p.ts +52 -46
- package/src/nat-manager.ts +11 -9
- package/src/peer-record-updater.ts +4 -4
- package/src/peer-routing.ts +9 -9
- package/src/ping/index.ts +6 -6
- package/src/pnet/crypto.ts +3 -3
- package/src/pnet/index.ts +3 -3
- package/src/pnet/key-generator.ts +1 -1
- package/src/pubsub/dummy-pubsub.ts +9 -9
- package/src/registrar.ts +12 -12
- package/src/transport-manager.ts +17 -18
- package/src/upgrader.ts +43 -42
- package/src/version.ts +1 -1
- package/dist/src/circuit/auto-relay.d.ts +0 -46
- package/dist/src/circuit/auto-relay.d.ts.map +0 -1
- package/dist/src/circuit/auto-relay.js +0 -220
- package/dist/src/circuit/auto-relay.js.map +0 -1
- package/dist/src/circuit/circuit/hop.d.ts +0 -42
- package/dist/src/circuit/circuit/hop.d.ts.map +0 -1
- package/dist/src/circuit/circuit/hop.js +0 -142
- package/dist/src/circuit/circuit/hop.js.map +0 -1
- package/dist/src/circuit/circuit/stop.d.ts +0 -24
- package/dist/src/circuit/circuit/stop.d.ts.map +0 -1
- package/dist/src/circuit/circuit/stop.js +0 -51
- package/dist/src/circuit/circuit/stop.js.map +0 -1
- package/dist/src/circuit/circuit/stream-handler.d.ts +0 -40
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +0 -1
- package/dist/src/circuit/circuit/stream-handler.js +0 -59
- package/dist/src/circuit/circuit/stream-handler.js.map +0 -1
- package/dist/src/circuit/circuit/utils.d.ts +0 -7
- package/dist/src/circuit/circuit/utils.d.ts.map +0 -1
- package/dist/src/circuit/circuit/utils.js +0 -43
- package/dist/src/circuit/circuit/utils.js.map +0 -1
- package/dist/src/circuit/listener.d.ts +0 -9
- package/dist/src/circuit/listener.d.ts.map +0 -1
- package/dist/src/circuit/listener.js +0 -62
- package/dist/src/circuit/listener.js.map +0 -1
- package/dist/src/circuit/multicodec.d.ts +0 -2
- package/dist/src/circuit/multicodec.d.ts.map +0 -1
- package/dist/src/circuit/multicodec.js +0 -2
- package/dist/src/circuit/multicodec.js.map +0 -1
- package/dist/src/circuit/transport.d.ts +0 -51
- package/dist/src/circuit/transport.d.ts.map +0 -1
- package/dist/src/circuit/transport.js +0 -223
- package/dist/src/circuit/transport.js.map +0 -1
- package/dist/src/keychain/cms.d.ts +0 -33
- package/dist/src/keychain/cms.d.ts.map +0 -1
- package/dist/src/keychain/cms.js +0 -129
- package/dist/src/keychain/cms.js.map +0 -1
- package/dist/src/keychain/index.d.ts +0 -151
- package/dist/src/keychain/index.d.ts.map +0 -1
- package/dist/src/keychain/index.js +0 -519
- package/dist/src/keychain/index.js.map +0 -1
- package/dist/src/keychain/util.d.ts +0 -21
- package/dist/src/keychain/util.d.ts.map +0 -1
- package/dist/src/keychain/util.js +0 -79
- package/dist/src/keychain/util.js.map +0 -1
- package/src/circuit/IMPLEMENTATION_NOTES.md +0 -128
- package/src/circuit/README.md +0 -111
- package/src/circuit/auto-relay.ts +0 -292
- package/src/circuit/circuit/hop.ts +0 -220
- package/src/circuit/circuit/stop.ts +0 -83
- package/src/circuit/circuit/stream-handler.ts +0 -87
- package/src/circuit/circuit/utils.ts +0 -44
- package/src/circuit/listener.ts +0 -83
- package/src/circuit/multicodec.ts +0 -2
- package/src/circuit/transport.ts +0 -278
- package/src/keychain/README.md +0 -55
- package/src/keychain/cms.ts +0 -150
- package/src/keychain/doc/private-key.png +0 -0
- package/src/keychain/doc/private-key.xml +0 -1
- package/src/keychain/index.ts +0 -629
- package/src/keychain/util.ts +0 -82
package/src/connection/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
2
|
-
import
|
|
2
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
3
3
|
import { OPEN, CLOSING, CLOSED } from '@libp2p/interface-connection/status'
|
|
4
4
|
import { symbol } from '@libp2p/interface-connection'
|
|
5
5
|
import type { Connection, ConnectionStat, Stream } from '@libp2p/interface-connection'
|
|
@@ -87,18 +87,18 @@ export class ConnectionImpl implements Connection {
|
|
|
87
87
|
this._closing = false
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
get [Symbol.toStringTag] () {
|
|
90
|
+
get [Symbol.toStringTag] (): 'Connection' {
|
|
91
91
|
return 'Connection'
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
get [symbol] () {
|
|
94
|
+
get [symbol] (): true {
|
|
95
95
|
return true
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* Get all the streams of the muxer
|
|
100
100
|
*/
|
|
101
|
-
get streams () {
|
|
101
|
+
get streams (): Stream[] {
|
|
102
102
|
return this._getStreams()
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -107,11 +107,11 @@ export class ConnectionImpl implements Connection {
|
|
|
107
107
|
*/
|
|
108
108
|
async newStream (protocols: string | string[], options?: AbortOptions): Promise<Stream> {
|
|
109
109
|
if (this.stat.status === CLOSING) {
|
|
110
|
-
throw
|
|
110
|
+
throw new CodeError('the connection is being closed', 'ERR_CONNECTION_BEING_CLOSED')
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
if (this.stat.status === CLOSED) {
|
|
114
|
-
throw
|
|
114
|
+
throw new CodeError('the connection is closed', 'ERR_CONNECTION_CLOSED')
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
if (!Array.isArray(protocols)) {
|
|
@@ -128,21 +128,21 @@ export class ConnectionImpl implements Connection {
|
|
|
128
128
|
/**
|
|
129
129
|
* Add a stream when it is opened to the registry
|
|
130
130
|
*/
|
|
131
|
-
addStream (stream: Stream) {
|
|
131
|
+
addStream (stream: Stream): void {
|
|
132
132
|
stream.stat.direction = 'inbound'
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Remove stream registry after it is closed
|
|
137
137
|
*/
|
|
138
|
-
removeStream (id: string) {
|
|
138
|
+
removeStream (id: string): void {
|
|
139
139
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
143
|
* Close the connection
|
|
144
144
|
*/
|
|
145
|
-
async close () {
|
|
145
|
+
async close (): Promise<void> {
|
|
146
146
|
if (this.stat.status === CLOSED || this._closing) {
|
|
147
147
|
return
|
|
148
148
|
}
|
|
@@ -151,7 +151,7 @@ export class ConnectionImpl implements Connection {
|
|
|
151
151
|
|
|
152
152
|
// close all streams - this can throw if we're not multiplexed
|
|
153
153
|
try {
|
|
154
|
-
this.streams.forEach(s => s.close())
|
|
154
|
+
this.streams.forEach(s => { s.close() })
|
|
155
155
|
} catch (err) {
|
|
156
156
|
log.error(err)
|
|
157
157
|
}
|
|
@@ -2,10 +2,6 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import mergeOptions from 'merge-options'
|
|
3
3
|
// @ts-expect-error retimer does not have types
|
|
4
4
|
import retimer from 'retimer'
|
|
5
|
-
import all from 'it-all'
|
|
6
|
-
import { pipe } from 'it-pipe'
|
|
7
|
-
import filter from 'it-filter'
|
|
8
|
-
import sort from 'it-sort'
|
|
9
5
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
10
6
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
7
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
@@ -14,11 +10,6 @@ import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
|
14
10
|
const log = logger('libp2p:connection-manager:auto-dialler')
|
|
15
11
|
|
|
16
12
|
export interface AutoDiallerInit {
|
|
17
|
-
/**
|
|
18
|
-
* Should preemptively guarantee connections are above the low watermark
|
|
19
|
-
*/
|
|
20
|
-
enabled?: boolean
|
|
21
|
-
|
|
22
13
|
/**
|
|
23
14
|
* The minimum number of connections to avoid pruning
|
|
24
15
|
*/
|
|
@@ -37,7 +28,6 @@ export interface AutoDiallerComponents {
|
|
|
37
28
|
}
|
|
38
29
|
|
|
39
30
|
const defaultOptions: Partial<AutoDiallerInit> = {
|
|
40
|
-
enabled: true,
|
|
41
31
|
minConnections: 0,
|
|
42
32
|
autoDialInterval: 10000
|
|
43
33
|
}
|
|
@@ -62,19 +52,14 @@ export class AutoDialler implements Startable {
|
|
|
62
52
|
log('options: %j', this.options)
|
|
63
53
|
}
|
|
64
54
|
|
|
65
|
-
isStarted () {
|
|
55
|
+
isStarted (): boolean {
|
|
66
56
|
return this.running
|
|
67
57
|
}
|
|
68
58
|
|
|
69
59
|
/**
|
|
70
60
|
* Starts the auto dialer
|
|
71
61
|
*/
|
|
72
|
-
async start () {
|
|
73
|
-
if (!this.options.enabled) {
|
|
74
|
-
log('not enabled')
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
62
|
+
async start (): Promise<void> {
|
|
78
63
|
this.running = true
|
|
79
64
|
|
|
80
65
|
void this._autoDial().catch(err => {
|
|
@@ -87,12 +72,7 @@ export class AutoDialler implements Startable {
|
|
|
87
72
|
/**
|
|
88
73
|
* Stops the auto dialler
|
|
89
74
|
*/
|
|
90
|
-
async stop () {
|
|
91
|
-
if (!this.options.enabled) {
|
|
92
|
-
log('not enabled')
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
|
|
75
|
+
async stop (): Promise<void> {
|
|
96
76
|
this.running = false
|
|
97
77
|
|
|
98
78
|
if (this.autoDialTimeout != null) {
|
|
@@ -102,7 +82,7 @@ export class AutoDialler implements Startable {
|
|
|
102
82
|
log('stopped')
|
|
103
83
|
}
|
|
104
84
|
|
|
105
|
-
async _autoDial () {
|
|
85
|
+
async _autoDial (): Promise<void> {
|
|
106
86
|
if (this.autoDialTimeout != null) {
|
|
107
87
|
this.autoDialTimeout.clear()
|
|
108
88
|
}
|
|
@@ -117,22 +97,38 @@ export class AutoDialler implements Startable {
|
|
|
117
97
|
}
|
|
118
98
|
|
|
119
99
|
// Sort peers on whether we know protocols or public keys for them
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
100
|
+
let peers = await this.components.peerStore.all()
|
|
101
|
+
|
|
102
|
+
peers = peers.filter((peer) => {
|
|
103
|
+
// do not dial ourselves
|
|
104
|
+
if (peer.id.equals(this.components.peerId)) {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// do not dial peers without multiaddrs
|
|
109
|
+
if (peer.addresses.length === 0) {
|
|
110
|
+
return false
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return true
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
// shuffle the peers
|
|
117
|
+
peers = peers.sort(() => Math.random() > 0.5 ? 1 : -1)
|
|
118
|
+
|
|
119
|
+
peers = peers.sort((a, b) => {
|
|
120
|
+
// dial peers with the most protocols first
|
|
121
|
+
if (b.protocols.length > a.protocols.length) {
|
|
122
|
+
return 1
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// dial peers with public keys first
|
|
126
|
+
if (b.id.publicKey != null && a.id.publicKey == null) {
|
|
127
|
+
return 1
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return -1
|
|
131
|
+
})
|
|
136
132
|
|
|
137
133
|
for (let i = 0; this.running && i < peers.length && this.components.connectionManager.getConnections().length < minConnections; i++) {
|
|
138
134
|
// Connection Manager was stopped during async dial
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
2
|
import { anySignal } from 'any-signal'
|
|
3
3
|
import FIFO from 'p-fifo'
|
|
4
4
|
import { setMaxListeners } from 'events'
|
|
@@ -50,7 +50,7 @@ export class DialRequest {
|
|
|
50
50
|
|
|
51
51
|
// If no tokens are available, throw
|
|
52
52
|
if (tokens.length < 1) {
|
|
53
|
-
throw
|
|
53
|
+
throw new CodeError('No dial tokens available', codes.ERR_NO_DIAL_TOKENS)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const tokenHolder = new FIFO<number>()
|
|
@@ -87,12 +87,12 @@ export class DialRequest {
|
|
|
87
87
|
// End attempt once another attempt succeeded
|
|
88
88
|
if (done) {
|
|
89
89
|
this.dialer.releaseToken(tokens.splice(tokens.indexOf(token), 1)[0])
|
|
90
|
-
throw
|
|
90
|
+
throw new CodeError('dialAction already succeeded', codes.ERR_ALREADY_SUCCEEDED)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
const controller = dialAbortControllers[i]
|
|
94
94
|
if (controller == null) {
|
|
95
|
-
throw
|
|
95
|
+
throw new CodeError('dialAction did not come with an AbortController', codes.ERR_INVALID_PARAMETERS)
|
|
96
96
|
}
|
|
97
97
|
let conn
|
|
98
98
|
try {
|
|
@@ -116,7 +116,7 @@ export class DialRequest {
|
|
|
116
116
|
// Notify Promise.any that attempt was not successful
|
|
117
117
|
// to prevent from returning undefined despite there
|
|
118
118
|
// were successful dial attempts
|
|
119
|
-
throw
|
|
119
|
+
throw new CodeError('dialAction led to empty object', codes.ERR_TRANSPORT_DIAL_FAILED)
|
|
120
120
|
} else {
|
|
121
121
|
// This dial succeeded, don't attempt anything else
|
|
122
122
|
done = true
|
|
@@ -124,6 +124,13 @@ export class DialRequest {
|
|
|
124
124
|
|
|
125
125
|
return conn
|
|
126
126
|
}))
|
|
127
|
+
} catch (err: any) {
|
|
128
|
+
// if we only dialed one address, unwrap the AggregateError
|
|
129
|
+
if (this.addrs.length === 1 && err.name === 'AggregateError') {
|
|
130
|
+
throw err.errors[0]
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
throw err
|
|
127
134
|
} finally {
|
|
128
135
|
// success/failure happened, abort everything else
|
|
129
136
|
dialAbortControllers.forEach(c => {
|
|
@@ -131,7 +138,7 @@ export class DialRequest {
|
|
|
131
138
|
c.abort()
|
|
132
139
|
}
|
|
133
140
|
})
|
|
134
|
-
tokens.forEach(token => this.dialer.releaseToken(token)) // release tokens back to the dialer
|
|
141
|
+
tokens.forEach(token => { this.dialer.releaseToken(token) }) // release tokens back to the dialer
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import
|
|
2
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
3
3
|
import { isMultiaddr, Multiaddr, Resolver, multiaddr, resolvers } from '@multiformats/multiaddr'
|
|
4
4
|
import { TimeoutController } from 'timeout-abort-controller'
|
|
5
5
|
import { anySignal } from 'any-signal'
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
MAX_PER_PEER_DIALS,
|
|
15
15
|
MAX_ADDRS_TO_DIAL
|
|
16
16
|
} from '../../constants.js'
|
|
17
|
-
import type { Connection
|
|
17
|
+
import type { Connection } from '@libp2p/interface-connection'
|
|
18
18
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
19
19
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
20
20
|
import { isPeerId, PeerId } from '@libp2p/interface-peer-id'
|
|
@@ -23,6 +23,7 @@ import type { AddressSorter, PeerStore } from '@libp2p/interface-peer-store'
|
|
|
23
23
|
import type { Metrics } from '@libp2p/interface-metrics'
|
|
24
24
|
import type { Dialer } from '@libp2p/interface-connection-manager'
|
|
25
25
|
import type { TransportManager } from '@libp2p/interface-transport'
|
|
26
|
+
import type { ConnectionGater } from '@libp2p/interface-connection-gater'
|
|
26
27
|
|
|
27
28
|
const log = logger('libp2p:dialer')
|
|
28
29
|
|
|
@@ -116,18 +117,18 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
isStarted () {
|
|
120
|
+
isStarted (): boolean {
|
|
120
121
|
return this.started
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
async start () {
|
|
124
|
+
async start (): Promise<void> {
|
|
124
125
|
this.started = true
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
129
|
* Clears any pending dials
|
|
129
130
|
*/
|
|
130
|
-
async stop () {
|
|
131
|
+
async stop (): Promise<void> {
|
|
131
132
|
this.started = false
|
|
132
133
|
|
|
133
134
|
for (const dial of this.pendingDials.values()) {
|
|
@@ -155,7 +156,7 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
155
156
|
|
|
156
157
|
if (peerId != null) {
|
|
157
158
|
if (this.components.peerId.equals(peerId)) {
|
|
158
|
-
throw
|
|
159
|
+
throw new CodeError('Tried to dial self', codes.ERR_DIALED_SELF)
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
if (multiaddr != null) {
|
|
@@ -163,8 +164,8 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
163
164
|
await this.components.peerStore.addressBook.add(peerId, [multiaddr])
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
if (await this.components.connectionGater.denyDialPeer(peerId)) {
|
|
167
|
-
throw
|
|
167
|
+
if ((await this.components.connectionGater.denyDialPeer?.(peerId)) === true) {
|
|
168
|
+
throw new CodeError('The dial request is blocked by gater.allowDialPeer', codes.ERR_PEER_DIAL_INTERCEPTED)
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
171
|
|
|
@@ -194,7 +195,7 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
if (dialTarget.addrs.length === 0) {
|
|
197
|
-
throw
|
|
198
|
+
throw new CodeError('The dial request has no valid addresses', codes.ERR_NO_VALID_ADDRESSES)
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
// try to join an in-flight dial for this peer if one is available
|
|
@@ -217,6 +218,24 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Get the current dial targets which are pending
|
|
223
|
+
*/
|
|
224
|
+
getPendingDialTargets (): Map<string, AbortController> {
|
|
225
|
+
return this.pendingDialTargets
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Returns true if the peer id is in the pending dials
|
|
230
|
+
*/
|
|
231
|
+
hasPendingDial (peerId: PeerId | Multiaddr): boolean {
|
|
232
|
+
if (isMultiaddr(peerId)) {
|
|
233
|
+
return this.pendingDials.has(peerId.getPeerId() ?? '')
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return this.pendingDials.has(peerId.toString())
|
|
237
|
+
}
|
|
238
|
+
|
|
220
239
|
/**
|
|
221
240
|
* Creates a DialTarget. The DialTarget is used to create and track
|
|
222
241
|
* the DialRequest to a given peer.
|
|
@@ -248,7 +267,7 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
248
267
|
addrs = [...new Set(addrs.map(ma => ma.toString()))].map(ma => multiaddr(ma))
|
|
249
268
|
|
|
250
269
|
if (addrs.length > this.maxAddrsToDial) {
|
|
251
|
-
throw
|
|
270
|
+
throw new CodeError('dial with more addresses than allowed', codes.ERR_TOO_MANY_ADDRESSES)
|
|
252
271
|
}
|
|
253
272
|
|
|
254
273
|
const peerId = isPeerId(peerIdOrMultiaddr.peerId) ? peerIdOrMultiaddr.peerId : undefined
|
|
@@ -280,9 +299,9 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
280
299
|
|
|
281
300
|
return (await Promise.all(
|
|
282
301
|
addresses.map(async address => {
|
|
283
|
-
const deny = await this.components.connectionGater.denyDialMultiaddr(peer, address.multiaddr)
|
|
302
|
+
const deny = await this.components.connectionGater.denyDialMultiaddr?.(peer, address.multiaddr)
|
|
284
303
|
|
|
285
|
-
if (deny) {
|
|
304
|
+
if (deny === true) {
|
|
286
305
|
return false
|
|
287
306
|
}
|
|
288
307
|
|
|
@@ -305,7 +324,7 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
305
324
|
*/
|
|
306
325
|
const dialAction: DialAction = async (addr, options = {}) => {
|
|
307
326
|
if (options.signal?.aborted === true) {
|
|
308
|
-
throw
|
|
327
|
+
throw new CodeError('already aborted', codes.ERR_ALREADY_ABORTED)
|
|
309
328
|
}
|
|
310
329
|
|
|
311
330
|
return await this.components.transportManager.dial(addr, options).catch(err => {
|
|
@@ -348,14 +367,14 @@ export class DefaultDialer implements Startable, Dialer {
|
|
|
348
367
|
return pendingDial
|
|
349
368
|
}
|
|
350
369
|
|
|
351
|
-
getTokens (num: number) {
|
|
370
|
+
getTokens (num: number): number[] {
|
|
352
371
|
const total = Math.min(num, this.maxDialsPerPeer, this.tokens.length)
|
|
353
372
|
const tokens = this.tokens.splice(0, total)
|
|
354
373
|
log('%d tokens request, returning %d, %d remaining', num, total, this.tokens.length)
|
|
355
374
|
return tokens
|
|
356
375
|
}
|
|
357
376
|
|
|
358
|
-
releaseToken (token: number) {
|
|
377
|
+
releaseToken (token: number): void {
|
|
359
378
|
// Guard against duplicate releases
|
|
360
379
|
if (this.tokens.includes(token)) {
|
|
361
380
|
return
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import
|
|
2
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
3
3
|
import mergeOptions from 'merge-options'
|
|
4
4
|
import { LatencyMonitor, SummaryObject } from './latency-monitor.js'
|
|
5
5
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
@@ -44,11 +44,6 @@ export interface ConnectionManagerConfig {
|
|
|
44
44
|
*/
|
|
45
45
|
pollInterval?: number
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
* If true, try to connect to all discovered peers up to the connection manager limit
|
|
49
|
-
*/
|
|
50
|
-
autoDial?: boolean
|
|
51
|
-
|
|
52
47
|
/**
|
|
53
48
|
* How long to wait between attempting to keep our number of concurrent connections
|
|
54
49
|
* above minConnections
|
|
@@ -168,7 +163,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
168
163
|
this.opts = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, init)
|
|
169
164
|
|
|
170
165
|
if (this.opts.maxConnections < this.opts.minConnections) {
|
|
171
|
-
throw
|
|
166
|
+
throw new CodeError('Connection Manager maxConnections must be greater than minConnections', codes.ERR_INVALID_PARAMETERS)
|
|
172
167
|
}
|
|
173
168
|
|
|
174
169
|
log('options: %o', this.opts)
|
|
@@ -211,7 +206,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
211
206
|
this.incomingPendingConnections = 0
|
|
212
207
|
}
|
|
213
208
|
|
|
214
|
-
isStarted () {
|
|
209
|
+
isStarted (): boolean {
|
|
215
210
|
return this.started
|
|
216
211
|
}
|
|
217
212
|
|
|
@@ -219,7 +214,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
219
214
|
* Starts the Connection Manager. If Metrics are not enabled on libp2p
|
|
220
215
|
* only event loop and connection limits will be monitored.
|
|
221
216
|
*/
|
|
222
|
-
async start () {
|
|
217
|
+
async start (): Promise<void> {
|
|
223
218
|
// track inbound/outbound connections
|
|
224
219
|
this.components.metrics?.registerMetricGroup('libp2p_connection_manager_connections', {
|
|
225
220
|
calculate: () => {
|
|
@@ -307,7 +302,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
307
302
|
log('started')
|
|
308
303
|
}
|
|
309
304
|
|
|
310
|
-
async afterStart () {
|
|
305
|
+
async afterStart (): Promise<void> {
|
|
311
306
|
this.components.upgrader.addEventListener('connection', this.onConnect)
|
|
312
307
|
this.components.upgrader.addEventListener('connectionEnd', this.onDisconnect)
|
|
313
308
|
|
|
@@ -352,7 +347,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
352
347
|
})
|
|
353
348
|
}
|
|
354
349
|
|
|
355
|
-
async beforeStop () {
|
|
350
|
+
async beforeStop (): Promise<void> {
|
|
356
351
|
// if we are still dialing KEEP_ALIVE peers, abort those dials
|
|
357
352
|
this.connectOnStartupController?.abort()
|
|
358
353
|
this.components.upgrader.removeEventListener('connection', this.onConnect)
|
|
@@ -362,7 +357,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
362
357
|
/**
|
|
363
358
|
* Stops the Connection Manager
|
|
364
359
|
*/
|
|
365
|
-
async stop () {
|
|
360
|
+
async stop (): Promise<void> {
|
|
366
361
|
this.latencyMonitor?.removeEventListener('data', this._onLatencyMeasure)
|
|
367
362
|
this.latencyMonitor?.stop()
|
|
368
363
|
|
|
@@ -374,7 +369,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
374
369
|
/**
|
|
375
370
|
* Cleans up the connections
|
|
376
371
|
*/
|
|
377
|
-
async _close () {
|
|
372
|
+
async _close (): Promise<void> {
|
|
378
373
|
// Close all connections we're tracking
|
|
379
374
|
const tasks: Array<Promise<void>> = []
|
|
380
375
|
for (const connectionList of this.connections.values()) {
|
|
@@ -394,7 +389,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
394
389
|
this.connections.clear()
|
|
395
390
|
}
|
|
396
391
|
|
|
397
|
-
onConnect (evt: CustomEvent<Connection>) {
|
|
392
|
+
onConnect (evt: CustomEvent<Connection>): void {
|
|
398
393
|
void this._onConnect(evt).catch(err => {
|
|
399
394
|
log.error(err)
|
|
400
395
|
})
|
|
@@ -403,7 +398,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
403
398
|
/**
|
|
404
399
|
* Tracks the incoming connection and check the connection limit
|
|
405
400
|
*/
|
|
406
|
-
async _onConnect (evt: CustomEvent<Connection>) {
|
|
401
|
+
async _onConnect (evt: CustomEvent<Connection>): Promise<void> {
|
|
407
402
|
const { detail: connection } = evt
|
|
408
403
|
|
|
409
404
|
if (!this.started) {
|
|
@@ -436,7 +431,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
436
431
|
/**
|
|
437
432
|
* Removes the connection from tracking
|
|
438
433
|
*/
|
|
439
|
-
onDisconnect (evt: CustomEvent<Connection>) {
|
|
434
|
+
onDisconnect (evt: CustomEvent<Connection>): void {
|
|
440
435
|
const { detail: connection } = evt
|
|
441
436
|
|
|
442
437
|
if (!this.started) {
|
|
@@ -470,11 +465,15 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
470
465
|
return conns
|
|
471
466
|
}
|
|
472
467
|
|
|
468
|
+
getConnectionsMap (): Map<string, Connection[]> {
|
|
469
|
+
return this.connections
|
|
470
|
+
}
|
|
471
|
+
|
|
473
472
|
async openConnection (peerIdOrMultiaddr: PeerId | Multiaddr, options: AbortOptions = {}): Promise<Connection> {
|
|
474
473
|
const { peerId, multiaddr } = getPeerAddress(peerIdOrMultiaddr)
|
|
475
474
|
|
|
476
475
|
if (peerId == null && multiaddr == null) {
|
|
477
|
-
throw
|
|
476
|
+
throw new CodeError('Can only open connections to PeerIds or Multiaddrs', codes.ERR_INVALID_PARAMETERS)
|
|
478
477
|
}
|
|
479
478
|
|
|
480
479
|
if (peerId != null) {
|
|
@@ -538,7 +537,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
538
537
|
|
|
539
538
|
await Promise.all(
|
|
540
539
|
connections.map(async connection => {
|
|
541
|
-
|
|
540
|
+
await connection.close()
|
|
542
541
|
})
|
|
543
542
|
)
|
|
544
543
|
}
|
|
@@ -548,7 +547,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
548
547
|
*/
|
|
549
548
|
getAll (peerId: PeerId): Connection[] {
|
|
550
549
|
if (!isPeerId(peerId)) {
|
|
551
|
-
throw
|
|
550
|
+
throw new CodeError('peerId must be an instance of peer-id', codes.ERR_INVALID_PARAMETERS)
|
|
552
551
|
}
|
|
553
552
|
|
|
554
553
|
const id = peerId.toString()
|
|
@@ -565,7 +564,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
565
564
|
/**
|
|
566
565
|
* If the event loop is slow, maybe close a connection
|
|
567
566
|
*/
|
|
568
|
-
_onLatencyMeasure (evt: CustomEvent<SummaryObject>) {
|
|
567
|
+
_onLatencyMeasure (evt: CustomEvent<SummaryObject>): void {
|
|
569
568
|
const { detail: summary } = evt
|
|
570
569
|
|
|
571
570
|
this._checkMaxLimit('maxEventLoopDelay', summary.avgMs, 1)
|
|
@@ -577,7 +576,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
577
576
|
/**
|
|
578
577
|
* If the `value` of `name` has exceeded its limit, maybe close a connection
|
|
579
578
|
*/
|
|
580
|
-
async _checkMaxLimit (name: keyof ConnectionManagerInit, value: number, toPrune: number = 1) {
|
|
579
|
+
async _checkMaxLimit (name: keyof ConnectionManagerInit, value: number, toPrune: number = 1): Promise<void> {
|
|
581
580
|
const limit = this.opts[name]
|
|
582
581
|
|
|
583
582
|
if (limit == null) {
|
|
@@ -596,7 +595,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
596
595
|
* If we have more connections than our maximum, select some excess connections
|
|
597
596
|
* to prune based on peer value
|
|
598
597
|
*/
|
|
599
|
-
async _pruneConnections (toPrune: number) {
|
|
598
|
+
async _pruneConnections (toPrune: number): Promise<void> {
|
|
600
599
|
const connections = this.getConnections()
|
|
601
600
|
const peerValues = new PeerMap<number>()
|
|
602
601
|
|
|
@@ -722,7 +721,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
722
721
|
return false
|
|
723
722
|
}
|
|
724
723
|
|
|
725
|
-
afterUpgradeInbound () {
|
|
724
|
+
afterUpgradeInbound (): void {
|
|
726
725
|
this.incomingPendingConnections--
|
|
727
726
|
}
|
|
728
727
|
}
|
|
@@ -148,7 +148,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
148
148
|
this.latencyData = this.initLatencyData()
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
start () {
|
|
151
|
+
start (): void {
|
|
152
152
|
// We check for isBrowser because of browsers set max rates of timeouts when a page is hidden,
|
|
153
153
|
// so we fall back to another library
|
|
154
154
|
// See: http://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs
|
|
@@ -172,7 +172,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
stop () {
|
|
175
|
+
stop (): void {
|
|
176
176
|
this._stopTimers()
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -181,7 +181,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
181
181
|
*
|
|
182
182
|
* @private
|
|
183
183
|
*/
|
|
184
|
-
_startTimers () {
|
|
184
|
+
_startTimers (): void {
|
|
185
185
|
// Timer already started, ignore this
|
|
186
186
|
if (this.checkLatencyID != null) {
|
|
187
187
|
return
|
|
@@ -190,7 +190,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
190
190
|
this.checkLatency()
|
|
191
191
|
|
|
192
192
|
if (this.dataEmitIntervalMs != null) {
|
|
193
|
-
this.emitIntervalID = setInterval(() => this._emitSummary(), this.dataEmitIntervalMs)
|
|
193
|
+
this.emitIntervalID = setInterval(() => { this._emitSummary() }, this.dataEmitIntervalMs)
|
|
194
194
|
if (typeof this.emitIntervalID.unref === 'function') {
|
|
195
195
|
this.emitIntervalID.unref() // Doesn't block exit
|
|
196
196
|
}
|
|
@@ -202,7 +202,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
202
202
|
*
|
|
203
203
|
* @private
|
|
204
204
|
*/
|
|
205
|
-
_stopTimers () {
|
|
205
|
+
_stopTimers (): void {
|
|
206
206
|
if (this.checkLatencyID != null) {
|
|
207
207
|
clearTimeout(this.checkLatencyID)
|
|
208
208
|
this.checkLatencyID = undefined
|
|
@@ -218,7 +218,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
218
218
|
*
|
|
219
219
|
* @private
|
|
220
220
|
*/
|
|
221
|
-
_emitSummary () {
|
|
221
|
+
_emitSummary (): void {
|
|
222
222
|
const summary = this.getSummary()
|
|
223
223
|
if (summary.events > 0) {
|
|
224
224
|
this.dispatchEvent(new CustomEvent<SummaryObject>('data', {
|
|
@@ -254,7 +254,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
254
254
|
* Randomly calls an async fn every roughly latencyCheckIntervalMs (plus some randomness). If no async fn is found,
|
|
255
255
|
* it will simply report on event loop latency.
|
|
256
256
|
*/
|
|
257
|
-
checkLatency () {
|
|
257
|
+
checkLatency (): void {
|
|
258
258
|
// Randomness is needed to avoid alignment by accident to regular things in the event loop
|
|
259
259
|
const randomness = (Math.random() * this.latencyCheckMultiply) - this.latencyCheckSubtract
|
|
260
260
|
|
|
@@ -264,7 +264,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
264
264
|
startTime: this.now()
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
const cb = () => {
|
|
267
|
+
const cb = (): void => {
|
|
268
268
|
// We are already stopped, ignore this datapoint
|
|
269
269
|
if (this.checkLatencyID == null) {
|
|
270
270
|
return
|
|
@@ -314,6 +314,6 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
function isBrowser () {
|
|
317
|
+
function isBrowser (): boolean {
|
|
318
318
|
return typeof globalThis.window !== 'undefined'
|
|
319
319
|
}
|