feat: enable peer discovery modules by default

This PR will enable any provided peer discovery modules by default if no configuration for the module is supplied/needed.

As before, modules can be explicitly disabled or enabled by passing config.

This also enables pre-configured modules (instances) to be passed and enabled without them having to have a `tag` and an unused config section.

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
This commit is contained in:
Alan Shaw 2018-06-28 12:21:34 +01:00 committed by Jacob Heun
parent 501cc22fb4
commit e320854db7

View File

@ -154,15 +154,26 @@ class Node extends EventEmitter {
}
// all transports need to be setup before discover starts
if (this._modules.peerDiscovery && this._config.peerDiscovery) {
if (this._modules.peerDiscovery) {
each(this._modules.peerDiscovery, (D, _cb) => {
let config = {}
if (D.tag &&
this._config.peerDiscovery &&
this._config.peerDiscovery[D.tag]) {
config = this._config.peerDiscovery[D.tag]
}
// If not configured to be enabled/disabled then enable by default
const enabled = config.enabled == null ? true : config.enabled
// If enabled then start it
if (this._config.peerDiscovery[D.tag].enabled) {
if (enabled) {
let d
if (typeof D === 'function') {
this._config.peerDiscovery[D.tag].peerInfo = this.peerInfo
d = new D(this._config.peerDiscovery[D.tag])
config.peerInfo = this.peerInfo
d = new D(config)
} else {
d = D
}