From 9abb0c0fc4a754a7c3518eaedf035f6b649f3bbc Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Mon, 26 Nov 2018 14:00:21 +0100 Subject: [PATCH] fix: add default dht values to config --- src/config.js | 4 ++-- src/index.js | 2 +- test/config.spec.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) 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..dca0d52b3f 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 @@ -143,4 +144,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) + }) })