summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/src/lib.rs1
-rw-r--r--mullvad-daemon/src/wireguard.rs40
2 files changed, 28 insertions, 13 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index e830d8edca..3e9f405907 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -1357,6 +1357,7 @@ where
Self::oneshot_send(tx, (), "set_wireguard_automatic_rotation response");
if settings_changed {
self.event_listener.notify_settings(self.settings.clone());
+ self.wireguard_key_manager.update_rotation_interval(interval);
}
}
Err(e) => error!("{}", e.display_chain_with_msg("Unable to save settings")),
diff --git a/mullvad-daemon/src/wireguard.rs b/mullvad-daemon/src/wireguard.rs
index 884c144113..4a0da9fdc8 100644
--- a/mullvad-daemon/src/wireguard.rs
+++ b/mullvad-daemon/src/wireguard.rs
@@ -137,26 +137,40 @@ impl KeyManager {
tokio_remote: Remote,
automatic_key_rotation: Option<u32>,
) -> Self {
- let remote_clone = tokio_remote.clone();
- let daemon_tx_clone = daemon_tx.clone();
+ let mut manager = Self {
+ daemon_tx,
+ http_handle,
+ tokio_remote,
+ current_job: None,
+ abort_scheduler_tx: None,
+ };
+ manager.update_rotation_interval(automatic_key_rotation);
+
+ manager
+ }
- let abort_scheduler_tx = match automatic_key_rotation {
+ /// Update automatic key rotation interval (given in hours)
+ /// Passing `None` will use the default value.
+ /// A value of `0` disables automatic key rotation.
+ pub fn update_rotation_interval(
+ &mut self,
+ automatic_key_rotation: Option<u32>,
+ ) {
+ log::debug!("update_rotation_interval");
+ if self.abort_scheduler_tx.is_some() {
+ // Stop existing scheduler, if one exists
+ let tx = self.abort_scheduler_tx.take().unwrap();
+ tx.send(());
+ }
+ self.abort_scheduler_tx = match automatic_key_rotation {
// Interval=0 disables automatic key rotation
Some(0) => None,
_ => KeyRotationScheduler::new(
- remote_clone,
- daemon_tx_clone,
+ self.tokio_remote.clone(),
+ self.daemon_tx.clone(),
automatic_key_rotation,
).ok(),
};
-
- Self {
- daemon_tx,
- http_handle,
- tokio_remote,
- current_job: None,
- abort_scheduler_tx,
- }
}
/// Stop current key generation