# hyperdiscovery

> Join the p2p swarm for hypercore and hyperdrive feeds.

Latest version **10.2.2** (published 2022-01-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install hyperdiscovery
pnpm add hyperdiscovery
yarn add hyperdiscovery
bun add hyperdiscovery
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 10.2.2 |
| Published | 2022-01-06 |
| First published | 2016-11-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 20.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 132 |
| Author | Dat Project Contributors |
| Maintainers | karissa, maxogden, yoshuawuyts, mafintosh, jhand, rangermauve, leichtgewicht, the-real-dk, pfrazee, frando, cblgh, ninabreznik, serapath, zootella, juliangruber |

## Links

- npm: https://www.npmjs.com/package/hyperdiscovery
- Repository: https://github.com/datproject/hyperdiscovery
- Homepage: https://github.com/datproject/hyperdiscovery#readme
- Issues: https://github.com/datproject/hyperdiscovery/issues
- npm.io page: https://npm.io/package/hyperdiscovery

## Dependencies (7)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [mutexify](https://npm.io/package/mutexify.md) ^1.2.0
- [dat-encoding](https://npm.io/package/dat-encoding.md) ^5.0.1
- [discovery-swarm](https://npm.io/package/discovery-swarm.md) ^5.1.4
- [dat-swarm-defaults](https://npm.io/package/dat-swarm-defaults.md) ^1.0.2
- [hypercore-protocol](https://npm.io/package/hypercore-protocol.md) ^6.9.0
- [discovery-swarm-web](https://npm.io/package/discovery-swarm-web.md) ^2.0.0

## Recent versions

- 10.2.2 (latest) — 2022-01-06
- 10.2.1 — 2019-11-06
- 10.2.0 — 2019-11-06
- 10.1.0 — 2019-10-02
- 10.0.1 — 2019-08-08
- 10.0.0 — 2019-06-24
- 9.0.2 — 2019-05-28
- 9.0.1 — 2019-05-06
- 9.0.0 — 2019-04-22
- 8.0.0 — 2018-06-30
- 7.1.1 — 2018-05-27
- 7.1.0 — 2018-05-02
- 7.0.0 — 2017-10-09
- 6.0.4 — 2017-05-16
- 6.0.3 — 2017-05-16
- … 8 more at https://npm.io/package/hyperdiscovery/versions

## README

[![deprecated](http://badges.github.io/stability-badges/dist/deprecated.svg)](https://github.com/hyperswarm/replicator) See [hyperswarm replicator](https://github.com/hyperswarm/replicator) for similar functionality. 

More info on active projects and modules at [dat-ecosystem.org](https://dat-ecosystem.org/) <img src="https://i.imgur.com/qZWlO1y.jpg" width="30" height="30" /> 

---

# hyperdiscovery

### Old documentation below

This library is compatible with hypercore<=v7, which is now out of date. 

[![build status](https://travis-ci.org/datproject/hyperdiscovery.svg?branch=master)](http://travis-ci.org/datproject/hyperdiscovery)

Join the p2p swarm for [hypercore][core] and [hyperdrive][drive]. Uses
[discovery-swarm][swarm] under the hood. Also works in web browsers using [discovery-swarm-web](https://github.com/RangerMauve/discovery-swarm-web).

This module only works

```
npm install hyperdiscovery
```

## Usage

Run the following code in two different places and they will replicate the contents of the given `ARCHIVE_KEY`.

```js
var hyperdrive = require('hyperdrive')
var hypercore = require('hypercore')
var Discovery = require('hyperdiscovery')

var archive = hyperdrive('./database', 'ARCHIVE_KEY')
var discovery = Discovery(archive)
discovery.on('connection', function (peer, type) {
  console.log('got', peer, type)
  console.log('connected to', discovery.connections, 'peers')
  peer.on('close', function () {
    console.log('peer disconnected')
  })
})

// add another archive/feed later
var feed = hypercore('./feed')
discovery.add(feed) // adds this hypercore feed to the same discovery swarm
```

Will use `discovery-swarm` to attempt to connect peers. Uses `dat-swarm-defaults` for peer introduction defaults on the server side, which can be overwritten (see below).

The module can also create and join a swarm for a hypercore feed:

```js
var hypercore = require('hypercore')
var Discovery = require('hyperdiscovery')

var feed = hypercore('/feed')
var discovery = Discovery(feed)
```

## API

### `var discovery = Discovery(archive, opts)`

Join the p2p swarm for the given feed. The return object, `discovery`, is an event emitter that will emit a `peer` event with the peer information when a peer is found.

### `discovery.add(archive, [opts])`

Add an archive/feed to the discovery swarm. Options will be passed to `discovery-swarm`. If you pass `opts.announce` as a falsy value you don't announce your port (discover-only mode).

### `discovery.totalConnections`

Get length of the list of total active connections, across all archives and feeds.

### `discovery.leave(discoveryKey)`

Leave discovery for a specific discovery key.

### `discovery.rejoin(discoveryKey)`

Rejoin discovery for a discovery key (*must be added first using `discovery.add`).

### `discovery.close()`

Exit the swarm, close all replication streams.

##### Options

  * `stream`: function, replication stream for connection. Default is `archive.replicate({live, upload, download})`.
  * `upload`: bool, upload data to the other peer?
  * `download`: bool, download data from the other peer?
  * `port`: port for discovery swarm
  * `utp`: use utp in discovery swarm
  * `tcp`: use tcp in discovery swarm
  * `bootstrap`: [string], WebRTC bootstrap signal servers for web
  * `discovery`: string, discovery-swarm-stream server for web

Defaults from datland-swarm-defaults can also be overwritten:

  * `dns.server`: DNS server
  * `dns.domain`: DNS domain
  * `dht.bootstrap`: distributed hash table bootstrapping nodes

## Debugging

Set `DEBUG='*'` in the environment to enable debugging output inside discovery-swarm.

## See Also
- [mafintosh/hypercore][core]
- [mafintosh/hyperdrive][drive]
- [mafintosh/hyperdb][db]
- [mafintosh/discovery-swarm][swarm]
- [discovery-swarm-web][swarm-web]

## License
ISC

[core]: https://github.com/mafintosh/hypercore
[drive]: https://github.com/mafintosh/hyperdrive
[db]: https://github.com/mafintosh/hyperdb
[swarm]: https://github.com/mafintosh/discovery-swarm
[swarm-web]: https://github.com/RangerMauve/discovery-swarm-web

---
_Source: https://npm.io/package/hyperdiscovery · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
