Retrieve the Peer Info of a reachable node in the network.
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.
Retrieve the providers for content that is addressed by an hash.
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.
Retrieve a value from DHT
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.
Announce to the network that you are providing given values.
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.
Store a value on the DHT
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.
Queries the network for the 'closest peers' to a given key. 'closest' is defined by the rules of the underlying Peer Routing mechanism.
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.