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: remove unused address method from LocalDiscovery #600

Merged
merged 1 commit into from
May 2, 2024
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: 1 addition & 5 deletions src/discovery/local-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ export class LocalDiscovery extends TypedEmitter {
return this.#identityKeypair.publicKey
}

address() {
return this.#server.address()
}

/** @returns {Promise<{ name: string, port: number }>} */
async start() {
await this.#sm.start()
Expand Down Expand Up @@ -291,7 +287,7 @@ export class LocalDiscovery extends TypedEmitter {
* Get the address of a server, will throw if the server is not yet listening or
* if it is listening on a socket
* @param {import('node:net').Server} server
* @returns
* @returns {import('node:net').AddressInfo}
*/
function getAddress(server) {
const addr = server.address()
Expand Down
14 changes: 6 additions & 8 deletions tests/discovery/local-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,16 @@ test('deduplicate incoming connections', async (t) => {
const localKp = new KeyManager(randomBytes(16)).getIdentityKeypair()
const remoteKp = new KeyManager(randomBytes(16)).getIdentityKeypair()
const discovery = new LocalDiscovery({ identityKeypair: localKp })
await discovery.start()
const { port } = await discovery.start()

discovery.on('connection', (conn) => {
conn.on('error', handleConnectionError.bind(null, t))
localConnections.add(conn)
conn.on('close', () => localConnections.delete(conn))
})

const addrInfo = discovery.address()
for (let i = 0; i < 20; i++) {
noiseConnect(addrInfo, remoteKp).then((conn) => {
noiseConnect(port, '127.0.0.1', remoteKp).then((conn) => {
conn.on('error', handleConnectionError.bind(null, t))
conn.on('connect', () => remoteConnections.add(conn))
conn.on('close', () => remoteConnections.delete(conn))
Expand All @@ -98,13 +97,12 @@ test(`peer discovery of 30 peers connected at the same time`, async (t) => {
})

/**
*
* @param {net.AddressInfo} addrInfo
* @param {number} port
* @param {string} host
* @param {{ publicKey: Buffer, secretKey: Buffer }} keyPair
* @returns
*/
async function noiseConnect({ port, address }, keyPair) {
const socket = net.connect(port, address)
async function noiseConnect(port, host, keyPair) {
const socket = net.connect(port, host)
return new NoiseSecretStream(true, socket, { keyPair })
}

Expand Down
Loading