diff options
Diffstat (limited to 'crates/tor-hsservice/src')
| -rw-r--r-- | crates/tor-hsservice/src/internal_prelude.rs | 2 | ||||
| -rw-r--r-- | crates/tor-hsservice/src/pow/v1.rs | 10 | ||||
| -rw-r--r-- | crates/tor-hsservice/src/publish.rs | 1 | ||||
| -rw-r--r-- | crates/tor-hsservice/src/publish/reupload_timer.rs | 4 | ||||
| -rw-r--r-- | crates/tor-hsservice/src/rend_handshake.rs | 8 | ||||
| -rw-r--r-- | crates/tor-hsservice/src/time_store.rs | 7 | ||||
| -rw-r--r-- | crates/tor-hsservice/src/timeout_track.rs | 5 |
7 files changed, 19 insertions, 18 deletions
diff --git a/crates/tor-hsservice/src/internal_prelude.rs b/crates/tor-hsservice/src/internal_prelude.rs index ed17f48bd..f3e3f77c9 100644 --- a/crates/tor-hsservice/src/internal_prelude.rs +++ b/crates/tor-hsservice/src/internal_prelude.rs @@ -37,7 +37,6 @@ pub(crate) use { std::path::{Path, PathBuf}, std::str::FromStr, std::sync::{Arc, Mutex, MutexGuard}, - std::time::{Duration, Instant, SystemTime}, }; //---------- upstreams ---------- @@ -110,6 +109,7 @@ pub(crate) use { tor_proto::client::stream::DataStream, tor_rtcompat::SleepProvider, tor_rtcompat::{Runtime, SleepProviderExt as _}, + web_time_compat::{Duration, Instant, SystemTime}, }; //---------- names from this crate ---------- diff --git a/crates/tor-hsservice/src/pow/v1.rs b/crates/tor-hsservice/src/pow/v1.rs index e791f0bb5..b92972491 100644 --- a/crates/tor-hsservice/src/pow/v1.rs +++ b/crates/tor-hsservice/src/pow/v1.rs @@ -8,7 +8,6 @@ use std::{ collections::{BTreeSet, HashMap, VecDeque}, sync::{Arc, Mutex, RwLock}, task::Waker, - time::{Duration, Instant, SystemTime}, }; use arrayvec::ArrayVec; @@ -39,6 +38,7 @@ use tor_persist::{ }; use tor_rtcompat::Runtime; use tor_rtcompat::SpawnExt; +use web_time_compat::{Duration, Instant, InstantExt, SystemTime, SystemTimeExt}; use crate::{ BlindIdPublicKeySpecifier, OnionServiceConfig, RendRequest, ReplayError, StartupError, @@ -426,7 +426,7 @@ impl<R: Runtime, Q: MockableRendRequest + Send + 'static> PowManagerGeneric<R, Q .checked_sub(SEED_EARLY_ROTATION_TIME) .expect("SEED_EARLY_ROTATION_TIME too high, or EXPIRATION_TIME_MINS_MIN too low."); let delay = next_update_time - .map(|x| x.duration_since(SystemTime::now()).unwrap_or(MAX_DELAY)) + .map(|x| x.duration_since(SystemTime::get()).unwrap_or(MAX_DELAY)) .unwrap_or(MAX_DELAY) .min(MAX_DELAY) .min(suggested_effort_update_delay); @@ -439,7 +439,7 @@ impl<R: Runtime, Q: MockableRendRequest + Send + 'static> PowManagerGeneric<R, Q /// Make a randomized seed expiration time. fn make_next_expiration_time<Rng: RngCore + CryptoRng>(rng: &mut Rng) -> SystemTime { - SystemTime::now() + SystemTime::get() + Duration::from_secs( 60 * rng .gen_range_checked(EXPIRATION_TIME_MINS_MIN..=EXPIRATION_TIME_MINS_MAX) @@ -519,7 +519,7 @@ impl<R: Runtime, Q: MockableRendRequest + Send + 'static> PowManagerGeneric<R, Q let rotation_time = Self::calculate_early_rotation_time(info.next_expiration_time); update_times.push(rotation_time); - if rotation_time <= SystemTime::now() { + if rotation_time <= SystemTime::get() { // This does not allow for easy testing, but because we're in a async function, it's // non-trivial to pass in a Rng from the outside world. If we end up writing tests that // require that, we can take a function to generate a Rng, but for now, just using the @@ -774,7 +774,7 @@ impl<Q: MockableRendRequest> RendRequestOrdByEffort<Q> { request, pow, max_effort, - recv_time: Instant::now(), + recv_time: Instant::get(), request_num, }) } diff --git a/crates/tor-hsservice/src/publish.rs b/crates/tor-hsservice/src/publish.rs index bb0040316..2ee1b9a56 100644 --- a/crates/tor-hsservice/src/publish.rs +++ b/crates/tor-hsservice/src/publish.rs @@ -169,7 +169,6 @@ mod test { use std::sync::Mutex; use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::{Context, Poll}; - use std::time::Duration; use async_trait::async_trait; use fs_mistrust::Mistrust; diff --git a/crates/tor-hsservice/src/publish/reupload_timer.rs b/crates/tor-hsservice/src/publish/reupload_timer.rs index 565895d9f..60c2a7e79 100644 --- a/crates/tor-hsservice/src/publish/reupload_timer.rs +++ b/crates/tor-hsservice/src/publish/reupload_timer.rs @@ -53,15 +53,15 @@ mod test { #![allow(clippy::needless_pass_by_value)] //! <!-- @@ end test lint list maintained by maint/add_warning @@ --> use std::collections::BinaryHeap; - use std::time::Duration; use super::*; + use web_time_compat::InstantExt; #[test] fn reupload_for_time_period_ordering() { const ONE_SEC: Duration = Duration::from_secs(1); - let now = Instant::now(); + let now = Instant::get(); let later = now + ONE_SEC; let later_still = now + ONE_SEC * 2; let timer1 = ReuploadTimer { diff --git a/crates/tor-hsservice/src/rend_handshake.rs b/crates/tor-hsservice/src/rend_handshake.rs index ea1599b6c..c4e6f9141 100644 --- a/crates/tor-hsservice/src/rend_handshake.rs +++ b/crates/tor-hsservice/src/rend_handshake.rs @@ -176,10 +176,10 @@ pub(crate) trait RendCircConnector: Send + Sync { /// Return the current time instant from the runtime. /// /// This provides mockable time for use in error tracking. - fn now(&self) -> std::time::Instant; + fn now(&self) -> Instant; /// Return the current wall-clock time from the runtime. - fn wallclock(&self) -> std::time::SystemTime; + fn wallclock(&self) -> SystemTime; } #[async_trait] @@ -192,11 +192,11 @@ impl<R: Runtime> RendCircConnector for HsCircPool<R> { HsCircPool::get_or_launch_svc_rend(self, netdir, target).await } - fn now(&self) -> std::time::Instant { + fn now(&self) -> Instant { HsCircPool::now(self) } - fn wallclock(&self) -> std::time::SystemTime { + fn wallclock(&self) -> SystemTime { HsCircPool::wallclock(self) } } diff --git a/crates/tor-hsservice/src/time_store.rs b/crates/tor-hsservice/src/time_store.rs index 54be02664..cf3e247bf 100644 --- a/crates/tor-hsservice/src/time_store.rs +++ b/crates/tor-hsservice/src/time_store.rs @@ -26,8 +26,8 @@ //! //! ``` //! use serde::{Serialize, Deserialize}; -//! use std::time::{Duration, Instant}; //! use tor_rtcompat::{PreferredRuntime, SleepProvider as _}; +//! use web_time_compat::{Duration, Instant}; //! //! # use tor_hsservice::time_store_for_doctests_unstable_no_semver_guarantees as time_store; //! # #[cfg(all)] // works like #[cfg(FALSE)]. Instead, we have this workaround ^. @@ -80,7 +80,7 @@ use std::fmt::{self, Display}; use std::str::FromStr; -use std::time::{Duration, Instant, SystemTime}; +use web_time_compat::{Duration, Instant, SystemTime}; use derive_deftly::{Deftly, define_derive_deftly}; use serde::{Deserialize, Serialize}; @@ -492,6 +492,7 @@ mod test { use humantime::parse_rfc3339; use itertools::{Itertools, chain}; use tor_rtmock::{MockRuntime, simple_time::SimpleMockTimeProvider}; + use web_time_compat::InstantExt; fn secs(s: u64) -> Duration { Duration::from_secs(s) @@ -561,7 +562,7 @@ mod test { s2: FutureTimestamp, } - let real_instant = Instant::now(); + let real_instant = Instant::get(); let test_systime = parse_rfc3339("2008-08-02T00:00:00Z").unwrap(); let mk_runtime = |instant, systime| { diff --git a/crates/tor-hsservice/src/timeout_track.rs b/crates/tor-hsservice/src/timeout_track.rs index f6fd2ab2f..65a747dd7 100644 --- a/crates/tor-hsservice/src/timeout_track.rs +++ b/crates/tor-hsservice/src/timeout_track.rs @@ -147,7 +147,7 @@ use std::cell::Cell; use std::cmp::Ordering; -use std::time::{Duration, Instant, SystemTime}; +use web_time_compat::{Duration, Instant, SystemTime}; use derive_deftly::{Deftly, define_derive_deftly}; use futures::{FutureExt as _, future, select_biased}; @@ -634,6 +634,7 @@ mod test { use std::task::Poll; use tor_rtcompat::ToplevelBlockOn; use tor_rtmock::MockRuntime; + use web_time_compat::InstantExt; fn parse_rfc3339(s: &str) -> SystemTime { humantime::parse_rfc3339(s).unwrap() @@ -715,7 +716,7 @@ mod test { #[test] fn arith_instant_combined() { // Adding 1Ms gives us some headroom, since we don't want to underflow - let earliest = Instant::now() + secs(1000000); + let earliest = Instant::get() + secs(1000000); let middle_d = secs(200); let middle = earliest + middle_d; let later_d = secs(300); |
