pub struct ProtocolInfo {
pub protocol_version: u32,
pub tor_version: Version,
pub auth_methods: Vec<AuthMethod>,
pub cookie_path: Option<PathBuf>,
}Expand description
Information about Tor’s control protocol and authentication requirements.
This struct contains the response from a PROTOCOLINFO query, which must
be issued before authentication. It provides:
- The protocol version supported by Tor
- The Tor software version
- Available authentication methods
- The path to the authentication cookie (if cookie auth is available)
§Invariants
protocol_versionis typically 1 for all current Tor versionscookie_pathisSomeonly whenAuthMethod::CookieorAuthMethod::SafeCookieis inauth_methodsauth_methodsmay be empty if Tor is misconfigured
§Example
use stem_rs::auth::{get_protocol_info, AuthMethod};
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!("Protocol version: {}", info.protocol_version);
println!("Tor version: {}", info.tor_version);
if info.auth_methods.contains(&AuthMethod::SafeCookie) {
println!("SafeCookie auth available at: {:?}", info.cookie_path);
}Fields§
§protocol_version: u32The control protocol version (typically 1).
This indicates the version of the control protocol that Tor speaks. Currently, only version 1 is defined.
tor_version: VersionThe version of the Tor software.
This can be used to check for feature availability or known bugs in specific Tor versions.
auth_methods: Vec<AuthMethod>Authentication methods accepted by this Tor instance.
The methods are listed in the order they appear in the PROTOCOLINFO
response. Use authenticate to automatically select the best method.
Path to the authentication cookie file, if available.
This is Some when cookie-based authentication (AuthMethod::Cookie
or AuthMethod::SafeCookie) is available. The path may be absolute
or relative to Tor’s data directory.
§Security Note
The cookie file should be readable only by the user running Tor. If you’re in a chroot environment, you may need to adjust this path.
Implementations§
Source§impl ProtocolInfo
impl ProtocolInfo
Sourcepub fn parse(message: &ControlMessage) -> Result<Self, Error>
pub fn parse(message: &ControlMessage) -> Result<Self, Error>
Parses a PROTOCOLINFO response from Tor.
This function extracts authentication information from a raw control protocol response. It handles the multi-line PROTOCOLINFO format and extracts all relevant fields.
§Arguments
message- The control message containing the PROTOCOLINFO response
§Returns
A ProtocolInfo struct with the parsed information.
§Errors
Returns Error::Protocol if:
- The response status code indicates failure
- The response format is malformed
§Example
use stem_rs::auth::{ProtocolInfo, AuthMethod};
use stem_rs::socket::ControlMessage;
let message = ControlMessage {
status_code: 250,
lines: vec![
"PROTOCOLINFO 1".to_string(),
"AUTH METHODS=COOKIE,SAFECOOKIE COOKIEFILE=\"/var/run/tor/control.authcookie\"".to_string(),
"VERSION Tor=\"0.4.7.1\"".to_string(),
"OK".to_string(),
],
};
let info = ProtocolInfo::parse(&message).unwrap();
assert_eq!(info.protocol_version, 1);
assert!(info.auth_methods.contains(&AuthMethod::Cookie));Trait Implementations§
Source§impl Clone for ProtocolInfo
impl Clone for ProtocolInfo
Source§fn clone(&self) -> ProtocolInfo
fn clone(&self) -> ProtocolInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more