diff --git a/src/config.js b/src/config.js index 09b9d7ca..6b718038 100644 --- a/src/config.js +++ b/src/config.js @@ -48,27 +48,16 @@ const configSchema = s({ enabled: true }), // DHT config - dht: s({ - kBucketSize: 'number', - enabled: 'boolean?', - validators: 'object?', - selectors: 'object?', - randomWalk: optional(s({ - enabled: 'boolean?', - queriesPerPeriod: 'number?', - interval: 'number?', - timeout: 'number?' - }, { - // random walk defaults - enabled: false, // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86 - queriesPerPeriod: 1, - interval: 30000, - timeout: 10000 - })) - }, { + dht: s('object?', { // DHT defaults enabled: false, - kBucketSize: 20 + kBucketSize: 20, + randomWalk: { + enabled: false, // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86 + queriesPerPeriod: 1, + interval: 300e3, + timeout: 10e3 + } }), // Experimental config EXPERIMENTAL: s({ @@ -77,11 +66,7 @@ const configSchema = s({ // Experimental defaults pubsub: false }) -}, { - relay: {}, - dht: {}, - EXPERIMENTAL: {} -}) +}, {}) const optionsSchema = s({ switch: 'object?', diff --git a/test/config.spec.js b/test/config.spec.js index d9b63173..c28f08f6 100644 --- a/test/config.spec.js +++ b/test/config.spec.js @@ -91,7 +91,7 @@ describe('configuration', () => { randomWalk: { enabled: false, queriesPerPeriod: 1, - interval: 30000, + interval: 300000, timeout: 10000 } }, @@ -153,7 +153,7 @@ describe('configuration', () => { randomWalk: { enabled: false, queriesPerPeriod: 1, - interval: 30000, + interval: 300000, timeout: 10000 } }, @@ -242,7 +242,7 @@ describe('configuration', () => { expect(() => validateConfig(options)).to.throw() }) - it('should add defaults, validators and selectors for dht', () => { + it('should be able to add validators and selectors for dht', () => { const selectors = {} const validators = {} @@ -283,14 +283,6 @@ describe('configuration', () => { } }, dht: { - kBucketSize: 20, - enabled: false, - randomWalk: { - enabled: false, - queriesPerPeriod: 1, - interval: 30000, - timeout: 10000 - }, selectors, validators } @@ -298,4 +290,43 @@ describe('configuration', () => { } expect(validateConfig(options)).to.deep.equal(expected) }) + + it('should support new properties for the dht config', () => { + const options = { + peerInfo, + modules: { + transport: [WS], + dht: DHT + }, + config: { + dht: { + kBucketSize: 20, + enabled: false, + myNewDHTConfigProperty: true, + randomWalk: { + enabled: false, + queriesPerPeriod: 1, + interval: 300000, + timeout: 10000 + } + } + } + } + + const expected = { + kBucketSize: 20, + enabled: false, + myNewDHTConfigProperty: true, + randomWalk: { + enabled: false, + queriesPerPeriod: 1, + interval: 300000, + timeout: 10000 + } + } + + const actual = validateConfig(options).config.dht + + expect(actual).to.deep.equal(expected) + }) })