libp2p 1.9.4 → 2.0.0-7cd984569
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 +17 -18
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +4 -3
- package/dist/src/components.js.map +1 -1
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +2 -7
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection/index.d.ts +3 -3
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +7 -7
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +1 -1
- package/dist/src/connection-manager/constants.browser.d.ts +0 -8
- package/dist/src/connection-manager/constants.browser.d.ts.map +1 -1
- package/dist/src/connection-manager/constants.browser.js +0 -8
- package/dist/src/connection-manager/constants.browser.js.map +1 -1
- package/dist/src/connection-manager/constants.d.ts +0 -8
- package/dist/src/connection-manager/constants.d.ts.map +1 -1
- package/dist/src/connection-manager/constants.defaults.d.ts +12 -22
- package/dist/src/connection-manager/constants.defaults.d.ts.map +1 -1
- package/dist/src/connection-manager/constants.defaults.js +12 -22
- package/dist/src/connection-manager/constants.defaults.js.map +1 -1
- package/dist/src/connection-manager/constants.js +0 -8
- package/dist/src/connection-manager/constants.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +29 -15
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +47 -50
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +23 -57
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/reconnect-queue.d.ts +35 -0
- package/dist/src/connection-manager/reconnect-queue.d.ts.map +1 -0
- package/dist/src/connection-manager/reconnect-queue.js +104 -0
- package/dist/src/connection-manager/reconnect-queue.js.map +1 -0
- package/dist/src/connection-monitor.d.ts +1 -0
- package/dist/src/connection-monitor.d.ts.map +1 -1
- package/dist/src/connection-monitor.js +15 -5
- package/dist/src/connection-monitor.js.map +1 -1
- package/dist/src/content-routing.js +6 -6
- package/dist/src/content-routing.js.map +1 -1
- package/dist/src/errors.d.ts +41 -61
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +84 -63
- package/dist/src/errors.js.map +1 -1
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +4 -5
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/index.d.ts +27 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +10 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +11 -10
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +13 -31
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.js +8 -8
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/registrar.js +7 -7
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +15 -23
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +8 -8
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +51 -51
- 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 +21 -21
- package/src/components.ts +4 -3
- package/src/config.ts +4 -10
- package/src/connection/index.ts +9 -9
- package/src/connection-manager/connection-pruner.ts +1 -1
- package/src/connection-manager/constants.browser.ts +0 -10
- package/src/connection-manager/constants.defaults.ts +14 -27
- package/src/connection-manager/constants.ts +0 -10
- package/src/connection-manager/dial-queue.ts +30 -15
- package/src/connection-manager/index.ts +80 -118
- package/src/connection-manager/reconnect-queue.ts +134 -0
- package/src/connection-monitor.ts +15 -6
- package/src/content-routing.ts +6 -6
- package/src/errors.ts +96 -61
- package/src/get-peer.ts +4 -5
- package/src/index.ts +42 -12
- package/src/libp2p.ts +22 -36
- package/src/peer-routing.ts +8 -8
- package/src/registrar.ts +7 -7
- package/src/transport-manager.ts +15 -23
- package/src/upgrader.ts +55 -56
- package/src/version.ts +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +0 -47
- package/dist/src/connection-manager/auto-dial.d.ts.map +0 -1
- package/dist/src/connection-manager/auto-dial.js +0 -223
- package/dist/src/connection-manager/auto-dial.js.map +0 -1
- package/dist/typedoc-urls.json +0 -14
- package/src/connection-manager/auto-dial.ts +0 -285
package/src/libp2p.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { contentRoutingSymbol,
|
|
1
|
+
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'
|
|
2
|
+
import { contentRoutingSymbol, TypedEventEmitter, setMaxListeners, peerDiscoverySymbol, peerRoutingSymbol, InvalidParametersError } from '@libp2p/interface'
|
|
3
3
|
import { defaultLogger } from '@libp2p/logger'
|
|
4
4
|
import { PeerSet } from '@libp2p/peer-collections'
|
|
5
5
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
6
|
-
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
7
6
|
import { PersistentPeerStore } from '@libp2p/peer-store'
|
|
8
7
|
import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
9
8
|
import { MemoryDatastore } from 'datastore-core/memory'
|
|
@@ -12,11 +11,9 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
|
12
11
|
import { DefaultAddressManager } from './address-manager/index.js'
|
|
13
12
|
import { checkServiceDependencies, defaultComponents } from './components.js'
|
|
14
13
|
import { connectionGater } from './config/connection-gater.js'
|
|
15
|
-
import { validateConfig } from './config.js'
|
|
16
14
|
import { DefaultConnectionManager } from './connection-manager/index.js'
|
|
17
15
|
import { ConnectionMonitor } from './connection-monitor.js'
|
|
18
16
|
import { CompoundContentRouting } from './content-routing.js'
|
|
19
|
-
import { codes } from './errors.js'
|
|
20
17
|
import { DefaultPeerRouting } from './peer-routing.js'
|
|
21
18
|
import { RandomWalk } from './random-walk.js'
|
|
22
19
|
import { DefaultRegistrar } from './registrar.js'
|
|
@@ -24,11 +21,11 @@ import { DefaultTransportManager } from './transport-manager.js'
|
|
|
24
21
|
import { DefaultUpgrader } from './upgrader.js'
|
|
25
22
|
import * as pkg from './version.js'
|
|
26
23
|
import type { Components } from './components.js'
|
|
27
|
-
import type { Libp2p, Libp2pInit
|
|
28
|
-
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions } from '@libp2p/interface'
|
|
24
|
+
import type { Libp2p as Libp2pInterface, Libp2pInit } from './index.js'
|
|
25
|
+
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey } from '@libp2p/interface'
|
|
29
26
|
import type { StreamHandler, StreamHandlerOptions } from '@libp2p/interface-internal'
|
|
30
27
|
|
|
31
|
-
export class
|
|
28
|
+
export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter<Libp2pEvents> implements Libp2pInterface<T> {
|
|
32
29
|
public peerId: PeerId
|
|
33
30
|
public peerStore: PeerStore
|
|
34
31
|
public contentRouting: ContentRouting
|
|
@@ -41,7 +38,7 @@ export class Libp2pNode<T extends ServiceMap = ServiceMap> extends TypedEventEmi
|
|
|
41
38
|
public components: Components & T
|
|
42
39
|
private readonly log: Logger
|
|
43
40
|
|
|
44
|
-
constructor (init: Libp2pInit<T> &
|
|
41
|
+
constructor (init: Libp2pInit<T> & { peerId: PeerId }) {
|
|
45
42
|
super()
|
|
46
43
|
|
|
47
44
|
this.status = 'stopped'
|
|
@@ -111,8 +108,8 @@ export class Libp2pNode<T extends ServiceMap = ServiceMap> extends TypedEventEmi
|
|
|
111
108
|
|
|
112
109
|
// Set up the Upgrader
|
|
113
110
|
this.components.upgrader = new DefaultUpgrader(this.components, {
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
connectionEncrypters: (init.connectionEncrypters ?? []).map((fn, index) => this.configureComponent(`connection-encryption-${index}`, fn(this.components))),
|
|
112
|
+
streamMuxers: (init.streamMuxers ?? []).map((fn, index) => this.configureComponent(`stream-muxers-${index}`, fn(this.components))),
|
|
116
113
|
inboundUpgradeTimeout: init.connectionManager?.inboundUpgradeTimeout
|
|
117
114
|
})
|
|
118
115
|
|
|
@@ -288,13 +285,13 @@ export class Libp2pNode<T extends ServiceMap = ServiceMap> extends TypedEventEmi
|
|
|
288
285
|
|
|
289
286
|
async dialProtocol (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options: NewStreamOptions = {}): Promise<Stream> {
|
|
290
287
|
if (protocols == null) {
|
|
291
|
-
throw new
|
|
288
|
+
throw new InvalidParametersError('no protocols were provided to open a stream')
|
|
292
289
|
}
|
|
293
290
|
|
|
294
291
|
protocols = Array.isArray(protocols) ? protocols : [protocols]
|
|
295
292
|
|
|
296
293
|
if (protocols.length === 0) {
|
|
297
|
-
throw new
|
|
294
|
+
throw new InvalidParametersError('no protocols were provided to open a stream')
|
|
298
295
|
}
|
|
299
296
|
|
|
300
297
|
const connection = await this.dial(peer, options)
|
|
@@ -321,7 +318,12 @@ export class Libp2pNode<T extends ServiceMap = ServiceMap> extends TypedEventEmi
|
|
|
321
318
|
/**
|
|
322
319
|
* Get the public key for the given peer id
|
|
323
320
|
*/
|
|
324
|
-
async getPublicKey (peer:
|
|
321
|
+
async getPublicKey (peer: Ed25519PeerId, options?: AbortOptions): Promise<Ed25519PublicKey>
|
|
322
|
+
async getPublicKey (peer: Secp256k1PeerId, options?: AbortOptions): Promise<Secp256k1PublicKey>
|
|
323
|
+
async getPublicKey (peer: RSAPeerId, options?: AbortOptions): Promise<RSAPublicKey>
|
|
324
|
+
async getPublicKey (peer: URLPeerId, options?: AbortOptions): Promise<never>
|
|
325
|
+
async getPublicKey (peer: PeerId, options?: AbortOptions): Promise<PublicKey>
|
|
326
|
+
async getPublicKey (peer: PeerId, options: AbortOptions = {}): Promise<PublicKey> {
|
|
325
327
|
this.log('getPublicKey %p', peer)
|
|
326
328
|
|
|
327
329
|
if (peer.publicKey != null) {
|
|
@@ -335,27 +337,27 @@ export class Libp2pNode<T extends ServiceMap = ServiceMap> extends TypedEventEmi
|
|
|
335
337
|
return peerInfo.id.publicKey
|
|
336
338
|
}
|
|
337
339
|
} catch (err: any) {
|
|
338
|
-
if (err.
|
|
340
|
+
if (err.name !== 'NotFoundError') {
|
|
339
341
|
throw err
|
|
340
342
|
}
|
|
341
343
|
}
|
|
342
344
|
|
|
343
345
|
const peerKey = uint8ArrayConcat([
|
|
344
346
|
uint8ArrayFromString('/pk/'),
|
|
345
|
-
peer.
|
|
347
|
+
peer.toMultihash().bytes
|
|
346
348
|
])
|
|
347
349
|
|
|
348
350
|
// search any available content routing methods
|
|
349
351
|
const bytes = await this.contentRouting.get(peerKey, options)
|
|
350
352
|
|
|
351
353
|
// ensure the returned key is valid
|
|
352
|
-
|
|
354
|
+
const publicKey = publicKeyFromProtobuf(bytes)
|
|
353
355
|
|
|
354
356
|
await this.peerStore.patch(peer, {
|
|
355
|
-
publicKey
|
|
357
|
+
publicKey
|
|
356
358
|
})
|
|
357
359
|
|
|
358
|
-
return
|
|
360
|
+
return publicKey
|
|
359
361
|
}
|
|
360
362
|
|
|
361
363
|
async handle (protocols: string | string[], handler: StreamHandler, options?: StreamHandlerOptions): Promise<void> {
|
|
@@ -402,7 +404,7 @@ export class Libp2pNode<T extends ServiceMap = ServiceMap> extends TypedEventEmi
|
|
|
402
404
|
const { detail: peer } = evt
|
|
403
405
|
|
|
404
406
|
if (peer.id.toString() === this.peerId.toString()) {
|
|
405
|
-
this.log.error(
|
|
407
|
+
this.log.error('peer discovery mechanism discovered self')
|
|
406
408
|
return
|
|
407
409
|
}
|
|
408
410
|
|
|
@@ -412,19 +414,3 @@ export class Libp2pNode<T extends ServiceMap = ServiceMap> extends TypedEventEmi
|
|
|
412
414
|
.catch(err => { this.log.error(err) })
|
|
413
415
|
}
|
|
414
416
|
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Returns a new Libp2pNode instance - this exposes more of the internals than the
|
|
418
|
-
* libp2p interface and is useful for testing and debugging.
|
|
419
|
-
*/
|
|
420
|
-
export async function createLibp2pNode <T extends ServiceMap = ServiceMap> (options: Libp2pOptions<T> = {}): Promise<Libp2pNode<T>> {
|
|
421
|
-
const peerId = options.peerId ??= await createEd25519PeerId()
|
|
422
|
-
|
|
423
|
-
if (peerId.privateKey == null) {
|
|
424
|
-
throw new CodeError('peer id was missing private key', 'ERR_MISSING_PRIVATE_KEY')
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
options.privateKey ??= await unmarshalPrivateKey(peerId.privateKey)
|
|
428
|
-
|
|
429
|
-
return new Libp2pNode(await validateConfig(options))
|
|
430
|
-
}
|
package/src/peer-routing.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NotFoundError } from '@libp2p/interface'
|
|
2
2
|
import { createScalableCuckooFilter } from '@libp2p/utils/filters'
|
|
3
3
|
import merge from 'it-merge'
|
|
4
4
|
import parallel from 'it-parallel'
|
|
5
|
-
import {
|
|
5
|
+
import { NoPeerRoutersError, QueriedForSelfError } from './errors.js'
|
|
6
6
|
import type { Logger, PeerId, PeerInfo, PeerRouting, PeerStore, RoutingOptions } from '@libp2p/interface'
|
|
7
7
|
import type { ComponentLogger } from '@libp2p/logger'
|
|
8
8
|
|
|
@@ -36,11 +36,11 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
36
36
|
*/
|
|
37
37
|
async findPeer (id: PeerId, options?: RoutingOptions): Promise<PeerInfo> {
|
|
38
38
|
if (this.routers.length === 0) {
|
|
39
|
-
throw new
|
|
39
|
+
throw new NoPeerRoutersError('No peer routers available')
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
if (id.toString() === this.peerId.toString()) {
|
|
43
|
-
throw new
|
|
43
|
+
throw new QueriedForSelfError('Should not try to find self')
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const self = this
|
|
@@ -69,7 +69,7 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
69
69
|
return peer
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
throw new
|
|
72
|
+
throw new NotFoundError()
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
@@ -77,7 +77,7 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
77
77
|
*/
|
|
78
78
|
async * getClosestPeers (key: Uint8Array, options: RoutingOptions = {}): AsyncIterable<PeerInfo> {
|
|
79
79
|
if (this.routers.length === 0) {
|
|
80
|
-
throw new
|
|
80
|
+
throw new NoPeerRoutersError('No peer routers available')
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const self = this
|
|
@@ -121,11 +121,11 @@ export class DefaultPeerRouting implements PeerRouting {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// deduplicate peers
|
|
124
|
-
if (seen.has(peer.id.
|
|
124
|
+
if (seen.has(peer.id.toMultihash().bytes)) {
|
|
125
125
|
continue
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
seen.add(peer.id.
|
|
128
|
+
seen.add(peer.id.toMultihash().bytes)
|
|
129
129
|
|
|
130
130
|
yield peer
|
|
131
131
|
}
|
package/src/registrar.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InvalidParametersError } from '@libp2p/interface'
|
|
2
2
|
import merge from 'merge-options'
|
|
3
|
-
import
|
|
3
|
+
import * as errorsJs from './errors.js'
|
|
4
4
|
import type { IdentifyResult, Libp2pEvents, Logger, PeerUpdate, TypedEventTarget, PeerId, PeerStore, Topology } from '@libp2p/interface'
|
|
5
5
|
import type { ConnectionManager, StreamHandlerOptions, StreamHandlerRecord, Registrar, StreamHandler } from '@libp2p/interface-internal'
|
|
6
6
|
import type { ComponentLogger } from '@libp2p/logger'
|
|
@@ -52,7 +52,7 @@ export class DefaultRegistrar implements Registrar {
|
|
|
52
52
|
const handler = this.handlers.get(protocol)
|
|
53
53
|
|
|
54
54
|
if (handler == null) {
|
|
55
|
-
throw new
|
|
55
|
+
throw new errorsJs.UnhandledProtocolError(`No handler registered for protocol ${protocol}`)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
return handler
|
|
@@ -75,7 +75,7 @@ export class DefaultRegistrar implements Registrar {
|
|
|
75
75
|
*/
|
|
76
76
|
async handle (protocol: string, handler: StreamHandler, opts?: StreamHandlerOptions): Promise<void> {
|
|
77
77
|
if (this.handlers.has(protocol)) {
|
|
78
|
-
throw new
|
|
78
|
+
throw new errorsJs.DuplicateProtocolHandlerError(`Handler already registered for protocol ${protocol}`)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
const options = merge.bind({ ignoreUndefined: true })({
|
|
@@ -116,7 +116,7 @@ export class DefaultRegistrar implements Registrar {
|
|
|
116
116
|
*/
|
|
117
117
|
async register (protocol: string, topology: Topology): Promise<string> {
|
|
118
118
|
if (topology == null) {
|
|
119
|
-
throw new
|
|
119
|
+
throw new InvalidParametersError('invalid topology')
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
// Create topology
|
|
@@ -176,7 +176,7 @@ export class DefaultRegistrar implements Registrar {
|
|
|
176
176
|
}
|
|
177
177
|
})
|
|
178
178
|
.catch(err => {
|
|
179
|
-
if (err.
|
|
179
|
+
if (err.name === 'NotFoundError') {
|
|
180
180
|
// peer has not completed identify so they are not in the peer store
|
|
181
181
|
return
|
|
182
182
|
}
|
|
@@ -230,7 +230,7 @@ export class DefaultRegistrar implements Registrar {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
for (const topology of topologies.values()) {
|
|
233
|
-
if (connection.
|
|
233
|
+
if (connection.limits != null && topology.notifyOnLimitedConnection !== true) {
|
|
234
234
|
continue
|
|
235
235
|
}
|
|
236
236
|
|
package/src/transport-manager.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FaultTolerance, InvalidParametersError, NotStartedError } from '@libp2p/interface'
|
|
2
2
|
import { trackedMap } from '@libp2p/utils/tracked-map'
|
|
3
3
|
import { CustomProgressEvent } from 'progress-events'
|
|
4
|
-
import {
|
|
4
|
+
import { NoValidAddressesError, TransportUnavailableError } from './errors.js'
|
|
5
5
|
import type { Libp2pEvents, ComponentLogger, Logger, Connection, TypedEventTarget, Metrics, Startable, Listener, Transport, Upgrader } from '@libp2p/interface'
|
|
6
6
|
import type { AddressManager, TransportManager, TransportManagerDialOptions } from '@libp2p/interface-internal'
|
|
7
7
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
@@ -47,11 +47,11 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
47
47
|
const tag = transport[Symbol.toStringTag]
|
|
48
48
|
|
|
49
49
|
if (tag == null) {
|
|
50
|
-
throw new
|
|
50
|
+
throw new InvalidParametersError('Transport must have a valid tag')
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (this.transports.has(tag)) {
|
|
54
|
-
throw new
|
|
54
|
+
throw new InvalidParametersError(`There is already a transport with the tag ${tag}`)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
this.log('adding transport %s', tag)
|
|
@@ -112,26 +112,18 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
112
112
|
const transport = this.dialTransportForMultiaddr(ma)
|
|
113
113
|
|
|
114
114
|
if (transport == null) {
|
|
115
|
-
throw new
|
|
115
|
+
throw new TransportUnavailableError(`No transport available for address ${String(ma)}`)
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
options?.onProgress?.(new CustomProgressEvent<string>('transport-manager:selected-transport', transport[Symbol.toStringTag]))
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
})
|
|
128
|
-
} catch (err: any) {
|
|
129
|
-
if (err.code == null) {
|
|
130
|
-
err.code = codes.ERR_TRANSPORT_DIAL_FAILED
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
throw err
|
|
134
|
-
}
|
|
120
|
+
// @ts-expect-error the transport has a typed onProgress option but we
|
|
121
|
+
// can't predict what transport implementation we selected so all we can
|
|
122
|
+
// do is pass the onProgress handler in and hope for the best
|
|
123
|
+
return transport.dial(ma, {
|
|
124
|
+
...options,
|
|
125
|
+
upgrader: this.components.upgrader
|
|
126
|
+
})
|
|
135
127
|
}
|
|
136
128
|
|
|
137
129
|
/**
|
|
@@ -192,7 +184,7 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
192
184
|
*/
|
|
193
185
|
async listen (addrs: Multiaddr[]): Promise<void> {
|
|
194
186
|
if (!this.isStarted()) {
|
|
195
|
-
throw new
|
|
187
|
+
throw new NotStartedError('Not started')
|
|
196
188
|
}
|
|
197
189
|
|
|
198
190
|
if (addrs == null || addrs.length === 0) {
|
|
@@ -256,7 +248,7 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
256
248
|
// just wait for any (`p-any`) listener to succeed on each transport before returning
|
|
257
249
|
const isListening = results.find(r => r.status === 'fulfilled')
|
|
258
250
|
if ((isListening == null) && this.faultTolerance !== FaultTolerance.NO_FATAL) {
|
|
259
|
-
throw new
|
|
251
|
+
throw new NoValidAddressesError(`Transport (${key}) could not listen on any available address`)
|
|
260
252
|
}
|
|
261
253
|
}
|
|
262
254
|
|
|
@@ -265,7 +257,7 @@ export class DefaultTransportManager implements TransportManager, Startable {
|
|
|
265
257
|
if (couldNotListen.length === this.transports.size) {
|
|
266
258
|
const message = `no valid addresses were provided for transports [${couldNotListen.join(', ')}]`
|
|
267
259
|
if (this.faultTolerance === FaultTolerance.FATAL_ALL) {
|
|
268
|
-
throw new
|
|
260
|
+
throw new NoValidAddressesError(message)
|
|
269
261
|
}
|
|
270
262
|
this.log(`libp2p in dial mode only: ${message}`)
|
|
271
263
|
}
|