summaryrefslogtreecommitdiff
path: root/crates/tor-proto/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tor-proto/src')
-rw-r--r--crates/tor-proto/src/channel/handshake.rs8
-rw-r--r--crates/tor-proto/src/channel/padding.rs4
-rw-r--r--crates/tor-proto/src/circuit/circhop.rs2
-rw-r--r--crates/tor-proto/src/client.rs2
-rw-r--r--crates/tor-proto/src/client/channel/handshake.rs2
-rw-r--r--crates/tor-proto/src/client/circuit.rs5
-rw-r--r--crates/tor-proto/src/client/circuit/padding/maybenot_padding.rs2
-rw-r--r--crates/tor-proto/src/client/circuit/padding/maybenot_padding/backend.rs4
-rw-r--r--crates/tor-proto/src/client/reactor/circuit.rs2
-rw-r--r--crates/tor-proto/src/client/reactor/circuit/circhop.rs2
-rw-r--r--crates/tor-proto/src/congestion/rtt.rs6
-rw-r--r--crates/tor-proto/src/congestion/vegas.rs8
-rw-r--r--crates/tor-proto/src/relay/channel/handshake.rs4
-rw-r--r--crates/tor-proto/src/relay/channel/responder.rs5
-rw-r--r--crates/tor-proto/src/streammap.rs5
-rw-r--r--crates/tor-proto/src/util/skew.rs3
-rw-r--r--crates/tor-proto/src/util/token_bucket/bucket.rs2
-rw-r--r--crates/tor-proto/src/util/token_bucket/writer.rs6
-rw-r--r--crates/tor-proto/src/util/tunnel_activity.rs9
19 files changed, 44 insertions, 37 deletions
diff --git a/crates/tor-proto/src/channel/handshake.rs b/crates/tor-proto/src/channel/handshake.rs
index 3c95cb036..f805ac346 100644
--- a/crates/tor-proto/src/channel/handshake.rs
+++ b/crates/tor-proto/src/channel/handshake.rs
@@ -5,7 +5,6 @@ use futures::sink::SinkExt;
use futures::stream::{Stream, StreamExt};
use std::net::IpAddr;
use std::sync::Arc;
-use std::time::SystemTime;
use tor_llcrypto::pk::ValidatableSignature;
use crate::channel::{Canonicity, ChannelFrame, UniqId};
@@ -26,6 +25,7 @@ use tor_linkspec::{
use tor_llcrypto as ll;
use tor_llcrypto::pk::ed25519::Ed25519Identity;
use tor_rtcompat::{CoarseTimeProvider, SleepProvider, StreamOps};
+use web_time_compat::{SystemTime, SystemTimeExt};
use digest::Digest;
@@ -656,7 +656,7 @@ impl<
use tor_cert::CertType;
// Replace 'now' with the real time to use.
- let now = now.unwrap_or_else(SystemTime::now);
+ let now = now.unwrap_or_else(SystemTime::get);
// We are a client initiating a channel to a relay or a bridge. We have received a CERTS
// cell and we need to verify these certs:
@@ -732,7 +732,7 @@ pub(crate) fn verify_link_auth_cert(
use tor_cert::CertType;
// Replace 'now' with the real time to use.
- let now = now.unwrap_or_else(SystemTime::now);
+ let now = now.unwrap_or_else(SystemTime::get);
// Now look at the signing->TLS cert and check it against the
// peer certificate.
@@ -956,7 +956,7 @@ pub(super) mod test {
{
let mb = MsgBuf::new(input);
let handshake = ClientInitiatorHandshake::new(mb, None, sleep_prov, fake_mq());
- handshake.connect(SystemTime::now).await.err().unwrap()
+ handshake.connect(SystemTime::get).await.err().unwrap()
}
#[test]
diff --git a/crates/tor-proto/src/channel/padding.rs b/crates/tor-proto/src/channel/padding.rs
index 7d2af56ce..dc3d40b17 100644
--- a/crates/tor-proto/src/channel/padding.rs
+++ b/crates/tor-proto/src/channel/padding.rs
@@ -29,7 +29,7 @@
use std::pin::Pin;
// TODO, coarsetime maybe? But see arti#496 and also we want to use the mockable SleepProvider
-use std::time::{Duration, Instant};
+use web_time_compat::{Duration, Instant};
use derive_builder::Builder;
use educe::Educe;
@@ -400,7 +400,7 @@ impl<R: SleepProvider> Timer<R> {
self.as_mut().select_fresh_timeout();
// Bet that we will be going to sleep again, and set up the new trigger time
- // and waker now. This will save us a future call to Instant::now.
+ // and waker now. This will save us a future call to Instant::get.
self.as_mut().prepare_to_sleep(Some(now));
Padding::new()
diff --git a/crates/tor-proto/src/circuit/circhop.rs b/crates/tor-proto/src/circuit/circhop.rs
index 13680c0ad..98e87c748 100644
--- a/crates/tor-proto/src/circuit/circhop.rs
+++ b/crates/tor-proto/src/circuit/circhop.rs
@@ -39,7 +39,7 @@ use std::num::NonZeroU32;
use std::pin::Pin;
use std::result::Result as StdResult;
use std::sync::{Arc, Mutex};
-use std::time::Instant;
+use web_time_compat::Instant;
#[cfg(test)]
use tor_cell::relaycell::msg::SendmeTag;
diff --git a/crates/tor-proto/src/client.rs b/crates/tor-proto/src/client.rs
index 89ab120ef..da3b30dc8 100644
--- a/crates/tor-proto/src/client.rs
+++ b/crates/tor-proto/src/client.rs
@@ -198,7 +198,7 @@ impl ClientTunnel {
/// NOTE that the Instant returned by this method is not affected by
/// any runtime mocking; it is the output of an ordinary call to
/// `Instant::now()`.
- pub async fn disused_since(&self) -> Result<Option<std::time::Instant>> {
+ pub async fn disused_since(&self) -> Result<Option<web_time_compat::Instant>> {
self.circ.disused_since().await
}
diff --git a/crates/tor-proto/src/client/channel/handshake.rs b/crates/tor-proto/src/client/channel/handshake.rs
index 48a594c45..a0130458e 100644
--- a/crates/tor-proto/src/client/channel/handshake.rs
+++ b/crates/tor-proto/src/client/channel/handshake.rs
@@ -93,7 +93,7 @@ impl<
/// the relay's handshake information.
///
/// Takes a function that reports the current time. In theory, this can just be
- /// `SystemTime::now()`.
+ /// `SystemTime::get()`.
#[instrument(skip_all, level = "trace")]
pub async fn connect<F>(mut self, now_fn: F) -> Result<UnverifiedClientChannel<T, S>>
where
diff --git a/crates/tor-proto/src/client/circuit.rs b/crates/tor-proto/src/client/circuit.rs
index bbd333b17..8ae369d2f 100644
--- a/crates/tor-proto/src/client/circuit.rs
+++ b/crates/tor-proto/src/client/circuit.rs
@@ -69,6 +69,7 @@ use tor_error::{bad_api_usage, internal, into_internal};
use tor_linkspec::{CircTarget, LinkSpecType, OwnedChanTarget, RelayIdType};
use tor_protover::named;
use tor_rtcompat::DynTimeProvider;
+use web_time_compat::Instant;
use crate::circuit::UniqId;
@@ -488,8 +489,8 @@ impl ClientCirc {
///
/// NOTE that the Instant returned by this method is not affected by
/// any runtime mocking; it is the output of an ordinary call to
- /// `Instant::now()`.
- pub async fn disused_since(&self) -> Result<Option<std::time::Instant>> {
+ /// `Instant::get()`.
+ pub async fn disused_since(&self) -> Result<Option<Instant>> {
let (tx, rx) = oneshot::channel();
self.command
.unbounded_send(CtrlCmd::GetTunnelActivity { sender: tx })
diff --git a/crates/tor-proto/src/client/circuit/padding/maybenot_padding.rs b/crates/tor-proto/src/client/circuit/padding/maybenot_padding.rs
index 449ae8caf..c24a79154 100644
--- a/crates/tor-proto/src/client/circuit/padding/maybenot_padding.rs
+++ b/crates/tor-proto/src/client/circuit/padding/maybenot_padding.rs
@@ -31,7 +31,7 @@ use backend::PaddingBackend;
/// The type of Instant that we'll use for our padding machines.
///
/// We use a separate type alias here in case we want to move to coarsetime.
-type Instant = std::time::Instant;
+type Instant = web_time_compat::Instant;
/// The type of Duration that we'll use for our padding machines.
///
diff --git a/crates/tor-proto/src/client/circuit/padding/maybenot_padding/backend.rs b/crates/tor-proto/src/client/circuit/padding/maybenot_padding/backend.rs
index 903db79ad..66b52793a 100644
--- a/crates/tor-proto/src/client/circuit/padding/maybenot_padding/backend.rs
+++ b/crates/tor-proto/src/client/circuit/padding/maybenot_padding/backend.rs
@@ -24,6 +24,7 @@ use std::{sync::Arc, task::Waker};
use maybenot::{MachineId, TriggerEvent};
use smallvec::SmallVec;
+use web_time_compat::InstantExt;
use super::{Bypass, Duration, Instant, PerHopPaddingEvent, PerHopPaddingEventVec, Replace};
@@ -341,7 +342,8 @@ impl<const N: usize> MaybenotPadder<N> {
rules.machines.clone(),
rules.max_outbound_padding_frac,
rules.max_outbound_blocking_frac,
- Instant::now(),
+ // TODO #2428 PADDING: We should be taking this from a SleepProvider!
+ Instant::get(),
ThisThreadRng,
)?;
Ok(Self::from_framework(framework))
diff --git a/crates/tor-proto/src/client/reactor/circuit.rs b/crates/tor-proto/src/client/reactor/circuit.rs
index 9bd4a7083..331e8ca02 100644
--- a/crates/tor-proto/src/client/reactor/circuit.rs
+++ b/crates/tor-proto/src/client/reactor/circuit.rs
@@ -52,6 +52,7 @@ use tor_error::{Bug, internal};
use tor_linkspec::RelayIds;
use tor_llcrypto::pk;
use tor_memquota::mq_queue::{ChannelSpec as _, MpscSpec};
+use web_time_compat::{Duration, Instant, SystemTime};
use futures::SinkExt as _;
use oneshot_fused_workaround as oneshot;
@@ -69,7 +70,6 @@ use std::borrow::Borrow;
use std::pin::Pin;
use std::result::Result as StdResult;
use std::sync::Arc;
-use std::time::{Duration, Instant, SystemTime};
use extender::HandshakeAuxDataHandler;
diff --git a/crates/tor-proto/src/client/reactor/circuit/circhop.rs b/crates/tor-proto/src/client/reactor/circuit/circhop.rs
index fc6b90404..d2b72a38d 100644
--- a/crates/tor-proto/src/client/reactor/circuit/circhop.rs
+++ b/crates/tor-proto/src/client/reactor/circuit/circhop.rs
@@ -27,6 +27,7 @@ use tor_cell::relaycell::{
AnyRelayMsgOuter, RelayCellDecoder, RelayCellDecoderResult, RelayCellFormat, StreamId,
UnparsedRelayMsg,
};
+use web_time_compat::Instant;
use safelog::sensitive as sv;
use tor_error::Bug;
@@ -35,7 +36,6 @@ use tracing::instrument;
use std::result::Result as StdResult;
use std::sync::{Arc, Mutex, MutexGuard};
use std::task::Poll;
-use std::time::Instant;
#[cfg(test)]
use tor_cell::relaycell::msg::SendmeTag;
diff --git a/crates/tor-proto/src/congestion/rtt.rs b/crates/tor-proto/src/congestion/rtt.rs
index 14b939f5b..ac04112f3 100644
--- a/crates/tor-proto/src/congestion/rtt.rs
+++ b/crates/tor-proto/src/congestion/rtt.rs
@@ -3,7 +3,7 @@
use std::cmp::{max, min};
use std::collections::VecDeque;
use std::sync::atomic::{AtomicBool, Ordering};
-use std::time::{Duration, Instant};
+use web_time_compat::{Duration, Instant};
use super::params::RoundTripEstimatorParams;
use super::{CongestionWindow, State};
@@ -269,7 +269,7 @@ mod test {
#![allow(clippy::needless_pass_by_value)]
//! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
- use std::time::{Duration, Instant};
+ use web_time_compat::{Duration, Instant, InstantExt};
use crate::congestion::test_utils::{new_cwnd, new_rtt_estimator};
@@ -333,7 +333,7 @@ mod test {
#[test]
fn test_vectors() {
let mut rtt = new_rtt_estimator();
- let now = Instant::now();
+ let now = Instant::get();
// from C-tor src/test/test_congestion_control.c
let vectors = [
[100000, 200000, 124, 1, 100000, 100000, 100000],
diff --git a/crates/tor-proto/src/congestion/vegas.rs b/crates/tor-proto/src/congestion/vegas.rs
index 0ad46deef..e0f2af68a 100644
--- a/crates/tor-proto/src/congestion/vegas.rs
+++ b/crates/tor-proto/src/congestion/vegas.rs
@@ -343,11 +343,9 @@ pub(crate) mod test {
#![allow(clippy::needless_pass_by_value)]
//! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
- use std::{
- collections::VecDeque,
- time::{Duration, Instant},
- };
+ use std::collections::VecDeque;
use tor_units::Percentage;
+ use web_time_compat::{Duration, Instant, InstantExt};
use super::*;
use crate::congestion::{
@@ -433,7 +431,7 @@ pub(crate) mod test {
self.vegas.set_inflight(p.inflight_in);
self.vegas.set_is_blocked_on_chan(p.or_conn_blocked_in);
- let now = Instant::now();
+ let now = Instant::get();
self.rtt
.expect_sendme(now + Duration::from_micros(p.sent_usec_in));
let ret = self.rtt.update(
diff --git a/crates/tor-proto/src/relay/channel/handshake.rs b/crates/tor-proto/src/relay/channel/handshake.rs
index dda1d2602..748d4a177 100644
--- a/crates/tor-proto/src/relay/channel/handshake.rs
+++ b/crates/tor-proto/src/relay/channel/handshake.rs
@@ -108,7 +108,7 @@ impl<
/// Connect to another relay as the relay Initiator.
///
/// Takes a function that reports the current time. In theory, this can just be
- /// `SystemTime::now()`.
+ /// `SystemTime::get()`.
pub async fn connect<F>(mut self, now_fn: F) -> Result<UnverifiedInitiatorRelayChannel<T, S>>
where
F: FnOnce() -> SystemTime,
@@ -237,7 +237,7 @@ impl<
/// Begin the handshake process.
///
/// Takes a function that reports the current time. In theory, this can just be
- /// `SystemTime::now()`.
+ /// `SystemTime::get()`.
pub async fn handshake<F>(
mut self,
now_fn: F,
diff --git a/crates/tor-proto/src/relay/channel/responder.rs b/crates/tor-proto/src/relay/channel/responder.rs
index 4633e641b..09e55def7 100644
--- a/crates/tor-proto/src/relay/channel/responder.rs
+++ b/crates/tor-proto/src/relay/channel/responder.rs
@@ -8,7 +8,7 @@
use digest::Digest;
use futures::{AsyncRead, AsyncWrite};
use safelog::{MaybeSensitive, Sensitive};
-use std::{net::IpAddr, ops::Deref, sync::Arc, time::SystemTime};
+use std::{net::IpAddr, ops::Deref, sync::Arc};
use subtle::ConstantTimeEq;
use tracing::instrument;
@@ -16,6 +16,7 @@ use tor_cell::chancell::msg;
use tor_linkspec::{OwnedChanTarget, RelayIds};
use tor_llcrypto as ll;
use tor_rtcompat::{CertifiedConn, CoarseTimeProvider, SleepProvider, StreamOps};
+use web_time_compat::{SystemTime, SystemTimeExt};
use crate::{
ClockSkew, Error, RelayIdentities, Result,
@@ -132,7 +133,7 @@ where
let initiator_auth_cell = self.auth_cell;
let my_addrs = self.my_addrs;
- let now = now.unwrap_or_else(SystemTime::now);
+ let now = now.unwrap_or_else(SystemTime::get);
// We are a client initiating a channel to a relay or a bridge. We have received a CERTS
// cell and we need to verify these certs:
diff --git a/crates/tor-proto/src/streammap.rs b/crates/tor-proto/src/streammap.rs
index 0840e4608..82b6d1b27 100644
--- a/crates/tor-proto/src/streammap.rs
+++ b/crates/tor-proto/src/streammap.rs
@@ -22,8 +22,8 @@ use std::collections::hash_map;
use std::num::NonZeroU16;
use std::pin::Pin;
use std::task::{Poll, Waker};
-use std::time::Instant;
use tor_error::{bad_api_usage, internal};
+use web_time_compat::Instant;
use rand::Rng;
@@ -590,6 +590,7 @@ mod test {
use crate::client::circuit::test::fake_mpsc;
use crate::stream::queue::fake_stream_queue;
use crate::{client::stream::OutboundDataCmdChecker, congestion::sendme::StreamSendWindow};
+ use web_time_compat::InstantExt;
#[test]
fn test_wrapping_next_stream_id() {
@@ -650,7 +651,7 @@ mod test {
// Test terminate
use TerminateReason as TR;
- let expiry = Instant::now(); // dummy value, unused outside of the reactor
+ let expiry = Instant::get(); // dummy value, unused outside of the reactor
assert!(map.terminate(nonesuch_id, TR::ExplicitEnd, expiry).is_err());
assert_eq!(map.n_open_streams(), 127);
assert_eq!(
diff --git a/crates/tor-proto/src/util/skew.rs b/crates/tor-proto/src/util/skew.rs
index a75d51e57..6648cda46 100644
--- a/crates/tor-proto/src/util/skew.rs
+++ b/crates/tor-proto/src/util/skew.rs
@@ -161,10 +161,11 @@ mod test {
use super::*;
use tor_basic_utils::test_rng::testing_rng;
+ use web_time_compat::SystemTimeExt;
#[test]
fn make_skew() {
- let now = SystemTime::now();
+ let now = SystemTime::get();
let later = now + Duration::from_secs(777);
let earlier = now - Duration::from_secs(333);
let window = Duration::from_secs(30);
diff --git a/crates/tor-proto/src/util/token_bucket/bucket.rs b/crates/tor-proto/src/util/token_bucket/bucket.rs
index ff39b1fe6..2e58f5cbe 100644
--- a/crates/tor-proto/src/util/token_bucket/bucket.rs
+++ b/crates/tor-proto/src/util/token_bucket/bucket.rs
@@ -1,7 +1,7 @@
//! A token bucket implementation.
use std::fmt::Debug;
-use std::time::{Duration, Instant};
+use web_time_compat::{Duration, Instant};
/// A token bucket.
///
diff --git a/crates/tor-proto/src/util/token_bucket/writer.rs b/crates/tor-proto/src/util/token_bucket/writer.rs
index 9e5b05ab6..6fd6d3eb5 100644
--- a/crates/tor-proto/src/util/token_bucket/writer.rs
+++ b/crates/tor-proto/src/util/token_bucket/writer.rs
@@ -4,7 +4,7 @@ use std::future::Future;
use std::num::NonZero;
use std::pin::Pin;
use std::task::{Context, Poll};
-use std::time::{Duration, Instant};
+use web_time_compat::{Duration, Instant};
use futures::AsyncWrite;
use futures::io::Error;
@@ -26,7 +26,9 @@ pub(crate) struct RateLimitedWriter<W: AsyncWrite, P: SleepProvider> {
///
/// While we use [`Instant`] for the time, we should always get the time from this
/// [`SleepProvider`].
- /// For example, use [`SleepProvider::now()`], not [`Instant::now()`].
+ /// For example, use [`SleepProvider::now()`],
+ /// not [`Instant::now()`](std::time::Instant::now) or
+ /// [`InstantExt::get`](web_time_compat::InstantExt::get).
#[educe(Debug(ignore))]
sleep_provider: P,
/// See [`RateLimitedWriterConfig::wake_when_bytes_available`].
diff --git a/crates/tor-proto/src/util/tunnel_activity.rs b/crates/tor-proto/src/util/tunnel_activity.rs
index 62307fd0c..a51bb71e4 100644
--- a/crates/tor-proto/src/util/tunnel_activity.rs
+++ b/crates/tor-proto/src/util/tunnel_activity.rs
@@ -1,7 +1,8 @@
//! Helpers for tracking whether a tunnel or circuit is still active.
use derive_deftly::Deftly;
-use std::{num::NonZeroUsize, time::Instant};
+use std::num::NonZeroUsize;
+use web_time_compat::{Instant, InstantExt};
/// An object to track whether a tunnel or circuit should still be considered active.
///
@@ -132,7 +133,7 @@ impl TunnelActivity {
*n_open_streams = new_value;
} else {
self.inner = Inner::Disused {
- since: Instant::now(),
+ since: Instant::get(),
};
}
}
@@ -154,7 +155,7 @@ impl TunnelActivity {
///
/// # A note about time
///
- /// The returned Instant value is a direct result of an earlier call to `Instant::now()`.
+ /// The returned Instant value is a direct result of an earlier call to `Instant::get()`.
/// It is not affected by any runtime mocking.
pub(crate) fn disused_since(&self) -> Option<Instant> {
match self.inner {
@@ -189,7 +190,7 @@ mod test {
#[test]
fn ordering() {
use Inner::*;
- let t1 = Instant::now();
+ let t1 = Instant::get();
let t2 = t1 + Duration::new(60, 0);
let t3 = t2 + Duration::new(120, 0);
let sorted = vec![