Trait tor_circmgr::mgr::AbstractSpec
source · pub(crate) trait AbstractSpec: Clone + Debug {
type Usage: Clone + Debug + Send + Sync;
// Required methods
fn supports(&self, other: &Self::Usage) -> bool;
fn restrict_mut(
&mut self,
usage: &Self::Usage
) -> Result<(), RestrictionFailed>;
fn channel_usage(&self) -> ChannelUsage;
// Provided method
fn find_supported<'a, 'b, C: AbstractCirc>(
list: impl Iterator<Item = &'b mut OpenEntry<Self, C>>,
usage: &Self::Usage
) -> Vec<&'b mut OpenEntry<Self, C>> { ... }
}
Expand description
Represents restrictions on circuit usage.
An AbstractSpec
describes what a circuit can be used for. Each
AbstractSpec
type has an associated Usage
type that
describes a single operation that the circuit might support or
not.
(For example, an AbstractSpec
can describe a set of ports
supported by the exit relay on a circuit. In that case, its
Usage
type could be a single port that a client wants to
connect to.)
If an AbstractSpec
A allows every operation described in a
Usage
B, we say that A “supports” B.
If one AbstractSpec
A supports every operation supported by
another AbstractSpec
B, we say that A “contains” B.
Some circuits can be used for either of two operations, but not both.
For example, a circuit that is used as a rendezvous point can’t
be used as an introduction point. To represent these transitions,
we use a restrict
operation. Every time a circuit is used for something
new, that new use “restricts” the circuit’s spec, and narrows
what the circuit can be used for.
Required Associated Types§
Required Methods§
sourcefn supports(&self, other: &Self::Usage) -> bool
fn supports(&self, other: &Self::Usage) -> bool
Return true if this spec permits the usage described by other
.
If this function returns true
, then it is okay to use a circuit
with this spec for the target usage described by other
.
sourcefn restrict_mut(&mut self, usage: &Self::Usage) -> Result<(), RestrictionFailed>
fn restrict_mut(&mut self, usage: &Self::Usage) -> Result<(), RestrictionFailed>
Change the value of this spec based on the circuit having
been used for usage
.
§Requirements
Must return an error and make no changes to self
if usage
was not supported by this spec.
If this function returns Ok, the resulting spec must be
contained by the original spec, and must support usage
.
sourcefn channel_usage(&self) -> ChannelUsage
fn channel_usage(&self) -> ChannelUsage
How the circuit will be used, for use by the channel
Provided Methods§
sourcefn find_supported<'a, 'b, C: AbstractCirc>(
list: impl Iterator<Item = &'b mut OpenEntry<Self, C>>,
usage: &Self::Usage
) -> Vec<&'b mut OpenEntry<Self, C>>
fn find_supported<'a, 'b, C: AbstractCirc>( list: impl Iterator<Item = &'b mut OpenEntry<Self, C>>, usage: &Self::Usage ) -> Vec<&'b mut OpenEntry<Self, C>>
Find all open circuits in list
whose specifications permit
usage
.
By default, this calls abstract_spec_find_supported
.