tor  0.4.2.1-alpha-dev
Data Structures | Macros | Typedefs | Functions
dircollate.c File Reference
#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_s
 

Macros

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

Typedefs

typedef struct ddmap_entry_s ddmap_entry_t
 

Functions

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 (HT_GENERATE2(double_digest_map, HT_GENERATE2(ddmap_entry_s, HT_GENERATE2(node, HT_GENERATE2(ddmap_entry_hash, HT_GENERATE2(ddmap_entry_eq)
 
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.

Typedef Documentation

◆ ddmap_entry_t

typedef struct ddmap_entry_s ddmap_entry_t

Hashtable entry mapping a pair of digests (actually an ed25519 key and an RSA SHA1 digest) to an array of vote_routerstatus_t.

Function Documentation

◆ ddmap_entry_eq()

static unsigned ddmap_entry_eq ( const ddmap_entry_t a,
const ddmap_entry_t b 
)
static

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

Release all storage held by e.

Definition at line 51 of file dircollate.c.

References tor_free.

◆ ddmap_entry_hash()

static unsigned ddmap_entry_hash ( const ddmap_entry_t ent)
static

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

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

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.

References DIGEST256_LEN, and DIGEST_LEN.

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

References dircollator_collate_by_ed25519(), smartlist_sort_digests(), and tor_assert().

◆ dircollator_collate_by_ed25519()

static void dircollator_collate_by_ed25519 ( dircollator_t *  dc)
static

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.

References DIGESTMAP_FOREACH, smartlist_add(), and tor_assert().

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.

References tor_assert().

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

References tor_assert().

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