Skip to content

Commit

Permalink
Improve readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Mar 10, 2022
1 parent 162d11f commit 4759df8
Showing 1 changed file with 24 additions and 52 deletions.
76 changes: 24 additions & 52 deletions massa-network/src/peer_info_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,39 +486,25 @@ impl PeerInfoDatabase {
PeerType::WhiteListed
};

if old_pt != PeerType::WhiteListed {
// update global connection counts by peer type
let peer = *self.peers.get(&ip).unwrap(); // filled just before
if peer.active_out_connection_attempts > 0 {
self.decrease_global_active_out_connection_attempt_count(
old_pt,
&ip,
)?;
self.increase_global_active_out_connection_attempt_count(
PeerType::WhiteListed, &ip

)?
}
if peer.active_out_connections > 0 {
self.decrease_global_active_out_connection_count(
old_pt,
&ip,
)?;
self.increase_global_active_out_connection_count(
PeerType::WhiteListed,

)?
}
if peer.active_in_connections > 0 {
self.decrease_global_active_in_connection_count(
old_pt,
&ip,
)?;
self.increase_global_active_in_connection_count(
PeerType::WhiteListed,

)?
}
if old_pt == PeerType::WhiteListed {
continue;
}
// update global connection counts by peer type
let peer = *self.peers.get(&ip).unwrap(); // filled just before
if peer.active_out_connection_attempts > 0 {
self.decrease_global_active_out_connection_attempt_count(old_pt, &ip)?;
self.increase_global_active_out_connection_attempt_count(
PeerType::WhiteListed,
&ip,
)?
}
if peer.active_out_connections > 0 {
self.decrease_global_active_out_connection_count(old_pt, &ip)?;
self.increase_global_active_out_connection_count(PeerType::WhiteListed)?
}
if peer.active_in_connections > 0 {
self.decrease_global_active_in_connection_count(old_pt, &ip)?;
self.increase_global_active_in_connection_count(PeerType::WhiteListed)?
}
}
self.update()
Expand All @@ -538,33 +524,19 @@ impl PeerInfoDatabase {
// update global connection counts by peer type
let peer = *self.peers.get(&ip).unwrap(); // filled just before
if peer.active_out_connection_attempts > 0 {
self.decrease_global_active_out_connection_attempt_count(
old_pt,
&ip,
)?;
self.decrease_global_active_out_connection_attempt_count(old_pt, &ip)?;
self.increase_global_active_out_connection_attempt_count(
Default::default(),
&ip,
)?
}
if peer.active_out_connections > 0 {
self.decrease_global_active_out_connection_count(
old_pt,

&ip,
)?;
self.increase_global_active_out_connection_count(
Default::default(),
)?
self.decrease_global_active_out_connection_count(old_pt, &ip)?;
self.increase_global_active_out_connection_count(Default::default())?
}
if peer.active_in_connections > 0 {
self.decrease_global_active_in_connection_count(
old_pt,
&ip,
)?;
self.increase_global_active_in_connection_count(
Default::default(),
)?
self.decrease_global_active_in_connection_count(old_pt, &ip)?;
self.increase_global_active_in_connection_count(Default::default())?
}
}
}
Expand Down

0 comments on commit 4759df8

Please sign in to comment.