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

Commit 8b0f996

Browse files
pgtedaviddias
authored andcommitted
fix: is online is only online if libp2p is online (#891)
1 parent 8735a08 commit 8b0f996

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@
111111
"is-ipfs": "^0.3.0",
112112
"isstream": "^0.1.2",
113113
"joi": "^10.6.0",
114-
"libp2p": "^0.9.1",
115-
"libp2p-floodsub": "~0.9.4",
116-
"libp2p-kad-dht": "^0.1.0",
114+
"libp2p": "^0.10.0",
115+
"libp2p-floodsub": "~0.10.0",
116+
"libp2p-kad-dht": "^0.2.0",
117117
"libp2p-mdns": "^0.7.0",
118118
"libp2p-multiplex": "^0.4.3",
119119
"libp2p-railing": "^0.5.1",
@@ -145,7 +145,7 @@
145145
"pull-stream-to-stream": "^1.3.4",
146146
"pull-zip": "^2.0.1",
147147
"read-pkg-up": "^2.0.0",
148-
"readable-stream": "1.1.14",
148+
"readable-stream": "2.3.3",
149149
"safe-buffer": "^5.1.1",
150150
"stream-to-pull-stream": "^1.7.2",
151151
"tar-stream": "^1.5.4",

src/core/components/is-online.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module.exports = function isOnline (self) {
44
return () => {
5-
return Boolean(self._bitswap && self._libp2pNode)
5+
return Boolean(self._bitswap && self._libp2pNode && self._libp2pNode.isStarted())
66
}
77
}

src/core/components/libp2p.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ module.exports = function libp2p (self) {
2626
self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)
2727

2828
self._libp2pNode.on('peer:discovery', (peerInfo) => {
29-
if (self.isOnline()) {
29+
const dial = () => {
3030
self._peerInfoBook.put(peerInfo)
3131
self._libp2pNode.dial(peerInfo, () => {})
3232
}
33+
if (self.isOnline()) {
34+
dial()
35+
} else {
36+
self._libp2pNode.once('start', dial)
37+
}
3338
})
3439

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

0 commit comments

Comments
 (0)