libp2p 0.43.4 → 0.44.0-17eb162a
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 +4 -6
- 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 +8 -6
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +10 -10
- package/dist/src/components.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -9
- 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 +131 -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 +374 -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 +116 -248
- 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.js +1 -1
- 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.js +3 -3
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/index.d.ts +4 -0
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +104 -128
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +2 -19
- 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 +5 -3
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +47 -50
- package/dist/src/libp2p.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 +25 -23
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +9 -3
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +23 -9
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +14 -11
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +14 -10
- package/dist/src/upgrader.js.map +1 -1
- package/package.json +46 -45
- package/src/address-manager/index.ts +12 -8
- package/src/autonat/index.ts +6 -9
- 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 +19 -17
- package/src/config.ts +0 -9
- package/src/connection-manager/auto-dial.ts +183 -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 +512 -0
- package/src/connection-manager/index.ts +191 -340
- package/src/connection-manager/utils.ts +76 -0
- package/src/content-routing/index.ts +1 -1
- package/src/content-routing/utils.ts +3 -1
- package/src/fetch/index.ts +4 -4
- package/src/identify/index.ts +100 -140
- package/src/index.ts +2 -20
- package/src/insecure/index.ts +9 -5
- package/src/libp2p.ts +54 -60
- package/src/registrar.ts +29 -25
- package/src/transport-manager.ts +31 -11
- package/src/upgrader.ts +31 -22
- 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/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/peer-record-updater.ts +0 -65
package/src/libp2p.ts
CHANGED
|
@@ -9,7 +9,6 @@ import { CompoundContentRouting } from './content-routing/index.js'
|
|
|
9
9
|
import { codes } from './errors.js'
|
|
10
10
|
import { DefaultAddressManager } from './address-manager/index.js'
|
|
11
11
|
import { DefaultConnectionManager } from './connection-manager/index.js'
|
|
12
|
-
import { AutoDialler } from './connection-manager/auto-dialler.js'
|
|
13
12
|
import { DefaultKeyChain } from '@libp2p/keychain'
|
|
14
13
|
import { DefaultTransportManager } from './transport-manager.js'
|
|
15
14
|
import { DefaultUpgrader } from './upgrader.js'
|
|
@@ -18,7 +17,6 @@ import { IdentifyService } from './identify/index.js'
|
|
|
18
17
|
import { FetchService } from './fetch/index.js'
|
|
19
18
|
import { PingService } from './ping/index.js'
|
|
20
19
|
import { NatManager } from './nat-manager.js'
|
|
21
|
-
import { PeerRecordUpdater } from './peer-record-updater.js'
|
|
22
20
|
import { DHTPeerRouting } from './dht/dht-peer-routing.js'
|
|
23
21
|
import { PersistentPeerStore } from '@libp2p/peer-store'
|
|
24
22
|
import { DHTContentRouting } from './dht/dht-content-routing.js'
|
|
@@ -33,7 +31,7 @@ import type { PubSub } from '@libp2p/interface-pubsub'
|
|
|
33
31
|
import type { Registrar, StreamHandler, StreamHandlerOptions, Topology } from '@libp2p/interface-registrar'
|
|
34
32
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
35
33
|
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
36
|
-
import type { Libp2p,
|
|
34
|
+
import type { Libp2p, Libp2pInit, Libp2pOptions } from './index.js'
|
|
37
35
|
import { validateConfig } from './config.js'
|
|
38
36
|
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
39
37
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
@@ -41,17 +39,17 @@ import type { DualDHT } from '@libp2p/interface-dht'
|
|
|
41
39
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
42
40
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
43
41
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
44
|
-
import { unmarshalPublicKey } from '@libp2p/crypto/keys'
|
|
45
42
|
import type { Metrics } from '@libp2p/interface-metrics'
|
|
46
43
|
import { DummyDHT } from './dht/dummy-dht.js'
|
|
47
44
|
import { DummyPubSub } from './pubsub/dummy-pubsub.js'
|
|
48
45
|
import { PeerSet } from '@libp2p/peer-collections'
|
|
49
|
-
import { DefaultDialer } from './connection-manager/dialer/index.js'
|
|
50
46
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
51
47
|
import type { Datastore } from 'interface-datastore'
|
|
52
48
|
import type { KeyChain } from '@libp2p/interface-keychain'
|
|
53
49
|
import mergeOptions from 'merge-options'
|
|
54
50
|
import type { CircuitRelayService } from './circuit-relay/index.js'
|
|
51
|
+
import type { Libp2pEvents, PendingDial } from '@libp2p/interface-libp2p'
|
|
52
|
+
import { setMaxListeners } from 'events'
|
|
55
53
|
|
|
56
54
|
const log = logger('libp2p')
|
|
57
55
|
|
|
@@ -79,10 +77,29 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
79
77
|
constructor (init: Libp2pInit) {
|
|
80
78
|
super()
|
|
81
79
|
|
|
80
|
+
// event bus - components can listen to this emitter to be notified of system events
|
|
81
|
+
// and also cause them to be emitted
|
|
82
|
+
const events = new EventEmitter<Libp2pEvents>()
|
|
83
|
+
const originalDispatch = events.dispatchEvent.bind(events)
|
|
84
|
+
events.dispatchEvent = (evt: any) => {
|
|
85
|
+
const internalResult = originalDispatch(evt)
|
|
86
|
+
const externalResult = this.dispatchEvent(
|
|
87
|
+
new CustomEvent(evt.type, { detail: evt.detail })
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
return internalResult || externalResult
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
// This emitter gets listened to a lot
|
|
95
|
+
setMaxListeners?.(Infinity, events)
|
|
96
|
+
} catch {}
|
|
97
|
+
|
|
82
98
|
this.started = false
|
|
83
99
|
this.peerId = init.peerId
|
|
84
100
|
const components = this.components = new DefaultComponents({
|
|
85
101
|
peerId: init.peerId,
|
|
102
|
+
events,
|
|
86
103
|
datastore: init.datastore ?? new MemoryDatastore(),
|
|
87
104
|
connectionGater: {
|
|
88
105
|
denyDialPeer: async () => await Promise.resolve(false),
|
|
@@ -113,10 +130,11 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
113
130
|
|
|
114
131
|
this.peerStore = this.components.peerStore
|
|
115
132
|
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
133
|
+
this.components.events.addEventListener('peer:update', evt => {
|
|
134
|
+
// if there was no peer previously in the peer store this is a new peer
|
|
135
|
+
if (evt.detail.previous == null) {
|
|
136
|
+
this.safeDispatchEvent('peer:discovery', { detail: evt.detail.peer })
|
|
137
|
+
}
|
|
120
138
|
})
|
|
121
139
|
|
|
122
140
|
// Set up connection protector if configured
|
|
@@ -131,32 +149,18 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
131
149
|
inboundUpgradeTimeout: init.connectionManager.inboundUpgradeTimeout
|
|
132
150
|
})
|
|
133
151
|
|
|
134
|
-
//
|
|
135
|
-
this.components.
|
|
152
|
+
// Setup the transport manager
|
|
153
|
+
this.components.transportManager = new DefaultTransportManager(this.components, init.transportManager)
|
|
136
154
|
|
|
137
155
|
// Create the Connection Manager
|
|
138
156
|
this.connectionManager = this.components.connectionManager = new DefaultConnectionManager(this.components, init.connectionManager)
|
|
139
157
|
|
|
140
|
-
// forward connection manager events
|
|
141
|
-
this.components.connectionManager.addEventListener('peer:disconnect', (event) => {
|
|
142
|
-
this.dispatchEvent(new CustomEvent<Connection>('peer:disconnect', { detail: event.detail }))
|
|
143
|
-
})
|
|
144
|
-
this.components.connectionManager.addEventListener('peer:connect', (event) => {
|
|
145
|
-
this.dispatchEvent(new CustomEvent<Connection>('peer:connect', { detail: event.detail }))
|
|
146
|
-
})
|
|
147
|
-
|
|
148
158
|
// Create the Registrar
|
|
149
159
|
this.registrar = this.components.registrar = new DefaultRegistrar(this.components)
|
|
150
160
|
|
|
151
|
-
// Setup the transport manager
|
|
152
|
-
this.components.transportManager = new DefaultTransportManager(this.components, init.transportManager)
|
|
153
|
-
|
|
154
161
|
// Addresses {listen, announce, noAnnounce}
|
|
155
162
|
this.components.addressManager = new DefaultAddressManager(this.components, init.addresses)
|
|
156
163
|
|
|
157
|
-
// update our peer record when addresses change
|
|
158
|
-
this.configureComponent(new PeerRecordUpdater(this.components))
|
|
159
|
-
|
|
160
164
|
// Create keychain
|
|
161
165
|
const keychainOpts = DefaultKeyChain.generateOptions()
|
|
162
166
|
this.keychain = this.configureComponent(new DefaultKeyChain(this.components, {
|
|
@@ -230,11 +234,6 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
230
234
|
...init.autonat
|
|
231
235
|
}))
|
|
232
236
|
|
|
233
|
-
this.configureComponent(new AutoDialler(this.components, {
|
|
234
|
-
minConnections: init.connectionManager.minConnections,
|
|
235
|
-
autoDialInterval: init.connectionManager.autoDialInterval
|
|
236
|
-
}))
|
|
237
|
-
|
|
238
237
|
if (init.relay != null) {
|
|
239
238
|
this.circuitService = this.configureComponent(init.relay(this.components))
|
|
240
239
|
}
|
|
@@ -354,6 +353,10 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
354
353
|
return this.components.connectionManager.getConnections(peerId)
|
|
355
354
|
}
|
|
356
355
|
|
|
356
|
+
getDialQueue (): PendingDial[] {
|
|
357
|
+
return this.components.connectionManager.getDialQueue()
|
|
358
|
+
}
|
|
359
|
+
|
|
357
360
|
getPeers (): PeerId[] {
|
|
358
361
|
const peerSet = new PeerSet()
|
|
359
362
|
|
|
@@ -365,7 +368,6 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
365
368
|
}
|
|
366
369
|
|
|
367
370
|
async dial (peer: PeerId | Multiaddr | Multiaddr[], options: AbortOptions = {}): Promise<Connection> {
|
|
368
|
-
// @ts-expect-error
|
|
369
371
|
return await this.components.connectionManager.openConnection(peer, options)
|
|
370
372
|
}
|
|
371
373
|
|
|
@@ -413,12 +415,8 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
413
415
|
|
|
414
416
|
const peerInfo = await this.peerStore.get(peer)
|
|
415
417
|
|
|
416
|
-
if (peerInfo.
|
|
417
|
-
return peerInfo.
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (this.dht == null) {
|
|
421
|
-
throw new CodeError('Public key was not in the peer store and the DHT is not enabled', codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
418
|
+
if (peerInfo.id.publicKey != null) {
|
|
419
|
+
return peerInfo.id.publicKey
|
|
422
420
|
}
|
|
423
421
|
|
|
424
422
|
const peerKey = uint8ArrayConcat([
|
|
@@ -426,24 +424,22 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
426
424
|
peer.multihash.digest
|
|
427
425
|
])
|
|
428
426
|
|
|
429
|
-
// search
|
|
430
|
-
|
|
431
|
-
if (event.name === 'VALUE') {
|
|
432
|
-
const key = unmarshalPublicKey(event.value)
|
|
433
|
-
|
|
434
|
-
await this.peerStore.keyBook.set(peer, event.value)
|
|
427
|
+
// search any available content routing methods
|
|
428
|
+
const bytes = await this.contentRouting.get(peerKey, options)
|
|
435
429
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
430
|
+
await this.peerStore.patch(peer, {
|
|
431
|
+
publicKey: bytes
|
|
432
|
+
})
|
|
439
433
|
|
|
440
|
-
|
|
434
|
+
return bytes
|
|
441
435
|
}
|
|
442
436
|
|
|
443
437
|
async fetch (peer: PeerId | Multiaddr, key: string, options: AbortOptions = {}): Promise<Uint8Array | null> {
|
|
444
438
|
if (isMultiaddr(peer)) {
|
|
445
439
|
const peerId = peerIdFromString(peer.getPeerId() ?? '')
|
|
446
|
-
await this.components.peerStore.
|
|
440
|
+
await this.components.peerStore.merge(peerId, {
|
|
441
|
+
multiaddrs: [peer]
|
|
442
|
+
})
|
|
447
443
|
peer = peerId
|
|
448
444
|
}
|
|
449
445
|
|
|
@@ -453,7 +449,9 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
453
449
|
async ping (peer: PeerId | Multiaddr, options: AbortOptions = {}): Promise<number> {
|
|
454
450
|
if (isMultiaddr(peer)) {
|
|
455
451
|
const peerId = peerIdFromString(peer.getPeerId() ?? '')
|
|
456
|
-
await this.components.peerStore.
|
|
452
|
+
await this.components.peerStore.merge(peerId, {
|
|
453
|
+
multiaddrs: [peer]
|
|
454
|
+
})
|
|
457
455
|
peer = peerId
|
|
458
456
|
}
|
|
459
457
|
|
|
@@ -493,8 +491,8 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
493
491
|
}
|
|
494
492
|
|
|
495
493
|
/**
|
|
496
|
-
* Called whenever peer discovery services emit `peer` events
|
|
497
|
-
*
|
|
494
|
+
* Called whenever peer discovery services emit `peer` events and adds peers
|
|
495
|
+
* to the peer store.
|
|
498
496
|
*/
|
|
499
497
|
onDiscoveryPeer (evt: CustomEvent<PeerInfo>): void {
|
|
500
498
|
const { detail: peer } = evt
|
|
@@ -504,15 +502,11 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
|
|
504
502
|
return
|
|
505
503
|
}
|
|
506
504
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
void this.components.peerStore.protoBook.set(peer.id, peer.protocols).catch(err => { log.error(err) })
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
this.dispatchEvent(new CustomEvent<PeerInfo>('peer:discovery', { detail: peer }))
|
|
505
|
+
void this.components.peerStore.merge(peer.id, {
|
|
506
|
+
multiaddrs: peer.multiaddrs,
|
|
507
|
+
protocols: peer.protocols
|
|
508
|
+
})
|
|
509
|
+
.catch(err => { log.error(err) })
|
|
516
510
|
}
|
|
517
511
|
}
|
|
518
512
|
|
package/src/registrar.ts
CHANGED
|
@@ -4,10 +4,12 @@ import { codes } from './errors.js'
|
|
|
4
4
|
import { isTopology, StreamHandlerOptions, StreamHandlerRecord } from '@libp2p/interface-registrar'
|
|
5
5
|
import merge from 'merge-options'
|
|
6
6
|
import type { Registrar, StreamHandler, Topology } from '@libp2p/interface-registrar'
|
|
7
|
-
import type {
|
|
7
|
+
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
8
8
|
import type { Connection } from '@libp2p/interface-connection'
|
|
9
9
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
10
10
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
|
+
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
12
|
+
import type { Libp2pEvents, PeerUpdate } from '@libp2p/interface-libp2p'
|
|
11
13
|
|
|
12
14
|
const log = logger('libp2p:registrar')
|
|
13
15
|
|
|
@@ -18,6 +20,7 @@ export interface RegistrarComponents {
|
|
|
18
20
|
peerId: PeerId
|
|
19
21
|
connectionManager: ConnectionManager
|
|
20
22
|
peerStore: PeerStore
|
|
23
|
+
events: EventEmitter<Libp2pEvents>
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
/**
|
|
@@ -34,19 +37,16 @@ export class DefaultRegistrar implements Registrar {
|
|
|
34
37
|
this.components = components
|
|
35
38
|
|
|
36
39
|
this._onDisconnect = this._onDisconnect.bind(this)
|
|
37
|
-
this.
|
|
40
|
+
this._onPeerUpdate = this._onPeerUpdate.bind(this)
|
|
38
41
|
this._onConnect = this._onConnect.bind(this)
|
|
39
42
|
|
|
40
|
-
this.components.
|
|
41
|
-
this.components.
|
|
42
|
-
|
|
43
|
-
// happens after identify
|
|
44
|
-
this.components.peerStore.addEventListener('change:protocols', this._onProtocolChange)
|
|
43
|
+
this.components.events.addEventListener('connection:close', this._onDisconnect)
|
|
44
|
+
this.components.events.addEventListener('connection:open', this._onConnect)
|
|
45
|
+
this.components.events.addEventListener('peer:update', this._onPeerUpdate)
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
getProtocols (): string[] {
|
|
48
49
|
return Array.from(new Set<string>([
|
|
49
|
-
...this.topologies.keys(),
|
|
50
50
|
...this.handlers.keys()
|
|
51
51
|
])).sort()
|
|
52
52
|
}
|
|
@@ -91,8 +91,10 @@ export class DefaultRegistrar implements Registrar {
|
|
|
91
91
|
options
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
// Add new
|
|
95
|
-
await this.components.peerStore.
|
|
94
|
+
// Add new protocol to self protocols in the peer store
|
|
95
|
+
await this.components.peerStore.merge(this.components.peerId, {
|
|
96
|
+
protocols: [protocol]
|
|
97
|
+
})
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
/**
|
|
@@ -106,8 +108,10 @@ export class DefaultRegistrar implements Registrar {
|
|
|
106
108
|
this.handlers.delete(protocol)
|
|
107
109
|
})
|
|
108
110
|
|
|
109
|
-
//
|
|
110
|
-
await this.components.peerStore.
|
|
111
|
+
// Update self protocols in the peer store
|
|
112
|
+
await this.components.peerStore.patch(this.components.peerId, {
|
|
113
|
+
protocols: protocolList
|
|
114
|
+
})
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
/**
|
|
@@ -158,9 +162,9 @@ export class DefaultRegistrar implements Registrar {
|
|
|
158
162
|
_onDisconnect (evt: CustomEvent<Connection>): void {
|
|
159
163
|
const connection = evt.detail
|
|
160
164
|
|
|
161
|
-
void this.components.peerStore.
|
|
162
|
-
.then(
|
|
163
|
-
for (const protocol of
|
|
165
|
+
void this.components.peerStore.get(connection.remotePeer)
|
|
166
|
+
.then(peer => {
|
|
167
|
+
for (const protocol of peer.protocols) {
|
|
164
168
|
const topologies = this.topologies.get(protocol)
|
|
165
169
|
|
|
166
170
|
if (topologies == null) {
|
|
@@ -185,9 +189,9 @@ export class DefaultRegistrar implements Registrar {
|
|
|
185
189
|
_onConnect (evt: CustomEvent<Connection>): void {
|
|
186
190
|
const connection = evt.detail
|
|
187
191
|
|
|
188
|
-
void this.components.peerStore.
|
|
189
|
-
.then(
|
|
190
|
-
for (const protocol of
|
|
192
|
+
void this.components.peerStore.get(connection.remotePeer)
|
|
193
|
+
.then(peer => {
|
|
194
|
+
for (const protocol of peer.protocols) {
|
|
191
195
|
const topologies = this.topologies.get(protocol)
|
|
192
196
|
|
|
193
197
|
if (topologies == null) {
|
|
@@ -208,10 +212,10 @@ export class DefaultRegistrar implements Registrar {
|
|
|
208
212
|
/**
|
|
209
213
|
* Check if a new peer support the multicodecs for this topology
|
|
210
214
|
*/
|
|
211
|
-
|
|
212
|
-
const {
|
|
213
|
-
const removed =
|
|
214
|
-
const added = protocols.filter(protocol => !
|
|
215
|
+
_onPeerUpdate (evt: CustomEvent<PeerUpdate>): void {
|
|
216
|
+
const { peer, previous } = evt.detail
|
|
217
|
+
const removed = (previous?.protocols ?? []).filter(protocol => !peer.protocols.includes(protocol))
|
|
218
|
+
const added = peer.protocols.filter(protocol => !(previous?.protocols ?? []).includes(protocol))
|
|
215
219
|
|
|
216
220
|
for (const protocol of removed) {
|
|
217
221
|
const topologies = this.topologies.get(protocol)
|
|
@@ -222,7 +226,7 @@ export class DefaultRegistrar implements Registrar {
|
|
|
222
226
|
}
|
|
223
227
|
|
|
224
228
|
for (const topology of topologies.values()) {
|
|
225
|
-
topology.onDisconnect(
|
|
229
|
+
topology.onDisconnect(peer.id)
|
|
226
230
|
}
|
|
227
231
|
}
|
|
228
232
|
|
|
@@ -235,12 +239,12 @@ export class DefaultRegistrar implements Registrar {
|
|
|
235
239
|
}
|
|
236
240
|
|
|
237
241
|
for (const topology of topologies.values()) {
|
|
238
|
-
const connection = this.components.connectionManager.getConnections(
|
|
242
|
+
const connection = this.components.connectionManager.getConnections(peer.id)[0]
|
|
239
243
|
|
|
240
244
|
if (connection == null) {
|
|
241
245
|
continue
|
|
242
246
|
}
|
|
243
|
-
topology.onConnect(
|
|
247
|
+
topology.onConnect(peer.id, connection)
|
|
244
248
|
}
|
|
245
249
|
}
|
|
246
250
|
}
|
package/src/transport-manager.ts
CHANGED
|
@@ -2,15 +2,18 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import { codes } from './errors.js'
|
|
3
3
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
4
4
|
import { FaultTolerance } from '@libp2p/interface-transport'
|
|
5
|
-
import type { Listener, Transport, TransportManager,
|
|
5
|
+
import type { Listener, Transport, TransportManager, Upgrader } from '@libp2p/interface-transport'
|
|
6
6
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
7
7
|
import type { Connection } from '@libp2p/interface-connection'
|
|
8
8
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
9
|
-
import {
|
|
9
|
+
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
10
10
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
11
11
|
import { trackedMap } from '@libp2p/tracked-map'
|
|
12
12
|
import type { Metrics } from '@libp2p/interface-metrics'
|
|
13
13
|
import type { AddressManager } from '@libp2p/interface-address-manager'
|
|
14
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
|
|
15
|
+
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
16
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
14
17
|
|
|
15
18
|
const log = logger('libp2p:transports')
|
|
16
19
|
|
|
@@ -22,9 +25,12 @@ export interface DefaultTransportManagerComponents {
|
|
|
22
25
|
metrics?: Metrics
|
|
23
26
|
addressManager: AddressManager
|
|
24
27
|
upgrader: Upgrader
|
|
28
|
+
events: EventEmitter<Libp2pEvents>
|
|
29
|
+
peerId: PeerId
|
|
30
|
+
peerStore: PeerStore
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
export class DefaultTransportManager
|
|
33
|
+
export class DefaultTransportManager implements TransportManager, Startable {
|
|
28
34
|
private readonly components: DefaultTransportManagerComponents
|
|
29
35
|
private readonly transports: Map<string, Transport>
|
|
30
36
|
private readonly listeners: Map<string, Listener[]>
|
|
@@ -32,8 +38,6 @@ export class DefaultTransportManager extends EventEmitter<TransportManagerEvents
|
|
|
32
38
|
private started: boolean
|
|
33
39
|
|
|
34
40
|
constructor (components: DefaultTransportManagerComponents, init: TransportManagerInit = {}) {
|
|
35
|
-
super()
|
|
36
|
-
|
|
37
41
|
this.components = components
|
|
38
42
|
this.started = false
|
|
39
43
|
this.transports = new Map<string, Transport>()
|
|
@@ -197,14 +201,30 @@ export class DefaultTransportManager extends EventEmitter<TransportManagerEvents
|
|
|
197
201
|
|
|
198
202
|
// Track listen/close events
|
|
199
203
|
listener.addEventListener('listening', () => {
|
|
200
|
-
this.
|
|
201
|
-
|
|
202
|
-
})
|
|
204
|
+
this.components.peerStore.patch(this.components.peerId, {
|
|
205
|
+
multiaddrs: this.getAddrs()
|
|
206
|
+
})
|
|
207
|
+
.then(() => {
|
|
208
|
+
this.components.events.safeDispatchEvent('transport:listening', {
|
|
209
|
+
detail: listener
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
.catch(err => {
|
|
213
|
+
log.error('error while updating peer record after listener began listening', err)
|
|
214
|
+
})
|
|
203
215
|
})
|
|
204
216
|
listener.addEventListener('close', () => {
|
|
205
|
-
this.
|
|
206
|
-
|
|
207
|
-
})
|
|
217
|
+
this.components.peerStore.patch(this.components.peerId, {
|
|
218
|
+
multiaddrs: this.getAddrs()
|
|
219
|
+
})
|
|
220
|
+
.then(() => {
|
|
221
|
+
this.components.events.safeDispatchEvent('transport:close', {
|
|
222
|
+
detail: listener
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
.catch(err => {
|
|
226
|
+
log.error('error while updating peer record after listener stopped listening', err)
|
|
227
|
+
})
|
|
208
228
|
})
|
|
209
229
|
|
|
210
230
|
// We need to attempt to listen on everything
|
package/src/upgrader.ts
CHANGED
|
@@ -3,14 +3,14 @@ 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'
|
|
@@ -21,14 +21,16 @@ import type { Metrics } from '@libp2p/interface-metrics'
|
|
|
21
21
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
22
22
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
23
23
|
import type { ConnectionGater } from '@libp2p/interface-connection-gater'
|
|
24
|
+
import { INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
|
|
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,17 @@ export interface DefaultUpgraderComponents {
|
|
|
102
104
|
connectionProtector?: ConnectionProtector
|
|
103
105
|
registrar: Registrar
|
|
104
106
|
peerStore: PeerStore
|
|
107
|
+
events: EventEmitter<Libp2pEvents>
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
export class DefaultUpgrader
|
|
110
|
+
export class DefaultUpgrader implements Upgrader {
|
|
108
111
|
private readonly components: DefaultUpgraderComponents
|
|
109
112
|
private readonly connectionEncryption: Map<string, ConnectionEncrypter>
|
|
110
113
|
private readonly muxers: Map<string, StreamMuxerFactory>
|
|
111
114
|
private readonly inboundUpgradeTimeout: number
|
|
115
|
+
private readonly events: EventEmitter<Libp2pEvents>
|
|
112
116
|
|
|
113
117
|
constructor (components: DefaultUpgraderComponents, init: UpgraderInit) {
|
|
114
|
-
super()
|
|
115
|
-
|
|
116
118
|
this.components = components
|
|
117
119
|
this.connectionEncryption = new Map()
|
|
118
120
|
|
|
@@ -126,7 +128,8 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
126
128
|
this.muxers.set(muxer.protocol, muxer)
|
|
127
129
|
})
|
|
128
130
|
|
|
129
|
-
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout
|
|
131
|
+
this.inboundUpgradeTimeout = init.inboundUpgradeTimeout ?? INBOUND_UPGRADE_TIMEOUT
|
|
132
|
+
this.events = components.events
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
/**
|
|
@@ -141,7 +144,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
141
144
|
|
|
142
145
|
let encryptedConn
|
|
143
146
|
let remotePeer
|
|
144
|
-
let upgradedConn: Duplex<Uint8Array
|
|
147
|
+
let upgradedConn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>
|
|
145
148
|
let muxerFactory: StreamMuxerFactory | undefined
|
|
146
149
|
let cryptoProtocol
|
|
147
150
|
|
|
@@ -263,7 +266,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
263
266
|
|
|
264
267
|
let encryptedConn
|
|
265
268
|
let remotePeer: PeerId
|
|
266
|
-
let upgradedConn
|
|
269
|
+
let upgradedConn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>
|
|
267
270
|
let cryptoProtocol
|
|
268
271
|
let muxerFactory
|
|
269
272
|
|
|
@@ -349,7 +352,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
349
352
|
/**
|
|
350
353
|
* A convenience method for generating a new `Connection`
|
|
351
354
|
*/
|
|
352
|
-
_createConnection (opts:
|
|
355
|
+
_createConnection (opts: CreateConnectionOptions): Connection {
|
|
353
356
|
const {
|
|
354
357
|
cryptoProtocol,
|
|
355
358
|
direction,
|
|
@@ -400,7 +403,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
400
403
|
|
|
401
404
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
402
405
|
// the peerstore should ensure that the peer is registered with that protocol
|
|
403
|
-
this.components.peerStore.
|
|
406
|
+
await this.components.peerStore.merge(remotePeer, {
|
|
407
|
+
protocols: [protocol]
|
|
408
|
+
})
|
|
404
409
|
|
|
405
410
|
connection.addStream(muxedStream)
|
|
406
411
|
this.components.metrics?.trackProtocolStream(muxedStream, connection)
|
|
@@ -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
|
|
@@ -509,9 +516,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
509
516
|
} catch (err: any) {
|
|
510
517
|
log.error(err)
|
|
511
518
|
} finally {
|
|
512
|
-
this.
|
|
519
|
+
this.events.safeDispatchEvent('connection:close', {
|
|
513
520
|
detail: connection
|
|
514
|
-
})
|
|
521
|
+
})
|
|
515
522
|
}
|
|
516
523
|
})().catch(err => {
|
|
517
524
|
log.error(err)
|
|
@@ -549,9 +556,9 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
549
556
|
}
|
|
550
557
|
})
|
|
551
558
|
|
|
552
|
-
this.
|
|
559
|
+
this.events.safeDispatchEvent('connection:open', {
|
|
553
560
|
detail: connection
|
|
554
|
-
})
|
|
561
|
+
})
|
|
555
562
|
|
|
556
563
|
return connection
|
|
557
564
|
}
|
|
@@ -569,7 +576,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
569
576
|
/**
|
|
570
577
|
* Attempts to encrypt the incoming `connection` with the provided `cryptos`
|
|
571
578
|
*/
|
|
572
|
-
async _encryptInbound (connection: Duplex<Uint8Array
|
|
579
|
+
async _encryptInbound (connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>>): Promise<CryptoResult> {
|
|
573
580
|
const protocols = Array.from(this.connectionEncryption.keys())
|
|
574
581
|
log('handling inbound crypto protocol selection', protocols)
|
|
575
582
|
|
|
@@ -627,7 +634,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
627
634
|
* Selects one of the given muxers via multistream-select. That
|
|
628
635
|
* muxer will be used for all future streams on the connection.
|
|
629
636
|
*/
|
|
630
|
-
async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<Uint8Array>, muxerFactory?: StreamMuxerFactory }> {
|
|
637
|
+
async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
|
|
631
638
|
const protocols = Array.from(muxers.keys())
|
|
632
639
|
log('outbound selecting muxer %s', protocols)
|
|
633
640
|
try {
|
|
@@ -636,6 +643,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
636
643
|
})
|
|
637
644
|
log('%s selected as muxer protocol', protocol)
|
|
638
645
|
const muxerFactory = muxers.get(protocol)
|
|
646
|
+
|
|
639
647
|
return { stream, muxerFactory }
|
|
640
648
|
} catch (err: any) {
|
|
641
649
|
log.error('error multiplexing outbound stream', err)
|
|
@@ -647,7 +655,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
647
655
|
* Registers support for one of the given muxers via multistream-select. The
|
|
648
656
|
* selected muxer will be used for all future streams on the connection.
|
|
649
657
|
*/
|
|
650
|
-
async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<Uint8Array>, muxerFactory?: StreamMuxerFactory }> {
|
|
658
|
+
async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
|
|
651
659
|
const protocols = Array.from(muxers.keys())
|
|
652
660
|
log('inbound handling muxers %s', protocols)
|
|
653
661
|
try {
|
|
@@ -655,6 +663,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|
|
655
663
|
writeBytes: true
|
|
656
664
|
})
|
|
657
665
|
const muxerFactory = muxers.get(protocol)
|
|
666
|
+
|
|
658
667
|
return { stream, muxerFactory }
|
|
659
668
|
} catch (err: any) {
|
|
660
669
|
log.error('error multiplexing inbound stream', err)
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.
|
|
1
|
+
export const version = '0.44.0-17eb162a'
|
|
2
2
|
export const name = 'libp2p'
|