Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
docs: updated spec
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Nov 20, 2018
1 parent c49a6de commit f258ad7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions SPEC/DHT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

##### `JavaScript` - ipfs.dht.findpeer(peerId, [callback])

Where `peerId` is a IPFS/libp2p Id of type [PeerId](https://github.com/libp2p/js-peer-id).
Where `peerId` is a IPFS/libp2p Id from [PeerId](https://github.com/libp2p/js-peer-id) type.

`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](https://github.com/libp2p/js-peer-info)
`callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. `res` is an object containing `responses` as an array of peer responses. In this case, as we are looking for a particular peer, there will be only one response. This response is composed by the peerId, as well as an array with its adresses.

If no `callback` is passed, a promise is returned.

Expand All @@ -26,8 +26,10 @@ If no `callback` is passed, a promise is returned.
```JavaScript
var id = PeerId.create()

ipfs.dht.findpeer(id, function (err, peerInfo) {
ipfs.dht.findpeer(id, function (err, res) {
// peerInfo will contain the multiaddrs of that peer
const id = res.responses[0].id
const addrs = res.responses[0].addrs
})
```

Expand All @@ -46,16 +48,16 @@ Where `hash` is a multihash.
`options` an optional object with the following properties
- `timeout` - a maximum timeout in milliseconds

`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](https://github.com/libp2p/js-peer-info)
`callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. `res` is an object containing `responses` as an array of peer responses. Each entry of this array is composed by the peerId, as well as an array with its adresses.

If no `callback` is passed, a promise is returned.

**Example:**

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

ipfs.dht.findprovs(multihash, { timeout: 4000 }, function (err, peerInfos) {})
ipfs.dht.findprovs(multihash, { timeout: 4000 }, function (err, res) {})
```

A great source of [examples][] can be found in the tests for this API.
Expand Down

0 comments on commit f258ad7

Please sign in to comment.