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

deps(dev): bump aegir from 37.12.1 to 38.1.7 #219

Merged
merged 2 commits into from
Mar 9, 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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@
"it-ws": "^5.0.6",
"p-defer": "^4.0.0",
"p-timeout": "^6.0.0",
"wherearewe": "^2.0.1"
"wherearewe": "^2.0.1",
"ws": "^8.12.1"
},
"devDependencies": {
"@libp2p/interface-mocks": "^8.0.2",
"@libp2p/interface-transport-compliance-tests": "^3.0.0",
"@types/ws": "^8.2.2",
"aegir": "^37.5.3",
"aegir": "^38.1.7",
"is-loopback-addr": "^2.0.1",
"it-all": "^2.0.0",
"it-drain": "^2.0.0",
"it-goodbye": "^4.0.1",
"it-pipe": "^2.0.3",
"it-stream-types": "^1.0.4",
"it-take": "^2.0.0",
"p-wait-for": "^5.0.0",
"uint8arraylist": "^2.3.2",
"uint8arrays": "^4.0.2"
Expand Down
8 changes: 4 additions & 4 deletions src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CODE_WSS
} from './constants.js'

export function all (multiaddrs: Multiaddr[]) {
export function all (multiaddrs: Multiaddr[]): Multiaddr[] {
return multiaddrs.filter((ma) => {
if (ma.protoCodes().includes(CODE_CIRCUIT)) {
return false
Expand All @@ -21,7 +21,7 @@ export function all (multiaddrs: Multiaddr[]) {
})
}

export function wss (multiaddrs: Multiaddr[]) {
export function wss (multiaddrs: Multiaddr[]): Multiaddr[] {
return multiaddrs.filter((ma) => {
if (ma.protoCodes().includes(CODE_CIRCUIT)) {
return false
Expand All @@ -33,7 +33,7 @@ export function wss (multiaddrs: Multiaddr[]) {
})
}

export function dnsWss (multiaddrs: Multiaddr[]) {
export function dnsWss (multiaddrs: Multiaddr[]): Multiaddr[] {
return multiaddrs.filter((ma) => {
if (ma.protoCodes().includes(CODE_CIRCUIT)) {
return false
Expand All @@ -46,7 +46,7 @@ export function dnsWss (multiaddrs: Multiaddr[]) {
})
}

export function dnsWsOrWss (multiaddrs: Multiaddr[]) {
export function dnsWsOrWss (multiaddrs: Multiaddr[]): Multiaddr[] {
return multiaddrs.filter((ma) => {
if (ma.protoCodes().includes(CODE_CIRCUIT)) {
return false
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isBrowser, isWebWorker } from 'wherearewe'
import { createListener } from './listener.js'
import { socketToMaConn } from './socket-to-conn.js'
import * as filters from './filters.js'
import { Transport, MultiaddrFilter, symbol, CreateListenerOptions, DialOptions } from '@libp2p/interface-transport'
import { Transport, MultiaddrFilter, symbol, CreateListenerOptions, DialOptions, Listener } from '@libp2p/interface-transport'
import type { Connection } from '@libp2p/interface-connection'
import type { AbortOptions } from '@libp2p/interfaces'
import type { Multiaddr } from '@multiformats/multiaddr'
Expand All @@ -30,7 +30,7 @@ class WebSockets implements Transport {
this.init = init
}

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

Expand Down Expand Up @@ -59,7 +59,7 @@ class WebSockets implements Transport {
log('dialing %s:%s', cOpts.host, cOpts.port)

const errorPromise = pDefer()
const errfn = (err: any) => {
const errfn = (err: any): void => {
log.error('connection error:', err)

errorPromise.reject(err)
Expand Down Expand Up @@ -92,7 +92,7 @@ class WebSockets implements Transport {

// Already aborted?
if (options?.signal?.aborted === true) {
return onAbort()
onAbort(); return
}

options?.signal?.addEventListener('abort', onAbort)
Expand All @@ -115,7 +115,7 @@ class WebSockets implements Transport {
* anytime a new incoming Connection has been successfully upgraded via
* `upgrader.upgradeInbound`
*/
createListener (options: CreateListenerOptions) {
createListener (options: CreateListenerOptions): Listener {
return createListener({ ...this.init, ...options })
}

Expand All @@ -124,7 +124,7 @@ class WebSockets implements Transport {
* By default, in a browser environment only DNS+WSS multiaddr is accepted,
* while in a Node.js environment DNS+{WS, WSS} multiaddrs are accepted.
*/
filter (multiaddrs: Multiaddr[]) {
filter (multiaddrs: Multiaddr[]): Multiaddr[] {
multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs]

if (this.init?.filter != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/listener.browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Listener } from '@libp2p/interface-transport'

export function createListener () {
export function createListener (): Listener {
throw new Error('WebSocket Servers can not be created in the browser!')
}
10 changes: 5 additions & 5 deletions src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,26 @@ class WebSocketListener extends EventEmitter<ListenerEvents> implements Listener
})
}

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

if (this.server.address() == null) {
// not listening, close will throw an error
return
}

return await this.server.close()
await this.server.close()
}

async listen (ma: Multiaddr) {
async listen (ma: Multiaddr): Promise<void> {
this.listeningMultiaddr = ma

await this.server.listen(ma.toOptions())
}

getAddrs () {
getAddrs (): Multiaddr[] {
const multiaddrs = []
const address = this.server.address()

Expand Down
7 changes: 4 additions & 3 deletions test/compliance.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import http from 'http'
import { webSockets } from '../src/index.js'
import * as filters from '../src/filters.js'
import type { WebSocketListenerInit } from '../src/listener.js'
import type { Listener } from '@libp2p/interface-transport'

describe('interface-transport compliance', () => {
tests({
Expand All @@ -19,17 +20,17 @@ describe('interface-transport compliance', () => {
]

let delayMs = 0
const delayedCreateListener = (options: WebSocketListenerInit) => {
const delayedCreateListener = (options: WebSocketListenerInit): Listener => {
// A server that will delay the upgrade event by delayMs
options.server = new Proxy(http.createServer(), {
get (server, prop) {
if (prop === 'on') {
return (event: string, handler: (...args: any[]) => void) => {
server.on(event, (...args) => {
if (event !== 'upgrade' || delayMs === 0) {
return handler(...args)
handler(...args); return
}
setTimeout(() => handler(...args), delayMs)
setTimeout(() => { handler(...args) }, delayMs)
})
}
}
Expand Down
48 changes: 24 additions & 24 deletions test/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { Uint8ArrayList } from 'uint8arraylist'
import type { Source } from 'it-stream-types'
import './compliance.node.js'

async function * toBuffers (source: Source<Uint8ArrayList>) {
async function * toBuffers (source: Source<Uint8ArrayList>): AsyncGenerator<Uint8Array, void, undefined> {
for await (const list of source) {
yield * list
}
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('listen', () => {
const listener = ws.createListener({
handler: (conn) => {
void conn.newStream([protocol]).then(async (stream) => {
return await pipe(stream, stream)
await pipe(stream, stream)
})
},
upgrader
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('listen', () => {
})

afterEach(async () => {
return await listener.close()
await listener.close()
})

it('listen, check for promise', async () => {
Expand All @@ -108,14 +108,14 @@ describe('listen', () => {
const dumbServer = http.createServer()
await new Promise<void>(resolve => dumbServer.listen(ma.toOptions().port, resolve))
await expect(listener.listen(ma)).to.eventually.rejectedWith('listen EADDRINUSE')
await new Promise<void>(resolve => dumbServer.close(() => resolve()))
await new Promise<void>(resolve => dumbServer.close(() => { resolve() }))
})

it('listen, check for the close event', (done) => {
const listener = ws.createListener({ upgrader })

listener.addEventListener('listening', () => {
listener.addEventListener('close', () => done())
listener.addEventListener('close', () => { done() })
void listener.close()
})

Expand All @@ -134,7 +134,7 @@ describe('listen', () => {
listener = ws.createListener({ upgrader })

await listener.listen(ma)
const addrs = await listener.getAddrs()
const addrs = listener.getAddrs()
expect(addrs.map((a) => a.toOptions().port)).to.not.include(0)
})

Expand All @@ -143,14 +143,14 @@ describe('listen', () => {
listener = ws.createListener({ upgrader })

await listener.listen(ma)
const addrs = await listener.getAddrs()
const addrs = listener.getAddrs()
expect(addrs.map((a) => a.toOptions().host)).to.not.include('0.0.0.0')
})

it('getAddrs', async () => {
listener = ws.createListener({ upgrader })
await listener.listen(ma)
const addrs = await listener.getAddrs()
const addrs = listener.getAddrs()
expect(addrs.length).to.equal(1)
expect(addrs[0]).to.deep.equal(ma)
})
Expand All @@ -159,7 +159,7 @@ describe('listen', () => {
const addr = multiaddr('/ip4/127.0.0.1/tcp/0/ws')
listener = ws.createListener({ upgrader })
await listener.listen(addr)
const addrs = await listener.getAddrs()
const addrs = listener.getAddrs()
expect(addrs.length).to.equal(1)
expect(addrs.map((a) => a.toOptions().port)).to.not.include('0')
})
Expand All @@ -168,15 +168,15 @@ describe('listen', () => {
const addr = multiaddr('/ip4/0.0.0.0/tcp/47382/ws')
listener = ws.createListener({ upgrader })
await listener.listen(addr)
const addrs = await listener.getAddrs()
const addrs = listener.getAddrs()
expect(addrs.map((a) => a.toOptions().host)).to.not.include('0.0.0.0')
})

it('getAddrs from listening on 0.0.0.0 and port 0', async () => {
const addr = multiaddr('/ip4/0.0.0.0/tcp/0/ws')
listener = ws.createListener({ upgrader })
await listener.listen(addr)
const addrs = await listener.getAddrs()
const addrs = listener.getAddrs()
expect(addrs.map((a) => a.toOptions().host)).to.not.include('0.0.0.0')
expect(addrs.map((a) => a.toOptions().port)).to.not.include('0')
})
Expand All @@ -186,7 +186,7 @@ describe('listen', () => {
listener = ws.createListener({ upgrader })

await listener.listen(ma)
const addrs = await listener.getAddrs()
const addrs = listener.getAddrs()
expect(addrs.length).to.equal(1)
expect(addrs[0]).to.deep.equal(ma)
})
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('listen', () => {
const listener = ws.createListener({ upgrader })

listener.addEventListener('listening', () => {
listener.addEventListener('close', () => done())
listener.addEventListener('close', () => { done() })
void listener.close()
})

Expand All @@ -245,10 +245,10 @@ describe('dial', () => {
beforeEach(async () => {
ws = webSockets()()
listener = ws.createListener({ upgrader })
return await listener.listen(ma)
await listener.listen(ma)
})

afterEach(async () => await listener.close())
afterEach(async () => { await listener.close() })

it('dial', async () => {
const conn = await ws.dial(ma, { upgrader })
Expand Down Expand Up @@ -313,15 +313,15 @@ describe('dial', () => {
listener = ws.createListener({
handler: (conn) => {
void conn.newStream([protocol]).then(async (stream) => {
return await pipe(stream, stream)
await pipe(stream, stream)
})
},
upgrader
})
return await listener.listen(ma)
await listener.listen(ma)
})

afterEach(async () => await listener.close())
afterEach(async () => { await listener.close() })

it('dial', async () => {
const addrs = listener.getAddrs().filter((ma) => {
Expand Down Expand Up @@ -359,17 +359,17 @@ describe('dial', () => {
listener = ws.createListener({
handler: (conn) => {
void conn.newStream([protocol]).then(async (stream) => {
return await pipe(stream, stream)
await pipe(stream, stream)
})
},
upgrader
})
return await listener.listen(ma)
await listener.listen(ma)
})

afterEach(async () => {
await listener.close()
await server.close()
server.close()
})

it('should listen on wss address', () => {
Expand Down Expand Up @@ -401,15 +401,15 @@ describe('dial', () => {
listener = ws.createListener({
handler: (conn) => {
void conn.newStream([protocol]).then(async (stream) => {
return await pipe(stream, stream)
await pipe(stream, stream)
})
},
upgrader
})
return await listener.listen(ma)
await listener.listen(ma)
})

afterEach(async () => await listener.close())
afterEach(async () => { await listener.close() })

it('dial ip6', async () => {
const conn = await ws.dial(ma, { upgrader })
Expand Down