mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
rust: Refactor protover::is_supported_here().
This changes `protover::is_supported_here()` to be aware of new datatypes (e.g. don't call `.0` on things which are no longer tuple structs) and also changes the method signature to take borrows, making it faster, threadable, and easier to read (i.e. the caller can know from reading the function signature that the function won't mutate values passed into it). * CHANGE the `protover::is_supported_here()` function to take borrows. * REFACTOR the `protover::is_supported_here()` function to be aware of new datatypes. * FIXES part of #24031: https://bugs.torproject.org/24031
This commit is contained in:
parent
2eb1b7f2fd
commit
35b86a12e6
@ -590,26 +590,25 @@ impl ProtoverVote {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use protover::*;
|
/// use protover::is_supported_here;
|
||||||
|
/// use protover::Protocol;
|
||||||
///
|
///
|
||||||
/// let is_supported = is_supported_here(Proto::Link, 10);
|
/// let is_supported = is_supported_here(&Protocol::Link, &10);
|
||||||
/// assert_eq!(false, is_supported);
|
/// assert_eq!(false, is_supported);
|
||||||
///
|
///
|
||||||
/// let is_supported = is_supported_here(Proto::Link, 1);
|
/// let is_supported = is_supported_here(&Protocol::Link, &1);
|
||||||
/// assert_eq!(true, is_supported);
|
/// assert_eq!(true, is_supported);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn is_supported_here(proto: Proto, vers: Version) -> bool {
|
pub fn is_supported_here(proto: &Protocol, vers: &Version) -> bool {
|
||||||
let currently_supported = match SupportedProtocols::tor_supported() {
|
let currently_supported: ProtoEntry = match ProtoEntry::supported() {
|
||||||
Ok(result) => result.0,
|
Ok(result) => result,
|
||||||
Err(_) => return false,
|
Err(_) => return false,
|
||||||
};
|
};
|
||||||
|
let supported_versions = match currently_supported.get(proto) {
|
||||||
let supported_versions = match currently_supported.get(&proto) {
|
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
|
supported_versions.contains(vers)
|
||||||
supported_versions.0.contains(&vers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Older versions of Tor cannot infer their own subprotocols
|
/// Older versions of Tor cannot infer their own subprotocols
|
||||||
|
Loading…
Reference in New Issue
Block a user