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

Commit aa2eb36

Browse files
committed
chore: address review
1 parent c4497e0 commit aa2eb36

8 files changed

+36
-9
lines changed

Diff for: .aegir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const ipfsdServer = IPFSFactory.createServer()
88
const preloadNode = MockPreloadNode.createNode()
99

1010
module.exports = {
11-
bundlesize: { maxSize: '694kB' },
11+
bundlesize: { maxSize: '689kB' },
1212
webpack: {
1313
resolve: {
1414
mainFields: ['browser', 'main'],

Diff for: README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ Configure remote preload nodes. The remote will preload content added on this no
324324
325325
| Type | Default |
326326
|------|---------|
327-
| object | `{ pubsub: false, ipnsPubsub: false, sharding: false }` |
327+
| object | `{ ipnsPubsub: false, sharding: false }` |
328328
329329
Enable and configure experimental features.
330330
@@ -495,6 +495,8 @@ You can see the bundle in action in the [custom libp2p example](examples/custom-
495495
- `modules` (object):
496496
- `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.
497497
- `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)
498+
- `dht` (object): a DHT implementation that enables PeerRouting and ContentRouting. Example [libp2p/js-libp2p-kad-dht](https://github.com/libp2p/js-libp2p-kad-dht)
499+
- `pubsub` (object): a Pubsub implementation on top of [libp2p/js-libp2p-pubsub](https://github.com/libp2p/js-libp2p-pubsub)
498500
- `config` (object):
499501
- `peerDiscovery` (object):
500502
- `autoDial` (boolean): Dial to discovered peers when under the Connection Manager min peer count watermark. (default `true`)
@@ -506,6 +508,11 @@ You can see the bundle in action in the [custom libp2p example](examples/custom-
506508
- `kBucketSize` (number): bucket size (default `20`)
507509
- `randomWalk` (object): configuration for random walk
508510
- `enabled` (boolean): whether random DHT walking is enabled (default `false`)
511+
- `pubsub` (object): Configuration options for Pubsub
512+
- `enabled` (boolean): if pubbsub subsystem should be enabled (default: `true`)
513+
- `emitSelf` (boolean): whether the node should emit to self on publish, in the event of the topic being subscribed (default: `true`)
514+
- `signMessages` (boolean): if messages should be signed (default: `true`)
515+
- `strictSigning` (boolean): if message signing should be required (default: `true`)
509516

510517
##### `options.connectionManager`
511518

Diff for: doc/config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ You can check the [parameter choice for pbkdf2](https://cryptosense.com/paramete
172172

173173
## `Pubsub`
174174

175-
Options for configuring the pubsub subsystem.
175+
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.
176176

177177
### `Router`
178178

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"./src/core/runtime/dns-nodejs.js": "./src/core/runtime/dns-browser.js",
2222
"./src/core/runtime/fetch-nodejs.js": "./src/core/runtime/fetch-browser.js",
2323
"./src/core/runtime/libp2p-nodejs.js": "./src/core/runtime/libp2p-browser.js",
24+
"./src/core/runtime/libp2p-pubsub-routers-nodejs.js": "./src/core/runtime/libp2p-pubsub-routers-browser.js",
2425
"./src/core/runtime/preload-nodejs.js": "./src/core/runtime/preload-browser.js",
2526
"./src/core/runtime/repo-nodejs.js": "./src/core/runtime/repo-browser.js",
2627
"./src/core/runtime/ipld-nodejs.js": "./src/core/runtime/ipld-browser.js",
@@ -193,7 +194,7 @@
193194
"execa": "^2.0.4",
194195
"form-data": "^2.5.0",
195196
"hat": "0.0.3",
196-
"interface-ipfs-core": "^0.110.0",
197+
"interface-ipfs-core": "^0.111.0",
197198
"ipfsd-ctl": "^0.43.0",
198199
"libp2p-websocket-star": "~0.10.2",
199200
"ncp": "^2.0.0",

Diff for: src/core/components/libp2p.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
const get = require('dlv')
44
const mergeOptions = require('merge-options')
5+
const errCode = require('err-code')
56
const ipnsUtils = require('../ipns/routing/utils')
67
const multiaddr = require('multiaddr')
78
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
89
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
10+
const PubsubRouters = require('../runtime/libp2p-pubsub-routers-nodejs')
911

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

63+
const getPubsubRouter = () => {
64+
const router = get(config, 'Pubsub.Router', 'gossipsub')
65+
66+
if (!PubsubRouters[router]) {
67+
throw errCode(new Error(`Router unavailable. Configure libp2p.modules.pubsub to use the ${router} router.`), 'ERR_NOT_SUPPORTED')
68+
}
69+
70+
return PubsubRouters[router]
71+
}
72+
6173
const libp2pDefaults = {
6274
datastore,
6375
peerInfo,
6476
peerBook,
6577
modules: {
6678
contentRouting,
6779
peerRouting,
68-
pubsub: get(config, 'Pubsub.Router', 'gossipsub') === 'floodsub'
69-
? require('libp2p-floodsub') : require('libp2p-gossipsub')
80+
pubsub: getPubsubRouter()
7081
},
7182
config: {
7283
peerDiscovery: {

Diff for: src/core/runtime/config-browser.js

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ module.exports = () => ({
2727
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
2828
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
2929
],
30-
Pubsub: {
31-
Router: 'gossipsub'
32-
},
3330
Swarm: {
3431
ConnMgr: {
3532
LowWater: 200,

Diff for: src/core/runtime/libp2p-pubsub-routers-browser.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
module.exports = {
4+
gossipsub: require('libp2p-gossipsub')
5+
}

Diff for: src/core/runtime/libp2p-pubsub-routers-nodejs.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict'
2+
3+
module.exports = {
4+
gossipsub: require('libp2p-gossipsub'),
5+
floodsub: require('libp2p-floodsub')
6+
}

0 commit comments

Comments
 (0)