From 7b80020a164ba5e4b3d739916141c14289790cd8 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Fri, 1 Mar 2019 16:09:03 +0000 Subject: [PATCH] fix: put query for closest peers --- src/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 78ccf562..d069428f 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -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)} 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) @@ -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)