Skip to main content

irtt_client/
lib.rs

1//! Reusable client/session/event layer for IRTT-compatible probes.
2//!
3//! `irtt-client` opens IRTT-compatible sessions, sends echo probes, receives
4//! replies, classifies loss/late/duplicate packets, and emits [`ClientEvent`]
5//! values for callers to consume directly or aggregate with `irtt-stats`.
6//! With the `tokio` feature enabled, `AsyncClient` provides the same low-level
7//! lifecycle for callers that own a Tokio runtime and drive readiness directly.
8//!
9//! Timing values intentionally preserve signed measurement semantics. When
10//! server timing is available, [`RttSample::effective`] is adjusted for server
11//! processing and can be negative if the reported server processing time exceeds
12//! the raw client-observed RTT. Directional [`OneWayDelaySample`] values are
13//! also signed when the required wall-clock timestamps are available; negative
14//! values usually indicate client/server clock skew.
15//!
16//! [`Client`] is the runtime-free low-level blocking adapter and requires no
17//! Tokio dependency at all; it is what a caller without a runtime, or that
18//! wants full control over its own event loop, should start from. With the
19//! `tokio` feature, `AsyncClient` provides the corresponding low-level Tokio
20//! adapter for a caller that owns a runtime and drives socket readiness
21//! itself. Both adapters send one probe whenever called; callers own cadence
22//! and run duration, using `negotiation()` after Open. Sends return a
23//! [`SendReceipt`] after socket acceptance and session commitment;
24//! [`SendProbeError`] distinguishes uncommitted failures from post-commit
25//! failures carrying that receipt. Convert a receipt to [`ClientEvent`] for
26//! presentation or statistics. [`managed`] owns
27//! negotiated-interval scheduling, finite runs, and staggered/burst pacing:
28//! `ManagedClientTask` /
29//! `ManagedClientHandle` (`tokio` feature) run and control one or more
30//! targets under a Tokio runtime, and `BlockingManagedClient` (`tokio`
31//! feature) wraps that in a synchronous owner backed by its own dedicated
32//! current-thread runtime for callers that want managed multi-target
33//! behavior without touching Tokio themselves.
34//!
35//! A successful [`OpenOutcome`] carries either [`SessionStarted`] (with a live
36//! token) or [`NoTestCompleted`] (terminal, with no probe session). Lifecycle
37//! events use these same payload types. Their [`NegotiationResult`] separates
38//! typed [`AcceptedSessionParameters`] from the exact decoded peer `Params` and
39//! accepted [`NegotiationChange`] records. Use `accepted.interval` and
40//! `accepted.duration` for cadence and lifetime, `accepted.dscp` for the public
41//! DSCP codepoint, and `peer_params` for wire diagnostics. Strict/Loose policy
42//! compares the actual request and reply wire values before deriving accepted
43//! semantics. Both adapters' `negotiation()` accessors return only a live
44//! session's result; no-test completion leaves no current session.
45//!
46//! See `examples/` in the repository for a runnable example of each tier.
47//!
48#![forbid(unsafe_code)]
49
50#[cfg(feature = "tokio")]
51mod async_client;
52mod auth;
53mod client;
54mod config;
55mod error;
56mod event;
57pub mod managed;
58mod metadata;
59mod probe;
60mod receive;
61mod send;
62mod session;
63mod socket;
64mod socket_options;
65mod timing;
66
67#[cfg(feature = "tokio")]
68pub use async_client::AsyncClient;
69pub use auth::{Authentication, HmacKey};
70pub use client::Client;
71pub use config::{
72    AddressFamily, ClientConfig, NegotiationPolicy, OpenPolicy, RecvBudget, RunMode,
73    SessionRequest, SocketConfig, MAX_DSCP_CODEPOINT, MAX_SERVER_FILL_BYTES, MAX_TTL,
74    MAX_UDP_PAYLOAD_LENGTH,
75};
76pub use error::ClientError;
77pub use event::{
78    ClientEvent, NoTestCompleted, OneWayDelaySample, OpenOutcome, PacketMeta, ReceivedStatsSample,
79    RttSample, ServerTiming, SessionStarted, SignedDuration, WarningKind,
80};
81pub use send::{SendProbeError, SendReceipt};
82pub use session::{AcceptedSessionParameters, NegotiationChange, NegotiationResult};
83pub use timing::ClientTimestamp;