pub struct TorAddr { /* private fields */ }
Expand description

An address object that you can connect to over the Tor network.

When you’re making a connection with Tor, you shouldn’t do your DNS lookups locally: that would leak your target address to your DNS server. Instead, it’s better to use a combination of a hostname and a port directly.

The preferred way to create a TorAddr is via the IntoTorAddr trait, using a hostname and a port (or a string containing a hostname and a port). It’s also okay to use an IP and Port there, but only if they come from some source other than a local DNS lookup.

In order to discourage local hostname lookups, the functions that construct a TorAddr from IpAddr, SocketAddr, and so forth are labeled as “dangerous”.

Examples

Making a TorAddr from various “safe” sources:

use arti_client::IntoTorAddr;

let example_from_tuple = ("example.com", 80).into_tor_addr()?;
let example_from_string = "example.com:80".into_tor_addr()?;

assert_eq!(example_from_tuple, example_from_string);

Making a TorAddr from an IP address and port:

Warning: This example is only safe because we’re not doing a DNS lookup; rather, the intent is to connect to a hardcoded IP address. If you’re using DangerouslyIntoTorAddr, pay careful attention to where your IP addresses are coming from, and whether there’s a risk of information leakage.

use arti_client::DangerouslyIntoTorAddr;
use std::net::{IpAddr, SocketAddr};

let quad_one_dns: SocketAddr = "1.1.1.1:53".parse()?;
let addr_from_socketaddr = quad_one_dns.into_tor_addr_dangerously()?;

let quad_one_ip: IpAddr = "1.1.1.1".parse()?;
let addr_from_tuple = (quad_one_ip, 53).into_tor_addr_dangerously()?;

assert_eq!(addr_from_socketaddr, addr_from_tuple);

Implementations

Construct a TorAddr from any object that implements IntoTorAddr.

Construct a TorAddr from any object that implements DangerouslyIntoTorAddr.

See DangerouslyIntoTorAddr for an explanation of why the style of programming supported by this function is dangerous to use.

Return true if this is an IP address (rather than a hostname).

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Try to make a TorAddr to represent connecting to this address. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more