pub async fn new_consensus_event(
controller: &mut Controller,
state: &mut VanguardState,
config: &Config,
) -> Result<()>Expand description
Handles a new consensus event by updating vanguard state.
This function is called when a new consensus is received from Tor. It performs a complete update cycle for all protection components.
§Processing Steps
┌─────────────────────────────────────────────────────────────┐
│ new_consensus_event() │
│ │
│ 1. Get router list from Tor (GETINFO ns/all) │
│ 2. Get ExcludeNodes configuration │
│ 3. Parse consensus weights from cached-microdesc-consensus │
│ 4. Update vanguard state: │
│ • Remove guards no longer in consensus │
│ • Remove expired guards │
│ • Remove excluded guards │
│ • Replenish guard layers │
│ 5. Update rendguard use counts │
│ 6. Configure Tor with new HSLayer2/3Nodes │
│ 7. Write state to file │
└─────────────────────────────────────────────────────────────┘§Arguments
controller- The Tor controller for querying and configurationstate- The vanguard state to updateconfig- The vanguards configuration
§Returns
Returns Ok(()) on successful update.
§Errors
Error::DescriptorUnavailable- Tor doesn’t have descriptors yet (retry later)Error::Consensus- Failed to parse consensus fileError::Config- DataDirectory not configured in TorError::Control- Failed to configure Tor
§Example
use stem_rs::controller::Controller;
use vanguards_rs::vanguards::VanguardState;
use vanguards_rs::config::Config;
use vanguards_rs::control::new_consensus_event;
let mut controller = Controller::from_port("127.0.0.1:9051".parse().unwrap()).await?;
controller.authenticate(None).await?;
let mut state = VanguardState::new("/tmp/vanguards.state");
let config = Config::default();
new_consensus_event(&mut controller, &mut state, &config).await?;§See Also
get_consensus_weights- Consensus weight parsingconfigure_tor- Tor configurationVanguardState::replenish_layers- Guard replenishment