try_close_circuit

Function try_close_circuit 

Source
pub async fn try_close_circuit(
    controller: &mut Controller,
    circ_id: &str,
    logguard: Option<&mut LogGuard>,
)
Expand description

Attempts to close a circuit, optionally dumping logs first.

This function is called when an attack is detected and a circuit needs to be closed. If logguard is enabled, it dumps the log queue for the circuit before closing to aid in post-incident analysis.

§Arguments

  • controller - The Tor controller
  • circ_id - The circuit ID to close
  • logguard - Optional log guard for pre-close log dumping

§Behavior

  1. If logguard is provided, dumps buffered logs for the circuit
  2. If close_circuits global flag is true, sends CLOSECIRCUIT command
  3. Logs success or failure of the close operation

§Global Flag

The close_circuits flag (set via set_close_circuits) controls whether circuits are actually closed. When false, the function logs but doesn’t close. This is useful for testing or monitoring-only mode.

§Example

use stem_rs::controller::Controller;
use vanguards_rs::control::try_close_circuit;

let mut controller = Controller::from_port("127.0.0.1:9051".parse().unwrap()).await?;
controller.authenticate(None).await?;

// Close circuit without log dumping
try_close_circuit(&mut controller, "42", None).await;

§See Also