Skip to content

Autonat and Kademlia settings updates. #2242

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

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions crates/subspace-networking/src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub(crate) struct BehaviorConfig<RecordStore> {
pub(crate) general_connected_peers_config: Option<ConnectedPeersConfig>,
/// The configuration for the [`ConnectedPeers`] protocol (special instance).
pub(crate) special_connected_peers_config: Option<ConnectedPeersConfig>,
/// Autonat configuration (optional).
pub(crate) autonat: Option<AutonatWrapperConfig>,
/// Autonat configuration.
pub(crate) autonat: AutonatWrapperConfig,
}

#[derive(Debug, Clone, Copy)]
Expand All @@ -88,7 +88,7 @@ pub(crate) struct Behavior<RecordStore> {
Toggle<ConnectedPeersBehaviour<GeneralConnectedPeersInstance>>,
pub(crate) special_connected_peers:
Toggle<ConnectedPeersBehaviour<SpecialConnectedPeersInstance>>,
pub(crate) autonat: Toggle<AutonatWrapper>,
pub(crate) autonat: AutonatWrapper,
}

impl<RecordStore> Behavior<RecordStore>
Expand Down Expand Up @@ -140,7 +140,7 @@ where
.special_connected_peers_config
.map(ConnectedPeersBehaviour::new)
.into(),
autonat: config.autonat.map(AutonatWrapper::new).into(),
autonat: AutonatWrapper::new(config.autonat),
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions crates/subspace-networking/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const YAMUX_BUFFER_SIZE: usize = Piece::SIZE + 1024 * 1024;

/// Max confidence for autonat protocol. Could affect Kademlia mode change.
pub(crate) const AUTONAT_MAX_CONFIDENCE: usize = 3;
/// We set a very long pause before autonat initialization.
const AUTONAT_SERVER_PROBE_DELAY: Duration = Duration::from_secs(3600 * 24 * 365);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not Duration::MAX?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/// Defines Kademlia mode
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -482,8 +484,12 @@ where

debug!(?connection_limits, "DSN connection limits set.");

let enable_autonat = external_addresses.is_empty() && kademlia_mode.is_dynamic();
debug!(%enable_autonat, ?external_addresses, ?kademlia_mode, "Autonat settings.");
let autonat_boot_delay = match kademlia_mode {
KademliaMode::Static(_) => AUTONAT_SERVER_PROBE_DELAY,
KademliaMode::Dynamic => AutonatConfig::default().boot_delay,
};

debug!(?autonat_boot_delay, "Autonat boot delay set.");

let mut behaviour = Behavior::new(BehaviorConfig {
peer_id: local_peer_id,
Expand Down Expand Up @@ -517,15 +523,16 @@ where
..ConnectedPeersConfig::default()
}
}),
autonat: enable_autonat.then(|| AutonatWrapperConfig {
autonat: AutonatWrapperConfig {
inner_config: AutonatConfig {
use_connected: true,
only_global_ips: !config.allow_non_global_addresses_in_dht,
confidence_max: AUTONAT_MAX_CONFIDENCE,
boot_delay: autonat_boot_delay,
..Default::default()
},
local_peer_id,
}),
},
});

match (kademlia_mode, external_addresses.is_empty()) {
Expand Down
13 changes: 6 additions & 7 deletions crates/subspace-networking/src/node_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,13 +1190,12 @@ where

async fn handle_autonat_event(&mut self, event: AutonatEvent) {
trace!(?event, "Autonat event received.");
if let Some(autonat) = self.swarm.behaviour().autonat.as_ref() {
debug!(
public_address=?autonat.public_address(),
confidence=%autonat.confidence(),
"Current public address confidence."
);
}
let autonat = &self.swarm.behaviour().autonat;
debug!(
public_address=?autonat.public_address(),
confidence=%autonat.confidence(),
"Current public address confidence."
);

match event {
AutonatEvent::InboundProbe(_inbound_probe_event) => {
Expand Down