Skip to content

Commit

Permalink
chore: upgrade aegir to 38.1.2 (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad authored Feb 20, 2023
1 parent ff42363 commit f86328c
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 67 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@
"@libp2p/peer-id": "^2.0.0",
"@multiformats/multiaddr": "^11.0.0",
"@types/multicast-dns": "^7.2.1",
"multicast-dns": "^7.2.0",
"multiformats": "^11.0.0"
"dns-packet": "^5.4.0",
"multicast-dns": "^7.2.0"
},
"devDependencies": {
"@libp2p/interface-address-manager": "^2.0.0",
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
"aegir": "^37.9.1",
"aegir": "^38.1.2",
"delay": "^5.0.0",
"p-defer": "^4.0.0",
"p-wait-for": "^5.0.0",
Expand Down
14 changes: 6 additions & 8 deletions src/compat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,26 @@ export class GoMulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements
return true
}

get [Symbol.toStringTag] () {
get [Symbol.toStringTag] (): '@libp2p/go-mdns' {
return '@libp2p/go-mdns'
}

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

async start () {
async start (): Promise<void> {
if (this.isStarted()) {
return
}

this._started = true

await Promise.all([
this._responder.start(),
this._querier.start()
])
await this._responder.start()
await this._querier.start()
}

async stop () {
async stop (): Promise<void> {
if (!this.isStarted()) {
return
}
Expand Down
16 changes: 8 additions & 8 deletions src/compat/querier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDi
return true
}

get [Symbol.toStringTag] () {
get [Symbol.toStringTag] (): '@libp2p/go-mdns-querier' {
return '@libp2p/go-mdns-querier'
}

isStarted () {
isStarted (): boolean {
return Boolean(this._handle)
}

start () {
async start (): Promise<void> {
this._handle = periodically(() => {
// Create a querier that queries multicast but gets responses unicast
const mdns = MDNS({ multicast: false, interface: '0.0.0.0', port: 0 })
Expand All @@ -84,7 +84,7 @@ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDi
return {
stop: async () => {
mdns.removeListener('response', this._onResponse)
return await new Promise(resolve => mdns.destroy(resolve))
await new Promise(resolve => { mdns.destroy(resolve as () => void) })
}
}
}, {
Expand All @@ -93,7 +93,7 @@ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDi
})
}

_onResponse (event: ResponsePacket, info: RemoteInfo) {
_onResponse (event: ResponsePacket, info: RemoteInfo): void {
log.trace('received mDNS query response')
const answers = event.answers ?? []

Expand All @@ -116,7 +116,7 @@ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDi
}))
}

async stop () {
async stop (): Promise<void> {
if (this._handle != null) {
await this._handle.stop()
}
Expand All @@ -128,12 +128,12 @@ export class Querier extends EventEmitter<PeerDiscoveryEvents> implements PeerDi
* running it again. `fn` must return an object with a stop function, which is
* called when the period expires.
*/
function periodically (fn: () => Handle, options: { period: number, interval: number }) {
function periodically (fn: () => Handle, options: { period: number, interval: number }): { stop: () => Promise<void> } {
let handle: Handle | null
let timeoutId: NodeJS.Timer
let stopped = false

const reRun = () => {
const reRun = (): void => {
handle = fn()
timeoutId = setTimeout(() => {
if (handle != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/compat/responder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export class Responder {
this._onQuery = this._onQuery.bind(this)
}

start () {
async start (): Promise<void> {
this._mdns = MDNS()
this._mdns.on('query', this._onQuery)
}

_onQuery (event: QueryPacket, info: RemoteInfo) {
_onQuery (event: QueryPacket, info: RemoteInfo): void {
const addresses = this.components.addressManager.getAddresses().reduce<MultiaddrObject[]>((acc, addr) => {
addr = addr.decapsulateCode(protocols('p2p').code)

Expand Down Expand Up @@ -101,10 +101,10 @@ export class Responder {
}
}

stop () {
async stop (): Promise<void> {
if (this._mdns != null) {
this._mdns.removeListener('query', this._onQuery)
return new Promise<void>(resolve => {
await new Promise<void>(resolve => {
if (this._mdns != null) {
this._mdns.destroy(resolve)
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDisc
return true
}

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

isStarted () {
isStarted (): boolean {
return Boolean(this.mdns)
}

Expand All @@ -79,7 +79,7 @@ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDisc
*
* @returns {void}
*/
async start () {
async start (): Promise<void> {
if (this.mdns != null) {
return
}
Expand All @@ -95,7 +95,7 @@ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDisc
}
}

_onMdnsQuery (event: multicastDNS.QueryPacket) {
_onMdnsQuery (event: multicastDNS.QueryPacket): void {
if (this.mdns == null) {
return
}
Expand All @@ -104,7 +104,7 @@ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDisc
query.gotQuery(event, this.mdns, this.components.peerId, this.components.addressManager.getAddresses(), this.serviceTag, this.broadcast)
}

_onMdnsResponse (event: multicastDNS.ResponsePacket) {
_onMdnsResponse (event: multicastDNS.ResponsePacket): void {
log.trace('received mDNS query response')

try {
Expand All @@ -122,7 +122,7 @@ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDisc
}
}

_onPeer (evt: CustomEvent<PeerInfo>) {
_onPeer (evt: CustomEvent<PeerInfo>): void {
if (this.mdns == null) {
return
}
Expand All @@ -137,7 +137,7 @@ class MulticastDNS extends EventEmitter<PeerDiscoveryEvents> implements PeerDisc
*
* @returns {Promise}
*/
async stop () {
async stop (): Promise<void> {
if (this.mdns == null) {
return
}
Expand Down
8 changes: 4 additions & 4 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { SrvAnswer, StringAnswer, TxtAnswer, Answer } from 'dns-packet'

const log = logger('libp2p:mdns:query')

export function queryLAN (mdns: MulticastDNS, serviceTag: string, interval: number) {
const query = () => {
export function queryLAN (mdns: MulticastDNS, serviceTag: string, interval: number): NodeJS.Timer {
const query = (): void => {
log('query', serviceTag)

mdns.query({
Expand Down Expand Up @@ -98,7 +98,7 @@ export function gotResponse (rsp: ResponsePacket, localPeerId: PeerId, serviceTa
}
}

export function gotQuery (qry: QueryPacket, mdns: MulticastDNS, peerId: PeerId, multiaddrs: Multiaddr[], serviceTag: string, broadcast: boolean) {
export function gotQuery (qry: QueryPacket, mdns: MulticastDNS, peerId: PeerId, multiaddrs: Multiaddr[], serviceTag: string, broadcast: boolean): void {
if (!broadcast) {
log('not responding to mDNS query as broadcast mode is false')
return
Expand Down Expand Up @@ -139,7 +139,7 @@ export function gotQuery (qry: QueryPacket, mdns: MulticastDNS, peerId: PeerId,
data: {
priority: 10,
weight: 1,
port: port,
port,
target: os.hostname()
}
})
Expand Down
8 changes: 4 additions & 4 deletions test/compat/go-multicast-dns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { PeerInfo } from '@libp2p/interface-peer-info'

let port = 20000

async function createGoMulticastDNS () {
async function createGoMulticastDNS (): Promise<{ mdns: GoMulticastDNS, components: any }> {
const peerId = await createEd25519PeerId()
const addressManager = stubInterface<AddressManager>()
addressManager.getAddresses.returns([
Expand All @@ -36,7 +36,7 @@ describe('GoMulticastDNS', () => {
const { mdns } = await createGoMulticastDNS()

await mdns.start()
return await mdns.stop()
await mdns.stop()
})

it('should ignore multiple start calls', async () => {
Expand All @@ -45,7 +45,7 @@ describe('GoMulticastDNS', () => {
await mdns.start()
await mdns.start()

return await mdns.stop()
await mdns.stop()
})

it('should ignore unnecessary stop calls', async () => {
Expand All @@ -62,7 +62,7 @@ describe('GoMulticastDNS', () => {
mdnsA.addEventListener('peer', (evt) => {
const { id } = evt.detail

if (!componentsB.peerId.equals(id)) {
if (componentsB.peerId.equals(id) !== true) {
return
}

Expand Down
25 changes: 12 additions & 13 deletions test/compat/querier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ describe('Querier', () => {
})

afterEach(async () => {
mdns?.destroy()
return await Promise.all([
querier?.stop(),
mdns?.destroy()
querier?.stop()
])
})

Expand Down Expand Up @@ -60,7 +60,7 @@ describe('Querier', () => {
})

it('should not emit peer for responses with non matching service tags', async () => {
return await ensureNoPeer(event => {
await ensureNoPeer(event => {
const peerServiceTagLocal = `${peerIds[1].toString()}.${SERVICE_TAG_LOCAL}`
const bogusServiceTagLocal = '_ifps-discovery._udp'

Expand All @@ -75,7 +75,7 @@ describe('Querier', () => {
})

it('should not emit peer for responses with missing TXT record', async () => {
return await ensureNoPeer(event => {
await ensureNoPeer(event => {
const peerServiceTagLocal = `${peerIds[1].toString()}.${SERVICE_TAG_LOCAL}`

return [{
Expand All @@ -89,7 +89,7 @@ describe('Querier', () => {
})

it('should not emit peer for responses with missing peer ID in TXT record', async () => {
return await ensureNoPeer(event => {
await ensureNoPeer(event => {
const peerServiceTagLocal = `${peerIds[1].toString()}.${SERVICE_TAG_LOCAL}`

return [{
Expand All @@ -109,7 +109,7 @@ describe('Querier', () => {
})

it('should not emit peer for responses to self', async () => {
return await ensureNoPeer(event => {
await ensureNoPeer(event => {
const peerServiceTagLocal = `${peerIds[1].toString()}.${SERVICE_TAG_LOCAL}`

return [{
Expand All @@ -128,9 +128,8 @@ describe('Querier', () => {
})
})

// TODO: unskip when https://github.com/libp2p/js-peer-id/issues/83 is resolved
it('should not emit peer for responses with invalid peer ID in TXT record', async () => {
return await ensureNoPeer(event => {
await ensureNoPeer(event => {
const peerServiceTagLocal = `${peerIds[1].toString()}.${SERVICE_TAG_LOCAL}`

return [{
Expand All @@ -150,7 +149,7 @@ describe('Querier', () => {
})

it('should not emit peer for responses with missing SRV record', async () => {
return await ensureNoPeer(event => {
await ensureNoPeer(event => {
const peerServiceTagLocal = `${peerIds[1].toString()}.${SERVICE_TAG_LOCAL}`

return [{
Expand All @@ -170,7 +169,7 @@ describe('Querier', () => {
})

it('should emit peer for responses even if no multiaddrs', async () => {
return await ensurePeer(event => {
await ensurePeer(event => {
const peerServiceTagLocal = `${peerIds[1].toString()}.${SERVICE_TAG_LOCAL}`

return [{
Expand Down Expand Up @@ -201,7 +200,7 @@ describe('Querier', () => {
})

it('should emit peer for responses with valid multiaddrs', async () => {
return await ensurePeer(event => {
await ensurePeer(event => {
const peerServiceTagLocal = `${peerIds[1].toString()}.${SERVICE_TAG_LOCAL}`

return [{
Expand Down Expand Up @@ -242,7 +241,7 @@ describe('Querier', () => {
*
* @param {Function} getResponse - Given a query, construct a response to test the querier
*/
async function ensurePeer (getResponse: (event: QueryPacket, info: RemoteInfo) => Answer[]) {
async function ensurePeer (getResponse: (event: QueryPacket, info: RemoteInfo) => Answer[]): Promise<void> {
const querier = new Querier({ peerId: peerIds[0] })
mdns = MDNS()

Expand Down Expand Up @@ -278,7 +277,7 @@ describe('Querier', () => {
*
* @param {Function} getResponse - Given a query, construct a response to test the querier
*/
async function ensureNoPeer (getResponse: (event: QueryPacket, info: RemoteInfo) => Answer[]) {
async function ensureNoPeer (getResponse: (event: QueryPacket, info: RemoteInfo) => Answer[]): Promise<void> {
const querier = new Querier({ peerId: peerIds[0] })
mdns = MDNS()

Expand Down
Loading

0 comments on commit f86328c

Please sign in to comment.