Module events

Module events 

Source
Expand description

Event parsing for Tor control protocol async notifications.

This module provides parsing for asynchronous event messages received from Tor’s control protocol. Events are notifications sent by Tor when certain conditions occur, such as bandwidth usage, circuit state changes, or log messages.

§Event Format

Events are sent with status code 650 and follow this format:

650 EVENT_TYPE [positional_args] [KEY=value ...]

Multi-line events use the extended format:

650-EVENT_TYPE [args]
650-additional data
650 OK

§Supported Event Types

EventDescription
BWBandwidth usage (bytes read/written per second)
CIRCCircuit status changes
STREAMStream status changes
ORCONNOR connection status changes
NOTICE, WARN, ERRLog messages at various levels
NEWDESCNew relay descriptors available
ADDRMAPAddress mapping changes
SIGNALSignal received by Tor
HS_DESCHidden service descriptor events
And many more…See EventType for full list

§Example

use stem_rs::response::{ControlMessage, events::parse_event};

// Parse a bandwidth event
let msg = ControlMessage::from_str("650 BW 1024 2048", None, true).unwrap();
let event = parse_event(&msg).unwrap();

// Events are returned as ParsedEvent enum variants
match event {
    stem_rs::events::ParsedEvent::Bandwidth(bw) => {
        println!("Read: {} bytes, Written: {} bytes", bw.read, bw.written);
    }
    _ => {}
}

§See Also

Re-exports§

pub use crate::events::Event;
pub use crate::events::ParsedEvent as EventEnum;

Functions§

event_type_to_class
Converts an event type string to its corresponding EventType enum.
is_known_event_type
Checks if an event type string is a known/recognized event type.
parse_event
Parses an event from a control message.