From c5c89d4f0ac27a3c8f3a1853433067181275a7c1 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 20 Sep 2018 09:47:55 +0100 Subject: [PATCH] fix: dht get options --- package.json | 2 +- src/dht.js | 20 ++++++++++---------- test/dht.node.js | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index e1095a907c..976f64fecb 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "dirty-chai": "^2.0.1", "electron-webrtc": "~0.3.0", "libp2p-circuit": "~0.2.0", - "libp2p-kad-dht": "~0.10.1", + "libp2p-kad-dht": "~0.10.3", "libp2p-mdns": "~0.12.0", "libp2p-mplex": "~0.8.0", "libp2p-railing": "~0.9.2", diff --git a/src/dht.js b/src/dht.js index 10326aa9dd..361d84f8c1 100644 --- a/src/dht.js +++ b/src/dht.js @@ -9,29 +9,29 @@ module.exports = (node) => { node._dht.put(key, value, callback) }, - get: (key, maxTimeout, callback) => { - if (typeof maxTimeout === 'function') { - callback = maxTimeout - maxTimeout = null + get: (key, options, callback) => { + if (typeof options === 'function') { + callback = options + options = {} } if (!node._dht) { return callback(new Error('DHT is not available')) } - node._dht.get(key, maxTimeout, callback) + node._dht.get(key, options, callback) }, - getMany: (key, nVals, maxTimeout, callback) => { - if (typeof maxTimeout === 'function') { - callback = maxTimeout - maxTimeout = null + getMany: (key, nVals, options, callback) => { + if (typeof options === 'function') { + callback = options + options = {} } if (!node._dht) { return callback(new Error('DHT is not available')) } - node._dht.getMany(key, nVals, maxTimeout, callback) + node._dht.getMany(key, nVals, options, callback) } } } diff --git a/test/dht.node.js b/test/dht.node.js index 0231eb7a3f..d2c392331d 100644 --- a/test/dht.node.js +++ b/test/dht.node.js @@ -53,14 +53,14 @@ describe('.dht', () => { }) }) - it('should be able to dht.get a value from the DHT with a maxTimeout', (done) => { + it('should be able to dht.get a value from the DHT with options', (done) => { const key = Buffer.from('/v/hello') const value = Buffer.from('world') nodeA.dht.put(key, value, (err) => { expect(err).to.not.exist() - nodeA.dht.get(key, 3000, (err, res) => { + nodeA.dht.get(key, { maxTimeout: 3000 }, (err, res) => { expect(err).to.not.exist() expect(res).to.eql(value) done() @@ -68,7 +68,7 @@ describe('.dht', () => { }) }) - it('should be able to dht.get a value from the DHT with no maxTimeout defined', (done) => { + it('should be able to dht.get a value from the DHT with no options defined', (done) => { const key = Buffer.from('/v/hello') const value = Buffer.from('world') @@ -83,14 +83,14 @@ describe('.dht', () => { }) }) - it('should be able to dht.getMany a value from the DHT with a maxTimeout', (done) => { + it('should be able to dht.getMany a value from the DHT with options', (done) => { const key = Buffer.from('/v/hello') const value = Buffer.from('world') nodeA.dht.put(key, value, (err) => { expect(err).to.not.exist() - nodeA.dht.getMany(key, 1, (err, res) => { + nodeA.dht.getMany(key, 1, { maxTimeout: 3000 }, (err, res) => { expect(err).to.not.exist() expect(res).to.exist() done() @@ -98,7 +98,7 @@ describe('.dht', () => { }) }) - it('should be able to dht.getMany a value from the DHT with no maxTimeout defined', (done) => { + it('should be able to dht.getMany a value from the DHT with no options defined', (done) => { const key = Buffer.from('/v/hello') const value = Buffer.from('world')