#include "or.h"
Data Structures | |
struct | pending_consensus_t |
struct | dir_src_ent_t |
struct | pending_vote_t |
Defines | |
#define | DIRVOTE_PRIVATE |
#define | MAX_SUPPORTED_CONSENSUS_METHOD 9 |
#define | MIN_METHOD_FOR_FOOTER 9 |
#define | MIN_METHOD_FOR_BW_WEIGHTS 9 |
#define | MIN_METHOD_FOR_PARAMS 7 |
#define | MIN_METHOD_FOR_MICRODESC 8 |
#define | MICRODESC_LINE_LEN 80 |
#define | get_most_frequent_member(lst) smartlist_get_most_frequent_string(lst) |
#define | RANGE_CHECK(a, b, c, d, e, f, g, mx) |
#define | CHECK_EQ(a, b, margin) ((a)-(b) >= 0 ? (a)-(b) <= (margin) : (b)-(a) <= (margin)) |
Enumerations | |
enum | bw_weights_error_t { BW_WEIGHTS_NO_ERROR = 0, BW_WEIGHTS_RANGE_ERROR = 1, BW_WEIGHTS_SUMG_ERROR = 2, BW_WEIGHTS_SUME_ERROR = 3, BW_WEIGHTS_SUMD_ERROR = 4, BW_WEIGHTS_BALANCE_MID_ERROR = 5, BW_WEIGHTS_BALANCE_EG_ERROR = 6 } |
Functions | |
static int | dirvote_add_signatures_to_all_pending_consensuses (const char *detached_signatures_body, const char **msg_out) |
static int | dirvote_add_signatures_to_pending_consensus (pending_consensus_t *pc, ns_detached_signatures_t *sigs, const char **msg_out) |
static char * | list_v3_auth_ids (void) |
static void | dirvote_fetch_missing_votes (void) |
static void | dirvote_fetch_missing_signatures (void) |
static int | dirvote_perform_vote (void) |
static void | dirvote_clear_votes (int all_votes) |
static int | dirvote_compute_consensuses (void) |
static int | dirvote_publish_consensus (void) |
static char * | make_consensus_method_list (int low, int high, const char *sep) |
char * | format_networkstatus_vote (crypto_pk_env_t *private_signing_key, networkstatus_t *v3_ns) |
static networkstatus_voter_info_t * | get_voter (const networkstatus_t *vote) |
document_signature_t * | voter_get_sig_by_algorithm (const networkstatus_voter_info_t *voter, digest_algorithm_t alg) |
static int | _compare_votes_by_authority_id (const void **_a, const void **_b) |
static int | _compare_dir_src_ents_by_authority_id (const void **_a, const void **_b) |
static void | get_frequent_members (smartlist_t *out, smartlist_t *in, int min) |
static int | compare_vote_rs (const vote_routerstatus_t *a, const vote_routerstatus_t *b) |
static int | _compare_vote_rs (const void **_a, const void **_b) |
static vote_routerstatus_t * | compute_routerstatus_consensus (smartlist_t *votes, int consensus_method, char *microdesc_digest256_out) |
static void | hash_list_members (char *digest_out, size_t len_out, smartlist_t *lst, digest_algorithm_t alg) |
static int | _cmp_int_strings (const void **_a, const void **_b) |
static int | compute_consensus_method (smartlist_t *votes) |
static int | consensus_method_is_supported (int method) |
static char * | compute_consensus_versions_list (smartlist_t *lst, int n_versioning) |
char * | dirvote_compute_params (smartlist_t *votes) |
static bw_weights_error_t | networkstatus_check_weights (int64_t Wgg, int64_t Wgd, int64_t Wmg, int64_t Wme, int64_t Wmd, int64_t Wee, int64_t Wed, int64_t scale, int64_t G, int64_t M, int64_t E, int64_t D, int64_t T, int64_t margin, int do_balance) |
static void | networkstatus_compute_bw_weights_v9 (smartlist_t *chunks, int64_t G, int64_t M, int64_t E, int64_t D, int64_t T, int64_t weight_scale) |
char * | networkstatus_compute_consensus (smartlist_t *votes, int total_authorities, crypto_pk_env_t *identity_key, crypto_pk_env_t *signing_key, const char *legacy_id_key_digest, crypto_pk_env_t *legacy_signing_key, consensus_flavor_t flavor) |
int | networkstatus_add_detached_signatures (networkstatus_t *target, ns_detached_signatures_t *sigs, const char **msg_out) |
static char * | networkstatus_format_signatures (networkstatus_t *consensus, int for_detached_signatures) |
char * | networkstatus_get_detached_signatures (smartlist_t *consensuses) |
static char * | get_detached_signatures_from_pending_consensuses (pending_consensus_t *pending, int n_flavors) |
void | ns_detached_signatures_free (ns_detached_signatures_t *s) |
authority_cert_t * | authority_cert_dup (authority_cert_t *cert) |
void | dirvote_get_preferred_voting_intervals (vote_timing_t *timing_out) |
time_t | dirvote_get_start_of_next_interval (time_t now, int interval) |
void | dirvote_recalculate_timing (or_options_t *options, time_t now) |
void | dirvote_act (or_options_t *options, time_t now) |
static void | dirvote_clear_pending_consensuses (void) |
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) |
void | dirvote_free_all (void) |
const char * | dirvote_get_pending_consensus (consensus_flavor_t flav) |
const char * | dirvote_get_pending_detached_signatures (void) |
const cached_dir_t * | dirvote_get_vote (const char *fp, int flags) |
microdesc_t * | dirvote_create_microdescriptor (const routerinfo_t *ri) |
ssize_t | dirvote_format_microdesc_vote_line (char *out, size_t out_len, const microdesc_t *md) |
int | vote_routerstatus_find_microdesc_hash (char *digest256_out, const vote_routerstatus_t *vrs, int method, digest_algorithm_t alg) |
Variables | |
struct { | |
time_t voting_starts | |
time_t fetch_missing_votes | |
time_t voting_ends | |
time_t fetch_missing_signatures | |
time_t interval_starts | |
int have_voted | |
int have_fetched_missing_votes | |
int have_built_consensus | |
int have_fetched_missing_signatures | |
int have_published_consensus | |
} | voting_schedule |
static smartlist_t * | pending_vote_list = NULL |
static smartlist_t * | previous_vote_list = NULL |
static pending_consensus_t | pending_consensuses [N_CONSENSUS_FLAVORS] |
static char * | pending_consensus_signatures = NULL |
static smartlist_t * | pending_consensus_signature_list = NULL |
static char * | microdesc_consensus_methods = NULL |
#define get_most_frequent_member | ( | lst | ) | smartlist_get_most_frequent_string(lst) |
Given a sorted list of strings lst, return the member that appears most. Break ties in favor of later-occurring members.
#define MAX_SUPPORTED_CONSENSUS_METHOD 9 |
The highest consensus method that we currently support.
Referenced by consensus_method_is_supported(), dirvote_format_microdesc_vote_line(), and format_networkstatus_vote().
#define MIN_METHOD_FOR_BW_WEIGHTS 9 |
Lowest consensus method that contains bandwidth weights
#define MIN_METHOD_FOR_FOOTER 9 |
Lowest consensus method that contains a 'directory-footer' marker
#define MIN_METHOD_FOR_MICRODESC 8 |
Lowest consensus method that generates microdescriptors
Referenced by dirvote_format_microdesc_vote_line().
#define MIN_METHOD_FOR_PARAMS 7 |
Lowest consensus method that contains consensus params
Referenced by networkstatus_compute_consensus().
#define RANGE_CHECK | ( | a, | |||
b, | |||||
c, | |||||
d, | |||||
e, | |||||
f, | |||||
g, | |||||
mx | ) |
Value:
((a) >= 0 && (a) <= (mx) && (b) >= 0 && (b) <= (mx) && \ (c) >= 0 && (c) <= (mx) && (d) >= 0 && (d) <= (mx) && \ (e) >= 0 && (e) <= (mx) && (f) >= 0 && (f) <= (mx) && \ (g) >= 0 && (g) <= (mx))
static int _cmp_int_strings | ( | const void ** | _a, | |
const void ** | _b | |||
) | [static] |
Sorting helper: compare two strings based on their values as base-ten positive integers. (Non-integers are treated as prior to all integers, and compared lexically.)
References tor_parse_long().
Referenced by compute_consensus_method().
static int _compare_dir_src_ents_by_authority_id | ( | const void ** | _a, | |
const void ** | _b | |||
) | [static] |
Helper: Compare the dir_src_ent_ts in *_a and *_b by their identity digests, and return -1, 0, or 1 depending on their ordering
References DIGEST_LEN, get_voter(), networkstatus_voter_info_t::identity_digest, dir_src_ent_t::is_legacy, networkstatus_voter_info_t::legacy_id_digest, and dir_src_ent_t::v.
Referenced by networkstatus_compute_consensus().
static int _compare_vote_rs | ( | const void ** | _a, | |
const void ** | _b | |||
) | [static] |
Helper for sorting routerlists based on compare_vote_rs.
References compare_vote_rs().
Referenced by compute_routerstatus_consensus().
static int _compare_votes_by_authority_id | ( | const void ** | _a, | |
const void ** | _b | |||
) | [static] |
Helper for sorting networkstatus_t votes (not consensuses) by the hash of their voters' identity digests.
References DIGEST_LEN, and get_voter().
Referenced by networkstatus_compute_consensus().
authority_cert_t* authority_cert_dup | ( | authority_cert_t * | cert | ) |
Allocate and return a new authority_cert_t with the same contents as cert.
References authority_cert_t::cache_info, crypto_pk_dup_key(), authority_cert_t::identity_key, signed_descriptor_t::saved_location, SAVED_NOWHERE, signed_descriptor_t::signed_descriptor_body, signed_descriptor_t::signed_descriptor_len, authority_cert_t::signing_key, and tor_assert.
static int compare_vote_rs | ( | const vote_routerstatus_t * | a, | |
const vote_routerstatus_t * | b | |||
) | [static] |
Return 0 if and only if a and b are routerstatuses that come from the same routerinfo, with the same derived elements.
References routerstatus_t::addr, routerstatus_t::descriptor_digest, DIGEST_LEN, routerstatus_t::dir_port, routerstatus_t::identity_digest, routerstatus_t::nickname, routerstatus_t::or_port, routerstatus_t::published_on, and vote_routerstatus_t::status.
Referenced by _compare_vote_rs(), and compute_routerstatus_consensus().
static int compute_consensus_method | ( | smartlist_t * | votes | ) | [static] |
Given a list of networkstatus_t votes, determine and return the number of the highest consensus method that is supported by 2/3 of the voters.
References _cmp_int_strings(), get_frequent_members(), smartlist_add_all(), smartlist_clear(), smartlist_create(), smartlist_free(), smartlist_sort(), smartlist_uniq(), tor_assert, and tor_parse_long().
Referenced by networkstatus_compute_consensus().
static char* compute_consensus_versions_list | ( | smartlist_t * | lst, | |
int | n_versioning | |||
) | [static] |
Helper: given lst, a list of version strings such that every version appears once for every versioning voter who recommends it, return a newly allocated string holding the resulting client-versions or server-versions list. May change contents of lst
References get_frequent_members(), smartlist_create(), smartlist_free(), smartlist_join_strings(), and sort_version_list().
Referenced by networkstatus_compute_consensus().
static vote_routerstatus_t* compute_routerstatus_consensus | ( | smartlist_t * | votes, | |
int | consensus_method, | |||
char * | microdesc_digest256_out | |||
) | [static] |
Given a list of vote_routerstatus_t, all for the same router identity, return whichever is most frequent, breaking ties in favor of more recently published vote_routerstatus_t and in case of ties there, in favor of smaller descriptor digest.
References _compare_vote_rs(), compare_vote_rs(), routerstatus_t::published_on, smartlist_sort(), and vote_routerstatus_t::status.
static int consensus_method_is_supported | ( | int | method | ) | [static] |
Return true iff method is a consensus method that we support.
References MAX_SUPPORTED_CONSENSUS_METHOD.
Referenced by make_consensus_method_list(), and networkstatus_compute_consensus().
void dirvote_act | ( | or_options_t * | options, | |
time_t | now | |||
) |
Entry point: Take whatever voting actions are pending as of now.
References authdir_mode_v3(), authority_cert_t::cache_info, DIGEST_LEN, dirvote_clear_votes(), dirvote_compute_consensuses(), dirvote_fetch_missing_signatures(), dirvote_fetch_missing_votes(), dirvote_perform_vote(), dirvote_publish_consensus(), dirvote_recalculate_timing(), get_my_v3_authority_cert(), hex_str(), signed_descriptor_t::identity_digest, LD_DIR, list_v3_auth_ids(), tor_free, and voting_schedule.
Referenced by run_scheduled_events().
int dirvote_add_signatures | ( | const char * | detached_signatures_body, | |
const char * | source, | |||
const char ** | msg | |||
) |
Helper: we just got the detached_signatures_body sent to us as signatures on the currently pending consensus. Add them to the pending consensus (if we have one); otherwise queue them until we have a consensus. Return negative on failure, nonnegative on success.
References LD_DIR, smartlist_add(), and smartlist_create().
Referenced by connection_dir_client_reached_eof(), and directory_handle_command_post().
static int dirvote_add_signatures_to_pending_consensus | ( | pending_consensus_t * | pc, | |
ns_detached_signatures_t * | sigs, | |||
const char ** | msg_out | |||
) | [static] |
Helper: we just got the detached_signatures_body sent to us as signatures on the currently pending consensus. Add them to pc as appropriate. Return the number of signatures added. (?)
References pending_consensus_t::body, pending_consensus_t::consensus, networkstatus_t::flavor, LD_DIR, networkstatus_add_detached_signatures(), networkstatus_format_signatures(), networkstatus_get_flavor_name(), networkstatus_parse_vote_from_string(), networkstatus_vote_free(), ns_detached_signatures_t::signatures, strmap_get(), and tor_assert.
pending_vote_t* dirvote_add_vote | ( | const char * | vote_body, | |
const char ** | msg_out, | |||
int * | status_out | |||
) | [read] |
Called when we have received a networkstatus vote in vote_body. Parse and validate it, and on success store it as a pending vote (which we then return). Return NULL on failure. Sets *msg_out and *status_out to an HTTP response and status code. (V3 authority only)
References networkstatus_voter_info_t::address, authority_cert_get_by_digests(), authority_cert_t::cache_info, cached_dir_decref(), networkstatus_t::cert, DIGEST_LEN, format_iso_time(), get_voter(), hex_str(), signed_descriptor_t::identity_digest, networkstatus_voter_info_t::identity_digest, LD_BUG, LD_DIR, list_v3_auth_ids(), networkstatus_parse_vote_from_string(), networkstatus_vote_free(), new_cached_dir(), networkstatus_voter_info_t::nickname, networkstatus_t::published, signed_descriptor_t::signed_descriptor_body, authority_cert_t::signing_key_digest, networkstatus_voter_info_t::sigs, smartlist_create(), strcmpstart(), tor_assert, tor_free, trusted_dirs_load_certs_from_string(), trusteddirserver_get_by_v3_auth_digest(), update_consensus_router_descriptor_downloads(), networkstatus_t::valid_after, networkstatus_voter_info_t::vote_digest, networkstatus_t::voters, and voting_schedule.
Referenced by connection_dir_client_reached_eof(), directory_handle_command_post(), and dirvote_perform_vote().
static void dirvote_clear_pending_consensuses | ( | void | ) | [static] |
Release all storage held by pending consensuses (those waiting for signatures).
References pending_consensus_t::body, pending_consensus_t::consensus, N_CONSENSUS_FLAVORS, networkstatus_vote_free(), and tor_free.
Referenced by dirvote_clear_votes(), dirvote_compute_consensuses(), and dirvote_free_all().
static void dirvote_clear_votes | ( | int | all_votes | ) | [static] |
Drop all currently pending votes, consensus, and detached signatures.
References cached_dir_decref(), dirvote_clear_pending_consensuses(), networkstatus_vote_free(), smartlist_add_all(), smartlist_clear(), smartlist_create(), and tor_free.
Referenced by dirvote_act(), and dirvote_free_all().
static int dirvote_compute_consensuses | ( | void | ) | [static] |
Try to compute a v3 networkstatus consensus from the currently pending votes. Return 0 on success, -1 on failure. Store the consensus in pending_consensus: it won't be ready to be published until we have everybody else's signatures collected too. (V3 Authority only)
References pending_consensus_t::body, sized_chunk_t::bytes, pending_consensus_t::consensus, crypto_pk_get_digest(), DIGEST_LEN, DIR_PURPOSE_UPLOAD_SIGNATURES, directory_post_to_dirservers(), dirvote_clear_pending_consensuses(), get_datadir_fname, get_detached_signatures_from_pending_consensuses(), get_my_v3_authority_cert(), get_my_v3_authority_signing_key(), get_my_v3_legacy_cert(), get_my_v3_legacy_signing_key(), get_n_authorities(), get_options(), authority_cert_t::identity_key, LD_DIR, sized_chunk_t::len, N_CONSENSUS_FLAVORS, networkstatus_check_consensus_signature(), networkstatus_compute_consensus(), networkstatus_get_flavor_name(), networkstatus_parse_vote_from_string(), networkstatus_vote_free(), ROUTER_PURPOSE_GENERAL, smartlist_add(), smartlist_clear(), smartlist_create(), smartlist_free(), smartlist_string_isin(), tor_assert, tor_free, V3_AUTHORITY, and write_chunks_to_file().
Referenced by dirvote_act().
char* dirvote_compute_params | ( | smartlist_t * | votes | ) |
Helper: given a list of valid networkstatus_t, return a new string containing the contents of the consensus network parameter set.
References smartlist_add(), smartlist_add_all(), smartlist_create(), smartlist_free(), smartlist_join_strings(), smartlist_sort_strings(), tor_assert, tor_free, tor_parse_long(), and tor_snprintf().
Referenced by networkstatus_compute_consensus().
microdesc_t* dirvote_create_microdescriptor | ( | const routerinfo_t * | ri | ) |
Construct and return a new microdescriptor from a routerinfo ri.
XXX Right now, there is only one way to generate microdescriptors from router descriptors. This may change in future consensus methods. If so, we'll need an internal way to remember which method we used, and ask for a particular method.
References crypto_pk_write_public_key_to_string(), routerinfo_t::declared_family, routerinfo_t::exit_policy, LD_DIR, microdescs_parse_from_string(), routerinfo_t::onion_pkey, policy_summarize(), smartlist_free(), smartlist_join_strings(), tor_free, and tor_snprintf().
static void dirvote_fetch_missing_signatures | ( | void | ) | [static] |
Send a request to every other authority for its detached signatures, unless we have signatures from all other v3 authorities already.
References pending_consensus_t::consensus, DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, directory_get_from_all_authorities(), N_CONSENSUS_FLAVORS, and networkstatus_check_consensus_signature().
Referenced by dirvote_act().
static void dirvote_fetch_missing_votes | ( | void | ) | [static] |
Send an HTTP request to every other v3 authority, for the votes of every authority for which we haven't received a vote yet in this period. (V3 authority only)
References base16_encode(), DIGEST_LEN, dirvote_get_vote(), HEX_DIGEST_LEN, router_get_trusted_dir_servers(), smartlist_add(), smartlist_create(), and V3_AUTHORITY.
Referenced by dirvote_act().
ssize_t dirvote_format_microdesc_vote_line | ( | char * | out, | |
size_t | out_len, | |||
const microdesc_t * | md | |||
) |
Format the appropriate vote line to describe the microdescriptor md in a consensus vote document. Write it into the out_len-byte buffer in out. Return -1 on failure and the number of characters written on success.
References BASE64_DIGEST256_LEN, microdesc_t::digest, digest256_to_base64(), make_consensus_method_list(), MAX_SUPPORTED_CONSENSUS_METHOD, MIN_METHOD_FOR_MICRODESC, tor_assert, and tor_snprintf().
void dirvote_free_all | ( | void | ) |
Release all static storage held in dirvote.c
References dirvote_clear_pending_consensuses(), dirvote_clear_votes(), smartlist_free(), and tor_free.
Referenced by tor_free_all().
const char* dirvote_get_pending_consensus | ( | consensus_flavor_t | flav | ) |
Return the body of the consensus that we're currently trying to build.
References pending_consensus_t::body, and tor_assert.
Referenced by directory_handle_command_get().
const char* dirvote_get_pending_detached_signatures | ( | void | ) |
Return the signatures that we know for the consensus that we're currently trying to build.
Referenced by directory_handle_command_get().
void dirvote_get_preferred_voting_intervals | ( | vote_timing_t * | timing_out | ) |
Set *timing_out to the intervals at which we would like to vote. Note that these aren't the intervals we'll use to vote; they're the ones that we'll vote to use.
References vote_timing_t::dist_delay, get_options(), vote_timing_t::n_intervals_valid, tor_assert, or_options_t::V3AuthDistDelay, or_options_t::V3AuthNIntervalsValid, or_options_t::V3AuthVoteDelay, or_options_t::V3AuthVotingInterval, vote_timing_t::vote_delay, and vote_timing_t::vote_interval.
time_t dirvote_get_start_of_next_interval | ( | time_t | now, | |
int | interval | |||
) |
Return the start of the next interval of size interval (in seconds) after now. Midnight always starts a fresh interval, and if the last interval of a day would be truncated to less than half its size, it is rolled into the previous interval.
References tor_timegm().
Referenced by dirvote_recalculate_timing().
const cached_dir_t* dirvote_get_vote | ( | const char * | fp, | |
int | flags | |||
) |
Return a given vote specified by fp. If by_id, return the vote for the authority with the v3 authority identity key digest fp; if by_id is false, return the vote whose digest is fp. If fp is NULL, return our own vote. If include_previous is false, do not consider any votes for a consensus that's already been built. If include_pending is false, do not consider any votes for the consensus that's in progress. May return NULL if we have no vote for the authority in question.
References authority_cert_t::cache_info, DIGEST_LEN, get_my_v3_authority_cert(), get_voter(), networkstatus_voter_info_t::identity_digest, and signed_descriptor_t::identity_digest.
Referenced by directory_handle_command_get(), and dirvote_fetch_missing_votes().
static int dirvote_perform_vote | ( | void | ) | [static] |
Generate a networkstatus vote and post it to all the v3 authorities. (V3 Authority only)
References cached_dir_t::dir, cached_dir_t::dir_len, DIR_PURPOSE_UPLOAD_VOTE, directory_post_to_dirservers(), dirserv_generate_networkstatus_vote_obj(), dirvote_add_vote(), authority_cert_t::expires, format_networkstatus_vote(), get_my_v3_authority_cert(), get_my_v3_authority_signing_key(), LD_DIR, LD_NET, networkstatus_vote_free(), ROUTER_PURPOSE_GENERAL, tor_free, V3_AUTHORITY, and pending_vote_t::vote_body.
Referenced by dirvote_act().
static int dirvote_publish_consensus | ( | void | ) | [static] |
Replace the consensus that we're currently serving with the one that we've been building. (V3 Authority only)
References pending_consensus_t::body, pending_consensus_t::consensus, LD_DIR, networkstatus_check_consensus_signature(), networkstatus_get_flavor_name(), networkstatus_set_current_consensus(), and tor_assert.
Referenced by dirvote_act().
void dirvote_recalculate_timing | ( | or_options_t * | options, | |
time_t | now | |||
) |
Set voting_schedule to hold the timing for the next vote we should be doing.
References authdir_mode_v3(), dirvote_get_start_of_next_interval(), networkstatus_t::dist_seconds, format_iso_time(), networkstatus_t::fresh_until, LD_DIR, networkstatus_get_live_consensus(), or_options_t::TestingV3AuthInitialDistDelay, or_options_t::TestingV3AuthInitialVoteDelay, or_options_t::TestingV3AuthInitialVotingInterval, tor_assert, networkstatus_t::valid_after, networkstatus_t::vote_seconds, and voting_schedule.
Referenced by dirvote_act(), networkstatus_set_current_consensus(), and options_act().
char* format_networkstatus_vote | ( | crypto_pk_env_t * | private_signing_key, | |
networkstatus_t * | v3_ns | |||
) |
Return a new string containing the string representation of the vote in v3_ns, signed with our v3 signing key private_signing_key. For v3 authorities.
References networkstatus_voter_info_t::addr, networkstatus_voter_info_t::address, base16_encode(), authority_cert_t::cache_info, networkstatus_t::cert, networkstatus_t::client_versions, networkstatus_voter_info_t::contact, crypto_pk_get_fingerprint(), DIGEST_LEN, networkstatus_voter_info_t::dir_port, networkstatus_t::dist_seconds, FINGERPRINT_LEN, format_iso_time(), networkstatus_t::fresh_until, HEX_DIGEST_LEN, signed_descriptor_t::identity_digest, INET_NTOA_BUF_LEN, networkstatus_t::known_flags, LD_BUG, networkstatus_voter_info_t::legacy_id_digest, make_consensus_method_list(), MAX_SUPPORTED_CONSENSUS_METHOD, networkstatus_t::net_params, networkstatus_parse_vote_from_string(), networkstatus_vote_free(), networkstatus_voter_info_t::nickname, note_crypto_pk_op(), networkstatus_voter_info_t::or_port, networkstatus_t::published, router_append_dirobj_signature(), router_get_networkstatus_v3_hash(), router_get_routerlist(), routerlist_t::routers, routerstatus_format_entry(), networkstatus_t::routerstatus_list, RS_ENTRY_LEN, networkstatus_t::server_versions, signed_descriptor_t::signed_descriptor_body, signed_descriptor_t::signed_descriptor_len, smartlist_join_strings(), tor_assert, tor_digest_is_zero(), tor_free, tor_inet_ntoa(), tor_snprintf(), networkstatus_t::type, networkstatus_t::valid_after, networkstatus_t::valid_until, networkstatus_t::vote_seconds, and networkstatus_t::voters.
Referenced by dirvote_perform_vote().
static char* get_detached_signatures_from_pending_consensuses | ( | pending_consensus_t * | pending, | |
int | n_flavors | |||
) | [static] |
Return a newly allocated string holding a detached-signatures document for all of the in-progress consensuses in the n_flavors-element array at pending.
References networkstatus_get_detached_signatures(), smartlist_add(), smartlist_create(), and smartlist_free().
Referenced by dirvote_compute_consensuses().
static void get_frequent_members | ( | smartlist_t * | out, | |
smartlist_t * | in, | |||
int | min | |||
) | [static] |
Given a sorted list of strings in, add every member to out that occurs more than min times.
References smartlist_add().
Referenced by compute_consensus_method(), and compute_consensus_versions_list().
static networkstatus_voter_info_t* get_voter | ( | const networkstatus_t * | vote | ) | [static] |
Given a vote vote (not a consensus!), return its associated networkstatus_voter_info_t.
References tor_assert, networkstatus_t::type, and networkstatus_t::voters.
Referenced by _compare_dir_src_ents_by_authority_id(), _compare_votes_by_authority_id(), dirvote_add_vote(), dirvote_get_vote(), and networkstatus_compute_consensus().
static void hash_list_members | ( | char * | digest_out, | |
size_t | len_out, | |||
smartlist_t * | lst, | |||
digest_algorithm_t | alg | |||
) | [static] |
Given a list of strings in lst, set the len_out-byte digest at digest_out to the hash of the concatenation of those strings, computed with the algorithm alg.
References crypto_digest_add_bytes(), crypto_digest_get_digest(), crypto_free_digest_env(), and crypto_new_digest_env().
static char * list_v3_auth_ids | ( | void | ) | [static] |
Return a newly allocated string containing the hex-encoded v3 authority identity digest of every recognized v3 authority.
References DIGEST_LEN, hex_str(), router_get_trusted_dir_servers(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_digest_is_zero(), tor_free, and V3_AUTHORITY.
Referenced by dirvote_act(), and dirvote_add_vote().
static char * make_consensus_method_list | ( | int | low, | |
int | high, | |||
const char * | separator | |||
) | [static] |
Return a newly allocated string holding the numbers between low and high (inclusive) that are supported consensus methods.
References consensus_method_is_supported(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_assert, tor_free, and tor_snprintf().
Referenced by dirvote_format_microdesc_vote_line(), and format_networkstatus_vote().
int networkstatus_add_detached_signatures | ( | networkstatus_t * | target, | |
ns_detached_signatures_t * | sigs, | |||
const char ** | msg_out | |||
) |
Given a consensus vote target and a set of detached signatures in sigs that correspond to the same consensus, check whether there are any new signatures in src_voter_list that should be added to target. (A signature should be added if we have no signature for that voter in target yet, or if we have no verifiable signature and the new signature is verifiable.) Return the number of signatures added or changed, or -1 if the document signed by sigs isn't the same document as target.
Make sure all the digests we know match, and at least one matches.
References authority_cert_get_by_digests(), document_signature_t::bad_signature, base16_encode(), crypto_digest_algorithm_get_name(), digests_t::d, DIGEST256_LEN, DIGEST_LEN, networkstatus_t::digests, ns_detached_signatures_t::digests, document_signature_dup(), document_signature_free(), networkstatus_t::flavor, ns_detached_signatures_t::fresh_until, networkstatus_t::fresh_until, document_signature_t::good_signature, HEX_DIGEST_LEN, LD_DIR, networkstatus_check_document_signature(), networkstatus_get_flavor_name(), networkstatus_get_voter_by_id(), ns_detached_signatures_t::signatures, networkstatus_voter_info_t::sigs, smartlist_add(), smartlist_remove(), strmap_get(), tor_assert, tor_mem_is_zero(), networkstatus_t::type, ns_detached_signatures_t::valid_after, networkstatus_t::valid_after, ns_detached_signatures_t::valid_until, networkstatus_t::valid_until, and voter_get_sig_by_algorithm().
Referenced by dirvote_add_signatures_to_pending_consensus().
static bw_weights_error_t networkstatus_check_weights | ( | int64_t | Wgg, | |
int64_t | Wgd, | |||
int64_t | Wmg, | |||
int64_t | Wme, | |||
int64_t | Wmd, | |||
int64_t | Wee, | |||
int64_t | Wed, | |||
int64_t | scale, | |||
int64_t | G, | |||
int64_t | M, | |||
int64_t | E, | |||
int64_t | D, | |||
int64_t | T, | |||
int64_t | margin, | |||
int | do_balance | |||
) | [static] |
Verify that any weightings satisfy the balanced formulas.
References LD_DIR.
char* networkstatus_compute_consensus | ( | smartlist_t * | votes, | |
int | total_authorities, | |||
crypto_pk_env_t * | identity_key, | |||
crypto_pk_env_t * | signing_key, | |||
const char * | legacy_id_key_digest, | |||
crypto_pk_env_t * | legacy_signing_key, | |||
consensus_flavor_t | flavor | |||
) |
Given a list of vote networkstatus_t in votes, our public authority identity_key, our private authority signing_key, and the number of total_authorities that we believe exist in our voting quorum, generate the text of a new v3 consensus vote, and return the value in a newly allocated string.
Note: this function DOES NOT check whether the votes are from recognized authorities. (dirvote_add_vote does that.)
References _compare_dir_src_ents_by_authority_id(), _compare_votes_by_authority_id(), networkstatus_voter_info_t::addr, networkstatus_voter_info_t::address, base16_encode(), compute_consensus_method(), compute_consensus_versions_list(), consensus_method_is_supported(), networkstatus_voter_info_t::contact, dir_src_ent_t::digest, DIGEST_LEN, networkstatus_voter_info_t::dir_port, dirvote_compute_params(), format_iso_time(), get_voter(), HEX_DIGEST_LEN, networkstatus_voter_info_t::identity_digest, INET_NTOA_BUF_LEN, dir_src_ent_t::is_legacy, LD_DIR, networkstatus_voter_info_t::legacy_id_digest, MIN_DIST_SECONDS, MIN_METHOD_FOR_PARAMS, MIN_VOTE_INTERVAL, MIN_VOTE_SECONDS, networkstatus_get_flavor_name(), networkstatus_voter_info_t::nickname, networkstatus_voter_info_t::or_port, smartlist_add(), smartlist_add_all(), smartlist_create(), smartlist_free(), smartlist_join_strings(), smartlist_sort(), smartlist_sort_strings(), smartlist_split_string(), smartlist_string_pos(), smartlist_uniq_strings(), sort_version_list(), strmap_get_lc(), strmap_set_lc(), tor_asprintf(), tor_assert, tor_digest_is_zero(), tor_free, tor_inet_ntoa(), dir_src_ent_t::v, and networkstatus_voter_info_t::vote_digest.
Referenced by dirvote_compute_consensuses().
static char* networkstatus_format_signatures | ( | networkstatus_t * | consensus, | |
int | for_detached_signatures | |||
) | [static] |
Return a newly allocated string containing all the signatures on consensus by all voters. If for_detached_signatures is true, then the signatures will be put in a detached signatures document, so prefix any non-NS-flavored signatures with "additional-signature" rather than "directory-signature".
References base16_encode(), base64_encode(), crypto_digest_algorithm_get_name(), DIGEST_LEN, networkstatus_t::flavor, HEX_DIGEST_LEN, networkstatus_get_flavor_name(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_free, tor_snprintf(), and networkstatus_t::voters.
Referenced by dirvote_add_signatures_to_pending_consensus(), and networkstatus_get_detached_signatures().
char* networkstatus_get_detached_signatures | ( | smartlist_t * | consensuses | ) |
Return a newly allocated string holding the detached-signatures document corresponding to the signatures on consensuses, which must contain exactly one FLAV_NS consensus, and no more than one consensus for each other flavor.
References base16_encode(), crypto_digest_algorithm_get_name(), digests_t::d, DIGEST256_LEN, DIGEST_LEN, networkstatus_t::digests, format_iso_time(), networkstatus_t::fresh_until, HEX_DIGEST256_LEN, HEX_DIGEST_LEN, LD_BUG, LD_DIR, networkstatus_format_signatures(), networkstatus_get_flavor_name(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_assert, tor_free, tor_mem_is_zero(), tor_snprintf(), networkstatus_t::valid_after, and networkstatus_t::valid_until.
Referenced by get_detached_signatures_from_pending_consensuses().
void ns_detached_signatures_free | ( | ns_detached_signatures_t * | s | ) |
Release all storage held in s.
References _tor_free(), ns_detached_signatures_t::digests, document_signature_free(), ns_detached_signatures_t::signatures, smartlist_free(), strmap_free(), and tor_free.
int vote_routerstatus_find_microdesc_hash | ( | char * | digest256_out, | |
const vote_routerstatus_t * | vrs, | |||
int | method, | |||
digest_algorithm_t | alg | |||
) |
If vrs has a hash made for the consensus method method with the digest algorithm alg, decode it and copy it into digest256_out and return 0. Otherwise return -1.
References BASE64_DIGEST256_LEN, crypto_digest_algorithm_get_name(), digest256_from_base64(), vote_routerstatus_t::microdesc, and tor_snprintf().
document_signature_t* voter_get_sig_by_algorithm | ( | const networkstatus_voter_info_t * | voter, | |
digest_algorithm_t | alg | |||
) |
Return the signature made by voter using the algorithm alg, or NULL if none is found.
References networkstatus_voter_info_t::sigs.
Referenced by networkstatus_add_detached_signatures(), and networkstatus_parse_vote_from_string().
time_t fetch_missing_signatures |
When do we send an HTTP request for any signatures we're expecting to see on the consensus?
time_t fetch_missing_votes |
When do we send an HTTP request for any votes that we haven't been posted yet?
time_t interval_starts |
When do we publish the consensus?
char* microdesc_consensus_methods = NULL [static] |
Cached space-separated string to hold
smartlist_t* pending_consensus_signature_list = NULL [static] |
List of ns_detached_signatures_t: hold signatures that get posted to us before we have generated the consensus on our own.
char* pending_consensus_signatures = NULL [static] |
The detached signatures for the consensus that we're currently building.
smartlist_t* pending_vote_list = NULL [static] |
List of pending_vote_t for the current vote. Before we've used them to build a consensus, the votes go here.
smartlist_t* previous_vote_list = NULL [static] |
List of pending_vote_t for the previous vote. After we've used them to build a consensus, the votes go here for the next period.
time_t voting_ends |
When do we give up on getting more votes and generate a consensus?
struct { ... } voting_schedule [static] |
Scheduling information for a voting interval.
Referenced by dirvote_act(), dirvote_add_vote(), and dirvote_recalculate_timing().
time_t voting_starts |
When do we generate and distribute our vote for this interval?