Skip to content

Commit

Permalink
final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
sistemd committed Jan 18, 2024
1 parent 08d0ab2 commit 9280c41
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 6 additions & 4 deletions crates/p2p/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions crates/p2p/src/recent_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IpAddr, Instant>,
Expand Down
1 change: 0 additions & 1 deletion crates/p2p/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()),
Expand Down

0 comments on commit 9280c41

Please sign in to comment.