summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-12-19 11:18:16 +0100
committerLinus Färnstrand <linus@mullvad.net>2018-12-19 11:18:16 +0100
commit4515c9a1bae88cbb07c607c460e06da3b5c980db (patch)
treeaf3631d3fa7a9e850e62717bbbda537f6b357554
parent37892d25daa0396a6a31c6dab634d0bbf3bcc6d8 (diff)
parentaf301a46b07fd18d1c569f2cd92816ffabd0c83c (diff)
downloadmullvadvpn-4515c9a1bae88cbb07c607c460e06da3b5c980db.tar.xz
mullvadvpn-4515c9a1bae88cbb07c607c460e06da3b5c980db.zip
Merge branch 'fix-sleep-related-relay-list-update-issues'
-rw-r--r--CHANGELOG.md1
-rw-r--r--mullvad-daemon/src/relays.rs34
2 files changed, 26 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2fa35dbbb6..ac3ffc31c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,7 @@ Line wrap the file at 100 chars. Th
- Stop GUI from glitching during the short reconnect state.
- Dismiss notifications automatically after four seconds in all platforms.
- Fix error printed from the CLI when issuing `relay update`.
+- Fix relay list update interval. Should now handle sleep better.
## [2018.6-beta1] - 2018-12-05
diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs
index a2c43d3b0a..7cdd6d61ee 100644
--- a/mullvad-daemon/src/relays.rs
+++ b/mullvad-daemon/src/relays.rs
@@ -33,7 +33,12 @@ use tokio_timer::{TimeoutError, Timer};
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);
+/// How often the updater should wake up to check the cache of the in-memory cache of relays.
+/// This check is very cheap. The only reason to not have it very often is because if downloading
+/// constantly fails it will try very often and fill the logs etc.
+const UPDATE_CHECK_INTERVAL: Duration = Duration::from_secs(60 * 2);
+/// How old the cached relays need to be to trigger an update
+const UPDATE_INTERVAL: Duration = Duration::from_secs(3600);
error_chain! {
errors {
@@ -436,13 +441,14 @@ impl RelayListUpdater {
fn run(&mut self) {
debug!("Starting relay list updater thread");
while self.wait_for_next_iteration() {
- trace!("Relay list updater iteration");
- match self
- .update()
- .chain_err(|| "Failed to update list of relays")
- {
- Ok(()) => info!("Updated list of relays"),
- Err(error) => error!("{}", error.display_chain()),
+ 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()),
+ }
}
}
debug!("Relay list updater thread has finished");
@@ -451,13 +457,23 @@ impl RelayListUpdater {
fn wait_for_next_iteration(&mut self) -> bool {
use self::mpsc::RecvTimeoutError::*;
- match self.close_handle.recv_timeout(UPDATE_INTERVAL) {
+ match self.close_handle.recv_timeout(UPDATE_CHECK_INTERVAL) {
Ok(()) => true,
Err(Timeout) => true,
Err(Disconnected) => false,
}
}
+ fn should_update(&mut self) -> bool {
+ match SystemTime::now().duration_since(self.lock_parsed_relays().last_updated()) {
+ Ok(duration) => duration > UPDATE_INTERVAL,
+ // If the clock is skewed we have no idea by how much or when the last update
+ // actually was, better download again to get in sync and get a `last_updated`
+ // timestamp corresponding to the new time.
+ Err(_) => true,
+ }
+ }
+
fn update(&mut self) -> Result<()> {
let new_relay_list = self
.download_relay_list()