Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

RFC: allow passing constructor for the libp2p modules #1383

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/core/components/libp2p.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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