Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Nov 25, 2024
1 parent acceb04 commit cc8acbe
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 101 deletions.
10 changes: 6 additions & 4 deletions mullvad-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,13 @@ impl AccessModeSelector {
let endpoint = resolved.endpoint.clone();
let daemon_sender = self.access_method_event_sender.clone();
tokio::spawn(async move {
let _ = AccessMethodEvent::New { setting,
let _ = AccessMethodEvent::New {
setting,
#[cfg(not(target_os = "android"))]
endpoint }
.send(daemon_sender)
.await;
endpoint,
}
.send(daemon_sender)
.await;
});

// Save the new connection mode to cache!
Expand Down
36 changes: 17 additions & 19 deletions mullvad-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ pub struct Daemon {
relay_selector: RelaySelector,
relay_list_updater: RelayListUpdaterHandle,
parameters_generator: tunnel::ParametersGenerator,
shutdown_tasks: Vec<Pin<Box<dyn Future<Output=()> + Send + Sync>>>,
shutdown_tasks: Vec<Pin<Box<dyn Future<Output = ()> + Send + Sync>>>,
tunnel_state_machine_handle: TunnelStateMachineHandle,
#[cfg(target_os = "windows")]
volume_update_tx: mpsc::UnboundedSender<()>,
Expand Down Expand Up @@ -631,8 +631,8 @@ impl Daemon {
#[cfg(target_os = "android")]
api::create_bypass_tx(&internal_event_tx),
)
.await
.map_err(Error::InitRpcFactory)?;
.await
.map_err(Error::InitRpcFactory)?;

let api_availability = api_runtime.availability_handle();
api_availability.suspend();
Expand Down Expand Up @@ -676,8 +676,8 @@ impl Daemon {
internal_event_tx.to_specialized_sender(),
api_runtime.address_cache().clone(),
)
.await
.map_err(Error::ApiConnectionModeError)?;
.await
.map_err(Error::ApiConnectionModeError)?;

let api_handle = api_runtime.mullvad_rest_handle(access_mode_provider);

Expand Down Expand Up @@ -716,15 +716,15 @@ impl Daemon {
.unwrap_or_default(),
internal_event_tx.to_specialized_sender(),
)
.await
.map_err(Error::LoadAccountManager)?;
.await
.map_err(Error::LoadAccountManager)?;

let account_history = account_history::AccountHistory::new(
&settings_dir,
data.device().map(|device| device.account_number.clone()),
)
.await
.map_err(Error::LoadAccountHistory)?;
.await
.map_err(Error::LoadAccountHistory)?;

let target_state = if settings.auto_connect {
log::info!("Automatically connecting since auto-connect is turned on");
Expand Down Expand Up @@ -805,8 +805,8 @@ impl Daemon {
table_id: mullvad_types::TUNNEL_TABLE_ID,
},
)
.await
.map_err(Error::TunnelError)?;
.await
.map_err(Error::TunnelError)?;

api::forward_offline_state(api_availability.clone(), offline_state_rx);

Expand All @@ -829,7 +829,7 @@ impl Daemon {
internal_event_tx.to_specialized_sender(),
settings.show_beta_releases,
)
.await;
.await;

// Attempt to download a fresh relay list
relay_list_updater.update().await;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ impl Daemon {
TunnelState::Disconnected {
ref mut location,
#[cfg(not(target_os = "android"))]
locked_down: _,
locked_down: _,
} => *location = Some(fetched_location),
TunnelState::Connected {
ref mut location, ..
Expand Down Expand Up @@ -1436,8 +1436,6 @@ impl Daemon {
event: AccessMethodEvent,
endpoint_active_tx: oneshot::Sender<()>,
) {


#[cfg(target_os = "android")]
match event {
AccessMethodEvent::New { setting, .. } => {
Expand Down Expand Up @@ -2768,8 +2766,8 @@ impl Daemon {
daemon_event_sender,
api_proxy,
)
.await
.map_err(Error::AccessMethodError);
.await
.map_err(Error::AccessMethodError);

Self::oneshot_send(tx, result, "on_test_proxy_as_access_method response");
});
Expand Down Expand Up @@ -2821,8 +2819,8 @@ impl Daemon {
daemon_event_sender,
api_proxy,
)
.await
.map_err(Error::AccessMethodError);
.await
.map_err(Error::AccessMethodError);

log::debug!(
"API access method {method} {verdict}",
Expand Down
132 changes: 69 additions & 63 deletions mullvad-management-interface/src/types/conversions/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,36 +142,42 @@ impl From<mullvad_types::states::TunnelState> for proto::TunnelState {
#[cfg(not(target_os = "android"))]
other_always_on_app_error: None,
#[cfg(target_os = "android")]
other_always_on_app_error: if let talpid_tunnel::ErrorStateCause::OtherAlwaysOnApp { app_name } =
error_state.cause()
{
Some(proto::error_state::OtherAlwaysOnAppError { app_name: app_name.to_string() })
} else {
None
},
other_always_on_app_error:
if let talpid_tunnel::ErrorStateCause::OtherAlwaysOnApp { app_name } =
error_state.cause()
{
Some(proto::error_state::OtherAlwaysOnAppError {
app_name: app_name.to_string(),
})
} else {
None
},
#[cfg(not(target_os = "android"))]
invalid_dns_servers_error: None,
#[cfg(target_os = "android")]
invalid_dns_servers_error: if let talpid_tunnel::ErrorStateCause::InvalidDnsServers(ip_addrs) =
error_state.cause()
{
Some(proto::error_state::InvalidDnsServersError { ip_addrs: ip_addrs.iter().map(|ip| ip.to_string()).collect() })
} else {
None
},
invalid_dns_servers_error:
if let talpid_tunnel::ErrorStateCause::InvalidDnsServers(ip_addrs) =
error_state.cause()
{
Some(proto::error_state::InvalidDnsServersError {
ip_addrs: ip_addrs.iter().map(|ip| ip.to_string()).collect(),
})
} else {
None
},
auth_failed_error: mullvad_types::auth_failed::AuthFailed::try_from(
error_state.cause(),
)
.ok()
.map(|auth_failed| {
i32::from(proto::error_state::AuthFailedError::from(auth_failed))
})
.unwrap_or(0i32),
.ok()
.map(|auth_failed| {
i32::from(proto::error_state::AuthFailedError::from(auth_failed))
})
.unwrap_or(0i32),
parameter_error:
if let talpid_tunnel::ErrorStateCause::TunnelParameterError(reason) =
error_state.cause()
{
match reason {
if let talpid_tunnel::ErrorStateCause::TunnelParameterError(reason) =
error_state.cause()
{
match reason {
talpid_tunnel::ParameterGenerationError::NoMatchingRelay => {
i32::from(GenerationError::NoMatchingRelay)
}
Expand All @@ -185,17 +191,17 @@ impl From<mullvad_types::states::TunnelState> for proto::TunnelState {
i32::from(GenerationError::CustomTunnelHostResolutionError)
}
}
} else {
0
},
} else {
0
},
policy_error:
if let talpid_tunnel::ErrorStateCause::SetFirewallPolicyError(reason) =
error_state.cause()
{
Some(map_firewall_error(reason))
} else {
None
},
if let talpid_tunnel::ErrorStateCause::SetFirewallPolicyError(reason) =
error_state.cause()
{
Some(map_firewall_error(reason))
} else {
None
},
#[cfg(not(target_os = "windows"))]
create_tunnel_error: None,
#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -258,23 +264,23 @@ impl TryFrom<proto::TunnelState> for mullvad_types::states::TunnelState {
let state = match state.state {
#[cfg_attr(target_os = "android", allow(unused_variables))]
Some(proto::tunnel_state::State::Disconnected(proto::tunnel_state::Disconnected {
disconnected_location,
locked_down,
})) => MullvadState::Disconnected {
disconnected_location,
locked_down,
})) => MullvadState::Disconnected {
location: disconnected_location
.map(mullvad_types::location::GeoIpLocation::try_from)
.transpose()?,
#[cfg(not(target_os = "android"))]
locked_down,
},
Some(proto::tunnel_state::State::Connecting(proto::tunnel_state::Connecting {
relay_info:
Some(proto::TunnelStateRelayInfo {
tunnel_endpoint: Some(tunnel_endpoint),
location,
}),
feature_indicators,
})) => MullvadState::Connecting {
relay_info:
Some(proto::TunnelStateRelayInfo {
tunnel_endpoint: Some(tunnel_endpoint),
location,
}),
feature_indicators,
})) => MullvadState::Connecting {
endpoint: talpid_net::TunnelEndpoint::try_from(tunnel_endpoint)?,
location: location
.map(mullvad_types::location::GeoIpLocation::try_from)
Expand All @@ -286,13 +292,13 @@ impl TryFrom<proto::TunnelState> for mullvad_types::states::TunnelState {
))?,
},
Some(proto::tunnel_state::State::Connected(proto::tunnel_state::Connected {
relay_info:
Some(proto::TunnelStateRelayInfo {
tunnel_endpoint: Some(tunnel_endpoint),
location,
}),
feature_indicators,
})) => MullvadState::Connected {
relay_info:
Some(proto::TunnelStateRelayInfo {
tunnel_endpoint: Some(tunnel_endpoint),
location,
}),
feature_indicators,
})) => MullvadState::Connected {
endpoint: talpid_net::TunnelEndpoint::try_from(tunnel_endpoint)?,
location: location
.map(mullvad_types::location::GeoIpLocation::try_from)
Expand All @@ -304,8 +310,8 @@ impl TryFrom<proto::TunnelState> for mullvad_types::states::TunnelState {
))?,
},
Some(proto::tunnel_state::State::Disconnecting(
proto::tunnel_state::Disconnecting { after_disconnect },
)) => MullvadState::Disconnecting(
proto::tunnel_state::Disconnecting { after_disconnect },
)) => MullvadState::Disconnecting(
match proto::AfterDisconnect::try_from(after_disconnect) {
Ok(proto::AfterDisconnect::Nothing) => {
talpid_tunnel::ActionAfterDisconnect::Nothing
Expand All @@ -324,17 +330,17 @@ impl TryFrom<proto::TunnelState> for mullvad_types::states::TunnelState {
},
),
Some(proto::tunnel_state::State::Error(proto::tunnel_state::Error {
error_state:
Some(proto::ErrorState {
cause,
blocking_error,
auth_failed_error,
parameter_error,
policy_error,
create_tunnel_error,
..
}),
})) => {
error_state:
Some(proto::ErrorState {
cause,
blocking_error,
auth_failed_error,
parameter_error,
policy_error,
create_tunnel_error,
..
}),
})) => {
#[cfg(not(target_os = "windows"))]
let _ = create_tunnel_error;

Expand Down
24 changes: 11 additions & 13 deletions talpid-core/src/tunnel_state_machine/connected_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::tunnel::TunnelMonitor;
use super::connecting_state::TunnelCloseEvent;

pub(crate) type TunnelEventsReceiver =
Fuse<mpsc::UnboundedReceiver<(TunnelEvent, oneshot::Sender<()>)>>;
Fuse<mpsc::UnboundedReceiver<(TunnelEvent, oneshot::Sender<()>)>>;

/// The tunnel is up and working.
pub struct ConnectedState {
Expand Down Expand Up @@ -297,18 +297,16 @@ impl ConnectedState {
{
if let Err(_err) = shared_values.restart_tunnel(false) {
match _err {
Error::InvalidDnsServers(ip_addrs) => {
self.disconnect(
shared_values,
AfterDisconnect::Block(ErrorStateCause::InvalidDnsServers(ip_addrs)),
)
}
_ => {
self.disconnect(
shared_values,
AfterDisconnect::Block(ErrorStateCause::StartTunnelError),
)
}
Error::InvalidDnsServers(ip_addrs) => self.disconnect(
shared_values,
AfterDisconnect::Block(ErrorStateCause::InvalidDnsServers(
ip_addrs,
)),
),
_ => self.disconnect(
shared_values,
AfterDisconnect::Block(ErrorStateCause::StartTunnelError),
),
}
} else {
self.disconnect(shared_values, AfterDisconnect::Reconnect(0))
Expand Down
2 changes: 1 addition & 1 deletion talpid-core/src/tunnel_state_machine/connecting_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl ConnectingState {
tun_provider::Error::OtherAlwaysOnApp { app_name },
),
),
) => ErrorStateCause::OtherAlwaysOnApp { app_name},
) => ErrorStateCause::OtherAlwaysOnApp { app_name },

#[cfg(target_os = "android")]
tunnel::Error::WireguardTunnelMonitoringError(
Expand Down
2 changes: 1 addition & 1 deletion talpid-tunnel/src/tun_provider/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl VpnServiceConfig {
.collect()
}

fn allowed_lan_networks() -> impl Iterator<Item=&'static IpNetwork> {
fn allowed_lan_networks() -> impl Iterator<Item = &'static IpNetwork> {
ALLOWED_LAN_NETS
.iter()
.chain(ALLOWED_LAN_MULTICAST_NETS.iter())
Expand Down

0 comments on commit cc8acbe

Please sign in to comment.