Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(network): remove nat detection via incoming connections check #1648

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions sn_networking/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ pub enum NetworkEvent {
#[derive(Debug, Clone)]
pub enum TerminateNodeReason {
HardDiskWriteError,
BehindNAT,
}

// Manually implement Debug as `#[debug(with = "unverified_record_fmt")]` not working as expected.
Expand Down Expand Up @@ -257,6 +256,13 @@ impl SwarmDriver {
event_string = "kad_event";
self.handle_kad_event(kad_event)?;
}
SwarmEvent::Behaviour(NodeEvent::Dcutr(event)) => {
event_string = "dcutr_event";
info!(
"Dcutr with remote peer: {:?} is: {:?}",
event.remote_peer_id, event.result
);
}
SwarmEvent::Behaviour(NodeEvent::RelayClient(event)) => {
event_string = "relay_client_event";

Expand Down Expand Up @@ -419,14 +425,6 @@ impl SwarmDriver {
.kademlia
.add_address(&peer_id, multiaddr.clone());
}

if self.relay_manager.are_we_behind_nat(&mut self.swarm) {
warn!("Node reported as being behind NAT for not having enough incoming connections. This can be a false positive. Do nothing.");

// self.send_event(NetworkEvent::TerminateNode {
// reason: TerminateNodeReason::BehindNAT,
// })
}
}
}
trace!(
Expand Down
25 changes: 0 additions & 25 deletions sn_networking/src/relay_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};

const MAX_CONCURRENT_RELAY_CONNECTIONS: usize = 3;
const MAX_POTENTIAL_CANDIDATES: usize = 15;
const MAX_PEERS_IN_RT_DURING_NAT_CHECK: usize = 30;

/// To manager relayed connections.
#[derive(Debug)]
Expand Down Expand Up @@ -65,30 +64,6 @@ impl RelayManager {
|| self.waiting_for_reservation.contains_key(peer_id)
}

/// If we have 0 incoming connection even after we have a lot of peers, then we are behind a NAT
pub(crate) fn are_we_behind_nat(&self, swarm: &mut Swarm<NodeBehaviour>) -> bool {
if swarm
.network_info()
.connection_counters()
.num_established_incoming()
== 0
|| swarm
.network_info()
.connection_counters()
.num_pending_incoming()
== 0
{
let mut total_peers = 0;
for kbucket in swarm.behaviour_mut().kademlia.kbuckets() {
total_peers += kbucket.num_entries();
if total_peers > MAX_PEERS_IN_RT_DURING_NAT_CHECK {
return true;
}
}
}
false
}

/// Add a potential candidate to the list if it satisfies all the identify checks and also supports the relay server
/// protocol.
pub(crate) fn add_potential_candidates(
Expand Down
Loading