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

Commit

Permalink
feat: pass libp2p peer discovery config
Browse files Browse the repository at this point in the history
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 <alan@tableflip.io>
  • Loading branch information
alanshaw committed Jun 28, 2018
1 parent bdbe7ed commit 71883e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,13 @@ Creates and returns an instance of an IPFS node. Use the `options` argument to s

- `libp2p` (object) add custom modules to the libp2p stack of your node
- `modules` (object):
- `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.
- `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.
- `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.
- `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)
- `config` (object):
- `peerDiscovery` (object):
- `[PeerDiscovery.tag]` (object): configuration for a peer discovery module
- `enabled` (boolean): whether this module is enabled or disabled
- `[custom config]` (any): other keys are specific to the module

#### Events

Expand Down
9 changes: 7 additions & 2 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const Node = require('../runtime/libp2p-nodejs')
const promisify = require('promisify-es6')
const get = require('lodash.get')
const defaultsDeep = require('lodash.defaultsdeep')

module.exports = function libp2p (self) {
return {
Expand All @@ -15,10 +16,9 @@ module.exports = function libp2p (self) {
return callback(err)
}

const libp2pOptions = {
const libp2pDefaults = {
peerInfo: self._peerInfo,
peerBook: self._peerInfoBook,
modules: self._libp2pModules,
config: {
peerDiscovery: {
mdns: {
Expand Down Expand Up @@ -51,6 +51,11 @@ module.exports = function libp2p (self) {
}
}

const libp2pOptions = defaultsDeep(
get(self._options, 'libp2p', {}),
libp2pDefaults
)

self._libp2pNode = new Node(libp2pOptions)

self._libp2pNode.on('peer:discovery', (peerInfo) => {
Expand Down
1 change: 0 additions & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class IPFS extends EventEmitter {
}

options = config.validate(options || {})
this._libp2pModules = options.libp2p && options.libp2p.modules

extend(this._options, options)

Expand Down

0 comments on commit 71883e3

Please sign in to comment.