From e320854db7e82b273d8ed194ab6e957207c25e0c Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 28 Jun 2018 12:21:34 +0100 Subject: [PATCH] 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 --- src/index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 0a5c1f1475..f308a3ecc3 100644 --- a/src/index.js +++ b/src/index.js @@ -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 }