Module response

Module response 

Source
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:

  • STATUS is a 3-digit code (e.g., 250 for success, 5xx for errors)
  • DIVIDER is one of:
    • (space): End of response
    • -: More lines follow
    • +: Data section follows (terminated by .\r\n)
  • CONTENT is the payload of the line

§Primary Types

§Response-Specific Types

Each submodule provides specialized parsing for specific command responses:

§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

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§

ControlLine
A single line from a control protocol response with parsing utilities.
ControlMessage
A parsed control protocol message from Tor.
SingleLineResponse
A simple single-line response from Tor.

Functions§

convert
Converts a control message to a specific response type.