Skip to content

Commit

Permalink
chore: upgrade aegir (libp2p#1566)
Browse files Browse the repository at this point in the history
Updates aegir, fixes all linting and dep issues.

Co-authored-by: achingbrain <alex@achingbrain.net>
  • Loading branch information
2 people authored and prathamesh0 committed Mar 24, 2023
1 parent f2111a1 commit 2061bb2
Show file tree
Hide file tree
Showing 50 changed files with 221 additions and 216 deletions.
3 changes: 2 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 5 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,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",
Expand All @@ -145,7 +143,6 @@
"it-pair": "^2.0.2",
"it-pipe": "^2.0.3",
"it-pushable": "^3.1.2",
"it-sort": "^2.0.0",
"it-stream-types": "^1.0.4",
"merge-options": "^3.0.4",
"multiformats": "^11.0.0",
Expand Down Expand Up @@ -176,31 +173,28 @@
"@libp2p/interface-connection-compliance-tests": "^2.0.3",
"@libp2p/interface-connection-encrypter-compliance-tests": "^4.0.0",
"@libp2p/interface-mocks": "9.1.3",
"@libp2p/interop": "^4.0.0",
"@libp2p/interop": "^5.0.0",
"@libp2p/kad-dht": "^7.0.0",
"@libp2p/mdns": "^6.0.0",
"@libp2p/mplex": "^7.0.0",
"@libp2p/pubsub": "^6.0.0",
"@libp2p/tcp": "^6.0.0",
"@libp2p/topology": "^4.0.0",
"@libp2p/webrtc-star": "^6.0.0",
"@libp2p/websockets": "^5.0.0",
"@types/node-forge": "^1.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": "^6.1.0",
"go-libp2p": "^0.0.6",
"it-to-buffer": "^3.0.0",
"execa": "^7.0.0",
"go-libp2p": "^1.0.1",
"it-to-buffer": "^3.0.1",
"npm-run-all": "^4.1.5",
"p-defer": "^4.0.0",
"p-event": "^5.0.1",
"p-times": "^4.0.0",
"p-wait-for": "^5.0.0",
"protons": "^6.0.0",
"sinon": "^15.0.1",
"sinon-ts": "^1.0.0"
},
Expand Down
14 changes: 7 additions & 7 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ export class DefaultComponents implements Components, Startable {
this._dialer = init.dialer
}

isStarted () {
isStarted (): boolean {
return this._started
}

async beforeStart () {
async beforeStart (): Promise<void> {
await Promise.all(
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
if (startable.beforeStart != null) {
Expand All @@ -104,7 +104,7 @@ export class DefaultComponents implements Components, Startable {
)
}

async start () {
async start (): Promise<void> {
await Promise.all(
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
await startable.start()
Expand All @@ -114,7 +114,7 @@ export class DefaultComponents implements Components, Startable {
this._started = true
}

async afterStart () {
async afterStart (): Promise<void> {
await Promise.all(
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
if (startable.afterStart != null) {
Expand All @@ -124,7 +124,7 @@ export class DefaultComponents implements Components, Startable {
)
}

async beforeStop () {
async beforeStop (): Promise<void> {
await Promise.all(
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
if (startable.beforeStop != null) {
Expand All @@ -134,7 +134,7 @@ export class DefaultComponents implements Components, Startable {
)
}

async stop () {
async stop (): Promise<void> {
await Promise.all(
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
await startable.stop()
Expand All @@ -144,7 +144,7 @@ export class DefaultComponents implements Components, Startable {
this._started = false
}

async afterStop () {
async afterStop (): Promise<void> {
await Promise.all(
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
if (startable.afterStop != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/connection-manager/auto-dialler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,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<void> {
if (!this.options.enabled) {
log('not enabled')
return
Expand All @@ -87,7 +87,7 @@ export class AutoDialler implements Startable {
/**
* Stops the auto dialler
*/
async stop () {
async stop (): Promise<void> {
if (!this.options.enabled) {
log('not enabled')
return
Expand All @@ -102,7 +102,7 @@ export class AutoDialler implements Startable {
log('stopped')
}

async _autoDial () {
async _autoDial (): Promise<void> {
if (this.autoDialTimeout != null) {
this.autoDialTimeout.clear()
}
Expand Down
2 changes: 1 addition & 1 deletion src/connection-manager/dialer/dial-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class DialRequest {
})
}

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
}
}
}
10 changes: 5 additions & 5 deletions src/connection-manager/dialer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ export class DefaultDialer implements Startable, Dialer {
}
}

isStarted () {
isStarted (): boolean {
return this.started
}

async start () {
async start (): Promise<void> {
this.started = true
}

/**
* Clears any pending dials
*/
async stop () {
async stop (): Promise<void> {
this.started = false

for (const dial of this.pendingDials.values()) {
Expand Down Expand Up @@ -356,14 +356,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
Expand Down
28 changes: 14 additions & 14 deletions src/connection-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
this.incomingPendingConnections = 0
}

isStarted () {
isStarted (): boolean {
return this.started
}

/**
* Starts the Connection Manager. If Metrics are not enabled on libp2p
* only event loop and connection limits will be monitored.
*/
async start () {
async start (): Promise<void> {
// track inbound/outbound connections
this.components.metrics?.registerMetricGroup('libp2p_connection_manager_connections', {
calculate: () => {
Expand Down Expand Up @@ -312,7 +312,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
log('started')
}

async afterStart () {
async afterStart (): Promise<void> {
this.components.upgrader.addEventListener('connection', this.onConnect)
this.components.upgrader.addEventListener('connectionEnd', this.onDisconnect)

Expand Down Expand Up @@ -357,7 +357,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
})
}

async beforeStop () {
async beforeStop (): Promise<void> {
// if we are still dialing KEEP_ALIVE peers, abort those dials
this.connectOnStartupController?.abort()
this.components.upgrader.removeEventListener('connection', this.onConnect)
Expand All @@ -367,7 +367,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
/**
* Stops the Connection Manager
*/
async stop () {
async stop (): Promise<void> {
this.latencyMonitor?.removeEventListener('data', this._onLatencyMeasure)
this.latencyMonitor?.stop()

Expand All @@ -379,7 +379,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
/**
* Cleans up the connections
*/
async _close () {
async _close (): Promise<void> {
// Close all connections we're tracking
const tasks: Array<Promise<void>> = []
for (const connectionList of this.connections.values()) {
Expand All @@ -399,7 +399,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
this.connections.clear()
}

onConnect (evt: CustomEvent<Connection>) {
onConnect (evt: CustomEvent<Connection>): void {
void this._onConnect(evt).catch(err => {
log.error(err)
})
Expand All @@ -408,7 +408,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
/**
* Tracks the incoming connection and check the connection limit
*/
async _onConnect (evt: CustomEvent<Connection>) {
async _onConnect (evt: CustomEvent<Connection>): Promise<void> {
const { detail: connection } = evt

if (!this.started) {
Expand Down Expand Up @@ -441,7 +441,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
/**
* Removes the connection from tracking
*/
onDisconnect (evt: CustomEvent<Connection>) {
onDisconnect (evt: CustomEvent<Connection>): void {
const { detail: connection } = evt

if (!this.started) {
Expand Down Expand Up @@ -543,7 +543,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven

await Promise.all(
connections.map(async connection => {
return await connection.close()
await connection.close()
})
)
}
Expand All @@ -570,7 +570,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
/**
* If the event loop is slow, maybe close a connection
*/
_onLatencyMeasure (evt: CustomEvent<SummaryObject>) {
_onLatencyMeasure (evt: CustomEvent<SummaryObject>): void {
const { detail: summary } = evt

this._checkMaxLimit('maxEventLoopDelay', summary.avgMs, 1)
Expand All @@ -582,7 +582,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
/**
* If the `value` of `name` has exceeded its limit, maybe close a connection
*/
async _checkMaxLimit (name: keyof ConnectionManagerInit, value: number, toPrune: number = 1) {
async _checkMaxLimit (name: keyof ConnectionManagerInit, value: number, toPrune: number = 1): Promise<void> {
const limit = this.opts[name]

if (limit == null) {
Expand All @@ -601,7 +601,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
* If we have more connections than our maximum, select some excess connections
* to prune based on peer value
*/
async _pruneConnections (toPrune: number) {
async _pruneConnections (toPrune: number): Promise<void> {
const connections = this.getConnections()
const peerValues = new PeerMap<number>()

Expand Down Expand Up @@ -727,7 +727,7 @@ export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEven
return false
}

afterUpgradeInbound () {
afterUpgradeInbound (): void {
this.incomingPendingConnections--
}
}
Loading

0 comments on commit 2061bb2

Please sign in to comment.