Skip to content

Commit

Permalink
chore(network): remove nat detection via incoming connections check
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Apr 25, 2024
1 parent 2c5209b commit ac77ad7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
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

0 comments on commit ac77ad7

Please sign in to comment.