feat: prepare for new randomWalk config parameters

As per: https://github.com/libp2p/js-libp2p-kad-dht/issues/76

fix: pass whole dht config into DHT constructor
This commit is contained in:
Thomas Eizinger 2019-02-04 12:20:24 +11:00 committed by Jacob Heun
parent 679d446daa
commit 91e60d4253
No known key found for this signature in database
GPG Key ID: CA5A94C15809879F
5 changed files with 25 additions and 10 deletions

View File

@ -34,7 +34,12 @@ const OptionsSchema = Joi.object({
dht: Joi.object().keys({
kBucketSize: Joi.number().default(20),
enabled: Joi.boolean().default(true),
enabledDiscovery: Joi.boolean().default(true),
randomWalk: Joi.object().keys({
enabled: Joi.boolean().default(true),
queriesPerPeriod: Joi.number().default(1),
interval: Joi.number().default(30000),
timeout: Joi.number().default(10000)
}).default(),
validators: Joi.object().allow(null),
selectors: Joi.object().allow(null)
}).default(),

View File

@ -105,14 +105,10 @@ class Node extends EventEmitter {
// dht provided components (peerRouting, contentRouting, dht)
if (this._config.dht.enabled) {
const DHT = this._modules.dht
const enabledDiscovery = this._config.dht.enabledDiscovery !== false
this._dht = new DHT(this._switch, {
kBucketSize: this._config.dht.kBucketSize,
enabledDiscovery,
datastore: this.datastore,
validators: this._config.dht.validators,
selectors: this._config.dht.selectors
...this._config.dht
})
}

View File

@ -96,7 +96,12 @@ describe('configuration', () => {
dht: {
kBucketSize: 20,
enabled: true,
enabledDiscovery: true
randomWalk: {
enabled: true,
queriesPerPeriod: 1,
interval: 30000,
timeout: 10000
}
},
relay: {
enabled: true
@ -185,7 +190,12 @@ describe('configuration', () => {
dht: {
kBucketSize: 20,
enabled: true,
enabledDiscovery: true,
randomWalk: {
enabled: true,
queriesPerPeriod: 1,
interval: 30000,
timeout: 10000
},
selectors,
validators
}

View File

@ -80,7 +80,9 @@ class Node extends libp2p {
},
dht: {
kBucketSize: 20,
enabledDiscovery: true,
randomWalk: {
enabled: true
},
enabled: false
},
EXPERIMENTAL: {

View File

@ -73,7 +73,9 @@ class Node extends libp2p {
},
dht: {
kBucketSize: 20,
enabledDiscovery: true,
randomWalk: {
enabled: true
},
enabled: true
},
EXPERIMENTAL: {