Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions quest/m1/time/crates.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ Split the PR by crate group if review needs it; ban direct clock reads in each
production scope as it finishes. Unrelated legacy test conversions and the
workspace-wide lint ratchet follow in m2.

The current checkpoint migrates auth clock reads, RTMP session timestamps and
deadlines, archive retention, and listener stall accounting. The rest of the
workspace and public `SystemTime` fields still need migration. In particular,
SRT and WebRTC hand instants to third-party APIs on std's clock, and audio/video
device threads block outside an async runtime; those boundaries still need
clock support rather than a second host-clock read at each call site.

Public API: breaking wherever a crate exposes an instant or a time source.
Wire: none.

Expand Down
1 change: 1 addition & 0 deletions rs/moq-archive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bytes = { workspace = true }
futures = { workspace = true }
hang = { workspace = true }
kio = { workspace = true }
moq-clock = { workspace = true }
moq-json = { workspace = true }
moq-mux = { workspace = true }
moq-net = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions rs/moq-archive/benches/writer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Host time measures benchmark throughput.
#![allow(clippy::disallowed_methods, clippy::disallowed_types)]

//! `Writer::run` recording every enrolled track into memory, swept over the number of tracks and
//! the groups each one publishes. Throughput is per frame, so a per-event cost that grows with the
//! track table shows up as a slope across the track counts.
Expand Down
23 changes: 23 additions & 0 deletions rs/moq-archive/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Production uses the ambient clock; legacy test-only clock cleanup is tracked separately.
disallowed-methods = [
{ path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" },
{ path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" },
{ path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" },
{ path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" },
{ path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" },
{ path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" },
{ path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" },
{ path = "tokio::time::interval_at", reason = "tick on the ambient clock" },
]

disallowed-types = [
{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" },
{ path = "std::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" },
{ path = "tokio::time::Interval", reason = "use moq_clock::Interval" },
]
1 change: 1 addition & 0 deletions rs/moq-archive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod info;
mod mock;
mod path;
#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod proof;
pub mod reader;
mod recover;
Expand Down
1 change: 1 addition & 0 deletions rs/moq-archive/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,5 @@ impl quick_cache::Weighter<Key, Arc<Object>> for Weight {
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests;
7 changes: 4 additions & 3 deletions rs/moq-archive/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ use futures::future::BoxFuture;
use futures::stream::FuturesUnordered;
use futures::{FutureExt, StreamExt};
use hang::timeline::{Position, Record};
use moq_clock::Instant;
use moq_mux::timeline::{self, Segmenter};
use moq_net::{Timescale, Timestamp, broadcast, group, track};
use object_store::ObjectStore;
use tokio::sync::{mpsc, watch};
use tokio::time::Instant;

use crate::recover::{Resume, checkpoint, recover};
use crate::segment::{Frame, Group, Object};
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<S: ObjectStore> Writer<S> {
_ = source.closed(), if !closed => closed = true,
// Also once commands closed: an enrollment in flight still settles its count.
_ = enrolling.changed(), if idle => {}
_ = tokio::time::sleep_until(deadline.unwrap_or_else(Instant::now)), if deadline.is_some() => {
_ = moq_clock::sleep_until(deadline.unwrap_or_else(Instant::now)), if deadline.is_some() => {
let (_, expired) = deletions.pop_front().unwrap();
delete(&shared.store, &mut pruned, expired).await;
}
Expand All @@ -328,7 +328,7 @@ impl<S: ObjectStore> Writer<S> {
// Complete expirations already committed to the timelines; nothing new expires after the
// final records.
for (deadline, expired) in deletions {
tokio::time::sleep_until(deadline).await;
moq_clock::sleep_until(deadline).await;
delete(&shared.store, &mut pruned, expired).await;
}

Expand Down Expand Up @@ -1048,6 +1048,7 @@ fn recorded_end(resume: &Resume, timescale: Option<Timescale>) -> Result<Option<
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use futures::TryStreamExt;
use object_store::memory::InMemory;
Expand Down
3 changes: 3 additions & 0 deletions rs/moq-auth/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ How to update your code for each breaking change, newest first.
Wait on it with `moq_clock::sleep_until`, which runs on tokio's clock in production.
`deadline` and `validate` read wall time from `moq_clock::wall()`, so a test on `moq_clock::sim` or a `moq_clock::Manual` clock decides when a grant expires; stamp `expires` from that clock too.

`Key::verify` and the reference server's default expiry use that wall clock too.
Session `End` durations and the server's idle-session accounting use its monotonic clock, so advancing controlled time advances those durations without a host-clock wait.

### Roles carry `Access` (#5697)

`publish` and `subscribe` on `Claims`, `Permissions`, and `Grant` are `Access`, which holds the path patterns and an optional per-connection `Rate` cap.
Expand Down
22 changes: 22 additions & 0 deletions rs/moq-auth/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Production uses the ambient clock; legacy test-only clock cleanup is tracked separately.
disallowed-methods = [
{ path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" },
{ path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" },
{ path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" },
{ path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" },
{ path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" },
{ path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" },
{ path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" },
{ path = "tokio::time::interval_at", reason = "tick on the ambient clock" },
]

disallowed-types = [
{ path = "std::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" },
{ path = "tokio::time::Interval", reason = "use moq_clock::Interval" },
]
1 change: 1 addition & 0 deletions rs/moq-auth/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl Claims {
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use super::*;

Expand Down
17 changes: 16 additions & 1 deletion rs/moq-auth/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::time::Duration;

use moq_clock::Instant;
use url::Url;

use crate::lease::{self, Due, Reason};
Expand Down Expand Up @@ -392,6 +393,7 @@ impl<S: Post> Driver<S> {
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use super::*;
use moq_pattern::Patterns;
Expand Down Expand Up @@ -545,6 +547,19 @@ mod tests {
}
}

#[tokio::test(start_paused = true)]
async fn session_duration_uses_the_lease_clock() {
let log = Log::default();
let script = Script::new(log.clone(), |_| Some(Ok(grant(None, None))));
let consumer = script.connect().await.unwrap();
tokio::time::advance(Duration::from_secs(60)).await;
consumer.close("done", Bytes::default());
match log.end().await.event {
Event::End { duration, .. } => assert_eq!(duration, Duration::from_secs(60)),
other => panic!("expected connection end, got {other:?}"),
}
}

#[tokio::test]
async fn an_attached_lease_never_reports_the_connection_end() {
let log = Log::default();
Expand Down
15 changes: 14 additions & 1 deletion rs/moq-auth/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl Key {
/// [`Claims::authorize`].
pub fn verify(&self, token: &str) -> crate::Result<Claims> {
let claims: Claims = self.decode(token)?;
validate_times(&claims, std::time::SystemTime::now())?;
validate_times(&claims, moq_clock::wall().into())?;
claims.validate()?;
self.validate_scope(&claims)?;
Ok(claims)
Expand Down Expand Up @@ -675,6 +675,7 @@ where
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use super::*;

Expand Down Expand Up @@ -1105,6 +1106,18 @@ mod tests {
assert!(result.is_err());
}

#[moq_clock::test]
async fn token_validity_uses_the_ambient_wall() {
let key = create_test_key();
let mut claims = create_test_claims();
claims.issued = Some(moq_clock::wall().into());
claims.expires = Some((moq_clock::wall() + Duration::from_secs(10)).into());
let token = key.sign(&claims).unwrap();
key.verify(&token).unwrap();
moq_clock::sleep(Duration::from_secs(10)).await;
assert!(matches!(key.verify(&token), Err(crate::Error::TokenExpired)));
}

#[test]
fn test_key_verify_token_without_exp() {
let key = create_test_key();
Expand Down
1 change: 1 addition & 0 deletions rs/moq-auth/src/lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ fn ready_if(condition: bool) -> Poll<()> {
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use super::*;
use std::future::Future;
Expand Down
25 changes: 22 additions & 3 deletions rs/moq-auth/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::routing::post;
use axum::{Json, Router};
use tokio::time::Instant;
use moq_clock::Instant;

use crate::{Event, Grant, Key, KeyId, KeySet, Permissions, Request, Token};

Expand Down Expand Up @@ -167,7 +167,11 @@ impl Policy {
let mut grant = Grant::new(permissions.publish, permissions.subscribe);
grant.expires = match (expires, self.expires) {
(Some(expires), _) => Some(expires),
(None, Some(bound)) => Some(SystemTime::now().checked_add(bound).ok_or(Refusal::ExpiresOutOfRange)?),
(None, Some(bound)) => Some(
SystemTime::from(moq_clock::wall())
.checked_add(bound)
.ok_or(Refusal::ExpiresOutOfRange)?,
),
(None, None) => None,
};
grant.revalidate = self.revalidate;
Expand Down Expand Up @@ -362,7 +366,7 @@ impl Server {
}
if policy
.expires
.is_some_and(|bound| SystemTime::now().checked_add(bound).is_none())
.is_some_and(|bound| SystemTime::from(moq_clock::wall()).checked_add(bound).is_none())
{
return Err(crate::Error::ExpiresOutOfRange);
}
Expand Down Expand Up @@ -443,6 +447,7 @@ async fn handle(State(server): State<Server>, Json(request): Json<Request>) -> R
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use super::*;
use crate::{Algorithm, Bytes, Claims, Client, Error, Peer, Transport, lease::Reason};
Expand All @@ -462,6 +467,20 @@ mod tests {
request
}

#[moq_clock::test]
async fn default_expiry_uses_the_ambient_wall() {
let policy = Policy {
public: rules(&["**"], &[]),
expires: Some(Duration::from_secs(30)),
..Default::default()
};
let grant = policy.decide(&request("/demo")).await.unwrap();
assert_eq!(
grant.expires,
Some((moq_clock::wall() + Duration::from_secs(30)).into())
);
}

fn with_token(mut request: Request, jwt: &str) -> Request {
request.query = Some(format!("jwt={jwt}"));
request
Expand Down
1 change: 1 addition & 0 deletions rs/moq-auth/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl KeySet {
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use super::*;

Expand Down
2 changes: 2 additions & 0 deletions rs/moq-rtmp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ bytes = { workspace = true }
futures = { workspace = true }
hang = { workspace = true }
hmac = "0.13"
moq-clock = { workspace = true }
moq-mux = { workspace = true }
moq-net = { workspace = true }
rand = { workspace = true }
Expand All @@ -54,6 +55,7 @@ tracing = { workspace = true }

[dev-dependencies]
criterion = { workspace = true }
moq-clock = { path = "../moq-clock", features = ["sim"] }
# The RTMPS test borrows moq-tokio's self-signed cert generation to build a
# `rustls::ServerConfig`. No transport feature: a QUIC backend here would be
# unified into every other crate a `--workspace` build selects, which is exactly
Expand Down
23 changes: 23 additions & 0 deletions rs/moq-rtmp/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Production uses the ambient clock; legacy test-only clock cleanup is tracked separately.
disallowed-methods = [
{ path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" },
{ path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" },
{ path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" },
{ path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" },
{ path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" },
{ path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" },
{ path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" },
{ path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" },
{ path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" },
{ path = "tokio::time::interval_at", reason = "tick on the ambient clock" },
]

disallowed-types = [
{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" },
{ path = "std::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Instant", reason = "use moq_clock::Instant" },
{ path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" },
{ path = "tokio::time::Interval", reason = "use moq_clock::Interval" },
]
1 change: 1 addition & 0 deletions rs/moq-rtmp/src/dial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ impl Publisher {
}

#[cfg(test)]
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
mod tests {
use std::time::Duration;

Expand Down
1 change: 1 addition & 0 deletions rs/moq-rtmp/src/rml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#![allow(clippy::pedantic)]
#![allow(clippy::nursery)]
#![allow(rustdoc::all)]
#![deny(clippy::disallowed_methods, clippy::disallowed_types)]

pub mod amf0;

Expand Down
Loading
Loading