summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2024-04-17 22:57:39 +0200
committerDavid Lönnhager <david.l@mullvad.net>2024-04-23 15:31:47 +0200
commitb0f5b60658fb723f224517b4232e3928fe7fe006 (patch)
tree8d13bcd8b6f3658396f2c1b5150d3ff9ba5593db /mullvad-daemon/src
parent0329c9e1c813da258f09d435809f3c7ce0f6293f (diff)
downloadmullvadvpn-b0f5b60658fb723f224517b4232e3928fe7fe006.tar.xz
mullvadvpn-b0f5b60658fb723f224517b4232e3928fe7fe006.zip
Remove pointless round trip for version check
Diffstat (limited to 'mullvad-daemon/src')
-rw-r--r--mullvad-daemon/src/lib.rs3
-rw-r--r--mullvad-daemon/src/version_check.rs59
2 files changed, 29 insertions, 33 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 52df09e6d5..2043936845 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -857,7 +857,7 @@ where
on_relay_list_update,
);
- let (version_updater, version_updater_handle) = version_check::VersionUpdater::new(
+ let version_updater_handle = version_check::VersionUpdater::spawn(
api_handle.clone(),
api_availability.clone(),
cache_dir.clone(),
@@ -865,7 +865,6 @@ where
settings.show_beta_releases,
)
.await;
- tokio::spawn(version_updater.run());
// Attempt to download a fresh relay list
relay_list_updater.update().await;
diff --git a/mullvad-daemon/src/version_check.rs b/mullvad-daemon/src/version_check.rs
index 91d34074d2..97492b3734 100644
--- a/mullvad-daemon/src/version_check.rs
+++ b/mullvad-daemon/src/version_check.rs
@@ -2,7 +2,6 @@ use crate::{version::is_beta_version, DaemonEventSender};
use futures::{
channel::{mpsc, oneshot},
future::FusedFuture,
- stream::FusedStream,
FutureExt, SinkExt, StreamExt, TryFutureExt,
};
use mullvad_api::{availability::ApiAvailabilityHandle, rest::MullvadRestHandle, AppVersionProxy};
@@ -101,7 +100,6 @@ pub(crate) struct VersionUpdater {
last_app_version_info: Option<(AppVersionInfo, SystemTime)>,
platform_version: String,
show_beta_releases: bool,
- rx: Option<mpsc::Receiver<VersionUpdaterCommand>>,
availability_handle: ApiAvailabilityHandle,
/// Oneshot channels for responding to [VersionUpdaterCommand::GetVersionInfo].
@@ -152,13 +150,13 @@ impl VersionUpdaterHandle {
}
impl VersionUpdater {
- pub async fn new(
+ pub async fn spawn(
mut api_handle: MullvadRestHandle,
availability_handle: ApiAvailabilityHandle,
cache_dir: PathBuf,
update_sender: DaemonEventSender<AppVersionInfo>,
show_beta_releases: bool,
- ) -> (Self, VersionUpdaterHandle) {
+ ) -> VersionUpdaterHandle {
// load the last known AppVersionInfo from cache
let last_app_version_info = load_cache(&cache_dir).await;
@@ -168,7 +166,7 @@ impl VersionUpdater {
let (tx, rx) = mpsc::channel(1);
let platform_version = talpid_platform_metadata::short_version();
- (
+ tokio::spawn(
Self {
version_proxy,
cache_path,
@@ -176,12 +174,13 @@ impl VersionUpdater {
last_app_version_info,
platform_version,
show_beta_releases,
- rx: Some(rx),
availability_handle,
get_version_info_responders: vec![],
- },
- VersionUpdaterHandle { tx },
- )
+ }
+ .run(rx),
+ );
+
+ VersionUpdaterHandle { tx }
}
/// Get the last known [AppVersionInfo]. May be stale.
@@ -382,11 +381,7 @@ impl VersionUpdater {
!self.get_version_info_responders.is_empty()
}
- pub async fn run(mut self) {
- let mut rx = self.rx.take().unwrap();
- let mut version_is_stale = self.wait_until_version_is_stale();
- let mut version_check = futures::future::Fuse::terminated();
-
+ async fn run(mut self, mut rx: mpsc::Receiver<VersionUpdaterCommand>) {
// If this is a dev build, there's no need to pester the API for version checks.
if *IS_DEV_BUILD {
log::warn!("Not checking for updates because this is a development build");
@@ -399,6 +394,9 @@ impl VersionUpdater {
return;
}
+ let mut version_is_stale = self.wait_until_version_is_stale();
+ let mut version_check = futures::future::Fuse::terminated();
+
loop {
futures::select! {
command = rx.next() => match command {
@@ -482,6 +480,22 @@ impl VersionUpdater {
}
}
+/// Read the app version cache from the provided directory.
+///
+/// Returns the [AppVersionInfo] along with the modification time of the cache file,
+/// or `None` on any error.
+async fn load_cache(cache_dir: &Path) -> Option<(AppVersionInfo, SystemTime)> {
+ try_load_cache(cache_dir)
+ .await
+ .inspect_err(|error| {
+ log::warn!(
+ "{}",
+ error.display_chain_with_msg("Unable to load cached version info")
+ )
+ })
+ .ok()
+}
+
async fn try_load_cache(cache_dir: &Path) -> Result<(AppVersionInfo, SystemTime), Error> {
if *IS_DEV_BUILD {
return Ok((dev_version_cache(), SystemTime::now()));
@@ -511,23 +525,6 @@ async fn try_load_cache(cache_dir: &Path) -> Result<(AppVersionInfo, SystemTime)
}
}
-/// Read the app version cache from the provided directory.
-///
-/// Returns the [AppVersionInfo] along with the modification time of the cache file,
-/// or `None` on any error.
-async fn load_cache(cache_dir: &Path) -> Option<(AppVersionInfo, SystemTime)> {
- match try_load_cache(cache_dir).await {
- Ok(app_version_info) => Some(app_version_info),
- Err(error) => {
- log::warn!(
- "{}",
- error.display_chain_with_msg("Unable to load cached version info")
- );
- None
- }
- }
-}
-
fn dev_version_cache() -> AppVersionInfo {
assert!(*IS_DEV_BUILD);