tor  0.4.2.1-alpha-dev
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
dirvote.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/or/policies.h"
#include "core/or/protover.h"
#include "core/or/tor_version_st.h"
#include "core/or/versions.h"
#include "feature/dirauth/bwauth.h"
#include "feature/dirauth/dircollate.h"
#include "feature/dirauth/dsigs_parse.h"
#include "feature/dirauth/guardfraction.h"
#include "feature/dirauth/recommend_pkg.h"
#include "feature/dirauth/voteflags.h"
#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dircommon/directory.h"
#include "feature/dirparse/microdesc_parse.h"
#include "feature/dirparse/ns_parse.h"
#include "feature/dirparse/parsecommon.h"
#include "feature/dirparse/signing.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/fmt_routerstatus.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodefamily.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/router.h"
#include "feature/relay/routerkeys.h"
#include "feature/stats/rephist.h"
#include "feature/client/entrynodes.h"
#include "feature/nodelist/torcert.h"
#include "feature/dircommon/voting_schedule.h"
#include "feature/dirauth/dirvote.h"
#include "feature/dirauth/authmode.h"
#include "feature/dirauth/shared_random_state.h"
#include "feature/nodelist/authority_cert_st.h"
#include "feature/dircache/cached_dir_st.h"
#include "feature/dirclient/dir_server_st.h"
#include "feature/nodelist/document_signature_st.h"
#include "feature/nodelist/microdesc_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "feature/nodelist/networkstatus_voter_info_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/dirauth/ns_detached_signatures_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist_st.h"
#include "feature/dirauth/vote_microdesc_hash_st.h"
#include "feature/nodelist/vote_routerstatus_st.h"
#include "feature/dircommon/vote_timing_st.h"
#include "lib/container/order.h"
#include "lib/encoding/confline.h"
#include "lib/crypt_ops/crypto_format.h"

Go to the source code of this file.

Data Structures

struct  pending_consensus_t
 
struct  dir_src_ent_t
 
struct  pending_vote_t
 
struct  consensus_method_range_t
 
struct  microdesc_vote_line_t
 

Macros

#define DIRVOTE_PRIVATE
 
#define DIGEST_ALG_BW_FILE   DIGEST_SHA256
 
#define get_most_frequent_member(lst)   smartlist_get_most_frequent_string(lst)
 
#define CMP_FIELD(utype, itype, field)
 
#define MIN_VOTES_FOR_PARAM   3
 
#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))
 
#define IF_TIME_FOR_NEXT_ACTION(when_field, done_field)
 
#define ENDIF
 

Typedefs

typedef struct pending_consensus_t pending_consensus_t
 
typedef struct dir_src_ent_t dir_src_ent_t
 
typedef struct pending_vote_t pending_vote_t
 
typedef struct microdesc_vote_line_t microdesc_vote_line_t
 

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 *source, const char **msg_out)
 
static int dirvote_add_signatures_to_pending_consensus (pending_consensus_t *pc, ns_detached_signatures_t *sigs, const char *source, int severity, 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 authority_cert_tauthority_cert_dup (authority_cert_t *cert)
 
static char * format_line_if_present (const char *keyword, const char *opt_value)
 
static char * format_protocols_lines_for_vote (const networkstatus_t *v3_ns)
 
STATIC char * format_networkstatus_vote (crypto_pk_t *private_signing_key, networkstatus_t *v3_ns)
 
static void dirvote_get_preferred_voting_intervals (vote_timing_t *timing_out)
 
static int vote_routerstatus_find_microdesc_hash (char *digest256_out, const vote_routerstatus_t *vrs, int method, digest_algorithm_t alg)
 
static networkstatus_voter_info_tget_voter (const networkstatus_t *vote)
 
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 int compare_orports_ (const void **_a, const void **_b)
 
static vote_routerstatus_tcompute_routerstatus_consensus (smartlist_t *votes, int consensus_method, char *microdesc_digest256_out, tor_addr_port_t *best_alt_orport_out)
 
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 * make_consensus_method_list (int low, int high, const char *separator)
 
static char * compute_consensus_versions_list (smartlist_t *lst, int n_versioning)
 
STATIC int32_t dirvote_get_intermediate_param_value (const smartlist_t *param_list, const char *keyword, int32_t default_val)
 
STATIC smartlist_tdirvote_compute_params (smartlist_t *votes, int method, int total_authorities)
 
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)
 
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)
 
static void update_total_bandwidth_weights (const routerstatus_t *rs, int is_exit, int is_guard, int64_t *G, int64_t *M, int64_t *E, int64_t *D, int64_t *T)
 
static const char * get_nth_protocol_set_vote (int n, const networkstatus_t *vote)
 
static char * compute_nth_protocol_set (int n, int n_voters, const smartlist_t *votes)
 
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)
 
STATIC char * compute_consensus_package_lines (smartlist_t *votes)
 
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_format_signatures (networkstatus_t *consensus, int for_detached_signatures)
 
STATIC char * networkstatus_get_detached_signatures (smartlist_t *consensuses)
 
static char * get_detached_signatures_from_pending_consensuses (pending_consensus_t *pending, int n_flavors)
 
time_t dirvote_act (const or_options_t *options, time_t now)
 
static void dirvote_clear_pending_consensuses (void)
 
pending_vote_tdirvote_add_vote (const char *vote_body, const char **msg_out, int *status_out)
 
static void write_v3_votes_to_disk (const smartlist_t *pending_votes)
 
int dirvote_add_signatures (const char *detached_signatures_body, const char *source, const char **msg)
 
void dirvote_free_all (void)
 
 MOCK_IMPL (const char *, dirvote_get_pending_consensus,(consensus_flavor_t flav))
 
 MOCK_IMPL (const char *, dirvote_get_pending_detached_signatures,(void))
 
const cached_dir_tdirvote_get_vote (const char *fp, int flags)
 
STATIC microdesc_tdirvote_create_microdescriptor (const routerinfo_t *ri, int consensus_method)
 
static ssize_t dirvote_format_microdesc_vote_line (char *out_buf, size_t out_buf_len, const microdesc_t *md, int consensus_method_low, int consensus_method_high)
 
vote_microdesc_hash_tdirvote_format_all_microdesc_vote_lines (const routerinfo_t *ri, time_t now, smartlist_t *microdescriptors_out)
 
static void extract_shared_random_commits (networkstatus_t *ns, const smartlist_t *tokens)
 
void dirvote_parse_sr_commits (networkstatus_t *ns, const smartlist_t *tokens)
 
void dirvote_clear_commits (networkstatus_t *ns)
 
void dirvote_dirreq_get_status_vote (const char *url, smartlist_t *items, smartlist_t *dir_items)
 
static uint32_t dirserv_get_bandwidth_for_router_kb (const routerinfo_t *ri)
 
static int compare_routerinfo_by_ip_and_bw_ (const void **a, const void **b)
 
static digestmap_t * get_possible_sybil_list (const smartlist_t *routers)
 
static char * version_from_platform (const char *platform)
 
char * format_recommended_version_list (const config_line_t *ln, int warn)
 
static void routers_make_ed_keys_unique (smartlist_t *routers)
 
static void clear_status_flags_on_sybil (routerstatus_t *rs)
 
networkstatus_tdirserv_generate_networkstatus_vote_obj (crypto_pk_t *private_key, authority_cert_t *cert)
 

Variables

static smartlist_tpending_vote_list = NULL
 
static smartlist_tprevious_vote_list = NULL
 
static pending_consensus_t pending_consensuses [N_CONSENSUS_FLAVORS]
 
static char * pending_consensus_signatures = NULL
 
static smartlist_tpending_consensus_signature_list = NULL
 
static const struct consensus_method_range_t microdesc_consensus_methods []
 
const char DIRVOTE_UNIVERSAL_FLAGS []
 
const char DIRVOTE_OPTIONAL_FLAGS []
 

Detailed Description

Functions to compute directory consensus, and schedule voting.

This module is the center of the consensus-voting based directory authority system. With this system, a set of authorities first publish vote based on their opinions of the network, and then compute a consensus from those votes. Each authority signs the consensus, and clients trust the consensus if enough known authorities have signed it.

The code in this module is only invoked on directory authorities. It's responsible for:

The main entry points are in dirvote_act(), which handles scheduled actions; and dirvote_add_vote() and dirvote_add_signatures(), which handle uploaded and downloaded votes and signatures.

(See dir-spec.txt from torspec.git for a complete specification of the directory protocol and voting algorithms.)

Definition in file dirvote.c.

Macro Definition Documentation

◆ CMP_FIELD

#define CMP_FIELD (   utype,
  itype,
  field 
)
Value:
do { \
utype aval = (utype) (itype) a->status.field; \
utype bval = (utype) (itype) b->status.field; \
utype u = bval - aval; \
itype r2 = (itype) u; \
if (r2 < 0) { \
return -1; \
} else if (r2 > 0) { \
return 1; \
} \
} while (0)

◆ ENDIF

#define ENDIF
Value:
} \
}

◆ get_most_frequent_member

#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.

Definition at line 590 of file dirvote.c.

◆ IF_TIME_FOR_NEXT_ACTION

#define IF_TIME_FOR_NEXT_ACTION (   when_field,
  done_field 
)
Value:
if (! voting_schedule.done_field) { \
if (voting_schedule.when_field > now) { \
return voting_schedule.when_field; \
} else {

◆ MIN_VOTES_FOR_PARAM

#define MIN_VOTES_FOR_PARAM   3

Minimum number of directory authorities voting for a parameter to include it in the consensus, if consensus method 12 or later is to be used. See proposal 178 for details.

Definition at line 905 of file dirvote.c.

◆ RANGE_CHECK

#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))

Definition at line 995 of file dirvote.c.

Typedef Documentation

◆ dir_src_ent_t

typedef struct dir_src_ent_t dir_src_ent_t

Temporary structure used in constructing a list of dir-source entries for a consensus. One of these is generated for every vote, and one more for every legacy key in each vote.

◆ microdesc_vote_line_t

Helper type used when generating the microdescriptor lines in a directory vote.

◆ pending_consensus_t

A consensus that we have built and are appending signatures to. Once it's time to publish it, it will become an active consensus if it accumulates enough signatures.

◆ pending_vote_t

A vote networkstatus_t and its unparsed body: held around so we can use it to generate a consensus (at voting_ends) and so we can serve it to other authorities that might want it.

Function Documentation

◆ authority_cert_dup()

STATIC authority_cert_t* authority_cert_dup ( authority_cert_t cert)

Allocate and return a new authority_cert_t with the same contents as cert.

Definition at line 142 of file dirvote.c.

◆ clear_status_flags_on_sybil()

static void clear_status_flags_on_sybil ( routerstatus_t rs)
static

Routerstatus rs is part of a group of routers that are on too narrow an IP-space. Clear out its flags since we don't want it be used because of its Sybil-like appearance.

Leave its BadExit flag alone though, since if we think it's a bad exit, we want to vote that way in case all the other authorities are voting Running and Exit.

Definition at line 4386 of file dirvote.c.

References routerstatus_t::is_authority, routerstatus_t::is_exit, routerstatus_t::is_fast, routerstatus_t::is_flagged_running, routerstatus_t::is_hs_dir, routerstatus_t::is_named, routerstatus_t::is_possible_guard, routerstatus_t::is_stable, and routerstatus_t::is_valid.

◆ cmp_int_strings_()

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.)

Definition at line 763 of file dirvote.c.

References tor_parse_long().

◆ compare_dir_src_ents_by_authority_id_()

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

Definition at line 555 of file dirvote.c.

References DIGEST_LEN, fast_memcmp, get_voter(), networkstatus_voter_info_t::identity_digest, and networkstatus_voter_info_t::legacy_id_digest.

◆ compare_orports_()

static int compare_orports_ ( const void **  _a,
const void **  _b 
)
static

Helper for sorting OR ports.

Definition at line 647 of file dirvote.c.

References tor_addr_compare().

◆ compare_routerinfo_by_ip_and_bw_()

static int compare_routerinfo_by_ip_and_bw_ ( const void **  a,
const void **  b 
)
static

Helper for sorting: compares two routerinfos first by address, and then by descending order of "usefulness". (An authority is more useful than a non-authority; a running router is more useful than a non-running router; and a router with more bandwidth is more useful than one with less.)

Definition at line 4171 of file dirvote.c.

References routerinfo_t::addr.

Referenced by get_possible_sybil_list().

◆ compare_vote_rs()

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.

Definition at line 597 of file dirvote.c.

References routerstatus_t::descriptor_digest, DIGEST_LEN, fast_memcmp, routerstatus_t::identity_digest, vote_routerstatus_t::status, and tor_assert().

Referenced by compare_vote_rs_(), and compute_routerstatus_consensus().

◆ compare_vote_rs_()

static int compare_vote_rs_ ( const void **  _a,
const void **  _b 
)
static

Helper for sorting routerlists based on compare_vote_rs.

Definition at line 639 of file dirvote.c.

References compare_vote_rs().

Referenced by compute_routerstatus_consensus().

◆ compare_votes_by_authority_id_()

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.

Definition at line 544 of file dirvote.c.

References DIGEST_LEN, fast_memcmp, and get_voter().

◆ compute_consensus_method()

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.

Definition at line 782 of file dirvote.c.

◆ compute_consensus_package_lines()

STATIC char* compute_consensus_package_lines ( smartlist_t votes)

Given a list of networkstatus_t for each vote, return a newly allocated string containing the "package" lines for the vote.

Definition at line 2459 of file dirvote.c.

◆ compute_consensus_versions_list()

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

Definition at line 850 of file dirvote.c.

References SMARTLIST_FOREACH_BEGIN.

◆ compute_nth_protocol_set()

static char* compute_nth_protocol_set ( int  n,
int  n_voters,
const smartlist_t votes 
)
static

Considering the different recommended/required protocols sets as a 4-element array, return a newly allocated string for the consensus value for the n'th set.

Definition at line 1429 of file dirvote.c.

◆ compute_routerstatus_consensus()

static vote_routerstatus_t* compute_routerstatus_consensus ( smartlist_t votes,
int  consensus_method,
char *  microdesc_digest256_out,
tor_addr_port_t best_alt_orport_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.

Definition at line 666 of file dirvote.c.

References compare_vote_rs(), compare_vote_rs_(), routerstatus_t::published_on, SMARTLIST_FOREACH_BEGIN, smartlist_sort(), and vote_routerstatus_t::status.

◆ consensus_method_is_supported()

static int consensus_method_is_supported ( int  method)
static

Return true iff method is a consensus method that we support.

Definition at line 817 of file dirvote.c.

Referenced by make_consensus_method_list().

◆ dirserv_generate_networkstatus_vote_obj()

networkstatus_t* dirserv_generate_networkstatus_vote_obj ( crypto_pk_t private_key,
authority_cert_t cert 
)

Return a new networkstatus_t* containing our current opinion. (For v3 authorities)

Definition at line 4416 of file dirvote.c.

References or_options_t::AuthDirListBadExits, DIGEST_LEN, router_get_routerlist(), and ROUTER_MAX_AGE_TO_PUBLISH.

◆ dirserv_get_bandwidth_for_router_kb()

static uint32_t dirserv_get_bandwidth_for_router_kb ( const routerinfo_t ri)
static

Get the best estimate of a router's bandwidth for dirauth purposes, preferring measured to advertised values if available.

Definition at line 4136 of file dirvote.c.

References dirserv_query_measured_bw_cache_kb(), signed_descriptor_t::identity_digest, and router_get_advertised_bandwidth().

◆ dirvote_act()

time_t dirvote_act ( const or_options_t options,
time_t  now 
)

Entry point: Take whatever voting actions are pending as of now.

Return the time at which the next action should be taken.

Definition at line 2839 of file dirvote.c.

◆ dirvote_add_signatures()

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.

Definition at line 3634 of file dirvote.c.

◆ dirvote_add_signatures_to_pending_consensus()

static int dirvote_add_signatures_to_pending_consensus ( pending_consensus_t pc,
ns_detached_signatures_t sigs,
const char *  source,
int  severity,
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. (?)

Definition at line 3494 of file dirvote.c.

References pending_consensus_t::body, pending_consensus_t::consensus, networkstatus_t::flavor, networkstatus_get_flavor_name(), pending_consensus_signatures, ns_detached_signatures_t::signatures, and tor_assert().

◆ dirvote_add_vote()

pending_vote_t* dirvote_add_vote ( const char *  vote_body,
const char **  msg_out,
int *  status_out 
)

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)

Definition at line 3131 of file dirvote.c.

References networkstatus_parse_vote_from_string(), pending_vote_list, and tor_assert().

◆ dirvote_clear_pending_consensuses()

static void dirvote_clear_pending_consensuses ( void  )
static

Release all storage held by pending consensuses (those waiting for signatures).

Definition at line 3053 of file dirvote.c.

References N_CONSENSUS_FLAVORS.

◆ dirvote_clear_votes()

static void dirvote_clear_votes ( int  all_votes)
static

Drop all currently pending votes, consensus, and detached signatures.

Definition at line 3067 of file dirvote.c.

References pending_vote_list, previous_vote_list, and SMARTLIST_FOREACH.

Referenced by dirvote_free_all().

◆ dirvote_compute_consensuses()

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)

Definition at line 3324 of file dirvote.c.

References N_CONSENSUS_FLAVORS, and pending_vote_list.

◆ dirvote_compute_params()

STATIC smartlist_t* dirvote_compute_params ( smartlist_t votes,
int  method,
int  total_authorities 
)

Helper: given a list of valid networkstatus_t, return a new smartlist containing the contents of the consensus network parameter set.

Definition at line 911 of file dirvote.c.

◆ dirvote_create_microdescriptor()

STATIC microdesc_t* dirvote_create_microdescriptor ( const routerinfo_t ri,
int  consensus_method 
)

Construct and return a new microdescriptor from a routerinfo ri according to consensus_method.

Definition at line 3780 of file dirvote.c.

◆ dirvote_fetch_missing_signatures()

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.

Definition at line 3030 of file dirvote.c.

References N_CONSENSUS_FLAVORS.

◆ dirvote_fetch_missing_votes()

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)

Definition at line 2990 of file dirvote.c.

References SMARTLIST_FOREACH_BEGIN.

◆ dirvote_format_all_microdesc_vote_lines()

vote_microdesc_hash_t* dirvote_format_all_microdesc_vote_lines ( const routerinfo_t ri,
time_t  now,
smartlist_t microdescriptors_out 
)

Generate and return a linked list of all the lines that should appear to describe a router's microdescriptor versions in a directory vote. Add the generated microdescriptors to microdescriptors_out.

Definition at line 3939 of file dirvote.c.

◆ dirvote_format_microdesc_vote_line()

static ssize_t dirvote_format_microdesc_vote_line ( char *  out_buf,
size_t  out_buf_len,
const microdesc_t md,
int  consensus_method_low,
int  consensus_method_high 
)
static

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.

Definition at line 3886 of file dirvote.c.

References BASE64_DIGEST256_LEN.

◆ dirvote_free_all()

void dirvote_free_all ( void  )

Release all static storage held in dirvote.c

Definition at line 3687 of file dirvote.c.

References dirvote_clear_votes().

◆ dirvote_get_intermediate_param_value()

STATIC int32_t dirvote_get_intermediate_param_value ( const smartlist_t param_list,
const char *  keyword,
int32_t  default_val 
)

Given a list of K=V values, return the int32_t value corresponding to KEYWORD=, or default_val if no such value exists, or if the value is corrupt.

Definition at line 875 of file dirvote.c.

References SMARTLIST_FOREACH_BEGIN, strcmpstart(), and tor_parse_long().

◆ dirvote_get_preferred_voting_intervals()

static void dirvote_get_preferred_voting_intervals ( vote_timing_t timing_out)
static

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.

Definition at line 457 of file dirvote.c.

References vote_timing_t::dist_delay, 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.

◆ dirvote_get_vote()

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.

Definition at line 3734 of file dirvote.c.

◆ dirvote_perform_vote()

static int dirvote_perform_vote ( void  )
static

Generate a networkstatus vote and post it to all the v3 authorities. (V3 Authority only)

Definition at line 2942 of file dirvote.c.

References get_my_v3_authority_signing_key().

◆ dirvote_publish_consensus()

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)

Definition at line 3658 of file dirvote.c.

References N_CONSENSUS_FLAVORS.

◆ extract_shared_random_commits()

static void extract_shared_random_commits ( networkstatus_t ns,
const smartlist_t tokens 
)
static

Parse and extract all SR commits from tokens and place them in ns.

Definition at line 3998 of file dirvote.c.

References find_all_by_keyword(), networkstatus_t::sr_info, tor_assert(), and networkstatus_t::type.

◆ format_networkstatus_vote()

STATIC char* format_networkstatus_vote ( crypto_pk_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.

Definition at line 219 of file dirvote.c.

References DIGEST_LEN, and FINGERPRINT_LEN.

◆ format_protocols_lines_for_vote()

static char* format_protocols_lines_for_vote ( const networkstatus_t v3_ns)
static

Format the recommended/required-relay-client protocols lines for a vote in a newly allocated string, and return that string.

Definition at line 180 of file dirvote.c.

◆ format_recommended_version_list()

char* format_recommended_version_list ( const config_line_t ln,
int  warn 
)

Given a (possibly empty) list of config_line_t, each line of which contains a list of comma-separated version numbers surrounded by optional space, allocate and return a new string containing the version numbers, in order, separated by commas. Used to generate Recommended(Client|Server)?Versions

Definition at line 4286 of file dirvote.c.

References smartlist_split_string().

◆ get_detached_signatures_from_pending_consensuses()

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.

Definition at line 2818 of file dirvote.c.

References networkstatus_get_detached_signatures(), and smartlist_add().

◆ get_frequent_members()

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.

Definition at line 570 of file dirvote.c.

References smartlist_add(), and SMARTLIST_FOREACH_BEGIN.

◆ get_nth_protocol_set_vote()

static const char* get_nth_protocol_set_vote ( int  n,
const networkstatus_t vote 
)
static

Considering the different recommended/required protocols sets as a 4-element array, return the element from vote for that protocol set.

Definition at line 1411 of file dirvote.c.

References networkstatus_t::recommended_relay_protocols.

◆ get_possible_sybil_list()

static digestmap_t* get_possible_sybil_list ( const smartlist_t routers)
static

Given a list of routerinfo_t in routers, return a new digestmap_t whose keys are the identity digests of those routers that we're going to exclude for Sybil-like appearance.

Definition at line 4229 of file dirvote.c.

References or_options_t::AuthDirMaxServersPerAddr, compare_routerinfo_by_ip_and_bw_(), smartlist_add_all(), SMARTLIST_FOREACH_BEGIN, and smartlist_sort().

◆ get_voter()

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.

Definition at line 523 of file dirvote.c.

References tor_assert(), networkstatus_t::type, and networkstatus_t::voters.

Referenced by compare_dir_src_ents_by_authority_id_(), and compare_votes_by_authority_id_().

◆ list_v3_auth_ids()

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.

Definition at line 3109 of file dirvote.c.

References SMARTLIST_FOREACH.

◆ make_consensus_method_list()

STATIC char* make_consensus_method_list ( int  low,
int  high,
const char *  separator 
)

Return a newly allocated string holding the numbers between low and high (inclusive) that are supported consensus methods.

Definition at line 826 of file dirvote.c.

References consensus_method_is_supported(), smartlist_add_asprintf(), SMARTLIST_FOREACH, smartlist_join_strings(), tor_assert(), and tor_free.

◆ MOCK_IMPL() [1/2]

MOCK_IMPL ( const char *  ,
dirvote_get_pending_consensus  ,
(consensus_flavor_t flav)   
)

Return the body of the consensus that we're currently trying to build.

Definition at line 3710 of file dirvote.c.

References N_CONSENSUS_FLAVORS, and tor_assert().

◆ MOCK_IMPL() [2/2]

MOCK_IMPL ( const char *  ,
dirvote_get_pending_detached_signatures  ,
(void)   
)

Return the signatures that we know for the consensus that we're currently trying to build.

Definition at line 3719 of file dirvote.c.

References pending_consensus_signatures.

◆ networkstatus_add_detached_signatures()

STATIC int networkstatus_add_detached_signatures ( networkstatus_t target,
ns_detached_signatures_t sigs,
const char *  source,
int  severity,
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.

Definition at line 2537 of file dirvote.c.

References ns_detached_signatures_t::digests, networkstatus_t::flavor, networkstatus_t::fresh_until, networkstatus_get_flavor_name(), ns_detached_signatures_t::signatures, tor_assert(), networkstatus_t::type, networkstatus_t::valid_after, and networkstatus_t::valid_until.

◆ networkstatus_check_weights()

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.

Definition at line 1018 of file dirvote.c.

◆ networkstatus_compute_bw_weights_v10()

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 
)

This function computes the bandwidth weights for consensus method 10.

It returns true if weights could be computed, false otherwise.

Definition at line 1087 of file dirvote.c.

◆ networkstatus_compute_consensus()

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 
)

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 or microdescriptor consensus (depending on flavor), 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.)

WATCH OUT: You need to think before you change the behavior of this function, or of the functions it calls! If some authorities compute the consensus with a different algorithm than others, they will not reach the same result, and they will not all sign the same thing! If you really need to change the algorithm here, you should allocate a new "consensus_method" for the new behavior, and make the new behavior conditional on a new-enough consensus_method.

Definition at line 1492 of file dirvote.c.

References DEFAULT_MAX_UNMEASURED_BW_KB, and T.

◆ networkstatus_format_signatures()

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".

Definition at line 2668 of file dirvote.c.

References networkstatus_t::flavor, and networkstatus_get_flavor_name().

◆ networkstatus_get_detached_signatures()

STATIC 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.

Definition at line 2729 of file dirvote.c.

References SMARTLIST_FOREACH, and tor_assert().

Referenced by get_detached_signatures_from_pending_consensuses().

◆ routers_make_ed_keys_unique()

static void routers_make_ed_keys_unique ( smartlist_t routers)
static

If there are entries in routers with exactly the same ed25519 keys, remove the older one. If they are exactly the same age, remove the one with the greater descriptor digest. May alter the order of the list.

Definition at line 4337 of file dirvote.c.

References DIGEST_LEN, fast_memcmp, routerinfo_t::omit_from_vote, signed_descriptor_t::published_on, signed_descriptor_t::signed_descriptor_digest, and SMARTLIST_FOREACH_BEGIN.

◆ update_total_bandwidth_weights()

static void update_total_bandwidth_weights ( const routerstatus_t rs,
int  is_exit,
int  is_guard,
int64_t *  G,
int64_t *  M,
int64_t *  E,
int64_t *  D,
int64_t *  T 
)
static

Update total bandwidth weights (G/M/E/D/T) with the bandwidth of the router in rs.

Definition at line 1327 of file dirvote.c.

References routerstatus_t::bandwidth_kb, and routerstatus_t::has_bandwidth.

◆ version_from_platform()

static char* version_from_platform ( const char *  platform)
static

Given a platform string as in a routerinfo_t (possibly null), return a newly allocated version string for a networkstatus document, or NULL if the platform doesn't give a Tor version.

Definition at line 4264 of file dirvote.c.

References find_whitespace(), and strcmpstart().

◆ vote_routerstatus_find_microdesc_hash()

static int vote_routerstatus_find_microdesc_hash ( char *  digest256_out,
const vote_routerstatus_t vrs,
int  method,
digest_algorithm_t  alg 
)
static

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.

Definition at line 477 of file dirvote.c.

Variable Documentation

◆ DIRVOTE_OPTIONAL_FLAGS

const char DIRVOTE_OPTIONAL_FLAGS[]
Initial value:
=
"BadExit "
"Running"

Space-separated list of all flags that we may or may not vote on, depending on our configuration.

Definition at line 4409 of file dirvote.c.

◆ DIRVOTE_UNIVERSAL_FLAGS

const char DIRVOTE_UNIVERSAL_FLAGS[]
Initial value:
=
"Authority "
"Exit "
"Fast "
"Guard "
"HSDir "
"Stable "
"StaleDesc "
"V2Dir "
"Valid"

Space-separated list of all the flags that we will always vote on.

Definition at line 4397 of file dirvote.c.

◆ microdesc_consensus_methods

const struct consensus_method_range_t microdesc_consensus_methods[]
static
Initial value:

◆ pending_consensus_signature_list

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.

Definition at line 2937 of file dirvote.c.

◆ pending_consensus_signatures

char* pending_consensus_signatures = NULL
static

The detached signatures for the consensus that we're currently building.

Definition at line 2933 of file dirvote.c.

Referenced by dirvote_add_signatures_to_pending_consensus(), and MOCK_IMPL().

◆ pending_vote_list

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.

Definition at line 2923 of file dirvote.c.

Referenced by dirvote_add_vote(), dirvote_clear_votes(), and dirvote_compute_consensuses().

◆ previous_vote_list

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.

Definition at line 2926 of file dirvote.c.

Referenced by dirvote_clear_votes().