diff options
Diffstat (limited to 'crates/arti-client')
| -rw-r--r-- | crates/arti-client/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/arti-client/src/builder.rs | 11 | ||||
| -rw-r--r-- | crates/arti-client/src/status.rs | 9 |
3 files changed, 10 insertions, 11 deletions
diff --git a/crates/arti-client/Cargo.toml b/crates/arti-client/Cargo.toml index 69a14e72c..6c2235473 100644 --- a/crates/arti-client/Cargo.toml +++ b/crates/arti-client/Cargo.toml @@ -215,6 +215,7 @@ tor-rtcompat = { path = "../tor-rtcompat", version = "0.40.0" } tracing = "0.1.36" visibility = { version = "0.1.0", optional = true } void = "1" +web-time-compat = { path = "../web-time-compat", version = "0.1.0" } # TODO wasm: Remove this once there is a supported wasm StateMgr. [target.'cfg(all(target_arch="wasm32", target_os="unknown"))'.dependencies] diff --git a/crates/arti-client/src/builder.rs b/crates/arti-client/src/builder.rs index 0fea83741..2520658d3 100644 --- a/crates/arti-client/src/builder.rs +++ b/crates/arti-client/src/builder.rs @@ -5,15 +5,12 @@ use crate::{ BootstrapBehavior, InertTorClient, Result, TorClient, TorClientConfig, err::ErrorDetail, }; -use std::{ - result::Result as StdResult, - sync::Arc, - time::{Duration, Instant}, -}; +use std::{result::Result as StdResult, sync::Arc}; use tor_dirmgr::{DirMgrConfig, DirMgrStore}; use tor_error::{ErrorKind, HasKind as _}; use tor_rtcompat::Runtime; use tracing::instrument; +use web_time_compat::{Duration, Instant, InstantExt}; /// An object that knows how to construct some kind of DirProvider. /// @@ -187,11 +184,11 @@ impl<R: Runtime> TorClientBuilder<R> { #[instrument(skip_all, level = "trace")] pub fn create_unbootstrapped(&self) -> Result<TorClient<R>> { let timeout = self.local_resource_timeout_or(Duration::from_millis(0))?; - let give_up_at = Instant::now() + timeout; + let give_up_at = Instant::get() + timeout; let mut first_attempt = true; loop { - match self.create_unbootstrapped_inner(Instant::now, give_up_at, first_attempt) { + match self.create_unbootstrapped_inner(Instant::get, give_up_at, first_attempt) { Err(delay) => { first_attempt = false; std::thread::sleep(delay); diff --git a/crates/arti-client/src/status.rs b/crates/arti-client/src/status.rs index 36e12ce51..2fb131a1b 100644 --- a/crates/arti-client/src/status.rs +++ b/crates/arti-client/src/status.rs @@ -1,7 +1,7 @@ //! Code to collect and publish information about a client's bootstrapping //! status. -use std::{borrow::Cow, fmt, fmt::Display, time::SystemTime}; +use std::{borrow::Cow, fmt, fmt::Display}; use educe::Educe; use futures::{Stream, StreamExt}; @@ -10,6 +10,7 @@ use tor_chanmgr::{ConnBlockage, ConnStatus, ConnStatusEvents}; use tor_circmgr::{ClockSkewEvents, SkewEstimate}; use tor_dirmgr::{DirBlockage, DirBootstrapStatus}; use tracing::debug; +use web_time_compat::{SystemTime, SystemTimeExt}; /// Information about how ready a [`crate::TorClient`] is to handle requests. /// @@ -40,7 +41,7 @@ impl BootstrapStatus { /// 0 is defined as "just started"; 1 is defined as "ready to use." pub fn as_frac(&self) -> f32 { // Coefficients chosen arbitrarily. - self.conn_status.frac() * 0.15 + self.dir_status.frac_at(SystemTime::now()) * 0.85 + self.conn_status.frac() * 0.15 + self.dir_status.frac_at(SystemTime::get()) * 0.85 } /// Return true if the status indicates that the client is ready for @@ -49,7 +50,7 @@ impl BootstrapStatus { /// For the purposes of this function, the client is "ready for traffic" if, /// as far as we know, we can start acting on a new client request immediately. pub fn ready_for_traffic(&self) -> bool { - let now = SystemTime::now(); + let now = SystemTime::get(); self.conn_status.usable() && self.dir_status.usable_at(now) } @@ -84,7 +85,7 @@ impl BootstrapStatus { } else { Some(Blockage { kind, message }) } - } else if let Some(b) = self.dir_status.blockage(SystemTime::now()) { + } else if let Some(b) = self.dir_status.blockage(SystemTime::get()) { let message = b.to_string().into(); let kind = b.into(); Some(Blockage { kind, message }) |
