mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-22 13:31:32 +00:00
feat: allow configurable validators and selectors to the dht (#288)
* feat: allow configurable validators and selectors to the dht * chore: remove fallback
This commit is contained in:
@ -32,9 +32,11 @@ const OptionsSchema = Joi.object({
|
|||||||
})
|
})
|
||||||
}).default(),
|
}).default(),
|
||||||
dht: Joi.object().keys({
|
dht: Joi.object().keys({
|
||||||
kBucketSize: Joi.number().allow(null),
|
kBucketSize: Joi.number().default(20),
|
||||||
enabledDiscovery: Joi.boolean().default(true)
|
enabledDiscovery: Joi.boolean().default(true),
|
||||||
}),
|
validators: Joi.object().allow(null),
|
||||||
|
selectors: Joi.object().allow(null)
|
||||||
|
}).default(),
|
||||||
EXPERIMENTAL: Joi.object().keys({
|
EXPERIMENTAL: Joi.object().keys({
|
||||||
dht: Joi.boolean().default(false),
|
dht: Joi.boolean().default(false),
|
||||||
pubsub: Joi.boolean().default(false)
|
pubsub: Joi.boolean().default(false)
|
||||||
|
@ -102,9 +102,11 @@ class Node extends EventEmitter {
|
|||||||
const enabledDiscovery = this._config.dht.enabledDiscovery !== false
|
const enabledDiscovery = this._config.dht.enabledDiscovery !== false
|
||||||
|
|
||||||
this._dht = new DHT(this._switch, {
|
this._dht = new DHT(this._switch, {
|
||||||
kBucketSize: this._config.dht.kBucketSize || 20,
|
kBucketSize: this._config.dht.kBucketSize,
|
||||||
enabledDiscovery,
|
enabledDiscovery,
|
||||||
datastore: this.datastore
|
datastore: this.datastore,
|
||||||
|
validators: this._config.dht.validators,
|
||||||
|
selectors: this._config.dht.selectors
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ const WS = require('libp2p-websockets')
|
|||||||
const Bootstrap = require('libp2p-bootstrap')
|
const Bootstrap = require('libp2p-bootstrap')
|
||||||
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
||||||
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
||||||
|
const DHT = require('libp2p-kad-dht')
|
||||||
|
|
||||||
const validateConfig = require('../src/config').validate
|
const validateConfig = require('../src/config').validate
|
||||||
|
|
||||||
@ -91,6 +92,10 @@ describe('configuration', () => {
|
|||||||
pubsub: false,
|
pubsub: false,
|
||||||
dht: false
|
dht: false
|
||||||
},
|
},
|
||||||
|
dht: {
|
||||||
|
kBucketSize: 20,
|
||||||
|
enabledDiscovery: true
|
||||||
|
},
|
||||||
relay: {
|
relay: {
|
||||||
enabled: true
|
enabled: true
|
||||||
}
|
}
|
||||||
@ -143,4 +148,49 @@ describe('configuration', () => {
|
|||||||
|
|
||||||
expect(() => validateConfig(options)).to.throw()
|
expect(() => validateConfig(options)).to.throw()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should add defaults, validators and selectors for dht', () => {
|
||||||
|
const selectors = {}
|
||||||
|
const validators = {}
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
peerInfo,
|
||||||
|
modules: {
|
||||||
|
transport: [WS],
|
||||||
|
dht: DHT
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
EXPERIMENTAL: {
|
||||||
|
dht: true
|
||||||
|
},
|
||||||
|
dht: {
|
||||||
|
selectors,
|
||||||
|
validators
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const expected = {
|
||||||
|
peerInfo,
|
||||||
|
modules: {
|
||||||
|
transport: [WS],
|
||||||
|
dht: DHT
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
EXPERIMENTAL: {
|
||||||
|
pubsub: false,
|
||||||
|
dht: true
|
||||||
|
},
|
||||||
|
relay: {
|
||||||
|
enabled: true
|
||||||
|
},
|
||||||
|
dht: {
|
||||||
|
kBucketSize: 20,
|
||||||
|
enabledDiscovery: true,
|
||||||
|
selectors,
|
||||||
|
validators
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(validateConfig(options)).to.deep.equal(expected)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user