All Projects → libp2p → Js Libp2p Kad Dht

libp2p / Js Libp2p Kad Dht

Licence: mit
JavaScript implementation of the DHT for libp2p

Programming Languages

javascript
184084 projects - #8 most used programming language

js-libp2p-kad-dht

Discourse posts Build Status Coverage Status Dependency Status Bundle Size js-standard-style standard-readme compliant

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

/**
 * @param {Libp2p} 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

Content Routing

Peer Discovery

libp2p-kad-dht provides a discovery service called Random Walk (random walks on the DHT to discover more nodes). It is accessible through dht.randomWalk and exposes the Peer Discovery interface.

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.

License

MIT - Protocol Labs 2017

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].