pub(crate) struct HsDirRing {
params: HsDirParams,
ring: TiVec<HsDirPos, (HsDirIndex, RouterStatusIdx)>,
}
hs-common
only.Expand description
A hash ring as used in NetDir
.
This type is immutable once constructed: entries cannot be added, changed, or removed. It can be interpreted only in the context of a given consensus document.
Fields§
§params: HsDirParams
The parameters (time period and shared random value)
ring: TiVec<HsDirPos, (HsDirIndex, RouterStatusIdx)>
The ring itself.
The first element of each tuple is a 32-byte hash representing a position on the ring; the second is the index for the corresponding relay within self.consensus.relays().
This vector is empty in a partial netdir; it is filled in when we convert to a complete netdir.
Implementations§
Source§impl HsDirRing
impl HsDirRing
Sourcepub(crate) fn empty_from_params(params: HsDirParams) -> Self
pub(crate) fn empty_from_params(params: HsDirParams) -> Self
Return a new empty HsDirRing from a given set of parameters.
Sourcepub(crate) fn compute(
new_params: HsDirParams,
this_netdir: &NetDir,
prev_netdir: Option<&NetDir>,
) -> Self
pub(crate) fn compute( new_params: HsDirParams, this_netdir: &NetDir, prev_netdir: Option<&NetDir>, ) -> Self
Compute the HsDirRing
Reuses existing hash calculations from a previous netdir, if available.
this_netdir.hsdir_rings
is not used; the return values from this function
will be stored there by
PartialNetDir::compute_rings
.
Sourcepub(crate) fn params(&self) -> &HsDirParams
pub(crate) fn params(&self) -> &HsDirParams
Return the parameters used for this ring
Sourcefn find_pos(&self, hsdir_index: HsDirIndex) -> HsDirPos
fn find_pos(&self, hsdir_index: HsDirIndex) -> HsDirPos
Find the location or (notional) insertion point for hsdir_index
within ring
.
Sourcepub(crate) fn ring_items_at(
&self,
hsdir_index: HsDirIndex,
spread: usize,
f: impl FnMut(&&(HsDirIndex, RouterStatusIdx)) -> bool,
) -> impl Iterator<Item = &(HsDirIndex, RouterStatusIdx)>
pub(crate) fn ring_items_at( &self, hsdir_index: HsDirIndex, spread: usize, f: impl FnMut(&&(HsDirIndex, RouterStatusIdx)) -> bool, ) -> impl Iterator<Item = &(HsDirIndex, RouterStatusIdx)>
Yield spread
items from ring
that satisfy the specified filter, starting with
hsdir_index
.
Wraps around once when we reach the end.
The specified filter function f
is applied to each item, and determines whether the item
should be yielded or not. This filtering functionality is used by NetDir::hs_dirs
to
prevent nodes that have already been selected for a lowered-numbered replica to be
considered again when choosing spread
nodes for a higher-numbered replicas.
Yields no element more than once, even if the ring is smaller than spread
.
Sourcepub(crate) fn time_period(&self) -> TimePeriod
pub(crate) fn time_period(&self) -> TimePeriod
Return the time period for which this ring applies.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HsDirRing
impl RefUnwindSafe for HsDirRing
impl Send for HsDirRing
impl Sync for HsDirRing
impl Unpin for HsDirRing
impl UnwindSafe for HsDirRing
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