new_consensus_event

Function new_consensus_event 

Source
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 configuration
  • state - The vanguard state to update
  • config - The vanguards configuration

§Returns

Returns Ok(()) on successful update.

§Errors

§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