Skip to content

Commit

Permalink
feat: libp2p: allows passing constructor for the libp2p modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Jun 10, 2018
1 parent cd449ff commit bab0910
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/core/components/libp2p.js
Expand Up @@ -19,7 +19,7 @@ module.exports = function libp2p (self) {
mdns: get(config, 'Discovery.MDNS.Enabled'),
webRTCStar: get(config, 'Discovery.webRTCStar.Enabled'),
bootstrap: get(config, 'Bootstrap'),
modules: self._libp2pModules,
modules: prepareModules(self, self._libp2pModules),
// EXPERIMENTAL
pubsub: get(self._options, 'EXPERIMENTAL.pubsub', false),
dht: get(self._options, 'EXPERIMENTAL.dht', false),
Expand Down Expand Up @@ -69,3 +69,10 @@ module.exports = function libp2p (self) {
})
}
}

function prepareModules (self, modules) {
if (typeof modules === 'function') {
return modules(self._peerInfo)
}
return modules
}
2 changes: 1 addition & 1 deletion src/core/config.js
Expand Up @@ -36,7 +36,7 @@ const schema = Joi.object().keys({
Bootstrap: Joi.array().items(Joi.multiaddr().IPFS().options({ convert: false }))
}).allow(null),
libp2p: Joi.object().keys({
modules: Joi.object().allow(null) // TODO: schemas for libp2p modules?
modules: Joi.any().allow(null) // TODO: schemas for libp2p modules?
}).allow(null)
}).options({ allowUnknown: true })

Expand Down

0 comments on commit bab0910

Please sign in to comment.