From a34d2bbcc3d69ec3006137a909a7e8c53b9d378e Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 11 Feb 2021 14:37:34 +0100 Subject: [PATCH] fix: routers should only use dht if enabled (#885) --- src/content-routing/index.js | 2 +- src/peer-routing.js | 2 +- test/content-routing/content-routing.node.js | 4 ++++ test/peer-routing/peer-routing.node.js | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/content-routing/index.js b/src/content-routing/index.js index f5d99926..f409daa3 100644 --- a/src/content-routing/index.js +++ b/src/content-routing/index.js @@ -35,7 +35,7 @@ class ContentRouting { this.dht = libp2p._dht // If we have the dht, add it to the available content routers - if (this.dht) { + if (this.dht && libp2p._config.dht.enabled) { this.routers.push(this.dht) } } diff --git a/src/peer-routing.js b/src/peer-routing.js index 637b8d24..32c9cc20 100644 --- a/src/peer-routing.js +++ b/src/peer-routing.js @@ -36,7 +36,7 @@ class PeerRouting { this._routers = libp2p._modules.peerRouting || [] // If we have the dht, add it to the available peer routers - if (libp2p._dht) { + if (libp2p._dht && libp2p._config.dht.enabled) { this._routers.push(libp2p._dht) } diff --git a/test/content-routing/content-routing.node.js b/test/content-routing/content-routing.node.js index a747b179..09a11f25 100644 --- a/test/content-routing/content-routing.node.js +++ b/test/content-routing/content-routing.node.js @@ -129,6 +129,10 @@ describe('content-routing', () => { afterEach(() => node.stop()) + it('should only have one router', () => { + expect(node.contentRouting.routers).to.have.lengthOf(1) + }) + it('should use the delegate router to provide', () => { const deferred = pDefer() diff --git a/test/peer-routing/peer-routing.node.js b/test/peer-routing/peer-routing.node.js index 3432cba8..2badd359 100644 --- a/test/peer-routing/peer-routing.node.js +++ b/test/peer-routing/peer-routing.node.js @@ -132,6 +132,10 @@ describe('peer-routing', () => { afterEach(() => node.stop()) + it('should only have one router', () => { + expect(node.peerRouting._routers).to.have.lengthOf(1) + }) + it('should use the delegate router to find peers', async () => { const deferred = pDefer() const [remotePeerId] = await peerUtils.createPeerId({ fixture: false })