mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-16 15:40:49 +00:00
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:
parent
501cc22fb4
commit
e320854db7
19
src/index.js
19
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user