Expand description
Response parsing for Tor control protocol messages.
This module provides types for parsing and handling responses from Tor’s control protocol. The control protocol uses a text-based format where responses consist of status codes, dividers, and content.
§Overview
The Tor control protocol response format follows this structure:
- Single-line responses:
STATUS DIVIDER CONTENT\r\n - Multi-line responses: Multiple lines with
-or+dividers, ending with
Where:
STATUSis a 3-digit code (e.g.,250for success,5xxfor errors)DIVIDERis one of:(space): End of response-: More lines follow+: Data section follows (terminated by.\r\n)
CONTENTis the payload of the line
§Primary Types
ControlMessage: Represents a complete control protocol responseControlLine: A single line with parsing utilities for extracting valuesSingleLineResponse: A simple response containing only one line
§Response-Specific Types
Each submodule provides specialized parsing for specific command responses:
add_onion: ADD_ONION response parsingauthchallenge: AUTHCHALLENGE response for SAFECOOKIE authenticationevents: Asynchronous event parsinggetconf: GETCONF response parsinggetinfo: GETINFO response parsingmapaddress: MAPADDRESS response parsingonion_client_auth: ONION_CLIENT_AUTH_VIEW response parsingprotocolinfo: PROTOCOLINFO response parsing
§Example
use stem_rs::response::{ControlMessage, ControlLine};
// Parse a simple OK response
let msg = ControlMessage::from_str("250 OK\r\n", None, false).unwrap();
assert!(msg.is_ok());
// Parse a multi-line GETINFO response
let response = "250-version=0.4.7.8\r\n250 OK\r\n";
let msg = ControlMessage::from_str(response, None, false).unwrap();
assert_eq!(msg.len(), 2);
// Iterate over response lines
for line in msg.iter() {
println!("Line: {}", line);
}§Thread Safety
ControlMessage is Send and Sync. ControlLine uses internal
synchronization for its mutable parsing state, making it safe to share
across threads.
§See Also
crate::Controller: High-level API that uses these response typescrate::socket::ControlSocket: Low-level socket that produces these messages- Tor Control Protocol Specification
Re-exports§
pub use add_onion::AddOnionResponse;pub use authchallenge::AuthChallengeResponse;pub use getconf::GetConfResponse;pub use getinfo::GetInfoResponse;pub use mapaddress::MapAddressResponse;pub use onion_client_auth::OnionClientAuthViewResponse;pub use protocolinfo::AuthMethod;pub use protocolinfo::ProtocolInfoResponse;
Modules§
- add_
onion - ADD_ONION response parsing.
- authchallenge
- AUTHCHALLENGE response parsing.
- events
- Event parsing for Tor control protocol async notifications.
- getconf
- GETCONF response parsing.
- getinfo
- GETINFO response parsing.
- mapaddress
- MAPADDRESS response parsing.
- onion_
client_ auth - ONION_CLIENT_AUTH_VIEW response parsing.
- protocolinfo
- PROTOCOLINFO response parsing.
Structs§
- Control
Line - A single line from a control protocol response with parsing utilities.
- Control
Message - A parsed control protocol message from Tor.
- Single
Line Response - A simple single-line response from Tor.
Functions§
- convert
- Converts a control message to a specific response type.