2010-07-22 12:19:28 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2019-01-16 18:33:22 +01:00
|
|
|
* Copyright (c) 2007-2019, The Tor Project, Inc. */
|
2010-07-22 12:19:28 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file dirvote.h
|
|
|
|
* \brief Header file for dirvote.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_DIRVOTE_H
|
|
|
|
#define TOR_DIRVOTE_H
|
2010-07-22 12:19:28 +02:00
|
|
|
|
2014-12-20 11:53:00 +01:00
|
|
|
/*
|
|
|
|
* Ideally, assuming synced clocks, we should only need 1 second for each of:
|
|
|
|
* - Vote
|
|
|
|
* - Distribute
|
|
|
|
* - Consensus Publication
|
|
|
|
* As we can gather descriptors continuously.
|
|
|
|
* (Could we even go as far as publishing the previous consensus,
|
|
|
|
* in the same second that we vote for the next one?)
|
|
|
|
* But we're not there yet: these are the lowest working values at this time.
|
|
|
|
*/
|
|
|
|
|
2010-07-22 12:19:28 +02:00
|
|
|
/** Lowest allowable value for VoteSeconds. */
|
2013-06-05 15:48:57 +02:00
|
|
|
#define MIN_VOTE_SECONDS 2
|
2014-12-20 11:53:00 +01:00
|
|
|
/** Lowest allowable value for VoteSeconds when TestingTorNetwork is 1 */
|
|
|
|
#define MIN_VOTE_SECONDS_TESTING 2
|
|
|
|
|
2010-07-22 12:19:28 +02:00
|
|
|
/** Lowest allowable value for DistSeconds. */
|
2013-06-05 15:48:57 +02:00
|
|
|
#define MIN_DIST_SECONDS 2
|
2014-12-20 11:53:00 +01:00
|
|
|
/** Lowest allowable value for DistSeconds when TestingTorNetwork is 1 */
|
|
|
|
#define MIN_DIST_SECONDS_TESTING 2
|
|
|
|
|
|
|
|
/** Lowest allowable voting interval. */
|
2010-07-22 12:19:28 +02:00
|
|
|
#define MIN_VOTE_INTERVAL 300
|
2014-12-20 11:53:00 +01:00
|
|
|
/** Lowest allowable voting interval when TestingTorNetwork is 1:
|
|
|
|
* Voting Interval can be:
|
|
|
|
* 10, 12, 15, 18, 20, 24, 25, 30, 36, 40, 45, 50, 60, ...
|
|
|
|
* Testing Initial Voting Interval can be:
|
|
|
|
* 5, 6, 8, 9, or any of the possible values for Voting Interval,
|
|
|
|
* as they both need to evenly divide 30 minutes.
|
|
|
|
* If clock desynchronisation is an issue, use an interval of at least:
|
|
|
|
* 18 * drift in seconds, to allow for a clock slop factor */
|
|
|
|
#define MIN_VOTE_INTERVAL_TESTING \
|
|
|
|
(((MIN_VOTE_SECONDS_TESTING)+(MIN_DIST_SECONDS_TESTING)+1)*2)
|
|
|
|
|
|
|
|
#define MIN_VOTE_INTERVAL_TESTING_INITIAL \
|
|
|
|
((MIN_VOTE_SECONDS_TESTING)+(MIN_DIST_SECONDS_TESTING)+1)
|
2010-07-22 12:19:28 +02:00
|
|
|
|
2017-10-15 18:09:52 +02:00
|
|
|
/* A placeholder for routerstatus_format_entry() when the consensus method
|
|
|
|
* argument is not applicable. */
|
|
|
|
#define ROUTERSTATUS_FORMAT_NO_CONSENSUS_METHOD 0
|
|
|
|
|
2014-08-15 23:51:16 +02:00
|
|
|
/** The lowest consensus method that we currently support. */
|
2018-04-09 20:31:51 +02:00
|
|
|
#define MIN_SUPPORTED_CONSENSUS_METHOD 25
|
2014-08-15 23:51:16 +02:00
|
|
|
|
2012-08-31 23:02:19 +02:00
|
|
|
/** The highest consensus method that we currently support. */
|
2018-11-24 17:51:41 +01:00
|
|
|
#define MAX_SUPPORTED_CONSENSUS_METHOD 29
|
2012-08-31 23:02:19 +02:00
|
|
|
|
2016-08-25 20:24:34 +02:00
|
|
|
/** Lowest consensus method where authorities vote on required/recommended
|
|
|
|
* protocols. */
|
2016-09-26 20:00:08 +02:00
|
|
|
#define MIN_METHOD_FOR_RECOMMENDED_PROTOCOLS 25
|
2016-08-25 20:24:34 +02:00
|
|
|
|
|
|
|
/** Lowest consensus method where authorities add protocols to routerstatus
|
|
|
|
* entries. */
|
2016-09-26 20:00:08 +02:00
|
|
|
#define MIN_METHOD_FOR_RS_PROTOCOLS 25
|
2016-08-25 20:24:34 +02:00
|
|
|
|
2016-09-06 18:09:13 +02:00
|
|
|
/** Lowest consensus method where authorities initialize bandwidth weights to 1
|
|
|
|
* instead of 0. See #14881 */
|
|
|
|
#define MIN_METHOD_FOR_INIT_BW_WEIGHTS_ONE 26
|
|
|
|
|
2017-10-15 18:10:51 +02:00
|
|
|
/** Lowest consensus method where the microdesc consensus contains relay IPv6
|
|
|
|
* addresses. See #23826 and #20916. */
|
|
|
|
#define MIN_METHOD_FOR_A_LINES_IN_MICRODESC_CONSENSUS 27
|
|
|
|
|
2017-10-15 18:31:39 +02:00
|
|
|
/** Lowest consensus method where microdescriptors do not contain relay IPv6
|
|
|
|
* addresses. See #23828 and #20916. */
|
|
|
|
#define MIN_METHOD_FOR_NO_A_LINES_IN_MICRODESC 28
|
|
|
|
|
2018-11-24 17:51:41 +01:00
|
|
|
/**
|
|
|
|
* Lowest consensus method where microdescriptor lines are put in canonical
|
|
|
|
* form for improved compressibility and ease of storage. See proposal 298.
|
|
|
|
**/
|
|
|
|
#define MIN_METHOD_FOR_CANONICAL_FAMILIES_IN_MICRODESCS 29
|
|
|
|
|
2013-02-19 15:20:29 +01:00
|
|
|
/** Default bandwidth to clip unmeasured bandwidths to using method >=
|
2015-02-18 15:17:02 +01:00
|
|
|
* MIN_METHOD_TO_CLIP_UNMEASURED_BW. (This is not a consensus method; do not
|
|
|
|
* get confused with the above macros.) */
|
2013-04-11 17:43:40 +02:00
|
|
|
#define DEFAULT_MAX_UNMEASURED_BW_KB 20
|
2013-02-19 15:20:29 +01:00
|
|
|
|
2018-04-05 17:38:37 +02:00
|
|
|
/* Directory Get Vote (DGV) flags for dirvote_get_vote(). */
|
|
|
|
#define DGV_BY_ID 1
|
|
|
|
#define DGV_INCLUDE_PENDING 2
|
|
|
|
#define DGV_INCLUDE_PREVIOUS 4
|
|
|
|
|
2018-06-30 15:56:38 +02:00
|
|
|
/** Maximum size of a line in a vote. */
|
|
|
|
#define MAX_BW_FILE_HEADERS_LINE_LEN 1024
|
|
|
|
|
2018-12-03 18:18:45 +01:00
|
|
|
extern const char DIRVOTE_UNIVERSAL_FLAGS[];
|
|
|
|
extern const char DIRVOTE_OPTIONAL_FLAGS[];
|
|
|
|
|
2018-04-05 17:38:37 +02:00
|
|
|
/*
|
|
|
|
* Public API. Used outside of the dirauth subsystem.
|
2018-04-25 15:06:29 +02:00
|
|
|
*
|
|
|
|
* We need to nullify them if the module is disabled.
|
2018-04-05 17:38:37 +02:00
|
|
|
*/
|
2018-04-25 15:06:29 +02:00
|
|
|
#ifdef HAVE_MODULE_DIRAUTH
|
2018-04-05 17:38:37 +02:00
|
|
|
|
2018-04-26 23:42:43 +02:00
|
|
|
time_t dirvote_act(const or_options_t *options, time_t now);
|
2010-07-22 12:19:28 +02:00
|
|
|
void dirvote_free_all(void);
|
|
|
|
|
2018-05-01 17:35:26 +02:00
|
|
|
void dirvote_parse_sr_commits(networkstatus_t *ns, const smartlist_t *tokens);
|
2018-04-25 16:49:32 +02:00
|
|
|
void dirvote_clear_commits(networkstatus_t *ns);
|
2018-04-25 17:04:47 +02:00
|
|
|
void dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items,
|
|
|
|
smartlist_t *dir_items);
|
2018-04-25 16:42:56 +02:00
|
|
|
|
2018-04-25 17:12:56 +02:00
|
|
|
/* Storing signatures and votes functions */
|
|
|
|
struct pending_vote_t * dirvote_add_vote(const char *vote_body,
|
|
|
|
const char **msg_out,
|
|
|
|
int *status_out);
|
|
|
|
int dirvote_add_signatures(const char *detached_signatures_body,
|
|
|
|
const char *source,
|
|
|
|
const char **msg_out);
|
|
|
|
|
2018-09-20 14:09:35 +02:00
|
|
|
struct config_line_t;
|
|
|
|
char *format_recommended_version_list(const struct config_line_t *line,
|
|
|
|
int warn);
|
|
|
|
|
2019-09-30 14:57:37 +02:00
|
|
|
#else /* !defined(HAVE_MODULE_DIRAUTH) */
|
2018-04-25 15:06:29 +02:00
|
|
|
|
2018-04-26 23:42:43 +02:00
|
|
|
static inline time_t
|
2018-04-25 15:06:29 +02:00
|
|
|
dirvote_act(const or_options_t *options, time_t now)
|
|
|
|
{
|
|
|
|
(void) options;
|
|
|
|
(void) now;
|
2018-04-26 23:42:43 +02:00
|
|
|
return TIME_MAX;
|
2018-04-25 15:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dirvote_free_all(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-25 16:42:56 +02:00
|
|
|
static inline void
|
2018-05-01 17:35:26 +02:00
|
|
|
dirvote_parse_sr_commits(networkstatus_t *ns, const smartlist_t *tokens)
|
2018-04-25 16:42:56 +02:00
|
|
|
{
|
|
|
|
(void) ns;
|
|
|
|
(void) tokens;
|
|
|
|
}
|
|
|
|
|
2018-04-25 16:49:32 +02:00
|
|
|
static inline void
|
|
|
|
dirvote_clear_commits(networkstatus_t *ns)
|
|
|
|
{
|
|
|
|
(void) ns;
|
|
|
|
}
|
|
|
|
|
2018-04-25 17:04:47 +02:00
|
|
|
static inline void
|
|
|
|
dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items,
|
|
|
|
smartlist_t *dir_items)
|
|
|
|
{
|
|
|
|
(void) url;
|
|
|
|
(void) items;
|
|
|
|
(void) dir_items;
|
|
|
|
}
|
|
|
|
|
2018-04-25 17:12:56 +02:00
|
|
|
static inline struct pending_vote_t *
|
|
|
|
dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
|
|
|
|
{
|
|
|
|
(void) vote_body;
|
|
|
|
/* If the dirauth module is disabled, this should NEVER be called else we
|
|
|
|
* failed to safeguard the dirauth module. */
|
|
|
|
tor_assert_nonfatal_unreached();
|
2018-05-01 16:15:28 +02:00
|
|
|
|
|
|
|
/* We need to send out an error code. */
|
|
|
|
*status_out = 400;
|
|
|
|
*msg_out = "No directory authority support";
|
|
|
|
return NULL;
|
2018-04-25 17:12:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2018-06-21 20:23:32 +02:00
|
|
|
dirvote_add_signatures(const char *detached_signatures_body,
|
|
|
|
const char *source,
|
2018-04-25 17:12:56 +02:00
|
|
|
const char **msg_out)
|
|
|
|
{
|
|
|
|
(void) detached_signatures_body;
|
|
|
|
(void) source;
|
|
|
|
(void) msg_out;
|
|
|
|
/* If the dirauth module is disabled, this should NEVER be called else we
|
|
|
|
* failed to safeguard the dirauth module. */
|
|
|
|
tor_assert_nonfatal_unreached();
|
2018-05-01 16:15:28 +02:00
|
|
|
return 0;
|
2018-04-25 17:12:56 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 15:33:35 +02:00
|
|
|
#endif /* defined(HAVE_MODULE_DIRAUTH) */
|
2018-04-25 15:06:29 +02:00
|
|
|
|
2010-07-22 12:19:28 +02:00
|
|
|
/* Item access */
|
2015-09-07 19:22:33 +02:00
|
|
|
MOCK_DECL(const char*, dirvote_get_pending_consensus,
|
|
|
|
(consensus_flavor_t flav));
|
|
|
|
MOCK_DECL(const char*, dirvote_get_pending_detached_signatures, (void));
|
2010-07-22 12:19:28 +02:00
|
|
|
const cached_dir_t *dirvote_get_vote(const char *fp, int flags);
|
2018-04-05 17:38:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* API used _only_ by the dirauth subsystem.
|
|
|
|
*/
|
|
|
|
|
2010-07-22 12:19:28 +02:00
|
|
|
networkstatus_t *
|
2012-01-18 21:53:30 +01:00
|
|
|
dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
|
2010-07-22 12:19:28 +02:00
|
|
|
authority_cert_t *cert);
|
|
|
|
|
2013-02-08 17:52:51 +01:00
|
|
|
vote_microdesc_hash_t *dirvote_format_all_microdesc_vote_lines(
|
|
|
|
const routerinfo_t *ri,
|
|
|
|
time_t now,
|
|
|
|
smartlist_t *microdescriptors_out);
|
|
|
|
|
2018-04-05 17:38:37 +02:00
|
|
|
/*
|
|
|
|
* Exposed functions for unit tests.
|
|
|
|
*/
|
2010-07-22 12:19:28 +02:00
|
|
|
#ifdef DIRVOTE_PRIVATE
|
2018-04-05 17:38:37 +02:00
|
|
|
|
2018-05-01 14:58:57 +02:00
|
|
|
/* Cert manipulation */
|
|
|
|
STATIC authority_cert_t *authority_cert_dup(authority_cert_t *cert);
|
2016-05-10 02:10:43 +02:00
|
|
|
STATIC int32_t dirvote_get_intermediate_param_value(
|
|
|
|
const smartlist_t *param_list,
|
|
|
|
const char *keyword,
|
|
|
|
int32_t default_val);
|
2013-06-06 23:58:28 +02:00
|
|
|
STATIC char *format_networkstatus_vote(crypto_pk_t *private_key,
|
2010-07-22 12:19:28 +02:00
|
|
|
networkstatus_t *v3_ns);
|
2016-05-10 02:10:43 +02:00
|
|
|
STATIC smartlist_t *dirvote_compute_params(smartlist_t *votes, int method,
|
2011-02-21 03:05:17 +01:00
|
|
|
int total_authorities);
|
2015-01-09 17:36:47 +01:00
|
|
|
STATIC char *compute_consensus_package_lines(smartlist_t *votes);
|
2015-05-27 10:28:33 +02:00
|
|
|
STATIC char *make_consensus_method_list(int low, int high, const char *sep);
|
2016-10-04 03:09:25 +02:00
|
|
|
STATIC 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);
|
2018-04-05 17:18:47 +02:00
|
|
|
STATIC
|
|
|
|
char *networkstatus_compute_consensus(smartlist_t *votes,
|
|
|
|
int total_authorities,
|
|
|
|
crypto_pk_t *identity_key,
|
|
|
|
crypto_pk_t *signing_key,
|
|
|
|
const char *legacy_identity_key_digest,
|
|
|
|
crypto_pk_t *legacy_signing_key,
|
|
|
|
consensus_flavor_t flavor);
|
|
|
|
STATIC
|
|
|
|
int networkstatus_add_detached_signatures(networkstatus_t *target,
|
|
|
|
ns_detached_signatures_t *sigs,
|
|
|
|
const char *source,
|
|
|
|
int severity,
|
|
|
|
const char **msg_out);
|
|
|
|
STATIC
|
|
|
|
char *networkstatus_get_detached_signatures(smartlist_t *consensuses);
|
|
|
|
STATIC microdesc_t *dirvote_create_microdescriptor(const routerinfo_t *ri,
|
|
|
|
int consensus_method);
|
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(DIRVOTE_PRIVATE) */
|
2010-07-22 12:19:28 +02:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_DIRVOTE_H) */
|