RouterStatusEntry

Struct RouterStatusEntry 

Source
pub struct RouterStatusEntry {
Show 22 fields pub entry_type: RouterStatusEntryType, pub nickname: String, pub fingerprint: String, pub digest: Option<String>, pub published: DateTime<Utc>, pub address: IpAddr, pub or_port: u16, pub dir_port: Option<u16>, pub or_addresses: Vec<(IpAddr, u16, bool)>, pub flags: Vec<String>, pub version_line: Option<String>, pub version: Option<Version>, pub bandwidth: Option<u64>, pub measured: Option<u64>, pub is_unmeasured: bool, pub unrecognized_bandwidth_entries: Vec<String>, pub exit_policy: Option<MicroExitPolicy>, pub protocols: HashMap<String, Vec<u32>>, pub microdescriptor_digest: Option<String>, pub microdescriptor_hashes: Vec<MicrodescriptorHash>, pub identifier_type: Option<String>, pub identifier: Option<String>, /* private fields */
}
Expand description

Information about an individual relay in a network status document.

A RouterStatusEntry contains the essential information about a single relay as recorded in a network status consensus or vote. This includes the relay’s identity, network location, capabilities, and performance characteristics.

§Overview

Router status entries are the building blocks of consensus documents. Each entry describes one relay and contains:

  • Identity: Nickname, fingerprint, and optional Ed25519 identity
  • Network: IP address, OR port, directory port, additional addresses
  • Capabilities: Flags assigned by directory authorities
  • Performance: Bandwidth weights for path selection
  • Policy: Exit policy summary
  • Version: Tor software version

§Entry Types

The entry_type field determines the format:

TypeDigest FieldMicrodescriptor
V2digest (hex)N/A
V3digest (hex)Via m line in votes
MicroV3N/Amicrodescriptor_digest
Bridgedigest (hex)N/A

§Parsing

Use the appropriate parsing method for your entry type:

§Example

use stem_rs::descriptor::router_status::RouterStatusEntry;

let content = r#"r example ARIJF2zbqirB9IwsW0mQznccWww oQZFLYe9e4A7bOkWKR7TaNxb0JE 2024-01-15 12:00:00 192.0.2.1 9001 9030
s Fast Guard Running Stable Valid
v Tor 0.4.8.10
w Bandwidth=5000 Measured=4800
p accept 80,443"#;

let entry = RouterStatusEntry::parse(content).unwrap();

// Access relay identity
assert_eq!(entry.nickname, "example");
assert!(!entry.fingerprint.is_empty());

// Check flags
assert!(entry.flags.contains(&"Guard".to_string()));
assert!(entry.flags.contains(&"Running".to_string()));

// Check bandwidth
assert_eq!(entry.bandwidth, Some(5000));
assert_eq!(entry.measured, Some(4800));

§Flags

The flags field contains strings assigned by directory authorities. Common flags include:

  • Authority - A directory authority
  • BadExit - Believed to be useless as an exit
  • Exit - Suitable for exit traffic
  • Fast - Suitable for high-bandwidth circuits
  • Guard - Suitable as an entry guard
  • HSDir - Hidden service directory
  • Running - Currently usable
  • Stable - Suitable for long-lived circuits
  • Valid - Has been validated

§Thread Safety

RouterStatusEntry is Send and Sync, making it safe to share across threads.

§See Also

Fields§

§entry_type: RouterStatusEntryType

The type of this router status entry.

Determines the format and which fields are available.

§nickname: String

The relay’s nickname (1-19 alphanumeric characters).

Nicknames are not unique identifiers; use fingerprint for reliable relay identification.

§fingerprint: String

The relay’s identity fingerprint as uppercase hexadecimal.

This is a 40-character hex string representing the SHA-1 hash of the relay’s identity key. This is the authoritative identifier for a relay.

§digest: Option<String>

SHA-1 digest of the relay’s server descriptor (hex, uppercase).

Present in V2, V3, and Bridge entries. Not present in MicroV3 entries (use microdescriptor_digest instead).

§published: DateTime<Utc>

When the relay’s descriptor was published (UTC).

§address: IpAddr

The relay’s primary IP address.

§or_port: u16

The relay’s OR (onion router) port for relay traffic.

§dir_port: Option<u16>

The relay’s directory port, if it serves directory information.

None if the relay doesn’t serve directory information (port 0).

§or_addresses: Vec<(IpAddr, u16, bool)>

Additional OR addresses (typically IPv6).

Each tuple contains (address, port, is_ipv6). The primary address is in the address field; this contains additional addresses from a lines.

§flags: Vec<String>

Flags assigned to this relay by directory authorities.

Common flags: “Authority”, “BadExit”, “Exit”, “Fast”, “Guard”, “HSDir”, “Running”, “Stable”, “Valid”, “V2Dir”.

§version_line: Option<String>

The raw version line from the entry.

Typically starts with “Tor “ followed by the version number.

§version: Option<Version>

Parsed Tor version, if the version line was parseable.

None if the relay uses a non-standard version format.

§bandwidth: Option<u64>

Consensus bandwidth weight (arbitrary units, typically KB/s).

Used for path selection weighting. Higher values indicate more bandwidth capacity.

§measured: Option<u64>

Bandwidth measured by bandwidth authorities.

More accurate than self-reported bandwidth. Used when available.

§is_unmeasured: bool

Whether the bandwidth value is unmeasured.

true if the bandwidth is not based on actual measurements (fewer than 3 measurements available).

§unrecognized_bandwidth_entries: Vec<String>

Unrecognized entries from the w (bandwidth) line.

Contains any bandwidth-related key=value pairs that weren’t recognized during parsing.

§exit_policy: Option<MicroExitPolicy>

Exit policy summary from the p line.

A compact representation of the relay’s exit policy.

§protocols: HashMap<String, Vec<u32>>

Protocol versions supported by this relay.

Maps protocol names (e.g., “Link”, “Relay”) to lists of supported version numbers.

§microdescriptor_digest: Option<String>

Microdescriptor digest (base64) for MicroV3 entries.

Used to fetch the corresponding microdescriptor.

§microdescriptor_hashes: Vec<MicrodescriptorHash>

Microdescriptor hashes from vote documents.

Contains digests computed using different consensus methods. Only present in vote documents, not consensus documents.

§identifier_type: Option<String>

Ed25519 identity key type (typically “ed25519”).

Present in vote documents when the relay has an Ed25519 key.

§identifier: Option<String>

Ed25519 identity key value (base64).

The value “none” indicates the relay doesn’t have an Ed25519 key.

Implementations§

Source§

impl RouterStatusEntry

Source

pub fn new( entry_type: RouterStatusEntryType, nickname: String, fingerprint: String, published: DateTime<Utc>, address: IpAddr, or_port: u16, ) -> Self

Creates a new router status entry with minimal required fields.

This constructor creates an entry with only the essential fields populated. Optional fields are set to their default values.

§Arguments
  • entry_type - The type of entry (V2, V3, MicroV3, or Bridge)
  • nickname - The relay’s nickname (1-19 alphanumeric characters)
  • fingerprint - The relay’s identity fingerprint (40 hex characters)
  • published - When the relay’s descriptor was published
  • address - The relay’s primary IP address
  • or_port - The relay’s OR port
§Example
use stem_rs::descriptor::router_status::{RouterStatusEntry, RouterStatusEntryType};
use chrono::Utc;
use std::net::IpAddr;

let entry = RouterStatusEntry::new(
    RouterStatusEntryType::V3,
    "example".to_string(),
    "AABBCCDD".repeat(5),
    Utc::now(),
    "192.0.2.1".parse().unwrap(),
    9001,
);

assert_eq!(entry.nickname, "example");
assert_eq!(entry.or_port, 9001);
Source

pub fn parse(content: &str) -> Result<Self, Error>

Parses a V3 router status entry from a string.

This is the standard parsing method for entries from network status v3 consensus documents.

§Arguments
  • content - The entry content as a multi-line string
§Returns

A parsed RouterStatusEntry on success.

§Errors

Returns Error::Parse if:

  • The r line is missing or malformed
  • Required fields cannot be parsed
  • The fingerprint cannot be decoded from base64
§Example
use stem_rs::descriptor::router_status::RouterStatusEntry;

let content = r#"r example ARIJF2zbqirB9IwsW0mQznccWww oQZFLYe9e4A7bOkWKR7TaNxb0JE 2024-01-15 12:00:00 192.0.2.1 9001 0
s Fast Running Valid"#;

let entry = RouterStatusEntry::parse(content).unwrap();
assert_eq!(entry.nickname, "example");
Source

pub fn parse_micro(content: &str) -> Result<Self, Error>

Parses a microdescriptor-flavored V3 router status entry.

Use this method for entries from microdescriptor consensus documents. The main difference from parse() is that the r line does not contain a server descriptor digest.

§Arguments
  • content - The entry content as a multi-line string
§Returns

A parsed RouterStatusEntry with entry_type set to MicroV3.

§Errors

Returns Error::Parse if the entry is malformed.

§Example
use stem_rs::descriptor::router_status::RouterStatusEntry;

let content = r#"r example ARIJF2zbqirB9IwsW0mQznccWww 2024-01-15 12:00:00 192.0.2.1 9001 0
m aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70
s Fast Running Valid"#;

let entry = RouterStatusEntry::parse_micro(content).unwrap();
assert!(entry.digest.is_none());
assert!(entry.microdescriptor_digest.is_some());
Source

pub fn parse_v2(content: &str) -> Result<Self, Error>

Parses a legacy V2 router status entry.

Use this method for entries from older network status v2 documents.

§Arguments
  • content - The entry content as a multi-line string
§Returns

A parsed RouterStatusEntry with entry_type set to V2.

§Errors

Returns Error::Parse if the entry is malformed.

Source

pub fn parse_vote(content: &str) -> Result<Self, Error>

Parses a router status entry from a vote document.

Vote documents may contain additional fields not present in consensus documents, such as Ed25519 identity keys (id line) and microdescriptor hashes (m lines with method numbers).

§Arguments
  • content - The entry content as a multi-line string
§Returns

A parsed RouterStatusEntry with vote-specific fields populated.

§Errors

Returns Error::Parse if the entry is malformed.

§Example
use stem_rs::descriptor::router_status::RouterStatusEntry;

let content = r#"r example ARIJF2zbqirB9IwsW0mQznccWww oQZFLYe9e4A7bOkWKR7TaNxb0JE 2024-01-15 12:00:00 192.0.2.1 9001 0
s Fast Running Valid
id ed25519 8RH34kO07Pp+XYwzdoATVyCibIvmbslUjRkAm7J4IA8
m 13,14,15 sha256=uaAYTOVuYRqUwJpNfP2WizjzO0FiNQB4U97xSQu+vMc"#;

let entry = RouterStatusEntry::parse_vote(content).unwrap();
assert_eq!(entry.identifier_type, Some("ed25519".to_string()));
assert!(!entry.microdescriptor_hashes.is_empty());
Source

pub fn parse_with_type( content: &str, entry_type: RouterStatusEntryType, is_vote: bool, ) -> Result<Self, Error>

Parses a router status entry with explicit type and vote flag.

This is the general-purpose parsing method that other parse methods delegate to. Use this when you need explicit control over the entry type and whether vote-specific parsing should be enabled.

§Arguments
  • content - The entry content as a multi-line string
  • entry_type - The type of entry to parse as
  • is_vote - Whether to enable vote-specific parsing (for m and id lines)
§Returns

A parsed RouterStatusEntry on success.

§Errors

Returns Error::Parse if:

  • The r line is missing or has insufficient fields
  • The fingerprint or digest cannot be decoded from base64
  • The IP address is invalid
  • The ports are invalid
  • The publication timestamp is malformed
§Line Parsing

The following lines are recognized:

KeywordDescription
rRouter identity (required)
aAdditional OR addresses
sFlags
vVersion
wBandwidth weights
pExit policy summary
prProtocol versions
mMicrodescriptor digest/hashes
idEd25519 identity (votes only)
Source

pub fn unrecognized_lines(&self) -> &[String]

Returns lines that weren’t recognized during parsing.

This is useful for forward compatibility when new fields are added to the router status entry format.

§Returns

A slice of unrecognized line strings.

Trait Implementations§

Source§

impl Clone for RouterStatusEntry

Source§

fn clone(&self) -> RouterStatusEntry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RouterStatusEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RouterStatusEntry

Formats the router status entry back to its string representation.

The output follows the standard router status entry format and can be parsed back using the appropriate parse_* method.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for RouterStatusEntry

Parses a router status entry from a string.

This implementation delegates to RouterStatusEntry::parse(), parsing the content as a V3 consensus entry.

§Example

use stem_rs::descriptor::router_status::RouterStatusEntry;
use std::str::FromStr;

let content = r#"r example ARIJF2zbqirB9IwsW0mQznccWww oQZFLYe9e4A7bOkWKR7TaNxb0JE 2024-01-15 12:00:00 192.0.2.1 9001 0
s Running Valid"#;

let entry = RouterStatusEntry::from_str(content).unwrap();
assert_eq!(entry.nickname, "example");
Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for RouterStatusEntry

Source§

fn eq(&self, other: &RouterStatusEntry) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for RouterStatusEntry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.