TimeoutStats

Struct TimeoutStats 

Source
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

StatisticDescription
all_launchedTotal circuits that started building
all_builtCircuits that completed successfully
all_timeoutCircuits that timed out
hs_launchedHidden service circuits started
hs_builtHS circuits completed
hs_timeoutHS 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 value
  • RESET: 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

Fields§

§circuits: HashMap<String, CircuitStat>

Circuits currently being tracked (not yet built or timed out).

§all_launched: u64

Total circuits launched.

§all_built: u64

Total circuits successfully built.

§all_timeout: u64

Total circuits that timed out.

§hs_launched: u64

Hidden service circuits launched.

§hs_built: u64

Hidden service circuits successfully built.

§hs_timeout: u64

Hidden service circuits that timed out.

§record_timeouts: bool

Whether to record timeouts (false after RESET, true after COMPUTED).

Implementations§

Source§

impl TimeoutStats

Source

pub fn new() -> Self

Creates a new timeout statistics tracker.

Source

pub fn zero_fields(&mut self)

Resets all counters to zero.

Source

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 ID
  • status - The circuit status (LAUNCHED, BUILT, FAILED, CLOSED)
  • purpose - The circuit purpose
  • hs_state - The hidden service state (if any)
  • reason - The close/fail reason (if any)
Source

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)
Source

pub fn add_circuit(&mut self, circ_id: &str, is_hs: bool)

Adds a new circuit to tracking.

Source

pub fn built_circuit(&mut self, circ_id: &str)

Records a circuit as successfully built.

Source

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.

Source

pub fn timeout_circuit(&mut self, circ_id: &str)

Records a circuit as timed out.

Source

pub fn timeout_rate_all(&self) -> f64

Calculates the timeout rate for all circuits.

Returns the ratio of timed out circuits to launched circuits.

Source

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.

Source

pub fn pending_count(&self) -> usize

Returns the number of circuits currently being tracked.

Trait Implementations§

Source§

impl Clone for TimeoutStats

Source§

fn clone(&self) -> TimeoutStats

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeoutStats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TimeoutStats

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more