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: create module directory for discovery #29

Merged
merged 5 commits into from
Sep 19, 2022
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
42 changes: 42 additions & 0 deletions lib/discovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Discovery

> Discover other peers via the DHT or MDNS and replicate with them

## Usage

The `Discovery` class provides an abstraction layer that allows peer discovery using either a [distributed hash table](https://en.wikipedia.org/wiki/Distributed_hash_table) (DHT) via [hyperswarm](https://npmjs.com/hyperswarm) or [Multicast DNS](https://en.wikipedia.org/wiki/Multicast_DNS) (mDNS) via [multicast-service-discovery](https://npmjs.com/multicast-service-discovery).

```js
import Hypercore from 'hypercore'
import { KeyManager } from '@mapeo/crypto'
import { Discovery } from './index.js'

const rootKey = KeyManager.generateRootKey()
const keyManager = new KeyManager(rootKey)
const identityKeyPair = keyManager.getIdentityKeypair()

const core = new Hypercore()
await core.ready()

const discover = new Discovery({
identityKeyPair,
mdns: true,
dht: true,
})

await discover.ready()

discover.on('connection', (connection, peer) => {
core.replicate(connection)
})

await discover.join(core.discoveryKey)
```

sethvincent marked this conversation as resolved.
Show resolved Hide resolved
## API Docs

TODO!

## Tests

The tests for this module are in [tests/discovery.js](../../tests/discovery.js)
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ram from 'random-access-memory'
import createTestnet from '@hyperswarm/testnet'

import { createCoreKeyPair, createIdentityKeys } from './helpers/index.js'
import { Discovery } from '../lib/discovery.js'
import { Discovery } from '../lib/discovery/index.js'

test('discovery - dht/hyperswarm', async (t) => {
t.plan(2)
Expand Down