Tor  0.4.7.0-alpha-dev
Data Structures | Macros | Functions | Variables
routerlist.c File Reference

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

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
#include "core/or/extendinfo.h"
#include "core/or/policies.h"
#include "feature/client/bridges.h"
#include "feature/control/control_events.h"
#include "feature/dirauth/authmode.h"
#include "feature/dirauth/process_descs.h"
#include "feature/dirauth/reachability.h"
#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dirclient_modes.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/dircommon/directory.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/describe.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/node_select.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/dirparse/routerparse.h"
#include "feature/nodelist/routerset.h"
#include "feature/nodelist/torcert.h"
#include "feature/relay/routermode.h"
#include "feature/relay/relay_find_addr.h"
#include "feature/stats/rephist.h"
#include "lib/crypt_ops/crypto_format.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "feature/dircommon/dir_connection_st.h"
#include "feature/dirclient/dir_server_st.h"
#include "feature/nodelist/document_signature_st.h"
#include "feature/nodelist/extrainfo_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "feature/nodelist/networkstatus_voter_info_st.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist_st.h"
#include "feature/nodelist/vote_routerstatus_st.h"
#include "lib/crypt_ops/digestset.h"

Go to the source code of this file.

Data Structures

struct  duration_idx_t
 

Macros

#define ROUTERLIST_PRIVATE
 
#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 eimap_free(map, fn)   MAP_FREE_AND_NULL(eimap, (map), (fn))
 
#define rimap_free(map, fn)   MAP_FREE_AND_NULL(rimap, (map), (fn))
 
#define sdmap_free(map, fn)   MAP_FREE_AND_NULL(sdmap, (map), (fn))
 
#define RRS_FORCE   1
 
#define RRS_DONT_REMOVE_OLD   2
 
#define DEFAULT_MAX_BELIEVABLE_BANDWIDTH   10000000 /* 10 MB/sec */
 
#define signed_descriptor_free(val)    FREE_AND_NULL(signed_descriptor_t, signed_descriptor_free_, (val))
 
#define should_cache_old_descriptors()    directory_caches_dir_info(get_options())
 
#define MIN_DL_PER_REQUEST   32
 
#define MIN_REQUESTS   3
 
#define MAX_DL_TO_DELAY   16
 
#define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE   (2*60*60)
 
#define ROUTER_ALLOW_UPTIME_DRIFT   (6*60*60)
 

Functions

static int signed_desc_digest_is_recognized (signed_descriptor_t *desc)
 
static const char * signed_descriptor_get_body_impl (const signed_descriptor_t *desc, int with_annotations)
 
static int router_should_rebuild_store (desc_store_t *store)
 
static desc_store_tdesc_get_store (routerlist_t *rl, const 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)
 
int router_or_conn_should_skip_reachable_address_check (const or_options_t *options, int try_ip_pref)
 
int router_dir_conn_should_skip_reachable_address_check (const or_options_t *options, int try_ip_pref)
 
int routers_have_same_or_addrs (const routerinfo_t *r1, const routerinfo_t *r2)
 
bool router_can_choose_node (const node_t *node, int flags)
 
void router_add_running_nodes_to_smartlist (smartlist_t *sl, int flags)
 
const routerinfo_trouterlist_find_my_routerinfo (void)
 
uint32_t router_get_advertised_bandwidth (const routerinfo_t *router)
 
uint32_t router_get_advertised_bandwidth_capped (const routerinfo_t *router)
 
int hex_digest_nickname_decode (const char *hexdigest, char *digest_out, char *nickname_qualifier_char_out, char *nickname_out)
 
int hex_digest_nickname_matches (const char *hexdigest, const char *identity_digest, const char *nickname)
 
int hexdigest_to_digest (const char *hexdigest, char *digest)
 
routerinfo_trouter_get_mutable_by_digest (const char *digest)
 
const routerinfo_trouter_get_by_id_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 (const signed_descriptor_t *desc)
 
const char * signed_descriptor_get_annotations (const 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 void signed_descriptor_reset (signed_descriptor_t *sd)
 
static void signed_descriptor_move (signed_descriptor_t *dest, signed_descriptor_t *src)
 
static signed_descriptor_tsigned_descriptor_from_routerinfo (routerinfo_t *ri)
 
static void extrainfo_free_void (void *e)
 
void routerlist_free_ (routerlist_t *rl)
 
void dump_routerlist_mem_usage (int severity)
 
static int routerlist_find_elt_ (smartlist_t *sl, void *ri, int idx)
 
static void routerlist_insert (routerlist_t *rl, routerinfo_t *ri)
 
STATIC was_router_added_t extrainfo_insert (routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible)
 
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)
 
int router_descriptor_is_older_than (const routerinfo_t *router, int seconds)
 
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)
 
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 update_all_descriptor_downloads (time_t now)
 
void routerlist_retry_directory_downloads (time_t now)
 
int router_exit_policy_rejects_all (const routerinfo_t *router)
 
void list_pending_downloads (digestmap_t *result, digest256map_t *result256, int purpose, const char *prefix)
 
static void list_pending_descriptor_downloads (digestmap_t *result, int extrainfo)
 
void list_pending_microdesc_downloads (digest256map_t *result)
 
STATIC void initiate_descriptor_downloads (const routerstatus_t *source, int purpose, smartlist_t *digests, int lo, int hi, int pds_flags)
 
static int max_dl_per_request (const or_options_t *options, int purpose)
 
void launch_descriptor_downloads (int purpose, smartlist_t *downloadable, const routerstatus_t *source, 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)
 
void router_reset_descriptor_download_failures (void)
 
int router_differences_are_cosmetic (const routerinfo_t *r1, const routerinfo_t *r2)
 
int routerinfo_incompatible_with_extrainfo (const crypto_pk_t *identity_pkey, extrainfo_t *ei, signed_descriptor_t *sd, const char **msg)
 
int routerinfo_has_curve25519_onion_key (const routerinfo_t *ri)
 
int routerstatus_version_supports_extend2_cells (const routerstatus_t *rs, int allow_unknown_versions)
 
void routerlist_assert_ok (const routerlist_t *rl)
 
const char * esc_router_info (const routerinfo_t *router)
 
static int compare_routerinfo_by_id_digest_ (const void **a, const void **b)
 
void routers_sort_by_identity (smartlist_t *routers)
 
void refresh_all_country_info (void)
 

Variables

static routerlist_trouterlist = NULL
 
static smartlist_twarned_nicknames = NULL
 
static time_t last_descriptor_download_attempted = 0
 

Detailed Description

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

A "routerinfo_t" object represents a single self-signed router descriptor, as generated by a Tor relay in order to tell the rest of the world about its keys, address, and capabilities. An "extrainfo_t" object represents an adjunct "extra-info" object, certified by a corresponding router descriptor, reporting more information about the relay that nearly all users will not need.

Most users will not use router descriptors for most relays. Instead, they use the information in microdescriptors and in the consensus networkstatus.

Right now, routerinfo_t objects are used in these ways:

Routerinfos are mostly created by parsing them from a string, in routerparse.c. We store them to disk on receiving them, and periodically discard the ones we don't need. On restarting, we re-read them from disk. (This also applies to extrainfo documents, if we are configured to fetch them.)

In order to keep our list of routerinfos up-to-date, we periodically check whether there are any listed in the latest consensus (or in the votes from other authorities, if we are an authority) that we don't have. (This also applies to extrainfo documents, if we are configured to fetch them.)

Almost nothing in Tor should use a routerinfo_t to refer directly to a relay; instead, almost everything should use node_t (implemented in nodelist.c), which provides a common interface to routerinfo_t, routerstatus_t, and microdescriptor_t.


This module also has some of the functions used for choosing random nodes according to different rules and weights. Historically, they were all in this module. Now, they are spread across this module, nodelist.c, and networkstatus.c. (TODO: Fix that.)

Definition in file routerlist.c.

Macro Definition Documentation

◆ DEFAULT_MAX_BELIEVABLE_BANDWIDTH

#define DEFAULT_MAX_BELIEVABLE_BANDWIDTH   10000000 /* 10 MB/sec */

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

Definition at line 652 of file routerlist.c.

◆ MAX_DL_TO_DELAY

#define MAX_DL_TO_DELAY   16

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

Definition at line 2511 of file routerlist.c.

◆ MIN_DL_PER_REQUEST

#define MIN_DL_PER_REQUEST   32

Don't split our requests so finely that we are requesting fewer than this number per server. (Grouping more than this at once leads to diminishing returns.)

Definition at line 2505 of file routerlist.c.

◆ MIN_REQUESTS

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

Definition at line 2508 of file routerlist.c.

◆ ROUTER_ALLOW_UPTIME_DRIFT

#define ROUTER_ALLOW_UPTIME_DRIFT   (6*60*60)

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

Definition at line 2916 of file routerlist.c.

◆ ROUTER_MAX_COSMETIC_TIME_DIFFERENCE

#define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE   (2*60*60)

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

Definition at line 2913 of file routerlist.c.

◆ SDMAP_FOREACH

#define SDMAP_FOREACH (   map,
  keyvar,
  valvar 
)
Value:
DIGESTMAP_FOREACH(sdmap_to_digestmap(map), keyvar, signed_descriptor_t *, \
valvar)
#define DIGESTMAP_FOREACH(map, keyvar, valtype, valvar)
Definition: map.h:154

Definition at line 127 of file routerlist.c.

Function Documentation

◆ compare_duration_idx_()

static int compare_duration_idx_ ( const void *  _d1,
const void *  _d2 
)
static

Sorting helper: compare two duration_idx_t by their duration.

Definition at line 1790 of file routerlist.c.

◆ compare_old_routers_by_identity_()

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.

Definition at line 1770 of file routerlist.c.

◆ compare_routerinfo_by_id_digest_()

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

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

Definition at line 3265 of file routerlist.c.

Referenced by routers_sort_by_identity().

◆ compare_signed_descriptors_by_age_()

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.

Definition at line 223 of file routerlist.c.

◆ desc_get_store()

static desc_store_t* desc_get_store ( routerlist_t rl,
const signed_descriptor_t sd 
)
inlinestatic

Return the desc_store_t in rl that should be used to store sd.

Definition at line 186 of file routerlist.c.

Referenced by signed_descriptor_get_body_impl().

◆ dump_routerlist_mem_usage()

void dump_routerlist_mem_usage ( int  severity)

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

Definition at line 1060 of file routerlist.c.

Referenced by dumpmemusage().

◆ esc_router_info()

const char* esc_router_info ( const 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.

Definition at line 3243 of file routerlist.c.

◆ extrainfo_free_()

void extrainfo_free_ ( extrainfo_t extrainfo)

Release all storage held by extrainfo

Definition at line 950 of file routerlist.c.

Referenced by extrainfo_free_void().

◆ extrainfo_free_void()

static void extrainfo_free_void ( void *  e)
static

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

Definition at line 1021 of file routerlist.c.

◆ extrainfo_get_by_descriptor_digest()

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.

Definition at line 810 of file routerlist.c.

Referenced by get_signed_descriptor_by_fp().

◆ extrainfo_insert()

STATIC was_router_added_t extrainfo_insert ( routerlist_t rl,
extrainfo_t ei,
int  warn_if_incompatible 
)

Adds the extrainfo_t ei to the routerlist rl, if there is a corresponding router in rl->routers or rl->old_routers. Return the status of inserting ei. Free ei if it isn't inserted.

Definition at line 1150 of file routerlist.c.

Referenced by router_add_extrainfo_to_routerlist().

◆ hex_digest_nickname_decode()

int hex_digest_nickname_decode ( const char *  hexdigest,
char *  digest_out,
char *  nickname_qualifier_char_out,
char *  nickname_out 
)

Helper: given an extended nickname in hexdigest try to decode it. Return 0 on success, -1 on failure. Store the result into the DIGEST_LEN-byte buffer at digest_out, the single character at nickname_qualifier_char_out, and the MAXNICKNAME_LEN+1-byte buffer at nickname_out.

The recognized format is: HexName = Dollar? HexDigest NamePart? Dollar = '?' HexDigest = HexChar*20 HexChar = 'a'..'f' | 'A'..'F' | '0'..'9' NamePart = QualChar Name QualChar = '=' | '~' Name = NameChar*(1..MAX_NICKNAME_LEN) NameChar = Any ASCII alphanumeric character

Definition at line 684 of file routerlist.c.

Referenced by hex_digest_nickname_matches(), and node_get_by_hex_id().

◆ hex_digest_nickname_matches()

int hex_digest_nickname_matches ( const char *  hexdigest,
const char *  identity_digest,
const char *  nickname 
)

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.

Definition at line 720 of file routerlist.c.

Referenced by node_nickname_matches().

◆ hexdigest_to_digest()

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.

Definition at line 749 of file routerlist.c.

Referenced by connection_ap_fail_onehop().

◆ initiate_descriptor_downloads()

STATIC void initiate_descriptor_downloads ( const routerstatus_t source,
int  purpose,
smartlist_t digests,
int  lo,
int  hi,
int  pds_flags 
)

Launch downloads for all the descriptors whose digests or digests256 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.

Definition at line 2409 of file routerlist.c.

◆ launch_descriptor_downloads()

void launch_descriptor_downloads ( int  purpose,
smartlist_t downloadable,
const routerstatus_t source,
time_t  now 
)

Given a purpose (FETCH_MICRODESC or FETCH_SERVERDESC) and a list of router descriptor digests or microdescriptor digest256s 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.

Definition at line 2520 of file routerlist.c.

◆ list_pending_descriptor_downloads()

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.

Definition at line 2385 of file routerlist.c.

Referenced by update_extrainfo_downloads().

◆ list_pending_downloads()

void list_pending_downloads ( digestmap_t *  result,
digest256map_t *  result256,
int  purpose,
const char *  prefix 
)

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 (or base64 fingerprints if purpose==DIR_PURPOSE_FETCH_MICRODESC), decode them, and set the corresponding elements of result to a nonzero value.

Definition at line 2342 of file routerlist.c.

Referenced by list_pending_descriptor_downloads(), and list_pending_microdesc_downloads().

◆ list_pending_microdesc_downloads()

void list_pending_microdesc_downloads ( digest256map_t *  result)

For every microdescriptor we are currently downloading by descriptor digest, set result[d] to (void*)1.

Definition at line 2396 of file routerlist.c.

◆ max_dl_per_request()

static int max_dl_per_request ( const or_options_t options,
int  purpose 
)
static

Return the max number of hashes to put in a URL for a given request.

Definition at line 2476 of file routerlist.c.

◆ refresh_all_country_info()

void refresh_all_country_info ( void  )

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

Definition at line 3284 of file routerlist.c.

Referenced by config_maybe_load_geoip_files_().

◆ router_add_extrainfo_to_routerlist()

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.

Definition at line 1749 of file routerlist.c.

◆ router_add_running_nodes_to_smartlist()

void router_add_running_nodes_to_smartlist ( smartlist_t sl,
int  flags 
)

Add every suitable node from our nodelist to sl, so that we can pick a node for a circuit based on flags.

See router_can_choose_node() for details of flags.

Definition at line 615 of file routerlist.c.

Referenced by pick_restricted_middle_node().

◆ router_add_to_routerlist()

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.

Definition at line 1573 of file routerlist.c.

◆ router_descriptor_is_older_than()

int router_descriptor_is_older_than ( const routerinfo_t router,
int  seconds 
)

Return 1 if the signed descriptor of this router is older than seconds seconds. Otherwise return 0.

Definition at line 1546 of file routerlist.c.

◆ router_differences_are_cosmetic()

int router_differences_are_cosmetic ( const routerinfo_t r1,
const routerinfo_t r2 
)

Return true iff the only differences between r1 and r2 are such that would not cause a recent (post 0.1.1.6) dirserver to republish.

Definition at line 2922 of file routerlist.c.

◆ router_exit_policy_rejects_all()

int router_exit_policy_rejects_all ( const routerinfo_t router)

Return true iff router does not permit exit streams.

Definition at line 2330 of file routerlist.c.

◆ router_get_advertised_bandwidth()

uint32_t router_get_advertised_bandwidth ( const routerinfo_t router)

Return the smaller of the router's configured BandwidthRate and its advertised capacity.

Definition at line 643 of file routerlist.c.

Referenced by dirserv_get_bandwidth_for_router_kb().

◆ router_get_advertised_bandwidth_capped()

uint32_t router_get_advertised_bandwidth_capped ( const routerinfo_t router)

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

Definition at line 657 of file routerlist.c.

◆ router_get_by_descriptor_digest()

signed_descriptor_t* router_get_by_descriptor_digest ( const char *  digest)

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

Definition at line 784 of file routerlist.c.

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

Definition at line 797 of file routerlist.c.

◆ router_get_by_id_digest()

const routerinfo_t* router_get_by_id_digest ( const char *  digest)

Return the router in our routerlist whose 20-byte key digest is digest. Return NULL if no such router is known.

Definition at line 776 of file routerlist.c.

Referenced by connection_or_digest_is_known_relay(), and get_signed_descriptor_by_fp().

◆ router_get_mutable_by_digest()

routerinfo_t* router_get_mutable_by_digest ( const char *  digest)

As router_get_by_id_digest,but return a pointer that you're allowed to modify

Definition at line 762 of file routerlist.c.

Referenced by dirserv_add_extrainfo(), and router_get_by_id_digest().

◆ router_get_routerlist()

routerlist_t* router_get_routerlist ( void  )

◆ router_load_extrainfo_from_string()

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

Parse one or more extrainfos from s (ending immediately before eos if eos is present). Other arguments are as for router_load_routers_from_string().

Definition at line 2213 of file routerlist.c.

◆ router_load_routers_from_string()

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.

Definition at line 2114 of file routerlist.c.

◆ router_load_single_router()

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.

Definition at line 2047 of file routerlist.c.

Referenced by handle_control_postdescriptor().

◆ router_rebuild_store()

static int router_rebuild_store ( int  flags,
desc_store_t store 
)
static

If the journal of store is too long, or if RRS_FORCE is set in flags, then atomically replace the saved router store with the routers currently in our routerlist, and clear the journal. Unless RRS_DONT_REMOVE_OLD is set in flags, delete expired routers before rebuilding the store. Return 0 on success, -1 on failure.

Definition at line 239 of file routerlist.c.

◆ router_reload_router_list()

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.

Definition at line 460 of file routerlist.c.

◆ router_reload_router_list_impl()

static int router_reload_router_list_impl ( desc_store_t store)
static

Helper: Reload a cache file and its associated journal, setting metadata appropriately. If extrainfo is true, reload the extrainfo store; else reload the router descriptor store.

Definition at line 393 of file routerlist.c.

Referenced by router_reload_router_list().

◆ router_reset_descriptor_download_failures()

void router_reset_descriptor_download_failures ( void  )

Reset the consensus and extra-info download failure count on all routers. When we get a new consensus, routers_update_status_from_consensus_networkstatus() will reset the download statuses on the descriptors in that consensus.

Definition at line 2890 of file routerlist.c.

◆ router_should_rebuild_store()

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.

Definition at line 174 of file routerlist.c.

◆ routerinfo_free_()

void routerinfo_free_ ( routerinfo_t router)

Free all storage held by router.

Definition at line 920 of file routerlist.c.

◆ routerinfo_incompatible_with_extrainfo()

int routerinfo_incompatible_with_extrainfo ( const crypto_pk_t identity_pkey,
extrainfo_t ei,
signed_descriptor_t sd,
const char **  msg 
)

Check whether sd describes a router descriptor compatible with the extrainfo document ei.

identity_pkey (which must also be provided) is RSA1024 identity key for the router. We use it to check the signature of the extrainfo document, if it has not already been checked.

If no router is compatible with ei, ei should be dropped. Return 0 for "compatible", return 1 for "reject, and inform whoever uploaded <b>ei</b>, and return -1 for "reject silently.". If msg is present, set *msg to a description of the incompatibility (if any).

Set the extrainfo_is_bogus field in sd if the digests matched but the extrainfo was nonetheless incompatible.

Definition at line 3018 of file routerlist.c.

◆ routerlist_assert_ok()

void routerlist_assert_ok ( const routerlist_t rl)

Assert that the internal representation of rl is self-consistent.

Definition at line 3155 of file routerlist.c.

◆ routerlist_descriptors_added()

void routerlist_descriptors_added ( smartlist_t sl,
int  from_cache 
)

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

Definition at line 2018 of file routerlist.c.

◆ routerlist_find_elt_()

static int routerlist_find_elt_ ( smartlist_t sl,
void *  ri,
int  idx 
)
inlinestatic

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.

Definition at line 1083 of file routerlist.c.

◆ routerlist_find_my_routerinfo()

const routerinfo_t* routerlist_find_my_routerinfo ( void  )

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

Definition at line 627 of file routerlist.c.

◆ routerlist_free_()

void routerlist_free_ ( routerlist_t rl)

Free all storage held by a routerlist rl.

Definition at line 1028 of file routerlist.c.

◆ routerlist_free_all()

void routerlist_free_all ( void  )

Free all memory held by the routerlist module. Note: Calling routerlist_free_all() should always be paired with a call to nodelist_free_all(). These should only be called during cleanup.

Definition at line 1515 of file routerlist.c.

◆ routerlist_insert()

static void routerlist_insert ( routerlist_t rl,
routerinfo_t ri 
)
static

Insert an item ri into the routerlist rl, updating indices as needed. There must be no previous member of rl with the same identity digest as ri: If there is, call routerlist_replace instead.

Definition at line 1105 of file routerlist.c.

◆ routerlist_insert_old()

static void routerlist_insert_old ( routerlist_t rl,
routerinfo_t ri 
)
static

If we're a directory cache and routerlist rl doesn't have a copy of router ri yet, add it to the list of old (not recommended but still served) descriptors. Else free it.

Definition at line 1240 of file routerlist.c.

◆ routerlist_remove()

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

Remove an item ri from the routerlist rl, updating indices as needed. If idx is nonnegative and smartlist_get(rl->routers, idx) == ri, we don't need to do a linear search over the list to decide which to remove. We fill the gap in rl->routers with a later element in the list, if any exists. ri is freed.

If make_old is true, instead of deleting the router, we try adding it to rl->old_routers.

Definition at line 1275 of file routerlist.c.

◆ routerlist_remove_old()

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

Remove a signed_descriptor_t sd from rl->old_routers, and adjust rl as appropriate. idx is -1, or the index of sd.

Definition at line 1334 of file routerlist.c.

Referenced by routerlist_reparse_old().

◆ routerlist_remove_old_cached_routers_with_id()

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.

Definition at line 1806 of file routerlist.c.

◆ routerlist_remove_old_routers()

void routerlist_remove_old_routers ( void  )

Deactivate any routers from the routerlist that are more than ROUTER_MAX_AGE seconds old and not recommended by any networkstatuses; remove old routers from the list of cached routers if we have too many.

Definition at line 1892 of file routerlist.c.

◆ routerlist_reparse_old()

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

Extract the descriptor sd from old_routerlist, and re-parse it as a fresh routerinfo_t.

Definition at line 1490 of file routerlist.c.

◆ routerlist_replace()

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

Remove ri_old from the routerlist rl, and replace it with ri_new, updating all index info. If idx is nonnegative and smartlist_get(rl->routers, idx) == ri, we don't need to do a linear search over the list to decide which to remove. We put ri_new in the same index as ri_old, if possible. ri is freed as appropriate.

If should_cache_descriptors() is true, instead of deleting the router, we add it to rl->old_routers.

Definition at line 1387 of file routerlist.c.

◆ routerlist_reset_warnings()

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.

Definition at line 1533 of file routerlist.c.

◆ routerlist_retry_directory_downloads()

void routerlist_retry_directory_downloads ( time_t  now)

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

Definition at line 2315 of file routerlist.c.

◆ routers_have_same_or_addrs()

int routers_have_same_or_addrs ( const routerinfo_t r1,
const routerinfo_t r2 
)

Return true iff r1 and r2 have the same address and OR port.

Definition at line 509 of file routerlist.c.

Referenced by nodelist_set_routerinfo().

◆ routers_sort_by_identity()

void routers_sort_by_identity ( smartlist_t routers)

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

Definition at line 3275 of file routerlist.c.

◆ signed_desc_append_to_journal()

static int signed_desc_append_to_journal ( signed_descriptor_t desc,
desc_store_t store 
)
static

Add the signed_descriptor_t in desc to the router journal; change its saved_location to SAVED_IN_JOURNAL and set its offset appropriately.

Definition at line 198 of file routerlist.c.

Referenced by router_add_extrainfo_to_routerlist().

◆ signed_desc_digest_is_recognized()

static int signed_desc_digest_is_recognized ( signed_descriptor_t desc)
static

Return true iff the latest ns-flavored consensus includes a descriptor whose digest is that of desc.

Definition at line 2286 of file routerlist.c.

◆ signed_descriptor_free_()

static void signed_descriptor_free_ ( signed_descriptor_t sd)
static

Release storage held by sd.

Definition at line 967 of file routerlist.c.

◆ signed_descriptor_from_routerinfo()

static signed_descriptor_t* signed_descriptor_from_routerinfo ( routerinfo_t ri)
static

Extract a signed_descriptor_t from a general routerinfo, and free the routerinfo.

Definition at line 1009 of file routerlist.c.

◆ signed_descriptor_get_annotations()

const char* signed_descriptor_get_annotations ( const 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.

Definition at line 888 of file routerlist.c.

Referenced by routerlist_reparse_old().

◆ signed_descriptor_get_body()

const char* signed_descriptor_get_body ( const 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.

Definition at line 880 of file routerlist.c.

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

◆ signed_descriptor_get_body_impl()

static const char * signed_descriptor_get_body_impl ( const 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.

Definition at line 831 of file routerlist.c.

Referenced by signed_descriptor_get_annotations(), and signed_descriptor_get_body().

◆ signed_descriptor_move()

static void signed_descriptor_move ( signed_descriptor_t dest,
signed_descriptor_t src 
)
static

Copy src into dest, and steal all references inside src so that when we free src, we don't mess up dest.

Definition at line 993 of file routerlist.c.

Referenced by routerlist_reparse_old().

◆ signed_descriptor_reset()

static void signed_descriptor_reset ( signed_descriptor_t sd)
static

Reset the given signed descriptor sd by freeing the allocated memory inside the object and by zeroing its content.

Definition at line 982 of file routerlist.c.

Referenced by signed_descriptor_move().

◆ update_all_descriptor_downloads()

void update_all_descriptor_downloads ( time_t  now)

Update downloads for router descriptors and/or microdescriptors as appropriate.

Definition at line 2304 of file routerlist.c.

Referenced by directory_info_has_arrived().

◆ update_consensus_router_descriptor_downloads()

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

For any descriptor that we want that's currently listed in consensus, download it as appropriate.

Definition at line 2618 of file routerlist.c.

Referenced by update_router_descriptor_downloads().

◆ update_extrainfo_downloads()

void update_extrainfo_downloads ( time_t  now)

Launch extrainfo downloads as needed.

Definition at line 2779 of file routerlist.c.

Referenced by directory_info_has_arrived().

◆ update_router_descriptor_downloads()

void update_router_descriptor_downloads ( time_t  now)

Launch downloads for router status as needed.

Definition at line 2765 of file routerlist.c.

Referenced by update_all_descriptor_downloads().

Variable Documentation

◆ last_descriptor_download_attempted

time_t last_descriptor_download_attempted = 0
static

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.

Definition at line 156 of file routerlist.c.

◆ routerlist

routerlist_t* routerlist = NULL
static

◆ warned_nicknames

smartlist_t* warned_nicknames = NULL
static

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

Definition at line 151 of file routerlist.c.

Referenced by routerlist_reset_warnings().