PathVerify

Struct PathVerify 

Source
pub struct PathVerify {
    pub layer1: Layer1Guards,
    pub layer2: HashSet<String>,
    pub layer3: HashSet<String>,
    pub full_vanguards: bool,
    pub num_layer1: u8,
    pub num_layer2: u8,
    pub num_layer3: u8,
}
Expand description

Path verification state.

Verifies that circuits use the configured vanguard relays and have the expected path lengths. Monitors guard connections and usage patterns to detect potential attacks or misconfigurations.

§State Tracking

┌─────────────────────────────────────────────────────────────────────┐
│                    PathVerify State                                 │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│  layer1: Layer1Guards                                               │
│    └── guards: HashMap<fingerprint, Layer1Stats>                    │
│                                                                     │
│  layer2: HashSet<fingerprint>                                       │
│    └── Expected layer 2 guard fingerprints                          │
│                                                                     │
│  layer3: HashSet<fingerprint>                                       │
│    └── Expected layer 3 guard fingerprints                          │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

§Example

use vanguards_rs::pathverify::PathVerify;

// Create verifier for full vanguards mode
let mut verifier = PathVerify::new(true, 2, 4, 8);
assert!(verifier.full_vanguards);
assert_eq!(verifier.routelen_for_purpose("HS_VANGUARDS"), Some(4));

// Create verifier for vanguards-lite mode
let mut verifier_lite = PathVerify::new(false, 1, 4, 0);
assert!(!verifier_lite.full_vanguards);
assert_eq!(verifier_lite.routelen_for_purpose("HS_VANGUARDS"), Some(3));

§Event Handling

The verifier responds to several Tor events:

  • ORCONN: Track guard connection state changes
  • GUARD: Track layer 2 guard changes (vanguards-lite)
  • CIRC: Verify circuit paths when built
  • CIRC_MINOR: Detect suspicious purpose changes
  • CONF_CHANGED: Update layer configuration

§See Also

Fields§

§layer1: Layer1Guards

Layer 1 guard tracking.

§layer2: HashSet<String>

Layer 2 guard fingerprints.

§layer3: HashSet<String>

Layer 3 guard fingerprints.

§full_vanguards: bool

Whether full vanguards mode is enabled.

§num_layer1: u8

Expected number of layer 1 guards.

§num_layer2: u8

Expected number of layer 2 guards.

§num_layer3: u8

Expected number of layer 3 guards.

Implementations§

Source§

impl PathVerify

Source

pub fn new( full_vanguards: bool, num_layer1: u8, num_layer2: u8, num_layer3: u8, ) -> Self

Creates a new PathVerify with the specified configuration.

Source

pub fn init_layers( &mut self, layer2_nodes: Option<&str>, layer3_nodes: Option<&str>, )

Initializes layer 2 and layer 3 from configuration values.

§Arguments
  • layer2_nodes - Comma-separated layer 2 fingerprints (or None)
  • layer3_nodes - Comma-separated layer 3 fingerprints (or None)
Source

pub fn check_layer_counts(&self) -> bool

Checks layer counts and logs warnings.

Returns true when counts are correct, false otherwise.

Source

pub fn conf_changed_event(&mut self, changed: &HashMap<String, Vec<String>>)

Handles a CONF_CHANGED event.

Updates layer configuration when HSLayer2Nodes or HSLayer3Nodes change.

Source

pub fn orconn_event(&mut self, guard_fp: &str, status: &str)

Handles an ORCONN event.

Tracks guard connection state changes.

Source

pub fn guard_event(&mut self, guard_fp: &str, status: &str)

Handles a GUARD event.

Tracks layer 2 guard changes for vanguards-lite.

Source

pub fn routelen_for_purpose(&self, purpose: &str) -> Option<usize>

Returns the expected path length for a circuit purpose.

Source

pub fn circ_event( &mut self, _circ_id: &str, status: &str, purpose: &str, hs_state: Option<&str>, path: &[(String, Option<String>)], )

Handles a CIRC event.

Verifies circuit paths when circuits are built.

Source

pub fn circ_minor_event( &mut self, _circ_id: &str, purpose: &str, old_purpose: Option<&str>, path: &[(String, Option<String>)], )

Handles a CIRC_MINOR event (purpose changes).

Warns on suspicious purpose changes.

Trait Implementations§

Source§

impl Clone for PathVerify

Source§

fn clone(&self) -> PathVerify

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 PathVerify

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