1
//! Calculate consensus footer
2

            
3
use super::*;
4

            
5
/// "Already computed" for footer calculoations
6
///
7
/// The footer can depend on all the previous consensus, notably the preamble and the routers.
8
#[derive(Debug, Clone, Copy)]
9
#[allow(unused)] // TODO DIRAUTH
10
pub(super) struct FooterAC<'r> {
11
    /// Preamble
12
    pub preamble: &'r netstatus::plain::Preamble,
13
    /// Routerstatuses
14
    pub routers: &'r [netstatus::plain::RouterStatus],
15
}
16

            
17
impl<'f> ConsensusesFromVotes<FooterAC<'f>> for netstatus::vote::Footer {
18
    type PlainOutput = netstatus::plain::Footer;
19
    type MdOutput = netstatus::md::Footer;
20

            
21
16
    fn consensuses<'i>(
22
16
        context: ConsensusContextRefs<FooterAC<'f>>,
23
16
        _inputs: impl ComponentInVotes<&'i Self>,
24
16
    ) -> Result<(Self::PlainOutput, Self::MdOutput), ConsensusError>
25
16
    where
26
16
        Self: 'i,
27
    {
28
16
        calc! { both.consensus = make_footer_fields(context)?; }
29

            
30
16
        Ok(construct_both! {
31
16
            netstatus::plain::Footer, netstatus::md::Footer {
32
16
                both. consensus;
33
16
            } {
34
16
            }
35
16
        })
36
16
    }
37
}
38

            
39
/// Calculate the actual footer, as a `ConsensusFooterFields`
40
///
41
/// Not `Aggregate` and doesn't take any inputs, because votes don't have footers
42
/// (so that field in a vote is `NotPresent`.)
43
32
fn make_footer_fields<'f>(
44
32
    _context: ConsensusContextRefs<FooterAC<'f>>,
45
32
) -> Result<netstatus::ConsensusFooterFields, ConsensusError> {
46
32
    let out_bandwidth_weights = ParamValues::default(); // TODO DIRAUTH
47

            
48
32
    Ok(construct! {
49
32
        netstatus::ConsensusFooterFields {
50
32
        } {
51
32
            out. bandwidth_weights;
52
32
        }
53
32
    })
54
32
}