Browse Source

revert id === null logic as it causes timeouts with bootstrap nodes

v4
Mathias Buus 5 years ago
parent
commit
f982562ca4
  1. 13
      lib/io.js
  2. 5
      lib/query-stream.js
  3. 40
      test.js

13
lib/io.js

@ -219,19 +219,6 @@ class IO {
}
response (request, value, closerNodes, peer) {
if (this._ctx.ephemeral) {
const privateCommand = request.command.charCodeAt(0) === 95 // '_'
if (privateCommand === false) {
// if a node was non-ephemeral and then was
// set to ephemeral, other DHT nodes will
// still have a reference to the node. Therefore
// if the node is ephemeral and the request
// is not a DHT internals command ignore the
// request to make other nodes remove it from
// their list.
return
}
}
const message = {
type: TYPE.RESPONSE,
rid: request.rid,

5
lib/query-stream.js

@ -95,11 +95,6 @@ class QueryStream extends Readable {
return
}
if (message.id === null) {
this._readMaybe()
return
}
const value = this._outputEncoding
? this._decodeOutput(message.value)
: message.value

40
test.js

@ -246,46 +246,6 @@ tape('setEphemeral(false)', function (t) {
})
})
tape('setEphemeral(true)', function (t) {
bootstrap(function (port, node) {
const a = dht({ bootstrap: port, ephemeral: false })
const b = dht({ bootstrap: port })
a.command('hello', {
query (data, callback) {
callback(null, Buffer.from('world'))
}
})
a.ready(function () {
b.ready(function () {
const key = blake2b(Buffer.from('hello'))
b.query('hello', key, (err, result) => {
t.error(err)
t.is(result.length, 1)
t.is(Buffer.compare(result[0].node.id, a.id), 0)
a.setEphemeral(true, (err) => {
t.error(err)
b.query('hello', key, (err, result) => {
t.ok(err)
})
b.once('remove-node', () => {
b.query('hello', key, (err, result) => {
t.error(err)
t.is(result.length, 0)
a.destroy()
b.destroy()
node.destroy()
t.end()
})
})
})
})
})
})
})
})
function bootstrap (done) {
const node = dht({
ephemeral: true

Loading…
Cancel
Save