From ad111a12686687473f26118c1c0b3509ecc6079e Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 9 Feb 2021 16:37:43 +0100 Subject: [PATCH] fix: routers should only use dht if enabled --- 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 f5d999264d..f409daa3c4 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 637b8d2425..32c9cc20e8 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 30caf0d610..b5869e0fa6 100644 --- a/test/content-routing/content-routing.node.js +++ b/test/content-routing/content-routing.node.js @@ -131,6 +131,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 3432cba8a4..2badd3597a 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 })