tor_netdoc/doc/netstatus/
rs.rs1#[cfg(feature = "build_docs")]
7pub(crate) mod build;
8pub(crate) mod md;
9#[cfg(feature = "plain-consensus")]
10pub(crate) mod plain;
11#[cfg(feature = "ns-vote")]
12pub(crate) mod vote;
13
14use super::{ConsensusFlavor, ConsensusMethods};
15use crate::doc;
16use crate::doc::netstatus::NetstatusKwd;
17use crate::doc::netstatus::{IgnoredPublicationTimeSp, Protocols, RelayFlags, RelayWeight};
18use crate::parse::parser::Section;
19use crate::types::misc::*;
20use crate::types::version::TorVersion;
21use crate::util::intern::InternCache;
22use crate::{Error, NetdocErrorKind as EK, Result};
23use itertools::chain;
24use std::sync::Arc;
25use std::{net, time};
26use tor_error::internal;
27use tor_llcrypto::pk::rsa::RsaIdentity;
28
29#[cfg(feature = "parse2")]
30use {
31 super::consensus_methods_comma_separated, derive_deftly::Deftly,
33};
34
35#[derive(Clone, Debug, Eq, PartialEq, Hash, derive_more::Display)]
41#[non_exhaustive]
42pub enum Version {
43 Tor(TorVersion),
45 Other(Arc<str>),
47}
48
49static OTHER_VERSION_CACHE: InternCache<str> = InternCache::new();
54
55#[derive(Debug, Clone, Default, Eq, PartialEq)]
71#[cfg(feature = "ns-vote")]
72#[cfg_attr(feature = "parse2", derive(Deftly), derive_deftly(ItemValueParseable))]
73#[non_exhaustive]
74pub struct RouterStatusMdDigestsVote {
75 #[cfg_attr(
77 feature = "parse2",
78 deftly(netdoc(with = "consensus_methods_comma_separated"))
79 )]
80 pub consensus_methods: ConsensusMethods,
81
82 pub digests: Vec<IdentifiedDigest>,
84}
85
86impl std::str::FromStr for Version {
87 type Err = Error;
88
89 fn from_str(s: &str) -> Result<Self> {
90 let mut elts = s.splitn(3, ' ');
91 if elts.next() == Some("Tor") {
92 if let Some(Ok(v)) = elts.next().map(str::parse) {
93 return Ok(Version::Tor(v));
94 }
95 }
96
97 Ok(Version::Other(OTHER_VERSION_CACHE.intern_ref(s)))
98 }
99}
100
101trait FromRsString: Sized {
104 fn decode(s: &str) -> Result<Self>;
106}