Skip to content

Commit

Permalink
feat: enable peer discovery modules by default
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
alanshaw authored and Jacob Heun committed Jun 29, 2018
1 parent 501cc22 commit e320854
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e320854

Please sign in to comment.