fix: routers should only use dht if enabled (#885)

This commit is contained in:
Vasco Santos 2021-02-11 14:37:34 +01:00 committed by GitHub
parent 9941414a91
commit a34d2bbcc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

View File

@ -35,7 +35,7 @@ class ContentRouting {
this.dht = libp2p._dht this.dht = libp2p._dht
// If we have the dht, add it to the available content routers // 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) this.routers.push(this.dht)
} }
} }

View File

@ -36,7 +36,7 @@ class PeerRouting {
this._routers = libp2p._modules.peerRouting || [] this._routers = libp2p._modules.peerRouting || []
// If we have the dht, add it to the available peer routers // 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) this._routers.push(libp2p._dht)
} }

View File

@ -129,6 +129,10 @@ describe('content-routing', () => {
afterEach(() => node.stop()) 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', () => { it('should use the delegate router to provide', () => {
const deferred = pDefer() const deferred = pDefer()

View File

@ -132,6 +132,10 @@ describe('peer-routing', () => {
afterEach(() => node.stop()) 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 () => { it('should use the delegate router to find peers', async () => {
const deferred = pDefer() const deferred = pDefer()
const [remotePeerId] = await peerUtils.createPeerId({ fixture: false }) const [remotePeerId] = await peerUtils.createPeerId({ fixture: false })