Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
feat: update deps and stop using swarm directly
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jul 21, 2017
1 parent 0c286db commit 281771e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ js-libp2p-floodsub
```JavaScript
const FloodSub = require('libp2p-floodsub')

const fsub = new FloodSub(libp2pNodeInstance)
const fsub = new FloodSub(node)

fsub.start((err) => {
if (err) {
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@
"devDependencies": {
"aegir": "^11.0.2",
"benchmark": "^2.1.4",
"chai": "^4.0.2",
"dirty-chai": "^2.0.0",
"libp2p": "^0.10.0",
"libp2p-secio": "^0.6.8",
"libp2p-spdy": "^0.10.6",
"libp2p-tcp": "^0.10.1",
"chai": "^4.1.0",
"dirty-chai": "^2.0.1",
"pre-commit": "^1.2.2",
"lodash.times": "^4.3.2",
"multiaddr": "^2.3.0",
"libp2p": "~0.10.1",
"libp2p-secio": "~0.6.8",
"libp2p-spdy": "~0.10.6",
"libp2p-tcp": "~0.10.1",
"peer-id": "~0.8.7",
"peer-info": "~0.9.2",
"pre-commit": "^1.2.2"
"peer-info": "~0.9.3"
},
"dependencies": {
"async": "^2.5.0",
Expand All @@ -75,4 +74,4 @@
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>",
"wanderer <mjbecze@gmail.com>"
]
}
}
21 changes: 7 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FloodSub extends EventEmitter {
// If already have a PubSub conn, ignore
const peer = this.peers.get(idB58Str)
if (peer && peer.isConnected) {
return callback()
return setImmediate(() => callback())
}

this.libp2p.dial(peerInfo, multicodec, (err, conn) => {
Expand Down Expand Up @@ -187,8 +187,7 @@ class FloodSub extends EventEmitter {

_forwardMessages (topics, messages) {
this.peers.forEach((peer) => {
if (!peer.isWritable ||
!utils.anyMatch(peer.topics, topics)) {
if (!peer.isWritable || !utils.anyMatch(peer.topics, topics)) {
return
}

Expand All @@ -214,14 +213,12 @@ class FloodSub extends EventEmitter {
this.libp2p.handle(multicodec, this._onConnection)

// Speed up any new peer that comes in my way
this.libp2p.swarm.on('peer-mux-established', this._dialPeer)
this.libp2p.on('peer:connect', this._dialPeer)

// Dial already connected peers
const peerInfos = values(this.libp2p.peerBook.getAll())

asyncEach(peerInfos, (peerInfo, cb) => {
this._dialPeer(peerInfo, cb)
}, (err) => {
asyncEach(peerInfos, (peer, cb) => this._dialPeer(peer, cb), (err) => {
setImmediate(() => {
this.started = true
callback(err)
Expand All @@ -242,7 +239,7 @@ class FloodSub extends EventEmitter {
}

this.libp2p.unhandle(multicodec)
this.libp2p.swarm.removeListener('peer-mux-established', this._dialPeer)
this.libp2p.removeListener('peer:connect', this._dialPeer)

asyncEach(this.peers.values(), (peer, cb) => peer.close(cb), (err) => {
if (err) {
Expand Down Expand Up @@ -304,9 +301,7 @@ class FloodSub extends EventEmitter {

topics = ensureArray(topics)

topics.forEach((topic) => {
this.subscriptions.add(topic)
})
topics.forEach((topic) => this.subscriptions.add(topic))

this.peers.forEach((peer) => checkIfReady(peer))
// make sure that FloodSub is already mounted
Expand All @@ -329,9 +324,7 @@ class FloodSub extends EventEmitter {
assert(this.started, 'FloodSub is not started')
topics = ensureArray(topics)

topics.forEach((topic) => {
this.subscriptions.delete(topic)
})
topics.forEach((topic) => this.subscriptions.delete(topic))

this.peers.forEach((peer) => checkIfReady(peer))
// make sure that FloodSub is already mounted
Expand Down

0 comments on commit 281771e

Please sign in to comment.