Skip to content

Latest commit

 

History

History
149 lines (85 loc) · 3.87 KB

DHT.md

File metadata and controls

149 lines (85 loc) · 3.87 KB

DHT API

dht.findpeer

Retrieve the Peer Info of a reachable node in the network.

Go WIP
JavaScript - ipfs.dht.findpeer(peerId, [callback])

Where peerId is a IPFS/libp2p Id of type PeerId.

callback must follow function (err, peerInfo) {} signature, where err is an error if the operation was not successful. peerInfo is an object of type PeerInfo

If no callback is passed, a promise is returned.

Example:

var id = PeerId.create()

ipfs.dht.findpeer(id, function (err, peerInfo) {
  // peerInfo will contain the multiaddrs of that peer
})

A great source of examples can be found in the tests for this API.

dht.findprovs

Retrieve the providers for content that is addressed by an hash.

Go WIP
JavaScript - ipfs.dht.findprovs(hash, [callback])

Where hash is a multihash.

callback must follow function (err, peerInfos) {} signature, where err is an error if the operation was not successful. peerInfos is an array of objects of type PeerInfo

If no callback is passed, a promise is returned.

Example:

ipfs.dht.findprovs(multihash, function (err, peerInfos) {})

A great source of examples can be found in the tests for this API.

dht.get

Retrieve a value from DHT

Go WIP
JavaScript - ipfs.dht.get(key, [callback])

Where key is a string.

callback must follow function (err, value) {} signature, where err is an error if the operation was not successful. value is the value that was stored under that key.

If no callback is passed, a promise is returned.

Example:

ipfs.dht.get(key, function (err, value) {})

A great source of examples can be found in the tests for this API.

dht.provide

Announce to the network that you are providing given values.

Go WIP
JavaScript - ipfs.dht.provide(cid, [callback])

Where cid is a CID or array of CIDs.

callback must follow function (err) {} signature, where err is an error if the operation was not successful.

If no callback is passed, a promise is returned.

Example:

ipfs.dht.provide(cid, function (err) {})

A great source of examples can be found in the tests for this API.

dht.put

Store a value on the DHT

Go WIP
JavaScript - ipfs.dht.put(key, value, [callback])

Where key is a string and value can be of any type.

callback must follow function (err) {} signature, where err is an error if the operation was not successful.

If no callback is passed, a promise is returned.

Example:

ipfs.dht.put(key, value, function (err) {})

A great source of examples can be found in the tests for this API.

dht.query

Queries the network for the 'closest peers' to a given key. 'closest' is defined by the rules of the underlying Peer Routing mechanism.

Go WIP
JavaScript - ipfs.dht.query(peerId, [callback])

Where peerId is a IPFS/libp2p Id of type PeerId.

callback must follow function (err, peerInfos) {} signature, where err is an error if the operation was not successful. peerInfos is an array of objects of type PeerInfo

If no callback is passed, a promise is returned.

Example:

const id = PeerId.create()

ipfs.dht.query(id, function (err, peerInfos) {
})

A great source of examples can be found in the tests for this API.