From 0133d5c40235e3e7927bac96bacb58ea87424c71 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 27 May 2021 21:26:08 +0200 Subject: [PATCH] add to field to all node objects for easier nat stuff --- index.js | 8 ++++---- lib/query.js | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b6f3bb0..5e9dfeb 100644 --- a/index.js +++ b/index.js @@ -501,8 +501,8 @@ class DHT extends EventEmitter { // if the node is indicating that we got a new ip // make sure to add it again to the sampler. make sure we don't allow the remote node // to add multiple entries though. - if (oldNode.network !== m.to.host) { - oldNode.network = m.to.host + if (oldNode.to === null || oldNode.to.host !== m.to.host) { + oldNode.to = m.to // TODO: would be technically better to add to the head of the sample queue, but // this is prop fine const s = this._nat.sample(m.from) @@ -527,9 +527,9 @@ class DHT extends EventEmitter { port: m.from.port, host: m.from.host, token: null, // adding this so it has the same "shape" as the query nodes for easier debugging + to: m.to, added: this._tick, seen: this._tick, - network: m.to.host, prev: null, next: null }) @@ -598,9 +598,9 @@ class DHT extends EventEmitter { port, host, token: null, + to: null, added: this._tick, seen: this._tick, - network: null, prev: null, next: null }) diff --git a/lib/query.js b/lib/query.js index c786498..7de7d49 100644 --- a/lib/query.js +++ b/lib/query.js @@ -162,7 +162,8 @@ module.exports = class Query extends Readable { id: m.id, host: m.from.host, port: m.from.port, - token: m.token + token: m.token, + to: m.to }) }