summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2022-01-19 13:33:29 +0100
committerDavid Lönnhager <david.l@mullvad.net>2022-03-14 12:08:49 +0100
commit55985af2f0944760b63c703242d02aa80d034ead (patch)
tree5baeddad8a64cbda121602111f4d2e68ef97720f /mullvad-daemon/src
parent4147be42fb83495e2035d232b2a4a36d926c1a9d (diff)
downloadmullvadvpn-55985af2f0944760b63c703242d02aa80d034ead.tar.xz
mullvadvpn-55985af2f0944760b63c703242d02aa80d034ead.zip
Only log out when setting device if id differs
Diffstat (limited to 'mullvad-daemon/src')
-rw-r--r--mullvad-daemon/src/device.rs33
1 files changed, 29 insertions, 4 deletions
diff --git a/mullvad-daemon/src/device.rs b/mullvad-daemon/src/device.rs
index 585855504d..bc5069929a 100644
--- a/mullvad-daemon/src/device.rs
+++ b/mullvad-daemon/src/device.rs
@@ -190,16 +190,41 @@ impl AccountManager {
}
pub async fn set(&mut self, data: DeviceData) -> Result<(), Error> {
- self.logout();
+ self.stop_key_rotation();
+
let (result_tx, result_rx) = oneshot::channel();
let _ = self
.cache_update_tx
.unbounded_send((Some(data.clone()), result_tx));
- {
+
+ let old_data = {
let mut inner = self.inner.lock().unwrap();
- inner.data.replace(data.clone());
+ inner.data.replace(data.clone())
+ };
+
+ if let Err(error) = flatten_result(result_rx.await.map_err(Error::DeviceUpdaterCancelled)) {
+ // Delete the device if an I/O error occurred
+ self.logout();
+ return Err(error);
+ }
+
+ if let Some(old_data) = old_data {
+ // Log out the previous device if the id differs
+ if !old_data.device.eq_id(&data.device) {
+ let service = self.device_service.clone();
+ tokio::spawn(async move {
+ if let Err(error) = service
+ .remove_device_with_backoff(old_data.token, old_data.device.id)
+ .await
+ {
+ log::error!(
+ "{}",
+ error.display_chain_with_msg("Failed to remove a previous device")
+ );
+ }
+ });
+ }
}
- result_rx.await.map_err(Error::DeviceUpdaterCancelled)??;
self.start_key_rotation();
Ok(())
}