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

Commit 6db447f

Browse files
committed
docs: updated spec
1 parent 087bf01 commit 6db447f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

SPEC/DHT.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

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

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

20-
`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)
20+
`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.
2121

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

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

29-
ipfs.dht.findpeer(id, function (err, peerInfo) {
29+
ipfs.dht.findpeer(id, function (err, res) {
3030
// peerInfo will contain the multiaddrs of that peer
31+
const id = res.responses[0].id
32+
const addrs = res.responses[0].addrs
3133
})
3234
```
3335

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

49-
`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)
51+
`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.
5052

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

5355
**Example:**
5456

5557
```JavaScript
56-
ipfs.dht.findprovs(multihash, function (err, peerInfos) {})
58+
ipfs.dht.findprovs(multihash, function (err, res) {})
5759

58-
ipfs.dht.findprovs(multihash, { timeout: 4000 }, function (err, peerInfos) {})
60+
ipfs.dht.findprovs(multihash, { timeout: 4000 }, function (err, res) {})
5961
```
6062

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

js/src/dht/findprovs.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ module.exports = (createCommon, options) => {
5454

5555
waterfall([
5656
(cb) => nodeB.object.new('unixfs-dir', cb),
57-
(dagNode, cb) => {
58-
const cidV0 = new CID(dagNode.toJSON().multihash)
59-
nodeB.dht.provide(cidV0, (err) => cb(err, cidV0))
57+
(cid, cb) => {
58+
nodeB.dht.provide(cid, (err) => cb(err, cid))
6059
},
61-
(cidV0, cb) => nodeA.dht.findprovs(cidV0, cb),
60+
(cid, cb) => nodeA.dht.findprovs(cid, cb),
6261
(provs, cb) => {
6362
expect(provs.responses.map((p) => p.id))
6463
.to.eql([nodeB.peerId.id])

0 commit comments

Comments
 (0)