Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade aegir #1566

Merged
merged 21 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/circuit/server/advert-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class AdvertService extends EventEmitter<AdvertServiceEvents> 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
}

Expand Down
13 changes: 7 additions & 6 deletions src/circuit/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -247,7 +248,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> 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 })
Expand All @@ -266,12 +267,12 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> 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)
}
}

Expand Down Expand Up @@ -325,7 +326,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> 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
Expand Down Expand Up @@ -368,7 +369,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> 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)
}
Expand Down Expand Up @@ -408,7 +409,7 @@ class CircuitRelayServer extends EventEmitter<RelayServerEvents> implements Star
stream.close()
}

get reservations () {
get reservations (): PeerMap<RelayReservation> {
return this.reservationStore.reservations
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/circuit/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down Expand Up @@ -208,7 +208,7 @@ class CircuitRelayTransport implements Transport {
destinationAddr, relayAddr, ma,
disconnectOnFailure
}: ConnectOptions
) {
): Promise<Connection> {
try {
const pbstr = pbStream(stream)
const hopstr = pbstr.pb(HopMessage)
Expand Down
2 changes: 1 addition & 1 deletion src/circuit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function * countStreamBytes (source: Source<Uint8Array | Uint8ArrayList>,
}

const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Required<Limit>): void => {
function abortStreams (err: Error) {
function abortStreams (err: Error): void {
src.abort(err)
dst.abort(err)
clearTimeout(timeout)
Expand Down
14 changes: 7 additions & 7 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await Promise.all(
Object.values(this).filter(obj => isStartable(obj)).map(async (startable: Startable) => {
if (startable.beforeStart != null) {
Expand All @@ -105,7 +105,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 @@ -115,7 +115,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 @@ -125,7 +125,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 @@ -135,7 +135,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 @@ -145,7 +145,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 @@ -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<void> {
if (!this.options.enabled) {
log('not enabled')
return
Expand All @@ -83,7 +83,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 @@ -98,7 +98,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 @@ -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
}
}
}
10 changes: 5 additions & 5 deletions src/connection-manager/dialer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,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 @@ -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
Expand Down
Loading