# libp2p-kad-dht

> JavaScript implementation of the Kad-DHT for libp2p

Latest version **0.28.6** (published 2022-01-19) · Apache-2.0 OR MIT license · 0 weekly downloads

## Install

```sh
npm install libp2p-kad-dht
pnpm add libp2p-kad-dht
yarn add libp2p-kad-dht
bun add libp2p-kad-dht
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.28.6 |
| Published | 2022-01-19 |
| First published | 2017-04-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 OR MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.0.0 |
| Dependencies | 32 |
| Unpacked size | 1.3 MB |
| Known vulnerabilities | 0 (+12 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | jacobheun, daviddias, achingbrain, vascosantos |
| Keywords | IPFS |

## Links

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

## Dependencies (32)

- [debug](https://npm.io/package/debug.md) ^4.3.1
- [p-map](https://npm.io/package/p-map.md) ^4.0.0
- [it-all](https://npm.io/package/it-all.md) ^1.0.5
- [it-map](https://npm.io/package/it-map.md) ^1.0.5
- [varint](https://npm.io/package/varint.md) ^6.0.0
- [hashlru](https://npm.io/package/hashlru.md) ^2.3.0
- [it-pipe](https://npm.io/package/it-pipe.md) ^1.1.0
- [it-take](https://npm.io/package/it-take.md) ^1.0.2
- [p-defer](https://npm.io/package/p-defer.md) ^3.0.0
- [p-queue](https://npm.io/package/p-queue.md) ^6.6.2
- [peer-id](https://npm.io/package/peer-id.md) ^0.16.0
- [err-code](https://npm.io/package/err-code.md) ^3.0.0
- [it-drain](https://npm.io/package/it-drain.md) ^1.0.4
- [it-first](https://npm.io/package/it-first.md) ^1.0.4
- [it-merge](https://npm.io/package/it-merge.md) ^1.0.3
- [k-bucket](https://npm.io/package/k-bucket.md) ^5.1.0
- [it-length](https://npm.io/package/it-length.md) ^1.0.3
- [multiaddr](https://npm.io/package/multiaddr.md) ^10.0.0
- [any-signal](https://npm.io/package/any-signal.md) ^3.0.0
- [private-ip](https://npm.io/package/private-ip.md) ^2.3.3
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.10.2
- [it-parallel](https://npm.io/package/it-parallel.md) ^2.0.1
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [multiformats](https://npm.io/package/multiformats.md) ^9.4.5
- [libp2p-crypto](https://npm.io/package/libp2p-crypto.md) ^0.21.0
- [libp2p-record](https://npm.io/package/libp2p-record.md) ^0.10.4
- [datastore-core](https://npm.io/package/datastore-core.md) ^7.0.0
- [libp2p-interfaces](https://npm.io/package/libp2p-interfaces.md) ^4.0.0
- [it-length-prefixed](https://npm.io/package/it-length-prefixed.md) ^5.0.2
- [interface-datastore](https://npm.io/package/interface-datastore.md) ^6.0.2
- [streaming-iterables](https://npm.io/package/streaming-iterables.md) ^6.0.0
- [timeout-abort-controller](https://npm.io/package/timeout-abort-controller.md) ^3.0.0

## Recent versions

- 0.28.6 (latest) — 2022-01-19
- 0.28.5 — 2022-01-19
- 0.28.4 — 2022-01-17
- 0.28.3 — 2022-01-17
- 0.28.2 — 2022-01-15
- 0.28.1 — 2021-12-31
- 0.28.0 — 2021-12-30
- 0.27.6 — 2021-12-29
- 0.27.5 — 2021-12-21
- 0.27.4 — 2021-12-15
- 0.27.3 — 2021-12-07
- 0.27.2 — 2021-12-03
- 0.27.1 — 2021-12-02
- 0.27.0 — 2021-12-01
- 0.26.7 — 2021-11-26
- … 94 more at https://npm.io/package/libp2p-kad-dht/versions

## README

# js-libp2p-kad-dht <!-- omit in toc -->

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![Build status](https://github.com/libp2p/js-libp2p-kad-dht/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/libp2p/js-libp2p-kad-dht/actions/workflows/test.yml)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-kad-dht/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-kad-dht?branch=master)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-kad-dht)
[![Bundle Size](https://flat.badgen.net/bundlephobia/minzip/libp2p-kad-dht)](https://bundlephobia.com/result?p=libp2p-kad-dht)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D6.0.0-orange.svg?style=flat-square)

> JavaScript implementation of the Kademlia DHT for libp2p, based on [go-libp2p-kad-dht](https://github.com/libp2p/go-libp2p-kad-dht).

## Lead Maintainer  <!-- omit in toc -->

[Vasco Santos](https://github.com/vasco-santos).

## Table of Contents  <!-- omit in toc -->

- [Install](#install)
  - [npm](#npm)
  - [Use in Node.js](#use-in-nodejs)
- [API](#api)
  - [Custom secondary DHT in libp2p](#custom-secondary-dht-in-libp2p)
  - [Peer Routing](#peer-routing)
  - [Content Routing](#content-routing)
  - [Peer Discovery](#peer-discovery)
- [Spec](#spec)
- [Contribute](#contribute)
- [License](#license)
## Install

### npm

```sh
> npm i libp2p-kad-dht
```

### Use in Node.js

```js
import { create } from 'libp2p-kad-dht'
```

## API

See https://libp2p.github.io/js-libp2p-kad-dht for the auto generated docs.

The libp2p-kad-dht module offers 3 APIs: Peer Routing, Content Routing and Peer Discovery.

### Custom secondary DHT in libp2p

```js
import { create } from 'libp2p-kad-dht'

/**
 * @param {Libp2p} libp2p
 */
async function addDHT(libp2p) {
    const customDHT = create({
        libp2p,
        protocolPrefix: '/custom'
    })
    await customDHT.start()

    return customDHT
}
```

Note that you may want to supply your own peer discovery function and datastore
### Peer Routing

[![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/peer-routing/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interfaces/src/peer-routing)

### Content Routing

[![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/content-routing/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interfaces/src/content-routing)

### Peer Discovery

[![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/peer-discovery/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interfaces/src/peer-discovery)

## Spec

js-libp2p-kad-dht follows the [libp2p/kad-dht spec](https://github.com/libp2p/specs/tree/master/kad-dht) and implements the algorithms described in the [IPFS DHT documentation](https://docs.ipfs.io/concepts/dht/).

## Contribute

Feel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-ipfs/issues)!

This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)

## License

MIT - Protocol Labs 2017

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