swarm/src/behaviour: Merge inject_* paired methods (#2445)

Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
Divma
2022-02-09 10:08:28 -05:00
committed by GitHub
parent 5a95a46cd3
commit dc8433e3fc
30 changed files with 583 additions and 481 deletions

View File

@ -226,6 +226,7 @@ impl NetworkBehaviour for Identify {
conn: &ConnectionId,
endpoint: &ConnectedPoint,
failed_addresses: Option<&Vec<Multiaddr>>,
_other_established: usize,
) {
let addr = match endpoint {
ConnectedPoint::Dialer { address, .. } => address.clone(),
@ -254,8 +255,12 @@ impl NetworkBehaviour for Identify {
conn: &ConnectionId,
_: &ConnectedPoint,
_: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
remaining_established: usize,
) {
if let Some(addrs) = self.connected.get_mut(peer_id) {
if remaining_established == 0 {
self.connected.remove(peer_id);
self.pending_push.remove(peer_id);
} else if let Some(addrs) = self.connected.get_mut(peer_id) {
addrs.remove(conn);
}
}
@ -281,11 +286,6 @@ impl NetworkBehaviour for Identify {
}
}
fn inject_disconnected(&mut self, peer_id: &PeerId) {
self.connected.remove(peer_id);
self.pending_push.remove(peer_id);
}
fn inject_new_listen_addr(&mut self, _id: ListenerId, _addr: &Multiaddr) {
if self.config.push_listen_addr_updates {
self.pending_push.extend(self.connected.keys());