libp2p 0.46.19-fb8a6f188 → 0.46.19
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 +22 -22
- package/dist/src/components.d.ts +1 -3
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +0 -4
- package/dist/src/components.js.map +1 -1
- package/dist/src/connection/index.d.ts +1 -3
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +9 -9
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +1 -3
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +20 -20
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts +1 -3
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +8 -8
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +1 -3
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +23 -26
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -3
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +18 -21
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/utils.d.ts +1 -2
- package/dist/src/connection-manager/utils.d.ts.map +1 -1
- package/dist/src/connection-manager/utils.js +4 -2
- package/dist/src/connection-manager/utils.js.map +1 -1
- package/dist/src/identify/consts.d.ts +1 -1
- package/dist/src/identify/consts.d.ts.map +1 -1
- package/dist/src/identify/identify.d.ts.map +1 -1
- package/dist/src/identify/identify.js +20 -20
- package/dist/src/identify/identify.js.map +1 -1
- package/dist/src/identify/index.d.ts +1 -2
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -21
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +1 -2
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +16 -20
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/upgrader.d.ts +1 -3
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +29 -30
- 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/dist/typedoc-urls.json +71 -0
- package/package.json +21 -21
- package/src/components.ts +1 -8
- package/src/connection/index.ts +11 -12
- package/src/connection-manager/auto-dial.ts +22 -22
- package/src/connection-manager/connection-pruner.ts +10 -10
- package/src/connection-manager/dial-queue.ts +25 -28
- package/src/connection-manager/index.ts +20 -23
- package/src/connection-manager/utils.ts +7 -5
- package/src/identify/identify.ts +22 -21
- package/src/identify/index.ts +1 -2
- package/src/index.ts +1 -22
- package/src/libp2p.ts +18 -21
- package/src/upgrader.ts +31 -32
- package/src/version.ts +1 -1
package/src/upgrader.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
2
2
|
import { setMaxListeners } from '@libp2p/interface/events'
|
|
3
|
+
import { logger } from '@libp2p/logger'
|
|
3
4
|
import * as mss from '@libp2p/multistream-select'
|
|
4
5
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
5
6
|
import { createConnection } from './connection/index.js'
|
|
6
7
|
import { INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
|
|
7
8
|
import { codes } from './errors.js'
|
|
8
9
|
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'
|
|
9
|
-
import type { Libp2pEvents, AbortOptions
|
|
10
|
+
import type { Libp2pEvents, AbortOptions } from '@libp2p/interface'
|
|
10
11
|
import type { MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions } from '@libp2p/interface/connection'
|
|
11
12
|
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface/connection-encrypter'
|
|
12
13
|
import type { ConnectionGater } from '@libp2p/interface/connection-gater'
|
|
@@ -20,6 +21,8 @@ import type { ConnectionManager } from '@libp2p/interface-internal/connection-ma
|
|
|
20
21
|
import type { Registrar } from '@libp2p/interface-internal/registrar'
|
|
21
22
|
import type { Duplex, Source } from 'it-stream-types'
|
|
22
23
|
|
|
24
|
+
const log = logger('libp2p:upgrader')
|
|
25
|
+
|
|
23
26
|
interface CreateConnectionOptions {
|
|
24
27
|
cryptoProtocol: string
|
|
25
28
|
direction: 'inbound' | 'outbound'
|
|
@@ -102,7 +105,6 @@ export interface DefaultUpgraderComponents {
|
|
|
102
105
|
registrar: Registrar
|
|
103
106
|
peerStore: PeerStore
|
|
104
107
|
events: TypedEventTarget<Libp2pEvents>
|
|
105
|
-
logger: ComponentLogger
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
type EncryptedConn = Duplex<AsyncGenerator<Uint8Array, any, unknown>, Source<Uint8Array>, Promise<void>>
|
|
@@ -115,12 +117,10 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
115
117
|
private readonly muxers: Map<string, StreamMuxerFactory>
|
|
116
118
|
private readonly inboundUpgradeTimeout: number
|
|
117
119
|
private readonly events: TypedEventTarget<Libp2pEvents>
|
|
118
|
-
readonly #log: Logger
|
|
119
120
|
|
|
120
121
|
constructor (components: DefaultUpgraderComponents, init: UpgraderInit) {
|
|
121
122
|
this.components = components
|
|
122
123
|
this.connectionEncryption = new Map()
|
|
123
|
-
this.#log = components.logger.forComponent('libp2p:upgrader')
|
|
124
124
|
|
|
125
125
|
init.connectionEncryption.forEach(encrypter => {
|
|
126
126
|
this.connectionEncryption.set(encrypter.protocol, encrypter)
|
|
@@ -179,7 +179,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
179
179
|
|
|
180
180
|
this.components.metrics?.trackMultiaddrConnection(maConn)
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
log('starting the inbound connection upgrade')
|
|
183
183
|
|
|
184
184
|
// Protect
|
|
185
185
|
let protectedConn = maConn
|
|
@@ -188,7 +188,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
188
188
|
const protector = this.components.connectionProtector
|
|
189
189
|
|
|
190
190
|
if (protector != null) {
|
|
191
|
-
|
|
191
|
+
log('protecting the inbound connection')
|
|
192
192
|
protectedConn = await protector.protect(maConn)
|
|
193
193
|
}
|
|
194
194
|
}
|
|
@@ -235,13 +235,13 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
235
235
|
upgradedConn = multiplexed.stream
|
|
236
236
|
}
|
|
237
237
|
} catch (err: any) {
|
|
238
|
-
|
|
238
|
+
log.error('Failed to upgrade inbound connection', err)
|
|
239
239
|
throw err
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
await this.shouldBlockConnection(remotePeer, maConn, 'denyInboundUpgradedConnection')
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
log('Successfully upgraded inbound connection')
|
|
245
245
|
|
|
246
246
|
return this._createConnection({
|
|
247
247
|
cryptoProtocol,
|
|
@@ -280,7 +280,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
280
280
|
|
|
281
281
|
this.components.metrics?.trackMultiaddrConnection(maConn)
|
|
282
282
|
|
|
283
|
-
|
|
283
|
+
log('Starting the outbound connection upgrade')
|
|
284
284
|
|
|
285
285
|
// If the transport natively supports encryption, skip connection
|
|
286
286
|
// protector and encryption
|
|
@@ -333,14 +333,14 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
333
333
|
upgradedConn = multiplexed.stream
|
|
334
334
|
}
|
|
335
335
|
} catch (err: any) {
|
|
336
|
-
|
|
336
|
+
log.error('Failed to upgrade outbound connection', err)
|
|
337
337
|
await maConn.close(err)
|
|
338
338
|
throw err
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
await this.shouldBlockConnection(remotePeer, maConn, 'denyOutboundUpgradedConnection')
|
|
342
342
|
|
|
343
|
-
|
|
343
|
+
log('Successfully upgraded outbound connection')
|
|
344
344
|
|
|
345
345
|
return this._createConnection({
|
|
346
346
|
cryptoProtocol,
|
|
@@ -385,7 +385,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
385
385
|
.then(async () => {
|
|
386
386
|
const protocols = this.components.registrar.getProtocols()
|
|
387
387
|
const { stream, protocol } = await mss.handle(muxedStream, protocols)
|
|
388
|
-
|
|
388
|
+
log('%s: incoming stream opened on %s', direction, protocol)
|
|
389
389
|
|
|
390
390
|
if (connection == null) {
|
|
391
391
|
return
|
|
@@ -418,7 +418,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
418
418
|
this._onStream({ connection, stream: muxedStream, protocol })
|
|
419
419
|
})
|
|
420
420
|
.catch(async err => {
|
|
421
|
-
|
|
421
|
+
log.error(err)
|
|
422
422
|
|
|
423
423
|
if (muxedStream.timeline.close == null) {
|
|
424
424
|
await muxedStream.close()
|
|
@@ -432,12 +432,12 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
432
432
|
throw new CodeError('Stream is not multiplexed', codes.ERR_MUXER_UNAVAILABLE)
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
|
|
435
|
+
log('%s-%s: starting new stream on %s', connection.id, direction, protocols)
|
|
436
436
|
const muxedStream = await muxer.newStream()
|
|
437
437
|
|
|
438
438
|
try {
|
|
439
439
|
if (options.signal == null) {
|
|
440
|
-
|
|
440
|
+
log('No abort signal was passed while trying to negotiate protocols %s falling back to default timeout', protocols)
|
|
441
441
|
|
|
442
442
|
options.signal = AbortSignal.timeout(30000)
|
|
443
443
|
|
|
@@ -472,7 +472,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
472
472
|
|
|
473
473
|
return muxedStream
|
|
474
474
|
} catch (err: any) {
|
|
475
|
-
|
|
475
|
+
log.error('could not create new stream for protocols %s on connection with address %a', protocols, connection.remoteAddr, err)
|
|
476
476
|
|
|
477
477
|
if (muxedStream.timeline.close == null) {
|
|
478
478
|
muxedStream.abort(err)
|
|
@@ -491,7 +491,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
491
491
|
muxer.sink(upgradedConn.source),
|
|
492
492
|
upgradedConn.sink(muxer.source)
|
|
493
493
|
]).catch(err => {
|
|
494
|
-
|
|
494
|
+
log.error(err)
|
|
495
495
|
})
|
|
496
496
|
}
|
|
497
497
|
|
|
@@ -506,14 +506,14 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
506
506
|
await connection.close()
|
|
507
507
|
}
|
|
508
508
|
} catch (err: any) {
|
|
509
|
-
|
|
509
|
+
log.error(err)
|
|
510
510
|
} finally {
|
|
511
511
|
this.events.safeDispatchEvent('connection:close', {
|
|
512
512
|
detail: connection
|
|
513
513
|
})
|
|
514
514
|
}
|
|
515
515
|
})().catch(err => {
|
|
516
|
-
|
|
516
|
+
log.error(err)
|
|
517
517
|
})
|
|
518
518
|
}
|
|
519
519
|
|
|
@@ -536,20 +536,19 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
536
536
|
multiplexer: muxer?.protocol,
|
|
537
537
|
encryption: cryptoProtocol,
|
|
538
538
|
transient,
|
|
539
|
-
logger: this.components.logger,
|
|
540
539
|
newStream: newStream ?? errConnectionNotMultiplexed,
|
|
541
540
|
getStreams: () => { if (muxer != null) { return muxer.streams } else { return [] } },
|
|
542
541
|
close: async (options?: AbortOptions) => {
|
|
543
542
|
// Ensure remaining streams are closed gracefully
|
|
544
543
|
if (muxer != null) {
|
|
545
|
-
|
|
544
|
+
log.trace('close muxer')
|
|
546
545
|
await muxer.close(options)
|
|
547
546
|
}
|
|
548
547
|
|
|
549
|
-
|
|
548
|
+
log.trace('close maconn')
|
|
550
549
|
// close the underlying transport
|
|
551
550
|
await maConn.close(options)
|
|
552
|
-
|
|
551
|
+
log.trace('closed maconn')
|
|
553
552
|
},
|
|
554
553
|
abort: (err) => {
|
|
555
554
|
maConn.abort(err)
|
|
@@ -586,7 +585,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
586
585
|
*/
|
|
587
586
|
async _encryptInbound (connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>>): Promise<CryptoResult> {
|
|
588
587
|
const protocols = Array.from(this.connectionEncryption.keys())
|
|
589
|
-
|
|
588
|
+
log('handling inbound crypto protocol selection', protocols)
|
|
590
589
|
|
|
591
590
|
try {
|
|
592
591
|
const { stream, protocol } = await mss.handle(connection, protocols, {
|
|
@@ -598,7 +597,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
598
597
|
throw new Error(`no crypto module found for ${protocol}`)
|
|
599
598
|
}
|
|
600
599
|
|
|
601
|
-
|
|
600
|
+
log('encrypting inbound connection...')
|
|
602
601
|
|
|
603
602
|
return {
|
|
604
603
|
...await encrypter.secureInbound(this.components.peerId, stream),
|
|
@@ -615,7 +614,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
615
614
|
*/
|
|
616
615
|
async _encryptOutbound (connection: MultiaddrConnection, remotePeerId?: PeerId): Promise<CryptoResult> {
|
|
617
616
|
const protocols = Array.from(this.connectionEncryption.keys())
|
|
618
|
-
|
|
617
|
+
log('selecting outbound crypto protocol', protocols)
|
|
619
618
|
|
|
620
619
|
try {
|
|
621
620
|
const { stream, protocol } = await mss.select(connection, protocols, {
|
|
@@ -627,7 +626,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
627
626
|
throw new Error(`no crypto module found for ${protocol}`)
|
|
628
627
|
}
|
|
629
628
|
|
|
630
|
-
|
|
629
|
+
log('encrypting outbound connection to %p', remotePeerId)
|
|
631
630
|
|
|
632
631
|
return {
|
|
633
632
|
...await encrypter.secureOutbound(this.components.peerId, stream, remotePeerId),
|
|
@@ -644,17 +643,17 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
644
643
|
*/
|
|
645
644
|
async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
|
|
646
645
|
const protocols = Array.from(muxers.keys())
|
|
647
|
-
|
|
646
|
+
log('outbound selecting muxer %s', protocols)
|
|
648
647
|
try {
|
|
649
648
|
const { stream, protocol } = await mss.select(connection, protocols, {
|
|
650
649
|
writeBytes: true
|
|
651
650
|
})
|
|
652
|
-
|
|
651
|
+
log('%s selected as muxer protocol', protocol)
|
|
653
652
|
const muxerFactory = muxers.get(protocol)
|
|
654
653
|
|
|
655
654
|
return { stream, muxerFactory }
|
|
656
655
|
} catch (err: any) {
|
|
657
|
-
|
|
656
|
+
log.error('error multiplexing outbound stream', err)
|
|
658
657
|
throw new CodeError(String(err), codes.ERR_MUXER_UNAVAILABLE)
|
|
659
658
|
}
|
|
660
659
|
}
|
|
@@ -665,7 +664,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
665
664
|
*/
|
|
666
665
|
async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
|
|
667
666
|
const protocols = Array.from(muxers.keys())
|
|
668
|
-
|
|
667
|
+
log('inbound handling muxers %s', protocols)
|
|
669
668
|
try {
|
|
670
669
|
const { stream, protocol } = await mss.handle(connection, protocols, {
|
|
671
670
|
writeBytes: true
|
|
@@ -674,7 +673,7 @@ export class DefaultUpgrader implements Upgrader {
|
|
|
674
673
|
|
|
675
674
|
return { stream, muxerFactory }
|
|
676
675
|
} catch (err: any) {
|
|
677
|
-
|
|
676
|
+
log.error('error multiplexing inbound stream', err)
|
|
678
677
|
throw new CodeError(String(err), codes.ERR_MUXER_UNAVAILABLE)
|
|
679
678
|
}
|
|
680
679
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.46.19
|
|
1
|
+
export const version = '0.46.19'
|
|
2
2
|
export const name = 'libp2p'
|