pub struct GuardNode {
pub idhex: String,
pub chosen_at: f64,
pub expires_at: f64,
}Expand description
A guard node selected as a vanguard with lifetime metadata.
Each guard node tracks when it was selected and when it should expire. Timestamps are stored as Unix timestamps (f64) for Python pickle compatibility.
§Fields
idhex: The relay’s 40-character uppercase hex fingerprintchosen_at: Unix timestamp when this guard was selectedexpires_at: Unix timestamp when this guard should be rotated
§Lifetime Calculation
Guard lifetimes are calculated using the max of two uniform random samples from the configured range. This distribution favors longer lifetimes, providing better security by reducing guard rotation frequency.
Lifetime = max(uniform(min, max), uniform(min, max))§Example
use vanguards_rs::vanguards::GuardNode;
use std::time::{SystemTime, UNIX_EPOCH};
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs_f64();
let expires = now + 86400.0; // 24 hours
let guard = GuardNode::new("A".repeat(40), now, expires);
assert!(!guard.is_expired());§See Also
VanguardState::calculate_guard_lifetime- Lifetime calculationVanguardState::add_new_layer2- Layer 2 guard creationVanguardState::add_new_layer3- Layer 3 guard creation
Fields§
§idhex: StringThe relay’s 40-character hex fingerprint.
chosen_at: f64Unix timestamp when this guard was selected.
expires_at: f64Unix timestamp when this guard should be rotated.
Implementations§
Source§impl GuardNode
impl GuardNode
Sourcepub fn new(idhex: String, chosen_at: f64, expires_at: f64) -> Self
pub fn new(idhex: String, chosen_at: f64, expires_at: f64) -> Self
Creates a new guard node with the specified fingerprint and timestamps.
§Arguments
idhex- The relay’s 40-character hex fingerprintchosen_at- Unix timestamp when this guard was selectedexpires_at- Unix timestamp when this guard should be rotated
§Returns
A new GuardNode instance.
§Example
use vanguards_rs::vanguards::GuardNode;
let guard = GuardNode::new(
"AABBCCDD00112233445566778899AABBCCDDEEFF".to_string(),
1700000000.0, // chosen_at
1700086400.0, // expires_at (24 hours later)
);Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Returns true if this guard has expired.
Compares the current time against expires_at to determine if
this guard should be rotated.
§Returns
true if the current time is past expires_at, false otherwise.
§Example
use vanguards_rs::vanguards::GuardNode;
use std::time::{SystemTime, UNIX_EPOCH};
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs_f64();
// Expired guard
let expired = GuardNode::new("A".repeat(40), now - 1000.0, now - 100.0);
assert!(expired.is_expired());
// Active guard
let active = GuardNode::new("B".repeat(40), now, now + 86400.0);
assert!(!active.is_expired());