From 001af1f76db17c2eabf608f0c313e161b868a055 Mon Sep 17 00:00:00 2001 From: Chad Nehemiah Date: Tue, 14 Mar 2023 03:50:21 -0500 Subject: [PATCH] chore: upgrade aegir (#1566) Updates aegir, fixes all linting and dep issues. Co-authored-by: achingbrain --- examples/package.json | 3 +- package.json | 10 ++----- src/circuit/server/advert-service.ts | 2 +- src/circuit/server/index.ts | 13 +++++---- src/circuit/transport/index.ts | 4 +-- src/circuit/utils.ts | 2 +- src/components.ts | 14 ++++----- src/connection-manager/auto-dialler.ts | 8 ++--- src/connection-manager/dialer/dial-request.ts | 2 +- src/connection-manager/dialer/index.ts | 10 +++---- src/connection-manager/index.ts | 28 +++++++++--------- src/connection-manager/latency-monitor.ts | 18 ++++++------ .../visibility-change-emitter.ts | 8 ++--- src/connection/index.ts | 14 ++++----- src/content-routing/index.ts | 18 +++++++----- src/content-routing/utils.ts | 6 ++-- src/dht/dht-content-routing.ts | 5 ++-- src/dht/dht-peer-routing.ts | 5 ++-- src/dht/dummy-dht.ts | 2 +- src/fetch/index.ts | 14 ++++----- src/identify/index.ts | 29 ++++++++++--------- src/insecure/index.ts | 3 +- src/libp2p.ts | 22 +++++++------- src/nat-manager.ts | 16 +++++----- src/peer-record-updater.ts | 8 ++--- src/peer-routing.ts | 8 ++--- src/ping/index.ts | 8 ++--- src/pnet/crypto.ts | 6 ++-- src/pnet/key-generator.ts | 2 +- src/registrar.ts | 16 +++++----- src/transport-manager.ts | 18 ++++++------ src/upgrader.ts | 16 +++++----- test/circuit/reservation-store.spec.ts | 28 +++++++++--------- test/circuit/utils.spec.ts | 2 +- test/circuit/utils.ts | 14 ++++----- test/configuration/pubsub.spec.ts | 2 +- test/connection-manager/index.node.ts | 10 +++---- test/connection-manager/index.spec.ts | 2 +- test/content-routing/content-routing.node.ts | 6 ++-- test/content-routing/dht/operation.node.ts | 4 +-- test/content-routing/dht/utils.ts | 2 +- test/dialing/dial-request.spec.ts | 6 ++-- test/dialing/direct.node.ts | 2 +- test/dialing/direct.spec.ts | 2 +- test/dialing/resolver.spec.ts | 9 +++--- test/fetch/fetch.node.ts | 4 +-- test/fetch/index.spec.ts | 2 +- test/identify/index.spec.ts | 10 +++---- test/identify/push.spec.ts | 2 +- test/interop.ts | 4 +-- test/nat-manager/nat-manager.node.ts | 2 +- test/peer-discovery/index.node.ts | 5 ++-- test/peer-routing/peer-routing.node.ts | 8 ++--- test/ping/ping.node.ts | 2 +- test/registrar/registrar.spec.ts | 14 ++++----- test/upgrading/upgrader.spec.ts | 14 ++++----- test/utils/creators/peer.ts | 2 +- 57 files changed, 252 insertions(+), 244 deletions(-) diff --git a/examples/package.json b/examples/package.json index 4bc40043fc..297e5d3789 100644 --- a/examples/package.json +++ b/examples/package.json @@ -9,11 +9,12 @@ }, "license": "MIT", "dependencies": { - "@libp2p/pubsub-peer-discovery": "^8.0.0", "@libp2p/floodsub": "^6.0.0", + "@libp2p/pubsub-peer-discovery": "^8.0.0", "@nodeutils/defaults-deep": "^1.1.0", "execa": "^6.1.0", "fs-extra": "^10.1.0", + "it-to-buffer": "^3.0.1", "libp2p": "../", "p-defer": "^4.0.0", "uint8arrays": "^4.0.0", diff --git a/package.json b/package.json index 50b883825e..86cee6cdac 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "@libp2p/interface-peer-routing": "^1.0.1", "@libp2p/interface-peer-store": "^1.2.2", "@libp2p/interface-pubsub": "^3.0.0", + "@libp2p/interface-record": "^2.0.6", "@libp2p/interface-registrar": "^2.0.3", "@libp2p/interface-stream-muxer": "^3.0.0", "@libp2p/interface-transport": "^2.1.0", @@ -137,8 +138,6 @@ "any-signal": "^3.0.0", "datastore-core": "^8.0.1", "err-code": "^3.0.1", - "events": "^3.3.0", - "hashlru": "^2.3.0", "interface-datastore": "^7.0.0", "it-all": "^2.0.0", "it-drain": "^2.0.0", @@ -151,7 +150,6 @@ "it-pair": "^2.0.2", "it-pb-stream": "^3.2.0", "it-pipe": "^2.0.3", - "it-sort": "^2.0.0", "it-stream-types": "^1.0.4", "merge-options": "^3.0.4", "multiformats": "^11.0.0", @@ -188,23 +186,21 @@ "@libp2p/mplex": "^7.0.0", "@libp2p/pubsub": "^6.0.0", "@libp2p/tcp": "^6.0.0", - "@libp2p/webrtc-star": "^6.0.0", "@libp2p/websockets": "^5.0.0", "@types/p-fifo": "^1.0.0", "@types/varint": "^6.0.0", "@types/xsalsa20": "^1.1.0", - "aegir": "^37.5.6", + "aegir": "^38.1.7", "cborg": "^1.8.1", "delay": "^5.0.0", "execa": "^7.0.0", "go-libp2p": "^1.0.1", "it-pushable": "^3.0.0", - "it-to-buffer": "^3.0.0", + "it-to-buffer": "^3.0.1", "npm-run-all": "^4.1.5", "p-event": "^5.0.1", "p-times": "^4.0.0", "p-wait-for": "^5.0.0", - "protons": "^7.0.2", "sinon": "^15.0.1", "sinon-ts": "^1.0.0" }, diff --git a/src/circuit/server/advert-service.ts b/src/circuit/server/advert-service.ts index 3e6589f27c..e9a942870a 100644 --- a/src/circuit/server/advert-service.ts +++ b/src/circuit/server/advert-service.ts @@ -96,7 +96,7 @@ export class AdvertService extends EventEmitter implements if (err.code === codes.ERR_NO_ROUTERS_AVAILABLE) { log.error('a content router, such as a DHT, must be provided in order to advertise the relay service', err) - await this.stop() + this.stop() return } diff --git a/src/circuit/server/index.ts b/src/circuit/server/index.ts index f4b20592d0..f9074d674a 100644 --- a/src/circuit/server/index.ts +++ b/src/circuit/server/index.ts @@ -26,6 +26,7 @@ import type { ConnectionManager } from '@libp2p/interface-connection-manager' import type { CircuitRelayService, RelayReservation } from '../index.js' import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events' import { setMaxListeners } from 'events' +import type { PeerMap } from '@libp2p/peer-collections' const log = logger('libp2p:circuit-relay:server') @@ -247,7 +248,7 @@ class CircuitRelayServer extends EventEmitter implements Star return } - const result = await this.reservationStore.reserve(connection.remotePeer, connection.remoteAddr) + const result = this.reservationStore.reserve(connection.remotePeer, connection.remoteAddr) if (result.status !== Status.OK) { hopstr.write({ type: HopMessage.Type.STATUS, status: result.status }) @@ -266,12 +267,12 @@ class CircuitRelayServer extends EventEmitter implements Star type: HopMessage.Type.STATUS, status: Status.OK, reservation: await this.makeReservation(connection.remotePeer, BigInt(result.expire ?? 0)), - limit: (await this.reservationStore.get(connection.remotePeer))?.limit + limit: this.reservationStore.get(connection.remotePeer)?.limit }) log('sent confirmation response to %s', connection.remotePeer) } catch (err) { log.error('failed to send confirmation response to %p', connection.remotePeer, err) - await this.reservationStore.removeReservation(connection.remotePeer) + this.reservationStore.removeReservation(connection.remotePeer) } } @@ -325,7 +326,7 @@ class CircuitRelayServer extends EventEmitter implements Star return } - if (!await this.reservationStore.hasReservation(dstPeer)) { + if (!this.reservationStore.hasReservation(dstPeer)) { log.error('hop connect denied for destination peer %p not having a reservation for %p with status %s', dstPeer, connection.remotePeer, Status.NO_RESERVATION) hopstr.write({ type: HopMessage.Type.STATUS, status: Status.NO_RESERVATION }) return @@ -368,7 +369,7 @@ class CircuitRelayServer extends EventEmitter implements Star const sourceStream = stream.unwrap() log('connection from %p to %p established - merging streans', connection.remotePeer, dstPeer) - const limit = (await this.reservationStore.get(dstPeer))?.limit + const limit = this.reservationStore.get(dstPeer)?.limit // Short circuit the two streams to create the relayed connection createLimitedRelay(sourceStream, destinationStream, this.shutdownController.signal, limit) } @@ -408,7 +409,7 @@ class CircuitRelayServer extends EventEmitter implements Star stream.close() } - get reservations () { + get reservations (): PeerMap { return this.reservationStore.reservations } } diff --git a/src/circuit/transport/index.ts b/src/circuit/transport/index.ts index de108f56f2..a76e320fc8 100644 --- a/src/circuit/transport/index.ts +++ b/src/circuit/transport/index.ts @@ -143,7 +143,7 @@ class CircuitRelayTransport implements Transport { return true } - get [Symbol.toStringTag] () { + get [Symbol.toStringTag] (): 'libp2p/circuit-relay-v2' { return 'libp2p/circuit-relay-v2' } @@ -208,7 +208,7 @@ class CircuitRelayTransport implements Transport { destinationAddr, relayAddr, ma, disconnectOnFailure }: ConnectOptions - ) { + ): Promise { try { const pbstr = pbStream(stream) const hopstr = pbstr.pb(HopMessage) diff --git a/src/circuit/utils.ts b/src/circuit/utils.ts index 10e4d2ba89..68a920d8a1 100644 --- a/src/circuit/utils.ts +++ b/src/circuit/utils.ts @@ -37,7 +37,7 @@ async function * countStreamBytes (source: Source, } const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Required): void => { - function abortStreams (err: Error) { + function abortStreams (err: Error): void { src.abort(err) dst.abort(err) clearTimeout(timeout) diff --git a/src/components.ts b/src/components.ts index e0f732cd8c..ee60acbc92 100644 --- a/src/components.ts +++ b/src/components.ts @@ -91,11 +91,11 @@ export class DefaultComponents implements Components, Startable { this._dialer = init.dialer } - isStarted () { + isStarted (): boolean { return this._started } - async beforeStart () { + async beforeStart (): Promise { await Promise.all( Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => { if (startable.beforeStart != null) { @@ -105,7 +105,7 @@ export class DefaultComponents implements Components, Startable { ) } - async start () { + async start (): Promise { await Promise.all( Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => { await startable.start() @@ -115,7 +115,7 @@ export class DefaultComponents implements Components, Startable { this._started = true } - async afterStart () { + async afterStart (): Promise { await Promise.all( Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => { if (startable.afterStart != null) { @@ -125,7 +125,7 @@ export class DefaultComponents implements Components, Startable { ) } - async beforeStop () { + async beforeStop (): Promise { await Promise.all( Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => { if (startable.beforeStop != null) { @@ -135,7 +135,7 @@ export class DefaultComponents implements Components, Startable { ) } - async stop () { + async stop (): Promise { await Promise.all( Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => { await startable.stop() @@ -145,7 +145,7 @@ export class DefaultComponents implements Components, Startable { this._started = false } - async afterStop () { + async afterStop (): Promise { await Promise.all( Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => { if (startable.afterStop != null) { diff --git a/src/connection-manager/auto-dialler.ts b/src/connection-manager/auto-dialler.ts index 46fda1faf3..f35337a65e 100644 --- a/src/connection-manager/auto-dialler.ts +++ b/src/connection-manager/auto-dialler.ts @@ -58,14 +58,14 @@ export class AutoDialler implements Startable { log('options: %j', this.options) } - isStarted () { + isStarted (): boolean { return this.running } /** * Starts the auto dialer */ - async start () { + async start (): Promise { if (!this.options.enabled) { log('not enabled') return @@ -83,7 +83,7 @@ export class AutoDialler implements Startable { /** * Stops the auto dialler */ - async stop () { + async stop (): Promise { if (!this.options.enabled) { log('not enabled') return @@ -98,7 +98,7 @@ export class AutoDialler implements Startable { log('stopped') } - async _autoDial () { + async _autoDial (): Promise { if (this.autoDialTimeout != null) { this.autoDialTimeout.clear() } diff --git a/src/connection-manager/dialer/dial-request.ts b/src/connection-manager/dialer/dial-request.ts index 77d1a306a9..d0034518b3 100644 --- a/src/connection-manager/dialer/dial-request.ts +++ b/src/connection-manager/dialer/dial-request.ts @@ -138,7 +138,7 @@ export class DialRequest { c.abort() } }) - tokens.forEach(token => this.dialer.releaseToken(token)) // release tokens back to the dialer + tokens.forEach(token => { this.dialer.releaseToken(token) }) // release tokens back to the dialer } } } diff --git a/src/connection-manager/dialer/index.ts b/src/connection-manager/dialer/index.ts index fc1365b303..a7ec43ca62 100644 --- a/src/connection-manager/dialer/index.ts +++ b/src/connection-manager/dialer/index.ts @@ -117,18 +117,18 @@ export class DefaultDialer implements Startable, Dialer { } } - isStarted () { + isStarted (): boolean { return this.started } - async start () { + async start (): Promise { this.started = true } /** * Clears any pending dials */ - async stop () { + async stop (): Promise { this.started = false for (const dial of this.pendingDials.values()) { @@ -367,14 +367,14 @@ export class DefaultDialer implements Startable, Dialer { return pendingDial } - getTokens (num: number) { + getTokens (num: number): number[] { const total = Math.min(num, this.maxDialsPerPeer, this.tokens.length) const tokens = this.tokens.splice(0, total) log('%d tokens request, returning %d, %d remaining', num, total, this.tokens.length) return tokens } - releaseToken (token: number) { + releaseToken (token: number): void { // Guard against duplicate releases if (this.tokens.includes(token)) { return diff --git a/src/connection-manager/index.ts b/src/connection-manager/index.ts index c22e59ec5b..c09929ecb4 100644 --- a/src/connection-manager/index.ts +++ b/src/connection-manager/index.ts @@ -211,7 +211,7 @@ export class DefaultConnectionManager extends EventEmitter { // track inbound/outbound connections this.components.metrics?.registerMetricGroup('libp2p_connection_manager_connections', { calculate: () => { @@ -307,7 +307,7 @@ export class DefaultConnectionManager extends EventEmitter { this.components.upgrader.addEventListener('connection', this.onConnect) this.components.upgrader.addEventListener('connectionEnd', this.onDisconnect) @@ -352,7 +352,7 @@ export class DefaultConnectionManager extends EventEmitter { // if we are still dialing KEEP_ALIVE peers, abort those dials this.connectOnStartupController?.abort() this.components.upgrader.removeEventListener('connection', this.onConnect) @@ -362,7 +362,7 @@ export class DefaultConnectionManager extends EventEmitter { this.latencyMonitor?.removeEventListener('data', this._onLatencyMeasure) this.latencyMonitor?.stop() @@ -374,7 +374,7 @@ export class DefaultConnectionManager extends EventEmitter { // Close all connections we're tracking const tasks: Array> = [] for (const connectionList of this.connections.values()) { @@ -394,7 +394,7 @@ export class DefaultConnectionManager extends EventEmitter) { + onConnect (evt: CustomEvent): void { void this._onConnect(evt).catch(err => { log.error(err) }) @@ -403,7 +403,7 @@ export class DefaultConnectionManager extends EventEmitter) { + async _onConnect (evt: CustomEvent): Promise { const { detail: connection } = evt if (!this.started) { @@ -436,7 +436,7 @@ export class DefaultConnectionManager extends EventEmitter) { + onDisconnect (evt: CustomEvent): void { const { detail: connection } = evt if (!this.started) { @@ -542,7 +542,7 @@ export class DefaultConnectionManager extends EventEmitter { - return await connection.close() + await connection.close() }) ) } @@ -569,7 +569,7 @@ export class DefaultConnectionManager extends EventEmitter) { + _onLatencyMeasure (evt: CustomEvent): void { const { detail: summary } = evt this._checkMaxLimit('maxEventLoopDelay', summary.avgMs, 1) @@ -581,7 +581,7 @@ export class DefaultConnectionManager extends EventEmitter { const limit = this.opts[name] if (limit == null) { @@ -600,7 +600,7 @@ export class DefaultConnectionManager extends EventEmitter { const connections = this.getConnections() const peerValues = new PeerMap() @@ -726,7 +726,7 @@ export class DefaultConnectionManager extends EventEmitter { this.latencyData = this.initLatencyData() } - start () { + start (): void { // We check for isBrowser because of browsers set max rates of timeouts when a page is hidden, // so we fall back to another library // See: http://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs @@ -172,7 +172,7 @@ export class LatencyMonitor extends EventEmitter { } } - stop () { + stop (): void { this._stopTimers() } @@ -181,7 +181,7 @@ export class LatencyMonitor extends EventEmitter { * * @private */ - _startTimers () { + _startTimers (): void { // Timer already started, ignore this if (this.checkLatencyID != null) { return @@ -190,7 +190,7 @@ export class LatencyMonitor extends EventEmitter { this.checkLatency() if (this.dataEmitIntervalMs != null) { - this.emitIntervalID = setInterval(() => this._emitSummary(), this.dataEmitIntervalMs) + this.emitIntervalID = setInterval(() => { this._emitSummary() }, this.dataEmitIntervalMs) if (typeof this.emitIntervalID.unref === 'function') { this.emitIntervalID.unref() // Doesn't block exit } @@ -202,7 +202,7 @@ export class LatencyMonitor extends EventEmitter { * * @private */ - _stopTimers () { + _stopTimers (): void { if (this.checkLatencyID != null) { clearTimeout(this.checkLatencyID) this.checkLatencyID = undefined @@ -218,7 +218,7 @@ export class LatencyMonitor extends EventEmitter { * * @private */ - _emitSummary () { + _emitSummary (): void { const summary = this.getSummary() if (summary.events > 0) { this.dispatchEvent(new CustomEvent('data', { @@ -254,7 +254,7 @@ export class LatencyMonitor extends EventEmitter { * Randomly calls an async fn every roughly latencyCheckIntervalMs (plus some randomness). If no async fn is found, * it will simply report on event loop latency. */ - checkLatency () { + checkLatency (): void { // Randomness is needed to avoid alignment by accident to regular things in the event loop const randomness = (Math.random() * this.latencyCheckMultiply) - this.latencyCheckSubtract @@ -264,7 +264,7 @@ export class LatencyMonitor extends EventEmitter { startTime: this.now() } - const cb = () => { + const cb = (): void => { // We are already stopped, ignore this datapoint if (this.checkLatencyID == null) { return @@ -314,6 +314,6 @@ export class LatencyMonitor extends EventEmitter { } } -function isBrowser () { +function isBrowser (): boolean { return typeof globalThis.window !== 'undefined' } diff --git a/src/connection-manager/visibility-change-emitter.ts b/src/connection-manager/visibility-change-emitter.ts index 1e0d2ab61e..3c103e28f2 100644 --- a/src/connection-manager/visibility-change-emitter.ts +++ b/src/connection-manager/visibility-change-emitter.ts @@ -60,7 +60,7 @@ export class VisibilityChangeEmitter extends EventEmitter