0.19.7
A DHT implementation modeled after Kademlia with S/Kademlia modifications. Original implementation in go: https://github.com/libp2p/go-libp2p-kad-dht.
Extends EventEmitter
(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 {} )
|
(Object)
Local reference to the libp2p dialer instance
Type: Dialer
Local peer-id
Type: PeerId
Local PeerStore
Type: PeerStore
Local peer info
Type: Registrar
ALPHA concurrency at which each query path with run, defaults to 3
Type: number
Number of disjoint query paths to use
This is set to kBucketSize
/2 per the S/Kademlia paper
Type: number
The routing table.
Type: RoutingTable
Reference to the datastore, uses an in-memory store if none given.
Type: Datastore
Random walk management
Type: RandomWalk
Keeps track of running queries
Type: QueryManager
Is this DHT running.
Type: bool
Search the dht for up to K
providers of the given CID.
(CID)
AsyncIterable<{id: PeerId, multiaddrs: Array<Multiaddr>}>
:
A wrapper around k-bucket
, to provide easy store and
retrival for peers.
(PeerId)
(number)
Creates a DHT ID by hashing a given buffer.
(Buffer)
Promise<Buffer>
:
Creates a DHT ID by hashing a Peer ID
(PeerId)
Promise<Buffer>
:
Convert a buffer to their SHA2-256 hash.
(Buffer)
Key
:
Generate the key for a public key.
(PeerId)
Buffer
:
Get the current time as timestamp.
number
:
Encode a given buffer into a base32 string.
(Buffer)
string
:
Decode a given base32 string into a buffer.
(string)
Buffer
:
Sort peers by distance to the given target
.
Array<PeerId>
:
Compare function to sort an array of elements which have a distance property which is the xor distance to a given element.
number
:
Computes how many results to collect on each disjoint path, rounding up. This ensures that we look for at least one result per path.
number
:
Create a new put record, encodes and signs it if enabled.
Buffer
:
Handle network operations for the dht
(KadDHT)
Is the network online?
Type: bool
Are all network components there?
Type: bool
Handle incoming streams on the dht protocol.
(Object)
Name | Description |
---|---|
props.stream DuplexStream
|
|
props.connection Connection
|
connection |
Promise<void>
:
Process GetValue
DHT messages.
(PeerId)
(Message)
Promise<Message>
:
Process PutValue
DHT messages.
(PeerId)
(Message)
Promise<Message>
:
Process FindNode
DHT messages.
(PeerId)
(Message)
Promise<Message>
:
Process AddProvider
DHT messages.
(PeerId)
(Message)
Promise<void>
:
Process GetProviders
DHT messages.
(PeerId)
(Message)
Promise<Message>
:
Process Ping
DHT messages.
(PeerId)
(Message)
Message
:
Store the given key/value pair in the DHT.
Promise<void>
:
Get the value to the given key. Times out after 1 minute by default.
(Buffer)
Promise<Buffer>
:
Get the n
values to the given key without sorting.
Promise<Array<{from: PeerId, val: Buffer}>>
:
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.
(DHT)
DHT instance
(Buffer)
(makePath)
Called to set up each disjoint path. Must return the query function.
Manages a single run of the query.
Extends EventEmitter
(Query)
Stop all the workers
Maintains a list of peerIds sorted by distance from a DHT key.
(Buffer)
the DHT key from which distance is calculated
(number)
the maximum size of the list
Manages a single Path through the DHT.
(Run)
(queryFunc)
Add a peer to the set of peers that are used to intialize the path.
(PeerId)
PeerQueue is a heap that sorts its entries (PeerIds) by their xor distance to the inital provided key.
(Buffer)
The sha2-256 encoded peer id
Creates a new WorkerQueue.
Create the underlying async queue.
Object
:
Stop the worker, optionally providing an error to pass to the worker's callback.
(Error)
Use the queue from async to keep concurrency
amount items running
per path.
Promise<void>
:
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.
Process the next peer in the queue
(PeerId)
Promise<void>
:
Announce to the network that we can provide given key's value.
(CID)
Promise<void>
:
Search the dht for up to K
providers of the given CID.
(CID)
AsyncIterable<{id: PeerId, multiaddrs: Array<Multiaddr>}>
:
Like PeerList but with a length restriction.
Extends PeerList
(number)
Add a PeerData if it fits in the list
(PeerData)
bool
:
A list of unique peers.
Add a new peer. Returns true
if it was a new one
(PeerData)
bool
:
Check if this PeerData is already in here.
(PeerId)
bool
:
Remove the last element
PeerData
:
Look if we are connected to a peer with the given id.
Returns its id and addresses, if found, otherwise undefined
.
(PeerId)
Promise<{id: PeerId, multiaddrs: Array<Multiaddr>}>
:
Search for a peer with the given ID.
(PeerId)
Promise<{id: PeerId, multiaddrs: Array<Multiaddr>}>
:
Kademlia 'node lookup' operation.
(Buffer)
AsyncIterable<PeerId>
:
Get the public key for the given peer id.
(PeerId)
Promise<PubKey>
:
Represents a single DHT control message.
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.
Start the provider cleanup service
void
:
Release any resources.
void
:
(DHT)
(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 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.
void
:
Stop the random-walk process. Any active queries will be aborted.
void
:
Keeps track of all running queries.