Skip to content

Commit

Permalink
Infer enable_autonat from external_addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Nov 15, 2023
1 parent 683f215 commit f3b7401
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion crates/subspace-networking/examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ pub async fn configure_dsn(
allow_non_global_addresses_in_dht: enable_private_ips,
request_response_protocols: vec![PieceByIndexRequestHandler::create(|_, _| async { None })],
bootstrap_addresses,
enable_autonat: false,
max_pending_outgoing_connections: pending_out_peers,
max_established_outgoing_connections: out_peers,
..default_config
Expand Down
1 change: 0 additions & 1 deletion crates/subspace-networking/examples/random-walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ async fn configure_dsn(
allow_non_global_addresses_in_dht: enable_private_ips,
request_response_protocols: vec![PieceByIndexRequestHandler::create(|_, _| async { None })],
bootstrap_addresses,
enable_autonat: false,
max_pending_outgoing_connections: pending_out_peers,
max_established_outgoing_connections: out_peers,
..default_config
Expand Down
20 changes: 11 additions & 9 deletions crates/subspace-networking/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ pub struct Config<LocalRecordProvider> {
/// Known external addresses to the local peer. The addresses will be added on the swarm start
/// and enable peer to notify others about its reachable address.
pub external_addresses: Vec<Multiaddr>,
/// Enable autonat protocol. Helps detecting whether we're behind the firewall.
///
/// NOTE: Ignored and implied to be `false` in case `external_addresses` is not empty.
pub enable_autonat: bool,
/// Defines whether we should run blocking Kademlia bootstrap() operation before other requests.
pub disable_bootstrap_on_start: bool,
}
Expand Down Expand Up @@ -382,7 +378,6 @@ where
bootstrap_addresses: Vec::new(),
kademlia_mode: KademliaMode::Static(Mode::Client),
external_addresses: Vec::new(),
enable_autonat: true,
disable_bootstrap_on_start: false,
}
}
Expand Down Expand Up @@ -453,7 +448,6 @@ where
bootstrap_addresses,
kademlia_mode,
external_addresses,
enable_autonat,
disable_bootstrap_on_start,
} = config;
let local_peer_id = peer_id(&keypair);
Expand Down Expand Up @@ -506,16 +500,24 @@ where
..ConnectedPeersConfig::default()
}
}),
autonat: (enable_autonat && external_addresses.is_empty()).then(|| AutonatConfig {
autonat: external_addresses.is_empty().then(|| AutonatConfig {
use_connected: true,
only_global_ips: !config.allow_non_global_addresses_in_dht,
confidence_max: AUTONAT_MAX_CONFIDENCE,
..Default::default()
}),
});

if let KademliaMode::Static(mode) = kademlia_mode {
behaviour.kademlia.set_mode(Some(mode));
match (kademlia_mode, external_addresses.is_empty()) {
(KademliaMode::Static(mode), _) => {
behaviour.kademlia.set_mode(Some(mode));
}
(KademliaMode::Dynamic, false) => {
behaviour.kademlia.set_mode(Some(Mode::Server));
}
_ => {
// Autonat will figure it out
}
};

let temporary_bans = Arc::new(Mutex::new(TemporaryBans::new(
Expand Down

0 comments on commit f3b7401

Please sign in to comment.