From 8b0f9964989bcc4a7ad4e3437f89a57eaa60913d Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 7 Jul 2017 14:27:46 +0100 Subject: [PATCH] fix: is online is only online if libp2p is online (#891) --- package.json | 8 ++++---- src/core/components/is-online.js | 2 +- src/core/components/libp2p.js | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 88ebf37115..4e0a878294 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/core/components/is-online.js b/src/core/components/is-online.js index 666aecf808..75a03776a1 100644 --- a/src/core/components/is-online.js +++ b/src/core/components/is-online.js @@ -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()) } } diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 54328fe255..79064a6a5b 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -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) => {