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

Commit 902e045

Browse files
vasco-santosAlan Shaw
authored andcommitted
feat: gossipsub as default pubsub (#2298)
BREAKING CHANGE: The default pubsub implementation has changed from floodsub to [gossipsub](https://github.com/ChainSafe/gossipsub-js). Additionally, to enable pubsub programmatically set `pubsub.enabled: true` instead of `EXPERIMENTAL.pubsub: true` or via the CLI pass `--enable-pubsub` instead of `--enable-pubsub-experiment` to `jsipfs daemon`.
1 parent f6cf876 commit 902e045

File tree

26 files changed

+241
-77
lines changed

26 files changed

+241
-77
lines changed

README.md

Lines changed: 8 additions & 1 deletion
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: `false`)
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

doc/config.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ The js-ipfs config file is a JSON document located in the root directory of the
1919
- [`PeerID`](#peerid)
2020
- [`PrivKey`](#privkey)
2121
- [`Keychain`](#keychain)
22+
- [`Pubsub`](#pubsub)
23+
- [`Router`](#router)
2224
- [`Swarm`](#swarm)
2325
- [`ConnMgr`](#connmgr)
2426

@@ -168,6 +170,16 @@ Default:
168170

169171
You can check the [parameter choice for pbkdf2](https://cryptosense.com/parameter-choice-for-pbkdf2/) for more information.
170172

173+
## `Pubsub`
174+
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.
176+
177+
### `Router`
178+
179+
A string value for specifying which pubsub routing protocol to use. You can either use `gossipsub` in order to use the [ChainSafe/gossipsub-js](https://github.com/ChainSafe/gossipsub-js) implementation, or `floodsub` to use the [libp2p/js-libp2p-floodsub](https://github.com/libp2p/js-libp2p-floodsub) implementation. You can read more about these implementations on the [libp2p/specs/pubsub](https://github.com/libp2p/specs/tree/master/pubsub) document.
180+
181+
Default: `gossipsub`
182+
171183
## `Swarm`
172184

173185
Options for configuring the swarm.

examples/circuit-relaying/src/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ document.addEventListener('DOMContentLoaded', async () => {
3636
enabled: true // make this node a relay (HOP)
3737
}
3838
},
39-
EXPERIMENTAL: {
40-
pubsub: true // enable pubsub
39+
pubsub: {
40+
enabled: true
4141
},
4242
config: {
4343
Bootstrap: []

examples/custom-libp2p/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ const libp2pBundle = (opts) => {
9696
timeout: 2e3 // End the query quickly since we're running so frequently
9797
}
9898
},
99-
EXPERIMENTAL: {
100-
pubsub: true
99+
pubsub: {
100+
enabled: true
101101
}
102102
}
103103
})

examples/custom-libp2p/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "MIT",
1111
"dependencies": {
1212
"ipfs": "file:../../",
13-
"libp2p": "~0.25.0",
13+
"libp2p": "~0.26.1",
1414
"libp2p-bootstrap": "~0.9.7",
1515
"libp2p-kad-dht": "~0.15.0",
1616
"libp2p-mdns": "~0.12.2",

examples/exchange-files-in-browser/public/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ let info
4444
async function start () {
4545
if (!node) {
4646
const options = {
47-
EXPERIMENTAL: {
48-
pubsub: true
47+
pubsub: {
48+
enabled: true
4949
},
5050
repo: 'ipfs-' + Math.random(),
5151
config: {

package.json

Lines changed: 7 additions & 4 deletions
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",
@@ -96,7 +97,7 @@
9697
"ipfs-bitswap": "~0.25.1",
9798
"ipfs-block": "~0.8.1",
9899
"ipfs-block-service": "~0.15.2",
99-
"ipfs-http-client": "^33.1.1",
100+
"ipfs-http-client": "^34.0.0",
100101
"ipfs-http-response": "~0.3.1",
101102
"ipfs-mfs": "~0.12.0",
102103
"ipfs-multipart": "~0.1.1",
@@ -121,11 +122,13 @@
121122
"iso-url": "~0.4.6",
122123
"just-safe-set": "^2.1.0",
123124
"kind-of": "^6.0.2",
124-
"libp2p": "~0.25.4",
125+
"libp2p": "~0.26.1",
125126
"libp2p-bootstrap": "~0.9.3",
126127
"libp2p-crypto": "~0.16.0",
127128
"libp2p-delegated-content-routing": "^0.2.4",
128129
"libp2p-delegated-peer-routing": "^0.2.4",
130+
"libp2p-floodsub": "^0.17.0",
131+
"libp2p-gossipsub": "~0.0.4",
129132
"libp2p-kad-dht": "~0.15.3",
130133
"libp2p-keychain": "~0.4.2",
131134
"libp2p-mdns": "~0.12.0",
@@ -191,8 +194,8 @@
191194
"execa": "^2.0.4",
192195
"form-data": "^2.5.1",
193196
"hat": "0.0.3",
194-
"interface-ipfs-core": "^0.110.0",
195-
"ipfsd-ctl": "^0.44.1",
197+
"interface-ipfs-core": "^0.111.0",
198+
"ipfsd-ctl": "~0.45.0",
196199
"libp2p-websocket-star": "~0.10.2",
197200
"ncp": "^2.0.0",
198201
"p-event": "^4.1.0",

src/cli/commands/daemon.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module.exports = {
1616
type: 'boolean',
1717
default: false
1818
})
19-
.option('enable-pubsub-experiment', {
19+
.option('enable-pubsub', {
20+
alias: 'enable-pubsub-experiment',
2021
type: 'boolean',
2122
default: false
2223
})
@@ -53,8 +54,8 @@ module.exports = {
5354
offline: argv.offline,
5455
pass: argv.pass,
5556
preload: { enabled: argv.enablePreload },
57+
pubsub: { enabled: argv.enablePubsub },
5658
EXPERIMENTAL: {
57-
pubsub: argv.enablePubsubExperiment,
5859
ipnsPubsub: argv.enableNamesysPubsub,
5960
dht: argv.enableDhtExperiment,
6061
sharding: argv.enableShardingExperiment

src/cli/daemon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Daemon {
3030
async start () {
3131
this._log('starting')
3232

33-
const libp2p = { modules: {} }
33+
const libp2p = { modules: {}, config: {} }
3434

3535
// Attempt to use any of the WebRTC versions available globally
3636
let electronWebRTC

src/cli/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ exports.getIPFS = (argv, callback) => {
5050
init: false,
5151
start: false,
5252
pass: argv.pass,
53-
EXPERIMENTAL: {
54-
pubsub: true
53+
pubsub: {
54+
enabled: true
5555
}
5656
})
5757

0 commit comments

Comments
 (0)