Skip to main content

Module weight

Module weight 

Source
Expand description

Functions for applying the correct weights to relays when choosing a relay at random.

The weight to use when picking a relay depends on several factors:

  • The relay’s apparent bandwidth. (This is ideally measured by a set of bandwidth authorities, but if no bandwidth authorities are running (as on a test network), we might fall back either to relays’ self-declared values, or we might treat all relays as having equal bandwidth.)
  • The role that we’re selecting a relay to play. (See WeightRole).
  • The flags that a relay has in the consensus, and their scarcity. If a relay provides particularly scarce functionality, we might choose not to use it for other roles, or to use it less commonly for them.

Re-exportsΒ§

use crate::ConsensusRelays; πŸ”’
use crate::params::NetParameters; πŸ”’
use bitflags::bitflags; πŸ”’
use tor_netdoc::doc::netstatus; πŸ”’
use tor_netdoc::doc::netstatus::MdConsensus; πŸ”’
use tor_netdoc::doc::netstatus::MdRouterStatus; πŸ”’
use tor_netdoc::doc::netstatus::ParamValues; πŸ”’

StructsΒ§

RelayWeight πŸ”’
Description for how to weight a single kind of relay for each WeightRole.
WeightKind πŸ”’
A kind of relay, for the purposes of selecting a relay by weight.
WeightSet πŸ”’
Information derived from a consensus to use when picking relays by weighted bandwidth.

EnumsΒ§

BandwidthFn πŸ”’
Internal: how should we find the base bandwidth of each relay? This value is global over a whole directory, and depends on the bandwidth weights in the consensus.
WeightRole
Possible ways to weight relays when selecting them a random.

ConstantsΒ§

DFLT_WEIGHT πŸ”’
The value to return if a weight parameter is absent.

FunctionsΒ§

calculate_shift πŸ”’
Compute a β€˜shift’ value such that (a * b) >> shift will be contained inside 64 bits.
clamp_to_pos πŸ”’
If inp is less than 0, return 0. Otherwise return inp as a u32.
log2_upper πŸ”’
Return an upper bound for the log2 of n.
pick_bandwidth_fn πŸ”’
Helper: Calculate the function we should use to find initial relay bandwidths.
w_param πŸ”’
Return the weight param named β€˜kwd’ in p.