pub struct TimeoutStats {
pub circuits: HashMap<String, CircuitStat>,
pub all_launched: u64,
pub all_built: u64,
pub all_timeout: u64,
pub hs_launched: u64,
pub hs_built: u64,
pub hs_timeout: u64,
pub record_timeouts: bool,
}Expand description
Circuit build timeout statistics.
Tracks circuit build statistics for all circuits and hidden service circuits separately, allowing comparison of timeout rates.
§Statistics Tracked
| Statistic | Description |
|---|---|
all_launched | Total circuits that started building |
all_built | Circuits that completed successfully |
all_timeout | Circuits that timed out |
hs_launched | Hidden service circuits started |
hs_built | HS circuits completed |
hs_timeout | HS circuits that timed out |
§Example
use vanguards_rs::cbtverify::TimeoutStats;
let mut stats = TimeoutStats::new();
// Track a circuit launch
stats.add_circuit("123", true);
assert_eq!(stats.all_launched, 1);
assert_eq!(stats.hs_launched, 1);
// Track circuit completion
stats.built_circuit("123");
assert_eq!(stats.all_built, 1);
assert_eq!(stats.hs_built, 1);
// Check timeout rates
assert_eq!(stats.timeout_rate_all(), 0.0);
assert_eq!(stats.timeout_rate_hs(), 0.0);§CBT Event Handling
The statistics respond to Tor’s CBT algorithm events:
COMPUTED: CBT algorithm has computed a new timeout valueRESET: CBT algorithm has been reset (e.g., after network change)
After a RESET, statistics are zeroed and recording is paused until
the next COMPUTED event.
§See Also
CircuitStat- Individual circuit trackingcrate::control- Event dispatch to CBT verification
Fields§
§circuits: HashMap<String, CircuitStat>Circuits currently being tracked (not yet built or timed out).
all_launched: u64Total circuits launched.
all_built: u64Total circuits successfully built.
all_timeout: u64Total circuits that timed out.
hs_launched: u64Hidden service circuits launched.
hs_built: u64Hidden service circuits successfully built.
hs_timeout: u64Hidden service circuits that timed out.
record_timeouts: boolWhether to record timeouts (false after RESET, true after COMPUTED).
Implementations§
Source§impl TimeoutStats
impl TimeoutStats
Sourcepub fn zero_fields(&mut self)
pub fn zero_fields(&mut self)
Resets all counters to zero.
Sourcepub fn circ_event(
&mut self,
circ_id: &str,
status: &str,
purpose: &str,
hs_state: Option<&str>,
reason: Option<&str>,
)
pub fn circ_event( &mut self, circ_id: &str, status: &str, purpose: &str, hs_state: Option<&str>, reason: Option<&str>, )
Handles a circuit event.
Tracks circuit state transitions and updates statistics accordingly.
§Arguments
circ_id- The circuit IDstatus- The circuit status (LAUNCHED, BUILT, FAILED, CLOSED)purpose- The circuit purposehs_state- The hidden service state (if any)reason- The close/fail reason (if any)
Sourcepub fn cbt_event(&mut self, set_type: &str, timeout_rate: Option<f64>)
pub fn cbt_event(&mut self, set_type: &str, timeout_rate: Option<f64>)
Handles a CBT (Circuit Build Timeout) event.
Processes COMPUTED and RESET events from Tor’s circuit build timeout algorithm.
§Arguments
set_type- The CBT event type (COMPUTED, RESET)timeout_rate- Tor’s reported timeout rate (if available)
Sourcepub fn add_circuit(&mut self, circ_id: &str, is_hs: bool)
pub fn add_circuit(&mut self, circ_id: &str, is_hs: bool)
Adds a new circuit to tracking.
Sourcepub fn built_circuit(&mut self, circ_id: &str)
pub fn built_circuit(&mut self, circ_id: &str)
Records a circuit as successfully built.
Sourcepub fn closed_circuit(&mut self, circ_id: &str)
pub fn closed_circuit(&mut self, circ_id: &str)
Records a circuit as closed before completion.
If we are closed but still in circuits, then we closed before being built or timing out. Don’t count as a launched circuit.
Sourcepub fn timeout_circuit(&mut self, circ_id: &str)
pub fn timeout_circuit(&mut self, circ_id: &str)
Records a circuit as timed out.
Sourcepub fn timeout_rate_all(&self) -> f64
pub fn timeout_rate_all(&self) -> f64
Calculates the timeout rate for all circuits.
Returns the ratio of timed out circuits to launched circuits.
Sourcepub fn timeout_rate_hs(&self) -> f64
pub fn timeout_rate_hs(&self) -> f64
Calculates the timeout rate for hidden service circuits.
Returns the ratio of timed out HS circuits to launched HS circuits.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of circuits currently being tracked.
Trait Implementations§
Source§impl Clone for TimeoutStats
impl Clone for TimeoutStats
Source§fn clone(&self) -> TimeoutStats
fn clone(&self) -> TimeoutStats
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more