BwCircuitStat

Struct BwCircuitStat 

Source
pub struct BwCircuitStat {
Show 21 fields pub circ_id: String, pub is_hs: bool, pub is_service: bool, pub is_hsdir: bool, pub is_serv_intro: bool, pub dropped_cells_allowed: u64, pub purpose: Option<String>, pub hs_state: Option<String>, pub old_purpose: Option<String>, pub old_hs_state: Option<String>, pub in_use: bool, pub built: bool, pub created_at: f64, pub read_bytes: u64, pub sent_bytes: u64, pub delivered_read_bytes: u64, pub delivered_sent_bytes: u64, pub overhead_read_bytes: u64, pub overhead_sent_bytes: u64, pub guard_fp: Option<String>, pub possibly_destroyed_at: Option<f64>,
}
Expand description

Per-circuit bandwidth statistics for attack detection.

Tracks all bandwidth-related information for a single circuit, including read/written bytes, delivered/overhead bytes, and circuit state information.

§Circuit Tracking

┌─────────────────────────────────────────────────────────────────────────┐
│                        BwCircuitStat Fields                              │
│                                                                          │
│  Identity          │ State              │ Bandwidth                     │
│  ──────────────────┼────────────────────┼───────────────────────────────│
│  circ_id           │ purpose            │ read_bytes                    │
│  guard_fp          │ hs_state           │ sent_bytes                    │
│  created_at        │ old_purpose        │ delivered_read_bytes          │
│                    │ old_hs_state       │ delivered_sent_bytes          │
│                    │ built              │ overhead_read_bytes           │
│                    │ in_use             │ overhead_sent_bytes           │
│                                                                          │
│  Flags             │ Attack Detection                                   │
│  ──────────────────┼────────────────────────────────────────────────────│
│  is_hs             │ dropped_cells_allowed                              │
│  is_service        │ possibly_destroyed_at                              │
│  is_hsdir          │                                                    │
│  is_serv_intro     │                                                    │
└─────────────────────────────────────────────────────────────────────────┘

§Dropped Cell Detection

Dropped cells are detected using the formula:

dropped = read_bytes / CELL_PAYLOAD_SIZE - (delivered_read + overhead_read) / RELAY_PAYLOAD_SIZE

§Circuit Types

FlagDescription
is_hsHidden service circuit (client or service)
is_serviceService-side circuit (vs client-side)
is_hsdirHSDIR circuit for descriptor operations
is_serv_introService introduction circuit

§Example

use vanguards_rs::bandguards::BwCircuitStat;

let mut circ = BwCircuitStat::new("123".to_string(), true);
circ.read_bytes = 5090;  // 10 cells
circ.delivered_read_bytes = 3984;  // 8 cells delivered

let dropped = circ.dropped_read_cells();
println!("Dropped cells: {}", dropped);

§See Also

Fields§

§circ_id: String

Circuit ID.

§is_hs: bool

Whether this is a hidden service circuit.

§is_service: bool

Whether this is a service-side circuit (vs client).

§is_hsdir: bool

Whether this is an HSDIR circuit.

§is_serv_intro: bool

Whether this is a service intro circuit.

§dropped_cells_allowed: u64

Number of dropped cells allowed (for Tor bug workarounds).

§purpose: Option<String>

Current circuit purpose.

§hs_state: Option<String>

Current hidden service state.

§old_purpose: Option<String>

Previous circuit purpose (before PURPOSE_CHANGED).

§old_hs_state: Option<String>

Previous hidden service state.

§in_use: bool

Whether the circuit is in use.

§built: bool

Whether the circuit has been built.

§created_at: f64

Unix timestamp when the circuit was created.

§read_bytes: u64

Total bytes read on this circuit.

§sent_bytes: u64

Total bytes sent on this circuit.

§delivered_read_bytes: u64

Delivered read bytes (application data).

§delivered_sent_bytes: u64

Delivered sent bytes (application data).

§overhead_read_bytes: u64

Overhead read bytes (protocol overhead).

§overhead_sent_bytes: u64

Overhead sent bytes (protocol overhead).

§guard_fp: Option<String>

Guard fingerprint for this circuit.

§possibly_destroyed_at: Option<f64>

Timestamp when the circuit may have been destroyed due to guard closure.

Implementations§

Source§

impl BwCircuitStat

Source

pub fn new(circ_id: String, is_hs: bool) -> Self

Creates a new circuit stat entry.

§Arguments
  • circ_id - The circuit ID
  • is_hs - Whether this is a hidden service circuit
Source

pub fn total_bytes(&self) -> u64

Returns the total bytes (read + sent) on this circuit.

Source

pub fn dropped_read_cells(&self) -> i64

Calculates the number of dropped read cells.

Dropped cells are cells that were received but not delivered to the application. This can indicate an attack or a Tor bug.

§Formula
dropped = read_bytes / CELL_PAYLOAD_SIZE - (delivered_read + overhead_read) / RELAY_PAYLOAD_SIZE
§Returns

The number of dropped cells. Can be negative due to timing issues.

Source

pub fn age_secs(&self) -> f64

Returns the circuit age in seconds.

Source

pub fn age_hours(&self) -> f64

Returns the circuit age in hours.

Trait Implementations§

Source§

impl Clone for BwCircuitStat

Source§

fn clone(&self) -> BwCircuitStat

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 BwCircuitStat

Source§

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

Formats the value using the given formatter. 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