# discovery-channel

> discover peers that have hashes using various kewl methods

Latest version **5.5.1** (published 2018-03-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install discovery-channel
pnpm add discovery-channel
yarn add discovery-channel
bun add discovery-channel
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.5.1 |
| Published | 2018-03-23 |
| First published | 2015-11-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 298 |
| Author | max ogden |
| Maintainers | karissa, mafintosh, maxogden |

## Links

- npm: https://www.npmjs.com/package/discovery-channel
- Repository: https://github.com/maxogden/discovery-channel
- Homepage: https://github.com/maxogden/discovery-channel#readme
- Issues: https://github.com/maxogden/discovery-channel/issues
- npm.io page: https://npm.io/package/discovery-channel

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^2.6.9
- [thunky](https://npm.io/package/thunky.md) ^0.1.0
- [buffer-from](https://npm.io/package/buffer-from.md) ^1.0.0
- [pretty-hash](https://npm.io/package/pretty-hash.md) ^1.0.1
- [dns-discovery](https://npm.io/package/dns-discovery.md) ^6.0.1
- [bittorrent-dht](https://npm.io/package/bittorrent-dht.md) ^7.10.0

## Recent versions

- 5.5.1 (latest) — 2018-03-23
- 5.5.0 — 2018-03-13
- 5.4.7 — 2018-01-16
- 5.4.6 — 2017-09-29
- 5.4.5 — 2017-08-04
- 5.4.4 — 2017-05-22
- 5.4.3 — 2017-04-27
- 5.4.2 — 2017-02-17
- 5.4.1 — 2016-12-29
- 5.4.0 — 2016-11-22
- 5.3.1 — 2016-11-17
- 5.3.0 — 2016-06-06
- 5.2.0 — 2016-06-06
- 5.1.0 — 2016-05-17
- 5.0.1 — 2016-02-27
- … 13 more at https://npm.io/package/discovery-channel/versions

## README

# discovery-channel

Search for a key across multiple discovery networks and find peers who answer.

Currently searches across and advertises on [the Bittorrent DHT](https://en.wikipedia.org/wiki/Mainline_DHT), centralized DNS servers and [Multicast DNS](https://en.wikipedia.org/wiki/Multicast_DNS) simultaneously.

Uses the [bittorrent-dht](https://github.com/feross/bittorrent-dht) and [dns-discovery](https://github.com/mafintosh/dns-discovery) modules.

Also check out [discovery-swarm](https://github.com/mafintosh/discovery-swarm) which adds connection management on top of this module.

[![travis][travis-image]][travis-url]

[travis-image]: https://img.shields.io/travis/maxogden/discovery-channel.svg?style=flat
[travis-url]: https://travis-ci.org/maxogden/discovery-channel

## Usage

### `var DC = require('discovery-channel')`

Returns a constructor

### `var channel = DC(<opts>)`

Returns a new instance. `opts` is optional and can have the following properties:

- `dns` - default `undefined`, if `false` will disable `dns` discovery, any other value type will be passed to the `dns-discovery` constructor
- `dht` - default `undefined`, if `false` will disable `dht` discovery, any other value type will be passed to the `bittorrent-dht` constructor
- `hash` - default `sha1`. provide a custom hash function to hash ids before they are stored in the dht / on dns servers.

By default hashes are re-announced around every 10 min on the dht and 1 min using dns. Set `dht.interval` or `dns.interval` to change these.

### `channel.join(id, [port], [cb])`

Perform a lookup across all networks for `id`. `id` can be a buffer or a string.
Specify `port` if you want to announce that you share `id` as well.

If you specify `cb`, it will be called **when the first round** of discovery has completed. But only on the first round.

### `channel.leave(id, [port])`

Stop looking for `id`. `id` can be a buffer or a string.
Specify `port` to stop announcing that you share `id` as well.

### `channel.update()`

Force announce / lookup all joined hashes

### `var list = channel.list()`

List all the channels you have joined. The returned array items look like this

``` js
{
  id: <Buffer>,
  port: <port you are announcing>
}
```

### `channel.on('peer', id, peer, type)`

Emitted when a peer answers your query.

- `id` is the id (as a buffer) this peer was discovered for
- `peer` is the peer that was discovered `{port: port, host: host}`
- `type` is the network type (one of `['dht', 'dns']`)

### `channel.destroy(cb)`

Stops all lookups and advertisements and call `cb` when done.

### `channel.on('close')`

Emitted when the channel is destroyed

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