diff --git a/src/core/ipns/routing/config.js b/src/core/ipns/routing/config.js index 7faa469258..2407c0d3cb 100644 --- a/src/core/ipns/routing/config.js +++ b/src/core/ipns/routing/config.js @@ -22,7 +22,7 @@ module.exports = (ipfs) => { } // DHT should not be added as routing if we are offline or it is disabled - if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', false)) { + if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', true)) { const offlineDatastore = new OfflineDatastore(ipfs._repo) ipnsStores.push(offlineDatastore) } else { diff --git a/test/core/name.js b/test/core/name.js index 1ad7bc3b7b..74d8b492b0 100644 --- a/test/core/name.js +++ b/test/core/name.js @@ -537,8 +537,16 @@ describe('name', function () { }) describe('ipns.routing', function () { - it('should use only the offline datastore by default', function (done) { - const ipfs = {} + it('should use offline datastore if DHT is disabled', function (done) { + const ipfs = { + _options: { + libp2p: { + dht: { + enabled: false + } + } + } + } const config = ipnsRouting(ipfs) expect(config.stores).to.have.lengthOf(1) @@ -562,8 +570,11 @@ describe('name', function () { }) it('should use the pubsub datastore if enabled', function (done) { + const dht = {} + const ipfs = { libp2p: { + dht, pubsub: {} }, _peerInfo: { @@ -581,8 +592,8 @@ describe('name', function () { const config = ipnsRouting(ipfs) expect(config.stores).to.have.lengthOf(2) - expect(config.stores[0] instanceof PubsubDatastore).to.eql(true) - expect(config.stores[1] instanceof OfflineDatastore).to.eql(true) + expect(config.stores.some(s => s instanceof PubsubDatastore)).to.eql(true) + expect(config.stores).to.include(dht) done() }) @@ -616,5 +627,16 @@ describe('name', function () { done() }) + + it('should use the dht by default', function (done) { + const dht = {} + const ipfs = { libp2p: { dht } } + const config = ipnsRouting(ipfs) + + expect(config.stores).to.have.lengthOf(1) + expect(config.stores[0]).to.eql(dht) + + done() + }) }) })