diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-11-05 13:54:54 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-11-05 13:54:54 +0100 |
| commit | 3ab939af52a66b84a195b0758ae81f62e2fa7250 (patch) | |
| tree | e252298458f95fb8309babb8d44eb198350cae06 | |
| parent | 52cdd81d77d4922945ec4598f6799671d92b0823 (diff) | |
| download | mullvadvpn-3ab939af52a66b84a195b0758ae81f62e2fa7250.tar.xz mullvadvpn-3ab939af52a66b84a195b0758ae81f62e2fa7250.zip | |
Add CLI command for making daemon update relay list
| -rw-r--r-- | mullvad-cli/src/cmds/relay.rs | 20 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 4 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 12 | ||||
| -rw-r--r-- | mullvad-ipc-client/src/lib.rs | 4 |
4 files changed, 36 insertions, 4 deletions
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs index f6838427ec..9f12f8af33 100644 --- a/mullvad-cli/src/cmds/relay.rs +++ b/mullvad-cli/src/cmds/relay.rs @@ -100,15 +100,21 @@ impl Command for Relay { .subcommand( clap::SubCommand::with_name("list").about("List available countries and cities"), ) + .subcommand( + clap::SubCommand::with_name("update") + .about("Update the list of available countries and cities"), + ) } fn run(&self, matches: &clap::ArgMatches) -> Result<()> { if let Some(set_matches) = matches.subcommand_matches("set") { self.set(set_matches) - } else if let Some(_) = matches.subcommand_matches("get") { + } else if matches.subcommand_matches("get").is_some() { self.get() - } else if let Some(list_matches) = matches.subcommand_matches("list") { - self.list(list_matches) + } else if matches.subcommand_matches("list").is_some() { + self.list() + } else if matches.subcommand_matches("update").is_some() { + self.update() } else { unreachable!("No relay command given"); } @@ -210,7 +216,7 @@ impl Relay { Ok(()) } - fn list(&self, _matches: &clap::ArgMatches) -> Result<()> { + fn list(&self) -> Result<()> { let mut rpc = new_rpc_client()?; let mut locations = rpc.get_relay_locations()?; locations.countries.sort_by(|c1, c2| c1.name.cmp(&c2.name)); @@ -227,6 +233,12 @@ impl Relay { } Ok(()) } + + fn update(&self) -> Result<()> { + new_rpc_client()?.update_relay_locations()?; + println!("Updating relay list in the background..."); + Ok(()) + } } diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 058466b04e..c24982db20 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -419,6 +419,7 @@ impl Daemon { GetCurrentLocation(tx) => self.on_get_current_location(tx), GetAccountData(tx, account_token) => self.on_get_account_data(tx, account_token), GetRelayLocations(tx) => self.on_get_relay_locations(tx), + UpdateRelayLocations => self.on_update_relay_locations(), SetAccount(tx, account_token) => self.on_set_account(tx, account_token), UpdateRelaySettings(tx, update) => self.on_update_relay_settings(tx, update), SetAllowLan(tx, allow_lan) => self.on_set_allow_lan(tx, allow_lan), @@ -523,6 +524,9 @@ impl Daemon { Self::oneshot_send(tx, self.relay_selector.get_locations(), "relay locations"); } + fn on_update_relay_locations(&mut self) { + self.relay_selector.update(); + } fn on_set_account(&mut self, tx: oneshot::Sender<()>, account_token: Option<String>) { let account_token_cleared = account_token.is_none(); diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 3e204245ae..227852e85f 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -48,6 +48,10 @@ build_rpc_trait! { #[rpc(meta, name = "get_relay_locations")] fn get_relay_locations(&self, Self::Metadata) -> BoxFuture<RelayList, Error>; + /// Triggers a relay list update + #[rpc(meta, name = "update_relay_locations")] + fn update_relay_locations(&self, Self::Metadata) -> BoxFuture<(), Error>; + /// Set which account to connect with. #[rpc(meta, name = "set_account")] fn set_account(&self, Self::Metadata, Option<AccountToken>) -> BoxFuture<(), Error>; @@ -165,6 +169,9 @@ pub enum ManagementCommand { ), /// Get the list of countries and cities where there are relays. GetRelayLocations(OneshotSender<RelayList>), + /// Trigger an asynchronous relay list update. This returns before the relay list is actually + /// updated. + UpdateRelayLocations, /// Set which account token to use for subsequent connection attempts. SetAccount(OneshotSender<()>, Option<AccountToken>), /// Place constraints on the type of tunnel and relay @@ -396,6 +403,11 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi Box::new(future) } + fn update_relay_locations(&self, _: Self::Metadata) -> BoxFuture<(), Error> { + log::debug!("update_relay_locations"); + self.send_command_to_daemon(ManagementCommand::UpdateRelayLocations) + } + fn set_account( &self, _: Self::Metadata, diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs index 9b20899ab2..c38f6d4fc1 100644 --- a/mullvad-ipc-client/src/lib.rs +++ b/mullvad-ipc-client/src/lib.rs @@ -167,6 +167,10 @@ impl DaemonRpcClient { self.call("get_relay_locations", &NO_ARGS) } + pub fn update_relay_locations(&mut self) -> Result<RelayList> { + self.call("update_relay_locations", &NO_ARGS) + } + pub fn get_relay_settings(&mut self) -> Result<RelaySettings> { self.call("get_relay_settings", &NO_ARGS) } |
