This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
fix: dht responses #414
Merged
Merged
fix: dht responses #414
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,11 @@ | |
|
||
##### Go **WIP** | ||
|
||
##### JavaScript - `ipfs.dht.findpeer(peerId, [callback])` | ||
##### JavaScript - `ipfs.dht.findPeer(peerId, [callback])` | ||
|
||
Where `peerId` is a IPFS/libp2p Id from [PeerId](https://github.com/libp2p/js-peer-id) type. | ||
|
||
`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. | ||
`callback` must follow `function (err, peerInfos) {}` signature, where `err` is an error if the operation was not successful. `peerInfos` is an array of type `[PeerInfo]`. In this case, as we are looking for a particular peer, there will be only one entry. This entry is composed by the peerId, as well as its adresses. | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
|
@@ -26,10 +26,10 @@ If no `callback` is passed, a promise is returned. | |
```JavaScript | ||
var id = PeerId.create() | ||
|
||
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 | ||
ipfs.dht.findPeer(id, function (err, peerInfos) { | ||
// peerInfos will contain the multiaddrs of that peer in the first entry of the array | ||
const id = peerInfos[0].id | ||
const addrs = peerInfos[0].multiaddrs | ||
}) | ||
``` | ||
|
||
|
@@ -41,23 +41,24 @@ A great source of [examples][] can be found in the tests for this API. | |
|
||
##### Go **WIP** | ||
|
||
##### JavaScript - `ipfs.dht.findprovs(hash, [options], [callback])` | ||
##### JavaScript - `ipfs.dht.findProvs(hash, [options], [callback])` | ||
|
||
Where `hash` is a multihash. | ||
|
||
`options` an optional object with the following properties | ||
- `timeout` - a maximum timeout in milliseconds | ||
- `maxTimeout` - a maximum timeout in milliseconds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO just |
||
- `maxNumProviders` - a maximum number of providers to find | ||
|
||
`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. | ||
`callback` must follow `function (err, peerInfos) {}` signature, where `err` is an error if the operation was not successful. `peerInfos` is an array of type `[PeerInfo]`. 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, res) {}) | ||
ipfs.dht.findProvs(multihash, function (err, res) {}) | ||
|
||
ipfs.dht.findprovs(multihash, { timeout: 4000 }, function (err, res) {}) | ||
ipfs.dht.findProvs(multihash, { timeout: 4000 }, function (err, res) {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
``` | ||
|
||
A great source of [examples][] can be found in the tests for this API. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is always one entry shall we return just the peerInfo instance?