diff options
| author | David Lönnhager <david.l@mullvad.net> | 2019-12-09 18:12:12 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2019-12-17 12:30:15 +0100 |
| commit | 31b9cb9fed4e214c9e95f41f840ef68e136e401c (patch) | |
| tree | 6a7457da9eb202ea0b3afa56598b2ff948c641a6 | |
| parent | f5dc93c3fc2e015470681c75c0a6d11c2c0190ef (diff) | |
| download | mullvadvpn-31b9cb9fed4e214c9e95f41f840ef68e136e401c.tar.xz mullvadvpn-31b9cb9fed4e214c9e95f41f840ef68e136e401c.zip | |
Update key rotation scheduler when the interval is changed
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/wireguard.rs | 40 |
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 |
