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

Commit 27751cf

Browse files
vasco-santosAlan Shaw
authored and
Alan Shaw
committed
feat: enable pubsub via config file and enabled by default (#2427)
As discussed, we will remove the pubsub flags from the js daemon and will use the config as the way to disable it (will be enabled by default now!) Needs: - [x] [ipfs/js-ipfsd-ctl#366](ipfs/js-ipfsd-ctl#366) Reference: - [ipfs/kubo#6621](ipfs/kubo#6621) BREAKING CHANGE: pubsub is now enabled by default and the experimental flag was removed
1 parent 03fc9b3 commit 27751cf

20 files changed

+53
-43
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ Configure remote preload nodes. The remote will preload content added on this no
328328
329329
Enable and configure experimental features.
330330
331-
- `pubsub` (boolean): Enable libp2p pub-sub. (Default: `false`)
332331
- `ipnsPubsub` (boolean): Enable pub-sub on IPNS. (Default: `false`)
333332
- `sharding` (boolean): Enable directory sharding. Directories that have many child objects will be represented by multiple DAG nodes instead of just one. It can improve lookup performance when a directory has several thousand files or more. (Default: `false`)
334333

doc/config.md

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ A string value for specifying which pubsub routing protocol to use. You can eith
180180

181181
Default: `gossipsub`
182182

183+
### `Enabled`
184+
185+
A boolean value for wether or not pubsub router should be active.
186+
187+
Default: `true`
188+
183189
## `Swarm`
184190

185191
Options for configuring the swarm.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@
194194
"execa": "^2.0.4",
195195
"form-data": "^2.5.1",
196196
"hat": "0.0.3",
197-
"ipfsd-ctl": "~0.45.0",
198197
"interface-ipfs-core": "^0.111.1",
198+
"ipfsd-ctl": "~0.46.0",
199199
"libp2p-websocket-star": "~0.10.2",
200200
"ncp": "^2.0.0",
201201
"p-event": "^4.1.0",

src/cli/commands/daemon.js

-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ module.exports = {
1616
type: 'boolean',
1717
default: false
1818
})
19-
.option('enable-pubsub', {
20-
alias: 'enable-pubsub-experiment',
21-
type: 'boolean',
22-
default: false
23-
})
2419
.option('offline', {
2520
type: 'boolean',
2621
desc: 'Run offline. Do not connect to the rest of the network but provide local API.',
@@ -54,7 +49,6 @@ module.exports = {
5449
offline: argv.offline,
5550
pass: argv.pass,
5651
preload: { enabled: argv.enablePreload },
57-
pubsub: { enabled: argv.enablePubsub },
5852
EXPERIMENTAL: {
5953
ipnsPubsub: argv.enableNamesysPubsub,
6054
dht: argv.enableDhtExperiment,

src/cli/utils.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ exports.getIPFS = (argv, callback) => {
4949
repo: exports.getRepoPath(),
5050
init: false,
5151
start: false,
52-
pass: argv.pass,
53-
pubsub: {
54-
enabled: true
55-
}
52+
pass: argv.pass
5653
})
5754

5855
const cleanup = promisify((cb) => {

src/core/components/libp2p.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
119119
}
120120
},
121121
pubsub: {
122-
enabled: get(options, 'pubsub.enabled', false)
122+
enabled: get(config, 'Pubsub.Enabled', true)
123123
}
124124
},
125125
connectionManager: get(options, 'connectionManager',

src/core/config.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ const configSchema = s({
3232
addresses: optional(s(['multiaddr'])),
3333
interval: 'number?'
3434
}, { enabled: true, interval: 30 * 1000 }),
35-
pubsub: optional(s({
36-
enabled: 'boolean?'
37-
})),
3835
init: optional(union(['boolean', s({
3936
bits: 'number?',
4037
emptyRepo: 'boolean?',
@@ -72,7 +69,8 @@ const configSchema = s({
7269
})),
7370
Bootstrap: optional(s(['multiaddr-ipfs'])),
7471
Pubsub: optional(s({
75-
Router: 'string?'
72+
Router: 'string?',
73+
Enabled: 'boolean?'
7674
})),
7775
Swarm: optional(s({
7876
ConnMgr: optional(s({

src/core/index.js

-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const multihashing = require('multihashing-async')
1515
const CID = require('cids')
1616
const debug = require('debug')
1717
const mergeOptions = require('merge-options')
18-
const get = require('dlv')
1918
const EventEmitter = require('events')
2019

2120
const config = require('./config')
@@ -47,9 +46,6 @@ class IPFS extends EventEmitter {
4746
init: true,
4847
start: true,
4948
EXPERIMENTAL: {},
50-
pubsub: {
51-
enabled: false
52-
},
5349
preload: {
5450
enabled: true,
5551
addresses: [
@@ -135,16 +131,7 @@ class IPFS extends EventEmitter {
135131
this.stats = components.stats(this)
136132
this.resolve = components.resolve(this)
137133

138-
if (this._options.pubsub.enabled) {
139-
this.log('pubsub is enabled')
140-
}
141134
if (this._options.EXPERIMENTAL.ipnsPubsub) {
142-
// if (!this._options.pubsub.enabled) {
143-
if (!get(this._options, 'pubsub.enabled', false)) {
144-
this.log('pubsub is enabled to use EXPERIMENTAL IPNS pubsub')
145-
this._options.pubsub.enabled = true
146-
}
147-
148135
this.log('EXPERIMENTAL IPNS pubsub is enabled')
149136
}
150137
if (this._options.EXPERIMENTAL.sharding) {

src/core/runtime/config-browser.js

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ 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+
Enabled: true
32+
},
3033
Swarm: {
3134
ConnMgr: {
3235
LowWater: 200,

src/core/runtime/config-nodejs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = () => ({
4141
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
4242
],
4343
Pubsub: {
44-
Router: 'gossipsub'
44+
Router: 'gossipsub',
45+
Enabled: true
4546
},
4647
Swarm: {
4748
ConnMgr: {

src/core/runtime/libp2p-browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Node extends libp2p {
6767
enabled: false
6868
},
6969
pubsub: {
70-
enabled: false,
70+
enabled: true,
7171
emitSelf: true
7272
}
7373
}

src/core/runtime/libp2p-nodejs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Node extends libp2p {
7070
}
7171
},
7272
pubsub: {
73-
enabled: false,
73+
enabled: true,
7474
emitSelf: true
7575
}
7676
}

test/cli/pubsub.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ describe('pubsub', function () {
4343
ipfsdA = await df.spawn({
4444
exec: IPFS,
4545
initOptions: { bits: 512 },
46-
config,
47-
args: ['--enable-pubsub']
46+
config
4847
})
4948
node = ipfsdA.api
5049
})
@@ -59,7 +58,6 @@ describe('pubsub', function () {
5958
const df = DaemonFactory.create({ type: 'js' })
6059
ipfsdB = await df.spawn({
6160
initOptions: { bits: 512 },
62-
args: ['--enable-pubsub'],
6361
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
6462
config
6563
})

test/core/config.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ describe('config', () => {
154154
{ config: { Swarm: { ConnMgr: undefined } } },
155155
{ config: { Swarm: undefined } },
156156

157+
{ config: { Pubsub: { Enabled: true, Router: 'gossipsub' } } },
158+
{ config: { Pubsub: { Enabled: false } } },
159+
157160
{ config: undefined }
158161
]
159162

@@ -184,6 +187,8 @@ describe('config', () => {
184187
{ config: { Swarm: { ConnMgr: 138 } } },
185188
{ config: { Swarm: 138 } },
186189

190+
{ config: { Pubsub: { Enabled: 1 } } },
191+
187192
{ config: 138 }
188193
]
189194

test/core/create-node.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,31 @@ describe('create node', function () {
387387
})
388388
})
389389

390+
it('disable pubsub', function (done) {
391+
this.timeout(80 * 1000)
392+
393+
if (!isNode) { return done() }
394+
395+
const node = new IPFS({
396+
repo: tempRepo,
397+
init: { bits: 512 },
398+
config: {
399+
Pubsub: {
400+
Enabled: false
401+
}
402+
}
403+
})
404+
405+
node.once('start', (err) => {
406+
expect(err).to.not.exist()
407+
node.pubsub.peers('topic', (err) => {
408+
expect(err).to.exist()
409+
expect(err.code).to.equal('ERR_PUBSUB_DISABLED')
410+
node.stop(done)
411+
})
412+
})
413+
})
414+
390415
it('start and stop, start and stop', function (done) {
391416
this.timeout(80 * 1000)
392417

test/core/interface.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ describe('interface-ipfs-core tests', function () {
141141

142142
tests.pubsub(CommonFactory.create({
143143
spawnOptions: {
144-
args: ['--enable-pubsub'],
145144
initOptions: { bits: 512 }
146145
}
147146
}), {

test/core/libp2p.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('libp2p customization', function () {
148148
}
149149
},
150150
pubsub: {
151-
enabled: false,
151+
enabled: true,
152152
emitSelf: true,
153153
signMessages: true,
154154
strictSigning: true

test/core/pubsub.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ describe('pubsub disabled', () => {
2424
config: {
2525
Addresses: {
2626
Swarm: []
27+
},
28+
Pubsub: {
29+
Enabled: false
2730
}
2831
},
2932
preload: {
3033
enabled: false
31-
},
32-
pubsub: {
33-
enabled: false
3434
}
3535
})
3636

test/http-api/interface.js

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
136136

137137
tests.pubsub(CommonFactory.create({
138138
spawnOptions: {
139-
args: ['--enable-pubsub'],
140139
initOptions: { bits: 512 }
141140
}
142141
}))

test/http-api/routes.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ describe('HTTP API', () => {
2626
repo: repoTests,
2727
pass: hat(),
2828
config,
29-
pubsub: { enabled: true },
3029
preload: { enabled: false }
3130
})
3231
await ncp(repoExample, repoTests)

0 commit comments

Comments
 (0)