pub struct IsolationToken(_);
Expand description

A token used to isolate unrelated streams on different circuits.

When two streams are associated with different isolation tokens, they can never share the same circuit.

Tokens created with IsolationToken::new are all different from one another, and different from tokens created with IsolationToken::no_isolation. However, tokens created with IsolationToken::no_isolation are all equal to one another.

Examples

Creating distinct isolation tokens:

let token_1 = IsolationToken::new();
let token_2 = IsolationToken::new();

assert_ne!(token_1, token_2);

// Demonstrating the behaviour of no_isolation() tokens:
assert_ne!(token_1, IsolationToken::no_isolation());
assert_eq!(IsolationToken::no_isolation(), IsolationToken::no_isolation());

Using an isolation token to route streams differently over the Tor network:

use arti_client::StreamPrefs;

let token_1 = IsolationToken::new();
let token_2 = IsolationToken::new();

let mut prefs_1 = StreamPrefs::new();
prefs_1.set_isolation_group(token_1);

let mut prefs_2 = StreamPrefs::new();
prefs_2.set_isolation_group(token_2);

// These two connections will come from different source IP addresses.
tor_client.connect(("example.com", 80), Some(prefs_1)).await?;
tor_client.connect(("example.com", 80), Some(prefs_2)).await?;

Implementations

Create a new IsolationToken, unequal to any other token this function has created.

Panics

Panics if we have already allocated 2^64 isolation tokens: in that case, we have exhausted the space of possible tokens, and it is no longer possible to ensure isolation.

Create a new IsolationToken equal to every other token created with this function, but different from all tokens created with new.

This can be used when no isolation is wanted for some streams.

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

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

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