summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-11-05 14:29:20 +0100
committerLinus Färnstrand <linus@mullvad.net>2018-11-05 14:29:20 +0100
commit2c983fbe1c2274a59edf871b00dab3dce1d20c88 (patch)
tree0df0b2afeab28787707dc21f5ef518db4baf5870
parent777d4916b8ce9e80372f4812067c341e7acd78a2 (diff)
parentf1c66472036682e502cdd264805ae45102c4080f (diff)
downloadmullvadvpn-2c983fbe1c2274a59edf871b00dab3dce1d20c88.tar.xz
mullvadvpn-2c983fbe1c2274a59edf871b00dab3dce1d20c88.zip
Merge branch 'update-relay-list-from-cli'
-rw-r--r--CHANGELOG.md1
-rw-r--r--mullvad-cli/src/cmds/relay.rs20
-rw-r--r--mullvad-daemon/src/lib.rs4
-rw-r--r--mullvad-daemon/src/management_interface.rs12
-rw-r--r--mullvad-daemon/src/relays.rs22
-rw-r--r--mullvad-ipc-client/src/lib.rs4
6 files changed, 43 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5217cb8bfd..5f4795142d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,7 @@ Line wrap the file at 100 chars. Th
- Allow the user to view the relay in/out IP address in the GUI.
- Add OpenVPN proxy support via CLI.
- Allow DHCPv6 in the firewall.
+- CLI command `relay update` that triggers an update of the relay list in the daemon.
### Fixed
- Pick new random relay for each reconnect attempt instead of just retrying with the same one.
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-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs
index dab1b50407..de01883e58 100644
--- a/mullvad-daemon/src/relays.rs
+++ b/mullvad-daemon/src/relays.rs
@@ -28,7 +28,6 @@ const DATE_TIME_FORMAT_STR: &str = "[%Y-%m-%d %H:%M:%S%.3f]";
const RELAYS_FILENAME: &str = "relays.json";
const DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15);
const UPDATE_INTERVAL: Duration = Duration::from_secs(60 * 60);
-const MAX_CACHE_AGE: Duration = Duration::from_secs(60 * 60 * 2);
error_chain! {
errors {
@@ -426,14 +425,12 @@ impl RelayListUpdater {
debug!("Starting relay list updater thread");
while self.wait_for_next_iteration() {
trace!("Relay list updater iteration");
- if self.should_update() {
- match self
- .update()
- .chain_err(|| "Failed to update list of relays")
- {
- Ok(()) => info!("Updated list of relays"),
- Err(error) => error!("{}", error.display_chain()),
- }
+ match self
+ .update()
+ .chain_err(|| "Failed to update list of relays")
+ {
+ Ok(()) => info!("Updated list of relays"),
+ Err(error) => error!("{}", error.display_chain()),
}
}
debug!("Relay list updater thread has finished");
@@ -449,13 +446,6 @@ impl RelayListUpdater {
}
}
- fn should_update(&mut self) -> bool {
- match SystemTime::now().duration_since(self.lock_parsed_relays().last_updated()) {
- Ok(duration) => duration > MAX_CACHE_AGE,
- Err(_) => false,
- }
- }
-
fn update(&mut self) -> Result<()> {
let new_relay_list = self
.download_relay_list()
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)
}