tor  0.4.2.0-alpha-dev
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-2019, 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 29
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 
86 #define MIN_METHOD_FOR_CANONICAL_FAMILIES_IN_MICRODESCS 29
87 
91 #define DEFAULT_MAX_UNMEASURED_BW_KB 20
92 
93 /* Directory Get Vote (DGV) flags for dirvote_get_vote(). */
94 #define DGV_BY_ID 1
95 #define DGV_INCLUDE_PENDING 2
96 #define DGV_INCLUDE_PREVIOUS 4
97 
99 #define MAX_BW_FILE_HEADERS_LINE_LEN 1024
100 
101 extern const char DIRVOTE_UNIVERSAL_FLAGS[];
102 extern const char DIRVOTE_OPTIONAL_FLAGS[];
103 
104 /*
105  * Public API. Used outside of the dirauth subsystem.
106  *
107  * We need to nullify them if the module is disabled.
108  */
109 #ifdef HAVE_MODULE_DIRAUTH
110 
111 time_t dirvote_act(const or_options_t *options, time_t now);
112 void dirvote_free_all(void);
113 
114 void dirvote_parse_sr_commits(networkstatus_t *ns, const smartlist_t *tokens);
115 void dirvote_clear_commits(networkstatus_t *ns);
116 void dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items,
117  smartlist_t *dir_items);
118 
119 /* Storing signatures and votes functions */
120 struct pending_vote_t * dirvote_add_vote(const char *vote_body,
121  const char **msg_out,
122  int *status_out);
123 int dirvote_add_signatures(const char *detached_signatures_body,
124  const char *source,
125  const char **msg_out);
126 
127 struct config_line_t;
128 char *format_recommended_version_list(const struct config_line_t *line,
129  int warn);
130 
131 #else /* !(defined(HAVE_MODULE_DIRAUTH)) */
132 
133 static inline time_t
134 dirvote_act(const or_options_t *options, time_t now)
135 {
136  (void) options;
137  (void) now;
138  return TIME_MAX;
139 }
140 
141 static inline void
142 dirvote_free_all(void)
143 {
144 }
145 
146 static inline void
147 dirvote_parse_sr_commits(networkstatus_t *ns, const smartlist_t *tokens)
148 {
149  (void) ns;
150  (void) tokens;
151 }
152 
153 static inline void
154 dirvote_clear_commits(networkstatus_t *ns)
155 {
156  (void) ns;
157 }
158 
159 static inline void
160 dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items,
161  smartlist_t *dir_items)
162 {
163  (void) url;
164  (void) items;
165  (void) dir_items;
166 }
167 
168 static inline struct pending_vote_t *
169 dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
170 {
171  (void) vote_body;
172  /* If the dirauth module is disabled, this should NEVER be called else we
173  * failed to safeguard the dirauth module. */
174  tor_assert_nonfatal_unreached();
175 
176  /* We need to send out an error code. */
177  *status_out = 400;
178  *msg_out = "No directory authority support";
179  return NULL;
180 }
181 
182 static inline int
183 dirvote_add_signatures(const char *detached_signatures_body,
184  const char *source,
185  const char **msg_out)
186 {
187  (void) detached_signatures_body;
188  (void) source;
189  (void) msg_out;
190  /* If the dirauth module is disabled, this should NEVER be called else we
191  * failed to safeguard the dirauth module. */
192  tor_assert_nonfatal_unreached();
193  return 0;
194 }
195 
196 #endif /* defined(HAVE_MODULE_DIRAUTH) */
197 
198 /* Item access */
199 MOCK_DECL(const char*, dirvote_get_pending_consensus,
200  (consensus_flavor_t flav));
201 MOCK_DECL(const char*, dirvote_get_pending_detached_signatures, (void));
202 const cached_dir_t *dirvote_get_vote(const char *fp, int flags);
203 
204 /*
205  * API used _only_ by the dirauth subsystem.
206  */
207 
210  authority_cert_t *cert);
211 
213  const routerinfo_t *ri,
214  time_t now,
215  smartlist_t *microdescriptors_out);
216 
217 /*
218  * Exposed functions for unit tests.
219  */
220 #ifdef DIRVOTE_PRIVATE
221 
222 /* Cert manipulation */
225  const smartlist_t *param_list,
226  const char *keyword,
227  int32_t default_val);
228 STATIC char *format_networkstatus_vote(crypto_pk_t *private_key,
229  networkstatus_t *v3_ns);
230 STATIC smartlist_t *dirvote_compute_params(smartlist_t *votes, int method,
231  int total_authorities);
232 STATIC char *compute_consensus_package_lines(smartlist_t *votes);
233 STATIC char *make_consensus_method_list(int low, int high, const char *sep);
234 STATIC int
236  int64_t M, int64_t E, int64_t D,
237  int64_t T, int64_t weight_scale);
238 STATIC
240  int total_authorities,
241  crypto_pk_t *identity_key,
242  crypto_pk_t *signing_key,
243  const char *legacy_identity_key_digest,
245  consensus_flavor_t flavor);
246 STATIC
249  const char *source,
250  int severity,
251  const char **msg_out);
252 STATIC
255  int consensus_method);
256 
257 #endif /* defined(DIRVOTE_PRIVATE) */
258 
259 #endif /* !defined(TOR_DIRVOTE_H) */
STATIC char * networkstatus_get_detached_signatures(smartlist_t *consensuses)
Definition: dirvote.c:2729
STATIC char * compute_consensus_package_lines(smartlist_t *votes)
Definition: dirvote.c:2459
time_t dirvote_act(const or_options_t *options, time_t now)
Definition: dirvote.c:2839
pending_vote_t * dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
Definition: dirvote.c:3131
networkstatus_t * dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key, authority_cert_t *cert)
Definition: dirvote.c:4416
STATIC char * make_consensus_method_list(int low, int high, const char *separator)
Definition: dirvote.c:826
STATIC authority_cert_t * authority_cert_dup(authority_cert_t *cert)
Definition: dirvote.c:142
const char DIRVOTE_OPTIONAL_FLAGS[]
Definition: dirvote.c:4409
void dirvote_free_all(void)
Definition: dirvote.c:3687
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:2537
STATIC microdesc_t * dirvote_create_microdescriptor(const routerinfo_t *ri, int consensus_method)
Definition: dirvote.c:3780
vote_microdesc_hash_t * dirvote_format_all_microdesc_vote_lines(const routerinfo_t *ri, time_t now, smartlist_t *microdescriptors_out)
Definition: dirvote.c:3939
consensus_flavor_t
Definition: or.h:863
STATIC int32_t dirvote_get_intermediate_param_value(const smartlist_t *param_list, const char *keyword, int32_t default_val)
Definition: dirvote.c:875
const cached_dir_t * dirvote_get_vote(const char *fp, int flags)
Definition: dirvote.c:3734
STATIC char * format_networkstatus_vote(crypto_pk_t *private_signing_key, networkstatus_t *v3_ns)
Definition: dirvote.c:219
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
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:1087
const char DIRVOTE_UNIVERSAL_FLAGS[]
Definition: dirvote.c:4397
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:1492
int dirvote_add_signatures(const char *detached_signatures_body, const char *source, const char **msg)
Definition: dirvote.c:3634
STATIC smartlist_t * dirvote_compute_params(smartlist_t *votes, int method, int total_authorities)
Definition: dirvote.c:911
static crypto_pk_t * legacy_signing_key
Definition: router.c:126
char * format_recommended_version_list(const config_line_t *ln, int warn)
Definition: dirvote.c:4286
#define T(s, t, a, o)
Definition: parsecommon.h:246