diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-05-08 17:24:59 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-05-08 17:24:59 +0200 |
| commit | 0e8b95e4d67b6be15a1990552e3accc513a4752a (patch) | |
| tree | d235d6a672cd9e18a514295709d067fa64dbe73b | |
| parent | dc188c31e9a8851a6c2cc9fea0921919f220edc3 (diff) | |
| parent | e99833c04bf180ef4752a51167b8067bee66c12d (diff) | |
| download | mullvadvpn-0e8b95e4d67b6be15a1990552e3accc513a4752a.tar.xz mullvadvpn-0e8b95e4d67b6be15a1990552e3accc513a4752a.zip | |
Merge branch 'update-location-cli'
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | mullvad-cli/src/location.rs | 24 | ||||
| -rw-r--r-- | mullvad-rpc/src/relay_list.rs | 26 |
3 files changed, 29 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d0402955d6..129fc3d48e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Line wrap the file at 100 chars. Th of the setting. - Embed TLS certificates used for HTTPS into the binary rather than loading them from disk at runtime +- Ignore case when setting the relay or bridge location in the CLI. #### Android - Adjust the minimum supported Android version to correctly reflect the supported versions decided diff --git a/mullvad-cli/src/location.rs b/mullvad-cli/src/location.rs index 75fe237c81..20853893b8 100644 --- a/mullvad-cli/src/location.rs +++ b/mullvad-cli/src/location.rs @@ -23,27 +23,23 @@ pub fn get_subcommand() -> clap::App<'static, 'static> { } pub fn get_constraint(matches: &clap::ArgMatches<'_>) -> Constraint<LocationConstraint> { - let country = matches.value_of("country").unwrap(); - let city = matches.value_of("city"); - let hostname = matches.value_of("hostname"); + let country_original = matches.value_of("country").unwrap(); + let country = country_original.to_lowercase(); + let city = matches.value_of("city").map(str::to_lowercase); + let hostname = matches.value_of("hostname").map(str::to_lowercase); - match (country, city, hostname) { + match (country_original, city, hostname) { ("any", None, None) => Constraint::Any, ("any", ..) => clap::Error::with_description( "City can't be given when selecting 'any' country", clap::ErrorKind::InvalidValue, ) .exit(), - (country, None, None) => Constraint::Only(LocationConstraint::Country(country.to_owned())), - (country, Some(city), None) => Constraint::Only(LocationConstraint::City( - country.to_owned(), - city.to_owned(), - )), - (country, Some(city), Some(hostname)) => Constraint::Only(LocationConstraint::Hostname( - country.to_owned(), - city.to_owned(), - hostname.to_owned(), - )), + (_, None, None) => Constraint::Only(LocationConstraint::Country(country)), + (_, Some(city), None) => Constraint::Only(LocationConstraint::City(country, city)), + (_, Some(city), Some(hostname)) => { + Constraint::Only(LocationConstraint::Hostname(country, city, hostname)) + } (..) => clap::Error::with_description( "Invalid country, city and hostname combination given", clap::ErrorKind::InvalidValue, diff --git a/mullvad-rpc/src/relay_list.rs b/mullvad-rpc/src/relay_list.rs index cd1d33f576..5e98d4f2c3 100644 --- a/mullvad-rpc/src/relay_list.rs +++ b/mullvad-rpc/src/relay_list.rs @@ -69,12 +69,12 @@ impl ServerRelayList { for (code, location) in locations.into_iter() { match split_location_code(&code) { Some((country_code, city_code)) => { + let country_code = country_code.to_lowercase(); + let city_code = city_code.to_lowercase(); let country = countries - .entry(country_code.to_string()) - .or_insert_with(|| location_to_country(&location, country_code.to_owned())); - country - .cities - .push(location_to_city(&location, city_code.to_owned())); + .entry(country_code.clone()) + .or_insert_with(|| location_to_country(&location, country_code)); + country.cities.push(location_to_city(&location, city_code)); } None => { log::error!("Bad location code - {}", code); @@ -102,7 +102,8 @@ impl ServerRelayList { openvpn: OpenVpn, ) { let openvpn_endpoint_data = openvpn.ports; - for openvpn_relay in openvpn.relays.into_iter() { + for mut openvpn_relay in openvpn.relays.into_iter() { + openvpn_relay.to_lower(); if let Some((country_code, city_code)) = split_location_code(&openvpn_relay.location) { if let Some(country) = countries.get_mut(country_code) { if let Some(city) = country @@ -155,7 +156,8 @@ impl ServerRelayList { public_key, }; - for wireguard_relay in relays { + for mut wireguard_relay in relays { + wireguard_relay.relay.to_lower(); if let Some((country_code, city_code)) = split_location_code(&wireguard_relay.relay.location) { @@ -205,7 +207,8 @@ impl ServerRelayList { shadowsocks, } = bridges; - for bridge_relay in relays { + for mut bridge_relay in relays { + bridge_relay.to_lower(); if let Some((country_code, city_code)) = split_location_code(&bridge_relay.location) { if let Some(country) = countries.get_mut(country_code) { if let Some(city) = country @@ -314,6 +317,13 @@ struct Relay { include_in_country: bool, } +impl Relay { + fn to_lower(&mut self) { + self.hostname = self.hostname.to_lowercase(); + self.location = self.location.to_lowercase(); + } +} + #[derive(Debug, serde::Deserialize)] struct Wireguard { port_ranges: Vec<(u16, u16)>, |
