Sync corrections (#1034)

* Correct status re-request logic improve logging

* Prevent multiple dials of the same peer

* Discovery to obey max peers when connecting to new peers
This commit is contained in:
Age Manning
2020-04-22 00:29:19 +10:00
committed by GitHub
parent b88b3ffe40
commit 20b6baf11f
11 changed files with 247 additions and 161 deletions

View File

@@ -454,11 +454,17 @@ where
for peer_id in closer_peers {
// if we need more peers, attempt a connection
if self.network_globals.connected_peers() < self.max_peers
&& !self.network_globals.peers.read().is_connected(&peer_id)
if self.network_globals.connected_or_dialing_peers()
< self.max_peers
&& !self
.network_globals
.peers
.read()
.is_connected_or_dialing(&peer_id)
&& !self.banned_peers.contains(&peer_id)
{
debug!(self.log, "Peer discovered"; "peer_id"=> format!("{:?}", peer_id));
debug!(self.log, "Connecting to discovered peer"; "peer_id"=> format!("{:?}", peer_id));
self.network_globals.peers.write().dialing_peer(&peer_id);
self.events
.push_back(NetworkBehaviourAction::DialPeer { peer_id });
}