summaryrefslogtreecommitdiff
path: root/crates/tor-dirmgr
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tor-dirmgr')
-rw-r--r--crates/tor-dirmgr/Cargo.toml1
-rw-r--r--crates/tor-dirmgr/src/bootstrap.rs3
-rw-r--r--crates/tor-dirmgr/src/bridgedesc.rs2
-rw-r--r--crates/tor-dirmgr/src/event.rs3
-rw-r--r--crates/tor-dirmgr/src/lib.rs4
-rw-r--r--crates/tor-dirmgr/src/storage/sqlite.rs26
6 files changed, 25 insertions, 14 deletions
diff --git a/crates/tor-dirmgr/Cargo.toml b/crates/tor-dirmgr/Cargo.toml
index 41ad825d1..e340f2471 100644
--- a/crates/tor-dirmgr/Cargo.toml
+++ b/crates/tor-dirmgr/Cargo.toml
@@ -115,6 +115,7 @@ tor-protover = { path = "../tor-protover", version = "0.40.0", features = ["serd
tor-rtcompat = { path = "../tor-rtcompat", version = "0.40.0" }
tracing = "0.1.36"
void = "1"
+web-time-compat = { path = "../web-time-compat", version = "0.1.0" }
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies]
fslock = "0.2.0"
diff --git a/crates/tor-dirmgr/src/bootstrap.rs b/crates/tor-dirmgr/src/bootstrap.rs
index f6a38332f..68ccfdd68 100644
--- a/crates/tor-dirmgr/src/bootstrap.rs
+++ b/crates/tor-dirmgr/src/bootstrap.rs
@@ -748,10 +748,11 @@ mod test {
use tor_dircommon::retry::DownloadSchedule;
use tor_netdoc::doc::microdesc::MdDigest;
use tor_rtcompat::SleepProvider;
+ use web_time_compat::SystemTimeExt;
#[test]
fn week() {
- let now = SystemTime::now();
+ let now = SystemTime::get();
let one_day = Duration::new(86400, 0);
assert_eq!(no_more_than_a_week_from(now, None), now + one_day * 7);
diff --git a/crates/tor-dirmgr/src/bridgedesc.rs b/crates/tor-dirmgr/src/bridgedesc.rs
index ecce442c6..b866937a5 100644
--- a/crates/tor-dirmgr/src/bridgedesc.rs
+++ b/crates/tor-dirmgr/src/bridgedesc.rs
@@ -7,7 +7,6 @@ use std::fmt::{self, Debug, Display};
use std::num::NonZeroU8;
use std::panic::AssertUnwindSafe;
use std::sync::{Arc, Mutex, MutexGuard, Weak};
-use std::time::{Duration, Instant, SystemTime};
use async_trait::async_trait;
use derive_more::{Deref, DerefMut};
@@ -29,6 +28,7 @@ use tor_guardmgr::bridge::{BridgeConfig, BridgeDesc};
use tor_guardmgr::bridge::{BridgeDescError, BridgeDescEvent, BridgeDescList, BridgeDescProvider};
use tor_netdoc::doc::routerdesc::RouterDesc;
use tor_rtcompat::{Runtime, SpawnExt as _};
+use web_time_compat::{Duration, Instant, SystemTime};
use crate::event::FlagPublisher;
use crate::storage::CachedBridgeDescriptor;
diff --git a/crates/tor-dirmgr/src/event.rs b/crates/tor-dirmgr/src/event.rs
index 5d9a7e94a..0744206b3 100644
--- a/crates/tor-dirmgr/src/event.rs
+++ b/crates/tor-dirmgr/src/event.rs
@@ -839,6 +839,7 @@ mod test {
use float_eq::assert_float_eq;
use futures::stream::StreamExt;
use tor_rtcompat::test_with_all_runtimes;
+ use web_time_compat::SystemTimeExt;
#[test]
fn subscribe_and_publish() {
@@ -965,7 +966,7 @@ mod test {
#[test]
fn dir_status_basics() {
- let now = SystemTime::now();
+ let now = SystemTime::get();
let hour = Duration::new(3600, 0);
let nothing = DirStatus {
diff --git a/crates/tor-dirmgr/src/lib.rs b/crates/tor-dirmgr/src/lib.rs
index bcdd4c9d4..5398dfa85 100644
--- a/crates/tor-dirmgr/src/lib.rs
+++ b/crates/tor-dirmgr/src/lib.rs
@@ -91,6 +91,7 @@ use tor_netdoc::doc::netstatus::ProtoStatuses;
use tor_rtcompat::scheduler::{TaskHandle, TaskSchedule};
use tor_rtcompat::{Runtime, SpawnExt};
use tracing::{debug, info, instrument, trace, warn};
+use web_time_compat::SystemTimeExt;
use std::marker::PhantomData;
use std::sync::atomic::{AtomicBool, Ordering};
@@ -182,7 +183,8 @@ impl<R: Runtime> NetDirProvider for DirMgr<R> {
.extend_lifetime(netdir.lifetime()),
Timeliness::Unchecked => return Ok(netdir),
};
- let now = SystemTime::now();
+ // TODO #2384 -- we have a runtime here; we should use it.
+ let now = SystemTime::get();
if lifetime.valid_after() > now {
Err(NetDirError::DirNotYetValid)
} else if lifetime.valid_until() < now {
diff --git a/crates/tor-dirmgr/src/storage/sqlite.rs b/crates/tor-dirmgr/src/storage/sqlite.rs
index db42e893e..4967ce6bb 100644
--- a/crates/tor-dirmgr/src/storage/sqlite.rs
+++ b/crates/tor-dirmgr/src/storage/sqlite.rs
@@ -17,6 +17,7 @@ use tor_netdoc::doc::microdesc::MdDigest;
use tor_netdoc::doc::netstatus::{ConsensusFlavor, Lifetime};
#[cfg(feature = "routerdesc")]
use tor_netdoc::doc::routerdesc::RdDigest;
+use web_time_compat::SystemTimeExt;
#[cfg(feature = "bridge-client")]
pub(crate) use {crate::storage::CachedBridgeDescriptor, tor_guardmgr::bridge::BridgeConfig};
@@ -610,7 +611,7 @@ impl Store for SqliteStore {
names
};
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
tx.execute(DROP_OLD_EXTDOCS, [])?;
// In theory bad system clocks might generate table rows with times far in the future.
@@ -1166,6 +1167,11 @@ fn cmeta_from_row(row: &rusqlite::Row<'_>) -> Result<ConsensusMeta> {
))
}
+/// Return `SystemTime::get()` as an OffsetDateTime in UTC.
+fn now_utc() -> OffsetDateTime {
+ SystemTime::get().into()
+}
+
/// Set up the tables for the arti cache schema in a sqlite database.
const INSTALL_V0_SCHEMA: &str = "
-- Helps us version the schema. The schema here corresponds to a
@@ -1538,7 +1544,7 @@ pub(crate) mod test {
fn blobs() -> Result<()> {
let (_tmp_dir, mut store) = new_empty()?;
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
let one_week = 1.weeks();
let fname1 = store.save_blob(
@@ -1598,7 +1604,7 @@ pub(crate) mod test {
use tor_netdoc::doc::netstatus;
let (_tmp_dir, mut store) = new_empty()?;
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
let one_hour = 1.hours();
assert_eq!(
@@ -1702,7 +1708,7 @@ pub(crate) mod test {
#[test]
fn authcerts() -> Result<()> {
let (_tmp_dir, mut store) = new_empty()?;
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
let one_hour = 1.hours();
let keyids = AuthCertKeyIds {
@@ -1729,7 +1735,7 @@ pub(crate) mod test {
fn microdescs() -> Result<()> {
let (_tmp_dir, mut store) = new_empty()?;
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
let one_day = 1.days();
let d1 = [5_u8; 32];
@@ -1770,7 +1776,7 @@ pub(crate) mod test {
fn routerdescs() -> Result<()> {
let (_tmp_dir, mut store) = new_empty()?;
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
let one_day = 1.days();
let long_ago: OffsetDateTime = now - one_day * 100;
let recently = now - one_day;
@@ -1843,7 +1849,7 @@ pub(crate) mod test {
*/
assert_eq!(store.blob_dir.read_directory(".")?.count(), 0);
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
let one_week = 1.weeks();
let _fname_good = store.save_blob(
b"Goodbye, dear friends",
@@ -1880,7 +1886,7 @@ pub(crate) mod test {
fn unreferenced_consensus_blob() -> Result<()> {
let (_tmp_dir, mut store) = new_empty()?;
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
let one_week = 1.weeks();
// Make a blob that claims to be a consensus, and which has not yet expired, but which is
@@ -1918,7 +1924,7 @@ pub(crate) mod test {
fn vanished_blob_cleanup() -> Result<()> {
let (_tmp_dir, mut store) = new_empty()?;
- let now = OffsetDateTime::now_utc();
+ let now = now_utc();
let one_week = 1.weeks();
// Make a few blobs.
@@ -1972,7 +1978,7 @@ pub(crate) mod test {
fn protocol_statuses() -> Result<()> {
let (_tmp_dir, mut store) = new_empty()?;
- let now = SystemTime::now();
+ let now = SystemTime::get();
let hour = 1.hours();
let valid_after = now;