diff options
Diffstat (limited to 'crates/tor-guardmgr/src/guard.rs')
| -rw-r--r-- | crates/tor-guardmgr/src/guard.rs | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/crates/tor-guardmgr/src/guard.rs b/crates/tor-guardmgr/src/guard.rs index 6e876340b..1fa6b2d52 100644 --- a/crates/tor-guardmgr/src/guard.rs +++ b/crates/tor-guardmgr/src/guard.rs @@ -6,8 +6,8 @@ use itertools::Itertools; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::net::SocketAddr; -use std::time::{Duration, Instant, SystemTime}; use tracing::{info, trace, warn}; +use web_time_compat::{Duration, Instant, InstantExt, SystemTime}; use crate::dirstatus::DirStatus; use crate::sample::Candidate; @@ -448,7 +448,7 @@ impl Guard { Some(retry_at) => warn!( "Could not connect to guard {}. Retrying in {}.", self, - humantime::format_duration(retry_at - Instant::now()), + humantime::format_duration(retry_at - Instant::get()), ), None => warn!( "Could not connect to guard {}. Next retry time unknown.", @@ -951,6 +951,7 @@ mod test { use crate::ids::FirstHopId; use tor_linkspec::{HasRelayIds, RelayId}; use tor_llcrypto::pk::ed25519::Ed25519Identity; + use web_time_compat::SystemTimeExt; #[test] fn crate_id() { @@ -965,7 +966,7 @@ mod test { fn basic_guard() -> Guard { let id = basic_id(); let ports = vec!["127.0.0.7:7777".parse().unwrap()]; - let added = SystemTime::now(); + let added = SystemTime::get(); Guard::new(id, ports, None, added) } @@ -1055,9 +1056,9 @@ mod test { #[test] fn record_attempt() { - let t1 = Instant::now() - Duration::from_secs(10); - let t2 = Instant::now() - Duration::from_secs(5); - let t3 = Instant::now(); + let t1 = Instant::get() - Duration::from_secs(10); + let t2 = Instant::get() - Duration::from_secs(5); + let t3 = Instant::get(); let mut g = basic_guard(); @@ -1072,8 +1073,8 @@ mod test { #[test] fn record_failure() { - let t1 = Instant::now() - Duration::from_secs(10); - let t2 = Instant::now(); + let t1 = Instant::get() - Duration::from_secs(10); + let t2 = Instant::get(); let mut g = basic_guard(); g.record_failure(t1, true); @@ -1090,11 +1091,11 @@ mod test { #[test] fn record_success() { - let t1 = Instant::now() - Duration::from_secs(10); + let t1 = Instant::get() - Duration::from_secs(10); // has to be in the future, since the guard's "added_at" time is based on now. - let now = SystemTime::now(); + let now = SystemTime::get(); let t2 = now + Duration::from_secs(300 * 86400); - let t3 = Instant::now() + Duration::from_secs(310 * 86400); + let t3 = Instant::get() + Duration::from_secs(310 * 86400); let t4 = now + Duration::from_secs(320 * 86400); let mut g = basic_guard(); @@ -1121,7 +1122,7 @@ mod test { #[test] fn retry() { - let t1 = Instant::now(); + let t1 = Instant::get(); let mut g = basic_guard(); g.record_failure(t1, true); @@ -1148,7 +1149,7 @@ mod test { fn expiration() { const DAY: Duration = Duration::from_secs(24 * 60 * 60); let params = GuardParams::default(); - let now = SystemTime::now(); + let now = SystemTime::get(); let g = basic_guard(); assert!(!g.is_expired(¶ms, now)); @@ -1176,7 +1177,7 @@ mod test { use tor_netdir::testnet; let netdir = testnet::construct_netdir().unwrap_if_sufficient().unwrap(); let params = GuardParams::default(); - let now = SystemTime::now(); + let now = SystemTime::get(); // Construct a guard from a relay from the netdir. let relay22 = netdir.by_id(&Ed25519Identity::from([22; 32])).unwrap(); @@ -1226,7 +1227,7 @@ mod test { .unwrap(); //let params = GuardParams::default(); - let now = SystemTime::now(); + let now = SystemTime::get(); // Try a guard that isn't in the netdir at all. let mut guard255 = Guard::new( @@ -1283,7 +1284,7 @@ mod test { #[test] fn pending() { let mut g = basic_guard(); - let t1 = Instant::now(); + let t1 = Instant::get(); let t2 = t1 + Duration::from_secs(100); let t3 = t1 + Duration::from_secs(200); @@ -1320,7 +1321,7 @@ mod test { let mut g = basic_guard(); let params = GuardParams::default(); - let now = SystemTime::now(); + let now = SystemTime::get(); let _ignore = g.record_success(now, ¶ms); for _ in 0..13 { @@ -1374,8 +1375,8 @@ mod test { use crate::GuardUsageBuilder; let mut g = basic_guard(); - let inst = Instant::now(); - let st = SystemTime::now(); + let inst = Instant::get(); + let st = SystemTime::get(); let sec = Duration::from_secs(1); let params = GuardParams::default(); let dir_usage = GuardUsageBuilder::new() |
