feat: add check for protector and enforced pnet

fix: update protector config and tests
docs: add private network info to the readme
test: fix an issue with config
This commit is contained in:
Jacob Heun
2018-06-08 00:30:21 +02:00
committed by David Dias
parent 40739e9639
commit 2b7cc55c88
5 changed files with 113 additions and 0 deletions

View File

@ -13,6 +13,9 @@ const OptionsSchema = Joi.object({
transport: Joi.array().items(ModuleSchema).min(1).required(),
streamMuxer: Joi.array().items(ModuleSchema).allow(null),
connEncryption: Joi.array().items(ModuleSchema).allow(null),
connProtector: Joi.object().keys({
protect: Joi.func().required()
}).unknown(),
peerDiscovery: Joi.array().items(ModuleSchema).allow(null),
dht: ModuleSchema.allow(null)
}).required(),

View File

@ -75,6 +75,13 @@ class Node extends EventEmitter {
})
}
// Attach private network protector
if (this._modules.connProtector) {
this._switch.protector = this._modules.connProtector
} else if (process.env.LIBP2P_FORCE_PNET) {
throw new Error('Private network is enforced, but no protector was provided')
}
// dht provided components (peerRouting, contentRouting, dht)
if (this._config.EXPERIMENTAL.dht) {
const DHT = this._modules.dht