libp2p 2.7.2 → 2.7.3-4939ef7ae
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 +33 -4
- package/dist/index.min.js +15 -10
- package/dist/src/address-manager/index.js +8 -8
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +1 -1
- package/dist/src/config/connection-gater.browser.js +1 -1
- package/dist/src/connection-manager/address-sorter.js +4 -4
- package/dist/src/connection-manager/constants.defaults.d.ts +4 -4
- package/dist/src/connection-manager/constants.defaults.d.ts.map +1 -1
- package/dist/src/connection-manager/constants.defaults.js +4 -4
- package/dist/src/connection-manager/constants.defaults.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +1 -0
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +106 -74
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +8 -6
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +12 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +2 -3
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/random-walk.js +2 -2
- package/dist/src/random-walk.js.map +1 -1
- package/dist/src/transport-manager.d.ts +1 -0
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +70 -26
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +5 -11
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +25 -18
- 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 +11 -11
- package/src/address-manager/index.ts +8 -8
- package/src/config/connection-gater.browser.ts +1 -1
- package/src/connection-manager/address-sorter.ts +4 -4
- package/src/connection-manager/constants.defaults.ts +4 -4
- package/src/connection-manager/dial-queue.ts +122 -78
- package/src/connection-manager/index.ts +8 -6
- package/src/errors.ts +14 -0
- package/src/index.ts +1 -1
- package/src/libp2p.ts +2 -3
- package/src/random-walk.ts +2 -2
- package/src/transport-manager.ts +94 -26
- package/src/upgrader.ts +30 -28
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -21
|
@@ -59,7 +59,7 @@ export interface ConnectionManagerInit {
|
|
|
59
59
|
* How long a dial attempt is allowed to take, including DNS resolution
|
|
60
60
|
* of the multiaddr, opening a socket and upgrading it to a Connection.
|
|
61
61
|
*
|
|
62
|
-
* @default
|
|
62
|
+
* @default 10_000
|
|
63
63
|
*/
|
|
64
64
|
dialTimeout?: number
|
|
65
65
|
|
|
@@ -67,7 +67,7 @@ export interface ConnectionManagerInit {
|
|
|
67
67
|
* When a new incoming connection is opened, the upgrade process (e.g.
|
|
68
68
|
* protect, encrypt, multiplex etc) must complete within this number of ms.
|
|
69
69
|
*
|
|
70
|
-
* @default
|
|
70
|
+
* @default 10_000
|
|
71
71
|
*/
|
|
72
72
|
inboundUpgradeTimeout?: number
|
|
73
73
|
|
|
@@ -77,7 +77,7 @@ export interface ConnectionManagerInit {
|
|
|
77
77
|
*
|
|
78
78
|
* Does not apply if an abort signal is passed to the `.dial` method.
|
|
79
79
|
*
|
|
80
|
-
* @
|
|
80
|
+
* @deprecated This is handled by `dialTimeout`
|
|
81
81
|
*/
|
|
82
82
|
outboundUpgradeTimeout?: number
|
|
83
83
|
|
|
@@ -92,16 +92,18 @@ export interface ConnectionManagerInit {
|
|
|
92
92
|
/**
|
|
93
93
|
* Outbound protocol negotiation must complete within this number of ms.
|
|
94
94
|
*
|
|
95
|
-
* Does not apply if an abort signal is passed to the `.dial`
|
|
95
|
+
* Does not apply if an abort signal is passed to the `.dial` or
|
|
96
|
+
* `.dialProtocol` method of the `ConnectionManager` or the `openStream`
|
|
97
|
+
* method of the `Connection`.
|
|
96
98
|
*
|
|
97
|
-
* @default
|
|
99
|
+
* @default 10_000
|
|
98
100
|
*/
|
|
99
101
|
outboundStreamProtocolNegotiationTimeout?: number
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
104
|
* Inbound protocol negotiation must complete within this number of ms
|
|
103
105
|
*
|
|
104
|
-
* @default
|
|
106
|
+
* @default 10_000
|
|
105
107
|
*/
|
|
106
108
|
inboundStreamProtocolNegotiationTimeout?: number
|
|
107
109
|
|
package/src/errors.ts
CHANGED
|
@@ -59,6 +59,20 @@ export class DialDeniedError extends Error {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
export class UnsupportedListenAddressError extends Error {
|
|
63
|
+
constructor (message = 'No transport was configured to listen on this address') {
|
|
64
|
+
super(message)
|
|
65
|
+
this.name = 'UnsupportedListenAddressError'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class UnsupportedListenAddressesError extends Error {
|
|
70
|
+
constructor (message = 'Configured listen addresses could not be listened on') {
|
|
71
|
+
super(message)
|
|
72
|
+
this.name = 'UnsupportedListenAddressesError'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
62
76
|
export class NoValidAddressesError extends Error {
|
|
63
77
|
constructor (message = 'No valid addresses') {
|
|
64
78
|
super(message)
|
package/src/index.ts
CHANGED
|
@@ -102,7 +102,7 @@ export interface Libp2pInit<T extends ServiceMap = ServiceMap> {
|
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Connection encrypters ensure that data sent over connections cannot be
|
|
105
|
-
* eavesdropped on, and that the remote peer
|
|
105
|
+
* eavesdropped on, and that the remote peer possesses the private key that
|
|
106
106
|
* corresponds to the public key that it's Peer ID is derived from.
|
|
107
107
|
*/
|
|
108
108
|
connectionEncrypters?: Array<(components: Components) => ConnectionEncrypter>
|
package/src/libp2p.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { DefaultPeerRouting } from './peer-routing.js'
|
|
|
18
18
|
import { RandomWalk } from './random-walk.js'
|
|
19
19
|
import { Registrar } from './registrar.js'
|
|
20
20
|
import { DefaultTransportManager } from './transport-manager.js'
|
|
21
|
-
import {
|
|
21
|
+
import { Upgrader } from './upgrader.js'
|
|
22
22
|
import { userAgent } from './user-agent.js'
|
|
23
23
|
import * as pkg from './version.js'
|
|
24
24
|
import type { Components } from './components.js'
|
|
@@ -113,11 +113,10 @@ export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
// Set up the Upgrader
|
|
116
|
-
this.components.upgrader = new
|
|
116
|
+
this.components.upgrader = new Upgrader(this.components, {
|
|
117
117
|
connectionEncrypters: (init.connectionEncrypters ?? []).map((fn, index) => this.configureComponent(`connection-encryption-${index}`, fn(this.components))),
|
|
118
118
|
streamMuxers: (init.streamMuxers ?? []).map((fn, index) => this.configureComponent(`stream-muxers-${index}`, fn(this.components))),
|
|
119
119
|
inboundUpgradeTimeout: init.connectionManager?.inboundUpgradeTimeout,
|
|
120
|
-
outboundUpgradeTimeout: init.connectionManager?.outboundUpgradeTimeout,
|
|
121
120
|
inboundStreamProtocolNegotiationTimeout: init.connectionManager?.inboundStreamProtocolNegotiationTimeout ?? init.connectionManager?.protocolNegotiationTimeout,
|
|
122
121
|
outboundStreamProtocolNegotiationTimeout: init.connectionManager?.outboundStreamProtocolNegotiationTimeout ?? init.connectionManager?.protocolNegotiationTimeout
|
|
123
122
|
})
|
package/src/random-walk.ts
CHANGED
|
@@ -133,7 +133,7 @@ export class RandomWalk extends TypedEventEmitter<RandomWalkEvents> implements R
|
|
|
133
133
|
|
|
134
134
|
this.log('walk iteration for %b and %d walkers finished, found %d peers', data, this.walkers, found)
|
|
135
135
|
} catch (err) {
|
|
136
|
-
this.log.error('
|
|
136
|
+
this.log.error('random walk errored', err)
|
|
137
137
|
|
|
138
138
|
this.safeDispatchEvent('walk:error', {
|
|
139
139
|
detail: err
|
|
@@ -144,7 +144,7 @@ export class RandomWalk extends TypedEventEmitter<RandomWalkEvents> implements R
|
|
|
144
144
|
this.log('no walkers left, ended walk')
|
|
145
145
|
})
|
|
146
146
|
.catch(err => {
|
|
147
|
-
this.log.error('
|
|
147
|
+
this.log.error('random walk errored', err)
|
|
148
148
|
})
|
|
149
149
|
.finally(() => {
|
|
150
150
|
this.log('finished walk, found %d peers after %dms', found, Date.now() - start)
|
package/src/transport-manager.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { FaultTolerance, InvalidParametersError, NotStartedError } from '@libp2p/interface'
|
|
2
2
|
import { trackedMap } from '@libp2p/utils/tracked-map'
|
|
3
|
+
import { IP4, IP6 } from '@multiformats/multiaddr-matcher'
|
|
3
4
|
import { CustomProgressEvent } from 'progress-events'
|
|
4
|
-
import {
|
|
5
|
+
import { TransportUnavailableError, UnsupportedListenAddressError, UnsupportedListenAddressesError } from './errors.js'
|
|
5
6
|
import type { Libp2pEvents, ComponentLogger, Logger, Connection, TypedEventTarget, Metrics, Startable, Listener, Transport, Upgrader } from '@libp2p/interface'
|
|
6
7
|
import type { AddressManager, TransportManager, TransportManagerDialOptions } from '@libp2p/interface-internal'
|
|
7
8
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
@@ -18,6 +19,17 @@ export interface DefaultTransportManagerComponents {
|
|
|
18
19
|
logger: ComponentLogger
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
interface IPStats {
|
|
23
|
+
success: number
|
|
24
|
+
attempts: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ListenStats {
|
|
28
|
+
errors: Map<string, Error>
|
|
29
|
+
ipv4: IPStats
|
|
30
|
+
ipv6: IPStats
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
export class DefaultTransportManager implements TransportManager, Startable {
|
|
22
34
|
private readonly log: Logger
|
|
23
35
|
private readonly components: DefaultTransportManagerComponents
|
|
@@ -192,11 +204,28 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
192
204
|
return
|
|
193
205
|
}
|
|
194
206
|
|
|
195
|
-
|
|
207
|
+
// track IPv4/IPv6 results - if we succeed on IPv4 but all IPv6 attempts
|
|
208
|
+
// fail then we are probably on a network without IPv6 support
|
|
209
|
+
const listenStats: ListenStats = {
|
|
210
|
+
errors: new Map(),
|
|
211
|
+
ipv4: {
|
|
212
|
+
success: 0,
|
|
213
|
+
attempts: 0
|
|
214
|
+
},
|
|
215
|
+
ipv6: {
|
|
216
|
+
success: 0,
|
|
217
|
+
attempts: 0
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
addrs.forEach(ma => {
|
|
222
|
+
listenStats.errors.set(ma.toString(), new UnsupportedListenAddressError())
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
const tasks: Array<Promise<void>> = []
|
|
196
226
|
|
|
197
227
|
for (const [key, transport] of this.transports.entries()) {
|
|
198
228
|
const supportedAddrs = transport.listenFilter(addrs)
|
|
199
|
-
const tasks = []
|
|
200
229
|
|
|
201
230
|
// For each supported multiaddr, create a listener
|
|
202
231
|
for (const addr of supportedAddrs) {
|
|
@@ -231,36 +260,75 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
231
260
|
})
|
|
232
261
|
})
|
|
233
262
|
|
|
263
|
+
// track IPv4/IPv6 support
|
|
264
|
+
if (IP4.matches(addr)) {
|
|
265
|
+
listenStats.ipv4.attempts++
|
|
266
|
+
} else if (IP6.matches(addr)) {
|
|
267
|
+
listenStats.ipv6.attempts++
|
|
268
|
+
}
|
|
269
|
+
|
|
234
270
|
// We need to attempt to listen on everything
|
|
235
|
-
tasks.push(
|
|
271
|
+
tasks.push(
|
|
272
|
+
listener.listen(addr)
|
|
273
|
+
.then(() => {
|
|
274
|
+
listenStats.errors.delete(addr.toString())
|
|
275
|
+
|
|
276
|
+
if (IP4.matches(addr)) {
|
|
277
|
+
listenStats.ipv4.success++
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (IP6.matches(addr)) {
|
|
281
|
+
listenStats.ipv6.success++
|
|
282
|
+
}
|
|
283
|
+
}, (err) => {
|
|
284
|
+
this.log.error('transport %s could not listen on address %a - %e', key, addr, err)
|
|
285
|
+
listenStats.errors.set(addr.toString(), err)
|
|
286
|
+
throw err
|
|
287
|
+
})
|
|
288
|
+
)
|
|
236
289
|
}
|
|
290
|
+
}
|
|
237
291
|
|
|
238
|
-
|
|
239
|
-
if (tasks.length === 0) {
|
|
240
|
-
couldNotListen.push(key)
|
|
241
|
-
continue
|
|
242
|
-
}
|
|
292
|
+
const results = await Promise.allSettled(tasks)
|
|
243
293
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// listening on remote addresses as they may be offline. We could then potentially
|
|
248
|
-
// just wait for any (`p-any`) listener to succeed on each transport before returning
|
|
249
|
-
const isListening = results.find(r => r.status === 'fulfilled')
|
|
250
|
-
if ((isListening == null) && this.faultTolerance !== FaultTolerance.NO_FATAL) {
|
|
251
|
-
throw new NoValidAddressesError(`Transport (${key}) could not listen on any available address`)
|
|
252
|
-
}
|
|
294
|
+
// listening on all addresses, all good
|
|
295
|
+
if (results.length > 0 && results.every(res => res.status === 'fulfilled')) {
|
|
296
|
+
return
|
|
253
297
|
}
|
|
254
298
|
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
299
|
+
// detect lack of IPv6 support on the current network - if we tried to
|
|
300
|
+
// listen on IPv4 and IPv6 addresses, and all IPv4 addresses succeeded but
|
|
301
|
+
// all IPv6 addresses fail, then we can assume there's no IPv6 here
|
|
302
|
+
if (this.ipv6Unsupported(listenStats)) {
|
|
303
|
+
this.log('all IPv4 addresses succeed but all IPv6 failed')
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (this.faultTolerance === FaultTolerance.NO_FATAL) {
|
|
308
|
+
// ok to be dial-only
|
|
309
|
+
this.log('failed to listen on any address but fault tolerance allows this')
|
|
310
|
+
return
|
|
263
311
|
}
|
|
312
|
+
|
|
313
|
+
// if a configured address was not able to be listened on, throw an error
|
|
314
|
+
throw new UnsupportedListenAddressesError(`Some configured addresses failed to be listened on, you may need to remove one or more listen addresses from your configuration or set \`transportManager.faultTolerance\` to NO_FATAL:\n${
|
|
315
|
+
[...listenStats.errors.entries()].map(([addr, err]) => {
|
|
316
|
+
return `
|
|
317
|
+
${addr}: ${`${err.stack ?? err}`.split('\n').join('\n ')}
|
|
318
|
+
`
|
|
319
|
+
}).join('')
|
|
320
|
+
}`)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private ipv6Unsupported (listenStats: ListenStats): boolean {
|
|
324
|
+
if (listenStats.ipv4.attempts === 0 || listenStats.ipv6.attempts === 0) {
|
|
325
|
+
return false
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const allIpv4Succeeded = listenStats.ipv4.attempts === listenStats.ipv4.success
|
|
329
|
+
const allIpv6Failed = listenStats.ipv6.success === 0
|
|
330
|
+
|
|
331
|
+
return allIpv4Succeeded && allIpv6Failed
|
|
264
332
|
}
|
|
265
333
|
|
|
266
334
|
/**
|
package/src/upgrader.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { InvalidMultiaddrError, TooManyInboundProtocolStreamsError, TooManyOutboundProtocolStreamsError, LimitedConnectionError, setMaxListeners, InvalidPeerIdError } from '@libp2p/interface'
|
|
2
2
|
import * as mss from '@libp2p/multistream-select'
|
|
3
3
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
4
|
+
import { anySignal } from 'any-signal'
|
|
4
5
|
import { CustomProgressEvent } from 'progress-events'
|
|
5
6
|
import { createConnection } from './connection/index.js'
|
|
6
|
-
import { PROTOCOL_NEGOTIATION_TIMEOUT,
|
|
7
|
+
import { PROTOCOL_NEGOTIATION_TIMEOUT, INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
|
|
7
8
|
import { ConnectionDeniedError, ConnectionInterceptedError, EncryptionFailedError, MuxerUnavailableError } from './errors.js'
|
|
8
9
|
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'
|
|
9
|
-
import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxer, StreamMuxerFactory, Upgrader, UpgraderOptions, ConnectionLimits, SecureConnectionOptions, CounterGroup } from '@libp2p/interface'
|
|
10
|
+
import type { Libp2pEvents, AbortOptions, ComponentLogger, MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions, ConnectionEncrypter, SecuredConnection, ConnectionGater, TypedEventTarget, Metrics, PeerId, PeerStore, StreamMuxer, StreamMuxerFactory, Upgrader as UpgraderInterface, UpgraderOptions, ConnectionLimits, SecureConnectionOptions, CounterGroup, ClearableSignal } from '@libp2p/interface'
|
|
10
11
|
import type { ConnectionManager, Registrar } from '@libp2p/interface-internal'
|
|
11
12
|
|
|
12
13
|
interface CreateConnectionOptions {
|
|
@@ -40,13 +41,6 @@ export interface UpgraderInit {
|
|
|
40
41
|
*/
|
|
41
42
|
inboundUpgradeTimeout?: number
|
|
42
43
|
|
|
43
|
-
/**
|
|
44
|
-
* An amount of ms by which an outbound connection upgrade must complete
|
|
45
|
-
*
|
|
46
|
-
* @default 3000
|
|
47
|
-
*/
|
|
48
|
-
outboundUpgradeTimeout?: number
|
|
49
|
-
|
|
50
44
|
/**
|
|
51
45
|
* When a new incoming stream is opened on a multiplexed connection, protocol
|
|
52
46
|
* negotiation on that stream must complete within this many ms
|
|
@@ -120,12 +114,11 @@ export interface DefaultUpgraderComponents {
|
|
|
120
114
|
|
|
121
115
|
type ConnectionDeniedType = keyof Pick<ConnectionGater, 'denyOutboundConnection' | 'denyInboundEncryptedConnection' | 'denyOutboundEncryptedConnection' | 'denyInboundUpgradedConnection' | 'denyOutboundUpgradedConnection'>
|
|
122
116
|
|
|
123
|
-
export class
|
|
117
|
+
export class Upgrader implements UpgraderInterface {
|
|
124
118
|
private readonly components: DefaultUpgraderComponents
|
|
125
119
|
private readonly connectionEncrypters: Map<string, ConnectionEncrypter>
|
|
126
120
|
private readonly streamMuxers: Map<string, StreamMuxerFactory>
|
|
127
121
|
private readonly inboundUpgradeTimeout: number
|
|
128
|
-
private readonly outboundUpgradeTimeout: number
|
|
129
122
|
private readonly inboundStreamProtocolNegotiationTimeout: number
|
|
130
123
|
private readonly outboundStreamProtocolNegotiationTimeout: number
|
|
131
124
|
private readonly events: TypedEventTarget<Libp2pEvents>
|
|
@@ -148,8 +141,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
148
141
|
this.streamMuxers.set(muxer.protocol, muxer)
|
|
149
142
|
})
|
|
150
143
|
|
|
151
|
-
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ??
|
|
152
|
-
this.outboundUpgradeTimeout = init.outboundUpgradeTimeout ?? UPGRADE_TIMEOUT
|
|
144
|
+
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? INBOUND_UPGRADE_TIMEOUT
|
|
153
145
|
this.inboundStreamProtocolNegotiationTimeout = init.inboundStreamProtocolNegotiationTimeout ?? PROTOCOL_NEGOTIATION_TIMEOUT
|
|
154
146
|
this.outboundStreamProtocolNegotiationTimeout = init.outboundStreamProtocolNegotiationTimeout ?? PROTOCOL_NEGOTIATION_TIMEOUT
|
|
155
147
|
this.events = components.events
|
|
@@ -177,12 +169,25 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
177
169
|
}
|
|
178
170
|
}
|
|
179
171
|
|
|
172
|
+
createInboundAbortSignal (signal: AbortSignal): ClearableSignal {
|
|
173
|
+
const output = anySignal([
|
|
174
|
+
AbortSignal.timeout(this.inboundUpgradeTimeout),
|
|
175
|
+
signal
|
|
176
|
+
])
|
|
177
|
+
setMaxListeners(Infinity, output)
|
|
178
|
+
|
|
179
|
+
return output
|
|
180
|
+
}
|
|
181
|
+
|
|
180
182
|
/**
|
|
181
183
|
* Upgrades an inbound connection
|
|
182
184
|
*/
|
|
183
|
-
async upgradeInbound (maConn: MultiaddrConnection, opts: UpgraderOptions
|
|
185
|
+
async upgradeInbound (maConn: MultiaddrConnection, opts: UpgraderOptions): Promise<void> {
|
|
184
186
|
let accepted = false
|
|
185
187
|
|
|
188
|
+
// always apply upgrade timeout for incoming upgrades
|
|
189
|
+
const signal = this.createInboundAbortSignal(opts.signal)
|
|
190
|
+
|
|
186
191
|
try {
|
|
187
192
|
this.metrics.dials?.increment({
|
|
188
193
|
inbound: true
|
|
@@ -196,7 +201,10 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
196
201
|
|
|
197
202
|
await this.shouldBlockConnection('denyInboundConnection', maConn)
|
|
198
203
|
|
|
199
|
-
await this._performUpgrade(maConn, 'inbound',
|
|
204
|
+
await this._performUpgrade(maConn, 'inbound', {
|
|
205
|
+
...opts,
|
|
206
|
+
signal
|
|
207
|
+
})
|
|
200
208
|
} catch (err) {
|
|
201
209
|
this.metrics.errors?.increment({
|
|
202
210
|
inbound: true
|
|
@@ -204,6 +212,8 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
204
212
|
|
|
205
213
|
throw err
|
|
206
214
|
} finally {
|
|
215
|
+
signal.clear()
|
|
216
|
+
|
|
207
217
|
if (accepted) {
|
|
208
218
|
this.components.connectionManager.afterUpgradeInbound()
|
|
209
219
|
}
|
|
@@ -213,7 +223,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
213
223
|
/**
|
|
214
224
|
* Upgrades an outbound connection
|
|
215
225
|
*/
|
|
216
|
-
async upgradeOutbound (maConn: MultiaddrConnection, opts: UpgraderOptions
|
|
226
|
+
async upgradeOutbound (maConn: MultiaddrConnection, opts: UpgraderOptions): Promise<Connection> {
|
|
217
227
|
try {
|
|
218
228
|
this.metrics.dials?.increment({
|
|
219
229
|
outbound: true
|
|
@@ -251,14 +261,6 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
251
261
|
let muxerFactory: StreamMuxerFactory | undefined
|
|
252
262
|
let cryptoProtocol
|
|
253
263
|
|
|
254
|
-
if (opts.signal == null) {
|
|
255
|
-
maConn.log('no abort signal was passed while trying to upgrade connection, falling back to default timeout')
|
|
256
|
-
|
|
257
|
-
const upgradeTimeoutSignal = AbortSignal.timeout(direction === 'inbound' ? this.inboundUpgradeTimeout : this.outboundUpgradeTimeout)
|
|
258
|
-
setMaxListeners(Infinity, upgradeTimeoutSignal)
|
|
259
|
-
opts.signal = upgradeTimeoutSignal
|
|
260
|
-
}
|
|
261
|
-
|
|
262
264
|
this.components.metrics?.trackMultiaddrConnection(maConn)
|
|
263
265
|
|
|
264
266
|
maConn.log.trace('starting the %s connection upgrade', direction)
|
|
@@ -413,7 +415,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
413
415
|
}
|
|
414
416
|
|
|
415
417
|
// after the handshake the returned stream can have early data so override
|
|
416
|
-
// the
|
|
418
|
+
// the source/sink
|
|
417
419
|
muxedStream.source = stream.source
|
|
418
420
|
muxedStream.sink = stream.sink
|
|
419
421
|
muxedStream.protocol = protocol
|
|
@@ -434,7 +436,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
434
436
|
}
|
|
435
437
|
|
|
436
438
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
437
|
-
// the
|
|
439
|
+
// the peer store should ensure that the peer is registered with that protocol
|
|
438
440
|
await this.components.peerStore.merge(remotePeer, {
|
|
439
441
|
protocols: [protocol]
|
|
440
442
|
})
|
|
@@ -499,13 +501,13 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
499
501
|
}
|
|
500
502
|
|
|
501
503
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
502
|
-
// the
|
|
504
|
+
// the peer store should ensure that the peer is registered with that protocol
|
|
503
505
|
await this.components.peerStore.merge(remotePeer, {
|
|
504
506
|
protocols: [protocol]
|
|
505
507
|
})
|
|
506
508
|
|
|
507
509
|
// after the handshake the returned stream can have early data so override
|
|
508
|
-
// the
|
|
510
|
+
// the source/sink
|
|
509
511
|
muxedStream.source = stream.source
|
|
510
512
|
muxedStream.sink = stream.sink
|
|
511
513
|
muxedStream.protocol = protocol
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '2.7.
|
|
1
|
+
export const version = '2.7.3-4939ef7ae'
|
|
2
2
|
export const name = 'js-libp2p'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AddressFilter": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressFilter.html",
|
|
3
|
-
"AddressManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressManagerInit.html",
|
|
4
|
-
"ConnectionManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionManagerInit.html",
|
|
5
|
-
"ConnectionMonitorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionMonitorInit.html",
|
|
6
|
-
"Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
7
|
-
".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
8
|
-
"TransportManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.TransportManagerInit.html",
|
|
9
|
-
"Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
10
|
-
".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
11
|
-
"ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
12
|
-
".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
13
|
-
"createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
14
|
-
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
15
|
-
"userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user_agent.userAgent.html",
|
|
16
|
-
"./user-agent:userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user_agent.userAgent.html",
|
|
17
|
-
"name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
18
|
-
"./version:name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
19
|
-
"version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html",
|
|
20
|
-
"./version:version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html"
|
|
21
|
-
}
|