diff --git a/src/index.js b/src/index.js index 78ccf562..73333112 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, true, cb), (peers, cb) => { // Ensure we have a default `minPeers` options.minPeers = options.minPeers || peers.length @@ -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)} 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) @@ -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)