diff options
| -rw-r--r-- | mullvad-cli/src/cmds/relay.rs | 32 | ||||
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 8 | ||||
| -rw-r--r-- | mullvad-types/src/location.rs | 1 | ||||
| -rw-r--r-- | mullvad-types/src/relay_constraints.rs | 4 |
4 files changed, 38 insertions, 7 deletions
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs index 4de7571307..57cc934b03 100644 --- a/mullvad-cli/src/cmds/relay.rs +++ b/mullvad-cli/src/cmds/relay.rs @@ -24,7 +24,9 @@ impl Command for Relay { .setting(clap::AppSettings::SubcommandRequired) .subcommand( clap::SubCommand::with_name("set") - .setting(clap::AppSettings::SubcommandRequired) + .about( + "Set relay server selection parameters. Such as location and port/protocol", + ).setting(clap::AppSettings::SubcommandRequired) .subcommand( clap::SubCommand::with_name("custom") .about("Set a custom VPN relay") @@ -67,6 +69,10 @@ impl Command for Relay { .help("The three letter city code") .index(2) .validator(city_code_validator), + ).arg( + clap::Arg::with_name("hostname") + .help("The relay hostname") + .index(3), ), ).subcommand( clap::SubCommand::with_name("tunnel") @@ -137,18 +143,32 @@ impl Relay { fn set_location(&self, matches: &clap::ArgMatches) -> Result<()> { let country = matches.value_of("country").unwrap(); let city = matches.value_of("city"); + let hostname = matches.value_of("hostname"); - let location_constraint = match (country, city) { - ("any", None) => Constraint::Any, - ("any", _) => clap::Error::with_description( + let location_constraint = match (country, 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) => Constraint::Only(LocationConstraint::Country(country.to_owned())), - (country, Some(city)) => Constraint::Only(LocationConstraint::City( + (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(), + )) + } + (..) => clap::Error::with_description( + "Invalid country, city and hostname combination given", + clap::ErrorKind::InvalidValue, + ).exit(), }; self.update_constraints(RelaySettingsUpdate::Normal(RelayConstraintsUpdate { diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index 45aabcba1d..fea9bd8340 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -261,6 +261,14 @@ impl RelaySelector { loc.country_code == *country && loc.city_code == *city }) } + Constraint::Only(LocationConstraint::Hostname(ref country, ref city, ref hostname)) => { + relay + .location + .as_ref() + .map_or(relay.hostname == *hostname, |loc| { + loc.country_code == *country && loc.city_code == *city + }) + } }; if !matches_location { return None; diff --git a/mullvad-types/src/location.rs b/mullvad-types/src/location.rs index 6c4ed94b00..5d14318da6 100644 --- a/mullvad-types/src/location.rs +++ b/mullvad-types/src/location.rs @@ -2,6 +2,7 @@ use std::net::IpAddr; pub type CountryCode = String; pub type CityCode = String; +pub type Hostname = String; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Location { diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index f2369ce7fa..f0a56a9d76 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -1,4 +1,4 @@ -use location::{CityCode, CountryCode}; +use location::{CityCode, CountryCode, Hostname}; use CustomTunnelEndpoint; use std::fmt; @@ -96,6 +96,8 @@ pub enum LocationConstraint { Country(CountryCode), /// A city is composed of a country code and a city code. City(CountryCode, CityCode), + /// An single hostname in a given city. + Hostname(CountryCode, CityCode, Hostname), } |
