diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-08-10 11:15:17 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-08-10 15:52:41 +0200 |
| commit | 380f8cd8ec9d2d37801f9cc8f2b77216feed8ea6 (patch) | |
| tree | 897b3cf0bfb8d661e8479dcb3747e27fbb25f01e /mullvad-daemon/src | |
| parent | 584dd808340b27b991db55b169a6ac1a0c4ac8d4 (diff) | |
| download | mullvadvpn-380f8cd8ec9d2d37801f9cc8f2b77216feed8ea6.tar.xz mullvadvpn-380f8cd8ec9d2d37801f9cc8f2b77216feed8ea6.zip | |
Upgrade tokio-timer
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 23 |
1 files changed, 12 insertions, 11 deletions
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) } |
