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
| Flag | Description |
|---|---|
is_hs | Hidden service circuit (client or service) |
is_service | Service-side circuit (vs client-side) |
is_hsdir | HSDIR circuit for descriptor operations |
is_serv_intro | Service 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
BandwidthStats- Main tracking structureCircuitLimitResult- Limit check results
Fields§
§circ_id: StringCircuit ID.
is_hs: boolWhether this is a hidden service circuit.
is_service: boolWhether this is a service-side circuit (vs client).
is_hsdir: boolWhether this is an HSDIR circuit.
is_serv_intro: boolWhether this is a service intro circuit.
dropped_cells_allowed: u64Number 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: boolWhether the circuit is in use.
built: boolWhether the circuit has been built.
created_at: f64Unix timestamp when the circuit was created.
read_bytes: u64Total bytes read on this circuit.
sent_bytes: u64Total bytes sent on this circuit.
delivered_read_bytes: u64Delivered read bytes (application data).
delivered_sent_bytes: u64Delivered sent bytes (application data).
overhead_read_bytes: u64Overhead read bytes (protocol overhead).
overhead_sent_bytes: u64Overhead 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
impl BwCircuitStat
Sourcepub fn new(circ_id: String, is_hs: bool) -> Self
pub fn new(circ_id: String, is_hs: bool) -> Self
Creates a new circuit stat entry.
§Arguments
circ_id- The circuit IDis_hs- Whether this is a hidden service circuit
Sourcepub fn total_bytes(&self) -> u64
pub fn total_bytes(&self) -> u64
Returns the total bytes (read + sent) on this circuit.
Sourcepub fn dropped_read_cells(&self) -> i64
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.
Trait Implementations§
Source§impl Clone for BwCircuitStat
impl Clone for BwCircuitStat
Source§fn clone(&self) -> BwCircuitStat
fn clone(&self) -> BwCircuitStat
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more