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 controllercirc_id- The circuit ID to closelogguard- Optional log guard for pre-close log dumping
§Behavior
- If logguard is provided, dumps buffered logs for the circuit
- If
close_circuitsglobal flag is true, sends CLOSECIRCUIT command - 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
set_close_circuits- Control whether circuits are actually closedLogGuard::dump_log_queue- Log dumping implementation