Skip to content

Commit c5c89d4

Browse files
committed
fix: dht get options
1 parent 69f7264 commit c5c89d4

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"dirty-chai": "^2.0.1",
6060
"electron-webrtc": "~0.3.0",
6161
"libp2p-circuit": "~0.2.0",
62-
"libp2p-kad-dht": "~0.10.1",
62+
"libp2p-kad-dht": "~0.10.3",
6363
"libp2p-mdns": "~0.12.0",
6464
"libp2p-mplex": "~0.8.0",
6565
"libp2p-railing": "~0.9.2",

src/dht.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ module.exports = (node) => {
99

1010
node._dht.put(key, value, callback)
1111
},
12-
get: (key, maxTimeout, callback) => {
13-
if (typeof maxTimeout === 'function') {
14-
callback = maxTimeout
15-
maxTimeout = null
12+
get: (key, options, callback) => {
13+
if (typeof options === 'function') {
14+
callback = options
15+
options = {}
1616
}
1717

1818
if (!node._dht) {
1919
return callback(new Error('DHT is not available'))
2020
}
2121

22-
node._dht.get(key, maxTimeout, callback)
22+
node._dht.get(key, options, callback)
2323
},
24-
getMany: (key, nVals, maxTimeout, callback) => {
25-
if (typeof maxTimeout === 'function') {
26-
callback = maxTimeout
27-
maxTimeout = null
24+
getMany: (key, nVals, options, callback) => {
25+
if (typeof options === 'function') {
26+
callback = options
27+
options = {}
2828
}
2929

3030
if (!node._dht) {
3131
return callback(new Error('DHT is not available'))
3232
}
3333

34-
node._dht.getMany(key, nVals, maxTimeout, callback)
34+
node._dht.getMany(key, nVals, options, callback)
3535
}
3636
}
3737
}

test/dht.node.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ describe('.dht', () => {
5353
})
5454
})
5555

56-
it('should be able to dht.get a value from the DHT with a maxTimeout', (done) => {
56+
it('should be able to dht.get a value from the DHT with options', (done) => {
5757
const key = Buffer.from('/v/hello')
5858
const value = Buffer.from('world')
5959

6060
nodeA.dht.put(key, value, (err) => {
6161
expect(err).to.not.exist()
6262

63-
nodeA.dht.get(key, 3000, (err, res) => {
63+
nodeA.dht.get(key, { maxTimeout: 3000 }, (err, res) => {
6464
expect(err).to.not.exist()
6565
expect(res).to.eql(value)
6666
done()
6767
})
6868
})
6969
})
7070

71-
it('should be able to dht.get a value from the DHT with no maxTimeout defined', (done) => {
71+
it('should be able to dht.get a value from the DHT with no options defined', (done) => {
7272
const key = Buffer.from('/v/hello')
7373
const value = Buffer.from('world')
7474

@@ -83,22 +83,22 @@ describe('.dht', () => {
8383
})
8484
})
8585

86-
it('should be able to dht.getMany a value from the DHT with a maxTimeout', (done) => {
86+
it('should be able to dht.getMany a value from the DHT with options', (done) => {
8787
const key = Buffer.from('/v/hello')
8888
const value = Buffer.from('world')
8989

9090
nodeA.dht.put(key, value, (err) => {
9191
expect(err).to.not.exist()
9292

93-
nodeA.dht.getMany(key, 1, (err, res) => {
93+
nodeA.dht.getMany(key, 1, { maxTimeout: 3000 }, (err, res) => {
9494
expect(err).to.not.exist()
9595
expect(res).to.exist()
9696
done()
9797
})
9898
})
9999
})
100100

101-
it('should be able to dht.getMany a value from the DHT with no maxTimeout defined', (done) => {
101+
it('should be able to dht.getMany a value from the DHT with no options defined', (done) => {
102102
const key = Buffer.from('/v/hello')
103103
const value = Buffer.from('world')
104104

0 commit comments

Comments
 (0)