Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: put query for closest peers
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Mar 4, 2019
1 parent e2af4ae commit 7b80020
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class KadDHT extends EventEmitter {
(cb) => utils.createPutRecord(key, value, cb),
(rec, cb) => waterfall([
(cb) => this._putLocal(key, rec, cb),
(cb) => this.getClosestPeers(key, cb),
(cb) => this.getClosestPeers(key, { shallow: true }, cb),
(peers, cb) => {
// Ensure we have a default `minPeers`
options.minPeers = options.minPeers || peers.length
Expand Down Expand Up @@ -387,11 +387,21 @@ class KadDHT extends EventEmitter {
* Kademlia 'node lookup' operation.
*
* @param {Buffer} key
* @param {Object} options
* @param {boolean} options.shallow shallow query
* @param {function(Error, Array<PeerId>)} callback
* @returns {void}
*/
getClosestPeers (key, callback) {
getClosestPeers (key, options, callback) {
this._log('getClosestPeers to %b', key)

if (typeof options === 'function') {
callback = options
options = {
shallow: false
}
}

utils.convertBuffer(key, (err, id) => {
if (err) {
return callback(err)
Expand All @@ -408,7 +418,8 @@ class KadDHT extends EventEmitter {
(cb) => this._closerPeersSingle(key, peer, cb),
(closer, cb) => {
cb(null, {
closerPeers: closer
closerPeers: closer,
success: options.shallow ? true : undefined
})
}
], callback)
Expand Down

0 comments on commit 7b80020

Please sign in to comment.