summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
authorJonathan <jonathan@mullvad.net>2023-06-26 13:21:28 +0200
committerJonathan <jonathan@mullvad.net>2023-06-29 15:00:09 +0200
commitb4bf8124fbc30bf891f70f120265f30c490d1244 (patch)
tree8a747c315066a8d5b216ab471fadc022aa4aa4b8 /mullvad-cli/src
parent2480e42126d54adfdeb6b70c475299ceac6718c9 (diff)
downloadmullvadvpn-b4bf8124fbc30bf891f70f120265f30c490d1244.tar.xz
mullvadvpn-b4bf8124fbc30bf891f70f120265f30c490d1244.zip
Cleanup review comments, CI issues and android support
Add necessary android support to allow it to not crash due to interface changes. Format the code, remove redundant async functions, fix android issues related to not having to use a Vec to store the custom lists and a string as an id. Fix unit tests.
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/bridge.rs21
-rw-r--r--mullvad-cli/src/cmds/custom_lists.rs4
-rw-r--r--mullvad-cli/src/cmds/relay.rs36
-rw-r--r--mullvad-cli/src/cmds/tunnel_state.rs3
4 files changed, 33 insertions, 31 deletions
diff --git a/mullvad-cli/src/cmds/bridge.rs b/mullvad-cli/src/cmds/bridge.rs
index a170661838..e43fce1b51 100644
--- a/mullvad-cli/src/cmds/bridge.rs
+++ b/mullvad-cli/src/cmds/bridge.rs
@@ -3,16 +3,15 @@ use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
relay_constraints::{
- BridgeConstraints, BridgeSettings, BridgeState, Constraint,
- LocationConstraint, Ownership, Provider, Providers,
+ BridgeConstraints, BridgeSettings, BridgeState, Constraint, LocationConstraint, Ownership,
+ Provider, Providers,
},
relay_list::RelayEndpointData,
};
use std::net::{IpAddr, SocketAddr};
use talpid_types::net::openvpn::{self, SHADOWSOCKS_CIPHERS};
-use super::relay::find_relay_by_hostname;
-use super::relay_constraints::LocationArgs;
+use super::{relay::find_relay_by_hostname, relay_constraints::LocationArgs};
#[derive(Subcommand, Debug)]
pub enum Bridge {
@@ -163,17 +162,19 @@ impl Bridge {
}
SetCommands::Location(location) => {
let countries = rpc.get_relay_locations().await?.countries;
- let location = if let Some(relay) = find_relay_by_hostname(&countries, &location.country) {
- Constraint::Only(relay)
- } else {
- Constraint::from(location)
- };
+ let location =
+ if let Some(relay) = find_relay_by_hostname(&countries, &location.country) {
+ Constraint::Only(relay)
+ } else {
+ Constraint::from(location)
+ };
let location = location.map(|location| LocationConstraint::Location { location });
Self::update_bridge_settings(&mut rpc, Some(location), None, None).await
}
SetCommands::CustomList { custom_list_name } => {
let list = rpc.get_custom_list(custom_list_name).await?;
- let location = Constraint::Only(LocationConstraint::CustomList { list_id: list.id });
+ let location =
+ Constraint::Only(LocationConstraint::CustomList { list_id: list.id });
Self::update_bridge_settings(&mut rpc, Some(location), None, None).await
}
SetCommands::Ownership { ownership } => {
diff --git a/mullvad-cli/src/cmds/custom_lists.rs b/mullvad-cli/src/cmds/custom_lists.rs
index 12dd0b0d64..9c0770a442 100644
--- a/mullvad-cli/src/cmds/custom_lists.rs
+++ b/mullvad-cli/src/cmds/custom_lists.rs
@@ -4,9 +4,7 @@ use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
custom_list::CustomListLocationUpdate,
- relay_constraints::{
- Constraint, GeographicLocationConstraint
- },
+ relay_constraints::{Constraint, GeographicLocationConstraint},
};
#[derive(Subcommand, Debug)]
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs
index 6787c588d8..1bb395c4e5 100644
--- a/mullvad-cli/src/cmds/relay.rs
+++ b/mullvad-cli/src/cmds/relay.rs
@@ -314,7 +314,9 @@ impl Relay {
match subcmd {
SetCommands::Custom(subcmd) => Self::set_custom(subcmd).await,
SetCommands::Location(location) => Self::set_location(location).await,
- SetCommands::CustomList { custom_list_name } => Self::set_custom_list(custom_list_name).await,
+ SetCommands::CustomList { custom_list_name } => {
+ Self::set_custom_list(custom_list_name).await
+ }
SetCommands::Provider { providers } => Self::set_providers(providers).await,
SetCommands::Ownership { ownership } => Self::set_ownership(ownership).await,
SetCommands::Tunnel(subcmd) => Self::set_tunnel(subcmd).await,
@@ -448,9 +450,10 @@ impl Relay {
// The country field is assumed to be hostname due to CLI argument parsing
find_relay_by_hostname(&countries, &location_constraint_args.country)
{
- Constraint::Only(relay)
+ Constraint::Only(LocationConstraint::Location { location: relay })
} else {
- let location_constraint: Constraint<LocationConstraint> = Constraint::from(location_constraint_args);
+ let location_constraint: Constraint<GeographicLocationConstraint> =
+ Constraint::from(location_constraint_args);
match &location_constraint {
Constraint::Any => (),
Constraint::Only(constraint) => {
@@ -465,11 +468,11 @@ impl Relay {
}
}
}
- location_constraint
+ location_constraint.map(|location| LocationConstraint::Location { location })
};
Self::update_constraints(RelaySettingsUpdate::Normal(RelayConstraintsUpdate {
- location: Some(constraint.map(|location| LocationConstraint::Location { location })),
+ location: Some(constraint),
..Default::default()
}))
.await
@@ -571,17 +574,18 @@ impl Relay {
Some(EntryLocation::EntryLocation(entry)) => {
let countries = Self::get_filtered_relays().await?;
// The country field is assumed to be hostname due to CLI argument parsing
- wireguard_constraints.entry_location =
- if let Some(relay) = find_relay_by_hostname(&countries, &entry.country) {
- Constraint::Only(relay)
- } else {
- Constraint::from(entry)
- };
- },
+ wireguard_constraints.entry_location =
+ if let Some(relay) = find_relay_by_hostname(&countries, &entry.country) {
+ Constraint::Only(LocationConstraint::Location { location: relay })
+ } else {
+ Constraint::from(entry)
+ };
+ }
Some(EntryLocation::CustomList { custom_list_name }) => {
let list = rpc.get_custom_list(custom_list_name).await?;
- wireguard_constraints.entry_location = Constraint::Only(LocationConstraint::CustomList { list_id: list.id });
- },
+ wireguard_constraints.entry_location =
+ Constraint::Only(LocationConstraint::CustomList { list_id: list.id });
+ }
None => (),
}
@@ -644,7 +648,7 @@ fn parse_transport_port(
pub fn find_relay_by_hostname(
countries: &[RelayListCountry],
hostname: &str,
-) -> Option<LocationConstraint> {
+) -> Option<GeographicLocationConstraint> {
countries
.iter()
.flat_map(|country| country.cities.clone())
@@ -657,7 +661,7 @@ pub fn find_relay_by_hostname(
city_code,
..
}| {
- LocationConstraint::Normal { location: GeographicLocationConstraint::Hostname(country_code, city_code, relay.hostname) }
+ GeographicLocationConstraint::Hostname(country_code, city_code, relay.hostname)
},
)
})
diff --git a/mullvad-cli/src/cmds/tunnel_state.rs b/mullvad-cli/src/cmds/tunnel_state.rs
index 6e115c5ba1..76393091c5 100644
--- a/mullvad-cli/src/cmds/tunnel_state.rs
+++ b/mullvad-cli/src/cmds/tunnel_state.rs
@@ -2,8 +2,7 @@ use crate::format;
use anyhow::{anyhow, Result};
use futures::{Stream, StreamExt};
use mullvad_management_interface::{client::DaemonEvent, MullvadProxyClient};
-use mullvad_types::device::DeviceState;
-use mullvad_types::states::TunnelState;
+use mullvad_types::{device::DeviceState, states::TunnelState};
pub async fn connect(wait: bool) -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;