diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-08-11 14:44:13 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-08-20 14:41:41 +0200 |
| commit | 45ee23da9eda49462db6cc55f0e4f78b133727b9 (patch) | |
| tree | e3f90447cd9616587bd1833d83025403fbb62851 /mullvad-cli/src | |
| parent | 235c7189109d2d47e860cdb3a054266b4506e022 (diff) | |
| download | mullvadvpn-45ee23da9eda49462db6cc55f0e4f78b133727b9.tar.xz mullvadvpn-45ee23da9eda49462db6cc55f0e4f78b133727b9.zip | |
Add mullvad-management-interface crate for IPC types and functions
Diffstat (limited to 'mullvad-cli/src')
| -rw-r--r-- | mullvad-cli/src/cmds/account.rs | 31 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/auto_connect.rs | 8 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/beta_program.rs | 8 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/block_when_disconnected.rs | 8 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/bridge.rs | 20 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/connect.rs | 6 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/disconnect.rs | 6 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/lan.rs | 8 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/reconnect.rs | 6 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/relay.rs | 16 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/reset.rs | 6 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/split_tunnel/linux.rs | 12 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/status.rs | 34 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel.rs | 30 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/version.rs | 6 | ||||
| -rw-r--r-- | mullvad-cli/src/format.rs | 4 | ||||
| -rw-r--r-- | mullvad-cli/src/location.rs | 2 | ||||
| -rw-r--r-- | mullvad-cli/src/main.rs | 35 |
18 files changed, 113 insertions, 133 deletions
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs index a0a223eaf2..ef5c117c41 100644 --- a/mullvad-cli/src/cmds/account.rs +++ b/mullvad-cli/src/cmds/account.rs @@ -1,10 +1,11 @@ -use crate::{new_grpc_client, Command, Error, Result}; +use crate::{new_rpc_client, Command, Error, Result}; use clap::value_t_or_exit; -use mullvad_types::account::{AccountToken, VoucherError}; +use mullvad_management_interface::{types::Timestamp, Code}; +use mullvad_types::account::AccountToken; pub struct Account; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Account { fn name(&self) -> &'static str { "account" @@ -73,7 +74,7 @@ impl Command for Account { impl Account { async fn set(&self, token: Option<AccountToken>) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_account(token.clone().unwrap_or_default()).await?; if let Some(token) = token { println!("Mullvad account \"{}\" set", token); @@ -84,7 +85,7 @@ impl Account { } async fn get(&self) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let settings = rpc.get_settings(()).await?.into_inner(); if settings.account_token != "" { println!("Mullvad account: {}", settings.account_token); @@ -103,14 +104,14 @@ impl Account { } async fn create(&self) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.create_new_account(()).await?; println!("New account created!"); self.get().await } async fn redeem_voucher(&self, mut voucher: String) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; voucher.retain(|c| c.is_alphanumeric()); match rpc.submit_voucher(voucher).await { @@ -127,11 +128,13 @@ impl Account { Ok(()) } Err(err) => { - eprintln!( - "Failed to submit voucher.\n{}", - VoucherError::from_rpc_error_code(err.code() as i64) - ); - Err(Error::GrpcClientError(err)) + match err.code() { + Code::NotFound | Code::ResourceExhausted => { + eprintln!("Failed to submit voucher: {}", err.message()); + } + _ => return Err(Error::GrpcClientError(err)), + } + std::process::exit(1); } } } @@ -149,12 +152,12 @@ impl Account { } } - fn format_expiry(expiry: &prost_types::Timestamp) -> String { + fn format_expiry(expiry: &Timestamp) -> String { chrono::NaiveDateTime::from_timestamp(expiry.seconds, expiry.nanos as u32).to_string() } async fn clear_history(&self) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.clear_account_history(()).await?; println!("Removed account history and all associated keys"); Ok(()) diff --git a/mullvad-cli/src/cmds/auto_connect.rs b/mullvad-cli/src/cmds/auto_connect.rs index e934e8e37c..40f8f2bd9e 100644 --- a/mullvad-cli/src/cmds/auto_connect.rs +++ b/mullvad-cli/src/cmds/auto_connect.rs @@ -1,9 +1,9 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; use clap::value_t_or_exit; pub struct AutoConnect; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for AutoConnect { fn name(&self) -> &'static str { "auto-connect" @@ -42,14 +42,14 @@ impl Command for AutoConnect { impl AutoConnect { async fn set(&self, auto_connect: bool) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_auto_connect(auto_connect).await?; println!("Changed auto-connect sharing setting"); Ok(()) } async fn get(&self) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let auto_connect = rpc.get_settings(()).await?.into_inner().auto_connect; println!("Autoconnect: {}", if auto_connect { "on" } else { "off" }); Ok(()) diff --git a/mullvad-cli/src/cmds/beta_program.rs b/mullvad-cli/src/cmds/beta_program.rs index 3950d54433..73a0ba15c7 100644 --- a/mullvad-cli/src/cmds/beta_program.rs +++ b/mullvad-cli/src/cmds/beta_program.rs @@ -1,9 +1,9 @@ -use crate::{new_grpc_client, Command, Error, Result, PRODUCT_VERSION}; +use crate::{new_rpc_client, Command, Error, Result, PRODUCT_VERSION}; use clap::value_t_or_exit; pub struct BetaProgram; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for BetaProgram { fn name(&self) -> &'static str { "beta-program" @@ -28,7 +28,7 @@ impl Command for BetaProgram { async fn run(&self, matches: &clap::ArgMatches<'_>) -> Result<()> { match matches.subcommand() { ("get", Some(_)) => { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let settings = rpc.get_settings(()).await?.into_inner(); let enabled_str = if settings.show_beta_releases { "on" @@ -48,7 +48,7 @@ impl Command for BetaProgram { )); } - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_show_beta_releases(enable).await?; println!("Beta program: {}", enable_str); diff --git a/mullvad-cli/src/cmds/block_when_disconnected.rs b/mullvad-cli/src/cmds/block_when_disconnected.rs index b66acf168d..3cb1baff5a 100644 --- a/mullvad-cli/src/cmds/block_when_disconnected.rs +++ b/mullvad-cli/src/cmds/block_when_disconnected.rs @@ -1,9 +1,9 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; use clap::value_t_or_exit; pub struct BlockWhenDisconnected; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for BlockWhenDisconnected { fn name(&self) -> &'static str { "always-require-vpn" @@ -42,7 +42,7 @@ impl Command for BlockWhenDisconnected { impl BlockWhenDisconnected { async fn set(&self, block_when_disconnected: bool) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_block_when_disconnected(block_when_disconnected) .await?; println!("Changed always require VPN setting"); @@ -50,7 +50,7 @@ impl BlockWhenDisconnected { } async fn get(&self) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let block_when_disconnected = rpc .get_settings(()) .await? diff --git a/mullvad-cli/src/cmds/bridge.rs b/mullvad-cli/src/cmds/bridge.rs index 7ad4cf1b22..3118c09a39 100644 --- a/mullvad-cli/src/cmds/bridge.rs +++ b/mullvad-cli/src/cmds/bridge.rs @@ -1,7 +1,7 @@ -use crate::{location, new_grpc_client, Command, Result}; +use crate::{location, new_rpc_client, Command, Result}; use clap::value_t; -use crate::proto::{ +use mullvad_management_interface::types::{ bridge_settings::{Type as BridgeSettingsType, *}, bridge_state::State as BridgeStateType, BridgeSettings, BridgeState, @@ -12,7 +12,7 @@ use std::net::{IpAddr, SocketAddr}; pub struct Bridge; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Bridge { fn name(&self) -> &'static str { "bridge" @@ -164,7 +164,7 @@ impl Bridge { } async fn handle_get() -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let settings = rpc.get_settings(()).await?.into_inner(); Self::print_state(settings.bridge_state.unwrap()); match settings.bridge_settings.unwrap().r#type.unwrap() { @@ -185,7 +185,7 @@ impl Bridge { async fn handle_set_bridge_location(matches: &clap::ArgMatches<'_>) -> Result<()> { let constraints = location::get_constraint(matches); - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_bridge_settings(BridgeSettings { r#type: Some(BridgeSettingsType::Normal(BridgeConstraints { location: Some(constraints), @@ -202,7 +202,7 @@ impl Bridge { "off" => BridgeStateType::Off as i32, _ => unreachable!(), }; - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_bridge_state(BridgeState { state }).await?; Ok(()) } @@ -231,7 +231,7 @@ impl Bridge { panic!(error); } - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_bridge_settings(BridgeSettings { r#type: Some(BridgeSettingsType::Local(prost_proxy)), }) @@ -270,7 +270,7 @@ impl Bridge { panic!(error); } - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_bridge_settings(BridgeSettings { r#type: Some(BridgeSettingsType::Remote(prost_proxy)), }) @@ -299,7 +299,7 @@ impl Bridge { panic!(error); } - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_bridge_settings(BridgeSettings { r#type: Some(BridgeSettingsType::Shadowsocks(prost_proxy)), }) @@ -347,7 +347,7 @@ impl Bridge { } async fn list_bridge_relays() -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let mut locations = rpc.get_relay_locations(()).await?.into_inner(); let mut countries = Vec::new(); diff --git a/mullvad-cli/src/cmds/connect.rs b/mullvad-cli/src/cmds/connect.rs index 899a450547..6fc7072580 100644 --- a/mullvad-cli/src/cmds/connect.rs +++ b/mullvad-cli/src/cmds/connect.rs @@ -1,9 +1,9 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; use talpid_types::ErrorExt; pub struct Connect; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Connect { fn name(&self) -> &'static str { "connect" @@ -15,7 +15,7 @@ impl Command for Connect { } async fn run(&self, _: &clap::ArgMatches<'_>) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; if let Err(e) = rpc.connect_tunnel(()).await { eprintln!("{}", e.display_chain()); } diff --git a/mullvad-cli/src/cmds/disconnect.rs b/mullvad-cli/src/cmds/disconnect.rs index a3d6698fc9..f976b96fab 100644 --- a/mullvad-cli/src/cmds/disconnect.rs +++ b/mullvad-cli/src/cmds/disconnect.rs @@ -1,8 +1,8 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; pub struct Disconnect; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Disconnect { fn name(&self) -> &'static str { "disconnect" @@ -14,7 +14,7 @@ impl Command for Disconnect { } async fn run(&self, _: &clap::ArgMatches<'_>) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.disconnect_tunnel(()).await?; Ok(()) } diff --git a/mullvad-cli/src/cmds/lan.rs b/mullvad-cli/src/cmds/lan.rs index 05f4f867d2..dd84851f33 100644 --- a/mullvad-cli/src/cmds/lan.rs +++ b/mullvad-cli/src/cmds/lan.rs @@ -1,9 +1,9 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; use clap::value_t_or_exit; pub struct Lan; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Lan { fn name(&self) -> &'static str { "lan" @@ -42,14 +42,14 @@ impl Command for Lan { impl Lan { async fn set(&self, allow_lan: bool) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_allow_lan(allow_lan).await?; println!("Changed local network sharing setting"); Ok(()) } async fn get(&self) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let allow_lan = rpc.get_settings(()).await?.into_inner().allow_lan; println!( "Local network sharing setting: {}", diff --git a/mullvad-cli/src/cmds/reconnect.rs b/mullvad-cli/src/cmds/reconnect.rs index d281266e11..ecc0b089c0 100644 --- a/mullvad-cli/src/cmds/reconnect.rs +++ b/mullvad-cli/src/cmds/reconnect.rs @@ -1,9 +1,9 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; use talpid_types::ErrorExt; pub struct Reconnect; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Reconnect { fn name(&self) -> &'static str { "reconnect" @@ -14,7 +14,7 @@ impl Command for Reconnect { } async fn run(&self, _: &clap::ArgMatches<'_>) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; if let Err(e) = rpc.reconnect_tunnel(()).await { eprintln!("{}", e.display_chain()); } diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs index 07d07fc447..ba00654258 100644 --- a/mullvad-cli/src/cmds/relay.rs +++ b/mullvad-cli/src/cmds/relay.rs @@ -1,4 +1,4 @@ -use crate::{location, new_grpc_client, proto, Command, Error, Result}; +use crate::{location, new_rpc_client, Command, Error, Result}; use clap::{value_t, values_t}; use std::{ io::{self, BufRead}, @@ -6,18 +6,18 @@ use std::{ str::FromStr, }; -use mullvad_types::relay_constraints::Constraint; -use proto::{ +use mullvad_management_interface::types::{ connection_config::{self, OpenvpnConfig, WireguardConfig}, relay_settings, relay_settings_update, ConnectionConfig, CustomRelaySettings, NormalRelaySettingsUpdate, OpenvpnConstraints, RelaySettingsUpdate, TransportProtocol, TunnelType, TunnelTypeUpdate, WireguardConstraints, }; +use mullvad_types::relay_constraints::Constraint; use talpid_types::net::all_of_the_internet; pub struct Relay; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Relay { fn name(&self) -> &'static str { "relay" @@ -171,7 +171,7 @@ impl Command for Relay { impl Relay { async fn update_constraints(&self, update: RelaySettingsUpdate) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.update_relay_settings(update).await?; println!("Relay constraints updated"); Ok(()) @@ -384,7 +384,7 @@ impl Relay { } async fn get(&self) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let constraints = rpc .get_settings(()) .await? @@ -454,7 +454,7 @@ impl Relay { } async fn list(&self) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let mut locations = rpc.get_relay_locations(()).await?.into_inner(); let mut countries = Vec::new(); @@ -517,7 +517,7 @@ impl Relay { } async fn update(&self) -> Result<()> { - new_grpc_client().await?.update_relay_locations(()).await?; + new_rpc_client().await?.update_relay_locations(()).await?; println!("Updating relay list in the background..."); Ok(()) } diff --git a/mullvad-cli/src/cmds/reset.rs b/mullvad-cli/src/cmds/reset.rs index 2461e86ad5..bb10a3f0fe 100644 --- a/mullvad-cli/src/cmds/reset.rs +++ b/mullvad-cli/src/cmds/reset.rs @@ -1,8 +1,8 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; use std::io::stdin; pub struct Reset; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Reset { fn name(&self) -> &'static str { "factory-reset" @@ -13,7 +13,7 @@ impl Command for Reset { } async fn run(&self, _: &clap::ArgMatches<'_>) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; if Self::receive_confirmation() { if rpc.factory_reset(()).await.is_err() { eprintln!("FAILED TO PERFORM FACTORY RESET"); diff --git a/mullvad-cli/src/cmds/split_tunnel/linux.rs b/mullvad-cli/src/cmds/split_tunnel/linux.rs index 5e8a9b9644..5903d84f68 100644 --- a/mullvad-cli/src/cmds/split_tunnel/linux.rs +++ b/mullvad-cli/src/cmds/split_tunnel/linux.rs @@ -1,9 +1,9 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; use clap::value_t_or_exit; pub struct SplitTunnel; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for SplitTunnel { fn name(&self) -> &'static str { "split-tunnel" @@ -43,7 +43,7 @@ impl SplitTunnel { match matches.subcommand() { ("add", Some(matches)) => { let pid = value_t_or_exit!(matches.value_of("pid"), i32); - new_grpc_client() + new_rpc_client() .await? .add_split_tunnel_process(pid) .await?; @@ -51,21 +51,21 @@ impl SplitTunnel { } ("delete", Some(matches)) => { let pid = value_t_or_exit!(matches.value_of("pid"), i32); - new_grpc_client() + new_rpc_client() .await? .remove_split_tunnel_process(pid) .await?; Ok(()) } ("clear", Some(_)) => { - new_grpc_client() + new_rpc_client() .await? .clear_split_tunnel_processes(()) .await?; Ok(()) } ("list", Some(_)) => { - let mut pids_stream = new_grpc_client() + let mut pids_stream = new_rpc_client() .await? .get_split_tunnel_processes(()) .await? diff --git a/mullvad-cli/src/cmds/status.rs b/mullvad-cli/src/cmds/status.rs index ec05492c46..5084cea8b8 100644 --- a/mullvad-cli/src/cmds/status.rs +++ b/mullvad-cli/src/cmds/status.rs @@ -1,19 +1,21 @@ -use crate::{format::print_keygen_event, new_grpc_client, proto, Command, Error, Result}; -use mullvad_types::auth_failed::AuthFailed; -use proto::{ - daemon_event::Event as EventType, - error_state::{ - firewall_policy_error::ErrorType as FirewallPolicyErrorType, Cause as ErrorStateCause, - FirewallPolicyError, GenerationError, +use crate::{format::print_keygen_event, new_rpc_client, Command, Error, Result}; +use mullvad_management_interface::{ + types::{ + daemon_event::Event as EventType, + error_state::{ + firewall_policy_error::ErrorType as FirewallPolicyErrorType, Cause as ErrorStateCause, + FirewallPolicyError, GenerationError, + }, + ErrorState, ProxyType, TransportProtocol, TunnelEndpoint, TunnelState, TunnelType, }, - management_service_client::ManagementServiceClient, - ErrorState, ProxyType, TransportProtocol, TunnelEndpoint, TunnelState, TunnelType, + ManagementServiceClient, }; +use mullvad_types::auth_failed::AuthFailed; use std::fmt::Write; pub struct Status; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Status { fn name(&self) -> &'static str { "status" @@ -40,7 +42,7 @@ impl Command for Status { } async fn run(&self, matches: &clap::ArgMatches<'_>) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let state = rpc.get_tunnel_state(()).await?.into_inner(); print_state(&state); @@ -57,7 +59,7 @@ impl Command for Status { match event.event.unwrap() { EventType::TunnelState(new_state) => { print_state(&new_state); - use proto::tunnel_state::State::*; + use mullvad_management_interface::types::tunnel_state::State::*; match new_state.state.unwrap() { Connected(..) | Disconnected(..) => { if matches.is_present("location") { @@ -97,7 +99,7 @@ impl Command for Status { } fn print_state(state: &TunnelState) { - use proto::{tunnel_state, tunnel_state::State::*}; + use mullvad_management_interface::types::{tunnel_state, tunnel_state::State::*}; print!("Tunnel status: "); match state.state.as_ref().unwrap() { @@ -242,14 +244,12 @@ fn policy_error_to_string(policy_error: &FirewallPolicyError) -> String { format!("Failed to set firewall policy: {}", cause) } -async fn print_location( - rpc: &mut ManagementServiceClient<tonic::transport::Channel>, -) -> Result<()> { +async fn print_location(rpc: &mut ManagementServiceClient) -> Result<()> { let location = rpc.get_current_location(()).await; let location = match location { Ok(response) => response.into_inner(), Err(status) => { - if status.code() == tonic::Code::NotFound { + if status.code() == mullvad_management_interface::Code::NotFound { println!("Location data unavailable"); return Ok(()); } else { diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs index 3c3d55092f..601115003b 100644 --- a/mullvad-cli/src/cmds/tunnel.rs +++ b/mullvad-cli/src/cmds/tunnel.rs @@ -1,10 +1,10 @@ -use crate::{format::print_keygen_event, new_grpc_client, proto, Command, Error, Result}; +use crate::{format::print_keygen_event, new_rpc_client, Command, Error, Result}; use clap::value_t; -use proto::TunnelOptions; +use mullvad_management_interface::types::{Timestamp, TunnelOptions}; pub struct Tunnel; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Tunnel { fn name(&self) -> &'static str { "tunnel" @@ -165,26 +165,26 @@ impl Tunnel { async fn process_wireguard_mtu_set(matches: &clap::ArgMatches<'_>) -> Result<()> { let mtu = value_t!(matches.value_of("mtu"), u16).unwrap_or_else(|e| e.exit()); - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_wireguard_mtu(mtu as u32).await?; println!("Wireguard MTU has been updated"); Ok(()) } async fn process_wireguard_mtu_unset() -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_wireguard_mtu(0).await?; println!("Wireguard MTU has been unset"); Ok(()) } async fn process_wireguard_key_check() -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let key = rpc.get_wireguard_key(()).await; let key = match key { Ok(response) => Some(response.into_inner()), Err(status) => { - if status.code() == tonic::Code::NotFound { + if status.code() == mullvad_management_interface::Code::NotFound { None } else { return Err(Error::GrpcClientError(status)); @@ -208,7 +208,7 @@ impl Tunnel { } async fn process_wireguard_key_generate() -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let keygen_event = rpc.generate_wireguard_key(()).await?; print_keygen_event(&keygen_event.into_inner()); Ok(()) @@ -226,14 +226,14 @@ impl Tunnel { async fn process_wireguard_rotation_interval_set(matches: &clap::ArgMatches<'_>) -> Result<()> { let rotate_interval = value_t!(matches.value_of("interval"), u32).unwrap_or_else(|e| e.exit()); - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_wireguard_rotation_interval(rotate_interval).await?; println!("Set key rotation interval: {} hour(s)", rotate_interval); Ok(()) } async fn process_wireguard_rotation_interval_reset() -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.reset_wireguard_rotation_interval(()).await?; println!("Set key rotation interval: default"); Ok(()) @@ -264,7 +264,7 @@ impl Tunnel { } async fn get_tunnel_options() -> Result<TunnelOptions> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; Ok(rpc .get_settings(()) .await? @@ -274,7 +274,7 @@ impl Tunnel { } async fn process_openvpn_mssfix_unset() -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_openvpn_mssfix(0).await?; println!("mssfix parameter has been unset"); Ok(()) @@ -282,7 +282,7 @@ impl Tunnel { async fn process_openvpn_mssfix_set(matches: &clap::ArgMatches<'_>) -> Result<()> { let new_value = value_t!(matches.value_of("mssfix"), u16).unwrap_or_else(|e| e.exit()); - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_openvpn_mssfix(new_value as u32).await?; println!("mssfix parameter has been updated"); Ok(()) @@ -304,7 +304,7 @@ impl Tunnel { async fn process_ipv6_set(matches: &clap::ArgMatches<'_>) -> Result<()> { let enabled = matches.value_of("enable").unwrap() == "on"; - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; rpc.set_enable_ipv6(enabled).await?; if enabled { println!("Enabled IPv6"); @@ -314,7 +314,7 @@ impl Tunnel { Ok(()) } - fn format_key_timestamp(timestamp: &prost_types::Timestamp) -> String { + fn format_key_timestamp(timestamp: &Timestamp) -> String { chrono::NaiveDateTime::from_timestamp(timestamp.seconds, timestamp.nanos as u32).to_string() } } diff --git a/mullvad-cli/src/cmds/version.rs b/mullvad-cli/src/cmds/version.rs index 48b3e621ed..0d66411283 100644 --- a/mullvad-cli/src/cmds/version.rs +++ b/mullvad-cli/src/cmds/version.rs @@ -1,8 +1,8 @@ -use crate::{new_grpc_client, Command, Result}; +use crate::{new_rpc_client, Command, Result}; pub struct Version; -#[async_trait::async_trait] +#[mullvad_management_interface::async_trait] impl Command for Version { fn name(&self) -> &'static str { "version" @@ -14,7 +14,7 @@ impl Command for Version { } async fn run(&self, _: &clap::ArgMatches<'_>) -> Result<()> { - let mut rpc = new_grpc_client().await?; + let mut rpc = new_rpc_client().await?; let current_version = rpc.get_current_version(()).await?.into_inner(); println!("Current version: {}", current_version); let version_info = rpc.get_version_info(()).await?.into_inner(); diff --git a/mullvad-cli/src/format.rs b/mullvad-cli/src/format.rs index c2e71fce0f..4f69d05317 100644 --- a/mullvad-cli/src/format.rs +++ b/mullvad-cli/src/format.rs @@ -1,7 +1,7 @@ -use crate::proto::KeygenEvent; +use mullvad_management_interface::types::KeygenEvent; pub fn print_keygen_event(key_event: &KeygenEvent) { - use crate::proto::keygen_event::KeygenEvent as EventType; + use mullvad_management_interface::types::keygen_event::KeygenEvent as EventType; match EventType::from_i32(key_event.event).unwrap() { EventType::NewKey => { diff --git a/mullvad-cli/src/location.rs b/mullvad-cli/src/location.rs index 3d2705ae88..21e6a1c35c 100644 --- a/mullvad-cli/src/location.rs +++ b/mullvad-cli/src/location.rs @@ -1,4 +1,4 @@ -use crate::proto::RelayLocation; +use mullvad_management_interface::types::RelayLocation; pub fn get_subcommand() -> clap::App<'static, 'static> { clap::SubCommand::with_name("location") diff --git a/mullvad-cli/src/main.rs b/mullvad-cli/src/main.rs index 11309ff019..356a50ce69 100644 --- a/mullvad-cli/src/main.rs +++ b/mullvad-cli/src/main.rs @@ -1,10 +1,12 @@ #![deny(rust_2018_idioms)] -use async_trait::async_trait; use clap::{crate_authors, crate_description}; +use mullvad_management_interface::async_trait; use std::{collections::HashMap, io}; use talpid_types::ErrorExt; +pub use mullvad_management_interface::{self, new_rpc_client}; + mod cmds; mod format; mod location; @@ -14,47 +16,22 @@ pub const PRODUCT_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/produc pub type Result<T> = std::result::Result<T, Error>; -mod proto { - tonic::include_proto!("mullvad_daemon.management_interface"); -} -use proto::management_service_client::ManagementServiceClient; - -use parity_tokio_ipc::Endpoint as IpcEndpoint; -use tonic::{ - self, - transport::{Endpoint, Uri}, -}; -use tower::service_fn; - #[derive(err_derive::Error, Debug)] pub enum Error { #[error(display = "Failed to connect to daemon")] DaemonNotRunning(#[error(source)] io::Error), - #[error(display = "Failed to connect to mullvad-daemon over RPC")] - GrpcTransportError(#[error(source)] tonic::transport::Error), + #[error(display = "Management interface error")] + ManagementInterfaceError(#[error(source)] mullvad_management_interface::Error), #[error(display = "Failed to communicate with mullvad-daemon over RPC")] - GrpcClientError(#[error(source)] tonic::Status), + GrpcClientError(#[error(source)] mullvad_management_interface::Status), /// The given command is not correct in some way #[error(display = "Invalid command: {}", _0)] InvalidCommand(&'static str), } -pub async fn new_grpc_client() -> Result<ManagementServiceClient<tonic::transport::Channel>> { - let ipc_path = mullvad_paths::get_rpc_socket_path(); - - // The URI will be ignored - let channel = Endpoint::from_static("lttp://[::]:50051") - .connect_with_connector(service_fn(move |_: Uri| { - IpcEndpoint::connect(ipc_path.clone()) - })) - .await?; - - Ok(ManagementServiceClient::new(channel)) -} - #[tokio::main] async fn main() { let exit_code = match run().await { |
