Merge branch 'maint-0.4.8' into release-0.4.8
[tor.git] / src / feature / dirauth / voting_schedule.h
blob8d13e208b7238c67ae725059ef55d3500d20a42a
1 /* Copyright (c) 2018-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 /**
5 * \file voting_schedule.h
6 * \brief Header file for voting_schedule.c.
7 **/
9 #ifndef TOR_VOTING_SCHEDULE_H
10 #define TOR_VOTING_SCHEDULE_H
12 #include "core/or/or.h"
14 #ifdef HAVE_MODULE_DIRAUTH
16 /** Scheduling information for a voting interval. */
17 typedef struct {
18 /** When do we generate and distribute our vote for this interval? */
19 time_t voting_starts;
20 /** When do we send an HTTP request for any votes that we haven't
21 * been posted yet?*/
22 time_t fetch_missing_votes;
23 /** When do we give up on getting more votes and generate a consensus? */
24 time_t voting_ends;
25 /** When do we send an HTTP request for any signatures we're expecting to
26 * see on the consensus? */
27 time_t fetch_missing_signatures;
28 /** When do we publish the consensus? */
29 time_t interval_starts;
31 /** Our computed dirauth interval */
32 int interval;
34 /** True iff we have generated and distributed our vote. */
35 int have_voted;
36 /** True iff we've requested missing votes. */
37 int have_fetched_missing_votes;
38 /** True iff we have built a consensus and sent the signatures around. */
39 int have_built_consensus;
40 /** True iff we've fetched missing signatures. */
41 int have_fetched_missing_signatures;
42 /** True iff we have published our consensus. */
43 int have_published_consensus;
45 /* True iff this voting schedule was set on demand meaning not through the
46 * normal vote operation of a dirauth or when a consensus is set. This only
47 * applies to a directory authority that needs to recalculate the voting
48 * timings only for the first vote even though this object was initialized
49 * prior to voting. */
50 int created_on_demand;
52 /** The valid-after time of the last live consensus that filled this voting
53 * schedule. It's used to detect outdated voting schedules. */
54 time_t live_consensus_valid_after;
55 } voting_schedule_t;
57 /* Public API. */
59 extern voting_schedule_t voting_schedule;
61 void dirauth_sched_recalculate_timing(const or_options_t *options,
62 time_t now);
64 time_t dirauth_sched_get_next_valid_after_time(void);
65 time_t dirauth_sched_get_cur_valid_after_time(void);
66 int dirauth_sched_get_configured_interval(void);
68 #else /* !defined(HAVE_MODULE_DIRAUTH) */
70 #define dirauth_sched_recalculate_timing(opt,now) \
71 ((void)(opt), (void)(now))
73 static inline time_t
74 dirauth_sched_get_next_valid_after_time(void)
76 tor_assert_unreached();
77 return 0;
79 static inline time_t
80 dirauth_sched_get_cur_valid_after_time(void)
82 tor_assert_unreached();
83 return 0;
85 static inline int
86 dirauth_sched_get_configured_interval(void)
88 tor_assert_unreached();
89 return 1;
91 #endif /* defined(HAVE_MODULE_DIRAUTH) */
93 #endif /* !defined(TOR_VOTING_SCHEDULE_H) */