js-libp2p-kad-dht
![](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.
Lead Maintainer
Vasco Santos.
Table of Contents
Install
npm
> npm i libp2p-kad-dht
Use in Node.js
const KadDHT = require('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
function addDHT(libp2p) {
const customDHT = new KadDHT({
libp2p,
dialer: libp2p.dialer,
peerId: libp2p.peerId,
peerStore: libp2p.peerStore,
registrar: libp2p.registrar,
protocolPrefix: '/custom'
})
customDHT.start()
customDHT.on('peer', libp2p._onDiscoveryPeer)
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)
Content Routing
![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/content-routing/img/badge.png)
Peer Discovery
![](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/src/peer-discovery/img/badge.png)
Implementation Summary
A summary of the algorithms and API for this implementation of Kademlia.
Contribute
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.
![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)
License
MIT - Protocol Labs 2017