1
//! Consensus methods
2

            
3
use crate::internal_prelude::*;
4

            
5
use tor_netdoc::doc::netstatus::{
6
    self, NetParams, PlainPreamble, RelayWeightsItem, VoteRelayWeightsItem,
7
};
8
use tor_netdoc::types::{
9
    NotPresent,
10
    relay_flags::{DocRelayFlags, RelayFlag},
11
};
12

            
13
// md calculations
14
mod ip_summary;
15
mod method;
16
mod microdesc;
17
mod tracked_method;
18

            
19
// consensus calculations
20
#[macro_use]
21
mod calculate_macros;
22
mod framework;
23
mod functions;
24
mod preamble;
25
#[macro_use]
26
mod rs_common;
27
mod rs_body;
28
mod rs_select;
29
mod toplevel;
30

            
31
pub use framework::*;
32
pub use method::*;
33
pub use microdesc::*;
34
pub use toplevel::*;
35
pub use tracked_method::*;
36

            
37
/// Supported consensus methods
38
///
39
/// Not guaranteed to be minimal, but guaranteed to be well-formed,
40
/// sorted and non-overlapping.
41
///
42
/// See <https://spec.torproject.org/dir-spec/computing-consensus.html#consensus-method-list>
43
/// for where these values come from.
44
///
45
/// In tor-dirauth, we use literal numeric constants for consensus method values,
46
/// rather than trying to give each consensus method a named `const`.
47
pub const SUPPORTED_METHODS: &[RangeInclusive<ConsensusMethod>] = {
48
    use ConsensusMethod as M;
49
    &[
50
        // This list is where the set of supported methods is defined.
51
        // Only values listed here can be made into a `SupportedConsensusMethod`.
52
        //
53
        M(100)..=M(100),
54
    ]
55
};
56

            
57
#[cfg(test)]
58
mod test {
59
    // @@ begin test lint list maintained by maint/add_warning @@
60
    #![allow(clippy::bool_assert_comparison)]
61
    #![allow(clippy::clone_on_copy)]
62
    #![allow(clippy::dbg_macro)]
63
    #![allow(clippy::mixed_attributes_style)]
64
    #![allow(clippy::print_stderr)]
65
    #![allow(clippy::print_stdout)]
66
    #![allow(clippy::single_char_pattern)]
67
    #![allow(clippy::unwrap_used)]
68
    #![allow(clippy::unchecked_time_subtraction)]
69
    #![allow(clippy::useless_vec)]
70
    #![allow(clippy::needless_pass_by_value)]
71
    #![allow(clippy::string_slice)] // See arti#2571
72
    //! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
73
    use super::*;
74

            
75
    #[test]
76
    fn supported_well_formed() {
77
        for r in SUPPORTED_METHODS {
78
            assert!(r.start() <= r.end());
79
        }
80
        for pair in SUPPORTED_METHODS.windows(2) {
81
            assert!(pair[0].end() < pair[1].start());
82
        }
83
    }
84
}