# multiserver-dht

> A multiserver plugin that uses a Distributed Hash Table

Latest version **5.0.0** (published 2021-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install multiserver-dht
pnpm add multiserver-dht
yarn add multiserver-dht
bun add multiserver-dht
```

## 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.0.0 |
| Published | 2021-01-27 |
| First published | 2018-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 4 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Andre Staltz |
| Maintainers | staltz |

## Links

- npm: https://www.npmjs.com/package/multiserver-dht
- Repository: https://github.com/staltz/multiserver-dht
- Homepage: https://github.com/staltz/multiserver-dht#readme
- Issues: https://github.com/staltz/multiserver-dht/issues
- npm.io page: https://npm.io/package/multiserver-dht

## Dependencies (4)

- [hyperswarm](https://npm.io/package/hyperswarm.md) ^2.15.2
- [pull-stream](https://npm.io/package/pull-stream.md) ^3.6.9
- [hyperswarm-web](https://npm.io/package/hyperswarm-web.md) ^2.1.1
- [stream-to-pull-stream](https://npm.io/package/stream-to-pull-stream.md) 1.7.x

## Recent versions

- 5.0.0 (latest) — 2021-01-27
- 5.0.0-rc.3 (canary) — 2019-09-20
- 4.4.0 — 2019-09-20
- 4.3.0 — 2019-09-20
- 5.0.0-rc.2 — 2019-09-20
- 4.2.0 — 2019-09-19
- 4.1.1 — 2019-09-19
- 4.1.0 — 2019-09-19
- 5.0.0-rc.1 — 2018-10-31
- 4.0.0 — 2018-10-25
- 3.3.1 — 2018-09-19
- 3.3.0 — 2018-09-17
- 3.2.0 — 2018-09-17
- 3.1.0 — 2018-09-13
- 3.0.0 — 2018-09-13
- … 11 more at https://npm.io/package/multiserver-dht/versions

## README

# multiserver-dht

_A [multiserver](https://github.com/ssbc/multiserver) plugin that uses a Distributed Hash Table and channel keys as addresses_

```
npm install --save multiserver-dht
```

This module is a multiserver plugin that joins a Distributed Hash Table (DHT) and uses channel keys as "addresses" where peers communicate as clients and as servers.

## Usage

As client:

```js
var pull = require('pull-stream');
var Pushable = require('pull-pushable');
var MultiServer = require('multiserver');
var Dht = require('multiserver-dht');

var ms = MultiServer([Dht({ key: 'japan' })]);

ms.client('dht:japan', function(err, stream) {
  var pushable = Pushable();
  pull(
    pushable,
    stream,
    pull.drain(x => {
      console.log(buf.toString('utf-8'));
      // ALICE
      // BOB
    }),
  );
  pushable.push('alice');
  pushable.push('bob');
});
```

As server:

```js
var pull = require('pull-stream');
var MultiServer = require('multiserver');
var Dht = require('multiserver-dht');

var ms = MultiServer([Dht({ key: 'japan' })]);

ms.server(function(stream) {
  pull(
    stream,
    pull.map(buf => buf.toString('utf-8')),
    pull.map(s => s.toUpperCase()),
    pull.map(str => Buffer.from(str, 'utf-8')),
    stream,
  );
});
```

## API

### `Dht(opts)`

Joins a global Distributed Hash Table on the Internet under the channel `opts.key` as the address. The `opts` may include:

* `key` (REQUIRED unless `keys` is present), a string identifying the channel to be used as address.
* `keys` (REQUIRED unless `key` is present), a pull-stream of arrays of strings that identify all the channels where servers are hosted.
* `port`, the port on which to listen for connections in the DHT. Default: 8007
* `id` a string identifying this specific DHT peer. Default: something random

Returns a multiserver plugin.

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