diff --git a/crates/p2p/src/main_loop.rs b/crates/p2p/src/main_loop.rs index aa1dfa801f..98fc671180 100644 --- a/crates/p2p/src/main_loop.rs +++ b/crates/p2p/src/main_loop.rs @@ -5,12 +5,12 @@ use std::sync::Arc; use futures::{channel::mpsc::Receiver as ResponseReceiver, StreamExt}; use libp2p::gossipsub::{self, IdentTopic}; -use libp2p::{identify, Multiaddr}; use libp2p::kad::{self, BootstrapError, BootstrapOk, QueryId, QueryResult}; use libp2p::multiaddr::Protocol; use libp2p::swarm::dial_opts::DialOpts; use libp2p::swarm::SwarmEvent; use libp2p::PeerId; +use libp2p::{identify, Multiaddr}; use p2p_proto::block::{BlockBodiesResponse, BlockHeadersResponse}; use p2p_proto::event::EventsResponse; use p2p_proto::receipt::ReceiptsResponse; @@ -197,9 +197,11 @@ impl MainLoop { // If this is an incoming connection, we have to prevent the peer from // reconnecting too quickly. if endpoint.is_listener() { - // Is this connection established over a relay node? - let is_relay = endpoint.get_remote_address().iter().any(|p| p == Protocol::P2pCircuit); - // Different rules apply to direct and relayed peers. + // Different timeouts apply to direct peers and peers connecting over a relay. + let is_relay = endpoint + .get_remote_address() + .iter() + .any(|p| p == Protocol::P2pCircuit); let recent_peers = if is_relay { &mut self.recent_relay_peers } else { diff --git a/crates/p2p/src/recent_peers.rs b/crates/p2p/src/recent_peers.rs index b2053cc73f..61f7aaf047 100644 --- a/crates/p2p/src/recent_peers.rs +++ b/crates/p2p/src/recent_peers.rs @@ -4,11 +4,10 @@ use std::{ time::{Duration, Instant}, }; -/// Set of recently connected peers. Peers are tracked primarily by their IP address, but the -/// peer ID is also stored to allow for removal of peers. +/// Set of recently connected peers tracked by their IP address. /// -/// Peers are removed from the set after a timeout. The actual removal only happens once any -/// of the methods on this type are called. +/// Peers are removed from the set after a timeout. The actual removal only happens once one +/// of the methods on this type is called. #[derive(Debug)] pub struct RecentPeers { peers: HashMap, diff --git a/crates/p2p/src/tests.rs b/crates/p2p/src/tests.rs index 377305e18a..3964096c1d 100644 --- a/crates/p2p/src/tests.rs +++ b/crates/p2p/src/tests.rs @@ -359,7 +359,6 @@ async fn reconnect_too_quickly() { .await .unwrap(); - // TODO Try to use the IncomingConnection swarm event instead? Not sure if possible // The peer gets disconnected without completing the connection establishment handler. wait_for_event(&mut peer1.event_receiver, |event| match event { Event::Test(TestEvent::ConnectionClosed { remote }) if remote == peer2.peer_id => Some(()),