Struct tor_relay_selection::RelaySelector
source · pub struct RelaySelector<'a> { /* private fields */ }Expand description
Description of the requirements that a relay must implement in order to be selected.
This object is used to pick a Relay from a NetDir, or to ensure that a
previously selected Relay still meets its requirements.
The requirements on a relay can be strict or flexible.
If any restriction is flexible, and relay selection fails at first,
we relax the RelaySelector by removing that restriction,
and trying again,
before we give up completely.
Implementations§
source§impl<'a> RelaySelector<'a>
impl<'a> RelaySelector<'a>
sourcepub fn new(usage: RelayUsage, exclusion: RelayExclusion<'a>) -> Self
pub fn new(usage: RelayUsage, exclusion: RelayExclusion<'a>) -> Self
Create a new RelaySelector to pick relays with a given
RelayUsage and RelayExclusion.
Both arguments are required, since every caller should consider them explicitly.
The provided usage and exclusion are strict by default.
sourcepub fn mark_usage_flexible(&mut self)
pub fn mark_usage_flexible(&mut self)
Mark the originally provided RelayUsage as flexible.
sourcepub fn mark_exclusion_flexible(&mut self)
pub fn mark_exclusion_flexible(&mut self)
Mark the originally provided RelayExclusion as flexible.
sourcepub fn push_restriction(&mut self, restriction: RelayRestriction<'a>)
pub fn push_restriction(&mut self, restriction: RelayRestriction<'a>)
Add a new strict RelayRestriction to this selector.
sourcepub fn push_flexible_restriction(&mut self, restriction: RelayRestriction<'a>)
pub fn push_flexible_restriction(&mut self, restriction: RelayRestriction<'a>)
Add a new flexible RelayRestriction to this selector.
sourcepub fn usage(&self) -> &RelayUsage
pub fn usage(&self) -> &RelayUsage
Return the usage for this selector.
sourcepub fn permits_relay(&self, relay: &Relay<'_>) -> bool
pub fn permits_relay(&self, relay: &Relay<'_>) -> bool
Return true if relay is one that this selector would pick.
sourcepub fn select_relay<'s, 'd, R: Rng>(
&'s self,
rng: &mut R,
netdir: &'d NetDir,
) -> (Option<Relay<'d>>, SelectionInfo<'s>)
pub fn select_relay<'s, 'd, R: Rng>( &'s self, rng: &mut R, netdir: &'d NetDir, ) -> (Option<Relay<'d>>, SelectionInfo<'s>)
Try to pick a random relay from netdir,
according to the rules of this selector.
sourcepub fn select_n_relays<'s, 'd, R: Rng>(
&'s self,
rng: &mut R,
n_relays: usize,
netdir: &'d NetDir,
) -> (Vec<Relay<'d>>, SelectionInfo<'s>)
pub fn select_n_relays<'s, 'd, R: Rng>( &'s self, rng: &mut R, n_relays: usize, netdir: &'d NetDir, ) -> (Vec<Relay<'d>>, SelectionInfo<'s>)
Try to pick n_relays distinct random relay from netdir,
according to the rules of this selector.
Trait Implementations§
source§impl<'a> Clone for RelaySelector<'a>
impl<'a> Clone for RelaySelector<'a>
source§fn clone(&self) -> RelaySelector<'a>
fn clone(&self) -> RelaySelector<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'a> Debug for RelaySelector<'a>
impl<'a> Debug for RelaySelector<'a>
source§impl<'a> LowLevelRelayPredicate for RelaySelector<'a>
impl<'a> LowLevelRelayPredicate for RelaySelector<'a>
source§fn low_level_predicate_permits_relay(&self, relay: &Relay<'_>) -> bool
fn low_level_predicate_permits_relay(&self, relay: &Relay<'_>) -> bool
relay provides this predicate.Auto Trait Implementations§
impl<'a> Freeze for RelaySelector<'a>
impl<'a> RefUnwindSafe for RelaySelector<'a>
impl<'a> Send for RelaySelector<'a>
impl<'a> Sync for RelaySelector<'a>
impl<'a> Unpin for RelaySelector<'a>
impl<'a> UnwindSafe for RelaySelector<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more