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-2013, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Header file for dirvote.c.
15 /** Lowest allowable value for VoteSeconds. */
16 #define MIN_VOTE_SECONDS 20
17 /** Lowest allowable value for DistSeconds. */
18 #define MIN_DIST_SECONDS 20
19 /** Smallest allowable voting interval. */
20 #define MIN_VOTE_INTERVAL 300
22 /** The highest consensus method that we currently support. */
23 #define MAX_SUPPORTED_CONSENSUS_METHOD 17
25 /** Lowest consensus method that contains a 'directory-footer' marker */
26 #define MIN_METHOD_FOR_FOOTER 9
28 /** Lowest consensus method that contains bandwidth weights */
29 #define MIN_METHOD_FOR_BW_WEIGHTS 9
31 /** Lowest consensus method that contains consensus params */
32 #define MIN_METHOD_FOR_PARAMS 7
34 /** Lowest consensus method that generates microdescriptors */
35 #define MIN_METHOD_FOR_MICRODESC 8
37 /** Lowest consensus method that doesn't count bad exits as exits for weight */
38 #define MIN_METHOD_TO_CUT_BADEXIT_WEIGHT 11
40 /** Lowest consensus method that ensures a majority of authorities voted
42 #define MIN_METHOD_FOR_MAJORITY_PARAMS 12
44 /** Lowest consensus method where microdesc consensuses omit any entry
45 * with no microdesc. */
46 #define MIN_METHOD_FOR_MANDATORY_MICRODESC 13
48 /** Lowest consensus method that contains "a" lines. */
49 #define MIN_METHOD_FOR_A_LINES 14
51 /** Lowest consensus method where microdescs may include a "p6" line. */
52 #define MIN_METHOD_FOR_P6_LINES 15
54 /** Lowest consensus method where microdescs may include an onion-key-ntor
56 #define MIN_METHOD_FOR_NTOR_KEY 16
58 /** Lowest consensus method that ensures that authorities output an
59 * Unmeasured=1 flag for unmeasured bandwidths */
60 #define MIN_METHOD_TO_CLIP_UNMEASURED_BW 17
62 /** Default bandwidth to clip unmeasured bandwidths to using method >=
63 * MIN_METHOD_TO_CLIP_UNMEASURED_BW */
64 #define DEFAULT_MAX_UNMEASURED_BW_KB 20
66 void dirvote_free_all(void);
68 /* vote manipulation */
69 char *networkstatus_compute_consensus(smartlist_t
*votes
,
70 int total_authorities
,
71 crypto_pk_t
*identity_key
,
72 crypto_pk_t
*signing_key
,
73 const char *legacy_identity_key_digest
,
74 crypto_pk_t
*legacy_signing_key
,
75 consensus_flavor_t flavor
);
76 int networkstatus_add_detached_signatures(networkstatus_t
*target
,
77 ns_detached_signatures_t
*sigs
,
80 const char **msg_out
);
81 char *networkstatus_get_detached_signatures(smartlist_t
*consensuses
);
82 void ns_detached_signatures_free(ns_detached_signatures_t
*s
);
84 /* cert manipulation */
85 authority_cert_t
*authority_cert_dup(authority_cert_t
*cert
);
88 void dirvote_get_preferred_voting_intervals(vote_timing_t
*timing_out
);
89 time_t dirvote_get_start_of_next_interval(time_t now
, int interval
);
90 void dirvote_recalculate_timing(const or_options_t
*options
, time_t now
);
91 void dirvote_act(const or_options_t
*options
, time_t now
);
93 /* invoked on timers and by outside triggers. */
94 struct pending_vote_t
* dirvote_add_vote(const char *vote_body
,
97 int dirvote_add_signatures(const char *detached_signatures_body
,
99 const char **msg_out
);
102 const char *dirvote_get_pending_consensus(consensus_flavor_t flav
);
103 const char *dirvote_get_pending_detached_signatures(void);
105 #define DGV_INCLUDE_PENDING 2
106 #define DGV_INCLUDE_PREVIOUS 4
107 const cached_dir_t
*dirvote_get_vote(const char *fp
, int flags
);
108 void set_routerstatus_from_routerinfo(routerstatus_t
*rs
,
110 routerinfo_t
*ri
, time_t now
,
111 int naming
, int listbadexits
,
112 int listbaddirs
, int vote_on_hsdirs
);
114 dirserv_generate_networkstatus_vote_obj(crypto_pk_t
*private_key
,
115 authority_cert_t
*cert
);
117 microdesc_t
*dirvote_create_microdescriptor(const routerinfo_t
*ri
,
118 int consensus_method
);
119 ssize_t
dirvote_format_microdesc_vote_line(char *out
, size_t out_len
,
120 const microdesc_t
*md
,
121 int consensus_method_low
,
122 int consensus_method_high
);
123 vote_microdesc_hash_t
*dirvote_format_all_microdesc_vote_lines(
124 const routerinfo_t
*ri
,
126 smartlist_t
*microdescriptors_out
);
128 int vote_routerstatus_find_microdesc_hash(char *digest256_out
,
129 const vote_routerstatus_t
*vrs
,
131 digest_algorithm_t alg
);
132 document_signature_t
*voter_get_sig_by_algorithm(
133 const networkstatus_voter_info_t
*voter
,
134 digest_algorithm_t alg
);
136 #ifdef DIRVOTE_PRIVATE
137 char *format_networkstatus_vote(crypto_pk_t
*private_key
,
138 networkstatus_t
*v3_ns
);
139 char *dirvote_compute_params(smartlist_t
*votes
, int method
,
140 int total_authorities
);