diff options
| author | Sebastian Holmin <sebastian.holmin@mullvad.net> | 2025-02-10 10:55:30 +0100 |
|---|---|---|
| committer | Sebastian Holmin <sebastian.holmin@mullvad.net> | 2025-02-12 10:15:26 +0100 |
| commit | b083dbefa0676d4e67ad890667943995a3d7e4c4 (patch) | |
| tree | ddcb825e6f0b508827e1b3d3c17705d07b74b2ca | |
| parent | 1bd9eabf1d3b604e7f322e835a73c07c264b050c (diff) | |
| download | mullvadvpn-b083dbefa0676d4e67ad890667943995a3d7e4c4.tar.xz mullvadvpn-b083dbefa0676d4e67ad890667943995a3d7e4c4.zip | |
Fix `clippy::precedence`
29 files changed, 191 insertions, 173 deletions
diff --git a/mullvad-daemon/src/access_method.rs b/mullvad-daemon/src/access_method.rs index 94f126a115..a5980ec596 100644 --- a/mullvad-daemon/src/access_method.rs +++ b/mullvad-daemon/src/access_method.rs @@ -1,5 +1,5 @@ -use crate::{api, settings, Daemon}; -use mullvad_api::{proxy::ApiConnectionMode, rest, ApiProxy}; +use crate::{Daemon, api, settings}; +use mullvad_api::{ApiProxy, proxy::ApiConnectionMode, rest}; use mullvad_types::{ access_method::{self, AccessMethod, AccessMethodSetting}, settings::Settings, diff --git a/mullvad-daemon/src/android_dns.rs b/mullvad-daemon/src/android_dns.rs index 5cbc9c271a..8409edd6e3 100644 --- a/mullvad-daemon/src/android_dns.rs +++ b/mullvad-daemon/src/android_dns.rs @@ -3,8 +3,8 @@ use async_trait::async_trait; use hickory_resolver::{ - config::{NameServerConfigGroup, ResolverConfig, ResolverOpts}, TokioAsyncResolver, + config::{NameServerConfigGroup, ResolverConfig, ResolverOpts}, }; use mullvad_api::DnsResolver; use std::{io, net::SocketAddr}; diff --git a/mullvad-daemon/src/api.rs b/mullvad-daemon/src/api.rs index 97799d244e..b37c628281 100644 --- a/mullvad-daemon/src/api.rs +++ b/mullvad-daemon/src/api.rs @@ -7,15 +7,15 @@ use crate::DaemonCommand; use crate::DaemonEventSender; use futures::{ - channel::{mpsc, oneshot}, StreamExt, + channel::{mpsc, oneshot}, }; #[cfg(feature = "api-override")] use mullvad_api::ApiEndpoint; use mullvad_api::{ + AddressCache, availability::ApiAvailability, proxy::{ApiConnectionMode, ConnectionModeProvider, ProxyConfig}, - AddressCache, }; use mullvad_encrypted_dns_proxy::state::EncryptedDnsProxyState; use mullvad_relay_selector::RelaySelector; @@ -25,7 +25,7 @@ use mullvad_types::access_method::{ use std::{net::SocketAddr, path::PathBuf}; use talpid_core::mpsc::Sender; use talpid_types::net::{ - proxy::CustomProxy, AllowedClients, AllowedEndpoint, Connectivity, Endpoint, TransportProtocol, + AllowedClients, AllowedEndpoint, Connectivity, Endpoint, TransportProtocol, proxy::CustomProxy, }; pub enum Message { @@ -344,7 +344,9 @@ impl AccessModeSelector { match execution { Ok(_) => (), Err(error) if error.is_critical_error() => { - log::error!("AccessModeSelector failed due to an internal error and won't be able to recover without a restart. {error}"); + log::error!( + "AccessModeSelector failed due to an internal error and won't be able to recover without a restart. {error}" + ); break; } Err(error) => { diff --git a/mullvad-daemon/src/api_address_updater.rs b/mullvad-daemon/src/api_address_updater.rs index de347daccb..d020038fca 100644 --- a/mullvad-daemon/src/api_address_updater.rs +++ b/mullvad-daemon/src/api_address_updater.rs @@ -2,7 +2,7 @@ //! Mullvad API. #[cfg(feature = "api-override")] use mullvad_api::ApiEndpoint; -use mullvad_api::{rest::MullvadRestHandle, AddressCache, ApiProxy}; +use mullvad_api::{AddressCache, ApiProxy, rest::MullvadRestHandle}; use std::time::Duration; const API_IP_CHECK_INITIAL: Duration = Duration::from_secs(15 * 60); diff --git a/mullvad-daemon/src/device/api.rs b/mullvad-daemon/src/device/api.rs index f333142308..93cfba8851 100644 --- a/mullvad-daemon/src/device/api.rs +++ b/mullvad-daemon/src/device/api.rs @@ -1,7 +1,7 @@ use std::pin::Pin; use chrono::{DateTime, Utc}; -use futures::{future::FusedFuture, Future}; +use futures::{Future, future::FusedFuture}; #[cfg(target_os = "android")] use mullvad_types::account::PlayPurchasePaymentToken; use mullvad_types::{account::VoucherSubmission, device::Device, wireguard::WireguardData}; @@ -151,27 +151,22 @@ impl futures::Future for Call { ) -> std::task::Poll<Self::Output> { use Call::*; match &mut *self { - Login(call, tx) => { - match Pin::new(call).poll(cx) { std::task::Poll::Ready(response) => { + Login(call, tx) => match Pin::new(call).poll(cx) { + std::task::Poll::Ready(response) => { std::task::Poll::Ready(ApiResult::Login(response, tx.take().unwrap())) - } _ => { - std::task::Poll::Pending - }} - } + } + _ => std::task::Poll::Pending, + }, TimerKeyRotation(call) | OneshotKeyRotation(call) => { Pin::new(call).poll(cx).map(ApiResult::Rotation) } Validation(call) => Pin::new(call).poll(cx).map(ApiResult::Validation), - VoucherSubmission(call, tx) => { - match Pin::new(call).poll(cx) { std::task::Poll::Ready(response) => { - std::task::Poll::Ready(ApiResult::VoucherSubmission( - response, - tx.take().unwrap(), - )) - } _ => { - std::task::Poll::Pending - }} - } + VoucherSubmission(call, tx) => match Pin::new(call).poll(cx) { + std::task::Poll::Ready(response) => std::task::Poll::Ready( + ApiResult::VoucherSubmission(response, tx.take().unwrap()), + ), + _ => std::task::Poll::Pending, + }, #[cfg(target_os = "android")] InitPlayPurchase(call, tx) => { if let std::task::Poll::Ready(response) = Pin::new(call).poll(cx) { diff --git a/mullvad-daemon/src/device/mod.rs b/mullvad-daemon/src/device/mod.rs index 80f6243ac8..7b0649a4d9 100644 --- a/mullvad-daemon/src/device/mod.rs +++ b/mullvad-daemon/src/device/mod.rs @@ -19,16 +19,16 @@ use std::{ future::Future, path::Path, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, time::{Duration, SystemTime}, }; use talpid_core::mpsc::Sender; use talpid_types::{ + ErrorExt, net::{TunnelEndpoint, TunnelType}, tunnel::TunnelStateTransition, - ErrorExt, }; use tokio::{ fs, @@ -1002,20 +1002,26 @@ impl AccountManager { .is_ok() }); - match old_config { Some(old_config) => { - let logout_call = tokio::spawn(Box::pin(self.logout_api_call(old_config))); + match old_config { + Some(old_config) => { + let logout_call = tokio::spawn(Box::pin(self.logout_api_call(old_config))); - tokio::spawn(async move { - let _response = tokio::time::timeout(LOGOUT_TIMEOUT, logout_call).await; + tokio::spawn(async move { + let _response = tokio::time::timeout(LOGOUT_TIMEOUT, logout_call).await; + let _ = tx.send(Ok(())); + }); + } + _ => { + // The state was `revoked`. let _ = tx.send(Ok(())); - }); - } _ => { - // The state was `revoked`. - let _ = tx.send(Ok(())); - }} + } + } } - fn logout_api_call(&self, data: PrivateAccountAndDevice) -> impl Future<Output = ()> + 'static + use<> { + fn logout_api_call( + &self, + data: PrivateAccountAndDevice, + ) -> impl Future<Output = ()> + 'static + use<> { let service = self.device_service.clone(); async move { @@ -1067,7 +1073,10 @@ impl AccountManager { }) } - fn key_rotation_timer(&self, key_created: DateTime<Utc>) -> impl Future<Output = ()> + 'static + use<> { + fn key_rotation_timer( + &self, + key_created: DateTime<Utc>, + ) -> impl Future<Output = ()> + 'static + use<> { let rotation_interval = self.rotation_interval; async move { @@ -1104,7 +1113,9 @@ impl AccountManager { async move { device_service.get(account_number, device_id).await } } - fn validation_call(&self) -> Result<impl Future<Output = Result<Device, Error>> + use<>, Error> { + fn validation_call( + &self, + ) -> Result<impl Future<Output = Result<Device, Error>> + use<>, Error> { let old_config = self.data.device().ok_or(Error::NoDevice)?; Ok(self.fetch_device_config(old_config)) } @@ -1374,8 +1385,8 @@ impl TunnelStateChangeHandler { #[cfg(test)] mod test { use std::sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }; use talpid_types::tunnel::TunnelStateTransition; diff --git a/mullvad-daemon/src/device/service.rs b/mullvad-daemon/src/device/service.rs index 3ebecf0483..32dc1bb4e1 100644 --- a/mullvad-daemon/src/device/service.rs +++ b/mullvad-daemon/src/device/service.rs @@ -1,7 +1,7 @@ use std::{future::Future, time::Duration}; use chrono::Utc; -use futures::future::{abortable, AbortHandle}; +use futures::future::{AbortHandle, abortable}; #[cfg(target_os = "android")] use mullvad_types::account::{PlayPurchase, PlayPurchasePaymentToken}; use mullvad_types::{ @@ -13,11 +13,11 @@ use talpid_types::net::wireguard::PrivateKey; use super::{Error, PrivateAccountAndDevice, PrivateDevice}; use mullvad_api::{ + AccountsProxy, DevicesProxy, availability::ApiAvailability, rest::{self, MullvadRestHandle}, - AccountsProxy, DevicesProxy, }; -use talpid_future::retry::{retry_future, ConstantInterval, ExponentialBackoff, Jittered}; +use talpid_future::retry::{ConstantInterval, ExponentialBackoff, Jittered, retry_future}; /// Retry strategy used for user-initiated actions that require immediate feedback const RETRY_ACTION_STRATEGY: ConstantInterval = ConstantInterval::new(Duration::ZERO, Some(3)); /// Retry strategy used for background tasks diff --git a/mullvad-daemon/src/exception_logging/unix.rs b/mullvad-daemon/src/exception_logging/unix.rs index b956db8319..7b8940b984 100644 --- a/mullvad-daemon/src/exception_logging/unix.rs +++ b/mullvad-daemon/src/exception_logging/unix.rs @@ -2,17 +2,17 @@ #![warn(clippy::undocumented_unsafe_blocks)] use libc::siginfo_t; -use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal}; +use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction}; use core::fmt; use std::{ backtrace::Backtrace, env, - ffi::{c_int, c_void, CString}, + ffi::{CString, c_int, c_void}, os::fd::{FromRawFd, RawFd}, sync::{ - atomic::{AtomicBool, Ordering}, Once, OnceLock, + atomic::{AtomicBool, Ordering}, }, }; diff --git a/mullvad-daemon/src/exception_logging/win.rs b/mullvad-daemon/src/exception_logging/win.rs index 3fa50aa506..9687de8db9 100644 --- a/mullvad-daemon/src/exception_logging/win.rs +++ b/mullvad-daemon/src/exception_logging/win.rs @@ -17,8 +17,8 @@ use windows_sys::Win32::{ System::{ Diagnostics::{ Debug::{ - MiniDumpNormal, MiniDumpWriteDump, SetUnhandledExceptionFilter, CONTEXT, - EXCEPTION_POINTERS, EXCEPTION_RECORD, MINIDUMP_EXCEPTION_INFORMATION, + CONTEXT, EXCEPTION_POINTERS, EXCEPTION_RECORD, MINIDUMP_EXCEPTION_INFORMATION, + MiniDumpNormal, MiniDumpWriteDump, SetUnhandledExceptionFilter, }, ToolHelp::TH32CS_SNAPMODULE, }, diff --git a/mullvad-daemon/src/geoip.rs b/mullvad-daemon/src/geoip.rs index 815b83b13f..09d52ba824 100644 --- a/mullvad-daemon/src/geoip.rs +++ b/mullvad-daemon/src/geoip.rs @@ -5,7 +5,7 @@ use mullvad_api::rest::{Error, RequestServiceHandle}; use mullvad_types::location::{AmIMullvad, GeoIpLocation, LocationEventData}; use std::sync::LazyLock; use talpid_core::mpsc::Sender; -use talpid_future::retry::{retry_future, ExponentialBackoff, Jittered}; +use talpid_future::retry::{ExponentialBackoff, Jittered, retry_future}; use talpid_types::ErrorExt; use crate::{DaemonEventSender, InternalDaemonEvent}; diff --git a/mullvad-daemon/src/leak_checker/mod.rs b/mullvad-daemon/src/leak_checker/mod.rs index e24c2358fe..625c094290 100644 --- a/mullvad-daemon/src/leak_checker/mod.rs +++ b/mullvad-daemon/src/leak_checker/mod.rs @@ -1,4 +1,4 @@ -use futures::{select, FutureExt}; +use futures::{FutureExt, select}; pub use mullvad_leak_checker::LeakInfo; use std::time::Duration; use talpid_routing::RouteManagerHandle; @@ -167,8 +167,8 @@ async fn check_for_leaks( route_manager: &RouteManagerHandle, destination: Endpoint, ) -> anyhow::Result<Option<LeakInfo>> { - use anyhow::{anyhow, Context}; - use mullvad_leak_checker::{traceroute::TracerouteOpt, LeakStatus}; + use anyhow::{Context, anyhow}; + use mullvad_leak_checker::{LeakStatus, traceroute::TracerouteOpt}; #[cfg(target_os = "linux")] let interface = { diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index be2792e845..7fd3411fa8 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -34,9 +34,9 @@ use crate::target_state::PersistentTargetState; use api::AccessMethodEvent; use device::{AccountEvent, PrivateAccountAndDevice, PrivateDeviceEvent}; use futures::{ - channel::{mpsc, oneshot}, - future::{abortable, AbortHandle, Future}, StreamExt, + channel::{mpsc, oneshot}, + future::{AbortHandle, Future, abortable}, }; use geoip::GeoIpHandler; use leak_checker::{LeakChecker, LeakInfo}; @@ -55,7 +55,7 @@ use mullvad_types::{ auth_failed::AuthFailed, custom_list::CustomList, device::{Device, DeviceEvent, DeviceEventCause, DeviceId, DeviceState, RemoveDeviceEvent}, - features::{compute_feature_indicators, FeatureIndicator, FeatureIndicators}, + features::{FeatureIndicator, FeatureIndicators, compute_feature_indicators}, location::{GeoIpLocation, LocationEventData}, relay_constraints::{ BridgeSettings, BridgeState, BridgeType, ObfuscationSettings, RelayOverride, RelaySettings, @@ -66,7 +66,7 @@ use mullvad_types::{ version::{AppVersion, AppVersionInfo}, wireguard::{PublicKey, QuantumResistantState, RotationInterval}, }; -use relay_list::{RelayListUpdater, RelayListUpdaterHandle, RELAYS_FILENAME}; +use relay_list::{RELAYS_FILENAME, RelayListUpdater, RelayListUpdaterHandle}; use settings::SettingsPersister; #[cfg(any(windows, target_os = "android", target_os = "macos"))] use std::collections::HashSet; @@ -90,9 +90,9 @@ use talpid_types::android::AndroidContext; #[cfg(target_os = "windows")] use talpid_types::split_tunnel::ExcludedProcess; use talpid_types::{ + ErrorExt, net::{IpVersion, TunnelType}, tunnel::{ErrorStateCause, TunnelStateTransition}, - ErrorExt, }; use tokio::io; @@ -560,13 +560,12 @@ where InternalDaemonEvent: From<E>, { fn send(&self, event: E) -> Result<(), talpid_core::mpsc::Error> { - match self.sender.upgrade() { Some(sender) => { - sender + match self.sender.upgrade() { + Some(sender) => sender .unbounded_send(InternalDaemonEvent::from(event)) - .map_err(|_| talpid_core::mpsc::Error::ChannelClosed) - } _ => { - Err(talpid_core::mpsc::Error::ChannelClosed) - }} + .map_err(|_| talpid_core::mpsc::Error::ChannelClosed), + _ => Err(talpid_core::mpsc::Error::ChannelClosed), + } } } @@ -958,11 +957,14 @@ impl Daemon { self.disconnect_tunnel(); while let Some(event) = self.rx.next().await { - match event { InternalDaemonEvent::TunnelStateTransition(transition) => { - self.handle_tunnel_state_transition(transition).await; - } _ => { - log::trace!("Ignoring event because the daemon is shutting down"); - }} + match event { + InternalDaemonEvent::TunnelStateTransition(transition) => { + self.handle_tunnel_state_transition(transition).await; + } + _ => { + log::trace!("Ignoring event because the daemon is shutting down"); + } + } if self.tunnel_state.is_disconnected() { break; @@ -1162,15 +1164,16 @@ impl Daemon { // If not connected, we have to guess whether the users local connection supports IPv6. // The only thing we have to go on is the wireguard setting. TunnelState::Disconnected { .. } => { - match &self.settings.relay_settings { RelaySettings::Normal(relay_constraints) => { - // Note that `Constraint::Any` corresponds to just IPv4 - matches!( - relay_constraints.wireguard_constraints.ip_version, - mullvad_types::constraints::Constraint::Only(IpVersion::V6) - ) - } _ => { - false - }} + match &self.settings.relay_settings { + RelaySettings::Normal(relay_constraints) => { + // Note that `Constraint::Any` corresponds to just IPv4 + matches!( + relay_constraints.wireguard_constraints.ip_version, + mullvad_types::constraints::Constraint::Only(IpVersion::V6) + ) + } + _ => false, + } } // Fetching IP from am.i.mullvad.net should only be done from a tunnel state where a // connection is available. Otherwise we just exist. @@ -1690,25 +1693,28 @@ impl Daemon { } async fn on_get_www_auth_token(&mut self, tx: ResponseTx<String, Error>) { - match self.account_manager.data().await.map(|s| s.into_device()) { Ok(Some(device)) => { - let future = self - .account_manager - .account_service - .get_www_auth_token(device.account_number); - tokio::spawn(async { + match self.account_manager.data().await.map(|s| s.into_device()) { + Ok(Some(device)) => { + let future = self + .account_manager + .account_service + .get_www_auth_token(device.account_number); + tokio::spawn(async { + Self::oneshot_send( + tx, + future.await.map_err(Error::RestError), + "get_www_auth_token response", + ); + }); + } + _ => { Self::oneshot_send( tx, - future.await.map_err(Error::RestError), + Err(Error::NoAccountNumber), "get_www_auth_token response", ); - }); - } _ => { - Self::oneshot_send( - tx, - Err(Error::NoAccountNumber), - "get_www_auth_token response", - ); - }} + } + } } fn on_submit_voucher(&mut self, tx: ResponseTx<VoucherSubmission, Error>, voucher: String) { @@ -2459,7 +2465,7 @@ impl Daemon { #[cfg(daita)] async fn on_set_daita_enabled(&mut self, tx: ResponseTx<(), settings::Error>, value: bool) { - use mullvad_types::{constraints::Constraint, Intersection}; + use mullvad_types::{Intersection, constraints::Constraint}; let result = self .settings @@ -2498,7 +2504,7 @@ impl Daemon { tx: ResponseTx<(), settings::Error>, value: bool, ) { - use mullvad_types::{constraints::Constraint, Intersection}; + use mullvad_types::{Intersection, constraints::Constraint}; match self .settings @@ -2709,12 +2715,10 @@ impl Daemon { } async fn on_get_wireguard_key(&self, tx: ResponseTx<Option<PublicKey>, Error>) { - let result = - match self.account_manager.data().await.map(|s| s.into_device()) { Ok(Some(config)) => { - Ok(Some(config.device.wg_data.get_public_key())) - } _ => { - Err(Error::NoAccountNumber) - }}; + let result = match self.account_manager.data().await.map(|s| s.into_device()) { + Ok(Some(config)) => Ok(Some(config.device.wg_data.get_public_key())), + _ => Err(Error::NoAccountNumber), + }; Self::oneshot_send(tx, result, "get_wireguard_key response"); } diff --git a/mullvad-daemon/src/logging.rs b/mullvad-daemon/src/logging.rs index 6e91e86ea6..9f98dda394 100644 --- a/mullvad-daemon/src/logging.rs +++ b/mullvad-daemon/src/logging.rs @@ -1,6 +1,6 @@ use fern::{ - colors::{Color, ColoredLevelConfig}, Output, + colors::{Color, ColoredLevelConfig}, }; use std::{ fmt, io, diff --git a/mullvad-daemon/src/macos_launch_daemon.rs b/mullvad-daemon/src/macos_launch_daemon.rs index 0c9c89080c..4b46c5bb0a 100644 --- a/mullvad-daemon/src/macos_launch_daemon.rs +++ b/mullvad-daemon/src/macos_launch_daemon.rs @@ -6,7 +6,7 @@ //! daemon in the system settings. use libc::c_longlong; -use objc2::{class, msg_send, runtime::AnyObject, Encode, Encoding, RefEncode}; +use objc2::{Encode, Encoding, RefEncode, class, msg_send, runtime::AnyObject}; use std::ffi::CStr; type Id = *mut AnyObject; diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index c2146752c7..f20ee3c816 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -3,8 +3,8 @@ use std::{path::PathBuf, thread, time::Duration}; #[cfg(not(windows))] use mullvad_daemon::cleanup_old_rpc_socket; use mullvad_daemon::{ - exception_logging, logging, rpc_uniqueness_check, runtime, version, Daemon, - DaemonCommandChannel, DaemonConfig, + Daemon, DaemonCommandChannel, DaemonConfig, exception_logging, logging, rpc_uniqueness_check, + runtime, version, }; use talpid_types::ErrorExt; diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 320a7ef02d..86af3eb676 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -1,12 +1,12 @@ -use crate::{account_history, device, version_check, DaemonCommand, DaemonCommandSender}; +use crate::{DaemonCommand, DaemonCommandSender, account_history, device, version_check}; use futures::{ - channel::{mpsc, oneshot}, StreamExt, + channel::{mpsc, oneshot}, }; -use mullvad_api::{rest::Error as RestError, StatusCode}; +use mullvad_api::{StatusCode, rest::Error as RestError}; use mullvad_management_interface::{ - types::{self, daemon_event, management_service_server::ManagementService}, Code, Request, Response, ServerJoinHandle, Status, + types::{self, daemon_event, management_service_server::ManagementService}, }; use mullvad_types::{ account::AccountNumber, @@ -290,7 +290,9 @@ impl ManagementService for ManagementServiceImpl { async fn set_block_when_disconnected(&self, request: Request<bool>) -> ServiceResult<()> { let block_when_disconnected = request.into_inner(); log::debug!("set_block_when_disconnected({})", block_when_disconnected); - Err(Status::unimplemented("Setting Lockdown mode on Android is not supported - this is handled by the OS, not the daemon")) + Err(Status::unimplemented( + "Setting Lockdown mode on Android is not supported - this is handled by the OS, not the daemon", + )) } async fn set_auto_connect(&self, request: Request<bool>) -> ServiceResult<()> { @@ -1353,9 +1355,7 @@ fn map_device_error(error: &device::Error) -> Status { } device::Error::InvalidVoucher => Status::new(Code::NotFound, INVALID_VOUCHER_MESSAGE), device::Error::UsedVoucher => Status::new(Code::ResourceExhausted, USED_VOUCHER_MESSAGE), - device::Error::DeviceIoError(_error) => { - Status::new(Code::Unavailable, error.to_string()) - } + device::Error::DeviceIoError(_error) => Status::new(Code::Unavailable, error.to_string()), device::Error::OtherRestError(error) => map_rest_error(error), _ => Status::new(Code::Unknown, error.to_string()), } diff --git a/mullvad-daemon/src/migrations/account_history.rs b/mullvad-daemon/src/migrations/account_history.rs index 1008261136..7f9579ce04 100644 --- a/mullvad-daemon/src/migrations/account_history.rs +++ b/mullvad-daemon/src/migrations/account_history.rs @@ -25,14 +25,17 @@ pub async fn migrate_location(old_dir: &Path, new_dir: &Path) { return; } - match fs::copy(&old_path, &new_path).await { Err(error) => { - log::error!( - "{}", - error.display_chain_with_msg("Failed to migrate account history file location") - ); - } _ => { - let _ = fs::remove_file(old_path).await; - }} + match fs::copy(&old_path, &new_path).await { + Err(error) => { + log::error!( + "{}", + error.display_chain_with_msg("Failed to migrate account history file location") + ); + } + _ => { + let _ = fs::remove_file(old_path).await; + } + } } pub async fn migrate_formats(settings_dir: &Path, settings: &mut serde_json::Value) -> Result<()> { diff --git a/mullvad-daemon/src/migrations/device.rs b/mullvad-daemon/src/migrations/device.rs index d5c05c9353..efbf926e83 100644 --- a/mullvad-daemon/src/migrations/device.rs +++ b/mullvad-daemon/src/migrations/device.rs @@ -6,10 +6,10 @@ //! This module is allowed to import a number of types, unlike other migration modules, as it //! does not modify any files directly and may safely fail. -use super::{v5::MigrationData, MigrationComplete}; +use super::{MigrationComplete, v5::MigrationData}; use crate::{ - device::{self, DeviceService, PrivateAccountAndDevice, PrivateDevice}, DaemonEventSender, InternalDaemonEvent, + device::{self, DeviceService, PrivateAccountAndDevice, PrivateDevice}, }; use mullvad_types::{account::AccountNumber, wireguard::WireguardData}; use std::time::Duration; diff --git a/mullvad-daemon/src/migrations/mod.rs b/mullvad-daemon/src/migrations/mod.rs index 635c2f6ebe..20dca54820 100644 --- a/mullvad-daemon/src/migrations/mod.rs +++ b/mullvad-daemon/src/migrations/mod.rs @@ -34,8 +34,8 @@ use std::{ path::Path, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, }; use tokio::{ @@ -231,11 +231,11 @@ mod windows { use talpid_types::ErrorExt; use tokio::fs; use windows_sys::Win32::{ - Foundation::{LocalFree, ERROR_SUCCESS, HLOCAL, PSID}, + Foundation::{ERROR_SUCCESS, HLOCAL, LocalFree, PSID}, Security::{ Authorization::{GetNamedSecurityInfoW, SE_FILE_OBJECT, SE_OBJECT_TYPE}, - IsWellKnownSid, WinBuiltinAdministratorsSid, WinLocalSystemSid, - OWNER_SECURITY_INFORMATION, SECURITY_DESCRIPTOR, SID, WELL_KNOWN_SID_TYPE, + IsWellKnownSid, OWNER_SECURITY_INFORMATION, SECURITY_DESCRIPTOR, SID, + WELL_KNOWN_SID_TYPE, WinBuiltinAdministratorsSid, WinLocalSystemSid, }, }; diff --git a/mullvad-daemon/src/migrations/v7.rs b/mullvad-daemon/src/migrations/v7.rs index 47c6bf6275..0cc29df04e 100644 --- a/mullvad-daemon/src/migrations/v7.rs +++ b/mullvad-daemon/src/migrations/v7.rs @@ -7,8 +7,8 @@ use mullvad_types::{ }; use serde::{Deserialize, Serialize}; use talpid_types::net::{ - proxy::{CustomProxy, Shadowsocks, Socks5Local, Socks5Remote, SocksAuth}, Endpoint, TransportProtocol, + proxy::{CustomProxy, Shadowsocks, Socks5Local, Socks5Remote, SocksAuth}, }; // ====================================================== diff --git a/mullvad-daemon/src/migrations/v9.rs b/mullvad-daemon/src/migrations/v9.rs index 1275c488e1..f8ee03831b 100644 --- a/mullvad-daemon/src/migrations/v9.rs +++ b/mullvad-daemon/src/migrations/v9.rs @@ -205,7 +205,7 @@ mod test { fn test_v9_to_v10_migration() { use crate::migrations::v9::{ add_split_tunneling_settings, - test::constants::{V10_ANDROID_SETTINGS, V9_ANDROID_SETTINGS}, + test::constants::{V9_ANDROID_SETTINGS, V10_ANDROID_SETTINGS}, }; let enabled = true; diff --git a/mullvad-daemon/src/relay_list/mod.rs b/mullvad-daemon/src/relay_list/mod.rs index ee5781aff0..6126f113a0 100644 --- a/mullvad-daemon/src/relay_list/mod.rs +++ b/mullvad-daemon/src/relay_list/mod.rs @@ -1,9 +1,9 @@ //! Relay list updater use futures::{ + Future, FutureExt, SinkExt, StreamExt, channel::mpsc, future::{Fuse, FusedFuture}, - Future, FutureExt, SinkExt, StreamExt, }; use std::{ path::{Path, PathBuf}, @@ -11,10 +11,10 @@ use std::{ }; use tokio::fs::File; -use mullvad_api::{availability::ApiAvailability, rest::MullvadRestHandle, RelayListProxy}; +use mullvad_api::{RelayListProxy, availability::ApiAvailability, rest::MullvadRestHandle}; use mullvad_relay_selector::RelaySelector; use mullvad_types::relay_list::RelayList; -use talpid_future::retry::{retry_future, ExponentialBackoff, Jittered}; +use talpid_future::retry::{ExponentialBackoff, Jittered, retry_future}; use talpid_types::ErrorExt; /// How often the updater should wake up to check the cache of the in-memory cache of relays. diff --git a/mullvad-daemon/src/settings/mod.rs b/mullvad-daemon/src/settings/mod.rs index c376aeec9c..31c7d8874b 100644 --- a/mullvad-daemon/src/settings/mod.rs +++ b/mullvad-daemon/src/settings/mod.rs @@ -398,11 +398,7 @@ pub struct SettingsSummary<'a> { impl Display for SettingsSummary<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let bool_to_label = |state| { - if state { - "on" - } else { - "off" - } + if state { "on" } else { "off" } }; let relay_settings = self.settings.get_relay_settings(); @@ -504,11 +500,10 @@ impl Display for SettingsSummary<'_> { impl SettingsSummary<'_> { fn fmt_option<T: Display>(f: &mut fmt::Formatter<'_>, val: Option<T>) -> fmt::Result { - match &val { Some(inner) => { - inner.fmt(f) - } _ => { - f.write_str("unset") - }} + match &val { + Some(inner) => inner.fmt(f), + _ => f.write_str("unset"), + } } } diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index ccec49486b..ec2ad3ff3a 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -1,12 +1,13 @@ use crate::cli; -use mullvad_daemon::{runtime::new_multi_thread, DaemonShutdownHandle}; +use mullvad_daemon::{DaemonShutdownHandle, runtime::new_multi_thread}; use std::{ env, - ffi::{c_void, OsString}, + ffi::{OsString, c_void}, ptr, slice, sync::{ + Arc, LazyLock, atomic::{AtomicBool, AtomicUsize, Ordering}, - mpsc, Arc, LazyLock, + mpsc, }, thread, time::{Duration, Instant}, diff --git a/mullvad-daemon/src/tunnel.rs b/mullvad-daemon/src/tunnel.rs index 3fd94d591d..4f97207389 100644 --- a/mullvad-daemon/src/tunnel.rs +++ b/mullvad-daemon/src/tunnel.rs @@ -17,13 +17,13 @@ use std::sync::LazyLock; use talpid_core::tunnel_state_machine::TunnelParametersGenerator; #[cfg(not(target_os = "android"))] use talpid_types::net::{ - obfuscation::ObfuscatorConfig, openvpn, proxy::CustomProxy, wireguard, Endpoint, - TunnelParameters, + Endpoint, TunnelParameters, obfuscation::ObfuscatorConfig, openvpn, proxy::CustomProxy, + wireguard, }; #[cfg(target_os = "android")] -use talpid_types::net::{obfuscation::ObfuscatorConfig, wireguard, TunnelParameters}; +use talpid_types::net::{TunnelParameters, obfuscation::ObfuscatorConfig, wireguard}; -use talpid_types::{tunnel::ParameterGenerationError, ErrorExt}; +use talpid_types::{ErrorExt, tunnel::ParameterGenerationError}; use crate::device::{AccountManagerHandle, Error as DeviceError, PrivateAccountAndDevice}; diff --git a/mullvad-daemon/src/version_check.rs b/mullvad-daemon/src/version_check.rs index d59c0d09cf..8e4578a9ea 100644 --- a/mullvad-daemon/src/version_check.rs +++ b/mullvad-daemon/src/version_check.rs @@ -1,10 +1,10 @@ -use crate::{version::is_beta_version, DaemonEventSender}; +use crate::{DaemonEventSender, version::is_beta_version}; use futures::{ + FutureExt, SinkExt, StreamExt, TryFutureExt, channel::{mpsc, oneshot}, future::{BoxFuture, FusedFuture}, - FutureExt, SinkExt, StreamExt, TryFutureExt, }; -use mullvad_api::{availability::ApiAvailability, rest::MullvadRestHandle, AppVersionProxy}; +use mullvad_api::{AppVersionProxy, availability::ApiAvailability, rest::MullvadRestHandle}; use mullvad_types::version::{AppVersionInfo, ParsedAppVersion}; use serde::{Deserialize, Serialize}; use std::{ @@ -18,7 +18,7 @@ use std::{ time::{Duration, SystemTime}, }; use talpid_core::mpsc::Sender; -use talpid_future::retry::{retry_future, ConstantInterval}; +use talpid_future::retry::{ConstantInterval, retry_future}; use talpid_types::ErrorExt; use tokio::{fs::File, io::AsyncReadExt}; @@ -396,7 +396,10 @@ struct UpdateContext { impl UpdateContext { /// Write [VersionUpdaterInner::last_app_version_info], if any, to the cache file /// ([VERSION_INFO_FILENAME]). Also, notify `self.update_sender` - fn update(&self, last_app_version: AppVersionInfo) -> impl Future<Output = Result<(), Error>> + use<> { + fn update( + &self, + last_app_version: AppVersionInfo, + ) -> impl Future<Output = Result<(), Error>> + use<> { let _ = self.update_sender.send(last_app_version.clone()); let cache_path = self.cache_path.clone(); @@ -561,8 +564,8 @@ fn suggested_upgrade( #[cfg(test)] mod test { use std::sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }; use super::*; diff --git a/talpid-core/src/split_tunnel/windows/driver.rs b/talpid-core/src/split_tunnel/windows/driver.rs index 118063a96c..481514c61b 100644 --- a/talpid-core/src/split_tunnel/windows/driver.rs +++ b/talpid-core/src/split_tunnel/windows/driver.rs @@ -42,7 +42,7 @@ const DRIVER_SYMBOLIC_NAME: &str = "\\\\.\\MULLVADSPLITTUNNEL"; const ST_DEVICE_TYPE: u32 = 0x8000; const fn ctl_code(device_type: u32, function: u32, method: u32, access: u32) -> u32 { - device_type << 16 | access << 14 | function << 2 | method + (device_type << 16) | (access << 14) | (function << 2) | method } #[repr(u32)] @@ -936,22 +936,24 @@ pub unsafe fn wait_for_single_object(object: HANDLE, timeout: Option<Duration>) /// /// * `objects` must be a slice of valid objects that can be signaled, such as event objects. pub unsafe fn wait_for_multiple_objects(objects: &[HANDLE], wait_all: bool) -> io::Result<HANDLE> { - let objects_len = u32::try_from(objects.len()) - .map_err(|_error| io::Error::new(io::ErrorKind::InvalidInput, "too many objects"))?; - let result = WaitForMultipleObjects( - objects_len, - objects.as_ptr(), - if wait_all { 1 } else { 0 }, - INFINITE, - ); - let signaled_index = if result < objects_len { - result - } else if result >= WAIT_ABANDONED_0 && result < WAIT_ABANDONED_0 + objects_len { - return Err(io::Error::new(io::ErrorKind::Other, "abandoned mutex")); - } else { - return Err(io::Error::last_os_error()); - }; - Ok(objects[usize::try_from(signaled_index).expect("usize must be larger than u32")]) + unsafe { + let objects_len = u32::try_from(objects.len()) + .map_err(|_error| io::Error::new(io::ErrorKind::InvalidInput, "too many objects"))?; + let result = WaitForMultipleObjects( + objects_len, + objects.as_ptr(), + if wait_all { 1 } else { 0 }, + INFINITE, + ); + let signaled_index = if result < objects_len { + result + } else if result >= WAIT_ABANDONED_0 && result < WAIT_ABANDONED_0 + objects_len { + return Err(io::Error::new(io::ErrorKind::Other, "abandoned mutex")); + } else { + return Err(io::Error::last_os_error()); + }; + Ok(objects[usize::try_from(signaled_index).expect("usize must be larger than u32")]) + } } /// Reads the value from `buffer`, zeroing any remaining bytes. diff --git a/test/test-manager/src/tests/helpers.rs b/test/test-manager/src/tests/helpers.rs index a63ff928b9..195c3da26a 100644 --- a/test/test-manager/src/tests/helpers.rs +++ b/test/test-manager/src/tests/helpers.rs @@ -528,7 +528,7 @@ where break Err(Error::Daemon(format!( "Failed to get next event: {}", status - ))) + ))); } None => break Err(Error::Daemon(String::from("Lost daemon event stream"))), } diff --git a/test/test-manager/src/tests/mod.rs b/test/test-manager/src/tests/mod.rs index 19d305a8a3..4f5362167f 100644 --- a/test/test-manager/src/tests/mod.rs +++ b/test/test-manager/src/tests/mod.rs @@ -242,7 +242,9 @@ pub async fn ensure_daemon_environment(rpc: &ServiceClient) -> Result<(), anyhow .await .context("Failed to get daemon default env variables")?; if current_env != default_env { - log::debug!("Restarting daemon due changed environment variables. Values since last test {current_env:?}"); + log::debug!( + "Restarting daemon due changed environment variables. Values since last test {current_env:?}" + ); rpc.set_daemon_environment(default_env) .await .context("Failed to restart daemon")?; |
