Skip to content

Commit

Permalink
[network]saturating_sub.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangong3624749 committed Apr 28, 2021
1 parent 67a210c commit f1fdc62
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions network-p2p/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,13 @@ impl NetworkBehaviour for DiscoveryBehaviour {
debug!("[network]Threshold reached for single address {:}, max connections {:?}, real connections {:?}", ip, self.max_connections_per_address, *connections);
return;
}
*connections += 1;
*connections.saturating_add(1);
} else {
self.connections.insert(ip, 1);
};
}
}
self.num_connections += 1;
self.num_connections.saturating_add(1);
for k in self.kademlias.values_mut() {
NetworkBehaviour::inject_connection_established(k, peer_id, conn, endpoint)
}
Expand All @@ -573,14 +573,14 @@ impl NetworkBehaviour for DiscoveryBehaviour {
conn: &ConnectionId,
endpoint: &ConnectedPoint,
) {
self.num_connections -= 1;
self.num_connections.saturating_sub(1);
if endpoint.is_listener() {
if let Some(ip) = multiaddr_to_ip_address(endpoint.get_remote_address()) {
if let Some(connections) = self.connections.get_mut(&ip) {
if *connections == 1_u8 {
*connections -= 1;
} else {
if *connections <= 1_u8 {
self.connections.remove(&ip);
} else {
*connections.saturating_sub(1);
}
};
}
Expand Down

0 comments on commit f1fdc62

Please sign in to comment.