Don't add as an explicit peer if already connected

This commit is contained in:
Luke Parker
2024-03-22 23:51:51 -04:00
parent f11a08c436
commit 4914420a37

View File

@@ -435,18 +435,18 @@ impl LibP2p {
Some(SwarmEvent::Dialing { connection_id, .. }) => { Some(SwarmEvent::Dialing { connection_id, .. }) => {
log::debug!("dialing to peer in connection ID {}", &connection_id); log::debug!("dialing to peer in connection ID {}", &connection_id);
} }
Some(SwarmEvent::ConnectionEstablished { peer_id, connection_id, .. }) => { Some(SwarmEvent::ConnectionEstablished { peer_id, connection_id, .. }) => {
if &peer_id == swarm.local_peer_id() { if &peer_id == swarm.local_peer_id() {
swarm.close_connection(connection_id); swarm.close_connection(connection_id);
} else { } else if swarm.is_connected(&peer_id) {} else {
log::debug!( log::debug!(
"connection established to peer {} in connection ID {}", "connection established to peer {} in connection ID {}",
&peer_id, &peer_id,
&connection_id, &connection_id,
); );
swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id) swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer_id)
}
} }
}
Some(SwarmEvent::Behaviour(BehaviorEvent::Gossipsub( Some(SwarmEvent::Behaviour(BehaviorEvent::Gossipsub(
GsEvent::Message { propagation_source, message, .. }, GsEvent::Message { propagation_source, message, .. },
))) => { ))) => {