1
//! Consensus methods
2

            
3
// We have many free functions that have signatures matching `Aggregate::aggregate`, etc.
4
// This annoys clippy because it can't see they have to be that way.
5
//
6
// These lints are generally not all that useful anyway.  Suppress them in this whole code area.
7
#![allow(clippy::needless_pass_by_value, clippy::unnecessary_wraps)]
8

            
9
use crate::internal_prelude::*;
10

            
11
use tor_netdoc::doc::netstatus::{
12
    self, NetParamValues, NetParams, ParamValues, PlainPreamble, RelayBandwidthItem,
13
    VoteRelayBandwidthItem,
14
};
15
use tor_netdoc::types::{
16
    DigestName, NotPresent,
17
    relay_flags::{DocRelayFlags, RelayFlag},
18
};
19

            
20
// md calculations
21
mod ip_summary;
22
mod method;
23
mod microdesc;
24
mod tracked_method;
25

            
26
// consensus calculations
27
#[macro_use]
28
mod framework;
29
#[macro_use]
30
mod calculate_macros;
31
mod footer;
32
mod functions;
33
mod preamble;
34
#[macro_use]
35
mod rs_common;
36
mod rs_body;
37
mod rs_select;
38
mod shared_random;
39
mod toplevel;
40

            
41
use footer::*;
42
pub use framework::*;
43
use functions::ComponentInVotesOptionExt;
44
pub use method::*;
45
pub use microdesc::*;
46
use shared_random::*;
47
pub use toplevel::*;
48
pub use tracked_method::*;
49

            
50
/// Supported consensus methods
51
///
52
/// Not guaranteed to be minimal, but guaranteed to be well-formed,
53
/// sorted and non-overlapping.
54
///
55
/// See <https://spec.torproject.org/dir-spec/computing-consensus.html#consensus-method-list>
56
/// for where these values come from.
57
///
58
/// In tor-dirauth, we use literal numeric constants for consensus method values,
59
/// rather than trying to give each consensus method a named `const`.
60
pub const SUPPORTED_METHODS: &[RangeInclusive<ConsensusMethod>] = {
61
    use ConsensusMethod as M;
62
    &[
63
        // This list is where the set of supported methods is defined.
64
        // Only values listed here can be made into a `SupportedConsensusMethod`.
65
        //
66
        M(100)..=M(100),
67
    ]
68
};
69

            
70
#[cfg(test)]
71
pub(crate) mod test {
72
    // @@ begin test lint list maintained by maint/add_warning @@
73
    #![allow(clippy::bool_assert_comparison)]
74
    #![allow(clippy::clone_on_copy)]
75
    #![allow(clippy::dbg_macro)]
76
    #![allow(clippy::mixed_attributes_style)]
77
    #![allow(clippy::print_stderr)]
78
    #![allow(clippy::print_stdout)]
79
    #![allow(clippy::single_char_pattern)]
80
    #![allow(clippy::unwrap_used)]
81
    #![allow(clippy::unchecked_time_subtraction)]
82
    #![allow(clippy::useless_vec)]
83
    #![allow(clippy::needless_pass_by_value)]
84
    #![allow(clippy::string_slice)] // See arti#2571
85
    //! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
86
    use super::*;
87

            
88
    pub(crate) use toplevel::test::compute_test;
89

            
90
    #[test]
91
    fn supported_well_formed() {
92
        for r in SUPPORTED_METHODS {
93
            assert!(r.start() <= r.end());
94
        }
95
        for pair in SUPPORTED_METHODS.windows(2) {
96
            assert!(pair[0].end() < pair[1].start());
97
        }
98
    }
99
}