summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock12
-rw-r--r--mullvad-daemon/Cargo.toml2
-rw-r--r--mullvad-daemon/src/relays.rs23
3 files changed, 14 insertions, 23 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d9269977d8..6074e9b516 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -854,7 +854,7 @@ dependencies = [
"talpid-ipc 0.1.0",
"talpid-types 0.1.0",
"tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
- "tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tokio-timer 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"windows-service 0.1.0 (git+https://github.com/mullvad/windows-service-rs.git?rev=55c5dfb372e6b3f5607a3159c5388d27b6b84ff6)",
@@ -1761,15 +1761,6 @@ dependencies = [
[[package]]
name = "tokio-timer"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
- "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "tokio-timer"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
@@ -2200,7 +2191,6 @@ source = "git+https://github.com/mullvad/rust-openssl#4dbd237fe1f6454d8a0042ccf4
"checksum tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24da22d077e0f15f55162bdbdc661228c1581892f52074fb242678d015b45162"
"checksum tokio-tcp 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5b4c329b47f071eb8a746040465fa751bd95e4716e98daef6a9b4e434c17d565"
"checksum tokio-threadpool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "24ab84f574027b0e875378f31575cf175360891919e93a3490f07e76e00e4efb"
-"checksum tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6131e780037787ff1b3f8aad9da83bca02438b72277850dd6ad0d455e0e20efc"
"checksum tokio-timer 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1c76b4e97a4f61030edff8bd272364e4f731b9f54c7307eb4eb733c3926eb96a"
"checksum tokio-udp 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43eb534af6e8f37d43ab1b612660df14755c42bd003c5f8d2475ee78cc4600c0"
"checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2"
diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml
index cfb910603a..147bc0b1e1 100644
--- a/mullvad-daemon/Cargo.toml
+++ b/mullvad-daemon/Cargo.toml
@@ -22,7 +22,7 @@ uuid = { version = "0.6", features = ["v4"] }
lazy_static = "1.0"
rand = "0.5"
tokio-core = "0.1"
-tokio-timer = "0.1"
+tokio-timer = "0.2"
regex = "1.0"
mullvad-ipc-client = { path = "../mullvad-ipc-client" }
diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs
index ef81adc4fa..4dbed24d6a 100644
--- a/mullvad-daemon/src/relays.rs
+++ b/mullvad-daemon/src/relays.rs
@@ -17,12 +17,11 @@ use std::fs::File;
use std::net::IpAddr;
use std::path::{Path, PathBuf};
use std::sync::{mpsc, Arc, Mutex, MutexGuard};
-use std::time::{self, Duration, SystemTime};
+use std::time::{self, Duration, Instant, SystemTime};
use std::{io, thread};
-use rand::distributions::{IndependentSample, Range};
use rand::{self, Rng, ThreadRng};
-use tokio_timer::{TimeoutError, Timer};
+use tokio_timer::{Deadline, DeadlineError};
const RELAYS_FILENAME: &str = "relays.json";
const DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15);
@@ -33,15 +32,18 @@ error_chain! {
errors {
RelayCacheError { description("Error with relay cache on disk") }
DownloadError { description("Error when trying to download the list of relays") }
- TimeoutError { description("Timed out when trying to download the list of relays") }
+ DeadlineError { description("Timed out when trying to download the list of relays") }
NoRelay { description("No relays matching current constraints") }
SerializationError { description("Error in serialization of relaylist") }
}
}
-impl<F> From<TimeoutError<F>> for Error {
- fn from(_: TimeoutError<F>) -> Error {
- Error::from_kind(ErrorKind::TimeoutError)
+impl From<DeadlineError<Error>> for Error {
+ fn from(e: DeadlineError<Error>) -> Error {
+ match e.into_inner() {
+ Some(inner_e) => inner_e,
+ None => Error::from_kind(ErrorKind::DeadlineError),
+ }
}
}
@@ -308,7 +310,7 @@ impl RelaySelector {
None
} else {
// Pick a random number in the range 0 - total_weight. This choses the relay.
- let mut i: u64 = Range::new(0, total_weight + 1).ind_sample(&mut self.rng);
+ let mut i: u64 = self.rng.gen_range(0, total_weight + 1);
Some(
relays
.iter()
@@ -435,13 +437,12 @@ impl RelayListUpdater {
fn download_relay_list(&mut self) -> Result<RelayList> {
info!("Downloading list of relays...");
+ let timeout_instant = Instant::now() + DOWNLOAD_TIMEOUT;
let download_future = self
.rpc_client
.relay_list()
.map_err(|e| Error::with_chain(e, ErrorKind::DownloadError));
- let relay_list = Timer::default()
- .timeout(download_future, DOWNLOAD_TIMEOUT)
- .wait()?;
+ let relay_list = Deadline::new(download_future, timeout_instant).wait()?;
Ok(relay_list)
}