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

Commit 1478652

Browse files
author
Alan Shaw
authored
fix: only dial to unconnected peers (#1914)
* 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]>
1 parent ceec0bc commit 1478652

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/core/components/libp2p.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ module.exports = function libp2p (self, config) {
1919
const libp2p = createBundle({ options, config, datastore, peerInfo, peerBook })
2020
let discoveredPeers = []
2121

22+
const noop = () => {}
2223
const putAndDial = peerInfo => {
23-
peerBook.put(peerInfo)
24-
libp2p.dial(peerInfo, () => {})
24+
peerInfo = peerBook.put(peerInfo)
25+
if (!peerInfo.isConnected()) {
26+
libp2p.dial(peerInfo, noop)
27+
}
2528
}
2629

2730
libp2p.on('start', () => {

0 commit comments

Comments
 (0)