diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-01-20 17:29:52 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-01-22 13:09:15 +0100 |
| commit | a013f4aaf542d7caa3240d4e30c5f8e5976bdb03 (patch) | |
| tree | 09d98150661bcf42d7eb8b86bdb74c3ab26d0293 | |
| parent | 53cc20e5710307db90e9ca64b0e2912019f90627 (diff) | |
| download | mullvadvpn-a013f4aaf542d7caa3240d4e30c5f8e5976bdb03.tar.xz mullvadvpn-a013f4aaf542d7caa3240d4e30c5f8e5976bdb03.zip | |
Start without version cache instead of using incorrect defaults
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 8 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 5 | ||||
| -rw-r--r-- | mullvad-daemon/src/version_check.rs | 27 | ||||
| -rw-r--r-- | mullvad-jni/src/daemon_interface.rs | 4 |
4 files changed, 24 insertions, 20 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index ae76b2eafa..2c943296aa 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -208,7 +208,7 @@ pub enum DaemonCommand { /// Verify if the currently set wireguard key is valid. VerifyWireguardKey(oneshot::Sender<bool>), /// Get information about the currently running and latest app versions - GetVersionInfo(oneshot::Sender<AppVersionInfo>), + GetVersionInfo(oneshot::Sender<Option<AppVersionInfo>>), /// Get current version of the app GetCurrentVersion(oneshot::Sender<AppVersion>), /// Remove settings and clear the cache @@ -467,7 +467,7 @@ pub struct Daemon<L: EventListener> { relay_selector: relays::RelaySelector, last_generated_relay: Option<Relay>, last_generated_bridge_relay: Option<Relay>, - app_version_info: AppVersionInfo, + app_version_info: Option<AppVersionInfo>, shutdown_callbacks: Vec<Box<dyn FnOnce()>>, /// oneshot channel that completes once the tunnel state machine has been shut down tunnel_state_machine_shutdown_signal: oneshot::Receiver<()>, @@ -1221,7 +1221,7 @@ where } fn handle_new_app_version_info(&mut self, app_version_info: AppVersionInfo) { - self.app_version_info = app_version_info.clone(); + self.app_version_info = Some(app_version_info.clone()); self.event_listener.notify_app_version(app_version_info); } @@ -1468,7 +1468,7 @@ where } } - fn on_get_version_info(&mut self, tx: oneshot::Sender<AppVersionInfo>) { + fn on_get_version_info(&mut self, tx: oneshot::Sender<Option<AppVersionInfo>>) { Self::oneshot_send( tx, self.app_version_info.clone(), diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 4fe5b3aee1..ccde44ba8f 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -150,8 +150,9 @@ impl ManagementService for ManagementServiceImpl { let (tx, rx) = oneshot::channel(); self.send_command_to_daemon(DaemonCommand::GetVersionInfo(tx))?; - rx.await - .map_err(|_| Status::internal("internal error")) + let version_info = rx.await.map_err(|_| Status::internal("internal error"))?; + version_info + .ok_or(Status::not_found("no version cache")) .map(|version_info| convert_version_info(&version_info)) .map(Response::new) } diff --git a/mullvad-daemon/src/version_check.rs b/mullvad-daemon/src/version_check.rs index 8f52f5694a..340ea24600 100644 --- a/mullvad-daemon/src/version_check.rs +++ b/mullvad-daemon/src/version_check.rs @@ -85,7 +85,7 @@ pub(crate) struct VersionUpdater { version_proxy: AppVersionProxy, cache_path: PathBuf, update_sender: DaemonEventSender<AppVersionInfo>, - last_app_version_info: AppVersionInfo, + last_app_version_info: Option<AppVersionInfo>, platform_version: String, next_update_time: Instant, show_beta_releases: bool, @@ -110,7 +110,7 @@ impl VersionUpdater { mut rpc_handle: MullvadRestHandle, cache_dir: PathBuf, update_sender: DaemonEventSender<AppVersionInfo>, - last_app_version_info: AppVersionInfo, + last_app_version_info: Option<AppVersionInfo>, show_beta_releases: bool, ) -> (Self, VersionUpdaterHandle) { rpc_handle.factory.timeout = DOWNLOAD_TIMEOUT; @@ -158,6 +158,13 @@ impl VersionUpdater { } async fn write_cache(&self) -> Result<(), Error> { + let last_app_version_info = match self.last_app_version_info.as_ref() { + Some(version_info) => version_info, + None => { + log::debug!("The version cache is empty -- not writing"); + return Ok(()); + } + }; log::debug!( "Writing version check cache to {}", self.cache_path.display() @@ -165,7 +172,7 @@ impl VersionUpdater { let mut file = File::create(&self.cache_path) .await .map_err(Error::WriteVersionCache)?; - let cached_app_version = CachedAppVersionInfo::from(self.last_app_version_info.clone()); + let cached_app_version = CachedAppVersionInfo::from(last_app_version_info.clone()); let mut buf = serde_json::to_vec_pretty(&cached_app_version).map_err(Error::Serialize)?; let mut read_buf: &[u8] = buf.as_mut(); @@ -277,7 +284,7 @@ impl VersionUpdater { return; } - self.last_app_version_info = new_version_info; + self.last_app_version_info = Some(new_version_info); if let Err(err) = self.write_cache().await { log::error!("Failed to save version cache to disk: {}", err); @@ -309,21 +316,15 @@ fn try_load_cache(cache_dir: &Path) -> Result<AppVersionInfo, Error> { } } -pub fn load_cache(cache_dir: &Path) -> AppVersionInfo { +pub fn load_cache(cache_dir: &Path) -> Option<AppVersionInfo> { match try_load_cache(cache_dir) { - Ok(app_version_info) => app_version_info, + Ok(app_version_info) => Some(app_version_info), Err(error) => { log::warn!( "{}", error.display_chain_with_msg("Unable to load cached version info") ); - // If we don't have a cache, start out with sane defaults. - AppVersionInfo { - supported: !*IS_DEV_BUILD, - latest_stable: PRODUCT_VERSION.to_owned(), - latest_beta: PRODUCT_VERSION.to_owned(), - suggested_upgrade: None, - } + None } } } diff --git a/mullvad-jni/src/daemon_interface.rs b/mullvad-jni/src/daemon_interface.rs index d3ab959b33..4b54ca4c58 100644 --- a/mullvad-jni/src/daemon_interface.rs +++ b/mullvad-jni/src/daemon_interface.rs @@ -144,7 +144,9 @@ impl DaemonInterface { self.send_command(DaemonCommand::GetVersionInfo(tx))?; - block_on(rx).map_err(|_| Error::NoResponse) + block_on(rx) + .map_err(|_| Error::NoResponse)? + .ok_or(Error::NoResponse) } pub fn reconnect(&self) -> Result<()> { |
