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 changesGUARD: Track layer 2 guard changes (vanguards-lite)CIRC: Verify circuit paths when builtCIRC_MINOR: Detect suspicious purpose changesCONF_CHANGED: Update layer configuration
§See Also
Layer1Guards- Layer 1 guard trackingcrate::control- Event dispatch to path verification
Fields§
§layer1: Layer1GuardsLayer 1 guard tracking.
layer2: HashSet<String>Layer 2 guard fingerprints.
layer3: HashSet<String>Layer 3 guard fingerprints.
full_vanguards: boolWhether full vanguards mode is enabled.
num_layer1: u8Expected number of layer 1 guards.
num_layer2: u8Expected number of layer 2 guards.
num_layer3: u8Expected number of layer 3 guards.
Implementations§
Source§impl PathVerify
impl PathVerify
Sourcepub fn new(
full_vanguards: bool,
num_layer1: u8,
num_layer2: u8,
num_layer3: u8,
) -> Self
pub fn new( full_vanguards: bool, num_layer1: u8, num_layer2: u8, num_layer3: u8, ) -> Self
Creates a new PathVerify with the specified configuration.
Sourcepub fn init_layers(
&mut self,
layer2_nodes: Option<&str>,
layer3_nodes: Option<&str>,
)
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)
Sourcepub fn check_layer_counts(&self) -> bool
pub fn check_layer_counts(&self) -> bool
Checks layer counts and logs warnings.
Returns true when counts are correct, false otherwise.
Sourcepub fn conf_changed_event(&mut self, changed: &HashMap<String, Vec<String>>)
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.
Sourcepub fn orconn_event(&mut self, guard_fp: &str, status: &str)
pub fn orconn_event(&mut self, guard_fp: &str, status: &str)
Handles an ORCONN event.
Tracks guard connection state changes.
Sourcepub fn guard_event(&mut self, guard_fp: &str, status: &str)
pub fn guard_event(&mut self, guard_fp: &str, status: &str)
Handles a GUARD event.
Tracks layer 2 guard changes for vanguards-lite.
Sourcepub fn routelen_for_purpose(&self, purpose: &str) -> Option<usize>
pub fn routelen_for_purpose(&self, purpose: &str) -> Option<usize>
Returns the expected path length for a circuit purpose.
Trait Implementations§
Source§impl Clone for PathVerify
impl Clone for PathVerify
Source§fn clone(&self) -> PathVerify
fn clone(&self) -> PathVerify
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more