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

Commit 63cd538

Browse files
committed
chore: add config for pubsub router
1 parent 5f20a68 commit 63cd538

File tree

6 files changed

+68
-11
lines changed

6 files changed

+68
-11
lines changed

src/core/components/libp2p.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
6464
peerBook,
6565
modules: {
6666
contentRouting,
67-
peerRouting
67+
peerRouting,
68+
pubsub: get(config, 'Pubsub.Router', 'gossipsub') === 'floodsub'
69+
? require('libp2p-floodsub') : require('libp2p-gossipsub')
6870
},
6971
config: {
7072
peerDiscovery: {

src/core/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ const configSchema = s({
6868
}))
6969
})),
7070
Bootstrap: optional(s(['multiaddr-ipfs'])),
71+
Pubsub: optional(s({
72+
Router: 'string?'
73+
})),
7174
Swarm: optional(s({
7275
ConnMgr: optional(s({
7376
LowWater: 'number?',

src/core/runtime/config-browser.js

Lines changed: 3 additions & 0 deletions
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+
Router: 'gossipsub'
32+
},
3033
Swarm: {
3134
ConnMgr: {
3235
LowWater: 200,

src/core/runtime/config-nodejs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ module.exports = () => ({
4040
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
4141
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
4242
],
43+
Pubsub: {
44+
Router: 'gossipsub'
45+
},
4346
Swarm: {
4447
ConnMgr: {
4548
LowWater: 200,

test/core/interface.spec.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ describe('interface-ipfs-core tests', function () {
1616

1717
tests.bootstrap(defaultCommonFactory)
1818

19-
tests.config(defaultCommonFactory, {
20-
skip: [{
21-
name: 'should set a number',
22-
reason: 'Failing - needs to be fixed'
23-
}]
24-
})
25-
2619
tests.config(defaultCommonFactory, {
2720
skip: [
2821
{

test/core/libp2p.spec.js

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ describe('libp2p customization', function () {
4444
webRTCStar: {
4545
Enabled: false
4646
}
47-
},
48-
pubsub: {
49-
enabled: false
5047
}
5148
}
5249
datastore = new MemoryStore()
@@ -290,4 +287,60 @@ describe('libp2p customization', function () {
290287
})
291288
})
292289
})
290+
291+
describe('bundle via custom config for pubsub', () => {
292+
it('select gossipsub as pubsub router', (done) => {
293+
const ipfs = {
294+
_repo: {
295+
datastore
296+
},
297+
_peerInfo: peerInfo,
298+
_peerBook: peerBook,
299+
// eslint-disable-next-line no-console
300+
_print: console.log,
301+
_options: {}
302+
}
303+
const customConfig = {
304+
...testConfig,
305+
Pubsub: {
306+
Router: 'gossipsub'
307+
}
308+
}
309+
310+
_libp2p = libp2pComponent(ipfs, customConfig)
311+
312+
_libp2p.start((err) => {
313+
expect(err).to.not.exist()
314+
expect(_libp2p._modules.pubsub).to.eql(require('libp2p-gossipsub'))
315+
done()
316+
})
317+
})
318+
319+
it('select floodsub as pubsub router', (done) => {
320+
const ipfs = {
321+
_repo: {
322+
datastore
323+
},
324+
_peerInfo: peerInfo,
325+
_peerBook: peerBook,
326+
// eslint-disable-next-line no-console
327+
_print: console.log,
328+
_options: {}
329+
}
330+
const customConfig = {
331+
...testConfig,
332+
Pubsub: {
333+
Router: 'floodsub'
334+
}
335+
}
336+
337+
_libp2p = libp2pComponent(ipfs, customConfig)
338+
339+
_libp2p.start((err) => {
340+
expect(err).to.not.exist()
341+
expect(_libp2p._modules.pubsub).to.eql(require('libp2p-floodsub'))
342+
done()
343+
})
344+
})
345+
})
293346
})

0 commit comments

Comments
 (0)