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

Commit

Permalink
fix: only dial to unconnected peers (#1914)
Browse files Browse the repository at this point in the history
* fix: only dial to unconnected peers

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* fix: update peer info before conditionally dialing

When we discover a peer, we may not have the latest information from our PeerBook, such as the connected multiaddress. Doing peerBook.put handles merging this information and the new PeerInfo instance is returned. Updating the peerInfo instance, before performing a check, should make sure we have the correct information.

Co-Authored-By: alanshaw <[email protected]>

* refactor: share noop callback

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
Alan Shaw authored Mar 13, 2019
1 parent ceec0bc commit 1478652
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ module.exports = function libp2p (self, config) {
const libp2p = createBundle({ options, config, datastore, peerInfo, peerBook })
let discoveredPeers = []

const noop = () => {}
const putAndDial = peerInfo => {
peerBook.put(peerInfo)
libp2p.dial(peerInfo, () => {})
peerInfo = peerBook.put(peerInfo)
if (!peerInfo.isConnected()) {
libp2p.dial(peerInfo, noop)
}
}

libp2p.on('start', () => {
Expand Down

0 comments on commit 1478652

Please sign in to comment.