Skip to content

Commit

Permalink
fix: routers should only use dht if enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Feb 11, 2021
1 parent 1af8472 commit ad111a1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/content-routing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/peer-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions test/content-routing/content-routing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 4 additions & 0 deletions test/peer-routing/peer-routing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit ad111a1

Please sign in to comment.