diff options
| author | David Lönnhager <david.l@mullvad.net> | 2025-02-17 21:16:30 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-03-05 23:32:08 +0100 |
| commit | 1281dd790d376a0a04c38cf26c4ad5bc3bbc49db (patch) | |
| tree | 921f0c413359aef00e99bc07456ccc6902b37e2a | |
| parent | ee2858eb52d8e3fb28f8e994c3c4fb9d6f8ea2ae (diff) | |
| download | mullvadvpn-1281dd790d376a0a04c38cf26c4ad5bc3bbc49db.tar.xz mullvadvpn-1281dd790d376a0a04c38cf26c4ad5bc3bbc49db.zip | |
Select random mirror for downloading
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | installer-downloader/Cargo.toml | 1 | ||||
| -rw-r--r-- | installer-downloader/src/controller.rs | 10 |
3 files changed, 10 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock index e9d1acf67a..888450184f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2130,6 +2130,7 @@ dependencies = [ "native-windows-gui", "nsvg", "objc_id", + "rand 0.8.5", "serde", "tokio", "windows-sys 0.52.0", diff --git a/installer-downloader/Cargo.toml b/installer-downloader/Cargo.toml index 79c7066074..029a10dcbb 100644 --- a/installer-downloader/Cargo.toml +++ b/installer-downloader/Cargo.toml @@ -19,6 +19,7 @@ windows-sys = { version = "0.52.0", features = ["Win32_System", "Win32_System_Li anyhow = "1.0" tokio = { version = "1", features = ["full"] } async-trait = "0.1" +rand = { version = "0.8.5" } serde = { workspace = true, features = ["derive"] } mullvad-update = { path = "../mullvad-update" } diff --git a/installer-downloader/src/controller.rs b/installer-downloader/src/controller.rs index 09860ec56c..103f06a3f5 100644 --- a/installer-downloader/src/controller.rs +++ b/installer-downloader/src/controller.rs @@ -9,6 +9,7 @@ use mullvad_update::{ app::{self, AppDownloader}, version::{Version, VersionArchitecture, VersionInfo, VersionParameters}, }; +use rand::seq::SliceRandom; use std::future::Future; use std::path::PathBuf; @@ -313,8 +314,7 @@ async fn handle_action_messages<D, A, DirProvider>( } }; - // TODO: Select appropriate URLs - let Some(app_url) = selected_version.urls.first() else { + let Some(app_url) = select_cdn_url(&selected_version.urls) else { return; }; let app_version = selected_version.version.clone(); @@ -386,6 +386,12 @@ async fn handle_action_messages<D, A, DirProvider>( } } +/// Select a mirror to download from +/// Currently, the selection is random +fn select_cdn_url(urls: &[String]) -> Option<&str> { + urls.choose(&mut rand::thread_rng()).map(String::as_str) +} + fn format_latest_version(version: &Version) -> String { format!("{}: {}", resource::LATEST_VERSION_PREFIX, version.version) } |
