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

Commit

Permalink
fix: when peer is discovered but not online yet (racing cond), delay …
Browse files Browse the repository at this point in the history
…dial until libp2p is online
  • Loading branch information
pgte committed Jul 6, 2017
1 parent 3be165d commit cd3b754
Showing 1 changed file with 6 additions and 1 deletion.
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('online', dial)
}
})

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

0 comments on commit cd3b754

Please sign in to comment.