summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/src/main.rs26
-rw-r--r--mullvad-daemon/src/settings.rs6
2 files changed, 24 insertions, 8 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index dfce02606b..dd35239d91 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -262,7 +262,7 @@ impl Daemon {
match event {
SetTargetState(state) => self.on_set_target_state(state),
GetState(tx) => Ok(self.on_get_state(tx)),
- SetAccount(tx, account_token) => Ok(self.on_set_account(tx, account_token)),
+ SetAccount(tx, account_token) => self.on_set_account(tx, account_token),
GetAccount(tx) => Ok(self.on_get_account(tx)),
}
}
@@ -282,15 +282,29 @@ impl Daemon {
}
}
- fn on_set_account(&mut self, tx: sync::oneshot::Sender<()>, account_token: Option<String>) {
- let save_result = self.settings.set_account_token(account_token.clone());
+ fn on_set_account(&mut self,
+ tx: sync::oneshot::Sender<()>,
+ account_token: Option<String>)
+ -> Result<()> {
+
+ let save_result = self.settings.set_account_token(account_token);
match save_result.chain_err(|| "Unable to save settings") {
- Ok(()) => if let Err(_) = tx.send(()) {
- warn!("Unable to send response to management interface client");
- },
+ Ok(account_changed) => {
+ if let Err(_) = tx.send(()) {
+ warn!("Unable to send response to management interface client");
+ }
+
+ let tunnel_needs_restart = self.state == TunnelState::Connecting ||
+ self.state == TunnelState::Connected;
+ if account_changed && tunnel_needs_restart {
+ info!("Initiating tunnel restart because the account token changed");
+ self.kill_tunnel()?;
+ }
+ }
Err(e) => error!("{}", e.display()),
}
+ Ok(())
}
fn on_get_account(&self, tx: sync::oneshot::Sender<Option<String>>) {
diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs
index 229ccd9709..d2d652adf0 100644
--- a/mullvad-daemon/src/settings.rs
+++ b/mullvad-daemon/src/settings.rs
@@ -89,7 +89,8 @@ impl Settings {
}
/// Changes account number to the one given. Also saves the new settings to disk.
- pub fn set_account_token(&mut self, account_token: Option<String>) -> Result<()> {
+ /// The boolean in the Result indicates if the account token changed or not
+ pub fn set_account_token(&mut self, account_token: Option<String>) -> Result<bool> {
if account_token != self.account_token {
info!(
"Changing account token from {} to {}",
@@ -98,8 +99,9 @@ impl Settings {
);
self.account_token = account_token;
self.save()
+ .map(|_| true)
} else {
- Ok(())
+ Ok(false)
}
}