mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 08:51:08 +03:00
Allow to have more than min_peers/2 outbound peers (#2537)
* Allow to have more than min_peers/2 outbound peers Default value is 8, so we allow only 4 outbound peers, unfortunately if a node is behind NAT it can't get inbound peers and it stucks with 4 peers as maximum. This PR allows a number of outbound peers to be between min_peers and max_peers/2. Node behind NAT will eventually have just min_peers number of peers. * Extract into healthy_peers_mix function
This commit is contained in:
parent
1f7ea4930e
commit
a63cfa7138
2 changed files with 9 additions and 6 deletions
|
@ -513,7 +513,13 @@ impl Peers {
|
|||
}
|
||||
|
||||
pub fn enough_peers(&self) -> bool {
|
||||
self.connected_peers().len() >= self.config.peer_min_preferred_count() as usize
|
||||
self.peer_count() >= self.config.peer_min_preferred_count()
|
||||
}
|
||||
|
||||
/// We have enough peers, both total connected and outbound connected
|
||||
pub fn healthy_peers_mix(&self) -> bool {
|
||||
self.enough_peers()
|
||||
&& self.peer_outbound_count() >= self.config.peer_min_preferred_count() / 2
|
||||
}
|
||||
|
||||
/// Removes those peers that seem to have expired
|
||||
|
|
|
@ -186,10 +186,7 @@ fn monitor_peers(
|
|||
// maintenance step first, clean up p2p server peers
|
||||
peers.clean_peers(config.peer_max_count() as usize);
|
||||
|
||||
// We have enough peers, both total connected and outbound connected so we are good.
|
||||
if peers.peer_count() >= config.peer_min_preferred_count()
|
||||
&& peers.peer_outbound_count() >= config.peer_min_preferred_count() / 2
|
||||
{
|
||||
if peers.healthy_peers_mix() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -318,7 +315,7 @@ fn listen_for_addrs(
|
|||
let addrs: Vec<SocketAddr> = rx.try_iter().collect();
|
||||
|
||||
// If we have a healthy number of outbound peers then we are done here.
|
||||
if peers.peer_outbound_count() >= p2p.config.peer_min_preferred_count() / 2 {
|
||||
if peers.healthy_peers_mix() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue