diff options
Diffstat (limited to 'mullvad-daemon/src/access_methods.rs')
| -rw-r--r-- | mullvad-daemon/src/access_methods.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/mullvad-daemon/src/access_methods.rs b/mullvad-daemon/src/access_methods.rs index 79afdae054..a0c168c026 100644 --- a/mullvad-daemon/src/access_methods.rs +++ b/mullvad-daemon/src/access_methods.rs @@ -86,22 +86,29 @@ where .map_err(Error::Settings) } + pub async fn set_api_access_method( + &mut self, + access_method: AccessMethod, + ) -> Result<(), Error> { + { + let mut connection_modes = self.connection_modes.lock().unwrap(); + connection_modes.set_access_method(access_method); + } + // Force a rotation of Acces Methods. + let _ = self.api_handle.service().next_api_endpoint(); + Ok(()) + } + /// If settings were changed due to an update, notify all listeners. fn notify_on_change(&mut self, settings_changed: MadeChanges) { if settings_changed { self.event_listener .notify_settings(self.settings.to_settings()); - }; - // TODO: Could this be replaced by message passing? Yes plz. - let mut connection_modes = self.connection_modes.lock().unwrap(); - *connection_modes = self - .settings - .api_access_methods - .api_access_methods - .clone() - .into_iter() - .map(|x| (x, 1)) - .collect(); + // TODO: Could this be replaced by message passing? Yes plz. + let mut connection_modes = self.connection_modes.lock().unwrap(); + connection_modes + .update_access_methods(self.settings.api_access_methods.api_access_methods.clone()) + }; } } |
