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

Commit 71883e3

Browse files
committed
feat: pass libp2p peer discovery config
BREAKING CHANGE: the configuration key for adding your own libp2p peer discovery modules has changed in the config passed to the IPFS constructor. Previously this key was `libp2p.modules.discovery` and has changed to `libp2p.modules.peerDiscovery`. License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent bdbe7ed commit 71883e3

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,13 @@ Creates and returns an instance of an IPFS node. Use the `options` argument to s
238238

239239
- `libp2p` (object) add custom modules to the libp2p stack of your node
240240
- `modules` (object):
241-
- `transport` (Array<[libp2p.Transport](https://github.com/libp2p/interface-transport)>): An array of additional Libp2p transport instances to use. See [libp2p/interface-transport](https://github.com/libp2p/interface-transport) for details.
242-
- `discovery` (Array<[libp2p.PeerDiscovery](https://github.com/libp2p/interface-peer-discovery)>): An array of additional Libp2p peer discovery instances to use. See [libp2p/peer-discovery](https://github.com/libp2p/interface-peer-discovery) for details.
241+
- `transport` (Array<[libp2p.Transport](https://github.com/libp2p/interface-transport)>): An array of additional Libp2p transport classes/instances to use. See [libp2p/interface-transport](https://github.com/libp2p/interface-transport) for details.
242+
- `peerDiscovery` (Array<[libp2p.PeerDiscovery](https://github.com/libp2p/interface-peer-discovery)>): An array of additional Libp2p peer discovery classes/instances to use. See [libp2p/peer-discovery](https://github.com/libp2p/interface-peer-discovery) for details. If passing a class, configuration can be passed using the config section below under the key corresponding to you module's unique `tag` (a static property on the class)
243+
- `config` (object):
244+
- `peerDiscovery` (object):
245+
- `[PeerDiscovery.tag]` (object): configuration for a peer discovery module
246+
- `enabled` (boolean): whether this module is enabled or disabled
247+
- `[custom config]` (any): other keys are specific to the module
243248

244249
#### Events
245250

src/core/components/libp2p.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const Node = require('../runtime/libp2p-nodejs')
55
const promisify = require('promisify-es6')
66
const get = require('lodash.get')
7+
const defaultsDeep = require('lodash.defaultsdeep')
78

89
module.exports = function libp2p (self) {
910
return {
@@ -15,10 +16,9 @@ module.exports = function libp2p (self) {
1516
return callback(err)
1617
}
1718

18-
const libp2pOptions = {
19+
const libp2pDefaults = {
1920
peerInfo: self._peerInfo,
2021
peerBook: self._peerInfoBook,
21-
modules: self._libp2pModules,
2222
config: {
2323
peerDiscovery: {
2424
mdns: {
@@ -51,6 +51,11 @@ module.exports = function libp2p (self) {
5151
}
5252
}
5353

54+
const libp2pOptions = defaultsDeep(
55+
get(self._options, 'libp2p', {}),
56+
libp2pDefaults
57+
)
58+
5459
self._libp2pNode = new Node(libp2pOptions)
5560

5661
self._libp2pNode.on('peer:discovery', (peerInfo) => {

src/core/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class IPFS extends EventEmitter {
3434
}
3535

3636
options = config.validate(options || {})
37-
this._libp2pModules = options.libp2p && options.libp2p.modules
3837

3938
extend(this._options, options)
4039

0 commit comments

Comments
 (0)