2018-06-28 10:06:25 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Joi = require('joi')
|
|
|
|
|
2018-06-28 16:06:42 +01:00
|
|
|
const ModuleSchema = Joi.alternatives().try(Joi.func(), Joi.object())
|
|
|
|
|
|
|
|
const OptionsSchema = Joi.object({
|
2018-06-28 10:06:25 +02:00
|
|
|
// TODO: create proper validators for the generics
|
|
|
|
connectionManager: Joi.object(),
|
2018-10-31 11:48:02 +00:00
|
|
|
datastore: Joi.object(),
|
2018-06-28 10:06:25 +02:00
|
|
|
peerInfo: Joi.object().required(),
|
|
|
|
peerBook: Joi.object(),
|
|
|
|
modules: Joi.object().keys({
|
2018-06-28 16:06:42 +01:00
|
|
|
connEncryption: Joi.array().items(ModuleSchema).allow(null),
|
2018-06-08 00:30:21 +02:00
|
|
|
connProtector: Joi.object().keys({
|
|
|
|
protect: Joi.func().required()
|
|
|
|
}).unknown(),
|
2018-10-19 16:28:28 +02:00
|
|
|
contentRouting: Joi.array().items(Joi.object()).allow(null),
|
|
|
|
dht: ModuleSchema.allow(null),
|
2018-06-28 16:06:42 +01:00
|
|
|
peerDiscovery: Joi.array().items(ModuleSchema).allow(null),
|
2018-10-19 16:28:28 +02:00
|
|
|
peerRouting: Joi.array().items(Joi.object()).allow(null),
|
|
|
|
streamMuxer: Joi.array().items(ModuleSchema).allow(null),
|
|
|
|
transport: Joi.array().items(ModuleSchema).min(1).required()
|
2018-06-28 10:06:25 +02:00
|
|
|
}).required(),
|
|
|
|
config: Joi.object().keys({
|
|
|
|
peerDiscovery: Joi.object().allow(null),
|
|
|
|
relay: Joi.object().keys({
|
2018-10-19 16:31:40 +02:00
|
|
|
enabled: Joi.boolean().default(true),
|
2018-06-28 10:06:25 +02:00
|
|
|
hop: Joi.object().keys({
|
|
|
|
enabled: Joi.boolean().default(false),
|
|
|
|
active: Joi.boolean().default(false)
|
|
|
|
})
|
|
|
|
}).default(),
|
|
|
|
dht: Joi.object().keys({
|
2018-11-29 14:10:23 +00:00
|
|
|
kBucketSize: Joi.number().default(20),
|
2019-01-29 17:57:09 +00:00
|
|
|
enabled: Joi.boolean().default(true),
|
2019-02-04 12:20:24 +11:00
|
|
|
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(),
|
2018-11-29 14:10:23 +00:00
|
|
|
validators: Joi.object().allow(null),
|
|
|
|
selectors: Joi.object().allow(null)
|
|
|
|
}).default(),
|
2018-06-28 10:06:25 +02:00
|
|
|
EXPERIMENTAL: Joi.object().keys({
|
|
|
|
pubsub: Joi.boolean().default(false)
|
|
|
|
}).default()
|
|
|
|
}).default()
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports.validate = (options) => {
|
2018-06-28 16:06:42 +01:00
|
|
|
options = Joi.attempt(options, OptionsSchema)
|
2018-06-28 10:06:25 +02:00
|
|
|
|
|
|
|
// Ensure dht is correct
|
2019-01-29 17:57:09 +00:00
|
|
|
if (options.config.dht.enabled) {
|
2018-06-28 16:06:42 +01:00
|
|
|
Joi.assert(options.modules.dht, ModuleSchema.required())
|
2018-06-28 10:06:25 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 16:06:42 +01:00
|
|
|
return options
|
2018-06-28 10:06:25 +02:00
|
|
|
}
|