get_protocol_info

Function get_protocol_info 

Source
pub async fn get_protocol_info(
    socket: &mut ControlSocket,
) -> Result<ProtocolInfo, Error>
Expand description

Queries Tor for protocol and authentication information.

Issues a PROTOCOLINFO 1 command to the control socket and parses the response. This must be called before authentication to determine which authentication methods are available.

§Preconditions

  • The socket must be connected but not yet authenticated
  • No prior commands should have been sent on this connection

§Postconditions

  • On success: Returns protocol information including available auth methods
  • On failure: The socket state is undefined; reconnection may be required

§Arguments

  • socket - A connected control socket

§Errors

Returns an error if:

§Example

use stem_rs::auth::get_protocol_info;
use stem_rs::ControlSocket;

let mut socket = ControlSocket::connect_port("127.0.0.1:9051".parse()?).await?;
let info = get_protocol_info(&mut socket).await?;

println!("Connected to Tor {}", info.tor_version);
for method in &info.auth_methods {
    println!("  Auth method: {:?}", method);
}

§Protocol Details

The PROTOCOLINFO command returns a multi-line response:

250-PROTOCOLINFO 1
250-AUTH METHODS=COOKIE,SAFECOOKIE COOKIEFILE="/path/to/cookie"
250-VERSION Tor="0.4.7.1"
250 OK