pub struct Protocols {
pub(crate) recognized: [u64; 13],
pub(crate) unrecognized: Vec<SubprotocolEntry>,
}
Expand description
A set of supported or required subprotocol versions.
This type supports both recognized subprotocols (listed in ProtoKind), and unrecognized subprotocols (stored by name).
To construct an instance, use the FromStr trait:
use tor_protover::Protocols;
let p: Result<Protocols,_> = "Link=1-3 LinkAuth=2-3 Relay=1-2".parse();
Fields§
§recognized: [u64; 13]
A mapping from protocols’ integer encodings to bit-vectors.
unrecognized: Vec<SubprotocolEntry>
A vector of unrecognized protocol versions, in sorted order.
Every entry in this list has supported != 0.
Implementations§
Source§impl Protocols
impl Protocols
Sourcepub(crate) fn supports_recognized_ver(&self, proto: usize, ver: u8) -> bool
pub(crate) fn supports_recognized_ver(&self, proto: usize, ver: u8) -> bool
Helper: return true iff this protocol set contains the
version ver
of the protocol represented by the integer proto
.
Sourcepub(crate) fn supports_unrecognized_ver(&self, proto: &str, ver: u8) -> bool
pub(crate) fn supports_unrecognized_ver(&self, proto: &str, ver: u8) -> bool
Helper: return true iff this protocol set contains version
ver
of the unrecognized protocol represented by the string
proto
.
Requires that proto
is not the name of a recognized protocol.
Sourcepub fn supports_known_subver(&self, proto: ProtoKind, ver: u8) -> bool
pub fn supports_known_subver(&self, proto: ProtoKind, ver: u8) -> bool
Check whether a known protocol version is supported.
use tor_protover::*;
let protos: Protocols = "Link=1-3 HSDir=2,4-5".parse().unwrap();
assert!(protos.supports_known_subver(ProtoKind::Link, 2));
assert!(protos.supports_known_subver(ProtoKind::HSDir, 4));
assert!(! protos.supports_known_subver(ProtoKind::HSDir, 3));
assert!(! protos.supports_known_subver(ProtoKind::LinkAuth, 3));
Sourcepub fn supports_subver(&self, proto: &str, ver: u8) -> bool
pub fn supports_subver(&self, proto: &str, ver: u8) -> bool
Check whether a protocol version identified by a string is supported.
use tor_protover::*;
let protos: Protocols = "Link=1-3 Foobar=7".parse().unwrap();
assert!(protos.supports_subver("Link", 2));
assert!(protos.supports_subver("Foobar", 7));
assert!(! protos.supports_subver("Link", 5));
assert!(! protos.supports_subver("Foobar", 6));
assert!(! protos.supports_subver("Wombat", 3));
Sourcepub fn supports_named_subver(&self, protover: NamedSubver) -> bool
pub fn supports_named_subver(&self, protover: NamedSubver) -> bool
Check whether a protocol version is supported.
use tor_protover::*;
let protos: Protocols = "Link=1-5 Desc=2-4".parse().unwrap();
assert!(protos.supports_named_subver(named::DESC_FAMILY_IDS)); // Desc=4
assert!(! protos.supports_named_subver(named::CONFLUX_BASE)); // Conflux=1
Sourcepub fn supports_numbered_subver(&self, protover: NumberedSubver) -> bool
pub fn supports_numbered_subver(&self, protover: NumberedSubver) -> bool
Check whether a numbered subprotocol capability is supported.
use tor_protover::*;
let protos: Protocols = "Link=1-5 Desc=2-4".parse().unwrap();
assert!(protos.supports_numbered_subver(NumberedSubver::new(ProtoKind::Desc, 4)));
assert!(! protos.supports_numbered_subver(NumberedSubver::new(ProtoKind::Conflux, 1)));
Sourcepub fn difference(&self, other: &Protocols) -> Protocols
pub fn difference(&self, other: &Protocols) -> Protocols
Return a Protocols holding every protocol flag that is present in self
but not other
.
use tor_protover::*;
let protos: Protocols = "Desc=2-4 Microdesc=1-5".parse().unwrap();
let protos2: Protocols = "Desc=3 Microdesc=3".parse().unwrap();
assert_eq!(protos.difference(&protos2),
"Desc=2,4 Microdesc=1-2,4-5".parse().unwrap());
Sourcepub fn union(&self, other: &Protocols) -> Protocols
pub fn union(&self, other: &Protocols) -> Protocols
Return a Protocols holding every protocol flag that is present in self
or other
or both.
use tor_protover::*;
let protos: Protocols = "Desc=2-4 Microdesc=1-5".parse().unwrap();
let protos2: Protocols = "Desc=3 Microdesc=10".parse().unwrap();
assert_eq!(protos.union(&protos2),
"Desc=2-4 Microdesc=1-5,10".parse().unwrap());
Sourcepub fn intersection(&self, other: &Protocols) -> Protocols
pub fn intersection(&self, other: &Protocols) -> Protocols
Return a Protocols holding every protocol flag that is present in both self
and other
.
use tor_protover::*;
let protos: Protocols = "Desc=2-4 Microdesc=1-5".parse().unwrap();
let protos2: Protocols = "Desc=3 Microdesc=10".parse().unwrap();
assert_eq!(protos.intersection(&protos2),
"Desc=3".parse().unwrap());
Sourcepub(crate) fn add(
&mut self,
foundmask: &mut u64,
ent: SubprotocolEntry,
) -> Result<(), ParseError>
pub(crate) fn add( &mut self, foundmask: &mut u64, ent: SubprotocolEntry, ) -> Result<(), ParseError>
Parsing helper: Try to add a new entry ent
to this set of protocols.
Uses foundmask
, a bit mask saying which recognized protocols
we’ve already found entries for. Returns an error if ent
is
for a protocol we’ve already added.
Does not preserve sorting order; the caller must call self.unrecognized.sort()
before returning.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Protocols
impl<'de> Deserialize<'de> for Protocols
Source§fn deserialize<__D>(deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Protocols
The Display trait formats a protocol set in the format expected by Tor
consensus documents.
impl Display for Protocols
The Display trait formats a protocol set in the format expected by Tor consensus documents.
use tor_protover::*;
let protos: Protocols = "Link=1,2,3 Foobar=7 Relay=2".parse().unwrap();
assert_eq!(format!("{}", protos),
"Foobar=7 Link=1-3 Relay=2");
Source§impl FromIterator<NamedSubver> for Protocols
impl FromIterator<NamedSubver> for Protocols
Source§fn from_iter<T: IntoIterator<Item = NamedSubver>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = NamedSubver>>(iter: T) -> Self
Source§impl FromStr for Protocols
A Protocols set can be parsed from a string according to the
format used in Tor consensus documents.
impl FromStr for Protocols
A Protocols set can be parsed from a string according to the format used in Tor consensus documents.
A protocols set is represented by a space-separated list of
entries. Each entry is of the form Name=Versions
, where Name
is the name of a protocol, and Versions
is a comma-separated
list of version numbers and version ranges. Each version range is
a pair of integers separated by -
.
No protocol name may be listed twice. No version may be listed twice for a single protocol. All versions must be in range 0 through 63 inclusive.
impl Eq for Protocols
impl StructuralPartialEq for Protocols
Auto Trait Implementations§
impl Freeze for Protocols
impl RefUnwindSafe for Protocols
impl Send for Protocols
impl Sync for Protocols
impl Unpin for Protocols
impl UnwindSafe for Protocols
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more