libp2p 0.43.4 → 0.44.0-0d46c78f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +29 -29
- package/dist/src/address-manager/index.d.ts +4 -4
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +9 -6
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/autonat/index.d.ts +1 -2
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +19 -19
- package/dist/src/autonat/index.js.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.js +2 -2
- package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +7 -3
- package/dist/src/circuit-relay/server/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.js +3 -1
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/circuit-relay/transport/index.d.ts +3 -0
- package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/index.js +6 -2
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/listener.d.ts +3 -0
- package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/listener.js +5 -4
- package/dist/src/circuit-relay/transport/listener.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +4 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +11 -6
- package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
- package/dist/src/circuit-relay/utils.d.ts.map +1 -1
- package/dist/src/circuit-relay/utils.js +3 -1
- package/dist/src/circuit-relay/utils.js.map +1 -1
- package/dist/src/components.d.ts +7 -69
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +60 -174
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +8 -0
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -0
- package/dist/src/config/connection-gater.browser.js +27 -0
- package/dist/src/config/connection-gater.browser.js.map +1 -0
- package/dist/src/config/connection-gater.d.ts +6 -0
- package/dist/src/config/connection-gater.d.ts.map +1 -0
- package/dist/src/config/connection-gater.js +18 -0
- package/dist/src/config/connection-gater.js.map +1 -0
- package/dist/src/config.d.ts +2 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -71
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +39 -0
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -0
- package/dist/src/connection-manager/auto-dial.js +136 -0
- package/dist/src/connection-manager/auto-dial.js.map +1 -0
- package/dist/src/connection-manager/connection-pruner.d.ts +32 -0
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -0
- package/dist/src/connection-manager/connection-pruner.js +111 -0
- package/dist/src/connection-manager/connection-pruner.js.map +1 -0
- package/dist/src/connection-manager/constants.d.ts +49 -0
- package/dist/src/connection-manager/constants.d.ts.map +1 -0
- package/dist/src/connection-manager/constants.js +49 -0
- package/dist/src/connection-manager/constants.js.map +1 -0
- package/dist/src/connection-manager/dial-queue.d.ts +78 -0
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -0
- package/dist/src/connection-manager/dial-queue.js +372 -0
- package/dist/src/connection-manager/dial-queue.js.map +1 -0
- package/dist/src/connection-manager/index.d.ts +70 -73
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +118 -247
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/utils.d.ts +9 -0
- package/dist/src/connection-manager/utils.d.ts.map +1 -0
- package/dist/src/connection-manager/utils.js +66 -0
- package/dist/src/connection-manager/utils.js.map +1 -0
- package/dist/src/content-routing/index.d.ts +0 -10
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +7 -42
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +3 -1
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/fetch/index.d.ts +13 -35
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +10 -12
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/index.d.ts +16 -48
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +203 -201
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +11 -67
- 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 +3 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +12 -35
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +141 -206
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -38
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +0 -59
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/constants.d.ts +4 -0
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +10 -0
- package/dist/src/ping/constants.js.map +1 -1
- package/dist/src/ping/index.d.ts +10 -27
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +18 -21
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/registrar.d.ts +5 -2
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +27 -25
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +15 -4
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +37 -12
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +16 -11
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +38 -47
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +42 -0
- package/dist/src/upnp-nat/index.d.ts.map +1 -0
- package/dist/src/{nat-manager.js → upnp-nat/index.js} +11 -7
- package/dist/src/upnp-nat/index.js.map +1 -0
- package/package.json +70 -54
- package/src/address-manager/index.ts +12 -8
- package/src/autonat/index.ts +20 -22
- package/src/circuit-relay/server/advert-service.ts +2 -2
- package/src/circuit-relay/server/index.ts +7 -3
- package/src/circuit-relay/transport/discovery.ts +3 -1
- package/src/circuit-relay/transport/index.ts +10 -2
- package/src/circuit-relay/transport/listener.ts +8 -4
- package/src/circuit-relay/transport/reservation-store.ts +15 -7
- package/src/circuit-relay/utils.ts +3 -1
- package/src/components.ts +72 -251
- package/src/config/connection-gater.browser.ts +31 -0
- package/src/config/connection-gater.ts +19 -0
- package/src/config.ts +3 -73
- package/src/connection-manager/auto-dial.ts +189 -0
- package/src/connection-manager/connection-pruner.ts +157 -0
- package/src/connection-manager/constants.ts +60 -0
- package/src/connection-manager/dial-queue.ts +506 -0
- package/src/connection-manager/index.ts +194 -339
- package/src/connection-manager/utils.ts +76 -0
- package/src/content-routing/index.ts +7 -55
- package/src/content-routing/utils.ts +3 -1
- package/src/fetch/index.ts +55 -18
- package/src/identify/index.ts +238 -228
- package/src/index.ts +12 -76
- package/src/insecure/index.ts +9 -5
- package/src/libp2p.ts +146 -265
- package/src/peer-routing.ts +1 -101
- package/src/ping/constants.ts +11 -0
- package/src/ping/index.ts +32 -28
- package/src/registrar.ts +31 -27
- package/src/transport-manager.ts +49 -15
- package/src/upgrader.ts +62 -57
- package/src/{nat-manager.ts → upnp-nat/index.ts} +15 -16
- package/src/version.ts +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +0 -42
- package/dist/src/connection-manager/auto-dialler.d.ts.map +0 -1
- package/dist/src/connection-manager/auto-dialler.js +0 -105
- package/dist/src/connection-manager/auto-dialler.js.map +0 -1
- package/dist/src/connection-manager/dialer/dial-request.d.ts +0 -27
- package/dist/src/connection-manager/dialer/dial-request.d.ts.map +0 -1
- package/dist/src/connection-manager/dialer/dial-request.js +0 -114
- package/dist/src/connection-manager/dialer/dial-request.js.map +0 -1
- package/dist/src/connection-manager/dialer/index.d.ts +0 -121
- package/dist/src/connection-manager/dialer/index.d.ts.map +0 -1
- package/dist/src/connection-manager/dialer/index.js +0 -324
- package/dist/src/connection-manager/dialer/index.js.map +0 -1
- package/dist/src/connection-manager/latency-monitor.d.ts +0 -120
- package/dist/src/connection-manager/latency-monitor.d.ts.map +0 -1
- package/dist/src/connection-manager/latency-monitor.js +0 -220
- package/dist/src/connection-manager/latency-monitor.js.map +0 -1
- package/dist/src/connection-manager/visibility-change-emitter.d.ts +0 -66
- package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +0 -1
- package/dist/src/connection-manager/visibility-change-emitter.js +0 -118
- package/dist/src/connection-manager/visibility-change-emitter.js.map +0 -1
- package/dist/src/constants.d.ts +0 -27
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js +0 -31
- package/dist/src/constants.js.map +0 -1
- package/dist/src/dht/dht-content-routing.d.ts +0 -17
- package/dist/src/dht/dht-content-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-content-routing.js +0 -32
- package/dist/src/dht/dht-content-routing.js.map +0 -1
- package/dist/src/dht/dht-peer-routing.d.ts +0 -15
- package/dist/src/dht/dht-peer-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-peer-routing.js +0 -26
- package/dist/src/dht/dht-peer-routing.js.map +0 -1
- package/dist/src/dht/dummy-dht.d.ts +0 -20
- package/dist/src/dht/dummy-dht.d.ts.map +0 -1
- package/dist/src/dht/dummy-dht.js +0 -46
- package/dist/src/dht/dummy-dht.js.map +0 -1
- package/dist/src/nat-manager.d.ts +0 -74
- package/dist/src/nat-manager.d.ts.map +0 -1
- package/dist/src/nat-manager.js.map +0 -1
- package/dist/src/peer-record-updater.d.ts +0 -24
- package/dist/src/peer-record-updater.d.ts.map +0 -1
- package/dist/src/peer-record-updater.js +0 -44
- package/dist/src/peer-record-updater.js.map +0 -1
- package/dist/typedoc-urls.json +0 -41
- package/src/connection-manager/auto-dialler.ts +0 -158
- package/src/connection-manager/dialer/dial-request.ts +0 -144
- package/src/connection-manager/dialer/index.ts +0 -461
- package/src/connection-manager/latency-monitor.ts +0 -319
- package/src/connection-manager/visibility-change-emitter.ts +0 -135
- package/src/constants.ts +0 -36
- package/src/dht/dht-content-routing.ts +0 -44
- package/src/dht/dht-peer-routing.ts +0 -36
- package/src/dht/dummy-dht.ts +0 -60
- package/src/peer-record-updater.ts +0 -65
package/src/upgrader.ts
CHANGED
|
@@ -3,32 +3,34 @@ import { CodeError } from '@libp2p/interfaces/errors'
|
|
|
3
3
|
import * as mss from '@libp2p/multistream-select'
|
|
4
4
|
import { codes } from './errors.js'
|
|
5
5
|
import { createConnection } from './connection/index.js'
|
|
6
|
-
import {
|
|
6
|
+
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
7
7
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
8
8
|
import type { MultiaddrConnection, Connection, Stream, ConnectionProtector } from '@libp2p/interface-connection'
|
|
9
9
|
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
|
|
10
10
|
import type { StreamMuxer, StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
|
|
11
11
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
12
|
-
import type { Upgrader,
|
|
13
|
-
import type { Duplex } from 'it-stream-types'
|
|
12
|
+
import type { Upgrader, UpgraderOptions } from '@libp2p/interface-transport'
|
|
13
|
+
import type { Duplex, Source } from 'it-stream-types'
|
|
14
14
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
15
15
|
import type { Registrar } from '@libp2p/interface-registrar'
|
|
16
16
|
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'
|
|
17
|
-
import { TimeoutController } from 'timeout-abort-controller'
|
|
18
17
|
import { abortableDuplex } from 'abortable-iterator'
|
|
19
18
|
import { setMaxListeners } from 'events'
|
|
20
19
|
import type { Metrics } from '@libp2p/interface-metrics'
|
|
21
20
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
22
21
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
23
22
|
import type { ConnectionGater } from '@libp2p/interface-connection-gater'
|
|
23
|
+
import { INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
|
|
24
|
+
import { anySignal } from 'any-signal'
|
|
25
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
|
|
24
26
|
|
|
25
27
|
const log = logger('libp2p:upgrader')
|
|
26
28
|
|
|
27
|
-
interface
|
|
29
|
+
interface CreateConnectionOptions {
|
|
28
30
|
cryptoProtocol: string
|
|
29
31
|
direction: 'inbound' | 'outbound'
|
|
30
32
|
maConn: MultiaddrConnection
|
|
31
|
-
upgradedConn: Duplex<Uint8Array
|
|
33
|
+
upgradedConn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>
|
|
32
34
|
remotePeer: PeerId
|
|
33
35
|
muxerFactory?: StreamMuxerFactory
|
|
34
36
|
}
|
|
@@ -51,7 +53,7 @@ export interface UpgraderInit {
|
|
|
51
53
|
* An amount of ms by which an inbound connection upgrade
|
|
52
54
|
* must complete
|
|
53
55
|
*/
|
|
54
|
-
inboundUpgradeTimeout
|
|
56
|
+
inboundUpgradeTimeout?: number
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
function findIncomingStreamLimit (protocol: string, registrar: Registrar): number | undefined {
|
|
@@ -102,17 +104,21 @@ export interface DefaultUpgraderComponents {
|
|
|
102
104
|
connectionProtector?: ConnectionProtector
|
|
103
105
|
registrar: Registrar
|
|
104
106
|
peerStore: PeerStore
|
|
107
|
+
events: EventEmitter<Libp2pEvents>
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
type EncryptedConn = Duplex<AsyncGenerator<Uint8Array, any, unknown>, Source<Uint8Array>, Promise<void>>
|
|
111
|
+
|
|
112
|
+
type ConnectionDeniedType = keyof Pick<ConnectionGater, 'denyOutboundConnection' | 'denyInboundEncryptedConnection' | 'denyOutboundEncryptedConnection' | 'denyInboundUpgradedConnection' | 'denyOutboundUpgradedConnection'>
|
|
113
|
+
|
|
114
|
+
export class DefaultUpgrader implements Upgrader {
|
|
108
115
|
private readonly components: DefaultUpgraderComponents
|
|
109
116
|
private readonly connectionEncryption: Map<string, ConnectionEncrypter>
|
|
110
117
|
private readonly muxers: Map<string, StreamMuxerFactory>
|
|
111
118
|
private readonly inboundUpgradeTimeout: number
|
|
119
|
+
private readonly events: EventEmitter<Libp2pEvents>
|
|
112
120
|
|
|
113
121
|
constructor (components: DefaultUpgraderComponents, init: UpgraderInit) {
|
|
114
|
-
super()
|
|
115
|
-
|
|
116
122
|
this.components = components
|
|
117
123
|
this.connectionEncryption = new Map()
|
|
118
124
|
|
|
@@ -126,7 +132,18 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
126
132
|
this.muxers.set(muxer.protocol, muxer)
|
|
127
133
|
})
|
|
128
134
|
|
|
129
|
-
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout
|
|
135
|
+
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? INBOUND_UPGRADE_TIMEOUT
|
|
136
|
+
this.events = components.events
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async shouldBlockConnection (remotePeer: PeerId, maConn: MultiaddrConnection, connectionType: ConnectionDeniedType): Promise<void> {
|
|
140
|
+
const connectionGater = this.components.connectionGater[connectionType]
|
|
141
|
+
|
|
142
|
+
if (connectionGater !== undefined) {
|
|
143
|
+
if (await connectionGater(remotePeer, maConn)) {
|
|
144
|
+
throw new CodeError(`The multiaddr connection is blocked by gater.${connectionType}`, codes.ERR_CONNECTION_INTERCEPTED)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
130
147
|
}
|
|
131
148
|
|
|
132
149
|
/**
|
|
@@ -139,21 +156,21 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
139
156
|
throw new CodeError('connection denied', codes.ERR_CONNECTION_DENIED)
|
|
140
157
|
}
|
|
141
158
|
|
|
142
|
-
let encryptedConn
|
|
159
|
+
let encryptedConn: EncryptedConn
|
|
143
160
|
let remotePeer
|
|
144
|
-
let upgradedConn: Duplex<Uint8Array
|
|
161
|
+
let upgradedConn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>
|
|
145
162
|
let muxerFactory: StreamMuxerFactory | undefined
|
|
146
163
|
let cryptoProtocol
|
|
147
164
|
|
|
148
|
-
const
|
|
165
|
+
const signal = anySignal([AbortSignal.timeout(this.inboundUpgradeTimeout)])
|
|
149
166
|
|
|
150
167
|
try {
|
|
151
168
|
// fails on node < 15.4
|
|
152
|
-
setMaxListeners?.(Infinity,
|
|
169
|
+
setMaxListeners?.(Infinity, signal)
|
|
153
170
|
} catch { }
|
|
154
171
|
|
|
155
172
|
try {
|
|
156
|
-
const abortableStream = abortableDuplex(maConn,
|
|
173
|
+
const abortableStream = abortableDuplex(maConn, signal)
|
|
157
174
|
maConn.source = abortableStream.source
|
|
158
175
|
maConn.sink = abortableStream.sink
|
|
159
176
|
|
|
@@ -187,12 +204,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
187
204
|
protocol: cryptoProtocol
|
|
188
205
|
} = await this._encryptInbound(protectedConn))
|
|
189
206
|
|
|
190
|
-
|
|
207
|
+
const maConn: MultiaddrConnection = {
|
|
191
208
|
...protectedConn,
|
|
192
209
|
...encryptedConn
|
|
193
|
-
})) === true) {
|
|
194
|
-
throw new CodeError('The multiaddr connection is blocked by gater.acceptEncryptedConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
195
210
|
}
|
|
211
|
+
|
|
212
|
+
await this.shouldBlockConnection(remotePeer, maConn, 'denyInboundEncryptedConnection')
|
|
196
213
|
} else {
|
|
197
214
|
const idStr = maConn.remoteAddr.getPeerId()
|
|
198
215
|
|
|
@@ -223,12 +240,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
223
240
|
throw err
|
|
224
241
|
}
|
|
225
242
|
|
|
226
|
-
|
|
227
|
-
...protectedConn,
|
|
228
|
-
...encryptedConn
|
|
229
|
-
})) === true) {
|
|
230
|
-
throw new CodeError('The multiaddr connection is blocked by gater.acceptEncryptedConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
231
|
-
}
|
|
243
|
+
await this.shouldBlockConnection(remotePeer, maConn, 'denyInboundUpgradedConnection')
|
|
232
244
|
|
|
233
245
|
log('Successfully upgraded inbound connection')
|
|
234
246
|
|
|
@@ -242,7 +254,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
242
254
|
})
|
|
243
255
|
} finally {
|
|
244
256
|
this.components.connectionManager.afterUpgradeInbound()
|
|
245
|
-
|
|
257
|
+
signal.clear()
|
|
246
258
|
}
|
|
247
259
|
}
|
|
248
260
|
|
|
@@ -256,14 +268,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
256
268
|
if (idStr != null) {
|
|
257
269
|
remotePeerId = peerIdFromString(idStr)
|
|
258
270
|
|
|
259
|
-
|
|
260
|
-
throw new CodeError('The multiaddr connection is blocked by connectionGater.denyOutboundConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
261
|
-
}
|
|
271
|
+
await this.shouldBlockConnection(remotePeerId, maConn, 'denyOutboundConnection')
|
|
262
272
|
}
|
|
263
273
|
|
|
264
274
|
let encryptedConn
|
|
265
275
|
let remotePeer: PeerId
|
|
266
|
-
let upgradedConn
|
|
276
|
+
let upgradedConn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>
|
|
267
277
|
let cryptoProtocol
|
|
268
278
|
let muxerFactory
|
|
269
279
|
|
|
@@ -294,12 +304,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
294
304
|
protocol: cryptoProtocol
|
|
295
305
|
} = await this._encryptOutbound(protectedConn, remotePeerId))
|
|
296
306
|
|
|
297
|
-
|
|
307
|
+
const maConn: MultiaddrConnection = {
|
|
298
308
|
...protectedConn,
|
|
299
309
|
...encryptedConn
|
|
300
|
-
})) === true) {
|
|
301
|
-
throw new CodeError('The multiaddr connection is blocked by gater.acceptEncryptedConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
302
310
|
}
|
|
311
|
+
|
|
312
|
+
await this.shouldBlockConnection(remotePeer, maConn, 'denyOutboundEncryptedConnection')
|
|
303
313
|
} else {
|
|
304
314
|
if (remotePeerId == null) {
|
|
305
315
|
throw new CodeError('Encryption was skipped but no peer id was passed', codes.ERR_INVALID_PEER)
|
|
@@ -327,12 +337,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
327
337
|
throw err
|
|
328
338
|
}
|
|
329
339
|
|
|
330
|
-
|
|
331
|
-
...protectedConn,
|
|
332
|
-
...encryptedConn
|
|
333
|
-
})) === true) {
|
|
334
|
-
throw new CodeError('The multiaddr connection is blocked by gater.acceptEncryptedConnection', codes.ERR_CONNECTION_INTERCEPTED)
|
|
335
|
-
}
|
|
340
|
+
await this.shouldBlockConnection(remotePeer, maConn, 'denyOutboundUpgradedConnection')
|
|
336
341
|
|
|
337
342
|
log('Successfully upgraded outbound connection')
|
|
338
343
|
|
|
@@ -349,7 +354,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
349
354
|
/**
|
|
350
355
|
* A convenience method for generating a new `Connection`
|
|
351
356
|
*/
|
|
352
|
-
_createConnection (opts:
|
|
357
|
+
_createConnection (opts: CreateConnectionOptions): Connection {
|
|
353
358
|
const {
|
|
354
359
|
cryptoProtocol,
|
|
355
360
|
direction,
|
|
@@ -400,7 +405,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
400
405
|
|
|
401
406
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
402
407
|
// the peerstore should ensure that the peer is registered with that protocol
|
|
403
|
-
this.components.peerStore.
|
|
408
|
+
await this.components.peerStore.merge(remotePeer, {
|
|
409
|
+
protocols: [protocol]
|
|
410
|
+
})
|
|
404
411
|
|
|
405
412
|
connection.addStream(muxedStream)
|
|
406
413
|
this.components.metrics?.trackProtocolStream(muxedStream, connection)
|
|
@@ -428,18 +435,16 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
428
435
|
|
|
429
436
|
log('%s: starting new stream on %s', direction, protocols)
|
|
430
437
|
const muxedStream = await muxer.newStream()
|
|
431
|
-
let controller: TimeoutController | undefined
|
|
432
438
|
|
|
433
439
|
try {
|
|
434
440
|
if (options.signal == null) {
|
|
435
441
|
log('No abort signal was passed while trying to negotiate protocols %s falling back to default timeout', protocols)
|
|
436
442
|
|
|
437
|
-
|
|
438
|
-
options.signal = controller.signal
|
|
443
|
+
options.signal = AbortSignal.timeout(30000)
|
|
439
444
|
|
|
440
445
|
try {
|
|
441
446
|
// fails on node < 15.4
|
|
442
|
-
setMaxListeners?.(Infinity,
|
|
447
|
+
setMaxListeners?.(Infinity, options.signal)
|
|
443
448
|
} catch { }
|
|
444
449
|
}
|
|
445
450
|
|
|
@@ -457,7 +462,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
457
462
|
|
|
458
463
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
459
464
|
// the peerstore should ensure that the peer is registered with that protocol
|
|
460
|
-
this.components.peerStore.
|
|
465
|
+
await this.components.peerStore.merge(remotePeer, {
|
|
466
|
+
protocols: [protocol]
|
|
467
|
+
})
|
|
461
468
|
|
|
462
469
|
// after the handshake the returned stream can have early data so override
|
|
463
470
|
// the souce/sink
|
|
@@ -480,10 +487,6 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
480
487
|
}
|
|
481
488
|
|
|
482
489
|
throw new CodeError(String(err), codes.ERR_UNSUPPORTED_PROTOCOL)
|
|
483
|
-
} finally {
|
|
484
|
-
if (controller != null) {
|
|
485
|
-
controller.clear()
|
|
486
|
-
}
|
|
487
490
|
}
|
|
488
491
|
}
|
|
489
492
|
|
|
@@ -509,9 +512,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
509
512
|
} catch (err: any) {
|
|
510
513
|
log.error(err)
|
|
511
514
|
} finally {
|
|
512
|
-
this.
|
|
515
|
+
this.events.safeDispatchEvent('connection:close', {
|
|
513
516
|
detail: connection
|
|
514
|
-
})
|
|
517
|
+
})
|
|
515
518
|
}
|
|
516
519
|
})().catch(err => {
|
|
517
520
|
log.error(err)
|
|
@@ -549,9 +552,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
549
552
|
}
|
|
550
553
|
})
|
|
551
554
|
|
|
552
|
-
this.
|
|
555
|
+
this.events.safeDispatchEvent('connection:open', {
|
|
553
556
|
detail: connection
|
|
554
|
-
})
|
|
557
|
+
})
|
|
555
558
|
|
|
556
559
|
return connection
|
|
557
560
|
}
|
|
@@ -569,7 +572,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
569
572
|
/**
|
|
570
573
|
* Attempts to encrypt the incoming `connection` with the provided `cryptos`
|
|
571
574
|
*/
|
|
572
|
-
async _encryptInbound (connection: Duplex<Uint8Array
|
|
575
|
+
async _encryptInbound (connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>>): Promise<CryptoResult> {
|
|
573
576
|
const protocols = Array.from(this.connectionEncryption.keys())
|
|
574
577
|
log('handling inbound crypto protocol selection', protocols)
|
|
575
578
|
|
|
@@ -627,7 +630,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
627
630
|
* Selects one of the given muxers via multistream-select. That
|
|
628
631
|
* muxer will be used for all future streams on the connection.
|
|
629
632
|
*/
|
|
630
|
-
async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<Uint8Array>, muxerFactory?: StreamMuxerFactory }> {
|
|
633
|
+
async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
|
|
631
634
|
const protocols = Array.from(muxers.keys())
|
|
632
635
|
log('outbound selecting muxer %s', protocols)
|
|
633
636
|
try {
|
|
@@ -636,6 +639,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
636
639
|
})
|
|
637
640
|
log('%s selected as muxer protocol', protocol)
|
|
638
641
|
const muxerFactory = muxers.get(protocol)
|
|
642
|
+
|
|
639
643
|
return { stream, muxerFactory }
|
|
640
644
|
} catch (err: any) {
|
|
641
645
|
log.error('error multiplexing outbound stream', err)
|
|
@@ -647,7 +651,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
647
651
|
* Registers support for one of the given muxers via multistream-select. The
|
|
648
652
|
* selected muxer will be used for all future streams on the connection.
|
|
649
653
|
*/
|
|
650
|
-
async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<Uint8Array>, muxerFactory?: StreamMuxerFactory }> {
|
|
654
|
+
async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
|
|
651
655
|
const protocols = Array.from(muxers.keys())
|
|
652
656
|
log('inbound handling muxers %s', protocols)
|
|
653
657
|
try {
|
|
@@ -655,6 +659,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
655
659
|
writeBytes: true
|
|
656
660
|
})
|
|
657
661
|
const muxerFactory = muxers.get(protocol)
|
|
662
|
+
|
|
658
663
|
return { stream, muxerFactory }
|
|
659
664
|
} catch (err: any) {
|
|
660
665
|
log.error('error multiplexing inbound stream', err)
|
|
@@ -3,16 +3,16 @@ import { logger } from '@libp2p/logger'
|
|
|
3
3
|
import { fromNodeAddress } from '@multiformats/multiaddr'
|
|
4
4
|
import { isBrowser } from 'wherearewe'
|
|
5
5
|
import isPrivateIp from 'private-ip'
|
|
6
|
-
import * as pkg from '
|
|
6
|
+
import * as pkg from '../version.js'
|
|
7
7
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
8
|
-
import { codes } from '
|
|
8
|
+
import { codes } from '../errors.js'
|
|
9
9
|
import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback'
|
|
10
10
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
11
11
|
import type { TransportManager } from '@libp2p/interface-transport'
|
|
12
12
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
13
13
|
import type { AddressManager } from '@libp2p/interface-address-manager'
|
|
14
14
|
|
|
15
|
-
const log = logger('libp2p:nat')
|
|
15
|
+
const log = logger('libp2p:upnp-nat')
|
|
16
16
|
const DEFAULT_TTL = 7200
|
|
17
17
|
|
|
18
18
|
function highPort (min = 1024, max = 65535): number {
|
|
@@ -26,12 +26,7 @@ export interface PMPOptions {
|
|
|
26
26
|
enabled?: boolean
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export interface
|
|
30
|
-
/**
|
|
31
|
-
* Whether to enable the NAT manager
|
|
32
|
-
*/
|
|
33
|
-
enabled: boolean
|
|
34
|
-
|
|
29
|
+
export interface UPnPNATInit {
|
|
35
30
|
/**
|
|
36
31
|
* Pass a value to use instead of auto-detection
|
|
37
32
|
*/
|
|
@@ -63,15 +58,14 @@ export interface NatManagerInit {
|
|
|
63
58
|
gateway?: string
|
|
64
59
|
}
|
|
65
60
|
|
|
66
|
-
export interface
|
|
61
|
+
export interface UPnPNATComponents {
|
|
67
62
|
peerId: PeerId
|
|
68
63
|
transportManager: TransportManager
|
|
69
64
|
addressManager: AddressManager
|
|
70
65
|
}
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
private readonly components:
|
|
74
|
-
private readonly enabled: boolean
|
|
67
|
+
class UPnPNAT implements Startable {
|
|
68
|
+
private readonly components: UPnPNATComponents
|
|
75
69
|
private readonly externalAddress?: string
|
|
76
70
|
private readonly localAddress?: string
|
|
77
71
|
private readonly description: string
|
|
@@ -81,11 +75,10 @@ export class NatManager implements Startable {
|
|
|
81
75
|
private started: boolean
|
|
82
76
|
private client?: NatAPI
|
|
83
77
|
|
|
84
|
-
constructor (components:
|
|
78
|
+
constructor (components: UPnPNATComponents, init: UPnPNATInit) {
|
|
85
79
|
this.components = components
|
|
86
80
|
|
|
87
81
|
this.started = false
|
|
88
|
-
this.enabled = init.enabled
|
|
89
82
|
this.externalAddress = init.externalAddress
|
|
90
83
|
this.localAddress = init.localAddress
|
|
91
84
|
this.description = init.description ?? `${pkg.name}@${pkg.version} ${this.components.peerId.toString()}`
|
|
@@ -112,7 +105,7 @@ export class NatManager implements Startable {
|
|
|
112
105
|
* Run after start to ensure the transport manager has all addresses configured.
|
|
113
106
|
*/
|
|
114
107
|
afterStart (): void {
|
|
115
|
-
if (isBrowser ||
|
|
108
|
+
if (isBrowser || this.started) {
|
|
116
109
|
return
|
|
117
110
|
}
|
|
118
111
|
|
|
@@ -211,3 +204,9 @@ export class NatManager implements Startable {
|
|
|
211
204
|
}
|
|
212
205
|
}
|
|
213
206
|
}
|
|
207
|
+
|
|
208
|
+
export function uPnPNAT (init: UPnPNATInit): (components: UPnPNATComponents) => {} {
|
|
209
|
+
return (components: UPnPNATComponents) => {
|
|
210
|
+
return new UPnPNAT(components, init)
|
|
211
|
+
}
|
|
212
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.
|
|
1
|
+
export const version = '0.44.0-0d46c78f'
|
|
2
2
|
export const name = 'libp2p'
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Startable } from '@libp2p/interfaces/startable';
|
|
2
|
-
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
3
|
-
import type { ConnectionManager } from '@libp2p/interface-connection-manager';
|
|
4
|
-
import type { PeerStore } from '@libp2p/interface-peer-store';
|
|
5
|
-
export interface AutoDiallerInit {
|
|
6
|
-
/**
|
|
7
|
-
* The minimum number of connections to avoid pruning
|
|
8
|
-
*/
|
|
9
|
-
minConnections?: number;
|
|
10
|
-
/**
|
|
11
|
-
* How often, in milliseconds, it should preemptively guarantee connections are above the low watermark
|
|
12
|
-
*/
|
|
13
|
-
autoDialInterval?: number;
|
|
14
|
-
}
|
|
15
|
-
export interface AutoDiallerComponents {
|
|
16
|
-
peerId: PeerId;
|
|
17
|
-
connectionManager: ConnectionManager;
|
|
18
|
-
peerStore: PeerStore;
|
|
19
|
-
}
|
|
20
|
-
export declare class AutoDialler implements Startable {
|
|
21
|
-
private readonly components;
|
|
22
|
-
private readonly options;
|
|
23
|
-
private running;
|
|
24
|
-
private autoDialTimeout?;
|
|
25
|
-
/**
|
|
26
|
-
* Proactively tries to connect to known peers stored in the PeerStore.
|
|
27
|
-
* It will keep the number of connections below the upper limit and sort
|
|
28
|
-
* the peers to connect based on wether we know their keys and protocols.
|
|
29
|
-
*/
|
|
30
|
-
constructor(components: AutoDiallerComponents, init: AutoDiallerInit);
|
|
31
|
-
isStarted(): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Starts the auto dialer
|
|
34
|
-
*/
|
|
35
|
-
start(): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Stops the auto dialler
|
|
38
|
-
*/
|
|
39
|
-
stop(): Promise<void>;
|
|
40
|
-
_autoDial(): Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=auto-dialler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-dialler.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAI7D,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,SAAS,EAAE,SAAS,CAAA;CACrB;AAOD,qBAAa,WAAY,YAAW,SAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,eAAe,CAAC,CAAqB;IAE7C;;;;OAIG;gBACU,UAAU,EAAE,qBAAqB,EAAE,IAAI,EAAE,eAAe;IASrE,SAAS,IAAK,OAAO;IAIrB;;OAEG;IACG,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAU7B;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAUtB,SAAS,IAAK,OAAO,CAAC,IAAI,CAAC;CAyElC"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger';
|
|
2
|
-
import mergeOptions from 'merge-options';
|
|
3
|
-
// @ts-expect-error retimer does not have types
|
|
4
|
-
import retimer from 'retimer';
|
|
5
|
-
const log = logger('libp2p:connection-manager:auto-dialler');
|
|
6
|
-
const defaultOptions = {
|
|
7
|
-
minConnections: 0,
|
|
8
|
-
autoDialInterval: 10000
|
|
9
|
-
};
|
|
10
|
-
export class AutoDialler {
|
|
11
|
-
/**
|
|
12
|
-
* Proactively tries to connect to known peers stored in the PeerStore.
|
|
13
|
-
* It will keep the number of connections below the upper limit and sort
|
|
14
|
-
* the peers to connect based on wether we know their keys and protocols.
|
|
15
|
-
*/
|
|
16
|
-
constructor(components, init) {
|
|
17
|
-
this.components = components;
|
|
18
|
-
this.options = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, init);
|
|
19
|
-
this.running = false;
|
|
20
|
-
this._autoDial = this._autoDial.bind(this);
|
|
21
|
-
log('options: %j', this.options);
|
|
22
|
-
}
|
|
23
|
-
isStarted() {
|
|
24
|
-
return this.running;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Starts the auto dialer
|
|
28
|
-
*/
|
|
29
|
-
async start() {
|
|
30
|
-
this.running = true;
|
|
31
|
-
void this._autoDial().catch(err => {
|
|
32
|
-
log.error('could not start autodial', err);
|
|
33
|
-
});
|
|
34
|
-
log('started');
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Stops the auto dialler
|
|
38
|
-
*/
|
|
39
|
-
async stop() {
|
|
40
|
-
this.running = false;
|
|
41
|
-
if (this.autoDialTimeout != null) {
|
|
42
|
-
this.autoDialTimeout.clear();
|
|
43
|
-
}
|
|
44
|
-
log('stopped');
|
|
45
|
-
}
|
|
46
|
-
async _autoDial() {
|
|
47
|
-
if (this.autoDialTimeout != null) {
|
|
48
|
-
this.autoDialTimeout.clear();
|
|
49
|
-
}
|
|
50
|
-
const minConnections = this.options.minConnections;
|
|
51
|
-
// Already has enough connections
|
|
52
|
-
if (this.components.connectionManager.getConnections().length >= minConnections) {
|
|
53
|
-
this.autoDialTimeout = retimer(this._autoDial, this.options.autoDialInterval);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
// Sort peers on whether we know protocols or public keys for them
|
|
57
|
-
let peers = await this.components.peerStore.all();
|
|
58
|
-
peers = peers.filter((peer) => {
|
|
59
|
-
// do not dial ourselves
|
|
60
|
-
if (peer.id.equals(this.components.peerId)) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
// do not dial peers without multiaddrs
|
|
64
|
-
if (peer.addresses.length === 0) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
68
|
-
});
|
|
69
|
-
// shuffle the peers
|
|
70
|
-
peers = peers.sort(() => Math.random() > 0.5 ? 1 : -1);
|
|
71
|
-
peers = peers.sort((a, b) => {
|
|
72
|
-
// dial peers with the most protocols first
|
|
73
|
-
if (b.protocols.length > a.protocols.length) {
|
|
74
|
-
return 1;
|
|
75
|
-
}
|
|
76
|
-
// dial peers with public keys first
|
|
77
|
-
if (b.id.publicKey != null && a.id.publicKey == null) {
|
|
78
|
-
return 1;
|
|
79
|
-
}
|
|
80
|
-
return -1;
|
|
81
|
-
});
|
|
82
|
-
for (let i = 0; this.running && i < peers.length && this.components.connectionManager.getConnections().length < minConnections; i++) {
|
|
83
|
-
// Connection Manager was stopped during async dial
|
|
84
|
-
if (!this.running) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const peer = peers[i];
|
|
88
|
-
if (this.components.connectionManager.getConnections(peer.id).length === 0) {
|
|
89
|
-
log('connecting to a peerStore stored peer %p', peer.id);
|
|
90
|
-
try {
|
|
91
|
-
await this.components.connectionManager.openConnection(peer.id);
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
log.error('could not connect to peerStore stored peer', err);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// Connection Manager was stopped
|
|
99
|
-
if (!this.running) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
this.autoDialTimeout = retimer(this._autoDial, this.options.autoDialInterval);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
//# sourceMappingURL=auto-dialler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-dialler.js","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
-
import type { Connection } from '@libp2p/interface-connection';
|
|
3
|
-
import type { AbortOptions } from '@libp2p/interfaces';
|
|
4
|
-
import type { Dialer } from '@libp2p/interface-connection-manager';
|
|
5
|
-
export interface DialAction {
|
|
6
|
-
(m: Multiaddr, options: AbortOptions): Promise<Connection>;
|
|
7
|
-
}
|
|
8
|
-
export interface DialRequestOptions {
|
|
9
|
-
addrs: Multiaddr[];
|
|
10
|
-
dialAction: DialAction;
|
|
11
|
-
dialer: Dialer;
|
|
12
|
-
}
|
|
13
|
-
export declare class DialRequest {
|
|
14
|
-
private readonly addrs;
|
|
15
|
-
private readonly dialer;
|
|
16
|
-
private readonly dialAction;
|
|
17
|
-
/**
|
|
18
|
-
* Manages running the `dialAction` on multiple provided `addrs` in parallel
|
|
19
|
-
* up to a maximum determined by the number of tokens returned
|
|
20
|
-
* from `dialer.getTokens`. Once a DialRequest is created, it can be
|
|
21
|
-
* started using `DialRequest.run(options)`. Once a single dial has succeeded,
|
|
22
|
-
* all other dials in the request will be cancelled.
|
|
23
|
-
*/
|
|
24
|
-
constructor(options: DialRequestOptions);
|
|
25
|
-
run(options?: AbortOptions): Promise<Connection>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=dial-request.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dial-request.d.ts","sourceRoot":"","sources":["../../../../src/connection-manager/dialer/dial-request.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAA;AAIlE,MAAM,WAAW,UAAU;IACzB,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CAC3D;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IAEvC;;;;;;OAMG;gBACU,OAAO,EAAE,kBAAkB;IAYlC,GAAG,CAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;CAgG5D"}
|