Skip to content

Commit

Permalink
Merge branch 'main' into feat/peer-sync-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan authored Oct 25, 2023
2 parents 2fabad2 + 8dce752 commit 48b6cfa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
47 changes: 29 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"streamx": "^2.15.1",
"tempy": "^3.1.0",
"ts-proto": "^1.156.7",
"type-fest": "^3.10.0",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "^5.1.6"
Expand Down Expand Up @@ -145,6 +144,7 @@
"sub-encoder": "^2.1.1",
"throttle-debounce": "^5.0.0",
"tiny-typed-emitter": "^2.1.0",
"type-fest": "^4.5.0",
"varint": "^6.0.0",
"z32": "^1.0.1"
}
Expand Down
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 48b6cfa

Please sign in to comment.