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
| Event | Description |
|---|---|
BW | Bandwidth usage (bytes read/written per second) |
CIRC | Circuit status changes |
STREAM | Stream status changes |
ORCONN | OR connection status changes |
NOTICE, WARN, ERR | Log messages at various levels |
NEWDESC | New relay descriptors available |
ADDRMAP | Address mapping changes |
SIGNAL | Signal received by Tor |
HS_DESC | Hidden 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
crate::events: Event type definitions and structures- [
crate::Controller::add_event_listener]: Subscribe to events crate::EventType: Enumeration of all event types- Tor Control Protocol: Async Events
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
EventTypeenum. - 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.