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

Commit

Permalink
chore: address review
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Aug 28, 2019
1 parent c4497e0 commit aa2eb36
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ipfsdServer = IPFSFactory.createServer()
const preloadNode = MockPreloadNode.createNode()

module.exports = {
bundlesize: { maxSize: '694kB' },
bundlesize: { maxSize: '689kB' },
webpack: {
resolve: {
mainFields: ['browser', 'main'],
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Configure remote preload nodes. The remote will preload content added on this no
| Type | Default |
|------|---------|
| object | `{ pubsub: false, ipnsPubsub: false, sharding: false }` |
| object | `{ ipnsPubsub: false, sharding: false }` |
Enable and configure experimental features.
Expand Down Expand Up @@ -495,6 +495,8 @@ You can see the bundle in action in the [custom libp2p example](examples/custom-
- `modules` (object):
- `transport` (Array<[libp2p.Transport](https://github.com/libp2p/interface-transport)>): An array of Libp2p transport classes/instances to use _instead_ of the defaults. 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 Libp2p peer discovery classes/instances to use _instead_ of the defaults. 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)
- `dht` (object): a DHT implementation that enables PeerRouting and ContentRouting. Example [libp2p/js-libp2p-kad-dht](https://github.com/libp2p/js-libp2p-kad-dht)
- `pubsub` (object): a Pubsub implementation on top of [libp2p/js-libp2p-pubsub](https://github.com/libp2p/js-libp2p-pubsub)
- `config` (object):
- `peerDiscovery` (object):
- `autoDial` (boolean): Dial to discovered peers when under the Connection Manager min peer count watermark. (default `true`)
Expand All @@ -506,6 +508,11 @@ You can see the bundle in action in the [custom libp2p example](examples/custom-
- `kBucketSize` (number): bucket size (default `20`)
- `randomWalk` (object): configuration for random walk
- `enabled` (boolean): whether random DHT walking is enabled (default `false`)
- `pubsub` (object): Configuration options for Pubsub
- `enabled` (boolean): if pubbsub subsystem should be enabled (default: `true`)
- `emitSelf` (boolean): whether the node should emit to self on publish, in the event of the topic being subscribed (default: `true`)
- `signMessages` (boolean): if messages should be signed (default: `true`)
- `strictSigning` (boolean): if message signing should be required (default: `true`)

##### `options.connectionManager`

Expand Down
2 changes: 1 addition & 1 deletion doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ You can check the [parameter choice for pbkdf2](https://cryptosense.com/paramete

## `Pubsub`

Options for configuring the pubsub subsystem.
Options for configuring the pubsub subsystem. It is important pointing out that this is not supported in the browser. If you want to configure a different pubsub router in the browser you must configure `libp2p.modules.pubsub` options instead.

### `Router`

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"./src/core/runtime/dns-nodejs.js": "./src/core/runtime/dns-browser.js",
"./src/core/runtime/fetch-nodejs.js": "./src/core/runtime/fetch-browser.js",
"./src/core/runtime/libp2p-nodejs.js": "./src/core/runtime/libp2p-browser.js",
"./src/core/runtime/libp2p-pubsub-routers-nodejs.js": "./src/core/runtime/libp2p-pubsub-routers-browser.js",
"./src/core/runtime/preload-nodejs.js": "./src/core/runtime/preload-browser.js",
"./src/core/runtime/repo-nodejs.js": "./src/core/runtime/repo-browser.js",
"./src/core/runtime/ipld-nodejs.js": "./src/core/runtime/ipld-browser.js",
Expand Down Expand Up @@ -193,7 +194,7 @@
"execa": "^2.0.4",
"form-data": "^2.5.0",
"hat": "0.0.3",
"interface-ipfs-core": "^0.110.0",
"interface-ipfs-core": "^0.111.0",
"ipfsd-ctl": "^0.43.0",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
Expand Down
15 changes: 13 additions & 2 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

const get = require('dlv')
const mergeOptions = require('merge-options')
const errCode = require('err-code')
const ipnsUtils = require('../ipns/routing/utils')
const multiaddr = require('multiaddr')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
const PubsubRouters = require('../runtime/libp2p-pubsub-routers-nodejs')

module.exports = function libp2p (self, config) {
const options = self._options || {}
Expand Down Expand Up @@ -58,15 +60,24 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
peerRouting = [new DelegatedPeerRouter(delegatedApiOptions)]
}

const getPubsubRouter = () => {
const router = get(config, 'Pubsub.Router', 'gossipsub')

if (!PubsubRouters[router]) {
throw errCode(new Error(`Router unavailable. Configure libp2p.modules.pubsub to use the ${router} router.`), 'ERR_NOT_SUPPORTED')
}

return PubsubRouters[router]
}

const libp2pDefaults = {
datastore,
peerInfo,
peerBook,
modules: {
contentRouting,
peerRouting,
pubsub: get(config, 'Pubsub.Router', 'gossipsub') === 'floodsub'
? require('libp2p-floodsub') : require('libp2p-gossipsub')
pubsub: getPubsubRouter()
},
config: {
peerDiscovery: {
Expand Down
3 changes: 0 additions & 3 deletions src/core/runtime/config-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ module.exports = () => ({
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
],
Pubsub: {
Router: 'gossipsub'
},
Swarm: {
ConnMgr: {
LowWater: 200,
Expand Down
5 changes: 5 additions & 0 deletions src/core/runtime/libp2p-pubsub-routers-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

module.exports = {
gossipsub: require('libp2p-gossipsub')
}
6 changes: 6 additions & 0 deletions src/core/runtime/libp2p-pubsub-routers-nodejs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = {
gossipsub: require('libp2p-gossipsub'),
floodsub: require('libp2p-floodsub')
}

0 comments on commit aa2eb36

Please sign in to comment.