pub struct MapAddressResponse {
pub mapped: HashMap<String, String>,
pub failures: Vec<String>,
}Expand description
Parsed response from the MAPADDRESS command.
Contains successful address mappings and any failure messages. Responses can contain a mixture of successes and failures.
§Example
use stem_rs::response::{ControlMessage, MapAddressResponse};
// Response with multiple mappings
let msg = ControlMessage::from_str(
"250-foo=bar\r\n\
250-baz=quux\r\n\
250 192.0.2.1=example.com\r\n",
None,
false
).unwrap();
let response = MapAddressResponse::from_message(&msg).unwrap();
assert_eq!(response.mapped.len(), 3);
assert_eq!(response.mapped.get("foo"), Some(&"bar".to_string()));Fields§
§mapped: HashMap<String, String>Successful address mappings.
Maps the original address (key) to the replacement address (value).
For example, "1.2.3.4" => "tor.freehaven.net" means connections
to 1.2.3.4 will be redirected to tor.freehaven.net.
failures: Vec<String>Failure messages for mappings that could not be created.
Each string contains the error message from Tor explaining why the mapping failed (e.g., “syntax error: invalid address ‘@@@’”).
Implementations§
Source§impl MapAddressResponse
impl MapAddressResponse
Sourcepub fn from_message(message: &ControlMessage) -> Result<Self, Error>
pub fn from_message(message: &ControlMessage) -> Result<Self, Error>
Parses a MAPADDRESS response from a control message.
Extracts successful mappings and failure messages from the response. This method only returns an error if ALL mappings fail or if the response format is invalid.
§Arguments
message- The control message to parse
§Errors
Returns an error if:
Error::InvalidRequest: All addresses were invalid (512 error code)Error::OperationFailed: Tor was unable to satisfy the request (451 error code)Error::Protocol: Response format was invalid (missing=separator, unexpected status code)
§Example
use stem_rs::response::{ControlMessage, MapAddressResponse};
// Successful mapping
let msg = ControlMessage::from_str(
"250 192.0.2.1=example.com\r\n",
None,
false
).unwrap();
let response = MapAddressResponse::from_message(&msg).unwrap();
assert_eq!(
response.mapped.get("192.0.2.1"),
Some(&"example.com".to_string())
);Trait Implementations§
Source§impl Clone for MapAddressResponse
impl Clone for MapAddressResponse
Source§fn clone(&self) -> MapAddressResponse
fn clone(&self) -> MapAddressResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more