summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/relay.rs49
-rw-r--r--mullvad-cli/src/location.rs8
2 files changed, 50 insertions, 7 deletions
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs
index 7071db4d45..975d2a15f3 100644
--- a/mullvad-cli/src/cmds/relay.rs
+++ b/mullvad-cli/src/cmds/relay.rs
@@ -9,7 +9,7 @@ use std::{
use mullvad_management_interface::types::{
connection_config::{self, OpenvpnConfig, WireguardConfig},
relay_settings, relay_settings_update, ConnectionConfig, CustomRelaySettings,
- NormalRelaySettingsUpdate, OpenvpnConstraints, RelayListCountry, RelayLocation,
+ NormalRelaySettingsUpdate, OpenvpnConstraints, ProviderUpdate, RelayListCountry, RelayLocation,
RelaySettingsUpdate, TransportProtocol, TransportProtocolConstraint, TunnelType,
TunnelTypeConstraint, TunnelTypeUpdate, WireguardConstraints,
};
@@ -127,6 +127,16 @@ impl Command for Relay {
),
)
.subcommand(
+ clap::SubCommand::with_name("provider")
+ .about("Set a hosting provider to select relays from. The 'list' \
+ command shows the available relays and their providers.")
+ .arg(
+ clap::Arg::with_name("provider")
+ .help("The hosting provider to use, or 'any' for no preference.")
+ .required(true)
+ )
+ )
+ .subcommand(
clap::SubCommand::with_name("tunnel")
.about("Set individual tunnel constraints")
.arg(
@@ -195,6 +205,8 @@ impl Relay {
self.set_location(location_matches).await
} else if let Some(relay_matches) = matches.subcommand_matches("relay") {
self.set_relay(relay_matches).await
+ } else if let Some(provider_matches) = matches.subcommand_matches("provider") {
+ self.set_provider(provider_matches).await
} else if let Some(tunnel_matches) = matches.subcommand_matches("tunnel") {
self.set_tunnel(tunnel_matches).await
} else if let Some(tunnel_matches) = matches.subcommand_matches("tunnel-protocol") {
@@ -426,6 +438,26 @@ impl Relay {
.await
}
+ async fn set_provider(&self, matches: &clap::ArgMatches<'_>) -> Result<()> {
+ let provider = value_t!(matches.value_of("provider"), String).unwrap_or_else(|e| e.exit());
+
+ self.update_constraints(RelaySettingsUpdate {
+ r#type: Some(relay_settings_update::Type::Normal(
+ NormalRelaySettingsUpdate {
+ provider: Some(ProviderUpdate {
+ provider: if provider == "any" {
+ "".to_string()
+ } else {
+ provider
+ },
+ }),
+ ..Default::default()
+ },
+ )),
+ })
+ .await
+ }
+
async fn set_tunnel(&self, matches: &clap::ArgMatches<'_>) -> Result<()> {
let vpn_protocol = matches.value_of("vpn protocol").unwrap();
let port = parse_port_constraint(matches.value_of("port").unwrap())?;
@@ -507,27 +539,30 @@ impl Relay {
relay_settings::Endpoint::Normal(settings) => match settings.tunnel_type {
None => {
println!(
- "Any tunnel protocol with OpenVPN over {} and WireGuard over {} in {}",
+ "Any tunnel protocol with OpenVPN over {} and WireGuard over {} in {} using {}",
Self::format_openvpn_constraints(settings.openvpn_constraints.as_ref()),
Self::format_wireguard_constraints(settings.wireguard_constraints.as_ref()),
- location::format_location(settings.location.as_ref())
+ location::format_location(settings.location.as_ref()),
+ location::format_provider(settings.provider.as_ref())
);
}
Some(constraint) => match TunnelType::from_i32(constraint.tunnel_type).unwrap() {
TunnelType::Wireguard => {
println!(
- "WireGuard over {} in {}",
+ "WireGuard over {} in {} using {}",
Self::format_wireguard_constraints(
settings.wireguard_constraints.as_ref()
),
- location::format_location(settings.location.as_ref())
+ location::format_location(settings.location.as_ref()),
+ location::format_provider(settings.provider.as_ref())
);
}
TunnelType::Openvpn => {
println!(
- "OpenVPN over {} in {}",
+ "OpenVPN over {} in {} using {}",
Self::format_openvpn_constraints(settings.openvpn_constraints.as_ref()),
- location::format_location(settings.location.as_ref())
+ location::format_location(settings.location.as_ref()),
+ location::format_provider(settings.provider.as_ref())
);
}
},
diff --git a/mullvad-cli/src/location.rs b/mullvad-cli/src/location.rs
index 21e6a1c35c..bc4c9bc630 100644
--- a/mullvad-cli/src/location.rs
+++ b/mullvad-cli/src/location.rs
@@ -73,6 +73,14 @@ pub fn format_location(location: Option<&RelayLocation>) -> String {
"any location".to_string()
}
+pub fn format_provider(provider: &str) -> String {
+ if !provider.is_empty() {
+ format!("provider {}", provider)
+ } else {
+ "any provider".to_string()
+ }
+}
+
fn country_code_validator(code: String) -> std::result::Result<(), String> {
if code.len() == 2 || code == "any" {
Ok(())