netdoc: add a few accessors

This commit is contained in:
Nick Mathewson 2020-09-07 18:07:34 -04:00
parent a4f1b27334
commit 17217a7dfa
2 changed files with 42 additions and 2 deletions

View File

@ -56,6 +56,22 @@ impl Microdesc {
pub fn get_digest(&self) -> &MDDigest {
&self.sha256
}
/// Return the ntor onion key for this microdesc
pub fn get_ntor_key(&self) -> &curve25519::PublicKey {
&self.ntor_onion_key
}
/// Return the ipv4 exit policy for this microdesc
pub fn get_ipv4_policy(&self) -> &PortPolicy {
&self.ipv4_policy
}
/// Return the ipv6 exit policy for this microdesc
pub fn get_ipv6_policy(&self) -> &PortPolicy {
&self.ipv6_policy
}
/// Return the ed25519 identity for this microdesc (if any)
pub fn get_opt_ed25519_id(&self) -> &Option<ed25519::PublicKey> {
&self.ed25519_id
}
}
/// A microdescriptor annotated with additional data

View File

@ -178,20 +178,37 @@ enum RouterWeight {
/// A single relay's status as represented in a microdesc consensus.
#[allow(dead_code)]
struct MDConsensusRouterStatus {
pub struct MDConsensusRouterStatus {
nickname: String,
identity: RSAIdentity,
published: time::SystemTime,
addrs: Vec<net::SocketAddr>,
or_port: u16,
dir_port: u16,
md_digest: [u8; 32],
md_digest: crate::microdesc::MDDigest,
flags: RouterFlags,
version: Option<String>,
protos: Option<Protocols>,
weight: RouterWeight,
}
// TODO: These methods should probably become, in whole or in part,
// methods on a RouterStatus trait.
impl MDConsensusRouterStatus {
/// Return the expected microdescriptor digest for this routerstatus
pub fn get_md_digest(&self) -> &crate::microdesc::MDDigest {
&self.md_digest
}
/// Return the expected microdescriptor digest for this routerstatus
pub fn get_rsa_identity(&self) -> &RSAIdentity {
&self.identity
}
/// Return an iterator of ORPort addresses for this routerstatus
pub fn orport_addrs(&self) -> impl Iterator<Item=&net::SocketAddr> {
self.addrs.iter()
}
}
/// All information about a single authority, as represented in a consensus
#[allow(dead_code)]
struct ConsensusVoterInfo {
@ -218,6 +235,13 @@ pub struct MDConsensus {
footer: Footer,
}
impl MDConsensus {
/// Return a slice of all the routerstatus entries in this consensus.
pub fn get_routers(&self) -> &[MDConsensusRouterStatus] {
&self.routers[..]
}
}
decl_keyword! {
/// Keywords that can be used in votes and consensuses.
NetstatusKW {