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

Commit

Permalink
chore: add config for pubsub router
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Jul 24, 2019
1 parent 5f20a68 commit 63cd538
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
peerBook,
modules: {
contentRouting,
peerRouting
peerRouting,
pubsub: get(config, 'Pubsub.Router', 'gossipsub') === 'floodsub'
? require('libp2p-floodsub') : require('libp2p-gossipsub')
},
config: {
peerDiscovery: {
Expand Down
3 changes: 3 additions & 0 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ const configSchema = s({
}))
})),
Bootstrap: optional(s(['multiaddr-ipfs'])),
Pubsub: optional(s({
Router: 'string?'
})),
Swarm: optional(s({
ConnMgr: optional(s({
LowWater: 'number?',
Expand Down
3 changes: 3 additions & 0 deletions src/core/runtime/config-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ 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
3 changes: 3 additions & 0 deletions src/core/runtime/config-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ 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
7 changes: 0 additions & 7 deletions test/core/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ describe('interface-ipfs-core tests', function () {

tests.bootstrap(defaultCommonFactory)

tests.config(defaultCommonFactory, {
skip: [{
name: 'should set a number',
reason: 'Failing - needs to be fixed'
}]
})

tests.config(defaultCommonFactory, {
skip: [
{
Expand Down
59 changes: 56 additions & 3 deletions test/core/libp2p.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ describe('libp2p customization', function () {
webRTCStar: {
Enabled: false
}
},
pubsub: {
enabled: false
}
}
datastore = new MemoryStore()
Expand Down Expand Up @@ -290,4 +287,60 @@ describe('libp2p customization', function () {
})
})
})

describe('bundle via custom config for pubsub', () => {
it('select gossipsub as pubsub router', (done) => {
const ipfs = {
_repo: {
datastore
},
_peerInfo: peerInfo,
_peerBook: peerBook,
// eslint-disable-next-line no-console
_print: console.log,
_options: {}
}
const customConfig = {
...testConfig,
Pubsub: {
Router: 'gossipsub'
}
}

_libp2p = libp2pComponent(ipfs, customConfig)

_libp2p.start((err) => {
expect(err).to.not.exist()
expect(_libp2p._modules.pubsub).to.eql(require('libp2p-gossipsub'))
done()
})
})

it('select floodsub as pubsub router', (done) => {
const ipfs = {
_repo: {
datastore
},
_peerInfo: peerInfo,
_peerBook: peerBook,
// eslint-disable-next-line no-console
_print: console.log,
_options: {}
}
const customConfig = {
...testConfig,
Pubsub: {
Router: 'floodsub'
}
}

_libp2p = libp2pComponent(ipfs, customConfig)

_libp2p.start((err) => {
expect(err).to.not.exist()
expect(_libp2p._modules.pubsub).to.eql(require('libp2p-floodsub'))
done()
})
})
})
})

0 comments on commit 63cd538

Please sign in to comment.