Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

deps(dev): bump aegir from 37.12.1 to 38.1.0 #243

Merged
merged 3 commits into from
Feb 1, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"devDependencies": {
"@libp2p/interface-mocks": "^8.0.1",
"@libp2p/interface-transport-compliance-tests": "^3.0.0",
"aegir": "^37.7.3",
"aegir": "^38.1.0",
"it-all": "^2.0.0",
"it-pipe": "^2.0.3",
"p-defer": "^4.0.0",
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class TCP implements Transport {
return true
}

get [Symbol.toStringTag] () {
get [Symbol.toStringTag] (): string {
return '@libp2p/tcp'
}

Expand All @@ -114,7 +114,7 @@ class TCP implements Transport {
metrics: this.metrics?.dialerEvents
})

const onAbort = () => {
const onAbort = (): void => {
maConn.close().catch(err => {
log.error('Error closing maConn after abort', err)
})
Expand All @@ -138,7 +138,7 @@ class TCP implements Transport {
return conn
}

async _connect (ma: Multiaddr, options: TCPDialOptions) {
async _connect (ma: Multiaddr, options: TCPDialOptions): Promise<Socket> {
if (options.signal?.aborted === true) {
throw new AbortError()
}
Expand All @@ -151,14 +151,14 @@ class TCP implements Transport {
log('dialing %j', cOpts)
const rawSocket = net.connect(cOpts)

const onError = (err: Error) => {
const onError = (err: Error): void => {
err.message = `connection error ${cOptsStr}: ${err.message}`
this.metrics?.dialerEvents.increment({ error: true })

done(err)
}

const onTimeout = () => {
const onTimeout = (): void => {
log('connection timeout %s', cOptsStr)
this.metrics?.dialerEvents.increment({ timeout: true })

Expand All @@ -167,20 +167,20 @@ class TCP implements Transport {
rawSocket.emit('error', err)
}

const onConnect = () => {
const onConnect = (): void => {
log('connection opened %j', cOpts)
this.metrics?.dialerEvents.increment({ connect: true })
done()
}

const onAbort = () => {
const onAbort = (): void => {
log('connection aborted %j', cOpts)
this.metrics?.dialerEvents.increment({ abort: true })
rawSocket.destroy()
done(new AbortError())
}

const done = (err?: any) => {
const done = (err?: any): void => {
rawSocket.removeListener('error', onError)
rawSocket.removeListener('timeout', onTimeout)
rawSocket.removeListener('connect', onConnect)
Expand All @@ -190,7 +190,7 @@ class TCP implements Transport {
}

if (err != null) {
return reject(err)
reject(err); return
}

resolve(rawSocket)
Expand Down
14 changes: 7 additions & 7 deletions src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const log = logger('libp2p:tcp:listener')
/**
* Attempts to close the given maConn. If a failure occurs, it will be logged
*/
async function attemptClose (maConn: MultiaddrConnection) {
async function attemptClose (maConn: MultiaddrConnection): Promise<void> {
try {
await maConn.close()
} catch (err) {
Expand Down Expand Up @@ -54,7 +54,7 @@ export interface TCPListenerMetrics {
events: CounterGroup
}

type Status = {started: false} | {
type Status = { started: false } | {
started: true
listeningAddr: Multiaddr
peerId: string | null
Expand Down Expand Up @@ -150,7 +150,7 @@ export class TCPListener extends EventEmitter<ListenerEvents> implements Listene
})
}

private onSocket (socket: net.Socket) {
private onSocket (socket: net.Socket): void {
// Avoid uncaught errors caused by unstable connections
socket.on('error', err => {
log('socket error', err)
Expand Down Expand Up @@ -230,7 +230,7 @@ export class TCPListener extends EventEmitter<ListenerEvents> implements Listene
}
}

getAddrs () {
getAddrs (): Multiaddr[] {
if (!this.status.started) {
return []
}
Expand Down Expand Up @@ -262,7 +262,7 @@ export class TCPListener extends EventEmitter<ListenerEvents> implements Listene
return addrs.map(ma => peerId != null ? ma.encapsulate(`/p2p/${peerId}`) : ma)
}

async listen (ma: Multiaddr) {
async listen (ma: Multiaddr): Promise<void> {
if (this.status.started) {
throw Error('server is already listening')
}
Expand All @@ -280,9 +280,9 @@ export class TCPListener extends EventEmitter<ListenerEvents> implements Listene
await this.netListen()
}

async close () {
async close (): Promise<void> {
await Promise.all(
Array.from(this.connections.values()).map(async maConn => await attemptClose(maConn))
Array.from(this.connections.values()).map(async maConn => { await attemptClose(maConn) })
)

// netClose already checks if server.listening
Expand Down
2 changes: 1 addition & 1 deletion src/socket-to-conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ToConnectionOptions {
* Convert a socket into a MultiaddrConnection
* https://github.com/libp2p/interface-transport#multiaddrconnection
*/
export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptions) => {
export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptions): MultiaddrConnection => {
const metrics = options.metrics
const metricPrefix = options.metricPrefix ?? ''
const inactivityTimeout = options.socketInactivityTimeout ?? SOCKET_TIMEOUT
Expand Down
10 changes: 5 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ export function multiaddrToNetConfig (addr: Multiaddr): NetConfig {
return addr.toOptions()
}

export function getMultiaddrs (proto: 'ip4' | 'ip6', ip: string, port: number) {
const toMa = (ip: string) => multiaddr(`/${proto}/${ip}/tcp/${port}`)
export function getMultiaddrs (proto: 'ip4' | 'ip6', ip: string, port: number): Multiaddr[] {
const toMa = (ip: string): Multiaddr => multiaddr(`/${proto}/${ip}/tcp/${port}`)
return (isAnyAddr(ip) ? getNetworkAddrs(ProtoFamily[proto]) : [ip]).map(toMa)
}

export function isAnyAddr (ip: string) {
export function isAnyAddr (ip: string): boolean {
return ['0.0.0.0', '::'].includes(ip)
}

const networks = os.networkInterfaces()

function getNetworkAddrs (family: string) {
const addresses = []
function getNetworkAddrs (family: string): string[] {
const addresses: string[] = []

for (const [, netAddrs] of Object.entries(networks)) {
if (netAddrs != null) {
Expand Down
6 changes: 3 additions & 3 deletions test/connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('valid localAddr and remoteAddr', () => {
let handled: (conn: Connection) => void
const handlerPromise = new Promise<Connection>(resolve => { handled = resolve })

const handler = (conn: Connection) => handled(conn)
const handler = (conn: Connection): void => { handled(conn) }

// Create a listener with the handler
const listener = transport.createListener({
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('valid localAddr and remoteAddr', () => {
let handled: (conn: Connection) => void
const handlerPromise = new Promise<Connection>(resolve => { handled = resolve })

const handler = (conn: Connection) => handled(conn)
const handler = (conn: Connection): void => { handled(conn) }

// Create a listener with the handler
const listener = transport.createListener({
Expand All @@ -76,7 +76,7 @@ describe('valid localAddr and remoteAddr', () => {

// Close the dialer with two simultaneous calls to `close`
await Promise.race([
new Promise((resolve, reject) => setTimeout(() => reject(new Error('Timed out waiting for connection close')), 500)),
new Promise((resolve, reject) => setTimeout(() => { reject(new Error('Timed out waiting for connection close')) }, 500)),
await Promise.all([
dialerConn.close(),
dialerConn.close()
Expand Down
8 changes: 4 additions & 4 deletions test/listen-dial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ describe('dial', () => {
// let multistream select finish before closing
setTimeout(() => {
void conn.close()
.then(() => handled())
.then(() => { handled() })
}, 100)
},
upgrader
Expand All @@ -272,7 +272,7 @@ describe('dial', () => {
upgrader
})
const stream = await conn.newStream([protocol])
await pipe(stream)
pipe(stream)

await handledPromise
await conn.close()
Expand Down Expand Up @@ -340,7 +340,7 @@ describe('dial', () => {

// take a long time to give us time to abort the dial
await new Promise<void>((resolve) => {
setTimeout(() => resolve(), 100)
setTimeout(() => { resolve() }, 100)
})
}

Expand All @@ -352,7 +352,7 @@ describe('dial', () => {
const abortController = new AbortController()

// abort once the upgrade process has started
void maConnPromise.promise.then(() => abortController.abort())
void maConnPromise.promise.then(() => { abortController.abort() })

await expect(transport.dial(ma, {
upgrader,
Expand Down
6 changes: 3 additions & 3 deletions test/max-connections-close.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('close server on maxConnections', () => {
return socket
}

async function assertConnectedSocket (i: number) {
async function assertConnectedSocket (i: number): Promise<net.Socket> {
const socket = createSocket()

await new Promise<void>((resolve, reject) => {
Expand All @@ -61,7 +61,7 @@ describe('close server on maxConnections', () => {
return socket
}

async function assertRefusedSocket (i: number) {
async function assertRefusedSocket (i: number): Promise<void> {
const socket = createSocket()

await new Promise<void>((resolve, reject) => {
Expand All @@ -79,7 +79,7 @@ describe('close server on maxConnections', () => {
})
}

async function assertServerConnections (connections: number) {
async function assertServerConnections (connections: number): Promise<void> {
// Expect server connections but allow time for sockets to connect or disconnect
for (let i = 0; i < 100; i++) {
// eslint-disable-next-line @typescript-eslint/dot-notation
Expand Down
2 changes: 1 addition & 1 deletion test/socket-to-conn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { toMultiaddrConnection } from '../src/socket-to-conn.js'
import os from 'os'
import type { ServerOpts, SocketConstructorOpts } from 'net'

async function setup (opts?: { server?: ServerOpts, client?: SocketConstructorOpts }) {
async function setup (opts?: { server?: ServerOpts, client?: SocketConstructorOpts }): Promise<{ server: Server, serverSocket: Socket, clientSocket: Socket }> {
const serverListening = defer()

const server = createServer(opts?.server)
Expand Down