diff --git a/src/config.js b/src/config.js index 1d01fe88da..e4b48a5007 100644 --- a/src/config.js +++ b/src/config.js @@ -32,9 +32,9 @@ const OptionsSchema = Joi.object({ }) }).default(), dht: Joi.object().keys({ - kBucketSize: Joi.number().allow(null), + kBucketSize: Joi.number().default(20), enabledDiscovery: Joi.boolean().default(true) - }), + }).default(), EXPERIMENTAL: Joi.object().keys({ dht: Joi.boolean().default(false), pubsub: Joi.boolean().default(false) diff --git a/src/index.js b/src/index.js index 00a9e6e51f..6652e8c13a 100644 --- a/src/index.js +++ b/src/index.js @@ -102,7 +102,7 @@ class Node extends EventEmitter { const enabledDiscovery = this._config.dht.enabledDiscovery !== false this._dht = new DHT(this._switch, { - kBucketSize: this._config.dht.kBucketSize || 20, + kBucketSize: this._config.dht.kBucketSize, enabledDiscovery, datastore: this.datastore }) diff --git a/test/config.spec.js b/test/config.spec.js index 14cf55c8c3..f829a4bebe 100644 --- a/test/config.spec.js +++ b/test/config.spec.js @@ -11,6 +11,7 @@ const WS = require('libp2p-websockets') const Bootstrap = require('libp2p-bootstrap') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing') +const DHT = require('libp2p-kad-dht') const validateConfig = require('../src/config').validate @@ -93,6 +94,10 @@ describe('configuration', () => { }, relay: { enabled: true + }, + dht: { + enabledDiscovery: true, + kBucketSize: 20 } } } @@ -143,4 +148,42 @@ describe('configuration', () => { expect(() => validateConfig(options)).to.throw() }) + + it('should add defaults for dht', () => { + const options = { + peerInfo, + modules: { + transport: [ WS ], + dht: DHT + }, + config: { + EXPERIMENTAL: { + dht: true + } + } + } + + const expected = { + peerInfo, + modules: { + transport: [ WS ], + dht: DHT + }, + config: { + EXPERIMENTAL: { + pubsub: false, + dht: true + }, + relay: { + enabled: true + }, + dht: { + kBucketSize: 20, + enabledDiscovery: true + } + } + } + + expect(validateConfig(options)).to.deep.equal(expected) + }) }) diff --git a/test/transports.node.js b/test/transports.node.js index 4b5b5c121e..464633c377 100644 --- a/test/transports.node.js +++ b/test/transports.node.js @@ -427,7 +427,7 @@ describe('transports', () => { cb() }), (cb) => { - const wstar = new WRTCStar({wrtc: wrtc}) + const wstar = new WRTCStar({ wrtc: wrtc }) createNode([ '/ip4/0.0.0.0/tcp/0', @@ -474,7 +474,7 @@ describe('transports', () => { }), (cb) => { - const wstar = new WRTCStar({wrtc: wrtc}) + const wstar = new WRTCStar({ wrtc: wrtc }) createNode([ '/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'