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 1, 2019
1 parent e2af4ae commit 1dd3f43
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 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, true, cb),
(peers, cb) => {
// Ensure we have a default `minPeers`
options.minPeers = options.minPeers || peers.length
Expand Down Expand Up @@ -387,11 +387,20 @@ class KadDHT extends EventEmitter {
* Kademlia 'node lookup' operation.
*
* @param {Buffer} key
* @param {boolean} isOneIteration query with one iteration
* @param {function(Error, Array<PeerId>)} callback
* @returns {void}
*/
getClosestPeers (key, callback) {
getClosestPeers (key, isOneIteration, callback) {
this._log('getClosestPeers to %b', key)

if (typeof isOneIteration === 'function') {
callback = isOneIteration
isOneIteration = false
} else if (typeof isOneIteration !== 'boolean') {
isOneIteration = false
}

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

0 comments on commit 1dd3f43

Please sign in to comment.