Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions src/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
12 changes: 6 additions & 6 deletions test/dht.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ 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()
})
})
})

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')

Expand All @@ -83,22 +83,22 @@ 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()
})
})
})

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')

Expand Down