Skip to content

Commit

Permalink
Avoid dublicating Features in requestedState
Browse files Browse the repository at this point in the history
Jauler committed Dec 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3f9a3e2 commit 0ab514e
Showing 2 changed files with 12 additions and 14 deletions.
4 changes: 0 additions & 4 deletions src/device.rs
Original file line number Diff line number Diff line change
@@ -232,9 +232,6 @@ pub struct RequestedState {

// Wireguard stun server that should be currently used
pub wg_stun_server: Option<StunServer>,

// Requested keepalive periods
pub(crate) keepalive_periods: FeaturePersistentKeepalive,
}

pub struct MeshnetEntities {
@@ -1207,7 +1204,6 @@ impl Runtime {

let requested_state = RequestedState {
device_config: config.clone(),
keepalive_periods: features.wireguard.persistent_keepalive.clone(),
..Default::default()
};

22 changes: 12 additions & 10 deletions src/device/wg_controller.rs
Original file line number Diff line number Diff line change
@@ -528,7 +528,7 @@ async fn consolidate_wg_peers<
requested_peer
.peer
.persistent_keepalive_interval
.unwrap_or(requested_state.keepalive_periods.direct)
.unwrap_or(features.wireguard.persistent_keepalive.direct)
.into(),
),
None,
@@ -704,9 +704,9 @@ async fn build_requested_peers_list<
ip_addresses.push(VPN_EXTERNAL_IPV4.into());
let (persistent_keepalive_interval, batching_keepalive_interval) =
if features.batching.is_some() {
(None, requested_state.keepalive_periods.vpn)
(None, features.wireguard.persistent_keepalive.vpn)
} else {
(requested_state.keepalive_periods.vpn, None)
(features.wireguard.persistent_keepalive.vpn, None)
};

// If the PQ VPN is set up we need to configure the preshared key
@@ -784,9 +784,9 @@ async fn build_requested_peers_list<
telio_log_debug!("Configuring wg-stun peer: {}, at {}", public_key, endpoint);
let (persistent_keepalive_interval, batching_keepalive_interval) =
if features.batching.is_some() {
(None, requested_state.keepalive_periods.stun)
(None, features.wireguard.persistent_keepalive.stun)
} else {
(requested_state.keepalive_periods.stun, None)
(features.wireguard.persistent_keepalive.stun, None)
};

let allowed_ips = if features.ipv6 {
@@ -860,9 +860,9 @@ async fn build_requested_meshnet_peers_list<
let public_key = p.base.public_key;
let (persistent_keepalive_interval, batching_keepalive_interval) =
if features.batching.is_some() {
(None, requested_state.keepalive_periods.proxying)
(None, features.wireguard.persistent_keepalive.proxying)
} else {
(requested_state.keepalive_periods.proxying, None)
(features.wireguard.persistent_keepalive.proxying, None)
};

let endpoint = proxy_endpoints
@@ -963,6 +963,7 @@ async fn build_requested_meshnet_peers_list<
None => &[],
},
requested_state,
features,
);

// If we are in direct state, tell cross ping check about it
@@ -1002,10 +1003,10 @@ async fn build_requested_meshnet_peers_list<
// If peer is offline according to derp, we turn off keepalives.
None
} else {
requested_state.keepalive_periods.proxying
features.wireguard.persistent_keepalive.proxying
}
} else {
Some(requested_state.keepalive_periods.direct)
Some(features.wireguard.persistent_keepalive.direct)
};

if features.batching.is_some() {
@@ -1201,11 +1202,12 @@ fn peer_state(
link_state: Option<LinkState>,
proxy_endpoints: &[SocketAddr],
requested_state: &RequestedState,
features: &Features,
) -> PeerState {
// Define some useful constants
let keepalive_period = peer
.and_then(|p| p.persistent_keepalive_interval)
.unwrap_or(requested_state.keepalive_periods.direct);
.unwrap_or(features.wireguard.persistent_keepalive.direct);
let peer_connectivity_timeout = Duration::from_secs((keepalive_period * 3) as u64);
let peer_upgrade_window = Duration::from_secs(DEFAULT_PEER_UPGRADE_WINDOW);

0 comments on commit 0ab514e

Please sign in to comment.