Data Structures | Macros | Functions
dircollate.c File Reference

Collation code for figuring out which identities to vote for in the directory voting process. More...

#include "feature/dirauth/dircollate.h"
#include "feature/dirauth/dirvote.h"
#include "feature/nodelist/networkstatus_st.h"
#include "feature/nodelist/vote_routerstatus_st.h"

Go to the source code of this file.

Data Structures

struct  ddmap_entry_t


#define ddmap_entry_free(e)    FREE_AND_NULL(ddmap_entry_t, ddmap_entry_free_, (e))


static void dircollator_collate_by_ed25519 (dircollator_t *dc)
static void ddmap_entry_free_ (ddmap_entry_t *e)
static ddmap_entry_tddmap_entry_new (int n_votes)
static unsigned ddmap_entry_hash (const ddmap_entry_t *ent)
static unsigned ddmap_entry_eq (const ddmap_entry_t *a, const ddmap_entry_t *b)
static void ddmap_entry_set_digests (ddmap_entry_t *ent, const uint8_t *rsa_sha1, const uint8_t *ed25519)
 HT_PROTOTYPE (double_digest_map, ddmap_entry_t, node, ddmap_entry_hash, ddmap_entry_eq)
 HT_GENERATE2 (double_digest_map, ddmap_entry_t, node, ddmap_entry_hash, ddmap_entry_eq, 0.6, tor_reallocarray, tor_free_)
static void dircollator_add_routerstatus (dircollator_t *dc, int vote_num, networkstatus_t *vote, vote_routerstatus_t *vrs)
dircollator_t * dircollator_new (int n_votes, int n_authorities)
void dircollator_free_ (dircollator_t *dc)
void dircollator_add_vote (dircollator_t *dc, networkstatus_t *v)
void dircollator_collate (dircollator_t *dc, int consensus_method)
int dircollator_n_routers (dircollator_t *dc)
vote_routerstatus_t ** dircollator_get_votes_for_router (dircollator_t *dc, int idx)

Detailed Description

Collation code for figuring out which identities to vote for in the directory voting process.

During the consensus calculation, when an authority is looking at the vote documents from all the authorities, it needs to compute the consensus for each relay listed by at least one authority. But the notion of "each relay" can be tricky: some relays have Ed25519 keys, and others don't.

Moreover, older consensus methods did RSA-based ID collation alone, and ignored Ed25519 keys. We need to support those too until we're completely sure that authorities will never downgrade.

This module is invoked exclusively from dirvote.c.

Definition in file dircollate.c.

Function Documentation

◆ ddmap_entry_eq()

static unsigned ddmap_entry_eq ( const ddmap_entry_t a,
const ddmap_entry_t b 

Helper: return true if a and b have the same identity/identities.

Definition at line 76 of file dircollate.c.

◆ ddmap_entry_free_()

static void ddmap_entry_free_ ( ddmap_entry_t e)

Release all storage held by e.

Definition at line 51 of file dircollate.c.

◆ ddmap_entry_hash()

static unsigned ddmap_entry_hash ( const ddmap_entry_t ent)

Helper: compute a hash of a single ddmap_entry_t's identity (or identities)

Definition at line 68 of file dircollate.c.

◆ ddmap_entry_new()

static ddmap_entry_t* ddmap_entry_new ( int  n_votes)

Return a new empty ddmap_entry, with n_votes elements in vrs_list.

Definition at line 59 of file dircollate.c.

◆ ddmap_entry_set_digests()

static void ddmap_entry_set_digests ( ddmap_entry_t ent,
const uint8_t *  rsa_sha1,
const uint8_t *  ed25519 

Record the RSA identity of ent as rsa_sha1, and the ed25519 identity as ed25519. Both must be provided.

Definition at line 84 of file dircollate.c.

◆ dircollator_add_routerstatus()

static void dircollator_add_routerstatus ( dircollator_t *  dc,
int  vote_num,
networkstatus_t vote,
vote_routerstatus_t vrs 

Helper: add a single vote_routerstatus_t vrs to the collator dc, indexing it by its RSA key digest, and by the 2-tuple of its RSA key digest and Ed25519 key. It must come from the vote_numth vote.

Requires that the vote is well-formed – that is, that it has no duplicate routerstatus entries. We already checked for that when parsing the vote.

Definition at line 105 of file dircollate.c.

◆ dircollator_add_vote()

void dircollator_add_vote ( dircollator_t *  dc,
networkstatus_t v 

Add a single vote v to a dircollator dc. This function must be called exactly once for each vote to be used in the consensus. It may only be called before dircollator_collate().

Definition at line 194 of file dircollate.c.

◆ dircollator_collate()

void dircollator_collate ( dircollator_t *  dc,
int  consensus_method 

Sort the entries in dc according to consensus_method, so that the consensus process can iterate over them with dircollator_n_routers() and dircollator_get_votes_for_router().

Definition at line 211 of file dircollate.c.

◆ dircollator_collate_by_ed25519()

static void dircollator_collate_by_ed25519 ( dircollator_t *  dc)

Collation function for ed25519 consensuses: collate the votes for each entry in dc by ed25519 key and by RSA key.

The rule is, approximately: If a (ed,rsa) identity is listed by more than half of authorities, include it. And include all (rsa)-only votes about that node as matching.

Otherwise, if an (*,rsa) or (rsa) identity is listed by more than half of the authorities, and no (ed,rsa) pair for the same RSA key has been already been included based on the rule above, include that RSA identity.

Definition at line 239 of file dircollate.c.

Referenced by dircollator_collate().

◆ dircollator_free_()

void dircollator_free_ ( dircollator_t *  dc)

Release all storage held by dc.

Definition at line 166 of file dircollate.c.

◆ dircollator_get_votes_for_router()

vote_routerstatus_t** dircollator_get_votes_for_router ( dircollator_t *  dc,
int  idx 

Return an array of vote_routerstatus_t entries for the idxth router in the collation order. Each array contains n_votes elements, where the nth element of the array is the vote_routerstatus_t from the nth voter for this identity (or NULL if there is no such entry).

The maximum value for idx is dircollator_n_routers().

This function may only be called after dircollator_collate.

Definition at line 320 of file dircollate.c.

◆ dircollator_n_routers()

int dircollator_n_routers ( dircollator_t *  dc)

Return the total number of collated router entries. This function may only be called after dircollator_collate.

Definition at line 305 of file dircollate.c.

◆ dircollator_new()

dircollator_t* dircollator_new ( int  n_votes,
int  n_authorities 

Create and return a new dircollator object to use when collating n_votes out of a total of n_authorities.

Definition at line 149 of file dircollate.c.