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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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