Skip to content

Commit 99cd723

Browse files
committed
address review comments
1 parent 4a740d3 commit 99cd723

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
"test:firefox": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
9393
"test:firefox-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
9494
"test:examples": "cd examples && npm run test:all",
95-
"test:interop": "aegir test -t node -f dist/test/interop.js"
95+
"test:interop": "aegir test -t node -f dist/test/interop.js",
96+
"test:relay": "aegir test -t node -f \"./dist/test/**/auto-relay.{node,spec}.js\" --cov"
9697
},
9798
"dependencies": {
9899
"@achingbrain/nat-port-mapper": "^1.0.3",

src/circuit/client.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ export class CircuitService extends EventEmitter<CircuitServiceEvents> implement
236236
const knownHopsToDial: PeerId[] = []
237237
const peers = (await this.components.peerStore.all())
238238
// filter by a list of peers supporting RELAY_V2_HOP and ones we are not listening on
239-
.filter(({ id, protocols }) =>
240-
protocols.includes(RELAY_V2_HOP_CODEC) && !this.relays.has(id.toString()) && peersToIgnore.includes(id.toString()))
239+
.filter(({ id, protocols }) => {
240+
const idString = id.toString()
241+
return protocols.includes(RELAY_V2_HOP_CODEC) && !this.relays.has(idString) && !peersToIgnore.includes(idString)
242+
})
241243
.map(({ id }) => {
242244
const connections = this.components.connectionManager.getConnections(id)
243245
if (connections.length === 0) {
@@ -246,7 +248,6 @@ export class CircuitService extends EventEmitter<CircuitServiceEvents> implement
246248
}
247249
return [id, connections[0]]
248250
})
249-
.filter(([id, conn]) => { conn })
250251
.sort(() => Math.random() - 0.5)
251252

252253
// Check if we have known hop peers to use and attempt to listen on the already connected

src/circuit/v2/stop.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { logger } from '@libp2p/logger'
66
import { StreamHandlerV2 } from './stream-handler.js'
77
import { RELAY_V2_STOP_CODEC } from '../multicodec.js'
88
import { validateStopConnectRequest } from './validation.js'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
10+
import type { Duplex } from 'it-stream-types'
911

1012
const log = logger('libp2p:circuit:v2:stop')
1113

@@ -24,7 +26,7 @@ export async function handleStop ({
2426
// Validate the STOP request has the required input
2527
try {
2628
validateStopConnectRequest(request, streamHandler)
27-
} catch (/** @type {any} */ err) {
29+
} catch (err) {
2830
return log.error('invalid stop connect request via peer %s', connection.remotePeer, err)
2931
}
3032
log('stop request is valid')
@@ -54,21 +56,21 @@ export interface StopOptions {
5456
export async function stop ({
5557
connection,
5658
request
57-
}: StopOptions) {
59+
}: StopOptions): Promise<Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array> | undefined> {
5860
const stream = await connection.newStream([RELAY_V2_STOP_CODEC])
5961
log('starting circuit relay v2 stop request to %s', connection.remotePeer)
6062
const streamHandler = new StreamHandlerV2({ stream })
6163
streamHandler.write(StopMessage.encode(request))
6264
let response
6365
try {
6466
response = StopMessage.decode(await streamHandler.read())
65-
} catch (/** @type {any} */ err) {
67+
} catch (err) {
6668
log.error('error parsing stop message response from %s', connection.remotePeer)
6769
}
6870

6971
if (response == null) {
7072
streamHandler.close()
71-
return undefined
73+
return
7274
}
7375
if (response.status === Status.OK) {
7476
log('stop request to %s was successful', connection.remotePeer)
@@ -77,5 +79,5 @@ export async function stop ({
7779

7880
log('stop request failed with code %d', response.status)
7981
streamHandler.close()
80-
return undefined
82+
return
8183
}

test/relay/auto-relay.node.ts

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ describe('auto-relay', () => {
202202
// Disconnect from peer used for relay
203203
const disconnectPromise = pEvent(relayLibp2p1.connectionManager, 'peer:disconnect', { timeout: 500 })
204204
await relayLibp2p2.stop()
205+
console.log('disconnected')
205206
const event = await disconnectPromise
206207
expect(event.detail.remotePeer.toString()).to.equal(relayLibp2p2.peerId.toString())
207208

@@ -210,6 +211,7 @@ describe('auto-relay', () => {
210211
timeout: 1000
211212
})).to.eventually.be.rejected()
212213

214+
console.log('abc')
213215
// Wait for other peer connected to be added as listen addr
214216
await usingAsRelay(relayLibp2p1, relayLibp2p3)
215217
})

tsconfig.json

-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,4 @@
77
"src",
88
"test"
99
],
10-
"exclude": [
11-
"src/circuit/v1/pb/index.js",
12-
"src/circuit/v2/pb/index.js",
13-
"src/fetch/pb/proto.js",
14-
"src/identify/pb/message.js",
15-
"src/insecure/pb/proto.js"
16-
]
1710
}

0 commit comments

Comments
 (0)