NetworkStatusDocument

Struct NetworkStatusDocument 

Source
pub struct NetworkStatusDocument {
Show 26 fields pub version: u32, pub version_flavor: String, pub is_consensus: bool, pub is_vote: bool, pub is_microdescriptor: bool, pub consensus_method: Option<u32>, pub consensus_methods: Option<Vec<u32>>, pub published: Option<DateTime<Utc>>, pub valid_after: DateTime<Utc>, pub fresh_until: DateTime<Utc>, pub valid_until: DateTime<Utc>, pub vote_delay: Option<u32>, pub dist_delay: Option<u32>, pub client_versions: Vec<Version>, pub server_versions: Vec<Version>, pub known_flags: Vec<String>, pub recommended_client_protocols: HashMap<String, Vec<u32>>, pub recommended_relay_protocols: HashMap<String, Vec<u32>>, pub required_client_protocols: HashMap<String, Vec<u32>>, pub required_relay_protocols: HashMap<String, Vec<u32>>, pub params: HashMap<String, i32>, pub shared_randomness_previous: Option<SharedRandomness>, pub shared_randomness_current: Option<SharedRandomness>, pub bandwidth_weights: HashMap<String, i32>, pub authorities: Vec<DirectoryAuthority>, pub signatures: Vec<DocumentSignature>, /* private fields */
}
Expand description

A network status consensus or vote document.

This is the primary document that describes the state of the Tor network. Clients download the consensus to learn about available relays and their capabilities.

§Document Types

  • Consensus (is_consensus = true): The agreed-upon network view
  • Vote (is_vote = true): An individual authority’s opinion
  • Microdesc (is_microdescriptor = true): Uses microdescriptor hashes

§Validity Times

The document has three important timestamps that control its lifecycle:

valid-after -----> fresh-until -----> valid-until
    |                  |                  |
    |   Document is    |   Should fetch   |   Document
    |   fresh/current  |   new consensus  |   expired

§Example

use stem_rs::descriptor::{NetworkStatusDocument, Descriptor};

let content = std::fs::read_to_string("cached-consensus").unwrap();
let doc = NetworkStatusDocument::parse(&content).unwrap();

// Check document type
if doc.is_consensus {
    println!("This is a consensus document");
}

// Check validity
let now = chrono::Utc::now();
if now > doc.valid_until {
    println!("Consensus has expired!");
} else if now > doc.fresh_until {
    println!("Should fetch a new consensus");
}

// Check required protocols
for (proto, versions) in &doc.required_client_protocols {
    println!("Required {}: {:?}", proto, versions);
}

§Thread Safety

NetworkStatusDocument is Send and Sync as it contains only owned data.

Fields§

§version: u32

Network status version (typically 3).

§version_flavor: String

Version flavor (empty string or “microdesc”).

§is_consensus: bool

Whether this is a consensus document.

§is_vote: bool

Whether this is a vote document.

§is_microdescriptor: bool

Whether this uses microdescriptor format.

§consensus_method: Option<u32>

Consensus method used (consensus only).

§consensus_methods: Option<Vec<u32>>

Supported consensus methods (vote only).

§published: Option<DateTime<Utc>>

When this vote was published (vote only).

§valid_after: DateTime<Utc>

When this document becomes valid.

§fresh_until: DateTime<Utc>

When clients should fetch a new document.

§valid_until: DateTime<Utc>

When this document expires.

§vote_delay: Option<u32>

Seconds authorities wait for votes.

§dist_delay: Option<u32>

Seconds authorities wait for signatures.

§client_versions: Vec<Version>

Recommended Tor versions for clients.

§server_versions: Vec<Version>

Recommended Tor versions for relays.

§known_flags: Vec<String>

Flags that may appear on relay entries.

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

Recommended protocol versions for clients.

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

Recommended protocol versions for relays.

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

Required protocol versions for clients.

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

Required protocol versions for relays.

§params: HashMap<String, i32>

Consensus parameters (key=value pairs).

§shared_randomness_previous: Option<SharedRandomness>

Previous shared randomness value.

§shared_randomness_current: Option<SharedRandomness>

Current shared randomness value.

§bandwidth_weights: HashMap<String, i32>

Bandwidth weights for path selection.

§authorities: Vec<DirectoryAuthority>

Directory authorities that contributed to this document.

§signatures: Vec<DocumentSignature>

Signatures from directory authorities.

Trait Implementations§

Source§

impl Clone for NetworkStatusDocument

Source§

fn clone(&self) -> NetworkStatusDocument

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 NetworkStatusDocument

Source§

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

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

impl Descriptor for NetworkStatusDocument

Source§

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

Parses a descriptor from its string content. Read more
Source§

fn to_descriptor_string(&self) -> String

Serializes the descriptor to its canonical string format. Read more
Source§

fn digest( &self, hash: DigestHash, encoding: DigestEncoding, ) -> Result<String, Error>

Computes the cryptographic digest of the descriptor. Read more
Source§

fn raw_content(&self) -> &[u8]

Returns the raw bytes of the original descriptor content. Read more
Source§

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

Returns lines from the descriptor that were not recognized. Read more
Source§

impl Display for NetworkStatusDocument

Source§

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

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

impl FromStr for NetworkStatusDocument

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 NetworkStatusDocument

Source§

fn eq(&self, other: &NetworkStatusDocument) -> 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 NetworkStatusDocument

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.