summaryrefslogtreecommitdiff
path: root/crates/tor-circmgr
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tor-circmgr')
-rw-r--r--crates/tor-circmgr/Cargo.toml1
-rw-r--r--crates/tor-circmgr/src/build.rs2
-rw-r--r--crates/tor-circmgr/src/err.rs3
-rw-r--r--crates/tor-circmgr/src/hspool.rs6
-rw-r--r--crates/tor-circmgr/src/hspool/pool.rs2
-rw-r--r--crates/tor-circmgr/src/impls.rs3
-rw-r--r--crates/tor-circmgr/src/lib.rs5
-rw-r--r--crates/tor-circmgr/src/mgr.rs5
-rw-r--r--crates/tor-circmgr/src/mocks.rs3
-rw-r--r--crates/tor-circmgr/src/path/exitpath.rs7
-rw-r--r--crates/tor-circmgr/src/path/hspath.rs7
-rw-r--r--crates/tor-circmgr/src/preemptive.rs14
-rw-r--r--crates/tor-circmgr/src/usage.rs5
13 files changed, 37 insertions, 26 deletions
diff --git a/crates/tor-circmgr/Cargo.toml b/crates/tor-circmgr/Cargo.toml
index 6b1380a6e..e28361d92 100644
--- a/crates/tor-circmgr/Cargo.toml
+++ b/crates/tor-circmgr/Cargo.toml
@@ -114,6 +114,7 @@ tracing = "0.1.36"
visibility = { version = "0.1.0", optional = true }
void = "1.0"
weak-table = "0.3.0"
+web-time-compat = { path = "../web-time-compat", version = "0.1.0" }
[dev-dependencies]
futures-await-test = "0.3.0"
diff --git a/crates/tor-circmgr/src/build.rs b/crates/tor-circmgr/src/build.rs
index 75edc577e..fed6c6555 100644
--- a/crates/tor-circmgr/src/build.rs
+++ b/crates/tor-circmgr/src/build.rs
@@ -10,7 +10,6 @@ use std::sync::{
Arc,
atomic::{AtomicU32, Ordering},
};
-use std::time::{Duration, Instant};
use tor_chanmgr::{ChanMgr, ChanProvenance, ChannelUsage};
use tor_error::into_internal;
use tor_guardmgr::GuardStatus;
@@ -23,6 +22,7 @@ use tor_rtcompat::SpawnExt;
use tor_rtcompat::{Runtime, SleepProviderExt};
use tor_units::Percentage;
use tracing::instrument;
+use web_time_compat::{Duration, Instant};
#[cfg(all(feature = "vanguards", feature = "hs-common"))]
use tor_guardmgr::vanguards::VanguardMgr;
diff --git a/crates/tor-circmgr/src/err.rs b/crates/tor-circmgr/src/err.rs
index 0570284e0..758614f6d 100644
--- a/crates/tor-circmgr/src/err.rs
+++ b/crates/tor-circmgr/src/err.rs
@@ -1,6 +1,6 @@
//! Declare an error type for tor-circmgr
-use std::{sync::Arc, time::Instant};
+use std::sync::Arc;
use futures::task::SpawnError;
use retry_error::RetryError;
@@ -10,6 +10,7 @@ use oneshot_fused_workaround as oneshot;
use tor_error::{Bug, ErrorKind, HasKind, HasRetryTime};
use tor_linkspec::{LoggedChanTarget, OwnedChanTarget};
use tor_proto::circuit::UniqId;
+use web_time_compat::Instant;
use crate::mgr::RestrictionFailed;
diff --git a/crates/tor-circmgr/src/hspool.rs b/crates/tor-circmgr/src/hspool.rs
index 307c92939..a92bb1da7 100644
--- a/crates/tor-circmgr/src/hspool.rs
+++ b/crates/tor-circmgr/src/hspool.rs
@@ -7,7 +7,6 @@ mod pool;
use std::{
ops::Deref,
sync::{Arc, Mutex, Weak},
- time::Duration,
};
use crate::{
@@ -35,6 +34,7 @@ use tor_rtcompat::{
scheduler::{TaskHandle, TaskSchedule},
};
use tracing::{debug, instrument, trace, warn};
+use web_time_compat::{Duration, Instant, SystemTime};
use std::result::Result as StdResult;
@@ -373,12 +373,12 @@ impl<R: Runtime> HsCircPool<R> {
///
/// This provides mockable time for use in error tracking and other
/// time-sensitive operations.
- pub fn now(&self) -> std::time::Instant {
+ pub fn now(&self) -> Instant {
self.0.circmgr.mgr.peek_runtime().now()
}
/// Return the current wall-clock time from the runtime.
- pub fn wallclock(&self) -> std::time::SystemTime {
+ pub fn wallclock(&self) -> SystemTime {
self.0.circmgr.mgr.peek_runtime().wallclock()
}
}
diff --git a/crates/tor-circmgr/src/hspool/pool.rs b/crates/tor-circmgr/src/hspool/pool.rs
index cf078d044..763665dca 100644
--- a/crates/tor-circmgr/src/hspool/pool.rs
+++ b/crates/tor-circmgr/src/hspool/pool.rs
@@ -1,6 +1,6 @@
//! An internal pool object that we use to implement HsCircPool.
-use std::time::{Duration, Instant};
+use web_time_compat::{Duration, Instant};
use crate::{
AbstractTunnel,
diff --git a/crates/tor-circmgr/src/impls.rs b/crates/tor-circmgr/src/impls.rs
index 01a046e8f..8544b1de1 100644
--- a/crates/tor-circmgr/src/impls.rs
+++ b/crates/tor-circmgr/src/impls.rs
@@ -19,6 +19,7 @@ use tor_proto::circuit::UniqId;
use tor_proto::client::circuit::{CircParameters, Path};
use tor_rtcompat::Runtime;
use tracing::instrument;
+use web_time_compat::Instant;
#[async_trait]
impl mgr::AbstractTunnel for tor_proto::ClientTunnel {
@@ -65,7 +66,7 @@ impl mgr::AbstractTunnel for tor_proto::ClientTunnel {
circ.extend(target, params).await
}
- async fn last_known_to_be_used_at(&self) -> tor_proto::Result<Option<std::time::Instant>> {
+ async fn last_known_to_be_used_at(&self) -> tor_proto::Result<Option<Instant>> {
self.disused_since().await
}
}
diff --git a/crates/tor-circmgr/src/lib.rs b/crates/tor-circmgr/src/lib.rs
index 8b0a56524..9aa7c2c3d 100644
--- a/crates/tor-circmgr/src/lib.rs
+++ b/crates/tor-circmgr/src/lib.rs
@@ -67,9 +67,9 @@ use tor_linkspec::IntoOwnedChanTarget;
use futures::StreamExt;
use std::sync::{Arc, Mutex, Weak};
-use std::time::{Duration, Instant};
use tor_rtcompat::SpawnExt;
use tracing::{debug, info, instrument, trace, warn};
+use web_time_compat::{Duration, Instant, InstantExt};
#[cfg(feature = "testing")]
pub use config::test_config::TestConfig;
@@ -574,7 +574,8 @@ impl<B: AbstractTunnelBuilder<R> + 'static, R: Runtime> CircMgrInner<B, R> {
#[cfg(feature = "geoip")] country_code: Option<CountryCode>,
) -> Result<Arc<B::Tunnel>> {
self.expire_circuits().await;
- let time = Instant::now();
+ // TODO #2428: Shouldn't we look at runtime.now() instead?
+ let time = Instant::get();
{
let mut predictive = self.predictor.lock().expect("preemptive lock poisoned");
if ports.is_empty() {
diff --git a/crates/tor-circmgr/src/mgr.rs b/crates/tor-circmgr/src/mgr.rs
index a8a501491..0e024bf0e 100644
--- a/crates/tor-circmgr/src/mgr.rs
+++ b/crates/tor-circmgr/src/mgr.rs
@@ -47,9 +47,9 @@ use std::fmt::Debug;
use std::hash::Hash;
use std::panic::AssertUnwindSafe;
use std::sync::{self, Arc, Weak};
-use std::time::{Duration, Instant};
use tor_rtcompat::SpawnExt;
use tracing::{debug, instrument, trace, warn};
+use web_time_compat::{Duration, Instant};
mod streams;
/// Alias to force use of RandomState, regardless of features enabled in `weak_tables`.
@@ -1879,6 +1879,7 @@ mod test {
use tor_persist::TestingStateMgr;
use tor_rtcompat::SleepProvider;
use tor_rtmock::MockRuntime;
+ use web_time_compat::InstantExt;
#[allow(deprecated)] // TODO #1885
use tor_rtmock::MockSleepRuntime;
@@ -2432,7 +2433,7 @@ mod test {
let (ep_none, ep_web, ep_full) = get_exit_policies();
let fake_circ = FakeCirc { id: FakeId::next() };
let expiration = ExpirationInfo::Unused {
- created: Instant::now(),
+ created: Instant::get(),
};
let mut entry_none = OpenEntry::new(
diff --git a/crates/tor-circmgr/src/mocks.rs b/crates/tor-circmgr/src/mocks.rs
index 274e6969d..776dd2c9b 100644
--- a/crates/tor-circmgr/src/mocks.rs
+++ b/crates/tor-circmgr/src/mocks.rs
@@ -9,6 +9,7 @@ use tor_persist::StateMgr;
use tor_proto::circuit::UniqId;
use tor_proto::client::circuit::{CircParameters, Path};
use tor_rtcompat::Runtime;
+use web_time_compat::Instant;
use async_trait::async_trait;
use std::sync::{self, Arc};
@@ -74,7 +75,7 @@ impl AbstractTunnel for FakeCirc {
todo!()
}
- async fn last_known_to_be_used_at(&self) -> tor_proto::Result<Option<std::time::Instant>> {
+ async fn last_known_to_be_used_at(&self) -> tor_proto::Result<Option<Instant>> {
Ok(None)
}
}
diff --git a/crates/tor-circmgr/src/path/exitpath.rs b/crates/tor-circmgr/src/path/exitpath.rs
index 793496444..63379cf2d 100644
--- a/crates/tor-circmgr/src/path/exitpath.rs
+++ b/crates/tor-circmgr/src/path/exitpath.rs
@@ -219,6 +219,7 @@ mod test {
use tor_persist::TestingStateMgr;
use tor_relay_selection::LowLevelRelayPredicate;
use tor_rtcompat::SleepProvider;
+ use web_time_compat::SystemTimeExt;
impl<'a> MaybeOwnedRelay<'a> {
fn can_share_circuit(
@@ -283,7 +284,7 @@ mod test {
let guards =
tor_guardmgr::GuardMgr::new(rt.clone(), statemgr, &TestConfig::default()).unwrap();
guards.install_test_netdir(&netdir);
- let now = SystemTime::now();
+ let now = SystemTime::get();
for _ in 0..1000 {
let (path, _, _) = ExitPathBuilder::from_target_ports(ports.clone())
@@ -317,7 +318,7 @@ mod test {
let guards =
tor_guardmgr::GuardMgr::new(rt.clone(), statemgr, &TestConfig::default()).unwrap();
guards.install_test_netdir(&netdir);
- let now = SystemTime::now();
+ let now = SystemTime::get();
let config = PathConfig::default();
for _ in 0..1000 {
@@ -372,7 +373,7 @@ mod test {
tor_guardmgr::GuardMgr::new(rt.clone(), statemgr, &TestConfig::default()).unwrap();
guards.install_test_netdir(&netdir);
let config = PathConfig::default();
- let now = SystemTime::now();
+ let now = SystemTime::get();
// With target ports
let outcome = ExitPathBuilder::from_target_ports(vec![TargetPort::ipv4(80)])
diff --git a/crates/tor-circmgr/src/path/hspath.rs b/crates/tor-circmgr/src/path/hspath.rs
index 2adba60d9..4c581fdf7 100644
--- a/crates/tor-circmgr/src/path/hspath.rs
+++ b/crates/tor-circmgr/src/path/hspath.rs
@@ -429,6 +429,7 @@ mod test {
use tor_netdoc::doc::netstatus::RelayWeight;
use tor_netdoc::types::relay_flags::RelayFlag;
use tor_rtmock::MockRuntime;
+ use web_time_compat::SystemTimeExt;
#[cfg(all(feature = "vanguards", feature = "hs-common"))]
use {
@@ -601,7 +602,8 @@ mod test {
let netdir_provider: Arc<dyn NetDirProvider> = netdir_provider;
guards.install_netdir_provider(&netdir_provider).unwrap();
let config = PathConfig::default();
- let now = SystemTime::now();
+ // TODO #2428. (This is just testing, though)
+ let now = SystemTime::get();
let dirinfo = (netdir).into();
HsPathBuilder::new(target.cloned(), stem_kind, circ_kind)
.pick_path_with_vanguards(&mut rng, dirinfo, &guards, &vanguardmgr, &config, now)
@@ -616,7 +618,8 @@ mod test {
) -> Result<TorPath<'a>> {
let mut rng = testing_rng();
let config = PathConfig::default();
- let now = SystemTime::now();
+ // TODO #2428. (This is just testing, though)
+ let now = SystemTime::get();
let dirinfo = (netdir).into();
let guards = tor_guardmgr::GuardMgr::new(
MockRuntime::new(),
diff --git a/crates/tor-circmgr/src/preemptive.rs b/crates/tor-circmgr/src/preemptive.rs
index 589237e68..ff2ee6e67 100644
--- a/crates/tor-circmgr/src/preemptive.rs
+++ b/crates/tor-circmgr/src/preemptive.rs
@@ -3,8 +3,8 @@
use crate::{PathConfig, PreemptiveCircuitConfig, TargetPort, TargetTunnelUsage};
use std::collections::HashMap;
use std::sync::Arc;
-use std::time::Instant;
use tracing::warn;
+use web_time_compat::{Instant, InstantExt};
/// Predicts what circuits might be used in future based on past activity, and suggests
/// circuits to preemptively build as a result.
@@ -25,11 +25,11 @@ impl PreemptiveCircuitPredictor {
let mut usages = HashMap::new();
for port in &config.initial_predicted_ports {
// TODO(nickm) should this be IPv6? Should we have a way to configure IPv6 initial ports?
- usages.insert(Some(TargetPort::ipv4(*port)), Instant::now());
+ usages.insert(Some(TargetPort::ipv4(*port)), Instant::get());
}
// We want to build circuits for resolving DNS, too.
- usages.insert(None, Instant::now());
+ usages.insert(None, Instant::get());
Self {
usages,
@@ -57,7 +57,7 @@ impl PreemptiveCircuitPredictor {
/// Make some predictions for what circuits should be built.
pub(crate) fn predict(&self, path_config: &PathConfig) -> Vec<TargetTunnelUsage> {
let config = self.config();
- let now = Instant::now();
+ let now = Instant::get();
let circs = config.min_exit_circs_for_port;
self.usages
.iter()
@@ -110,7 +110,7 @@ mod test {
PathConfig, PreemptiveCircuitConfig, PreemptiveCircuitPredictor, TargetPort,
TargetTunnelUsage,
};
- use std::time::{Duration, Instant};
+ use web_time_compat::{Duration, Instant, InstantExt};
use crate::isolation::test::{IsolationTokenEq, assert_isoleq};
@@ -175,7 +175,7 @@ mod test {
}]
);
- predictor.note_usage(Some(TargetPort::ipv4(1234)), Instant::now());
+ predictor.note_usage(Some(TargetPort::ipv4(1234)), Instant::get());
let results = predictor.predict(&path_config);
assert_eq!(results.len(), 2);
@@ -206,7 +206,7 @@ mod test {
cfg.set_initial_predicted_ports(vec![]);
cfg.prediction_lifetime(Duration::from_secs(2));
let mut predictor = PreemptiveCircuitPredictor::new(cfg.build().unwrap());
- let now = Instant::now();
+ let now = Instant::get();
let three_seconds_ago = now - Duration::from_secs(2 + 1);
predictor.note_usage(Some(TargetPort::ipv4(2345)), three_seconds_ago);
diff --git a/crates/tor-circmgr/src/usage.rs b/crates/tor-circmgr/src/usage.rs
index a2b24a8b5..5b0666ee9 100644
--- a/crates/tor-circmgr/src/usage.rs
+++ b/crates/tor-circmgr/src/usage.rs
@@ -620,6 +620,7 @@ pub(crate) mod test {
use tor_llcrypto::pk::ed25519::Ed25519Identity;
use tor_netdir::testnet;
use tor_persist::TestingStateMgr;
+ use web_time_compat::SystemTimeExt;
impl IsolationTokenEq for TargetTunnelUsage {
fn isol_eq(&self, other: &Self) -> bool {
@@ -956,7 +957,7 @@ pub(crate) mod test {
tor_guardmgr::GuardMgr::new(rt.clone(), statemgr.clone(), &TestConfig::default())
.unwrap();
guards.install_test_netdir(&netdir);
- let now = SystemTime::now();
+ let now = SystemTime::get();
// Only doing basic tests for now. We'll test the path
// building code a lot more closely in the tests for TorPath
@@ -1071,7 +1072,7 @@ pub(crate) mod test {
tor_guardmgr::GuardMgr::new(rt.clone(), statemgr.clone(), &TestConfig::default())
.unwrap();
guards.install_test_netdir(&netdir);
- let now = SystemTime::now();
+ let now = SystemTime::get();
#[cfg(all(feature = "vanguards", feature = "hs-common"))]
let vanguards =