diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-09-06 11:48:05 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-09-13 15:57:37 +0200 |
| commit | 9678aae7b73399e29ad33d8a28eb86a97ff1803f (patch) | |
| tree | 2a7c6b8abe71e2b14e481e38f7a5ec2ba46bd5b6 | |
| parent | 05b3e986871d5352a7031eb9a5c486e2eeaf0a31 (diff) | |
| download | mullvadvpn-9678aae7b73399e29ad33d8a28eb86a97ff1803f.tar.xz mullvadvpn-9678aae7b73399e29ad33d8a28eb86a97ff1803f.zip | |
Emit expiry event when account validity is checked
| -rw-r--r-- | mullvad-daemon/src/device/mod.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/mullvad-daemon/src/device/mod.rs b/mullvad-daemon/src/device/mod.rs index 22495bce9f..a27b3eb439 100644 --- a/mullvad-daemon/src/device/mod.rs +++ b/mullvad-daemon/src/device/mod.rs @@ -232,6 +232,8 @@ pub(crate) enum PrivateDeviceEvent { Updated(PrivateAccountAndDevice), /// The key was rotated. RotatedKey(PrivateAccountAndDevice), + /// Emitted when the account expiry is fetched. + AccountExpiry(DateTime<Utc>), } #[derive(err_derive::Error, Debug)] @@ -248,6 +250,7 @@ impl TryFrom<PrivateDeviceEvent> for DeviceEvent { PrivateDeviceEvent::Revoked => DeviceEventCause::Revoked, PrivateDeviceEvent::Updated(_) => DeviceEventCause::Updated, PrivateDeviceEvent::RotatedKey(_) => DeviceEventCause::RotatedKey, + PrivateDeviceEvent::AccountExpiry(_) => return Err(PrivateOnlyEvent), }; let new_state = DeviceState::from(event.state().ok_or(PrivateOnlyEvent)?); Ok(DeviceEvent { cause, new_state }) @@ -262,6 +265,7 @@ impl PrivateDeviceEvent { PrivateDeviceEvent::RotatedKey(config) => Some(PrivateDeviceState::LoggedIn(config)), PrivateDeviceEvent::Logout => Some(PrivateDeviceState::LoggedOut), PrivateDeviceEvent::Revoked => Some(PrivateDeviceState::Revoked), + PrivateDeviceEvent::AccountExpiry(_) => None, } } } @@ -604,6 +608,10 @@ impl AccountManager { async fn consume_expiry_result(&mut self, response: Result<DateTime<Utc>, Error>) { match response { Ok(expiry) => { + // Send expiry update event + let event = PrivateDeviceEvent::AccountExpiry(expiry); + self.listeners + .retain(|listener| listener.send(event.clone()).is_ok()); Self::drain_requests(&mut self.expiry_requests, || Ok(expiry)); } Err(Error::InvalidAccount) => { |
