pub fn get_consensus_weights(
consensus_filename: &Path,
) -> Result<HashMap<String, i64>>Expand description
Parses consensus bandwidth weights from a cached-microdesc-consensus file.
Bandwidth weights are used by Tor clients to select relays proportionally to their contribution to the network. These weights are essential for the bandwidth-weighted guard selection algorithm.
§Weight Keys
Common weight keys include:
| Key | Description |
|---|---|
Wgg | Weight for Guard-flagged nodes in guard position |
Wgm | Weight for Guard-flagged nodes in middle position |
Wmm | Weight for non-flagged nodes in middle position |
Wme | Weight for Exit-flagged nodes in middle position |
Wee | Weight for Exit-flagged nodes in exit position |
§Arguments
consensus_filename- Path to the cached-microdesc-consensus file
§Returns
A HashMap mapping weight keys (e.g., “Wmm”) to their integer values (typically in range 0-10000, representing parts per 10000).
§Errors
Returns Error::Consensus if:
- The file cannot be opened or read
- No
bandwidth-weightsline is found in the file
§File Format
The function looks for a line starting with bandwidth-weights followed
by space-separated key=value pairs:
bandwidth-weights Wbd=0 Wbe=0 Wbg=4194 Wbm=10000 ...§Example
use std::path::Path;
use vanguards_rs::control::get_consensus_weights;
let weights = get_consensus_weights(Path::new("/var/lib/tor/cached-microdesc-consensus"))?;
if let Some(wmm) = weights.get("Wmm") {
println!("Middle position weight: {}", wmm);
}§See Also
BwWeightedGenerator- Uses these weights- dir-spec.txt - Consensus format specification