Skip to content

Commit e320854

Browse files
alanshawJacob Heun
authored and
Jacob Heun
committed
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>
1 parent 501cc22 commit e320854

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/index.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,26 @@ class Node extends EventEmitter {
154154
}
155155

156156
// all transports need to be setup before discover starts
157-
if (this._modules.peerDiscovery && this._config.peerDiscovery) {
157+
if (this._modules.peerDiscovery) {
158158
each(this._modules.peerDiscovery, (D, _cb) => {
159+
let config = {}
160+
161+
if (D.tag &&
162+
this._config.peerDiscovery &&
163+
this._config.peerDiscovery[D.tag]) {
164+
config = this._config.peerDiscovery[D.tag]
165+
}
166+
167+
// If not configured to be enabled/disabled then enable by default
168+
const enabled = config.enabled == null ? true : config.enabled
169+
159170
// If enabled then start it
160-
if (this._config.peerDiscovery[D.tag].enabled) {
171+
if (enabled) {
161172
let d
162173

163174
if (typeof D === 'function') {
164-
this._config.peerDiscovery[D.tag].peerInfo = this.peerInfo
165-
d = new D(this._config.peerDiscovery[D.tag])
175+
config.peerInfo = this.peerInfo
176+
d = new D(config)
166177
} else {
167178
d = D
168179
}

0 commit comments

Comments
 (0)