### libp2p-kad-dht

`0.19.4`
Need help reading this?

## Intro

Installable via `npm install --save libp2p-kad-dht`, it can also be used directly in the browser.

## Download

The source is available for download from GitHub. Alternatively, you can install using npm:

    $ npm install --save libp2p-kad-dht

You can then `require()` libp2p-kad-dht as normal:

    const libp2PKadDht = require('libp2p-kad-dht')

## In the Browser

`libp2p-kad-dht` should work in any ECMAScript 2018 environment out of the box.

Usage:

    <script type="text/javascript" src="index.js"></script>

The portable versions of `libp2p-kad-dht`, including `index.js` and `index.min.js`, are included in the `/dist` folder. `libp2p-kad-dht` can also be found on unpkg.com under

- https://unpkg.com/libp2p-kad-dht/dist/index.min.js
- https://unpkg.com/libp2p-kad-dht/dist/index.js

### KadDHT

src/index.js

A DHT implementation modeled after Kademlia with S/Kademlia modifications. Original implementation in go: https://github.com/libp2p/go-libp2p-kad-dht.

new KadDHT($0: Object, props: Object)

Extends EventEmitter

Parameters
$0 `(Object)`

Name | Description
--- | ---
$0.dialer `any` |
$0.peerId `any` |
$0.peerStore `any` |
$0.registrar `any` |
$0.datastore `any` (default `new MemoryDatastore()`) |
$0.kBucketSize `any` (default `c.K`) |
$0.concurrency `any` (default `c.ALPHA`) |
$0.validators `any` (default `{}`) |
$0.selectors `any` (default `{}`) |
$0.randomWalk `any` (default `{}`) |

props `(Object)`
Instance Members
▸ dialer
src/index.js

Local reference to the libp2p dialer instance

dialer

Type: Dialer

▸ peerId
src/index.js

Local peer-id

peerId

Type: PeerId

▸ peerStore
src/index.js

Local PeerStore

peerStore

Type: PeerStore

▸ registrar
src/index.js

Local peer info

registrar

Type: Registrar

▸ kBucketSize
src/index.js

k-bucket size

kBucketSize

Type: number

▸ concurrency
src/index.js

ALPHA concurrency at which each query path with run, defaults to 3

concurrency

Type: number

▸ disjointPaths
src/index.js

Number of disjoint query paths to use This is set to `kBucketSize`/2 per the S/Kademlia paper

disjointPaths

Type: number

▸ routingTable
src/index.js

The routing table.

routingTable

Type: RoutingTable

▸ datastore
src/index.js

Reference to the datastore, uses an in-memory store if none given.

datastore

Type: Datastore

▸ providers
src/index.js

Provider management

providers

Type: Providers

▸ randomWalk
src/index.js

Random walk management

randomWalk

Type: RandomWalk

▸ _queryManager
src/index.js

Keeps track of running queries

_queryManager

Type: QueryManager

▸ isStarted
src/index.js

Is this DHT running.

isStarted

Type: bool

▸ start()
src/index.js

Start listening to incoming connections.

start(): Promise<void>
Returns
`Promise<void>`:
▸ stop()
src/index.js

Stop accepting incoming connections and sending outgoing messages.

stop(): Promise<void>
Returns
`Promise<void>`:
▸ put(key, value, options = {})
src/index.js

Store the given key/value pair in the DHT.

put(key: Buffer, value: Buffer, options: Object?): Promise<void>
Parameters
key `(Buffer)`
value `(Buffer)`
options `(Object? = `{}`)` put options

Name | Description
--- | ---
options.minPeers `number?` | minimum number of peers required to successfully put (default: closestPeers.length)

Returns
`Promise<void>`:
▸ get(key, options = {})
src/index.js

Get the value to the given key. Times out after 1 minute by default.

get(key: Buffer, options: Object?): Promise<Buffer>
Parameters
key `(Buffer)`
options `(Object? = `{}`)` get options

Name | Description
--- | ---
options.timeout `number?` | optional timeout (default: 60000)

Returns
`Promise<Buffer>`:
▸ getMany(key, nvals, options = {})
src/index.js

Get the `n` values to the given key without sorting.

getMany(key: Buffer, nvals: number, options: Object?): Promise<Array<{from: PeerId, val: Buffer}>>
Parameters
key `(Buffer)`
nvals `(number)`
options `(Object? = `{}`)` get options

Name | Description
--- | ---
options.timeout `number?` | optional timeout (default: 60000)

Returns
`Promise<Array<{from: PeerId, val: Buffer}>>`:
▸ provide(key)
src/index.js

Announce to the network that we can provide given key's value.

provide(key: CID): Promise<void>
Parameters
key `(CID)`
Returns
`Promise<void>`:
▸ findProviders(key, options)
src/index.js

Search the dht for up to `K` providers of the given CID.

findProviders(key: CID, options: Object): AsyncIterable<{id: PeerId, multiaddrs: Array<Multiaddr>}>
Parameters
key `(CID)`
options `(Object = `{}`)` findProviders options

Name | Description
--- | ---
options.timeout `number` | how long the query should maximally run, in milliseconds (default: 60000)
options.maxNumProviders `number` | maximum number of providers to find

Returns
`AsyncIterable<{id: PeerId, multiaddrs: Array<Multiaddr>}>`:
▸ findPeer(id, options)
src/index.js

Search for a peer with the given ID.

findPeer(id: PeerId, options: Object): Promise<{id: PeerId, multiaddrs: Array<Multiaddr>}>
Parameters
id `(PeerId)`
options `(Object = `{}`)` findPeer options

Name | Description
--- | ---
options.timeout `number` | how long the query should maximally run, in milliseconds (default: 60000)

Returns
`Promise<{id: PeerId, multiaddrs: Array<Multiaddr>}>`:
▸ getClosestPeers(key, options = {shallow:false})
src/index.js

Kademlia 'node lookup' operation.

getClosestPeers(key: Buffer, options: Object?): AsyncIterable<{id: PeerId, multiaddrs: Array<Multiaddr>}>
Parameters
key `(Buffer)`
options `(Object? = `{shallow:false}`)`

Name | Description
--- | ---
options.shallow `boolean?` | shallow query (default: false)

Returns
`AsyncIterable<{id: PeerId, multiaddrs: Array<Multiaddr>}>`:
▸ getPublicKey(peer)
src/index.js

Get the public key for the given peer id.

getPublicKey(peer: PeerId): Promise<PubKey>
Parameters
peer `(PeerId)`
Returns
`Promise<PubKey>`:

### RoutingTable

src/routing.js

A wrapper around `k-bucket`, to provide easy store and retrival for peers.

new RoutingTable(self: PeerId, kBucketSize: number)
Parameters
self `(PeerId)`
kBucketSize `(number)`
Instance Members
▸ size
src/routing.js

Amount of currently stored peers.

size

Type: number

▸ find(peer)
src/routing.js

Find a specific peer by id.

find(peer: PeerId): Promise<PeerId>
Parameters
peer `(PeerId)`
Returns
`Promise<PeerId>`:
▸ closestPeer(key)
src/routing.js

Retrieve the closest peers to the given key.

closestPeer(key: Buffer): (PeerId | undefined)
Parameters
key `(Buffer)`
Returns
`(PeerId | undefined)`:
▸ closestPeers(key, count)
src/routing.js

Retrieve the `count`-closest peers to the given key.

closestPeers(key: Buffer, count: number): Array<PeerId>
Parameters
key `(Buffer)`
count `(number)`
Returns
`Array<PeerId>`:
▸ add(peer)
src/routing.js

Add or update the routing table with the given peer.

add(peer: PeerId): Promise<void>
Parameters
peer `(PeerId)`
Returns
`Promise<void>`:
▸ remove(peer)
src/routing.js

Remove a given peer from the table.

remove(peer: PeerId): Promise<void>
Parameters
peer `(PeerId)`
Returns
`Promise<void>`:

### convertBuffer

src/utils.js

Creates a DHT ID by hashing a given buffer.

convertBuffer(buf: Buffer): Promise<Buffer>
Parameters
buf `(Buffer)`
Returns
`Promise<Buffer>`:

### convertPeerId

src/utils.js

Creates a DHT ID by hashing a Peer ID

convertPeerId(peer: PeerId): Promise<Buffer>
Parameters
peer `(PeerId)`
Returns
`Promise<Buffer>`:

### bufferToKey

src/utils.js

Convert a buffer to their SHA2-256 hash.

bufferToKey(buf: Buffer): Key
Parameters
buf `(Buffer)`
Returns
`Key`:

### keyForPublicKey

src/utils.js

Generate the key for a public key.

keyForPublicKey(peer: PeerId): Buffer
Parameters
peer `(PeerId)`
Returns
`Buffer`:

### now

src/utils.js

Get the current time as timestamp.

now(): number
Returns
`number`:

### encodeBase32

src/utils.js

Encode a given buffer into a base32 string.

encodeBase32(buf: Buffer): string
Parameters
buf `(Buffer)`
Returns
`string`:

### decodeBase32

src/utils.js

Decode a given base32 string into a buffer.

decodeBase32(raw: string): Buffer
Parameters
raw `(string)`
Returns
`Buffer`:

### sortClosestPeers

src/utils.js

Sort peers by distance to the given `target`.

sortClosestPeers(peers: Array<PeerId>, target: Buffer): Array<PeerId>
Parameters
peers `(Array<PeerId>)`
target `(Buffer)`
Returns
`Array<PeerId>`:

### xorCompare

src/utils.js

Compare function to sort an array of elements which have a distance property which is the xor distance to a given element.

xorCompare(a: Object, b: Object): number
Parameters
a `(Object)`
b `(Object)`
Returns
`number`:

### pathSize

src/utils.js

Computes how many results to collect on each disjoint path, rounding up. This ensures that we look for at least one result per path.

pathSize(resultsWanted: number, numPaths: number): number
Parameters
resultsWanted `(number)`
numPaths `(number)` total number of paths
Returns
`number`:

### createPutRecord

src/utils.js

Create a new put record, encodes and signs it if enabled.

createPutRecord(key: Buffer, value: Buffer): Buffer
Parameters
key `(Buffer)`
value `(Buffer)`
Returns
`Buffer`:

### Network

src/network.js

Handle network operations for the dht

new Network(self: KadDHT)
Parameters
self `(KadDHT)`
Instance Members
▸ start()
src/network.js

Start the network.

start(): Promise<void>
Returns
`Promise<void>`:
▸ stop()
src/network.js

Stop all network activity.

stop(): Promise<void>
Returns
`Promise<void>`:
▸ isStarted
src/network.js

Is the network online?

isStarted

Type: bool

▸ isConnected
src/network.js

Are all network components there?

isConnected

Type: bool

▸ sendRequest(to, msg)
src/network.js

Send a request and record RTT for latency measurements.

sendRequest(to: PeerId, msg: Message): Promise<Message>
Parameters
to `(PeerId)` The peer that should receive a message
msg `(Message)` The message to send.
Returns
`Promise<Message>`:
▸ sendMessage(to, msg)
src/network.js

Sends a message without expecting an answer.

sendMessage(to: PeerId, msg: Message): Promise<void>
Parameters
to `(PeerId)`
msg `(Message)`
Returns
`Promise<void>`:

### onIncomingStream

src/rpc/index.js

Handle incoming streams on the dht protocol.

onIncomingStream
Parameters
props `(Object)`

Name | Description
--- | ---
props.stream `DuplexStream` |
props.connection `Connection` | connection

Returns
`Promise<void>`:

### getValue

src/rpc/handlers/get-value.js

Process `GetValue` DHT messages.

getValue
Parameters
peerId `(PeerId)`
msg `(Message)`
Returns
`Promise<Message>`:

### putValue

src/rpc/handlers/put-value.js

Process `PutValue` DHT messages.

putValue
Parameters
peerId `(PeerId)`
msg `(Message)`
Returns
`Promise<Message>`:

### findNode

src/rpc/handlers/find-node.js

Process `FindNode` DHT messages.

findNode
Parameters
peerId `(PeerId)`
msg `(Message)`
Returns
`Promise<Message>`:

### addProvider

src/rpc/handlers/add-provider.js

Process `AddProvider` DHT messages.

addProvider
Parameters
peerId `(PeerId)`
msg `(Message)`
Returns
`Promise<void>`:

### getProviders

src/rpc/handlers/get-providers.js

Process `GetProviders` DHT messages.

getProviders
Parameters
peerId `(PeerId)`
msg `(Message)`
Returns
`Promise<Message>`:

### ping

src/rpc/handlers/ping.js

Process `Ping` DHT messages.

ping
Parameters
peerId `(PeerId)`
msg `(Message)`
Returns
`Message`:

### put

src/content-fetching/index.js

Store the given key/value pair in the DHT.

put(key: Buffer, value: Buffer, options: Object?): Promise<void>
Parameters
key `(Buffer)`
value `(Buffer)`
options `(Object? = `{}`)` put options

Name | Description
--- | ---
options.minPeers `number?` | minimum number of peers required to successfully put (default: closestPeers.length)

Returns
`Promise<void>`:

### get

src/content-fetching/index.js

Get the value to the given key. Times out after 1 minute by default.

get(key: Buffer, options: Object?): Promise<Buffer>
Parameters
key `(Buffer)`
options `(Object? = `{}`)` get options

Name | Description
--- | ---
options.timeout `number?` | optional timeout (default: 60000)

Returns
`Promise<Buffer>`:

### getMany

src/content-fetching/index.js

Get the `n` values to the given key without sorting.

getMany(key: Buffer, nvals: number, options: Object?): Promise<Array<{from: PeerId, val: Buffer}>>
Parameters
key `(Buffer)`
nvals `(number)`
options `(Object? = `{}`)` get options

Name | Description
--- | ---
options.timeout `number?` | optional timeout (default: 60000)

Returns
`Promise<Array<{from: PeerId, val: Buffer}>>`:

### provide

src/content-routing/index.js

Announce to the network that we can provide given key's value.

provide(key: CID): Promise<void>
Parameters
key `(CID)`
Returns
`Promise<void>`:

### findProviders

src/content-routing/index.js

Search the dht for up to `K` providers of the given CID.

findProviders(key: CID, options: Object): AsyncIterable<{id: PeerId, multiaddrs: Array<Multiaddr>}>
Parameters
key `(CID)`
options `(Object = `{}`)` findProviders options

Name | Description
--- | ---
options.timeout `number` | how long the query should maximally run, in milliseconds (default: 60000)
options.maxNumProviders `number` | maximum number of providers to find

Returns
`AsyncIterable<{id: PeerId, multiaddrs: Array<Multiaddr>}>`:

### LimitedPeerList

src/peer-list/limited-peer-list.js

Like PeerList but with a length restriction.

new LimitedPeerList(limit: number)

Extends PeerList

Parameters
limit `(number)`
Instance Members
▸ push(peerData)
src/peer-list/limited-peer-list.js

Add a PeerData if it fits in the list

push(peerData: PeerData): bool
Parameters
peerData `(PeerData)`
Returns
`bool`:

### PeerList

src/peer-list/index.js

A list of unique peers.

new PeerList()
Instance Members
▸ push(peerData)
src/peer-list/index.js

Add a new peer. Returns `true` if it was a new one

push(peerData: PeerData): bool
Parameters
peerData `(PeerData)`
Returns
`bool`:
▸ has(peerId)
src/peer-list/index.js

Check if this PeerData is already in here.

has(peerId: PeerId): bool
Parameters
peerId `(PeerId)`
Returns
`bool`:
▸ toArray()
src/peer-list/index.js

Get the list as an array.

toArray(): Array<PeerData>
Returns
`Array<PeerData>`:
▸ pop()
src/peer-list/index.js

Remove the last element

pop(): PeerData
Returns
`PeerData`:
▸ length
src/peer-list/index.js

The length of the list

length

Type: number

### Query

src/query/index.js

Divide peers up into disjoint paths (subqueries). Any peer can only be used once over all paths. Within each path, query peers from closest to farthest away.

new Query(dht: DHT, key: Buffer, makePath: makePath)
Parameters
dht `(DHT)` DHT instance
key `(Buffer)`
makePath `(makePath)` Called to set up each disjoint path. Must return the query function.
Instance Members
▸ run(peers)
src/query/index.js

Run this query, start with the given list of peers first.

run(peers: Array<PeerId>): Promise
Parameters
peers `(Array<PeerId>)`
Returns
`Promise`:
▸ _onStart()
src/query/index.js

Called when the run starts.

_onStart()
▸ _onComplete()
src/query/index.js

Called when the run completes (even if there's an error).

_onComplete()
▸ stop()
src/query/index.js

Stop the query.

stop()

### Run

src/query/run.js

Manages a single run of the query.

new Run(query: Query)

Extends EventEmitter

Parameters
query `(Query)`
Instance Members
▸ stop()
src/query/run.js

Stop all the workers

stop()
▸ execute(peers)
src/query/run.js

Execute the run with the given initial set of peers.

execute(peers: Array<PeerId>): Promise
Parameters
peers `(Array<PeerId>)`
Returns
`Promise`:
▸ executePaths(paths)
src/query/run.js

Execute all paths through the DHT.

executePaths(paths: Array<Path>): Promise<void>
Parameters
paths `(Array<Path>)`
Returns
`Promise<void>`:
▸ workerQueue(path)
src/query/run.js

Initialize the list of queried peers, then start a worker queue for the given path.

workerQueue(path: Path): Promise<void>
Parameters
path `(Path)`
Returns
`Promise<void>`:
▸ startWorker(path)
src/query/run.js

Create and start a worker queue for a particular path.

startWorker(path: Path): Promise<void>
Parameters
path `(Path)`
Returns
`Promise<void>`:
▸ init()
src/query/run.js

Initialize the list of closest peers we've queried - this is shared by all paths in the run.

init(): Promise<void>
Returns
`Promise<void>`:
▸ continueQuerying(worker)
src/query/run.js

If we've queried K peers, and the remaining peers in the given `worker`'s queue are all further from the key than the peers we've already queried, then we should stop querying on that `worker`.

continueQuerying(worker: WorkerQueue): Promise<Boolean>
Parameters
worker `(WorkerQueue)`
Returns
`Promise<Boolean>`:

### PeerDistanceList

src/peer-list/peer-distance-list.js

Maintains a list of peerIds sorted by distance from a DHT key.

new PeerDistanceList(originDhtKey: Buffer, capacity: number)
Parameters
originDhtKey `(Buffer)` the DHT key from which distance is calculated
capacity `(number)` the maximum size of the list
Instance Members
▸ length
src/peer-list/peer-distance-list.js

The length of the list

length
▸ peers
src/peer-list/peer-distance-list.js

The peerIds in the list, in order of distance from the origin key

peers
▸ add(peerId)
src/peer-list/peer-distance-list.js

Add a peerId to the list.

add(peerId: PeerId): Promise<void>
Parameters
peerId `(PeerId)`
Returns
`Promise<void>`:
▸ anyCloser(peerIds)
src/peer-list/peer-distance-list.js

Indicates whether any of the peerIds passed as a parameter are closer to the origin key than the furthest peerId in the PeerDistanceList.

anyCloser(peerIds: Array<PeerId>): Boolean
Parameters
peerIds `(Array<PeerId>)`
Returns
`Boolean`:

### Path

src/query/path.js

Manages a single Path through the DHT.

new Path(run: Run, queryFunc: queryFunc)
Parameters
run `(Run)`
queryFunc `(queryFunc)`
Instance Members
▸ initialPeers
src/query/path.js
initialPeers

Type: Array<PeerId>

▸ peersToQuery
src/query/path.js
peersToQuery

Type: PeerQueue

▸ addInitialPeer(peer)
src/query/path.js

Add a peer to the set of peers that are used to intialize the path.

addInitialPeer(peer: PeerId)
Parameters
peer `(PeerId)`
▸ execute()
src/query/path.js

Execute the path.

execute(): Promise
Returns
`Promise`:
▸ addPeerToQuery(peer)
src/query/path.js

Add a peer to the peers to be queried.

addPeerToQuery(peer: PeerId): Promise<void>
Parameters
peer `(PeerId)`
Returns
`Promise<void>`:

### PeerQueue

src/peer-list/peer-queue.js

PeerQueue is a heap that sorts its entries (PeerIds) by their xor distance to the inital provided key.

new PeerQueue(from: Buffer)
Parameters
from `(Buffer)` The sha2-256 encoded peer id
Static Members
▸ fromPeerId(id)
src/peer-list/peer-queue.js

Create from a given peer id.

fromPeerId(id: PeerId): Promise<PeerQueue>
Parameters
id `(PeerId)`
Returns
`Promise<PeerQueue>`:
▸ fromKey(keyBuffer)
src/peer-list/peer-queue.js

Create from a given buffer.

fromKey(keyBuffer: Buffer): Promise<PeerQueue>
Parameters
keyBuffer `(Buffer)`
Returns
`Promise<PeerQueue>`:
Instance Members
▸ enqueue(id)
src/peer-list/peer-queue.js

Add a new PeerId to the queue.

enqueue(id: PeerId): Promise
Parameters
id `(PeerId)`
Returns
`Promise`:
▸ dequeue()
src/peer-list/peer-queue.js

Returns the closest peer to the `from` peer.

dequeue(): PeerId
Returns
`PeerId`:

### constructor

src/query/workerQueue.js

Creates a new WorkerQueue.

constructor(dht: DHT, run: Run, path: Object, log: function)
Parameters
dht `(DHT)`
run `(Run)`
path `(Object)`
log `(function)`

### setupQueue

src/query/workerQueue.js

Create the underlying async queue.

setupQueue(): Object
Returns
`Object`:

### stop

src/query/workerQueue.js

Stop the worker, optionally providing an error to pass to the worker's callback.

stop(err: Error)
Parameters
err `(Error)`

### execute

src/query/workerQueue.js

Use the queue from async to keep `concurrency` amount items running per path.

execute(): Promise<void>
Returns
`Promise<void>`:

### fill

src/query/workerQueue.js

Add peers to the worker queue until there are enough to satisfy the worker queue concurrency. Note that we don't want to take any more than those required to satisfy concurrency from the peers-to-query queue, because we always want to query the closest peers to the key first, and new peers are continously being added to the peers-to-query queue.

fill()

### processNext

src/query/workerQueue.js

Process the next peer in the queue

processNext(peer: PeerId): Promise<void>
Parameters
peer `(PeerId)`
Returns
`Promise<void>`:

### findPeerLocal

src/peer-routing/index.js

Look if we are connected to a peer with the given id. Returns its id and addresses, if found, otherwise `undefined`.

findPeerLocal
Parameters
peer `(PeerId)`
Returns
`Promise<{id: PeerId, multiaddrs: Array<Multiaddr>}>`:

### findPeer

src/peer-routing/index.js

Search for a peer with the given ID.

findPeer(id: PeerId, options: Object): Promise<{id: PeerId, multiaddrs: Array<Multiaddr>}>
Parameters
id `(PeerId)`
options `(Object = `{}`)` findPeer options

Name | Description
--- | ---
options.timeout `number` | how long the query should maximally run, in milliseconds (default: 60000)

Returns
`Promise<{id: PeerId, multiaddrs: Array<Multiaddr>}>`:

### getClosestPeers

src/peer-routing/index.js

Kademlia 'node lookup' operation.

getClosestPeers(key: Buffer, options: Object?): AsyncIterable<PeerId>
Parameters
key `(Buffer)`
options `(Object? = `{shallow:false}`)`

Name | Description
--- | ---
options.shallow `boolean?` | shallow query (default: false)

Returns
`AsyncIterable<PeerId>`:

### getPublicKey

src/peer-routing/index.js

Get the public key for the given peer id.

getPublicKey(peer: PeerId): Promise<PubKey>
Parameters
peer `(PeerId)`
Returns
`Promise<PubKey>`:

### Message

src/message/index.js

Represents a single DHT control message.

new Message(type: MessageType, key: Buffer, level: number)
Parameters
type `(MessageType)`
key `(Buffer)`
level `(number)`
Static Members
▸ deserialize(raw)
src/message/index.js

Decode from protobuf

deserialize(raw: Buffer): Message
Parameters
raw `(Buffer)`
Returns
`Message`:
Instance Members
▸ clusterLevel
src/message/index.js
clusterLevel

Type: number

▸ serialize()
src/message/index.js

Encode into protobuf

serialize(): Buffer
Returns
`Buffer`:

### Providers

src/providers.js

This class manages known providers. A provider is a peer that we know to have the content for a given CID.

Every `cleanupInterval` providers are checked if they are still valid, i.e. younger than the `provideValidity`. If they are not, they are deleted.

To ensure the list survives restarts of the daemon, providers are stored in the datastore, but to ensure access is fast there is an LRU cache in front of that.

new Providers(datastore: Object, self: PeerId?, cacheSize: number)
Parameters
datastore `(Object)`
self `(PeerId?)`
cacheSize `(number = `256`)`
Instance Members
▸ cleanupInterval
src/providers.js

How often invalid records are cleaned. (in seconds)

cleanupInterval

Type: number

▸ provideValidity
src/providers.js

How long is a provider valid for. (in seconds)

provideValidity

Type: number

▸ lruCacheSize
src/providers.js

LRU cache size

lruCacheSize

Type: number

▸ stop()
src/providers.js

Release any resources.

stop(): void
Returns
`void`:
▸ addProvider(cid, provider)
src/providers.js

Add a new provider for the given CID.

addProvider(cid: CID, provider: PeerId): Promise<void>
Parameters
cid `(CID)`
provider `(PeerId)`
Returns
`Promise<void>`:
▸ getProviders(cid)
src/providers.js

Get a list of providers for the given CID.

getProviders(cid: CID): Promise<Array<PeerId>>
Parameters
cid `(CID)`
Returns
`Promise<Array<PeerId>>`:

### constructor

src/random-walk.js
new constructor(dht: DHT, options: object)
Parameters
dht `(DHT)`
options `(object)`

Name | Description
--- | ---
options.enabled `randomWalkOptions.enabled` |
options.queriesPerPeriod `randomWalkOptions.queriesPerPeriod` |
options.interval `randomWalkOptions.interval` |
options.timeout `randomWalkOptions.timeout` |
options.delay `randomWalkOptions.delay` |
options.dht `DHT` |

### start

src/random-walk.js

Start the Random Walk process. This means running a number of queries every interval requesting random data. This is done to keep the dht healthy over time.

start(): void
Returns
`void`:

### stop

src/random-walk.js

Stop the random-walk process. Any active queries will be aborted.

stop(): void
Returns
`void`:

### QueryManager

src/query-manager.js

Keeps track of all running queries.

new QueryManager()
Instance Members
▸ queryStarted(query)
src/query-manager.js

Called when a query is started.

queryStarted(query: Query)
Parameters
query `(Query)`
▸ queryCompleted(query)
src/query-manager.js

Called when a query completes.

queryCompleted(query: Query)
Parameters
query `(Query)`
▸ start()
src/query-manager.js

Starts the query manager.

start()
▸ stop()
src/query-manager.js

Stops all queries.

stop()