summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2019-12-09 09:54:50 +0100
committerDavid Lönnhager <david.l@mullvad.net>2019-12-17 12:30:15 +0100
commit25e397a44c2ffdb1a604f49f0c6945621320d25c (patch)
tree1fa5a74a0104397ea6a7639aba6e6c3af7f3c267
parentdf1841dbc0909a63ed053ebdeddd8f44fdfe943f (diff)
downloadmullvadvpn-25e397a44c2ffdb1a604f49f0c6945621320d25c.tar.xz
mullvadvpn-25e397a44c2ffdb1a604f49f0c6945621320d25c.zip
Improve error handling
-rw-r--r--mullvad-daemon/src/wireguard.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/mullvad-daemon/src/wireguard.rs b/mullvad-daemon/src/wireguard.rs
index 2dd1051dad..3961a1d586 100644
--- a/mullvad-daemon/src/wireguard.rs
+++ b/mullvad-daemon/src/wireguard.rs
@@ -31,6 +31,10 @@ pub enum Error {
TooManyKeys,
#[error(display = "Failed to create Delay object")]
Delay,
+ #[error(display = "Failed to create key rotation scheduler")]
+ CreateAutomaticKeyRotationScheduler,
+ #[error(display = "Failed to run automatic key rotation")]
+ RunAutomaticKeyRotation,
}
pub type Result<T> = std::result::Result<T, Error>;
@@ -62,12 +66,14 @@ impl Future for KeyRotationScheduler {
let _ = self.daemon_tx.send(InternalDaemonEvent::ManagementInterfaceEvent(
ManagementCommand::GenerateWireguardKey(wg_tx)
- )).map_err(|_| Error::Delay)?;
+ ))
+ .map_err(|_| Error::RunAutomaticKeyRotation)?;
+ log::info!("!!! Sending message DONE");
+
+ // TODO: replace with configurable interval
let somedelay = Instant::now() + Duration::from_secs(30);
- self.delay = Some(Box::new(Delay::new(somedelay)
- .map_err(|_| ())
- ));
+ self.delay = Some(Box::new(Delay::new(somedelay).map_err(|_| ())));
return self.delay
.as_mut()
.unwrap()
@@ -100,10 +106,16 @@ impl KeyRotationScheduler {
};
tokio_remote.execute(
- fut.map_err(|_| {
- log::error!("Failed to run key rotation scheduler")
- }) // FIXME: err
- ); // FIXME: select terminate rx
+ fut.map_err(|e| {
+ log::error!("Failed to run key rotation scheduler: {}", e)
+ })
+ .select(terminate_auto_rotation_rx.map_err(|_| ()))
+ .map_err(|_| ())
+ .map(|_| ())
+ ).map_err(|e| {
+ log::error!("Failed to run key rotation scheduler: {:?}", e);
+ Error::CreateAutomaticKeyRotationScheduler
+ })?;
Ok(terminate_auto_rotation_tx)
}