Merge branch 'maint-0.2.5' into maint-0.2.6
[tor.git] / src / or / dirvote.h
blob542563b7082de6b0b40bcdcb2b8d96e0c4dede84
1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2015, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file dirvote.h
9 * \brief Header file for dirvote.c.
10 **/
12 #ifndef TOR_DIRVOTE_H
13 #define TOR_DIRVOTE_H
15 #include "testsupport.h"
18 * Ideally, assuming synced clocks, we should only need 1 second for each of:
19 * - Vote
20 * - Distribute
21 * - Consensus Publication
22 * As we can gather descriptors continuously.
23 * (Could we even go as far as publishing the previous consensus,
24 * in the same second that we vote for the next one?)
25 * But we're not there yet: these are the lowest working values at this time.
28 /** Lowest allowable value for VoteSeconds. */
29 #define MIN_VOTE_SECONDS 2
30 /** Lowest allowable value for VoteSeconds when TestingTorNetwork is 1 */
31 #define MIN_VOTE_SECONDS_TESTING 2
33 /** Lowest allowable value for DistSeconds. */
34 #define MIN_DIST_SECONDS 2
35 /** Lowest allowable value for DistSeconds when TestingTorNetwork is 1 */
36 #define MIN_DIST_SECONDS_TESTING 2
38 /** Lowest allowable voting interval. */
39 #define MIN_VOTE_INTERVAL 300
40 /** Lowest allowable voting interval when TestingTorNetwork is 1:
41 * Voting Interval can be:
42 * 10, 12, 15, 18, 20, 24, 25, 30, 36, 40, 45, 50, 60, ...
43 * Testing Initial Voting Interval can be:
44 * 5, 6, 8, 9, or any of the possible values for Voting Interval,
45 * as they both need to evenly divide 30 minutes.
46 * If clock desynchronisation is an issue, use an interval of at least:
47 * 18 * drift in seconds, to allow for a clock slop factor */
48 #define MIN_VOTE_INTERVAL_TESTING \
49 (((MIN_VOTE_SECONDS_TESTING)+(MIN_DIST_SECONDS_TESTING)+1)*2)
51 #define MIN_VOTE_INTERVAL_TESTING_INITIAL \
52 ((MIN_VOTE_SECONDS_TESTING)+(MIN_DIST_SECONDS_TESTING)+1)
54 /** The lowest consensus method that we currently support. */
55 #define MIN_SUPPORTED_CONSENSUS_METHOD 13
57 /** The highest consensus method that we currently support. */
58 #define MAX_SUPPORTED_CONSENSUS_METHOD 20
60 /** Lowest consensus method where microdesc consensuses omit any entry
61 * with no microdesc. */
62 #define MIN_METHOD_FOR_MANDATORY_MICRODESC 13
64 /** Lowest consensus method that contains "a" lines. */
65 #define MIN_METHOD_FOR_A_LINES 14
67 /** Lowest consensus method where microdescs may include a "p6" line. */
68 #define MIN_METHOD_FOR_P6_LINES 15
70 /** Lowest consensus method where microdescs may include an onion-key-ntor
71 * line */
72 #define MIN_METHOD_FOR_NTOR_KEY 16
74 /** Lowest consensus method that ensures that authorities output an
75 * Unmeasured=1 flag for unmeasured bandwidths */
76 #define MIN_METHOD_TO_CLIP_UNMEASURED_BW 17
78 /** Lowest consensus method where authorities may include an "id" line in
79 * microdescriptors. */
80 #define MIN_METHOD_FOR_ID_HASH_IN_MD 18
82 /** Lowest consensus method where we include "package" lines*/
83 #define MIN_METHOD_FOR_PACKAGE_LINES 19
85 /** Lowest consensus method where authorities may include
86 * GuardFraction information in microdescriptors. */
87 #define MIN_METHOD_FOR_GUARDFRACTION 20
89 /** Default bandwidth to clip unmeasured bandwidths to using method >=
90 * MIN_METHOD_TO_CLIP_UNMEASURED_BW. (This is not a consensus method; do not
91 * get confused with the above macros.) */
92 #define DEFAULT_MAX_UNMEASURED_BW_KB 20
94 void dirvote_free_all(void);
96 /* vote manipulation */
97 char *networkstatus_compute_consensus(smartlist_t *votes,
98 int total_authorities,
99 crypto_pk_t *identity_key,
100 crypto_pk_t *signing_key,
101 const char *legacy_identity_key_digest,
102 crypto_pk_t *legacy_signing_key,
103 consensus_flavor_t flavor);
104 int networkstatus_add_detached_signatures(networkstatus_t *target,
105 ns_detached_signatures_t *sigs,
106 const char *source,
107 int severity,
108 const char **msg_out);
109 char *networkstatus_get_detached_signatures(smartlist_t *consensuses);
110 void ns_detached_signatures_free(ns_detached_signatures_t *s);
112 /* cert manipulation */
113 authority_cert_t *authority_cert_dup(authority_cert_t *cert);
115 /* vote scheduling */
116 void dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out);
117 time_t dirvote_get_start_of_next_interval(time_t now,
118 int interval,
119 int offset);
120 void dirvote_recalculate_timing(const or_options_t *options, time_t now);
121 void dirvote_act(const or_options_t *options, time_t now);
123 /* invoked on timers and by outside triggers. */
124 struct pending_vote_t * dirvote_add_vote(const char *vote_body,
125 const char **msg_out,
126 int *status_out);
127 int dirvote_add_signatures(const char *detached_signatures_body,
128 const char *source,
129 const char **msg_out);
131 /* Item access */
132 const char *dirvote_get_pending_consensus(consensus_flavor_t flav);
133 const char *dirvote_get_pending_detached_signatures(void);
134 #define DGV_BY_ID 1
135 #define DGV_INCLUDE_PENDING 2
136 #define DGV_INCLUDE_PREVIOUS 4
137 const cached_dir_t *dirvote_get_vote(const char *fp, int flags);
138 void set_routerstatus_from_routerinfo(routerstatus_t *rs,
139 node_t *node,
140 routerinfo_t *ri, time_t now,
141 int listbadexits,
142 int vote_on_hsdirs);
143 networkstatus_t *
144 dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
145 authority_cert_t *cert);
147 microdesc_t *dirvote_create_microdescriptor(const routerinfo_t *ri,
148 int consensus_method);
149 ssize_t dirvote_format_microdesc_vote_line(char *out, size_t out_len,
150 const microdesc_t *md,
151 int consensus_method_low,
152 int consensus_method_high);
153 vote_microdesc_hash_t *dirvote_format_all_microdesc_vote_lines(
154 const routerinfo_t *ri,
155 time_t now,
156 smartlist_t *microdescriptors_out);
158 int vote_routerstatus_find_microdesc_hash(char *digest256_out,
159 const vote_routerstatus_t *vrs,
160 int method,
161 digest_algorithm_t alg);
162 document_signature_t *voter_get_sig_by_algorithm(
163 const networkstatus_voter_info_t *voter,
164 digest_algorithm_t alg);
166 #ifdef DIRVOTE_PRIVATE
167 STATIC char *format_networkstatus_vote(crypto_pk_t *private_key,
168 networkstatus_t *v3_ns);
169 STATIC char *dirvote_compute_params(smartlist_t *votes, int method,
170 int total_authorities);
171 STATIC char *compute_consensus_package_lines(smartlist_t *votes);
172 #endif
174 #endif