From 59e33430b1c441c96235a5fb03fa13f355e2594f Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 11 Mar 2019 12:46:26 +0000 Subject: [PATCH 1/3] fix: only dial to unconnected peers License: MIT Signed-off-by: Alan Shaw --- src/core/components/libp2p.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 2a5a4a9b6a..233c483932 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -21,7 +21,9 @@ module.exports = function libp2p (self, config) { const putAndDial = peerInfo => { peerBook.put(peerInfo) - libp2p.dial(peerInfo, () => {}) + if (!peerInfo.isConnected()) { + libp2p.dial(peerInfo, () => {}) + } } libp2p.on('start', () => { From 675dac37d1bb7d4d68e13426e14b7e6221f16a4c Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Tue, 12 Mar 2019 14:19:03 +0000 Subject: [PATCH 2/3] 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 --- src/core/components/libp2p.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 233c483932..530d730fb3 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -20,7 +20,7 @@ module.exports = function libp2p (self, config) { let discoveredPeers = [] const putAndDial = peerInfo => { - peerBook.put(peerInfo) + peerInfo = peerBook.put(peerInfo) if (!peerInfo.isConnected()) { libp2p.dial(peerInfo, () => {}) } From 540e10c5047aaa54d9545b737849a47268fdf8b3 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 12 Mar 2019 14:30:20 +0000 Subject: [PATCH 3/3] refactor: share noop callback License: MIT Signed-off-by: Alan Shaw --- src/core/components/libp2p.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 530d730fb3..7fc21bc922 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -19,10 +19,11 @@ module.exports = function libp2p (self, config) { const libp2p = createBundle({ options, config, datastore, peerInfo, peerBook }) let discoveredPeers = [] + const noop = () => {} const putAndDial = peerInfo => { peerInfo = peerBook.put(peerInfo) if (!peerInfo.isConnected()) { - libp2p.dial(peerInfo, () => {}) + libp2p.dial(peerInfo, noop) } }