libp2p 0.42.2-593deefe → 0.42.2-5e63ee2d
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 +30 -30
- package/dist/src/address-manager/index.d.ts +1 -10
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +46 -29
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/autonat/constants.d.ts +4 -0
- package/dist/src/autonat/constants.d.ts.map +1 -0
- package/dist/src/autonat/constants.js +4 -0
- package/dist/src/autonat/constants.js.map +1 -0
- package/dist/src/autonat/index.d.ts +64 -0
- package/dist/src/autonat/index.d.ts.map +1 -0
- package/dist/src/autonat/index.js +417 -0
- package/dist/src/autonat/index.js.map +1 -0
- package/dist/src/autonat/pb/index.d.ts +57 -0
- package/dist/src/autonat/pb/index.d.ts.map +1 -0
- package/dist/src/autonat/pb/index.js +250 -0
- package/dist/src/autonat/pb/index.js.map +1 -0
- package/dist/src/circuit/constants.d.ts +29 -3
- package/dist/src/circuit/constants.d.ts.map +1 -1
- package/dist/src/circuit/constants.js +32 -5
- package/dist/src/circuit/constants.js.map +1 -1
- package/dist/src/circuit/index.d.ts +16 -61
- package/dist/src/circuit/index.d.ts.map +1 -1
- package/dist/src/circuit/index.js +2 -1
- package/dist/src/circuit/index.js.map +1 -1
- package/dist/src/circuit/server/advert-service.d.ts +43 -0
- package/dist/src/circuit/server/advert-service.d.ts.map +1 -0
- package/dist/src/circuit/server/advert-service.js +69 -0
- package/dist/src/circuit/server/advert-service.js.map +1 -0
- package/dist/src/circuit/server/index.d.ts +60 -0
- package/dist/src/circuit/server/index.d.ts.map +1 -0
- package/dist/src/circuit/server/index.js +287 -0
- package/dist/src/circuit/server/index.js.map +1 -0
- package/dist/src/circuit/{reservation-store.d.ts → server/reservation-store.d.ts} +17 -10
- package/dist/src/circuit/server/reservation-store.d.ts.map +1 -0
- package/dist/src/circuit/server/reservation-store.js +57 -0
- package/dist/src/circuit/server/reservation-store.js.map +1 -0
- package/dist/src/circuit/server/reservation-voucher.d.ts.map +1 -0
- package/dist/src/circuit/{reservation-voucher.js → server/reservation-voucher.js} +1 -1
- package/dist/src/circuit/server/reservation-voucher.js.map +1 -0
- package/dist/src/circuit/transport/discovery.d.ts +45 -0
- package/dist/src/circuit/transport/discovery.d.ts.map +1 -0
- package/dist/src/circuit/transport/discovery.js +82 -0
- package/dist/src/circuit/transport/discovery.js.map +1 -0
- package/dist/src/circuit/transport/index.d.ts +33 -0
- package/dist/src/circuit/transport/index.d.ts.map +1 -0
- package/dist/src/circuit/transport/index.js +225 -0
- package/dist/src/circuit/transport/index.js.map +1 -0
- package/dist/src/circuit/transport/listener.d.ts +9 -0
- package/dist/src/circuit/transport/listener.d.ts.map +1 -0
- package/dist/src/circuit/transport/listener.js +76 -0
- package/dist/src/circuit/transport/listener.js.map +1 -0
- package/dist/src/circuit/transport/reservation-store.d.ts +60 -0
- package/dist/src/circuit/transport/reservation-store.d.ts.map +1 -0
- package/dist/src/circuit/transport/reservation-store.js +165 -0
- package/dist/src/circuit/transport/reservation-store.js.map +1 -0
- package/dist/src/circuit/utils.d.ts +4 -2
- package/dist/src/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/utils.js +75 -102
- package/dist/src/circuit/utils.js.map +1 -1
- package/dist/src/components.d.ts +2 -1
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +17 -20
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection/index.d.ts +2 -2
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +1 -1
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +0 -4
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.js +0 -9
- package/dist/src/connection-manager/auto-dialler.js.map +1 -1
- package/dist/src/connection-manager/dialer/dial-request.js +1 -1
- package/dist/src/connection-manager/dialer/dial-request.js.map +1 -1
- package/dist/src/connection-manager/dialer/index.d.ts +2 -1
- package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/index.js +3 -3
- package/dist/src/connection-manager/dialer/index.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +0 -4
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +1 -1
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/latency-monitor.d.ts.map +1 -1
- package/dist/src/connection-manager/latency-monitor.js +1 -1
- package/dist/src/connection-manager/latency-monitor.js.map +1 -1
- package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +1 -1
- package/dist/src/content-routing/index.d.ts +6 -4
- package/dist/src/content-routing/index.d.ts.map +1 -1
- 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 +3 -3
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +2 -1
- package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.js.map +1 -1
- package/dist/src/dht/dht-peer-routing.d.ts +3 -2
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-peer-routing.js.map +1 -1
- package/dist/src/dht/dummy-dht.d.ts +1 -1
- package/dist/src/dht/dummy-dht.d.ts.map +1 -1
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/identify/index.d.ts +3 -1
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +12 -7
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +13 -7
- 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.map +1 -1
- package/dist/src/libp2p.d.ts +6 -4
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +19 -28
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/nat-manager.d.ts.map +1 -1
- package/dist/src/nat-manager.js +3 -1
- package/dist/src/nat-manager.js.map +1 -1
- package/dist/src/peer-record-updater.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/pnet/crypto.d.ts +1 -1
- package/dist/src/pnet/crypto.d.ts.map +1 -1
- package/dist/src/pnet/crypto.js +1 -1
- package/dist/src/pnet/crypto.js.map +1 -1
- package/dist/src/pnet/key-generator.d.ts.map +1 -1
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +1 -1
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +2 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +19 -14
- package/dist/src/upgrader.js.map +1 -1
- package/package.json +23 -18
- package/src/address-manager/index.ts +62 -35
- package/src/autonat/constants.ts +4 -0
- package/src/autonat/index.ts +567 -0
- package/src/autonat/pb/index.proto +35 -0
- package/src/autonat/pb/index.ts +320 -0
- package/src/circuit/constants.ts +40 -5
- package/src/circuit/index.ts +17 -67
- package/src/circuit/server/advert-service.ts +108 -0
- package/src/circuit/server/index.ts +421 -0
- package/src/circuit/server/reservation-store.ts +111 -0
- package/src/circuit/{reservation-voucher.ts → server/reservation-voucher.ts} +3 -3
- package/src/circuit/transport/discovery.ts +127 -0
- package/src/circuit/transport/index.ts +325 -0
- package/src/circuit/transport/listener.ts +99 -0
- package/src/circuit/transport/reservation-store.ts +249 -0
- package/src/circuit/utils.ts +78 -115
- package/src/components.ts +9 -8
- package/src/config.ts +17 -20
- package/src/connection/index.ts +7 -7
- package/src/connection-manager/auto-dialler.ts +4 -20
- package/src/connection-manager/dialer/dial-request.ts +1 -1
- package/src/connection-manager/dialer/index.ts +10 -9
- package/src/connection-manager/index.ts +14 -19
- package/src/connection-manager/latency-monitor.ts +9 -9
- package/src/connection-manager/visibility-change-emitter.ts +4 -4
- package/src/content-routing/index.ts +10 -8
- package/src/content-routing/utils.ts +3 -3
- package/src/dht/dht-content-routing.ts +3 -2
- package/src/dht/dht-peer-routing.ts +3 -2
- package/src/dht/dummy-dht.ts +1 -1
- package/src/fetch/index.ts +7 -7
- package/src/identify/index.ts +22 -17
- package/src/index.ts +14 -7
- package/src/insecure/index.ts +2 -1
- package/src/libp2p.ts +33 -41
- package/src/nat-manager.ts +9 -7
- package/src/peer-record-updater.ts +4 -4
- package/src/peer-routing.ts +4 -4
- package/src/ping/index.ts +4 -4
- package/src/pnet/crypto.ts +3 -3
- package/src/pnet/key-generator.ts +1 -1
- package/src/registrar.ts +8 -8
- package/src/transport-manager.ts +10 -10
- package/src/upgrader.ts +20 -19
- package/src/version.ts +1 -1
- package/dist/src/circuit/client.d.ts +0 -81
- package/dist/src/circuit/client.d.ts.map +0 -1
- package/dist/src/circuit/client.js +0 -285
- package/dist/src/circuit/client.js.map +0 -1
- package/dist/src/circuit/hop.d.ts +0 -23
- package/dist/src/circuit/hop.d.ts.map +0 -1
- package/dist/src/circuit/hop.js +0 -167
- package/dist/src/circuit/hop.js.map +0 -1
- package/dist/src/circuit/interfaces.d.ts +0 -27
- package/dist/src/circuit/interfaces.d.ts.map +0 -1
- package/dist/src/circuit/interfaces.js +0 -2
- package/dist/src/circuit/interfaces.js.map +0 -1
- package/dist/src/circuit/listener.d.ts +0 -9
- package/dist/src/circuit/listener.d.ts.map +0 -1
- package/dist/src/circuit/listener.js +0 -62
- package/dist/src/circuit/listener.js.map +0 -1
- package/dist/src/circuit/multicodec.d.ts +0 -3
- package/dist/src/circuit/multicodec.d.ts.map +0 -1
- package/dist/src/circuit/multicodec.js +0 -3
- package/dist/src/circuit/multicodec.js.map +0 -1
- package/dist/src/circuit/relay.d.ts +0 -34
- package/dist/src/circuit/relay.d.ts.map +0 -1
- package/dist/src/circuit/relay.js +0 -61
- package/dist/src/circuit/relay.js.map +0 -1
- package/dist/src/circuit/reservation-store.d.ts.map +0 -1
- package/dist/src/circuit/reservation-store.js +0 -59
- package/dist/src/circuit/reservation-store.js.map +0 -1
- package/dist/src/circuit/reservation-voucher.d.ts.map +0 -1
- package/dist/src/circuit/reservation-voucher.js.map +0 -1
- package/dist/src/circuit/stop.d.ts +0 -19
- package/dist/src/circuit/stop.d.ts.map +0 -1
- package/dist/src/circuit/stop.js +0 -67
- package/dist/src/circuit/stop.js.map +0 -1
- package/dist/src/circuit/transport.d.ts +0 -66
- package/dist/src/circuit/transport.d.ts.map +0 -1
- package/dist/src/circuit/transport.js +0 -238
- package/dist/src/circuit/transport.js.map +0 -1
- package/src/circuit/client.ts +0 -381
- package/src/circuit/hop.ts +0 -210
- package/src/circuit/interfaces.ts +0 -28
- package/src/circuit/listener.ts +0 -83
- package/src/circuit/multicodec.ts +0 -3
- package/src/circuit/relay.ts +0 -87
- package/src/circuit/reservation-store.ts +0 -106
- package/src/circuit/stop.ts +0 -92
- package/src/circuit/transport.ts +0 -313
- /package/dist/src/circuit/{reservation-voucher.d.ts → server/reservation-voucher.d.ts} +0 -0
|
@@ -44,11 +44,6 @@ export interface ConnectionManagerConfig {
|
|
|
44
44
|
*/
|
|
45
45
|
pollInterval?: number
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
* If true, try to connect to all discovered peers up to the connection manager limit
|
|
49
|
-
*/
|
|
50
|
-
autoDial?: boolean
|
|
51
|
-
|
|
52
47
|
/**
|
|
53
48
|
* How long to wait between attempting to keep our number of concurrent connections
|
|
54
49
|
* above minConnections
|
|
@@ -211,7 +206,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
211
206
|
this.incomingPendingConnections = 0
|
|
212
207
|
}
|
|
213
208
|
|
|
214
|
-
isStarted () {
|
|
209
|
+
isStarted (): boolean {
|
|
215
210
|
return this.started
|
|
216
211
|
}
|
|
217
212
|
|
|
@@ -219,7 +214,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
219
214
|
* Starts the Connection Manager. If Metrics are not enabled on libp2p
|
|
220
215
|
* only event loop and connection limits will be monitored.
|
|
221
216
|
*/
|
|
222
|
-
async start () {
|
|
217
|
+
async start (): Promise<void> {
|
|
223
218
|
// track inbound/outbound connections
|
|
224
219
|
this.components.metrics?.registerMetricGroup('libp2p_connection_manager_connections', {
|
|
225
220
|
calculate: () => {
|
|
@@ -307,7 +302,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
307
302
|
log('started')
|
|
308
303
|
}
|
|
309
304
|
|
|
310
|
-
async afterStart () {
|
|
305
|
+
async afterStart (): Promise<void> {
|
|
311
306
|
this.components.upgrader.addEventListener('connection', this.onConnect)
|
|
312
307
|
this.components.upgrader.addEventListener('connectionEnd', this.onDisconnect)
|
|
313
308
|
|
|
@@ -352,7 +347,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
352
347
|
})
|
|
353
348
|
}
|
|
354
349
|
|
|
355
|
-
async beforeStop () {
|
|
350
|
+
async beforeStop (): Promise<void> {
|
|
356
351
|
// if we are still dialing KEEP_ALIVE peers, abort those dials
|
|
357
352
|
this.connectOnStartupController?.abort()
|
|
358
353
|
this.components.upgrader.removeEventListener('connection', this.onConnect)
|
|
@@ -362,7 +357,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
362
357
|
/**
|
|
363
358
|
* Stops the Connection Manager
|
|
364
359
|
*/
|
|
365
|
-
async stop () {
|
|
360
|
+
async stop (): Promise<void> {
|
|
366
361
|
this.latencyMonitor?.removeEventListener('data', this._onLatencyMeasure)
|
|
367
362
|
this.latencyMonitor?.stop()
|
|
368
363
|
|
|
@@ -374,7 +369,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
374
369
|
/**
|
|
375
370
|
* Cleans up the connections
|
|
376
371
|
*/
|
|
377
|
-
async _close () {
|
|
372
|
+
async _close (): Promise<void> {
|
|
378
373
|
// Close all connections we're tracking
|
|
379
374
|
const tasks: Array<Promise<void>> = []
|
|
380
375
|
for (const connectionList of this.connections.values()) {
|
|
@@ -394,7 +389,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
394
389
|
this.connections.clear()
|
|
395
390
|
}
|
|
396
391
|
|
|
397
|
-
onConnect (evt: CustomEvent<Connection>) {
|
|
392
|
+
onConnect (evt: CustomEvent<Connection>): void {
|
|
398
393
|
void this._onConnect(evt).catch(err => {
|
|
399
394
|
log.error(err)
|
|
400
395
|
})
|
|
@@ -403,7 +398,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
403
398
|
/**
|
|
404
399
|
* Tracks the incoming connection and check the connection limit
|
|
405
400
|
*/
|
|
406
|
-
async _onConnect (evt: CustomEvent<Connection>) {
|
|
401
|
+
async _onConnect (evt: CustomEvent<Connection>): Promise<void> {
|
|
407
402
|
const { detail: connection } = evt
|
|
408
403
|
|
|
409
404
|
if (!this.started) {
|
|
@@ -436,7 +431,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
436
431
|
/**
|
|
437
432
|
* Removes the connection from tracking
|
|
438
433
|
*/
|
|
439
|
-
onDisconnect (evt: CustomEvent<Connection>) {
|
|
434
|
+
onDisconnect (evt: CustomEvent<Connection>): void {
|
|
440
435
|
const { detail: connection } = evt
|
|
441
436
|
|
|
442
437
|
if (!this.started) {
|
|
@@ -542,7 +537,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
542
537
|
|
|
543
538
|
await Promise.all(
|
|
544
539
|
connections.map(async connection => {
|
|
545
|
-
|
|
540
|
+
await connection.close()
|
|
546
541
|
})
|
|
547
542
|
)
|
|
548
543
|
}
|
|
@@ -569,7 +564,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
569
564
|
/**
|
|
570
565
|
* If the event loop is slow, maybe close a connection
|
|
571
566
|
*/
|
|
572
|
-
_onLatencyMeasure (evt: CustomEvent<SummaryObject>) {
|
|
567
|
+
_onLatencyMeasure (evt: CustomEvent<SummaryObject>): void {
|
|
573
568
|
const { detail: summary } = evt
|
|
574
569
|
|
|
575
570
|
this._checkMaxLimit('maxEventLoopDelay', summary.avgMs, 1)
|
|
@@ -581,7 +576,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
581
576
|
/**
|
|
582
577
|
* If the `value` of `name` has exceeded its limit, maybe close a connection
|
|
583
578
|
*/
|
|
584
|
-
async _checkMaxLimit (name: keyof ConnectionManagerInit, value: number, toPrune: number = 1) {
|
|
579
|
+
async _checkMaxLimit (name: keyof ConnectionManagerInit, value: number, toPrune: number = 1): Promise<void> {
|
|
585
580
|
const limit = this.opts[name]
|
|
586
581
|
|
|
587
582
|
if (limit == null) {
|
|
@@ -600,7 +595,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
600
595
|
* If we have more connections than our maximum, select some excess connections
|
|
601
596
|
* to prune based on peer value
|
|
602
597
|
*/
|
|
603
|
-
async _pruneConnections (toPrune: number) {
|
|
598
|
+
async _pruneConnections (toPrune: number): Promise<void> {
|
|
604
599
|
const connections = this.getConnections()
|
|
605
600
|
const peerValues = new PeerMap<number>()
|
|
606
601
|
|
|
@@ -726,7 +721,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
|
|
|
726
721
|
return false
|
|
727
722
|
}
|
|
728
723
|
|
|
729
|
-
afterUpgradeInbound () {
|
|
724
|
+
afterUpgradeInbound (): void {
|
|
730
725
|
this.incomingPendingConnections--
|
|
731
726
|
}
|
|
732
727
|
}
|
|
@@ -148,7 +148,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
148
148
|
this.latencyData = this.initLatencyData()
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
start () {
|
|
151
|
+
start (): void {
|
|
152
152
|
// We check for isBrowser because of browsers set max rates of timeouts when a page is hidden,
|
|
153
153
|
// so we fall back to another library
|
|
154
154
|
// See: http://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs
|
|
@@ -172,7 +172,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
stop () {
|
|
175
|
+
stop (): void {
|
|
176
176
|
this._stopTimers()
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -181,7 +181,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
181
181
|
*
|
|
182
182
|
* @private
|
|
183
183
|
*/
|
|
184
|
-
_startTimers () {
|
|
184
|
+
_startTimers (): void {
|
|
185
185
|
// Timer already started, ignore this
|
|
186
186
|
if (this.checkLatencyID != null) {
|
|
187
187
|
return
|
|
@@ -190,7 +190,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
190
190
|
this.checkLatency()
|
|
191
191
|
|
|
192
192
|
if (this.dataEmitIntervalMs != null) {
|
|
193
|
-
this.emitIntervalID = setInterval(() => this._emitSummary(), this.dataEmitIntervalMs)
|
|
193
|
+
this.emitIntervalID = setInterval(() => { this._emitSummary() }, this.dataEmitIntervalMs)
|
|
194
194
|
if (typeof this.emitIntervalID.unref === 'function') {
|
|
195
195
|
this.emitIntervalID.unref() // Doesn't block exit
|
|
196
196
|
}
|
|
@@ -202,7 +202,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
202
202
|
*
|
|
203
203
|
* @private
|
|
204
204
|
*/
|
|
205
|
-
_stopTimers () {
|
|
205
|
+
_stopTimers (): void {
|
|
206
206
|
if (this.checkLatencyID != null) {
|
|
207
207
|
clearTimeout(this.checkLatencyID)
|
|
208
208
|
this.checkLatencyID = undefined
|
|
@@ -218,7 +218,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
218
218
|
*
|
|
219
219
|
* @private
|
|
220
220
|
*/
|
|
221
|
-
_emitSummary () {
|
|
221
|
+
_emitSummary (): void {
|
|
222
222
|
const summary = this.getSummary()
|
|
223
223
|
if (summary.events > 0) {
|
|
224
224
|
this.dispatchEvent(new CustomEvent<SummaryObject>('data', {
|
|
@@ -254,7 +254,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
254
254
|
* Randomly calls an async fn every roughly latencyCheckIntervalMs (plus some randomness). If no async fn is found,
|
|
255
255
|
* it will simply report on event loop latency.
|
|
256
256
|
*/
|
|
257
|
-
checkLatency () {
|
|
257
|
+
checkLatency (): void {
|
|
258
258
|
// Randomness is needed to avoid alignment by accident to regular things in the event loop
|
|
259
259
|
const randomness = (Math.random() * this.latencyCheckMultiply) - this.latencyCheckSubtract
|
|
260
260
|
|
|
@@ -264,7 +264,7 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
264
264
|
startTime: this.now()
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
const cb = () => {
|
|
267
|
+
const cb = (): void => {
|
|
268
268
|
// We are already stopped, ignore this datapoint
|
|
269
269
|
if (this.checkLatencyID == null) {
|
|
270
270
|
return
|
|
@@ -314,6 +314,6 @@ export class LatencyMonitor extends EventEmitter<LatencyMonitorEvents> {
|
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
function isBrowser () {
|
|
317
|
+
function isBrowser (): boolean {
|
|
318
318
|
return typeof globalThis.window !== 'undefined'
|
|
319
319
|
}
|
|
@@ -60,7 +60,7 @@ export class VisibilityChangeEmitter extends EventEmitter<VisibilityChangeEmitte
|
|
|
60
60
|
*
|
|
61
61
|
* @private
|
|
62
62
|
*/
|
|
63
|
-
_initializeVisibilityVarNames () {
|
|
63
|
+
_initializeVisibilityVarNames (): void {
|
|
64
64
|
let hidden: Hidden = 'hidden'
|
|
65
65
|
let visibilityChange = 'visibilitychange'
|
|
66
66
|
|
|
@@ -91,7 +91,7 @@ export class VisibilityChangeEmitter extends EventEmitter<VisibilityChangeEmitte
|
|
|
91
91
|
*
|
|
92
92
|
* @private
|
|
93
93
|
*/
|
|
94
|
-
_addVisibilityChangeListener () {
|
|
94
|
+
_addVisibilityChangeListener (): void {
|
|
95
95
|
// @ts-expect-error cannot index document object with string key
|
|
96
96
|
if (typeof globalThis.document.addEventListener === 'undefined' || typeof document[this.hidden] === 'undefined') {
|
|
97
97
|
log('Checking page visibility requires a browser that supports the Page Visibility API.')
|
|
@@ -105,7 +105,7 @@ export class VisibilityChangeEmitter extends EventEmitter<VisibilityChangeEmitte
|
|
|
105
105
|
* The function returns ```true``` if the page is visible or ```false``` if the page is not visible and
|
|
106
106
|
* ```undefined``` if the page visibility API is not supported by the browser.
|
|
107
107
|
*/
|
|
108
|
-
isVisible () {
|
|
108
|
+
isVisible (): boolean | undefined {
|
|
109
109
|
// @ts-expect-error cannot index document object with string key
|
|
110
110
|
if (this.hidden === undefined || document[this.hidden] === undefined) {
|
|
111
111
|
return undefined
|
|
@@ -122,7 +122,7 @@ export class VisibilityChangeEmitter extends EventEmitter<VisibilityChangeEmitte
|
|
|
122
122
|
*
|
|
123
123
|
* @private
|
|
124
124
|
*/
|
|
125
|
-
_handleVisibilityChange () {
|
|
125
|
+
_handleVisibilityChange (): void {
|
|
126
126
|
// @ts-expect-error cannot index document object with string key
|
|
127
127
|
const visible = globalThis.document[this.hidden] === false
|
|
128
128
|
log(visible ? 'Page Visible' : 'Page Hidden')
|
|
@@ -14,6 +14,8 @@ import type { Startable } from '@libp2p/interfaces/startable'
|
|
|
14
14
|
import type { CID } from 'multiformats/cid'
|
|
15
15
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
16
16
|
import type { DualDHT } from '@libp2p/interface-dht'
|
|
17
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
18
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
17
19
|
|
|
18
20
|
export interface CompoundContentRoutingInit {
|
|
19
21
|
routers: ContentRouting[]
|
|
@@ -35,22 +37,22 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
35
37
|
this.components = components
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
isStarted () {
|
|
40
|
+
isStarted (): boolean {
|
|
39
41
|
return this.started
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
async start () {
|
|
44
|
+
async start (): Promise<void> {
|
|
43
45
|
this.started = true
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
async stop () {
|
|
48
|
+
async stop (): Promise<void> {
|
|
47
49
|
this.started = false
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
53
|
* Iterates over all content routers in parallel to find providers of the given key
|
|
52
54
|
*/
|
|
53
|
-
async * findProviders (key: CID, options: AbortOptions = {}) {
|
|
55
|
+
async * findProviders (key: CID, options: AbortOptions = {}): AsyncIterable<PeerInfo> {
|
|
54
56
|
if (this.routers.length === 0) {
|
|
55
57
|
throw errCode(new Error('No content this.routers available'), codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
56
58
|
}
|
|
@@ -69,18 +71,18 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
69
71
|
* Iterates over all content routers in parallel to notify it is
|
|
70
72
|
* a provider of the given key
|
|
71
73
|
*/
|
|
72
|
-
async provide (key: CID, options: AbortOptions = {}) {
|
|
74
|
+
async provide (key: CID, options: AbortOptions = {}): Promise<void> {
|
|
73
75
|
if (this.routers.length === 0) {
|
|
74
76
|
throw errCode(new Error('No content routers available'), codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
await Promise.all(this.routers.map(async (router) => await router.provide(key, options)))
|
|
79
|
+
await Promise.all(this.routers.map(async (router) => { await router.provide(key, options) }))
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
83
|
* Store the given key/value pair in the available content routings
|
|
82
84
|
*/
|
|
83
|
-
async put (key: Uint8Array, value: Uint8Array, options?: AbortOptions) {
|
|
85
|
+
async put (key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void> {
|
|
84
86
|
if (!this.isStarted()) {
|
|
85
87
|
throw errCode(new Error(messages.NOT_STARTED_YET), codes.DHT_NOT_STARTED)
|
|
86
88
|
}
|
|
@@ -117,7 +119,7 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
117
119
|
/**
|
|
118
120
|
* Get the `n` values to the given key without sorting
|
|
119
121
|
*/
|
|
120
|
-
async * getMany (key: Uint8Array, nVals: number, options: AbortOptions) {
|
|
122
|
+
async * getMany (key: Uint8Array, nVals: number, options: AbortOptions): AsyncIterable<{ from: PeerId, val: Uint8Array }> {
|
|
121
123
|
if (!this.isStarted()) {
|
|
122
124
|
throw errCode(new Error(messages.NOT_STARTED_YET), codes.DHT_NOT_STARTED)
|
|
123
125
|
}
|
|
@@ -8,7 +8,7 @@ import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
|
8
8
|
/**
|
|
9
9
|
* Store the multiaddrs from every peer in the passed peer store
|
|
10
10
|
*/
|
|
11
|
-
export async function * storeAddresses (source: Source<PeerInfo>, peerStore: PeerStore) {
|
|
11
|
+
export async function * storeAddresses (source: Source<PeerInfo>, peerStore: PeerStore): AsyncIterable<PeerInfo> {
|
|
12
12
|
yield * map(source, async (peer) => {
|
|
13
13
|
// ensure we have the addresses for a given peer
|
|
14
14
|
await peerStore.addressBook.add(peer.id, peer.multiaddrs)
|
|
@@ -20,7 +20,7 @@ export async function * storeAddresses (source: Source<PeerInfo>, peerStore: Pee
|
|
|
20
20
|
/**
|
|
21
21
|
* Filter peers by unique peer id
|
|
22
22
|
*/
|
|
23
|
-
export function uniquePeers (source: Source<PeerInfo>) {
|
|
23
|
+
export function uniquePeers (source: Source<PeerInfo>): AsyncIterable<PeerInfo> {
|
|
24
24
|
/** @type Set<string> */
|
|
25
25
|
const seen = new Set()
|
|
26
26
|
|
|
@@ -39,7 +39,7 @@ export function uniquePeers (source: Source<PeerInfo>) {
|
|
|
39
39
|
/**
|
|
40
40
|
* Require at least `min` peers to be yielded from `source`
|
|
41
41
|
*/
|
|
42
|
-
export async function * requirePeers (source: Source<PeerInfo>, min: number = 1) {
|
|
42
|
+
export async function * requirePeers (source: Source<PeerInfo>, min: number = 1): AsyncIterable<PeerInfo> {
|
|
43
43
|
let seen = 0
|
|
44
44
|
|
|
45
45
|
for await (const peer of source) {
|
|
@@ -4,6 +4,7 @@ import type { DHT } from '@libp2p/interface-dht'
|
|
|
4
4
|
import type { ContentRouting } from '@libp2p/interface-content-routing'
|
|
5
5
|
import type { CID } from 'multiformats/cid'
|
|
6
6
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
7
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Wrapper class to convert events into returned values
|
|
@@ -15,11 +16,11 @@ export class DHTContentRouting implements ContentRouting {
|
|
|
15
16
|
this.dht = dht
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
async provide (cid: CID) {
|
|
19
|
+
async provide (cid: CID): Promise<void> {
|
|
19
20
|
await drain(this.dht.provide(cid))
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
async * findProviders (cid: CID, options: AbortOptions = {}) {
|
|
23
|
+
async * findProviders (cid: CID, options: AbortOptions = {}): AsyncGenerator<PeerInfo, void, undefined> {
|
|
23
24
|
for await (const event of this.dht.findProviders(cid, options)) {
|
|
24
25
|
if (event.name === 'PROVIDER') {
|
|
25
26
|
yield * event.providers
|
|
@@ -4,6 +4,7 @@ import type { PeerRouting } from '@libp2p/interface-peer-routing'
|
|
|
4
4
|
import type { DHT } from '@libp2p/interface-dht'
|
|
5
5
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
6
6
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
7
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Wrapper class to convert events into returned values
|
|
@@ -15,7 +16,7 @@ export class DHTPeerRouting implements PeerRouting {
|
|
|
15
16
|
this.dht = dht
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
async findPeer (peerId: PeerId, options: AbortOptions = {}) {
|
|
19
|
+
async findPeer (peerId: PeerId, options: AbortOptions = {}): Promise<PeerInfo> {
|
|
19
20
|
for await (const event of this.dht.findPeer(peerId, options)) {
|
|
20
21
|
if (event.name === 'FINAL_PEER') {
|
|
21
22
|
return event.peer
|
|
@@ -25,7 +26,7 @@ export class DHTPeerRouting implements PeerRouting {
|
|
|
25
26
|
throw errCode(new Error(messages.NOT_FOUND), codes.ERR_NOT_FOUND)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
async * getClosestPeers (key: Uint8Array, options: AbortOptions = {}) {
|
|
29
|
+
async * getClosestPeers (key: Uint8Array, options: AbortOptions = {}): AsyncIterable<PeerInfo> {
|
|
29
30
|
for await (const event of this.dht.getClosestPeers(key, options)) {
|
|
30
31
|
if (event.name === 'FINAL_PEER') {
|
|
31
32
|
yield event.peer
|
package/src/dht/dummy-dht.ts
CHANGED
package/src/fetch/index.ts
CHANGED
|
@@ -67,7 +67,7 @@ export class FetchService implements Startable {
|
|
|
67
67
|
this.init = init
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
async start () {
|
|
70
|
+
async start (): Promise<void> {
|
|
71
71
|
await this.components.registrar.handle(this.protocol, (data) => {
|
|
72
72
|
void this.handleMessage(data)
|
|
73
73
|
.catch(err => {
|
|
@@ -83,12 +83,12 @@ export class FetchService implements Startable {
|
|
|
83
83
|
this.started = true
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
async stop () {
|
|
86
|
+
async stop (): Promise<void> {
|
|
87
87
|
await this.components.registrar.unhandle(this.protocol)
|
|
88
88
|
this.started = false
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
isStarted () {
|
|
91
|
+
isStarted (): boolean {
|
|
92
92
|
return this.started
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -178,7 +178,7 @@ export class FetchService implements Startable {
|
|
|
178
178
|
* responds based on looking up the key in the request via the lookup callback that corresponds
|
|
179
179
|
* to the key's prefix.
|
|
180
180
|
*/
|
|
181
|
-
async handleMessage (data: IncomingStreamData) {
|
|
181
|
+
async handleMessage (data: IncomingStreamData): Promise<void> {
|
|
182
182
|
const { stream } = data
|
|
183
183
|
const self = this
|
|
184
184
|
|
|
@@ -224,7 +224,7 @@ export class FetchService implements Startable {
|
|
|
224
224
|
* Given a key, finds the appropriate function for looking up its corresponding value, based on
|
|
225
225
|
* the key's prefix.
|
|
226
226
|
*/
|
|
227
|
-
_getLookupFunction (key: string) {
|
|
227
|
+
_getLookupFunction (key: string): LookupFunction | undefined {
|
|
228
228
|
for (const prefix of this.lookupFunctions.keys()) {
|
|
229
229
|
if (key.startsWith(prefix)) {
|
|
230
230
|
return this.lookupFunctions.get(prefix)
|
|
@@ -243,7 +243,7 @@ export class FetchService implements Startable {
|
|
|
243
243
|
* libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... })
|
|
244
244
|
* ```
|
|
245
245
|
*/
|
|
246
|
-
registerLookupFunction (prefix: string, lookup: LookupFunction) {
|
|
246
|
+
registerLookupFunction (prefix: string, lookup: LookupFunction): void {
|
|
247
247
|
if (this.lookupFunctions.has(prefix)) {
|
|
248
248
|
throw errCode(new Error("Fetch protocol handler for key prefix '" + prefix + "' already registered"), codes.ERR_KEY_ALREADY_EXISTS)
|
|
249
249
|
}
|
|
@@ -262,7 +262,7 @@ export class FetchService implements Startable {
|
|
|
262
262
|
* libp2p.fetchService.unregisterLookupFunction('/prefix')
|
|
263
263
|
* ```
|
|
264
264
|
*/
|
|
265
|
-
unregisterLookupFunction (prefix: string, lookup?: LookupFunction) {
|
|
265
|
+
unregisterLookupFunction (prefix: string, lookup?: LookupFunction): void {
|
|
266
266
|
if (lookup != null) {
|
|
267
267
|
const existingLookup = this.lookupFunctions.get(prefix)
|
|
268
268
|
|
package/src/identify/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as lp from 'it-length-prefixed'
|
|
|
4
4
|
import { pipe } from 'it-pipe'
|
|
5
5
|
import first from 'it-first'
|
|
6
6
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
7
|
-
import { multiaddr, protocols } from '@multiformats/multiaddr'
|
|
7
|
+
import { Multiaddr, multiaddr, protocols } from '@multiformats/multiaddr'
|
|
8
8
|
import { Identify } from './pb/message.js'
|
|
9
9
|
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
|
|
10
10
|
import {
|
|
@@ -65,6 +65,7 @@ export interface IdentifyServiceInit {
|
|
|
65
65
|
|
|
66
66
|
maxPushIncomingStreams: number
|
|
67
67
|
maxPushOutgoingStreams: number
|
|
68
|
+
maxObservedAddresses?: number
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
export interface IdentifyServiceComponents {
|
|
@@ -112,7 +113,7 @@ export class IdentifyService implements Startable {
|
|
|
112
113
|
const { peerId } = evt.detail
|
|
113
114
|
|
|
114
115
|
if (this.components.peerId.equals(peerId)) {
|
|
115
|
-
void this.pushToPeerStore().catch(err => log.error(err))
|
|
116
|
+
void this.pushToPeerStore().catch(err => { log.error(err) })
|
|
116
117
|
}
|
|
117
118
|
})
|
|
118
119
|
|
|
@@ -121,16 +122,16 @@ export class IdentifyService implements Startable {
|
|
|
121
122
|
const { peerId } = evt.detail
|
|
122
123
|
|
|
123
124
|
if (this.components.peerId.equals(peerId)) {
|
|
124
|
-
void this.pushToPeerStore().catch(err => log.error(err))
|
|
125
|
+
void this.pushToPeerStore().catch(err => { log.error(err) })
|
|
125
126
|
}
|
|
126
127
|
})
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
isStarted () {
|
|
130
|
+
isStarted (): boolean {
|
|
130
131
|
return this.started
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
async start () {
|
|
134
|
+
async start (): Promise<void> {
|
|
134
135
|
if (this.started) {
|
|
135
136
|
return
|
|
136
137
|
}
|
|
@@ -158,7 +159,7 @@ export class IdentifyService implements Startable {
|
|
|
158
159
|
this.started = true
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
async stop () {
|
|
162
|
+
async stop (): Promise<void> {
|
|
162
163
|
await this.components.registrar.unhandle(this.identifyProtocolStr)
|
|
163
164
|
await this.components.registrar.unhandle(this.identifyPushProtocolStr)
|
|
164
165
|
|
|
@@ -216,7 +217,7 @@ export class IdentifyService implements Startable {
|
|
|
216
217
|
/**
|
|
217
218
|
* Calls `push` on all peer connections
|
|
218
219
|
*/
|
|
219
|
-
async pushToPeerStore () {
|
|
220
|
+
async pushToPeerStore (): Promise<void> {
|
|
220
221
|
// Do not try to push if we are not running
|
|
221
222
|
if (!this.isStarted()) {
|
|
222
223
|
return
|
|
@@ -378,17 +379,20 @@ export class IdentifyService implements Startable {
|
|
|
378
379
|
}
|
|
379
380
|
|
|
380
381
|
log('identify completed for peer %p and protocols %o', id, protocols)
|
|
382
|
+
log('our observed address is %s', cleanObservedAddr)
|
|
381
383
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
384
|
+
if (cleanObservedAddr != null &&
|
|
385
|
+
this.components.addressManager.getObservedAddrs().length < (this.init.maxObservedAddresses ?? Infinity)) {
|
|
386
|
+
log('storing our observed address %s', cleanObservedAddr?.toString())
|
|
387
|
+
this.components.addressManager.addObservedAddr(cleanObservedAddr)
|
|
388
|
+
}
|
|
385
389
|
}
|
|
386
390
|
|
|
387
391
|
/**
|
|
388
392
|
* Sends the `Identify` response with the Signed Peer Record
|
|
389
393
|
* to the requesting peer over the given `connection`
|
|
390
394
|
*/
|
|
391
|
-
async _handleIdentify (data: IncomingStreamData) {
|
|
395
|
+
async _handleIdentify (data: IncomingStreamData): Promise<void> {
|
|
392
396
|
const { connection, stream } = data
|
|
393
397
|
const timeoutController = new TimeoutController(this.init.timeout)
|
|
394
398
|
|
|
@@ -440,7 +444,7 @@ export class IdentifyService implements Startable {
|
|
|
440
444
|
/**
|
|
441
445
|
* Reads the Identify Push message from the given `connection`
|
|
442
446
|
*/
|
|
443
|
-
async _handlePush (data: IncomingStreamData) {
|
|
447
|
+
async _handlePush (data: IncomingStreamData): Promise<void> {
|
|
444
448
|
const { connection, stream } = data
|
|
445
449
|
const timeoutController = new TimeoutController(this.init.timeout)
|
|
446
450
|
|
|
@@ -467,14 +471,16 @@ export class IdentifyService implements Startable {
|
|
|
467
471
|
message = Identify.decode(data)
|
|
468
472
|
}
|
|
469
473
|
} catch (err: any) {
|
|
470
|
-
|
|
474
|
+
log.error('received invalid message', err)
|
|
475
|
+
return
|
|
471
476
|
} finally {
|
|
472
477
|
stream.close()
|
|
473
478
|
timeoutController.clear()
|
|
474
479
|
}
|
|
475
480
|
|
|
476
481
|
if (message == null) {
|
|
477
|
-
|
|
482
|
+
log.error('received invalid message')
|
|
483
|
+
return
|
|
478
484
|
}
|
|
479
485
|
|
|
480
486
|
const id = connection.remotePeer
|
|
@@ -509,8 +515,7 @@ export class IdentifyService implements Startable {
|
|
|
509
515
|
|
|
510
516
|
// LEGACY: Update peers data in PeerStore
|
|
511
517
|
try {
|
|
512
|
-
await this.components.peerStore.addressBook.set(id,
|
|
513
|
-
message.listenAddrs.map((addr) => multiaddr(addr)))
|
|
518
|
+
await this.components.peerStore.addressBook.set(id, message.listenAddrs.map((addr) => multiaddr(addr)))
|
|
514
519
|
} catch (err: any) {
|
|
515
520
|
log.error('received invalid addrs', err)
|
|
516
521
|
}
|
|
@@ -528,7 +533,7 @@ export class IdentifyService implements Startable {
|
|
|
528
533
|
/**
|
|
529
534
|
* Takes the `addr` and converts it to a Multiaddr if possible
|
|
530
535
|
*/
|
|
531
|
-
static getCleanMultiaddr (addr: Uint8Array | string | null | undefined) {
|
|
536
|
+
static getCleanMultiaddr (addr: Uint8Array | string | null | undefined): Multiaddr | undefined {
|
|
532
537
|
if (addr != null && addr.length > 0) {
|
|
533
538
|
try {
|
|
534
539
|
return multiaddr(addr)
|
package/src/index.ts
CHANGED
|
@@ -22,9 +22,9 @@ import type { DualDHT } from '@libp2p/interface-dht'
|
|
|
22
22
|
import type { Datastore } from 'interface-datastore'
|
|
23
23
|
import type { PeerStoreInit } from '@libp2p/interface-peer-store'
|
|
24
24
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
25
|
-
import type { RelayConfig } from './circuit/index.js'
|
|
26
25
|
import type { PeerDiscovery } from '@libp2p/interface-peer-discovery'
|
|
27
|
-
import type {
|
|
26
|
+
import type { ConnectionProtector } from '@libp2p/interface-connection'
|
|
27
|
+
import type { ConnectionGater } from '@libp2p/interface-connection-gater'
|
|
28
28
|
import type { Transport } from '@libp2p/interface-transport'
|
|
29
29
|
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
|
|
30
30
|
import type { ConnectionEncrypter } from '@libp2p/interface-connection-encrypter'
|
|
@@ -35,6 +35,7 @@ import type { Metrics } from '@libp2p/interface-metrics'
|
|
|
35
35
|
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
36
36
|
import type { PingServiceInit } from './ping/index.js'
|
|
37
37
|
import type { FetchServiceInit } from './fetch/index.js'
|
|
38
|
+
import type { AutonatServiceInit } from './autonat/index.js'
|
|
38
39
|
import type { Components } from './components.js'
|
|
39
40
|
import type { Libp2p } from '@libp2p/interface-libp2p'
|
|
40
41
|
import type { KeyChainInit } from '@libp2p/keychain'
|
|
@@ -42,6 +43,7 @@ import type { NatManagerInit } from './nat-manager.js'
|
|
|
42
43
|
import type { AddressManagerInit } from './address-manager/index.js'
|
|
43
44
|
import type { PeerRoutingInit } from './peer-routing.js'
|
|
44
45
|
import type { ConnectionManagerInit } from './connection-manager/index.js'
|
|
46
|
+
import type { CircuitRelayService } from './circuit/index.js'
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
49
|
* For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
|
|
@@ -65,7 +67,7 @@ export interface Libp2pInit {
|
|
|
65
67
|
/**
|
|
66
68
|
* A connection gater can deny new connections based on user criteria
|
|
67
69
|
*/
|
|
68
|
-
connectionGater:
|
|
70
|
+
connectionGater: ConnectionGater
|
|
69
71
|
|
|
70
72
|
/**
|
|
71
73
|
* libp2p transport manager configuration
|
|
@@ -103,23 +105,28 @@ export interface Libp2pInit {
|
|
|
103
105
|
* If configured as a relay this node will relay certain
|
|
104
106
|
* types of traffic for other peers
|
|
105
107
|
*/
|
|
106
|
-
relay:
|
|
108
|
+
relay: (components: Components) => CircuitRelayService
|
|
107
109
|
|
|
108
110
|
/**
|
|
109
|
-
*
|
|
111
|
+
* identify protocol options
|
|
110
112
|
*/
|
|
111
113
|
identify: IdentifyServiceInit
|
|
112
114
|
|
|
113
115
|
/**
|
|
114
|
-
*
|
|
116
|
+
* ping protocol options
|
|
115
117
|
*/
|
|
116
118
|
ping: PingServiceInit
|
|
117
119
|
|
|
118
120
|
/**
|
|
119
|
-
*
|
|
121
|
+
* fetch protocol options
|
|
120
122
|
*/
|
|
121
123
|
fetch: FetchServiceInit
|
|
122
124
|
|
|
125
|
+
/**
|
|
126
|
+
* autonat protocol options
|
|
127
|
+
*/
|
|
128
|
+
autonat: AutonatServiceInit
|
|
129
|
+
|
|
123
130
|
/**
|
|
124
131
|
* An array that must include at least 1 compliant transport
|
|
125
132
|
*/
|
package/src/insecure/index.ts
CHANGED
|
@@ -32,11 +32,12 @@ import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
|
|
32
32
|
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
|
|
33
33
|
import type { Duplex } from 'it-stream-types'
|
|
34
34
|
import map from 'it-map'
|
|
35
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
35
36
|
|
|
36
37
|
const log = logger('libp2p:plaintext')
|
|
37
38
|
const PROTOCOL = '/plaintext/2.0.0'
|
|
38
39
|
|
|
39
|
-
function lpEncodeExchange (exchange: Exchange) {
|
|
40
|
+
function lpEncodeExchange (exchange: Exchange): Uint8ArrayList {
|
|
40
41
|
const pb = Exchange.encode(exchange)
|
|
41
42
|
|
|
42
43
|
return lp.encode.single(pb)
|