TOR: update to v0.2.5.12
[tomato.git] / release / src / router / tor / src / or / dirvote.h
blob4c57e43661b127099d8da38d91ccdf5f3f6c28be
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 */
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"
17 /** Lowest allowable value for VoteSeconds. */
18 #define MIN_VOTE_SECONDS 2
19 /** Lowest allowable value for DistSeconds. */
20 #define MIN_DIST_SECONDS 2
21 /** Smallest allowable voting interval. */
22 #define MIN_VOTE_INTERVAL 300
24 /** The highest consensus method that we currently support. */
25 #define MAX_SUPPORTED_CONSENSUS_METHOD 18
27 /** Lowest consensus method that contains a 'directory-footer' marker */
28 #define MIN_METHOD_FOR_FOOTER 9
30 /** Lowest consensus method that contains bandwidth weights */
31 #define MIN_METHOD_FOR_BW_WEIGHTS 9
33 /** Lowest consensus method that contains consensus params */
34 #define MIN_METHOD_FOR_PARAMS 7
36 /** Lowest consensus method that generates microdescriptors */
37 #define MIN_METHOD_FOR_MICRODESC 8
39 /** Lowest consensus method that doesn't count bad exits as exits for weight */
40 #define MIN_METHOD_TO_CUT_BADEXIT_WEIGHT 11
42 /** Lowest consensus method that ensures a majority of authorities voted
43 * for a param. */
44 #define MIN_METHOD_FOR_MAJORITY_PARAMS 12
46 /** Lowest consensus method where microdesc consensuses omit any entry
47 * with no microdesc. */
48 #define MIN_METHOD_FOR_MANDATORY_MICRODESC 13
50 /** Lowest consensus method that contains "a" lines. */
51 #define MIN_METHOD_FOR_A_LINES 14
53 /** Lowest consensus method where microdescs may include a "p6" line. */
54 #define MIN_METHOD_FOR_P6_LINES 15
56 /** Lowest consensus method where microdescs may include an onion-key-ntor
57 * line */
58 #define MIN_METHOD_FOR_NTOR_KEY 16
60 /** Lowest consensus method that ensures that authorities output an
61 * Unmeasured=1 flag for unmeasured bandwidths */
62 #define MIN_METHOD_TO_CLIP_UNMEASURED_BW 17
64 /** Lowest consensus method where authorities may include an "id" line in
65 * microdescriptors. */
66 #define MIN_METHOD_FOR_ID_HASH_IN_MD 18
68 /** Default bandwidth to clip unmeasured bandwidths to using method >=
69 * MIN_METHOD_TO_CLIP_UNMEASURED_BW */
70 #define DEFAULT_MAX_UNMEASURED_BW_KB 20
72 void dirvote_free_all(void);
74 /* vote manipulation */
75 char *networkstatus_compute_consensus(smartlist_t *votes,
76 int total_authorities,
77 crypto_pk_t *identity_key,
78 crypto_pk_t *signing_key,
79 const char *legacy_identity_key_digest,
80 crypto_pk_t *legacy_signing_key,
81 consensus_flavor_t flavor);
82 int networkstatus_add_detached_signatures(networkstatus_t *target,
83 ns_detached_signatures_t *sigs,
84 const char *source,
85 int severity,
86 const char **msg_out);
87 char *networkstatus_get_detached_signatures(smartlist_t *consensuses);
88 void ns_detached_signatures_free(ns_detached_signatures_t *s);
90 /* cert manipulation */
91 authority_cert_t *authority_cert_dup(authority_cert_t *cert);
93 /* vote scheduling */
94 void dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out);
95 time_t dirvote_get_start_of_next_interval(time_t now,
96 int interval,
97 int offset);
98 void dirvote_recalculate_timing(const or_options_t *options, time_t now);
99 void dirvote_act(const or_options_t *options, time_t now);
101 /* invoked on timers and by outside triggers. */
102 struct pending_vote_t * dirvote_add_vote(const char *vote_body,
103 const char **msg_out,
104 int *status_out);
105 int dirvote_add_signatures(const char *detached_signatures_body,
106 const char *source,
107 const char **msg_out);
109 /* Item access */
110 const char *dirvote_get_pending_consensus(consensus_flavor_t flav);
111 const char *dirvote_get_pending_detached_signatures(void);
112 #define DGV_BY_ID 1
113 #define DGV_INCLUDE_PENDING 2
114 #define DGV_INCLUDE_PREVIOUS 4
115 const cached_dir_t *dirvote_get_vote(const char *fp, int flags);
116 void set_routerstatus_from_routerinfo(routerstatus_t *rs,
117 node_t *node,
118 routerinfo_t *ri, time_t now,
119 int naming, int listbadexits,
120 int listbaddirs, int vote_on_hsdirs);
121 networkstatus_t *
122 dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
123 authority_cert_t *cert);
125 microdesc_t *dirvote_create_microdescriptor(const routerinfo_t *ri,
126 int consensus_method);
127 ssize_t dirvote_format_microdesc_vote_line(char *out, size_t out_len,
128 const microdesc_t *md,
129 int consensus_method_low,
130 int consensus_method_high);
131 vote_microdesc_hash_t *dirvote_format_all_microdesc_vote_lines(
132 const routerinfo_t *ri,
133 time_t now,
134 smartlist_t *microdescriptors_out);
136 int vote_routerstatus_find_microdesc_hash(char *digest256_out,
137 const vote_routerstatus_t *vrs,
138 int method,
139 digest_algorithm_t alg);
140 document_signature_t *voter_get_sig_by_algorithm(
141 const networkstatus_voter_info_t *voter,
142 digest_algorithm_t alg);
144 #ifdef DIRVOTE_PRIVATE
145 STATIC char *format_networkstatus_vote(crypto_pk_t *private_key,
146 networkstatus_t *v3_ns);
147 STATIC char *dirvote_compute_params(smartlist_t *votes, int method,
148 int total_authorities);
149 #endif
151 #endif