Skip to content

Commit

Permalink
chore: rename MdnsDiscovery to LocalDiscovery
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Oct 25, 2023
1 parent bbdccfa commit 5467d62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/discovery/mdns.js → src/discovery/local-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ERR_DUPLICATE = 'Duplicate connection'
/**
* @extends {TypedEmitter<DiscoveryEvents>}
*/
export class MdnsDiscovery extends TypedEmitter {
export class LocalDiscovery extends TypedEmitter {
#identityKeypair
#server
/** @type {Map<string, NoiseSecretStream<net.Socket>>} */
Expand Down Expand Up @@ -254,7 +254,7 @@ export class MdnsDiscovery extends TypedEmitter {
}

/**
* @type {MdnsDiscovery['stop']}
* @type {LocalDiscovery['stop']}
*/
async #stop({ force = false, timeout = 0 } = {}) {
this.#log('stopping')
Expand Down
13 changes: 8 additions & 5 deletions tests/discovery/mdns.js → tests/discovery/local-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import { KeyManager } from '@mapeo/crypto'
import { setTimeout as delay } from 'node:timers/promises'
import pDefer from 'p-defer'
import { keyToPublicId } from '@mapeo/crypto'
import { ERR_DUPLICATE, MdnsDiscovery } from '../../src/discovery/mdns.js'
import {
ERR_DUPLICATE,
LocalDiscovery,
} from '../../src/discovery/local-discovery.js'
import NoiseSecretStream from '@hyperswarm/secret-stream'

test('mdns - discovery and sharing of data', (t) => {
const deferred = pDefer()
const identityKeypair1 = new KeyManager(randomBytes(16)).getIdentityKeypair()
const identityKeypair2 = new KeyManager(randomBytes(16)).getIdentityKeypair()

const mdnsDiscovery1 = new MdnsDiscovery({
const mdnsDiscovery1 = new LocalDiscovery({
identityKeypair: identityKeypair1,
})
const mdnsDiscovery2 = new MdnsDiscovery({
const mdnsDiscovery2 = new LocalDiscovery({
identityKeypair: identityKeypair2,
})
const str = 'hi'
Expand Down Expand Up @@ -52,7 +55,7 @@ test('deduplicate incoming connections', async (t) => {

const localKp = new KeyManager(randomBytes(16)).getIdentityKeypair()
const remoteKp = new KeyManager(randomBytes(16)).getIdentityKeypair()
const discovery = new MdnsDiscovery({ identityKeypair: localKp })
const discovery = new LocalDiscovery({ identityKeypair: localKp })
await discovery.start()

discovery.on('connection', (conn) => {
Expand Down Expand Up @@ -113,7 +116,7 @@ async function testMultiple(t, { period, nPeers = 20 }) {

async function spawnPeer(onConnected) {
const identityKeypair = new KeyManager(randomBytes(16)).getIdentityKeypair()
const discovery = new MdnsDiscovery({ identityKeypair })
const discovery = new LocalDiscovery({ identityKeypair })
const peerId = keyToPublicId(discovery.publicKey)
peersById.set(peerId, discovery)
const conns = []
Expand Down

0 comments on commit 5467d62

Please sign in to comment.