summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src/lib.rs
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-09-19 13:43:53 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-10-09 14:40:06 +0200
commitfc477f4e4df6db2973ff88fc4b6819d38d64d8cc (patch)
tree069b709abb09599b37f32716de679298095bc1c1 /mullvad-daemon/src/lib.rs
parentbe5e93c32f3b3e9ec59da18215fad80457dd4d49 (diff)
downloadmullvadvpn-fc477f4e4df6db2973ff88fc4b6819d38d64d8cc.tar.xz
mullvadvpn-fc477f4e4df6db2973ff88fc4b6819d38d64d8cc.zip
Add `mullvad proxy use`
Allow for settings a specific Access Method to use
Diffstat (limited to 'mullvad-daemon/src/lib.rs')
-rw-r--r--mullvad-daemon/src/lib.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 8427b1ea6b..3c822fdf4e 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -65,7 +65,7 @@ use std::{
mem,
path::PathBuf,
pin::Pin,
- sync::{Arc, Weak},
+ sync::{Arc, Mutex, Weak},
time::Duration,
};
#[cfg(any(target_os = "linux", windows))]
@@ -273,6 +273,8 @@ pub enum DaemonCommand {
ReplaceApiAccessMethod(ResponseTx<(), Error>, ApiAccessMethodReplace),
/// Toggle the status of an API access method
ToggleApiAccessMethod(ResponseTx<(), Error>, ApiAccessMethodToggle),
+ /// Set the API access method to use
+ SetApiAccessMethod(ResponseTx<(), Error>, AccessMethod),
/// Get information about the currently running and latest app versions
GetVersionInfo(oneshot::Sender<Option<AppVersionInfo>>),
/// Return whether the daemon is performing post-upgrade tasks
@@ -572,6 +574,7 @@ pub struct Daemon<L: EventListener> {
account_history: account_history::AccountHistory,
device_checker: device::TunnelStateChangeHandler,
account_manager: device::AccountManagerHandle,
+ connection_modes: Arc<Mutex<api::ConnectionModesIterator>>,
api_runtime: mullvad_api::Runtime,
api_handle: mullvad_api::rest::MullvadRestHandle,
version_updater_handle: version_check::VersionUpdaterHandle,
@@ -634,8 +637,15 @@ where
let initial_selector_config = new_selector_config(&settings);
let relay_selector = RelaySelector::new(initial_selector_config, &resource_dir, &cache_dir);
- let proxy_provider =
- api::ApiConnectionModeProvider::new(cache_dir.clone(), relay_selector.clone());
+ // TODO: Should ApiConnectionModeProvider be an Actor instead of sharing a datastructure-behind-locks with the daemon with the daemon?
+ let proxy_provider = api::ApiConnectionModeProvider::new(
+ cache_dir.clone(),
+ relay_selector.clone(),
+ settings.api_access_methods.api_access_methods.clone(),
+ );
+
+ let connection_modes = proxy_provider.handle();
+
let api_handle = api_runtime
.mullvad_rest_handle(proxy_provider, endpoint_updater.callback())
.await;
@@ -772,6 +782,7 @@ where
account_history,
device_checker: device::TunnelStateChangeHandler::new(account_manager.clone()),
account_manager,
+ connection_modes,
api_runtime,
api_handle,
version_updater_handle,
@@ -1055,6 +1066,7 @@ where
self.on_replace_api_access_method(tx, method).await
}
ToggleApiAccessMethod(tx, method) => self.on_toggle_api_access_method(tx, method).await,
+ SetApiAccessMethod(tx, method) => self.on_set_api_access_method(tx, method).await,
IsPerformingPostUpgrade(tx) => self.on_is_performing_post_upgrade(tx),
GetCurrentVersion(tx) => self.on_get_current_version(tx),
#[cfg(not(target_os = "android"))]
@@ -2275,7 +2287,15 @@ where
.toggle_api_access_method(method)
.await
.map_err(Error::AccessMethodError);
- Self::oneshot_send(tx, result, "edit_api_access_method response");
+ Self::oneshot_send(tx, result, "toggle_api_access_method response");
+ }
+
+ async fn on_set_api_access_method(&mut self, tx: ResponseTx<(), Error>, method: AccessMethod) {
+ let result = self
+ .set_api_access_method(method)
+ .await
+ .map_err(Error::AccessMethodError);
+ Self::oneshot_send(tx, result, "set_api_access_method response");
}
fn on_get_settings(&self, tx: oneshot::Sender<Settings>) {