summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-08-11 10:59:50 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-08-21 17:02:27 +0200
commitcc7c0943039c2ed5e3e7176e747792d3ba2c6a41 (patch)
tree1d5b8f4f2d3cf1e8406dec32eb252af58bf47009 /mullvad-cli/src
parent018220b252d2940d2250c4795476b4e4b31400a1 (diff)
downloadmullvadvpn-cc7c0943039c2ed5e3e7176e747792d3ba2c6a41.tar.xz
mullvadvpn-cc7c0943039c2ed5e3e7176e747792d3ba2c6a41.zip
Decouple `get_filtered_relays` from `mullvad_cli::relay::Relay`
To be able to more easily re-use `get_filtered_relays` from other modules, such as `custom_lists`, the function was to the module level.
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/relay.rs63
1 files changed, 32 insertions, 31 deletions
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs
index 290c2cacd0..1b14b31a45 100644
--- a/mullvad-cli/src/cmds/relay.rs
+++ b/mullvad-cli/src/cmds/relay.rs
@@ -285,7 +285,7 @@ impl Relay {
}
async fn list() -> Result<()> {
- let mut countries = Self::get_filtered_relays().await?;
+ let mut countries = get_filtered_relays().await?;
countries.sort_by(|c1, c2| natord::compare_ignore_case(&c1.name, &c2.name));
for mut country in countries {
country
@@ -338,34 +338,6 @@ impl Relay {
}
/// Get active relays which are not bridges.
- async fn get_filtered_relays() -> Result<Vec<RelayListCountry>> {
- let mut rpc = MullvadProxyClient::new().await?;
- let relay_list = rpc.get_relay_locations().await?;
-
- let mut countries = vec![];
-
- for mut country in relay_list.countries {
- country.cities = country
- .cities
- .into_iter()
- .filter_map(|mut city| {
- city.relays.retain(|relay| {
- relay.active && relay.endpoint_data != RelayEndpointData::Bridge
- });
- if !city.relays.is_empty() {
- Some(city)
- } else {
- None
- }
- })
- .collect();
- if !country.cities.is_empty() {
- countries.push(country);
- }
- }
-
- Ok(countries)
- }
async fn update_constraints(update: RelaySettingsUpdate) -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;
@@ -508,7 +480,7 @@ impl Relay {
}
async fn set_location(location_constraint_args: LocationArgs) -> Result<()> {
- let countries = Self::get_filtered_relays().await?;
+ let countries = get_filtered_relays().await?;
let constraint =
if let Some(relay) =
// The country field is assumed to be hostname due to CLI argument parsing
@@ -636,7 +608,7 @@ impl Relay {
}
match entry_location {
Some(EntryLocation::EntryLocation(entry)) => {
- let countries = Self::get_filtered_relays().await?;
+ let countries = 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) {
@@ -730,3 +702,32 @@ pub fn find_relay_by_hostname(
)
})
}
+
+pub async fn get_filtered_relays() -> Result<Vec<RelayListCountry>> {
+ let mut rpc = MullvadProxyClient::new().await?;
+ let relay_list = rpc.get_relay_locations().await?;
+
+ let mut countries = vec![];
+
+ for mut country in relay_list.countries {
+ country.cities = country
+ .cities
+ .into_iter()
+ .filter_map(|mut city| {
+ city.relays.retain(|relay| {
+ relay.active && relay.endpoint_data != RelayEndpointData::Bridge
+ });
+ if !city.relays.is_empty() {
+ Some(city)
+ } else {
+ None
+ }
+ })
+ .collect();
+ if !country.cities.is_empty() {
+ countries.push(country);
+ }
+ }
+
+ Ok(countries)
+}