routerlist.c File Reference

Code to maintain and access the global list of routerinfos for known servers. More...

#include "or.h"

Data Structures

struct  cert_list_t
struct  duration_idx_t
struct  routerset_t

Defines

#define SDMAP_FOREACH(map, keyvar, valvar)
#define RIMAP_FOREACH(map, keyvar, valvar)   DIGESTMAP_FOREACH(rimap_to_digestmap(map), keyvar, routerinfo_t *, valvar)
#define EIMAP_FOREACH(map, keyvar, valvar)   DIGESTMAP_FOREACH(eimap_to_digestmap(map), keyvar, extrainfo_t *, valvar)
#define get_n_v2_authorities()   get_n_authorities(V2_AUTHORITY)
#define DEAD_CERT_LIFETIME   (2*24*60*60)
#define OLD_CERT_LIFETIME   (7*24*60*60)
#define MAX_CERT_DL_FAILURES   8
#define RRS_FORCE   1
#define RRS_DONT_REMOVE_OLD   2
#define DIR_503_TIMEOUT   (60*60)
#define DEFAULT_MAX_BELIEVABLE_BANDWIDTH   10000000
#define should_cache_old_descriptors()   directory_caches_dir_info(get_options())
#define MAX_DL_PER_REQUEST   96
#define MIN_DL_PER_REQUEST   4
#define MIN_REQUESTS   3
#define MAX_DL_TO_DELAY   16
#define MAX_CLIENT_INTERVAL_WITHOUT_REQUEST   (10*60)
#define DUMMY_DOWNLOAD_INTERVAL   (20*60)
#define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE   (12*60*60)
#define ROUTER_ALLOW_UPTIME_DRIFT   (6*60*60)

Functions

static routerstatus_trouter_pick_directory_server_impl (authority_type_t auth, int flags)
static routerstatus_trouter_pick_trusteddirserver_impl (authority_type_t auth, int flags, int *n_busy_out)
static void mark_all_trusteddirservers_up (void)
static int router_nickname_matches (routerinfo_t *router, const char *nickname)
static void trusted_dir_server_free (trusted_dir_server_t *ds)
static void launch_router_descriptor_downloads (smartlist_t *downloadable, routerstatus_t *source, time_t now)
static int signed_desc_digest_is_recognized (signed_descriptor_t *desc)
static void update_router_have_minimum_dir_info (void)
static const char * signed_descriptor_get_body_impl (signed_descriptor_t *desc, int with_annotations)
static void list_pending_downloads (digestmap_t *result, int purpose, const char *prefix)
int get_n_authorities (authority_type_t type)
static cert_list_tget_cert_list (const char *id_digest)
int trusted_dirs_reload_certs (void)
static INLINE int already_have_cert (authority_cert_t *cert)
int trusted_dirs_load_certs_from_string (const char *contents, int from_store, int flush)
void trusted_dirs_flush_certs_to_disk (void)
static void trusted_dirs_remove_old_certs (void)
authority_cert_tauthority_cert_get_newest_by_id (const char *id_digest)
authority_cert_tauthority_cert_get_by_sk_digest (const char *sk_digest)
authority_cert_tauthority_cert_get_by_digests (const char *id_digest, const char *sk_digest)
void authority_cert_get_all (smartlist_t *certs_out)
void authority_cert_dl_failed (const char *id_digest, int status)
void authority_certs_fetch_missing (networkstatus_t *status, time_t now)
static int router_should_rebuild_store (desc_store_t *store)
static INLINE desc_store_tdesc_get_store (routerlist_t *rl, signed_descriptor_t *sd)
static int signed_desc_append_to_journal (signed_descriptor_t *desc, desc_store_t *store)
static int _compare_signed_descriptors_by_age (const void **_a, const void **_b)
static int router_rebuild_store (int flags, desc_store_t *store)
static int router_reload_router_list_impl (desc_store_t *store)
int router_reload_router_list (void)
smartlist_trouter_get_trusted_dir_servers (void)
routerstatus_trouter_pick_directory_server (authority_type_t type, int flags)
int router_get_my_share_of_directory_requests (double *v2_share_out, double *v3_share_out)
trusted_dir_server_trouter_get_trusteddirserver_by_digest (const char *digest)
trusted_dir_server_ttrusteddirserver_get_by_v3_auth_digest (const char *digest)
routerstatus_trouter_pick_trusteddirserver (authority_type_t type, int flags)
void router_reset_status_download_failures (void)
static INLINE int routers_in_same_network_family (routerinfo_t *r1, routerinfo_t *r2)
static void routerlist_add_network_family (smartlist_t *sl, routerinfo_t *router)
void routerlist_add_family (smartlist_t *sl, routerinfo_t *router)
static INLINE int router_in_nickname_smartlist (smartlist_t *lst, routerinfo_t *r)
int routers_in_same_family (routerinfo_t *r1, routerinfo_t *r2)
void add_nickname_list_to_smartlist (smartlist_t *sl, const char *list, int must_be_running)
int router_nickname_is_in_list (routerinfo_t *router, const char *list)
static void router_add_running_routers_to_smartlist (smartlist_t *sl, int allow_invalid, int need_uptime, int need_capacity, int need_guard)
routerinfo_trouterlist_find_my_routerinfo (void)
routerinfo_trouter_find_exact_exit_enclave (const char *address, uint16_t port)
int router_is_unreliable (routerinfo_t *router, int need_uptime, int need_capacity, int need_guard)
uint32_t router_get_advertised_bandwidth (routerinfo_t *router)
uint32_t router_get_advertised_bandwidth_capped (routerinfo_t *router)
static INLINE int32_t kb_to_bytes (uint32_t bw)
static void * smartlist_choose_by_bandwidth_weights (smartlist_t *sl, bandwidth_weight_rule_t rule, int statuses)
static void * smartlist_choose_by_bandwidth (smartlist_t *sl, bandwidth_weight_rule_t rule, int statuses)
routerinfo_trouterlist_sl_choose_by_bandwidth (smartlist_t *sl, bandwidth_weight_rule_t rule)
routerstatus_trouterstatus_sl_choose_by_bandwidth (smartlist_t *sl, bandwidth_weight_rule_t rule)
routerinfo_trouter_choose_random_node (smartlist_t *excludedsmartlist, routerset_t *excludedset, router_crn_flags_t flags)
static INLINE int hex_digest_matches (const char *hexdigest, const char *identity_digest, const char *nickname, int is_named)
static INLINE int router_hex_digest_matches (routerinfo_t *router, const char *hexdigest)
routerinfo_trouter_get_by_nickname (const char *nickname, int warn_if_unnamed)
int router_digest_version_as_new_as (const char *digest, const char *cutoff)
int router_digest_is_trusted_dir_type (const char *digest, authority_type_t type)
int router_addr_is_trusted_dir (uint32_t addr)
int hexdigest_to_digest (const char *hexdigest, char *digest)
routerinfo_trouter_get_by_hexdigest (const char *hexdigest)
routerinfo_trouter_get_by_digest (const char *digest)
signed_descriptor_trouter_get_by_descriptor_digest (const char *digest)
signed_descriptor_trouter_get_by_extrainfo_digest (const char *digest)
signed_descriptor_textrainfo_get_by_descriptor_digest (const char *digest)
const char * signed_descriptor_get_body (signed_descriptor_t *desc)
const char * signed_descriptor_get_annotations (signed_descriptor_t *desc)
routerlist_trouter_get_routerlist (void)
void routerinfo_free (routerinfo_t *router)
void extrainfo_free (extrainfo_t *extrainfo)
static void signed_descriptor_free (signed_descriptor_t *sd)
static signed_descriptor_tsigned_descriptor_from_routerinfo (routerinfo_t *ri)
static void _extrainfo_free (void *e)
void routerlist_free (routerlist_t *rl)
void dump_routerlist_mem_usage (int severity)
static INLINE int _routerlist_find_elt (smartlist_t *sl, void *ri, int idx)
static void routerlist_insert (routerlist_t *rl, routerinfo_t *ri)
static int extrainfo_insert (routerlist_t *rl, extrainfo_t *ei)
static void routerlist_insert_old (routerlist_t *rl, routerinfo_t *ri)
void routerlist_remove (routerlist_t *rl, routerinfo_t *ri, int make_old, time_t now)
static void routerlist_remove_old (routerlist_t *rl, signed_descriptor_t *sd, int idx)
static void routerlist_replace (routerlist_t *rl, routerinfo_t *ri_old, routerinfo_t *ri_new)
static routerinfo_trouterlist_reparse_old (routerlist_t *rl, signed_descriptor_t *sd)
void routerlist_free_all (void)
void routerlist_reset_warnings (void)
void router_set_status (const char *digest, int up)
was_router_added_t router_add_to_routerlist (routerinfo_t *router, const char **msg, int from_cache, int from_fetch)
was_router_added_t router_add_extrainfo_to_routerlist (extrainfo_t *ei, const char **msg, int from_cache, int from_fetch)
static int _compare_old_routers_by_identity (const void **_a, const void **_b)
static int _compare_duration_idx (const void *_d1, const void *_d2)
static void routerlist_remove_old_cached_routers_with_id (time_t now, time_t cutoff, int lo, int hi, digestset_t *retain)
void routerlist_remove_old_routers (void)
static void routerlist_descriptors_added (smartlist_t *sl, int from_cache)
int router_load_single_router (const char *s, uint8_t purpose, int cache, const char **msg)
int router_load_routers_from_string (const char *s, const char *eos, saved_location_t saved_location, smartlist_t *requested_fingerprints, int descriptor_digests, const char *prepend_annotations)
void router_load_extrainfo_from_string (const char *s, const char *eos, saved_location_t saved_location, smartlist_t *requested_fingerprints, int descriptor_digests)
void routerlist_retry_directory_downloads (time_t now)
int router_exit_policy_all_routers_reject (uint32_t addr, uint16_t port, int need_uptime)
int router_exit_policy_rejects_all (routerinfo_t *router)
trusted_dir_server_tadd_trusted_dir_server (const char *nickname, const char *address, uint16_t dir_port, uint16_t or_port, const char *digest, const char *v3_auth_digest, authority_type_t type)
void authority_cert_free (authority_cert_t *cert)
void clear_trusted_dir_servers (void)
int any_trusted_dir_is_v1_authority (void)
static void list_pending_descriptor_downloads (digestmap_t *result, int extrainfo)
static void initiate_descriptor_downloads (routerstatus_t *source, int purpose, smartlist_t *digests, int lo, int hi, int pds_flags)
static INLINE int client_would_use_router (routerstatus_t *rs, time_t now, or_options_t *options)
static void update_router_descriptor_cache_downloads_v2 (time_t now)
void update_consensus_router_descriptor_downloads (time_t now, int is_vote, networkstatus_t *consensus)
void update_router_descriptor_downloads (time_t now)
void update_extrainfo_downloads (time_t now)
int router_have_minimum_dir_info (void)
void router_dir_info_changed (void)
const char * get_dir_info_status_string (void)
static void count_usable_descriptors (int *num_present, int *num_usable, const networkstatus_t *consensus, or_options_t *options, time_t now)
int count_loading_descriptors_progress (void)
void router_reset_descriptor_download_failures (void)
int router_differences_are_cosmetic (routerinfo_t *r1, routerinfo_t *r2)
int routerinfo_incompatible_with_extrainfo (routerinfo_t *ri, extrainfo_t *ei, signed_descriptor_t *sd, const char **msg)
void routerlist_assert_ok (routerlist_t *rl)
const char * esc_router_info (routerinfo_t *router)
static int _compare_routerinfo_by_id_digest (const void **a, const void **b)
void routers_sort_by_identity (smartlist_t *routers)
routerset_trouterset_new (void)
static char * routerset_get_countryname (const char *c)
void routerset_refresh_countries (routerset_t *target)
int routerset_parse (routerset_t *target, const char *s, const char *description)
void refresh_all_country_info (void)
void routerset_union (routerset_t *target, const routerset_t *source)
int routerset_is_list (const routerset_t *set)
int routerset_needs_geoip (const routerset_t *set)
static int routerset_is_empty (const routerset_t *set)
static int routerset_contains (const routerset_t *set, const tor_addr_t *addr, uint16_t orport, const char *nickname, const char *id_digest, int is_named, country_t country)
int routerset_contains_extendinfo (const routerset_t *set, const extend_info_t *ei)
int routerset_contains_router (const routerset_t *set, routerinfo_t *ri)
int routerset_contains_routerstatus (const routerset_t *set, routerstatus_t *rs)
void routerset_get_all_routers (smartlist_t *out, const routerset_t *routerset, int running_only)
void routersets_get_disjunction (smartlist_t *target, const smartlist_t *source, const routerset_t *include, const routerset_t *exclude, int running_only)
void routerset_subtract_routers (smartlist_t *lst, const routerset_t *routerset)
char * routerset_to_string (const routerset_t *set)
int routerset_equal (const routerset_t *old, const routerset_t *new)
void routerset_free (routerset_t *routerset)
void routerinfo_set_country (routerinfo_t *ri)
void routerlist_refresh_countries (void)
int hid_serv_get_responsible_directories (smartlist_t *responsible_dirs, const char *id)
int hid_serv_acting_as_directory (void)
int hid_serv_responsible_for_desc_id (const char *query)

Variables

static smartlist_ttrusted_dir_servers = NULL
static digestmap_t * trusted_dir_certs = NULL
static int trusted_dir_servers_certs_changed = 0
static routerlist_trouterlist = NULL
static smartlist_twarned_nicknames = NULL
static time_t last_routerdesc_download_attempted = 0
static uint64_t sl_last_total_weighted_bw = 0
static uint64_t sl_last_weighted_bw_of_me = 0
static int have_min_dir_info = 0
static int need_to_update_have_min_dir_info = 1
static char dir_info_status [128] = ""


Detailed Description

Code to maintain and access the global list of routerinfos for known servers.


Define Documentation

#define DEFAULT_MAX_BELIEVABLE_BANDWIDTH   10000000

Do not weight any declared bandwidth more than this much when picking routers by bandwidth.

Referenced by router_get_advertised_bandwidth_capped().

#define DIR_503_TIMEOUT   (60*60)

How long do we avoid using a directory server after it's given us a 503?

Referenced by router_pick_directory_server_impl(), and router_pick_trusteddirserver_impl().

#define DUMMY_DOWNLOAD_INTERVAL   (20*60)

How often should we launch a server/authority request to be sure of getting a guess for our IP?

Referenced by update_router_descriptor_downloads().

#define MAX_CERT_DL_FAILURES   8

How many times will we try to fetch a certificate before giving up?

Referenced by authority_certs_fetch_missing().

#define MAX_CLIENT_INTERVAL_WITHOUT_REQUEST   (10*60)

When directory clients have only a few servers to request, they batch them until they have more, or until this amount of time has passed.

Referenced by launch_router_descriptor_downloads().

#define MAX_DL_PER_REQUEST   96

Max amount of hashes to download per request. Since squid does not like URLs >= 4096 bytes we limit it to 96. 4096 - strlen(http://255.255.255.255/tor/server/d/.z) == 4058 4058/41 (40 for the hash and 1 for the + that separates them) => 98 So use 96 because it's a nice number.

Referenced by launch_router_descriptor_downloads(), and update_extrainfo_downloads().

#define MAX_DL_TO_DELAY   16

If we want fewer than this many descriptors, wait until we want more, or until MAX_CLIENT_INTERVAL_WITHOUT_REQUEST has passed.

Referenced by launch_router_descriptor_downloads().

#define MIN_DL_PER_REQUEST   4

Don't split our requests so finely that we are requesting fewer than this number per server.

Referenced by launch_router_descriptor_downloads().

#define MIN_REQUESTS   3

To prevent a single screwy cache from confusing us by selective reply, try to split our requests into at least this many requests.

Referenced by launch_router_descriptor_downloads().

#define ROUTER_ALLOW_UPTIME_DRIFT   (6*60*60)

We allow uptime to vary from how much it ought to be by this much.

Referenced by router_differences_are_cosmetic().

#define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE   (12*60*60)

Any changes in a router descriptor's publication time larger than this are automatically non-cosmetic.

Referenced by router_differences_are_cosmetic().

#define SDMAP_FOREACH ( map,
keyvar,
valvar   ) 

Value:

DIGESTMAP_FOREACH(sdmap_to_digestmap(map), keyvar, signed_descriptor_t *, \
                    valvar)


Function Documentation

static int _compare_duration_idx ( const void *  _d1,
const void *  _d2 
) [static]

Sorting helper: compare two duration_idx_t by their duration.

References duration_idx_t::duration.

Referenced by routerlist_remove_old_cached_routers_with_id().

static int _compare_old_routers_by_identity ( const void **  _a,
const void **  _b 
) [static]

Sorting helper: return <0, 0, or >0 depending on whether the signed_descriptor_t* in *a has an identity digest preceding, equal to, or later than that of *b.

References DIGEST_LEN, signed_descriptor_t::identity_digest, and signed_descriptor_t::published_on.

Referenced by routerlist_remove_old_routers().

static int _compare_routerinfo_by_id_digest ( const void **  a,
const void **  b 
) [static]

Helper for sorting: compare two routerinfos by their identity digest.

References routerinfo_t::cache_info, DIGEST_LEN, and signed_descriptor_t::identity_digest.

Referenced by routers_sort_by_identity().

static int _compare_signed_descriptors_by_age ( const void **  _a,
const void **  _b 
) [static]

Sorting helper: return <0, 0, or >0 depending on whether the signed_descriptor_t* in *a is older, the same age as, or newer than the signed_descriptor_t* in *b.

References signed_descriptor_t::published_on.

Referenced by router_rebuild_store().

static void _extrainfo_free ( void *  e  )  [static]

Helper: free the storage held by the extrainfo_t in e.

References extrainfo_free().

Referenced by routerlist_free().

static INLINE int _routerlist_find_elt ( smartlist_t sl,
void *  ri,
int  idx 
) [static]

Debugging helper: If idx is nonnegative, assert that ri is in sl at position idx. Otherwise, search sl for ri. Return the index of ri in sl, or -1 if ri is not in sl.

References tor_assert.

Referenced by routerlist_replace().

void add_nickname_list_to_smartlist ( smartlist_t sl,
const char *  list,
int  must_be_running 
)

Given a (possibly NULL) comma-and-whitespace separated list of nicknames, see which nicknames in list name routers in our routerlist, and add the routerinfos for those routers to sl. If must_be_running, only include routers that we think are running. Warn if any non-Named routers are specified by nickname.

References is_legal_nickname_or_hexdigest(), routerinfo_t::is_running, LD_CONFIG, router_get_by_nickname(), router_get_consensus_status_by_nickname(), router_have_minimum_dir_info(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_split_string(), smartlist_string_isin(), tor_assert, tor_free, and warned_nicknames.

trusted_dir_server_t* add_trusted_dir_server ( const char *  nickname,
const char *  address,
uint16_t  dir_port,
uint16_t  or_port,
const char *  digest,
const char *  v3_auth_digest,
authority_type_t  type 
)

static INLINE int already_have_cert ( authority_cert_t cert  )  [static]

int any_trusted_dir_is_v1_authority ( void   ) 

Return 1 if any trusted dir server supports v1 directories, else return 0.

References get_n_authorities(), trusted_dir_servers, and V1_AUTHORITY.

void authority_cert_dl_failed ( const char *  id_digest,
int  status 
)

Called when an attempt to download a certificate with the authority with ID id_digest fails with HTTP response code status: remember the failure, so we don't try again immediately.

References digestmap_get(), cert_list_t::dl_status, download_status_failed, and trusted_dir_certs.

Referenced by connection_dir_download_cert_failed(), and trusted_dirs_load_certs_from_string().

void authority_cert_free ( authority_cert_t cert  ) 

void authority_cert_get_all ( smartlist_t certs_out  ) 

Add every known authority_cert_t to certs_out.

References smartlist_add(), tor_assert, and trusted_dir_certs.

Referenced by directory_handle_command_get().

authority_cert_t* authority_cert_get_by_digests ( const char *  id_digest,
const char *  sk_digest 
)

Return the v3 authority certificate with signing key matching sk_digest, for the authority with identity digest id_digest. Return NULL if no such authority is known.

References cert_list_t::certs, DIGEST_LEN, digestmap_get(), and trusted_dir_certs.

Referenced by authority_cert_parse_from_string(), authority_certs_fetch_missing(), directory_handle_command_get(), dirvote_add_vote(), networkstatus_add_detached_signatures(), and networkstatus_check_consensus_signature().

authority_cert_t* authority_cert_get_by_sk_digest ( const char *  sk_digest  ) 

Return the newest v3 authority certificate whose directory signing key has digest sk_digest. Return NULL if no such certificate is known.

References DIGEST_LEN, get_my_v3_authority_cert(), get_my_v3_legacy_cert(), authority_cert_t::signing_key_digest, and trusted_dir_certs.

Referenced by directory_handle_command_get().

authority_cert_t* authority_cert_get_newest_by_id ( const char *  id_digest  ) 

Return the newest v3 authority certificate whose v3 authority identity key has digest id_digest. Return NULL if no such authority is known, or it has no certificate.

References authority_cert_t::cache_info, cert_list_t::certs, digestmap_get(), signed_descriptor_t::published_on, and trusted_dir_certs.

Referenced by directory_handle_command_get().

void authority_certs_fetch_missing ( networkstatus_t status,
time_t  now 
)

void clear_trusted_dir_servers ( void   ) 

Remove all members from the list of trusted dir servers.

References router_dir_info_changed(), smartlist_clear(), smartlist_create(), trusted_dir_server_free(), and trusted_dir_servers.

Referenced by consider_adding_dir_authorities().

static INLINE int client_would_use_router ( routerstatus_t rs,
time_t  now,
or_options_t options 
) [static]

Return 0 if this routerstatus is obsolete, too new, isn't running, or otherwise not a descriptor that we would make any use of even if we had it. Else return 1.

References or_options_t::FetchUselessDescriptors, routerstatus_t::is_running, OLD_ROUTER_DESC_MAX_AGE, routerstatus_t::published_on, and or_options_t::TestingEstimatedDescriptorPropagationTime.

Referenced by count_usable_descriptors().

int count_loading_descriptors_progress ( void   ) 

We just fetched a new set of descriptors. Compute how far through the "loading descriptors" bootstrapping phase we are, so we can inform the controller of our progress.

References count_usable_descriptors(), get_options(), and networkstatus_get_reasonably_live_consensus().

Referenced by connection_edge_process_relay_cell_not_open(), and load_downloaded_routers().

static void count_usable_descriptors ( int *  num_present,
int *  num_usable,
const networkstatus_t consensus,
or_options_t options,
time_t  now 
) [static]

Iterate over the servers listed in consensus, and count how many of them seem like ones we'd use, and how many of those we have descriptors for. Store the former in *num_usable and the latter in *num_present.

References client_would_use_router(), router_get_by_descriptor_digest(), and networkstatus_t::routerstatus_list.

Referenced by count_loading_descriptors_progress(), and update_router_have_minimum_dir_info().

static INLINE desc_store_t* desc_get_store ( routerlist_t rl,
signed_descriptor_t sd 
) [static]

void dump_routerlist_mem_usage ( int  severity  ) 

Log information about how much memory is being used for routerlist, at log level severity.

References LD_DIR, routerlist_t::old_routers, routerlist, and routerlist_t::routers.

Referenced by dumpmemusage().

const char* esc_router_info ( routerinfo_t router  ) 

Allocate and return a new string representing the contact info and platform string for router, surrounded by quotes and using standard C escapes.

THIS FUNCTION IS NOT REENTRANT. Don't call it from outside the main thread. Also, each call invalidates the last-returned value, so don't try log_warn(LD_GENERAL, "%s %s", esc_router_info(a), esc_router_info(b));

If router is NULL, it just frees its internal memory and returns.

References routerinfo_t::contact_info, esc_for_log(), routerinfo_t::platform, tor_free, and tor_snprintf().

Referenced by authdir_wants_to_reject_router(), and tor_free_all().

void extrainfo_free ( extrainfo_t extrainfo  ) 

signed_descriptor_t* extrainfo_get_by_descriptor_digest ( const char *  digest  ) 

Return the signed descriptor for the extrainfo_t in our routerlist whose extra-info-digest is digest. Return NULL if no such extra-info document is known.

References extrainfo_t::cache_info, routerlist_t::extra_info_map, routerlist, and tor_assert.

Referenced by connection_dirserv_add_servers_to_outbuf(), dirserv_get_routerdesc_fingerprints(), dirserv_have_any_serverdesc(), and get_signed_descriptor_by_fp().

static int extrainfo_insert ( routerlist_t rl,
extrainfo_t ei 
) [static]

static cert_list_t* get_cert_list ( const char *  id_digest  )  [static]

Helper: Return the cert_list_t for an authority whose authority ID is id_digest, allocating a new list if necessary.

References cert_list_t::certs, digestmap_get(), digestmap_new(), digestmap_set(), cert_list_t::dl_status, download_status_t::schedule, and smartlist_create().

Referenced by already_have_cert(), authority_certs_fetch_missing(), and trusted_dirs_load_certs_from_string().

const char* get_dir_info_status_string ( void   ) 

Return a string describing what we're missing before we have enough directory info.

Referenced by directory_info_has_arrived().

int get_n_authorities ( authority_type_t  type  ) 

Return the number of directory authorities whose type matches some bit set in type

Referenced by any_trusted_dir_is_v1_authority(), dirvote_compute_consensuses(), fetch_bridge_descriptors(), getinfo_helper_events(), and networkstatus_check_consensus_signature().

static INLINE int hex_digest_matches ( const char *  hexdigest,
const char *  identity_digest,
const char *  nickname,
int  is_named 
) [static]

Helper: Return true iff the identity_digest and nickname combination of a router, encoded in hexadecimal, matches hexdigest (which is optionally prefixed with a single dollar sign). Return false if hexdigest is malformed, or it doesn't match.

References base16_decode(), DIGEST_LEN, HEX_DIGEST_LEN, and tor_assert.

Referenced by router_hex_digest_matches().

int hexdigest_to_digest ( const char *  hexdigest,
char *  digest 
)

If hexdigest is correctly formed, base16_decode it into digest, which must have DIGEST_LEN space in it. Return 0 on success, -1 on failure.

References base16_decode(), DIGEST_LEN, and HEX_DIGEST_LEN.

Referenced by circuit_is_acceptable(), connection_ap_fail_onehop(), and router_get_by_hexdigest().

int hid_serv_acting_as_directory ( void   ) 

int hid_serv_get_responsible_directories ( smartlist_t responsible_dirs,
const char *  id 
)

int hid_serv_responsible_for_desc_id ( const char *  query  ) 

static void initiate_descriptor_downloads ( routerstatus_t source,
int  purpose,
smartlist_t digests,
int  lo,
int  hi,
int  pds_flags 
) [static]

Launch downloads for all the descriptors whose digests are listed as digests[i] for lo <= i < hi. (Lo and hi may be out of range.) If source is given, download from source; otherwise, download from an appropriate random directory server.

References base16_encode(), DIGEST_LEN, directory_get_from_dirserver(), directory_initiate_command_routerstatus(), HEX_DIGEST_LEN, ROUTER_PURPOSE_GENERAL, and tor_free.

Referenced by launch_router_descriptor_downloads(), and update_extrainfo_downloads().

static INLINE int32_t kb_to_bytes ( uint32_t  bw  )  [static]

Return bw*1000, unless bw*1000 would overflow, in which case return INT32_MAX.

Referenced by smartlist_choose_by_bandwidth(), and smartlist_choose_by_bandwidth_weights().

static void launch_router_descriptor_downloads ( smartlist_t downloadable,
routerstatus_t source,
time_t  now 
) [static]

Given a list of router descriptor digests in downloadable, decide whether to delay fetching until we have more. If we don't want to delay, launch one or more requests to the appropriate directory authorities.

References authdir_mode_any_nonhidserv(), DIR_PURPOSE_FETCH_SERVERDESC, directory_fetches_dir_info_early(), get_options(), initiate_descriptor_downloads(), last_routerdesc_download_attempted, LD_DIR, MAX_CLIENT_INTERVAL_WITHOUT_REQUEST, MAX_DL_PER_REQUEST, MAX_DL_TO_DELAY, MIN_DL_PER_REQUEST, MIN_REQUESTS, PDS_NO_EXISTING_SERVERDESC_FETCH, PDS_RETRY_IF_NO_SERVERS, and smartlist_sort_digests().

static void list_pending_descriptor_downloads ( digestmap_t *  result,
int  extrainfo 
) [static]

For every router descriptor (or extra-info document if extrainfo is true) we are currently downloading by descriptor digest, set result[d] to (void*)1.

References DIR_PURPOSE_FETCH_EXTRAINFO, DIR_PURPOSE_FETCH_SERVERDESC, and list_pending_downloads().

Referenced by update_consensus_router_descriptor_downloads(), update_extrainfo_downloads(), and update_router_descriptor_cache_downloads_v2().

static void list_pending_downloads ( digestmap_t *  result,
int  purpose,
const char *  prefix 
) [static]

For every current directory connection whose purpose is purpose, and where the resource being downloaded begins with prefix, split rest of the resource into base16 fingerprints, decode them, and set the corresponding elements of result to a nonzero value.

References CONN_TYPE_DIR, dir_split_resource_into_fingerprints(), get_connection_array(), smartlist_create(), strcmpstart(), TO_DIR_CONN(), and tor_assert.

Referenced by authority_certs_fetch_missing(), and list_pending_descriptor_downloads().

static void mark_all_trusteddirservers_up ( void   )  [static]

Go through and mark the authoritative dirservers as up.

References routerlist, and routerlist_t::routers.

Referenced by router_pick_directory_server(), router_pick_trusteddirserver(), and router_reset_status_download_failures().

void refresh_all_country_info ( void   ) 

Called when we change a node set, or when we reload the geoip list: recompute all country info in all configuration node sets and in the routerlist.

References or_options_t::_ExcludeExitNodesUnion, or_options_t::EntryNodes, or_options_t::ExcludeExitNodes, or_options_t::ExcludeNodes, or_options_t::ExitNodes, get_options(), routerlist_refresh_countries(), and routerset_refresh_countries().

Referenced by geoip_load_file().

was_router_added_t router_add_extrainfo_to_routerlist ( extrainfo_t ei,
const char **  msg,
int  from_cache,
int  from_fetch 
)

Insert ei into the routerlist, or free it. Other arguments are as for router_add_to_routerlist(). Return ROUTER_ADDED_SUCCESSFULLY iff we actually inserted it, ROUTER_BAD_EI otherwise.

References extrainfo_t::cache_info, extrainfo_insert(), routerlist_t::extrainfo_store, router_get_routerlist(), routerlist, and signed_desc_append_to_journal().

Referenced by dirserv_add_extrainfo(), and router_load_extrainfo_from_string().

static void router_add_running_routers_to_smartlist ( smartlist_t sl,
int  allow_invalid,
int  need_uptime,
int  need_capacity,
int  need_guard 
) [static]

Add every suitable router from our routerlist to sl, so that we can pick a node for a circuit.

References router_is_unreliable(), ROUTER_PURPOSE_GENERAL, routerlist, routerlist_t::routers, and smartlist_add().

was_router_added_t router_add_to_routerlist ( routerinfo_t router,
const char **  msg,
int  from_cache,
int  from_fetch 
)

Add router to the routerlist, if we don't already have it. Replace older entries (if any) with the same key. Note: Callers should not hold their pointers to router if this function fails; router will either be inserted into the routerlist or freed. Similarly, even if this call succeeds, they should not hold their pointers to router after subsequent calls with other routerinfo's -- they might cause the original routerinfo to get freed.

Returns the status for the operation. Might set *msg if it wants the poster of the router to know something.

If from_cache, this descriptor came from our disk cache. If from_fetch, we received it in response to a request we made. (If both are false, that means it was uploaded to us as an auth dir server or via the controller.)

This function should be called *after* routers_update_status_from_consensus_networkstatus; subsequently, you should call router_rebuild_store and routerlist_descriptors_added.

References routerinfo_t::addr, authdir_mode_handles_descs(), authdir_wants_to_reject_router(), routerinfo_t::cache_info, routerlist_t::desc_digest_map, routerlist_t::desc_store, routerstatus_t::descriptor_digest, DIGEST_LEN, directory_set_dirty(), dirserv_single_reachability_test(), get_options(), hex_str(), signed_descriptor_t::identity_digest, routerlist_t::identity_map, routerinfo_t::is_valid, routerinfo_t::last_reachable, LD_DIR, routerstatus_t::need_to_mirror, networkstatus_get_latest_consensus(), networkstatus_get_v2_list(), networkstatus_v2_find_entry(), networkstatus_v2_list, networkstatus_vote_find_entry(), routerinfo_t::nickname, OLD_ROUTER_DESC_MAX_AGE, routerinfo_t::or_port, signed_descriptor_t::published_on, routerinfo_t::purpose, router_get_routerlist(), ROUTER_PURPOSE_GENERAL, routerinfo_free(), routerinfo_is_a_configured_bridge(), routerlist, routerlist_insert(), routerlist_insert_old(), routerlist_replace(), signed_desc_append_to_journal(), signed_desc_digest_is_recognized(), signed_descriptor_t::signed_descriptor_digest, routerinfo_t::testing_since, and tor_assert.

Referenced by dirserv_add_descriptor(), router_load_routers_from_string(), and router_load_single_router().

int router_addr_is_trusted_dir ( uint32_t  addr  ) 

Return true iff addr is the address of one of our trusted directory authorities.

References trusted_dir_servers.

Referenced by get_possible_sybil_list().

routerinfo_t* router_choose_random_node ( smartlist_t excludedsmartlist,
routerset_t excludedset,
router_crn_flags_t  flags 
)

Return a random running router from the routerlist. Never pick a node whose routerinfo is in excludedsmartlist, or whose routerinfo matches excludedset, even if they are the only nodes available. If CRN_NEED_UPTIME is set in flags and any router has more than a minimum uptime, return one of those. If CRN_NEED_CAPACITY is set in flags, weight your choice by the advertised capacity of each router. If CRN_ALLOW_INVALID is not set in flags, consider only Valid routers. If CRN_NEED_GUARD is set in flags, consider only Guard routers. If CRN_WEIGHT_AS_EXIT is set in flags, we weight bandwidths as if picking an exit node, otherwise we weight bandwidths for picking a relay node (that is, possibly discounting exit nodes).

References or_options_t::ExcludeSingleHopRelays, get_options(), router_get_routerlist(), routerlist_t::routers, smartlist_add(), smartlist_create(), and tor_assert.

Referenced by choose_good_exit_server(), and choose_good_middle_server().

int router_differences_are_cosmetic ( routerinfo_t r1,
routerinfo_t r2 
)

int router_digest_is_trusted_dir_type ( const char *  digest,
authority_type_t  type 
)

Return true iff digest is the digest of the identity key of a trusted directory matching at least one bit of type. If type is zero, any authority is okay.

References authdir_mode(), DIGEST_LEN, get_options(), router_digest_is_me(), and trusted_dir_servers.

Referenced by router_pick_directory_server_impl().

int router_digest_version_as_new_as ( const char *  digest,
const char *  cutoff 
)

Try to find a routerinfo for digest. If we don't have one, return 1. If we do, ask tor_version_as_new_as() for the answer.

References routerinfo_t::platform, router_get_by_digest(), and tor_version_as_new_as().

void router_dir_info_changed ( void   ) 

Called when our internal view of the directory has changed. This can be when the authorities change, networkstatuses change, the list of routerdescs changes, or number of running routers changes.

References rend_hsdir_routers_changed().

Referenced by add_trusted_dir_server(), clear_trusted_dir_servers(), networkstatus_set_current_consensus(), options_act(), router_set_status(), routerlist_free(), routerlist_insert(), routerlist_remove(), routerlist_replace(), and run_scheduled_events().

int router_exit_policy_all_routers_reject ( uint32_t  addr,
uint16_t  port,
int  need_uptime 
)

Return 1 if all running sufficiently-stable routers will reject addr:port, return 0 if any might accept it.

References ADDR_POLICY_PROBABLY_REJECTED, ADDR_POLICY_REJECTED, compare_addr_to_addr_policy(), router_is_unreliable(), routerlist, and routerlist_t::routers.

Referenced by circuit_get_open_circ_or_launch().

int router_exit_policy_rejects_all ( routerinfo_t router  ) 

Return true iff router does not permit exit streams.

References routerinfo_t::policy_is_reject_star.

Referenced by choose_good_exit_server_general(), and dirserv_compute_performance_thresholds().

routerinfo_t* router_find_exact_exit_enclave ( const char *  address,
uint16_t  port 
)

Find a router that's up, that has this IP address, and that allows exit to this address:port, or return NULL if there isn't a good one.

References ADDR_POLICY_ACCEPTED, compare_tor_addr_to_addr_policy(), routerlist, routerlist_t::routers, tor_addr_from_ipv4h, and tor_inet_aton().

uint32_t router_get_advertised_bandwidth ( routerinfo_t router  ) 

uint32_t router_get_advertised_bandwidth_capped ( routerinfo_t router  ) 

Return the smaller of the router's configured BandwidthRate and its advertised capacity, capped by max-believe-bw.

References routerinfo_t::bandwidthcapacity, routerinfo_t::bandwidthrate, and DEFAULT_MAX_BELIEVABLE_BANDWIDTH.

Referenced by routerstatus_format_entry(), smartlist_choose_by_bandwidth(), and smartlist_choose_by_bandwidth_weights().

signed_descriptor_t* router_get_by_descriptor_digest ( const char *  digest  ) 

routerinfo_t* router_get_by_digest ( const char *  digest  ) 

signed_descriptor_t* router_get_by_extrainfo_digest ( const char *  digest  ) 

Return the signed descriptor for the router in our routerlist whose 20-byte extra-info digest is digest. Return NULL if no such router is known.

References routerlist_t::desc_by_eid_map, routerlist, and tor_assert.

Referenced by dir_routerdesc_download_failed().

routerinfo_t* router_get_by_hexdigest ( const char *  hexdigest  ) 

Return the router in our routerlist whose hexadecimal key digest is hexdigest. Return NULL if no such router is known.

References DIGEST_LEN, HEX_DIGEST_LEN, hexdigest_to_digest(), routerinfo_t::is_named, routerinfo_t::nickname, router_get_by_digest(), routerlist, and tor_assert.

Referenced by getinfo_helper_dir(), and router_get_by_nickname().

routerinfo_t* router_get_by_nickname ( const char *  nickname,
int  warn_if_unnamed 
)

int router_get_my_share_of_directory_requests ( double *  v2_share_out,
double *  v3_share_out 
)

Try to determine which fraction of v2 and v3 directory requests aimed at caches will be sent to us. Set *v2_share_out and *v3_share_out to the fractions of v2 and v3 protocol shares we expect to see, respectively. Return 0 on success, negative on failure.

References routerinfo_t::cache_info, signed_descriptor_t::identity_digest, routerstatus_t::is_v2_dir, PDS_ALLOW_SELF, PDS_IGNORE_FASCISTFIREWALL, router_get_consensus_status_by_id(), router_get_my_routerinfo(), router_pick_directory_server(), sl_last_total_weighted_bw, V2_AUTHORITY, V3_AUTHORITY, and routerstatus_t::version_supports_v3_dir.

Referenced by geoip_determine_shares().

routerlist_t* router_get_routerlist ( void   ) 

smartlist_t* router_get_trusted_dir_servers ( void   ) 

trusted_dir_server_t* router_get_trusteddirserver_by_digest ( const char *  digest  ) 

Return the trusted_dir_server_t for the directory authority whose identity key hashes to digest, or NULL if no such authority is known.

References DIGEST_LEN, and trusted_dir_servers.

Referenced by connection_dir_client_reached_eof(), dir_networkstatus_download_failed(), init_keys(), router_set_networkstatus_v2(), and update_router_descriptor_cache_downloads_v2().

int router_have_minimum_dir_info ( void   ) 

Return true iff we have enough networkstatus and router information to start building circuits. Right now, this means "more than half the networkstatus documents, and at least 1/4 of expected routers."

References update_router_have_minimum_dir_info().

Referenced by add_nickname_list_to_smartlist(), circuit_get_open_circ_or_launch(), circuit_launch_by_extend_info(), directory_info_has_arrived(), getinfo_helper_events(), run_scheduled_events(), and update_extrainfo_downloads().

static INLINE int router_hex_digest_matches ( routerinfo_t router,
const char *  hexdigest 
) [static]

Return true iff the digest of router's identity key, encoded in hexadecimal, matches hexdigest (which is optionally prefixed with a single dollar sign). Return false if hexdigest is malformed, or it doesn't match.

References routerinfo_t::cache_info, hex_digest_matches(), signed_descriptor_t::identity_digest, routerinfo_t::is_named, and routerinfo_t::nickname.

Referenced by router_nickname_matches().

static INLINE int router_in_nickname_smartlist ( smartlist_t lst,
routerinfo_t r 
) [static]

Return true iff r is named by some nickname in lst.

References router_nickname_matches().

Referenced by routers_in_same_family().

int router_is_unreliable ( routerinfo_t router,
int  need_uptime,
int  need_capacity,
int  need_guard 
)

Return 1 if router is not suitable for these parameters, else 0. If need_uptime is non-zero, we require a minimum uptime. If need_capacity is non-zero, we require a minimum advertised bandwidth. If need_guard, we require that the router is a possible entry guard.

References routerinfo_t::is_fast, routerinfo_t::is_possible_guard, and routerinfo_t::is_stable.

Referenced by choose_good_exit_server_general(), entry_is_live(), router_add_running_routers_to_smartlist(), and router_exit_policy_all_routers_reject().

void router_load_extrainfo_from_string ( const char *  s,
const char *  eos,
saved_location_t  saved_location,
smartlist_t requested_fingerprints,
int  descriptor_digests 
)

int router_load_routers_from_string ( const char *  s,
const char *  eos,
saved_location_t  saved_location,
smartlist_t requested_fingerprints,
int  descriptor_digests,
const char *  prepend_annotations 
)

Given a string s containing some routerdescs, parse it and put the routers into our directory. If saved_location is SAVED_NOWHERE, the routers are in response to a query to the network: cache them by adding them to the journal.

Return the number of routers actually added.

If requested_fingerprints is provided, it must contain a list of uppercased fingerprints. Do not update any router whose fingerprint is not on the list; after updating a router, remove its fingerprint from the list.

If descriptor_digests is non-zero, then the requested_fingerprints are descriptor digests. Otherwise they are identity digests.

References base16_encode(), routerlist_t::desc_store, DIGEST_LEN, download_status_mark_impossible(), HEX_DIGEST_LEN, hex_str(), LD_DIR, LD_GENERAL, router_add_to_routerlist(), router_get_dl_status_by_descriptor_digest(), router_parse_list_from_string(), router_rebuild_store(), routerinfo_free(), routerlist, routerlist_assert_ok(), routerlist_descriptors_added(), routers_update_status_from_consensus_networkstatus(), SAVED_NOWHERE, smartlist_add(), smartlist_clear(), smartlist_create(), smartlist_free(), smartlist_join_strings(), smartlist_string_isin(), smartlist_string_remove(), tor_free, WRA_WAS_ADDED(), and WRA_WAS_REJECTED().

Referenced by load_downloaded_routers(), and router_reload_router_list_impl().

int router_load_single_router ( const char *  s,
uint8_t  purpose,
int  cache,
const char **  msg 
)

Code to parse a single router descriptor and insert it into the routerlist. Return -1 if the descriptor was ill-formed; 0 if the descriptor was well-formed but could not be added; and 1 if the descriptor was added.

If we don't add it and msg is not NULL, then assign to *msg a static string describing the reason for refusing the descriptor.

This is used only by the controller.

References routerinfo_t::cache_info, signed_descriptor_t::do_not_cache, LD_DIR, routerinfo_t::purpose, router_add_to_routerlist(), ROUTER_ANNOTATION_BUF_LEN, router_is_me(), router_parse_entry_from_string(), router_purpose_to_string(), routerinfo_free(), routerlist_descriptors_added(), routers_update_status_from_consensus_networkstatus(), smartlist_add(), smartlist_create(), smartlist_free(), tor_assert, tor_snprintf(), and WRA_WAS_ADDED().

Referenced by handle_control_postdescriptor().

int router_nickname_is_in_list ( routerinfo_t router,
const char *  list 
)

Return 1 iff any member of the (possibly NULL) comma-separated list list is an acceptable nickname or hexdigest for router. Else return 0.

References router_nickname_matches(), smartlist_create(), smartlist_free(), smartlist_split_string(), tor_assert, and tor_free.

Referenced by routers_in_same_family().

static int router_nickname_matches ( routerinfo_t router,
const char *  nickname 
) [static]

Return true if router's nickname matches nickname (case-insensitive), or if router's identity key digest matches a hexadecimal value stored in nickname. Return false otherwise.

References routerinfo_t::nickname, and router_hex_digest_matches().

Referenced by router_in_nickname_smartlist(), router_nickname_is_in_list(), and routerlist_add_family().

routerstatus_t* router_pick_directory_server ( authority_type_t  type,
int  flags 
)

Try to find a running dirserver that supports operations of type.

If there are no running dirservers in our routerlist and the PDS_RETRY_IF_NO_SERVERS flag is set, set all the authoritative ones as running again, and pick one.

If the PDS_IGNORE_FASCISTFIREWALL flag is set, then include dirservers that we can't reach.

If the PDS_ALLOW_SELF flag is not set, then don't include ourself (if we're a dirserver).

Don't pick an authority if any non-authority is viable; try to avoid using servers that have returned 503 recently.

References get_options(), LD_DIR, mark_all_trusteddirservers_up(), PDS_RETRY_IF_NO_SERVERS, router_pick_directory_server_impl(), and routerlist.

Referenced by directory_get_from_dirserver(), and router_get_my_share_of_directory_requests().

static routerstatus_t * router_pick_directory_server_impl ( authority_type_t  type,
int  flags 
) [static]

Pick a random running valid directory server/mirror from our routerlist. Arguments are as for router_pick_directory_server(), except that RETRY_IF_NO_SERVERS is ignored, and:

If the _PDS_PREFER_TUNNELED_DIR_CONNS flag is set, prefer directory servers that we can use with BEGINDIR.

References tor_addr_t::addr, DIR_503_TIMEOUT, EXTRAINFO_CACHE, fascist_firewall_allows_address_dir(), fascist_firewall_allows_address_or(), networkstatus_get_latest_consensus(), PDS_ALLOW_SELF, PDS_IGNORE_FASCISTFIREWALL, router_digest_is_me(), router_digest_is_trusted_dir_type(), router_supports_extrainfo(), networkstatus_t::routerstatus_list, routerstatus_sl_choose_by_bandwidth(), smartlist_add(), smartlist_choose(), smartlist_create(), smartlist_free(), tor_addr_from_ipv4h, V2_AUTHORITY, and V3_AUTHORITY.

Referenced by router_pick_directory_server().

routerstatus_t* router_pick_trusteddirserver ( authority_type_t  type,
int  flags 
)

Try to find a running trusted dirserver. Flags are as for router_pick_directory_server.

References get_options(), LD_DIR, mark_all_trusteddirservers_up(), PDS_NO_EXISTING_SERVERDESC_FETCH, PDS_RETRY_IF_NO_SERVERS, router_pick_trusteddirserver_impl(), and tor_assert.

Referenced by directory_get_from_dirserver().

static routerstatus_t * router_pick_trusteddirserver_impl ( authority_type_t  type,
int  flags,
int *  n_busy_out 
) [static]

static int router_rebuild_store ( int  flags,
desc_store_t store 
) [static]

int router_reload_router_list ( void   ) 

Load all cached router descriptors and extra-info documents from the store. Return 0 on success and -1 on failure.

References routerlist_t::desc_store, routerlist_t::extrainfo_store, router_get_routerlist(), and router_reload_router_list_impl().

Referenced by do_main_loop().

static int router_reload_router_list_impl ( desc_store_t store  )  [static]

void router_reset_descriptor_download_failures ( void   ) 

Reset the descriptor download failure count on all routers, so that we can retry any long-failed routers immediately.

References download_status_reset(), last_routerdesc_download_attempted, networkstatus_reset_download_failures(), routerlist, and routerlist_t::routers.

Referenced by do_hup(), routerlist_retry_directory_downloads(), and run_scheduled_events().

void router_reset_status_download_failures ( void   ) 

Reset all internal variables used to count failed downloads of network status objects.

References mark_all_trusteddirservers_up().

Referenced by do_hup(), and routerlist_retry_directory_downloads().

void router_set_status ( const char *  digest,
int  up 
)

static int router_should_rebuild_store ( desc_store_t store  )  [static]

Helper: return 1 iff the router log is so big we want to rebuild the store.

References desc_store_t::bytes_dropped, desc_store_t::journal_len, and desc_store_t::store_len.

Referenced by router_rebuild_store().

void routerinfo_free ( routerinfo_t router  ) 

int routerinfo_incompatible_with_extrainfo ( routerinfo_t ri,
extrainfo_t ei,
signed_descriptor_t sd,
const char **  msg 
)

Check whether ri (a.k.a. sd) is a router compatible with the extrainfo document ei. If no router is compatible with ei, ei should be dropped. Return 0 for "compatible", return 1 for "reject, and inform whoever uploaded ei, and return -1 for "reject silently.". If msg is present, set *msg to a description of the incompatibility (if any).

References extrainfo_t::bad_sig, extrainfo_t::cache_info, routerinfo_t::cache_info, crypto_pk_public_checksig(), DIGEST_LEN, signed_descriptor_t::extra_info_digest, signed_descriptor_t::extrainfo_is_bogus, signed_descriptor_t::identity_digest, routerinfo_t::identity_pkey, extrainfo_t::pending_sig, extrainfo_t::pending_sig_len, signed_descriptor_t::published_on, signed_descriptor_t::send_unencrypted, signed_descriptor_t::signed_descriptor_digest, tor_assert, and tor_free.

Referenced by dirserv_add_extrainfo(), extrainfo_insert(), and router_rebuild_descriptor().

void routerinfo_set_country ( routerinfo_t ri  ) 

Refresh the country code of ri. This function MUST be called on each router when the GeoIP database is reloaded, and on all new routers.

References routerinfo_t::addr, routerinfo_t::country, and geoip_get_country_by_ip().

Referenced by router_parse_entry_from_string(), router_rebuild_descriptor(), and routerlist_refresh_countries().

void routerlist_add_family ( smartlist_t sl,
routerinfo_t router 
)

Add all the family of router to the smartlist sl. This is used to make sure we don't pick siblings in a single path, or pick more than one relay from a family for our entry guard list.

References routerinfo_t::declared_family, or_options_t::EnforceDistinctSubnets, get_options(), router_get_by_nickname(), router_nickname_matches(), routerlist_add_network_family(), and smartlist_add().

Referenced by choose_good_entry_server(), choose_good_middle_server(), and choose_random_entry().

static void routerlist_add_network_family ( smartlist_t sl,
routerinfo_t router 
) [static]

Look through the routerlist and identify routers that advertise the same /16 network address as router. Add each of them to sl.

References routerlist, routerlist_t::routers, routers_in_same_network_family(), and smartlist_add().

Referenced by routerlist_add_family().

void routerlist_assert_ok ( routerlist_t rl  ) 

static void routerlist_descriptors_added ( smartlist_t sl,
int  from_cache 
) [static]

We just added a new set of descriptors. Take whatever extra steps we need.

References control_event_descriptors_changed(), learned_bridge_descriptor(), ROUTER_PURPOSE_BRIDGE, and tor_assert.

Referenced by router_load_routers_from_string(), and router_load_single_router().

routerinfo_t* routerlist_find_my_routerinfo ( void   ) 

Look through the routerlist until we find a router that has my key. Return it.

References router_is_me(), routerlist, and routerlist_t::routers.

void routerlist_free ( routerlist_t rl  ) 

void routerlist_free_all ( void   ) 

static void routerlist_insert ( routerlist_t rl,
routerinfo_t ri 
) [static]

static void routerlist_insert_old ( routerlist_t rl,
routerinfo_t ri 
) [static]

void routerlist_refresh_countries ( void   ) 

Set the country code of all routers in the routerlist.

References router_get_routerlist(), routerinfo_set_country(), and routerlist_t::routers.

Referenced by refresh_all_country_info().

void routerlist_remove ( routerlist_t rl,
routerinfo_t ri,
int  make_old,
time_t  now 
)

static void routerlist_remove_old ( routerlist_t rl,
signed_descriptor_t sd,
int  idx 
) [static]

static void routerlist_remove_old_cached_routers_with_id ( time_t  now,
time_t  cutoff,
int  lo,
int  hi,
digestset_t retain 
) [static]

The range lo through hi inclusive of routerlist->old_routers must contain routerinfo_t with the same identity and with publication time in ascending order. Remove members from this range until there are no more than max_descriptors_per_router() remaining. Start by removing the oldest members from before cutoff, then remove members which were current for the lowest amount of time. The order of members of old_routers at indices lo or higher may be changed.

We aren't removing enough servers for being old. Sort lifespans by the duration of liveness, and remove the ones we're not already going to remove based on how long they were alive.

References _compare_duration_idx(), DIGEST_LEN, directory_caches_dir_info(), duration_idx_t::duration, get_options(), signed_descriptor_t::identity_digest, duration_idx_t::idx, signed_descriptor_t::last_listed_as_valid_until, duration_idx_t::old, routerlist_t::old_routers, signed_descriptor_t::published_on, routerlist, routerlist_remove_old(), signed_descriptor_t::signed_descriptor_digest, tor_assert, and tor_free.

Referenced by routerlist_remove_old_routers().

void routerlist_remove_old_routers ( void   ) 

static routerinfo_t* routerlist_reparse_old ( routerlist_t rl,
signed_descriptor_t sd 
) [static]

static void routerlist_replace ( routerlist_t rl,
routerinfo_t ri_old,
routerinfo_t ri_new 
) [static]

void routerlist_reset_warnings ( void   ) 

Forget that we have issued any router-related warnings, so that we'll warn again if we see the same errors.

References networkstatus_reset_warnings(), smartlist_clear(), smartlist_create(), tor_free, and warned_nicknames.

Referenced by do_hup().

void routerlist_retry_directory_downloads ( time_t  now  ) 

Clear all our timeouts for fetching v2 and v3 directory stuff, and then give it all a try again.

References router_reset_descriptor_download_failures(), router_reset_status_download_failures(), update_networkstatus_downloads(), and update_router_descriptor_downloads().

Referenced by circuit_get_open_circ_or_launch(), and learned_bridge_descriptor().

routerinfo_t* routerlist_sl_choose_by_bandwidth ( smartlist_t sl,
bandwidth_weight_rule_t  rule 
)

Choose a random element of router list sl, weighted by the advertised bandwidth of each router.

References smartlist_choose_by_bandwidth(), and smartlist_choose_by_bandwidth_weights().

Referenced by choose_good_exit_server_general(), and choose_random_entry().

int routers_in_same_family ( routerinfo_t r1,
routerinfo_t r2 
)

static INLINE int routers_in_same_network_family ( routerinfo_t r1,
routerinfo_t r2 
) [static]

Return true iff router1 and router2 have the same /16 network.

References routerinfo_t::addr.

Referenced by routerlist_add_network_family(), and routers_in_same_family().

void routers_sort_by_identity ( smartlist_t routers  ) 

Sort a list of routerinfo_t in ascending order of identity digest.

References _compare_routerinfo_by_id_digest(), and smartlist_sort().

Referenced by routers_update_status_from_consensus_networkstatus().

static int routerset_contains ( const routerset_t set,
const tor_addr_t addr,
uint16_t  orport,
const char *  nickname,
const char *  id_digest,
int  is_named,
country_t  country 
) [static]

Helper. Return true iff set contains a router based on the other provided fields. Return higher values for more specific subentries: a single router is more specific than an address range of routers, which is more specific in turn than a country code.

(If country is -1, then we take the country from addr.)

References ADDR_POLICY_REJECTED, compare_tor_addr_to_addr_policy(), digestmap_get(), geoip_get_country_by_ip(), strmap_get_lc(), and tor_addr_to_ipv4h().

Referenced by routerset_contains_extendinfo(), routerset_contains_router(), and routerset_contains_routerstatus().

int routerset_contains_extendinfo ( const routerset_t set,
const extend_info_t ei 
)

int routerset_contains_router ( const routerset_t set,
routerinfo_t ri 
)

int routerset_contains_routerstatus ( const routerset_t set,
routerstatus_t rs 
)

int routerset_equal ( const routerset_t old,
const routerset_t new 
)

Helper: return true iff old and new are both NULL, or both non-NULL equal routersets.

References routerset_t::list.

Referenced by options_act().

void routerset_free ( routerset_t routerset  ) 

void routerset_get_all_routers ( smartlist_t out,
const routerset_t routerset,
int  running_only 
)

Add every known routerinfo_t that is a member of routerset to out. If running_only, only add the running ones.

References routerset_t::list, router_get_by_nickname(), routerset_is_list(), smartlist_add(), smartlist_create(), tor_assert, and warned_nicknames.

Referenced by entry_guards_prepend_from_config().

static char* routerset_get_countryname ( const char *  c  )  [static]

If c is a country code in the form {cc}, return a newly allocated string holding the "cc" part. Else, return NULL.

References tor_strlower().

Referenced by routerset_parse().

static int routerset_is_empty ( const routerset_t set  )  [static]

Return true iff there are no entries in set.

Referenced by routersets_get_disjunction().

int routerset_is_list ( const routerset_t set  ) 

Return true iff set lists only nicknames and digests, and includes no IP ranges or countries.

Referenced by options_validate(), and routerset_get_all_routers().

int routerset_needs_geoip ( const routerset_t set  ) 

Return true iff we need a GeoIP IP-to-country database to make sense of set.

Referenced by options_need_geoip_info().

routerset_t* routerset_new ( void   ) 

int routerset_parse ( routerset_t target,
const char *  s,
const char *  description 
)

Parse the string s to create a set of routerset entries, and add them to target. In log messages, refer to the string as description. Return 0 on success, -1 on failure.

Three kinds of elements are allowed in routersets: nicknames, IP address patterns, and fingerprints. They may be surrounded by optional space, and must be separated by commas.

References base16_decode(), routerset_t::country_names, DIGEST_LEN, digestmap_set(), routerset_t::digests, HEX_DIGEST_LEN, is_legal_hexdigest(), is_legal_nickname(), LD_CONFIG, routerset_t::list, routerset_t::names, routerset_t::policies, router_parse_addr_policy_item_from_string(), routerset_get_countryname(), routerset_refresh_countries(), smartlist_add(), smartlist_add_all(), smartlist_create(), smartlist_free(), smartlist_split_string(), strmap_set_lc(), and tor_free.

Referenced by config_assign_value(), and routerset_union().

void routerset_refresh_countries ( routerset_t target  ) 

Update the routerset's countries bitarray_t. Called whenever the GeoIP database is reloaded.

References routerset_t::countries, routerset_t::country_names, geoip_get_country(), geoip_get_n_countries(), geoip_is_loaded(), LD_CONFIG, routerset_t::n_countries, and tor_assert.

Referenced by refresh_all_country_info(), and routerset_parse().

void routerset_subtract_routers ( smartlist_t lst,
const routerset_t routerset 
)

Remove every routerinfo_t from lst that is in routerset.

References routerset_contains_router(), and tor_assert.

char* routerset_to_string ( const routerset_t set  ) 

Return a new string that when parsed by routerset_parse_string() will yield set.

References smartlist_join_strings().

Referenced by entry_guards_prepend_from_config(), get_assigned_option(), and routerset_union().

void routerset_union ( routerset_t target,
const routerset_t source 
)

Add all members of the set source to target.

References routerset_t::list, routerset_parse(), routerset_to_string(), tor_assert, and tor_free.

Referenced by options_validate().

void routersets_get_disjunction ( smartlist_t target,
const smartlist_t source,
const routerset_t include,
const routerset_t exclude,
int  running_only 
)

Add to target every routerinfo_t from source except:

1) Don't add it if include is non-empty and the relay isn't in include; and 2) Don't add it if exclude is non-empty and the relay is excluded in a more specific fashion by exclude. 3) If running_only, don't add non-running routers.

References routerset_contains_router(), routerset_is_empty(), and smartlist_add().

Referenced by choose_good_exit_server_general().

routerstatus_t* routerstatus_sl_choose_by_bandwidth ( smartlist_t sl,
bandwidth_weight_rule_t  rule 
)

Choose a random element of status list sl, weighted by the advertised bandwidth of each status.

References smartlist_choose_by_bandwidth(), and smartlist_choose_by_bandwidth_weights().

Referenced by router_pick_directory_server_impl().

static int signed_desc_append_to_journal ( signed_descriptor_t desc,
desc_store_t store 
) [static]

static int signed_desc_digest_is_recognized ( signed_descriptor_t desc  )  [static]

static void signed_descriptor_free ( signed_descriptor_t sd  )  [static]

Release storage held by sd.

References signed_descriptor_t::signed_descriptor_body, and tor_free.

Referenced by routerlist_free(), and routerlist_remove_old().

static signed_descriptor_t* signed_descriptor_from_routerinfo ( routerinfo_t ri  )  [static]

const char* signed_descriptor_get_annotations ( signed_descriptor_t desc  ) 

As signed_descriptor_get_body(), but points to the beginning of the annotations section rather than the beginning of the descriptor.

References signed_descriptor_get_body_impl().

Referenced by routerlist_reparse_old().

const char* signed_descriptor_get_body ( signed_descriptor_t desc  ) 

Return a pointer to the signed textual representation of a descriptor. The returned string is not guaranteed to be NUL-terminated: the string's length will be in desc->signed_descriptor_len.

The caller must not free the string returned.

References signed_descriptor_get_body_impl().

Referenced by connection_dirserv_add_servers_to_outbuf(), getinfo_helper_dir(), munge_extrainfo_into_routerinfo(), router_get_my_descriptor(), and router_rebuild_store().

static const char * signed_descriptor_get_body_impl ( signed_descriptor_t desc,
int  with_annotations 
) [static]

Return a pointer to the signed textual representation of a descriptor. The returned string is not guaranteed to be NUL-terminated: the string's length will be in desc->signed_descriptor_len.

If with_annotations is set, the returned string will include the annotations (if any) preceding the descriptor. This will increase the length of the string by desc->annotations_len.

The caller must not free the string returned.

References signed_descriptor_t::annotations_len, tor_mmap_t::data, desc_get_store(), escaped(), LD_DIR, desc_store_t::mmap, router_get_routerlist(), routerlist, SAVED_IN_CACHE, signed_descriptor_t::saved_location, signed_descriptor_t::saved_offset, signed_descriptor_t::signed_descriptor_body, signed_descriptor_t::signed_descriptor_len, and tor_assert.

Referenced by router_rebuild_store(), signed_desc_append_to_journal(), signed_descriptor_get_annotations(), and signed_descriptor_get_body().

static void* smartlist_choose_by_bandwidth ( smartlist_t sl,
bandwidth_weight_rule_t  rule,
int  statuses 
) [static]

Helper function: choose a random element of smartlist sl, weighted by the advertised bandwidth of each element.

If statuses is zero, then sl is a list of routerinfo_t's. Otherwise it's a list of routerstatus_t's.

If rule==WEIGHT_FOR_EXIT. we're picking an exit node: consider all nodes' bandwidth equally regardless of their Exit status, since there may be some in the list because they exit to obscure ports. If rule==NO_WEIGHTING, we're picking a non-exit node: weight exit-node's bandwidth less depending on the smallness of the fraction of Exit-to-total bandwidth. If rule==WEIGHT_FOR_GUARD, we're picking a guard node: consider all guard's bandwidth equally. Otherwise, weight guards proportionally less.

References routerstatus_t::bandwidth, bandwidth_weight_rule_to_string(), routerinfo_t::cache_info, crypto_rand_uint64(), routerstatus_t::has_bandwidth, signed_descriptor_t::identity_digest, routerstatus_t::identity_digest, routerinfo_t::is_exit, routerstatus_t::is_exit, routerinfo_t::is_fast, routerstatus_t::is_fast, routerinfo_t::is_possible_guard, routerstatus_t::is_possible_guard, kb_to_bytes(), LD_BUG, LD_CIRC, router_digest_is_me(), router_get_advertised_bandwidth_capped(), router_get_by_digest(), router_get_consensus_status_by_id(), sl_last_total_weighted_bw, smartlist_choose(), tor_assert, tor_fragile_assert, and tor_free.

Referenced by routerlist_sl_choose_by_bandwidth(), and routerstatus_sl_choose_by_bandwidth().

static void* smartlist_choose_by_bandwidth_weights ( smartlist_t sl,
bandwidth_weight_rule_t  rule,
int  statuses 
) [static]

Helper function: choose a random element of smartlist sl, weighted by the advertised bandwidth of each element using the consensus bandwidth weights.

If statuses is zero, then sl is a list of routerinfo_t's. Otherwise it's a list of routerstatus_t's.

If rule==WEIGHT_FOR_EXIT. we're picking an exit node: consider all nodes' bandwidth equally regardless of their Exit status, since there may be some in the list because they exit to obscure ports. If rule==NO_WEIGHTING, we're picking a non-exit node: weight exit-node's bandwidth less depending on the smallness of the fraction of Exit-to-total bandwidth. If rule==WEIGHT_FOR_GUARD, we're picking a guard node: consider all guard's bandwidth equally. Otherwise, weight guards proportionally less.

References routerstatus_t::bandwidth, bandwidth_weight_rule_to_string(), BW_WEIGHT_SCALE, routerinfo_t::cache_info, crypto_rand_uint64(), routerinfo_t::dir_port, routerstatus_t::dir_port, routerstatus_t::has_bandwidth, signed_descriptor_t::identity_digest, routerinfo_t::is_exit, routerstatus_t::is_exit, routerinfo_t::is_possible_guard, routerstatus_t::is_possible_guard, kb_to_bytes(), LD_BUG, LD_CIRC, networkstatus_get_bw_weight(), networkstatus_get_param(), router_get_advertised_bandwidth_capped(), router_get_consensus_status_by_id(), smartlist_choose(), tor_assert, tor_fragile_assert, and tor_free.

Referenced by routerlist_sl_choose_by_bandwidth(), and routerstatus_sl_choose_by_bandwidth().

static void trusted_dir_server_free ( trusted_dir_server_t ds  )  [static]

void trusted_dirs_flush_certs_to_disk ( void   ) 

Save all v3 key certificates to the cached-certs file.

References smartlist_add(), smartlist_create(), trusted_dir_certs, and trusted_dir_servers_certs_changed.

Referenced by trusted_dirs_load_certs_from_string(), and trusted_dirs_remove_old_certs().

int trusted_dirs_load_certs_from_string ( const char *  contents,
int  from_store,
int  flush 
)

int trusted_dirs_reload_certs ( void   ) 

Reload the cached v3 key certificates from the cached-certs file in the data directory. Return 0 on success, -1 on failure.

References get_datadir_fname, read_file_to_str(), RFTS_IGNORE_MISSING, tor_free, and trusted_dirs_load_certs_from_string().

Referenced by do_main_loop().

static void trusted_dirs_remove_old_certs ( void   )  [static]

Remove all v3 authority certificates that have been superseded for more than 48 hours. (If the most recent cert was published more than 48 hours ago, then we aren't going to get any consensuses signed with older keys.)

References authority_cert_free(), authority_cert_t::cache_info, ftime_definitely_after(), signed_descriptor_t::published_on, trusted_dir_certs, trusted_dir_servers_certs_changed, and trusted_dirs_flush_certs_to_disk().

Referenced by routerlist_remove_old_routers().

trusted_dir_server_t* trusteddirserver_get_by_v3_auth_digest ( const char *  digest  ) 

Return the trusted_dir_server_t for the directory authority whose v3 identity key hashes to digest, or NULL if no such authority is known.

References DIGEST_LEN, trusted_dir_servers, and V3_AUTHORITY.

Referenced by authority_certs_fetch_missing(), dirvote_add_vote(), networkstatus_check_consensus_signature(), trusted_dirs_load_certs_from_string(), and update_consensus_router_descriptor_downloads().

void update_consensus_router_descriptor_downloads ( time_t  now,
int  is_vote,
networkstatus_t consensus 
)

void update_extrainfo_downloads ( time_t  now  ) 

static void update_router_descriptor_cache_downloads_v2 ( time_t  now  )  [static]

Launch downloads for router status as needed, using the strategy used by authorities and caches: based on the v2 networkstatuses we have, download every descriptor we don't have but would serve, from a random authority that lists it.

References authdir_mode(), digestmap_get(), digestmap_new(), directory_fetches_dir_info_early(), dirserv_would_reject_router(), get_options(), trusted_dir_server_t::is_running, LD_BUG, list_pending_descriptor_downloads(), MAX_NETWORKSTATUS_AGE, networkstatus_get_v2_list(), networkstatus_v2_list, router_get_by_descriptor_digest(), router_get_trusteddirserver_by_digest(), and smartlist_create().

Referenced by update_router_descriptor_downloads().

void update_router_descriptor_downloads ( time_t  now  ) 

static void update_router_have_minimum_dir_info ( void   )  [static]


Variable Documentation

char dir_info_status[128] = "" [static]

String describing what we're missing before we have enough directory info.

Referenced by update_router_have_minimum_dir_info().

int have_min_dir_info = 0 [static]

True iff, the last time we checked whether we had enough directory info to build circuits, the answer was "yes".

Referenced by update_router_have_minimum_dir_info().

The last time we tried to download any routerdesc, or 0 for "never". We use this to rate-limit download attempts when the number of routerdescs to download is low.

Referenced by launch_router_descriptor_downloads(), router_reset_descriptor_download_failures(), and update_router_descriptor_downloads().

True iff enough has changed since the last time we checked whether we had enough directory info to build circuits that our old answer can no longer be trusted.

Referenced by update_router_have_minimum_dir_info().

routerlist_t* routerlist = NULL [static]

uint64_t sl_last_total_weighted_bw = 0 [static]

When we last computed the weights to use for bandwidths on directory requests, what were the total weighted bandwidth, and our share of that bandwidth? Used to determine what fraction of directory requests we should expect to see.

Referenced by router_get_my_share_of_directory_requests(), and smartlist_choose_by_bandwidth().

digestmap_t* trusted_dir_certs = NULL [static]

smartlist_t* trusted_dir_servers = NULL [static]

True iff any key certificate in at least one member of trusted_dir_certs has changed since we last flushed the certificates to disk.

Referenced by trusted_dirs_flush_certs_to_disk(), trusted_dirs_load_certs_from_string(), and trusted_dirs_remove_old_certs().

smartlist_t* warned_nicknames = NULL [static]

List of strings for nicknames we've already warned about and that are still unknown / unavailable.

Referenced by add_nickname_list_to_smartlist(), routerlist_free_all(), routerlist_reset_warnings(), and routerset_get_all_routers().


Generated on Tue May 25 00:30:50 2010 for tor by  doxygen 1.5.6