From a9bc5632ac014e8a4dcf2930cf710ec499ebd9f1 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Mon, 15 Jul 2019 15:38:39 +0200 Subject: [PATCH] rebootstrap if we become unreachable --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 4033bef..2ff2f9f 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,7 @@ class DHT extends EventEmitter { _ontick () { this._tick++ if ((this._tick & 7) === 0) this._pingSome() + if ((this._tick & 63) === 0 && this.nodes.length < 20) this.bootstrap() } address () { @@ -268,6 +269,9 @@ class DHT extends EventEmitter { var cnt = this.inflightQueries > 2 ? 1 : 3 var oldest = this.nodes.oldest + // tiny dht, ping the bootstrap again + if (!oldest) return this.bootstrap() + while (cnt--) { if (!oldest || this._tick === oldest.tick) continue this._check(oldest)