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

Commit

Permalink
fix: is online is only online if libp2p is online (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte authored and daviddias committed Jul 7, 2017
1 parent 8735a08 commit 8b0f996
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@
"is-ipfs": "^0.3.0",
"isstream": "^0.1.2",
"joi": "^10.6.0",
"libp2p": "^0.9.1",
"libp2p-floodsub": "~0.9.4",
"libp2p-kad-dht": "^0.1.0",
"libp2p": "^0.10.0",
"libp2p-floodsub": "~0.10.0",
"libp2p-kad-dht": "^0.2.0",
"libp2p-mdns": "^0.7.0",
"libp2p-multiplex": "^0.4.3",
"libp2p-railing": "^0.5.1",
Expand Down Expand Up @@ -145,7 +145,7 @@
"pull-stream-to-stream": "^1.3.4",
"pull-zip": "^2.0.1",
"read-pkg-up": "^2.0.0",
"readable-stream": "1.1.14",
"readable-stream": "2.3.3",
"safe-buffer": "^5.1.1",
"stream-to-pull-stream": "^1.7.2",
"tar-stream": "^1.5.4",
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/is-online.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module.exports = function isOnline (self) {
return () => {
return Boolean(self._bitswap && self._libp2pNode)
return Boolean(self._bitswap && self._libp2pNode && self._libp2pNode.isStarted())
}
}
7 changes: 6 additions & 1 deletion src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ module.exports = function libp2p (self) {
self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)

self._libp2pNode.on('peer:discovery', (peerInfo) => {
if (self.isOnline()) {
const dial = () => {
self._peerInfoBook.put(peerInfo)
self._libp2pNode.dial(peerInfo, () => {})
}
if (self.isOnline()) {
dial()
} else {
self._libp2pNode.once('start', dial)
}
})

self._libp2pNode.on('peer:connect', (peerInfo) => {
Expand Down

0 comments on commit 8b0f996

Please sign in to comment.