netdir, netdoc: Add accessors for protocol version status.

The consensus includes a listing for clients and for relays,
saying which protocol versions are _required_ for participation on
the network, and which versions are _recommended_.  We have been
parsing this, but not yet exposing it.

This commit adds accessors to expose it, since we'll need that in
order to create CircTargets for introduction points and rendezvous
points.
This commit is contained in:
Nick Mathewson 2023-06-06 09:06:01 -04:00
parent 9a30d76ea6
commit 205b6d176c
4 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,2 @@
ADDED: Accessor for relay protocol status.

View File

@ -1081,6 +1081,25 @@ impl NetDir {
pub fn params(&self) -> &NetParameters {
&self.params
}
/// Return a [`ProtoStatus`](netstatus::ProtoStatus) that lists the
/// network's current requirements and recommendations for the list of
/// protocols that every relay must implement.
//
// TODO HS: I am not sure this is the right API; other alternatives would be:
// * To expose the _required_ relay protocol list instead (since that's all that
// onion service implementations need).
// * To expose the client protocol list as well (for symmetry).
// * To expose the MdConsensus instead (since that's more general, although
// it restricts the future evolution of this API).
//
// I think that this is a reasonably good compromise for now, but I'm going
// to put it behind the `hs-common` feature to give us time to consider more.
#[cfg(feature = "hs-common")]
pub fn relay_protocol_status(&self) -> &netstatus::ProtoStatus {
self.consensus.relay_protocol_status()
}
/// Return weighted the fraction of relays we can use. We only
/// consider relays that match the predicate `usable`. We weight
/// this bandwidth according to the provided `role`.

View File

@ -0,0 +1,2 @@
ADDED: accessors for protocol status.

View File

@ -201,6 +201,8 @@ where
}
/// A list of subprotocol versions that implementors should/must provide.
///
/// Each consensus has two of these: one for relays, and one for clients.
#[allow(dead_code)]
#[derive(Debug, Clone, Default)]
pub struct ProtoStatus {
@ -679,6 +681,18 @@ impl<RS> Consensus<RS> {
pub fn shared_rand_prev(&self) -> Option<&SharedRandStatus> {
self.header.shared_rand_prev.as_ref()
}
/// Return a [`ProtoStatus`] that lists the network's current requirements and
/// recommendations for the list of protocols that every relay must implement.
pub fn relay_protocol_status(&self) -> &ProtoStatus {
&self.header.hdr.relay_protos
}
/// Return a [`ProtoStatus`] that lists the network's current requirements and
/// recommendations for the list of protocols that every client must implement.
pub fn client_protocol_status(&self) -> &ProtoStatus {
&self.header.hdr.client_protos
}
}
decl_keyword! {
@ -895,6 +909,24 @@ impl ProtoStatus {
required,
})
}
/// Return the protocols that are listed as "required" in this `ProtoStatus`.
///
/// Implementations may assume that relays on the network implement all the
/// protocols in the relays' required-protocols list. Implementations should
/// refuse to start if they do not implement all the protocols on their own
/// (client or relay) required-protocols list.
pub fn required_protocols(&self) -> &Protocols {
&self.required
}
/// Return the protocols that are listed as "recommended" in this `ProtoStatus`.
///
/// Implementations should warn if they do not implement all the protocols
/// on their own (client or relay) recommended-protocols list.
pub fn recommended_protocols(&self) -> &Protocols {
&self.recommended
}
}
impl<T> std::str::FromStr for NetParams<T>