Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate gossipsub by default #19

Merged
merged 8 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
"cids": "~0.6.0",
"debug": "^4.1.1",
"length-prefixed-stream": "github:jacobheun/length-prefixed-stream#v2.0.0-rc.1",
"libp2p": "~0.25.2",
"libp2p": "libp2p/js-libp2p#feat/integrate-gossipsub-by-default",
"libp2p-bootstrap": "~0.9.7",
"libp2p-floodsub": "~0.17.0",
"libp2p-gossipsub": "ChainSafe/gossipsub-js#master",
"libp2p-kad-dht": "~0.15.2",
"libp2p-secio": "~0.11.1",
"libp2p-tcp": "~0.13.0",
Expand Down
5 changes: 5 additions & 0 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ const main = async (processArgs) => {
type: 'boolean',
default: false
})
.option('pubsubRouter', {
desc: 'Specifies the pubsub router implementation',
type: 'string',
default: 'gossipsub'
})
.fail((msg, err, yargs) => {
if (err) {
throw err // preserve stack
Expand Down
24 changes: 15 additions & 9 deletions src/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const Bootstrap = require('libp2p-bootstrap')
const MPLEX = require('pull-mplex')
const SECIO = require('libp2p-secio')
const KadDHT = require('libp2p-kad-dht')
const FloodSub = require('libp2p-floodsub')
const GossipSub = require('libp2p-gossipsub')
const pullToStream = require('pull-stream-to-stream')
const PeerBook = require('peer-book')
const PeerInfo = require('peer-info')
Expand Down Expand Up @@ -122,7 +124,7 @@ class Pubsub {
*/
subscribe (topic, options, handler) {
return new Promise((resolve, reject) => {
this.libp2p._pubsub.subscribe(topic, options, handler, (err) => {
this.libp2p._pubSub.subscribe(topic, options, handler, (err) => {
if (err) return reject(err)
resolve()
})
Expand All @@ -137,7 +139,7 @@ class Pubsub {
*/
publish (topic, data) {
return new Promise((resolve, reject) => {
this.libp2p._pubsub.publish(topic, data, (err) => {
this.libp2p._pubSub.publish(topic, data, (err) => {
if (err) return reject(err)
resolve()
})
Expand All @@ -150,7 +152,7 @@ class Pubsub {
*/
getTopics () {
return new Promise((resolve, reject) => {
this.libp2p._pubsub.ls((err, topics) => {
this.libp2p._pubSub.ls((err, topics) => {
if (err) return reject(err)
resolve(topics)
})
Expand Down Expand Up @@ -253,8 +255,8 @@ class DaemonLibp2p extends Libp2p {
constructor (libp2pOpts, { announceAddrs }) {
super(libp2pOpts)
this.announceAddrs = announceAddrs
this.needsPullStream = libp2pOpts.config.EXPERIMENTAL.pubsub
this._pubsub = this.pubsub
this.needsPullStream = libp2pOpts.config.pubsub.enabled
this._pubSub = this.pubsub
jacobheun marked this conversation as resolved.
Show resolved Hide resolved
this.pubsub = new Pubsub(this)
}
get contentRouting () {
Expand Down Expand Up @@ -384,6 +386,8 @@ class DaemonLibp2p extends Libp2p {
* @param {string} opts.id
* @param {string} opts.bootstrapPeers
* @param {string} opts.hostAddrs
* @param {boolean} opts.pubsub
* @param {string} opts.pubsubRouter
* @returns {Libp2p}
*/
const createLibp2p = async ({
Expand All @@ -395,7 +399,8 @@ const createLibp2p = async ({
connMgrLo,
connMgrHi,
id,
pubsub
pubsub,
pubsubRouter
} = {}) => {
const peerInfo = await getPeerInfo(id)
const peerBook = new PeerBook()
Expand Down Expand Up @@ -430,7 +435,8 @@ const createLibp2p = async ({
peerDiscovery: [
Bootstrap
],
dht: KadDHT
dht: KadDHT,
pubsub: pubsubRouter === 'floodsub' ? GossipSub : FloodSub
},
config: {
peerDiscovery: {
Expand All @@ -451,8 +457,8 @@ const createLibp2p = async ({
enabled: dht,
kBucketSize: 20
},
EXPERIMENTAL: {
pubsub: pubsub
pubsub: {
enabled: pubsub
}
}
}, {
Expand Down
Loading