tor  master
dirvote.h
Go to the documentation of this file.
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-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_DIRVOTE_H
13 #define TOR_DIRVOTE_H
14 
15 /*
16  * Ideally, assuming synced clocks, we should only need 1 second for each of:
17  * - Vote
18  * - Distribute
19  * - Consensus Publication
20  * As we can gather descriptors continuously.
21  * (Could we even go as far as publishing the previous consensus,
22  * in the same second that we vote for the next one?)
23  * But we're not there yet: these are the lowest working values at this time.
24  */
25 
27 #define MIN_VOTE_SECONDS 2
28 
29 #define MIN_VOTE_SECONDS_TESTING 2
30 
32 #define MIN_DIST_SECONDS 2
33 
34 #define MIN_DIST_SECONDS_TESTING 2
35 
37 #define MIN_VOTE_INTERVAL 300
38 
46 #define MIN_VOTE_INTERVAL_TESTING \
47  (((MIN_VOTE_SECONDS_TESTING)+(MIN_DIST_SECONDS_TESTING)+1)*2)
48 
49 #define MIN_VOTE_INTERVAL_TESTING_INITIAL \
50  ((MIN_VOTE_SECONDS_TESTING)+(MIN_DIST_SECONDS_TESTING)+1)
51 
52 /* A placeholder for routerstatus_format_entry() when the consensus method
53  * argument is not applicable. */
54 #define ROUTERSTATUS_FORMAT_NO_CONSENSUS_METHOD 0
55 
57 #define MIN_SUPPORTED_CONSENSUS_METHOD 25
58 
60 #define MAX_SUPPORTED_CONSENSUS_METHOD 28
61 
64 #define MIN_METHOD_FOR_RECOMMENDED_PROTOCOLS 25
65 
68 #define MIN_METHOD_FOR_RS_PROTOCOLS 25
69 
72 #define MIN_METHOD_FOR_INIT_BW_WEIGHTS_ONE 26
73 
76 #define MIN_METHOD_FOR_A_LINES_IN_MICRODESC_CONSENSUS 27
77 
80 #define MIN_METHOD_FOR_NO_A_LINES_IN_MICRODESC 28
81 
85 #define DEFAULT_MAX_UNMEASURED_BW_KB 20
86 
87 /* Directory Get Vote (DGV) flags for dirvote_get_vote(). */
88 #define DGV_BY_ID 1
89 #define DGV_INCLUDE_PENDING 2
90 #define DGV_INCLUDE_PREVIOUS 4
91 
92 /*
93  * Public API. Used outside of the dirauth subsystem.
94  *
95  * We need to nullify them if the module is disabled.
96  */
97 #ifdef HAVE_MODULE_DIRAUTH
98 
99 time_t dirvote_act(const or_options_t *options, time_t now);
100 void dirvote_free_all(void);
101 
102 void dirvote_parse_sr_commits(networkstatus_t *ns, const smartlist_t *tokens);
103 void dirvote_clear_commits(networkstatus_t *ns);
104 void dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items,
105  smartlist_t *dir_items);
106 
107 /* Storing signatures and votes functions */
108 struct pending_vote_t * dirvote_add_vote(const char *vote_body,
109  const char **msg_out,
110  int *status_out);
111 int dirvote_add_signatures(const char *detached_signatures_body,
112  const char *source,
113  const char **msg_out);
114 
115 #else /* HAVE_MODULE_DIRAUTH */
116 
117 static inline time_t
118 dirvote_act(const or_options_t *options, time_t now)
119 {
120  (void) options;
121  (void) now;
122  return TIME_MAX;
123 }
124 
125 static inline void
126 dirvote_free_all(void)
127 {
128 }
129 
130 static inline void
131 dirvote_parse_sr_commits(networkstatus_t *ns, const smartlist_t *tokens)
132 {
133  (void) ns;
134  (void) tokens;
135 }
136 
137 static inline void
138 dirvote_clear_commits(networkstatus_t *ns)
139 {
140  (void) ns;
141 }
142 
143 static inline void
144 dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items,
145  smartlist_t *dir_items)
146 {
147  (void) url;
148  (void) items;
149  (void) dir_items;
150 }
151 
152 static inline struct pending_vote_t *
153 dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
154 {
155  (void) vote_body;
156  /* If the dirauth module is disabled, this should NEVER be called else we
157  * failed to safeguard the dirauth module. */
158  tor_assert_nonfatal_unreached();
159 
160  /* We need to send out an error code. */
161  *status_out = 400;
162  *msg_out = "No directory authority support";
163  return NULL;
164 }
165 
166 static inline int
167 dirvote_add_signatures(const char *detached_signatures_body, const char *source,
168  const char **msg_out)
169 {
170  (void) detached_signatures_body;
171  (void) source;
172  (void) msg_out;
173  /* If the dirauth module is disabled, this should NEVER be called else we
174  * failed to safeguard the dirauth module. */
175  tor_assert_nonfatal_unreached();
176  return 0;
177 }
178 
179 #endif /* HAVE_MODULE_DIRAUTH */
180 
181 /* Item access */
182 MOCK_DECL(const char*, dirvote_get_pending_consensus,
183  (consensus_flavor_t flav));
184 MOCK_DECL(const char*, dirvote_get_pending_detached_signatures, (void));
185 const cached_dir_t *dirvote_get_vote(const char *fp, int flags);
186 
187 /*
188  * API used _only_ by the dirauth subsystem.
189  */
190 
192  node_t *node,
193  routerinfo_t *ri, time_t now,
194  int listbadexits);
197  authority_cert_t *cert);
198 
200  const routerinfo_t *ri,
201  time_t now,
202  smartlist_t *microdescriptors_out);
203 
204 /*
205  * Exposed functions for unit tests.
206  */
207 #ifdef DIRVOTE_PRIVATE
208 
209 /* Cert manipulation */
212  const smartlist_t *param_list,
213  const char *keyword,
214  int32_t default_val);
215 STATIC char *format_networkstatus_vote(crypto_pk_t *private_key,
216  networkstatus_t *v3_ns);
217 STATIC smartlist_t *dirvote_compute_params(smartlist_t *votes, int method,
218  int total_authorities);
219 STATIC char *compute_consensus_package_lines(smartlist_t *votes);
220 STATIC char *make_consensus_method_list(int low, int high, const char *sep);
221 STATIC int
223  int64_t M, int64_t E, int64_t D,
224  int64_t T, int64_t weight_scale);
225 STATIC
227  int total_authorities,
228  crypto_pk_t *identity_key,
229  crypto_pk_t *signing_key,
230  const char *legacy_identity_key_digest,
231  crypto_pk_t *legacy_signing_key,
232  consensus_flavor_t flavor);
233 STATIC
236  const char *source,
237  int severity,
238  const char **msg_out);
239 STATIC
242  int consensus_method);
243 
244 #endif /* defined(DIRVOTE_PRIVATE) */
245 
246 #endif /* !defined(TOR_DIRVOTE_H) */
247 
STATIC char * networkstatus_get_detached_signatures(smartlist_t *consensuses)
Definition: dirvote.c:2646
Definition: or.h:3657
STATIC char * compute_consensus_package_lines(smartlist_t *votes)
Definition: dirvote.c:2376
Definition: or.h:2504
time_t dirvote_act(const or_options_t *options, time_t now)
Definition: dirvote.c:2756
MOCK_DECL(int, router_have_minimum_dir_info,(void))
Definition: container.h:18
Definition: or.h:2687
pending_vote_t * dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
Definition: dirvote.c:3048
networkstatus_t * dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key, authority_cert_t *cert)
Definition: dirvote.c:4267
STATIC char * make_consensus_method_list(int low, int high, const char *separator)
Definition: dirvote.c:752
Definition: or.h:2581
STATIC authority_cert_t * authority_cert_dup(authority_cert_t *cert)
Definition: dirvote.c:106
void set_routerstatus_from_routerinfo(routerstatus_t *rs, node_t *node, routerinfo_t *ri, time_t now, int listbadexits)
Definition: dirserv.c:2031
void dirvote_free_all(void)
Definition: dirvote.c:3599
STATIC int networkstatus_add_detached_signatures(networkstatus_t *target, ns_detached_signatures_t *sigs, const char *source, int severity, const char **msg_out)
Definition: dirvote.c:2454
Definition: or.h:2018
Definition: dirvote.c:2833
STATIC microdesc_t * dirvote_create_microdescriptor(const routerinfo_t *ri, int consensus_method)
Definition: dirvote.c:3692
vote_microdesc_hash_t * dirvote_format_all_microdesc_vote_lines(const routerinfo_t *ri, time_t now, smartlist_t *microdescriptors_out)
Definition: dirvote.c:3838
consensus_flavor_t
Definition: or.h:2677
Definition: crypto_rsa.c:41
STATIC int32_t dirvote_get_intermediate_param_value(const smartlist_t *param_list, const char *keyword, int32_t default_val)
Definition: dirvote.c:793
const cached_dir_t * dirvote_get_vote(const char *fp, int flags)
Definition: dirvote.c:3646
STATIC char * format_networkstatus_vote(crypto_pk_t *private_signing_key, networkstatus_t *v3_ns)
Definition: dirvote.c:183
int networkstatus_compute_bw_weights_v10(smartlist_t *chunks, int64_t G, int64_t M, int64_t E, int64_t D, int64_t T, int64_t weight_scale)
Definition: dirvote.c:1005
Definition: or.h:2769
STATIC char * networkstatus_compute_consensus(smartlist_t *votes, int total_authorities, crypto_pk_t *identity_key, crypto_pk_t *signing_key, const char *legacy_id_key_digest, crypto_pk_t *legacy_signing_key, consensus_flavor_t flavor)
Definition: dirvote.c:1410
Definition: or.h:2344
int dirvote_add_signatures(const char *detached_signatures_body, const char *source, const char **msg)
Definition: dirvote.c:3548
Definition: or.h:2433
STATIC smartlist_t * dirvote_compute_params(smartlist_t *votes, int method, int total_authorities)
Definition: dirvote.c:829
Definition: or.h:2853
Definition: or.h:2232
#define T(s, t, a, o)
Definition: parsecommon.h:244