pub(crate) struct WeightSet {
bandwidth_fn: BandwidthFn,
shift: u8,
w: [RelayWeight; 8],
}Expand description
Information derived from a consensus to use when picking relays by weighted bandwidth.
Fields§
§bandwidth_fn: BandwidthFnHow to find the bandwidth to use when picking a relay by weighted bandwidth.
(This tells us us whether to count unmeasured relays, whether to look at bandwidths at all, etc.)
shift: u8Number of bits that we need to right-shift our weighted products so that their sum won’t overflow u64::MAX.
w: [RelayWeight; 8]A set of RelayWeight values, indexed by WeightKind::idx, used
to weight different kinds of relays.
Implementations§
Source§impl WeightSet
impl WeightSet
Sourcepub(crate) fn weight_rs_for_role(
&self,
rs: &MdRouterStatus,
role: WeightRole,
) -> u64
pub(crate) fn weight_rs_for_role( &self, rs: &MdRouterStatus, role: WeightRole, ) -> u64
Find the actual 64-bit weight to use for a given routerstatus when considering it for a given role.
NOTE: This function does not consider whether the relay in question
actually matches the given role. For example, if role is Guard
we don’t check whether or not rs actually has the Guard flag.
Sourcefn weight_bw_for_role(
&self,
kind: WeightKind,
relay_weight: &RelayWeight,
role: WeightRole,
) -> u64
fn weight_bw_for_role( &self, kind: WeightKind, relay_weight: &RelayWeight, role: WeightRole, ) -> u64
Find the 64-bit weight to report for a relay of kind whose weight in
the consensus is relay_weight when using it for role.
Sourcepub(crate) fn from_consensus(
consensus: &MdConsensus,
params: &NetParameters,
) -> Self
pub(crate) fn from_consensus( consensus: &MdConsensus, params: &NetParameters, ) -> Self
Compute the correct WeightSet for a provided MdConsensus.
Sourcefn from_parts(
bandwidth_fn: BandwidthFn,
total_bw: u64,
weight_scale: u32,
p: &NetParams<i32>,
) -> Self
fn from_parts( bandwidth_fn: BandwidthFn, total_bw: u64, weight_scale: u32, p: &NetParams<i32>, ) -> Self
Compute the correct WeightSet given a bandwidth function, a weight-scaling parameter, a total amount of bandwidth for all relays in the consensus, and a set of bandwidth parameters.
Sourcefn validate(self, consensus: &MdConsensus) -> Self
fn validate(self, consensus: &MdConsensus) -> Self
Assert that we have correctly computed our shift values so that our total weighted bws do not exceed u64::MAX.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WeightSet
impl RefUnwindSafe for WeightSet
impl Send for WeightSet
impl Sync for WeightSet
impl Unpin for WeightSet
impl UnsafeUnpin for WeightSet
impl UnwindSafe for WeightSet
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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