#include "or.h"
#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)
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 | |||
) |
Add to the list of authoritative directory servers one at address:port, with identity key digest. If address is NULL, add ourself. Return the new trusted directory server entry on success or NULL if we couldn't add it.
References routerstatus_t::addr, trusted_dir_server_t::addr, trusted_dir_server_t::address, trusted_dir_server_t::description, trusted_dir_server_t::digest, DIGEST_LEN, routerstatus_t::dir_port, trusted_dir_server_t::dir_port, trusted_dir_server_t::fake_status, get_options(), routerstatus_t::identity_digest, trusted_dir_server_t::is_running, LD_CONFIG, routerstatus_t::nickname, trusted_dir_server_t::nickname, routerstatus_t::or_port, trusted_dir_server_t::or_port, resolve_my_address(), router_dir_info_changed(), smartlist_add(), smartlist_create(), tor_lookup_hostname(), tor_snprintf(), trusted_dir_servers, trusted_dir_server_t::type, V3_AUTHORITY, trusted_dir_server_t::v3_identity_digest, routerstatus_t::version_supports_begindir, and routerstatus_t::version_supports_conditional_consensus.
Referenced by init_keys(), and parse_dir_server_line().
static INLINE int already_have_cert | ( | authority_cert_t * | cert | ) | [static] |
Helper: return true iff we already have loaded the exact cert cert.
References authority_cert_t::cache_info, cert_list_t::certs, DIGEST_LEN, get_cert_list(), signed_descriptor_t::identity_digest, and signed_descriptor_t::signed_descriptor_digest.
Referenced by trusted_dirs_load_certs_from_string().
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 | ) |
Free storage held in cert.
References authority_cert_t::cache_info, crypto_free_pk_env(), authority_cert_t::identity_key, signed_descriptor_t::signed_descriptor_body, authority_cert_t::signing_key, and tor_free.
Referenced by authority_cert_parse_from_string(), load_authority_keyset(), networkstatus_vote_free(), router_free_all(), routerlist_free_all(), trusted_dirs_load_certs_from_string(), and trusted_dirs_remove_old_certs().
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 | |||
) |
Try to download any v3 authority certificates that we may be missing. If status is provided, try to get all the ones that were used to sign status. Additionally, try to have a non-expired certificate for every V3 authority in trusted_dir_servers. Don't fetch certificates we already have.
References authority_cert_get_by_digests(), cert_list_t::certs, DIGEST_LEN, digestmap_get(), digestmap_new(), DIR_PURPOSE_FETCH_CERTIFICATE, directory_caches_dir_info(), cert_list_t::dl_status, download_status_is_ready(), download_status_reset(), authority_cert_t::expires, ftime_definitely_after(), get_cert_list(), get_options(), hex_str(), LD_DIR, list_pending_downloads(), MAX_CERT_DL_FAILURES, should_delay_dir_fetches(), smartlist_add(), smartlist_create(), smartlist_digest_isin(), trusted_dir_servers, trusteddirserver_get_by_v3_auth_digest(), V3_AUTHORITY, and networkstatus_t::voters.
Referenced by networkstatus_set_current_consensus(), and update_certificate_downloads().
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] |
Return the desc_store_t in rl that should be used to store sd.
References routerlist_t::desc_store, routerlist_t::extrainfo_store, and signed_descriptor_t::is_extrainfo.
Referenced by routerlist_remove_old(), and signed_descriptor_get_body_impl().
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 | ) |
Release all storage held by extrainfo
References extrainfo_t::cache_info, extrainfo_t::pending_sig, signed_descriptor_t::signed_descriptor_body, and tor_free.
Referenced by _extrainfo_free(), dirserv_add_extrainfo(), extrainfo_dump_to_string(), extrainfo_insert(), extrainfo_parse_entry_from_string(), router_free_all(), router_rebuild_descriptor(), routerlist_remove(), routerlist_remove_old(), and routerlist_replace().
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] |
Adds the extrainfo_t ei to the routerlist rl, if there is a corresponding router in rl->routers or rl->old_routers. Return true iff we actually inserted ei. Free ei if it isn't inserted.
References desc_store_t::bytes_dropped, extrainfo_t::cache_info, routerlist_t::desc_by_eid_map, routerlist_t::extra_info_map, extrainfo_free(), routerlist_t::extrainfo_store, signed_descriptor_t::identity_digest, routerlist_t::identity_map, router_get_my_extrainfo(), routerinfo_incompatible_with_extrainfo(), routerlist_assert_ok(), signed_descriptor_t::signed_descriptor_digest, signed_descriptor_t::signed_descriptor_len, and tor_assert.
Referenced by router_add_extrainfo_to_routerlist().
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 | ) |
Return true if this node is currently acting as hidden service directory, false otherwise.
References routerinfo_t::cache_info, get_options(), signed_descriptor_t::identity_digest, routerstatus_t::is_hs_dir, LD_REND, networkstatus_get_latest_consensus(), networkstatus_vote_find_entry(), and router_get_my_routerinfo().
Referenced by hid_serv_responsible_for_desc_id(), and rend_cache_store_v2_desc_as_dir().
int hid_serv_get_responsible_directories | ( | smartlist_t * | responsible_dirs, | |
const char * | id | |||
) |
Determine the routers that are responsible for id (binary) and add pointers to those routers' routerstatus_t to responsible_dirs. Return -1 if we're returning an empty smartlist, else return 0.
References routerstatus_t::dir_port, get_options(), routerstatus_t::is_hs_dir, LD_REND, networkstatus_get_latest_consensus(), networkstatus_vote_find_entry_idx(), routerstatus_t::nickname, REND_NUMBER_OF_CONSECUTIVE_REPLICAS, networkstatus_t::routerstatus_list, smartlist_add(), tor_assert, and or_options_t::TunnelDirConns.
Referenced by directory_get_from_hs_dir(), directory_post_to_hs_dir(), and hid_serv_responsible_for_desc_id().
int hid_serv_responsible_for_desc_id | ( | const char * | query | ) |
Return true if this node is responsible for storing the descriptor ID in query and false otherwise.
References routerinfo_t::cache_info, hid_serv_acting_as_directory(), hid_serv_get_responsible_directories(), routerstatus_t::identity_digest, signed_descriptor_t::identity_digest, rend_id_is_in_interval(), router_get_my_routerinfo(), smartlist_create(), and smartlist_free().
Referenced by rend_cache_clean_v2_descs_as_dir(), rend_cache_lookup_v2_desc_as_dir(), and rend_cache_store_v2_desc_as_dir().
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 | |||
) |
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.
References routerinfo_t::address, routerinfo_t::bandwidthburst, routerinfo_t::bandwidthcapacity, routerinfo_t::bandwidthrate, routerinfo_t::cache_info, cmp_addr_policies(), routerinfo_t::contact_info, crypto_pk_cmp_keys(), routerinfo_t::declared_family, routerinfo_t::dir_port, routerinfo_t::exit_policy, routerinfo_t::has_old_dnsworkers, routerinfo_t::identity_pkey, routerinfo_t::is_hibernating, routerinfo_t::nickname, routerinfo_t::onion_pkey, routerinfo_t::or_port, routerinfo_t::platform, signed_descriptor_t::published_on, routerinfo_t::purpose, ROUTER_ALLOW_UPTIME_DRIFT, ROUTER_MAX_COSMETIC_TIME_DIFFERENCE, tor_assert, and routerinfo_t::uptime.
Referenced by dirserv_add_descriptor().
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 | ) |
Return the smaller of the router's configured BandwidthRate and its advertised capacity.
References routerinfo_t::bandwidthcapacity, and routerinfo_t::bandwidthrate.
Referenced by _compare_routerinfo_by_ip_and_bw(), dirserv_compute_performance_thresholds(), dirserv_thinks_router_is_unreliable(), and set_routerstatus_from_routerinfo().
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 | ) |
Return the router in our routerlist whose 20-byte descriptor is digest. Return NULL if no such router is known.
References routerlist_t::desc_digest_map, routerlist, and tor_assert.
Referenced by connection_dirserv_add_servers_to_outbuf(), count_usable_descriptors(), dirserv_get_routerdesc_fingerprints(), dirserv_get_routerdescs(), dirserv_have_any_serverdesc(), networkstatus_reset_download_failures(), router_set_networkstatus_v2(), update_consensus_router_descriptor_downloads(), and update_router_descriptor_cache_downloads_v2().
routerinfo_t* router_get_by_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.
References routerlist_t::identity_map, routerlist, and tor_assert.
Referenced by bridges_retry_helper(), build_state_get_exit_router(), choose_good_entry_server(), choose_good_middle_server(), circuit_find_to_cannibalize(), circuit_list_path_impl(), circuit_rep_hist_note_result(), circuit_send_next_onion_skin(), command_process_create_cell(), command_process_netinfo_cell(), connection_ap_process_end_not_open(), connection_or_digest_is_known_relay(), connection_or_init_conn_from_address(), connection_or_set_state_open(), control_event_guard(), directory_get_from_hs_dir(), directory_initiate_command_routerstatus_rend(), directory_post_to_hs_dir(), dirserv_add_descriptor(), dirserv_add_extrainfo(), dirserv_get_routerdescs(), entry_guards_compute_status(), entry_is_live(), get_signed_descriptor_by_fp(), getinfo_helper_entry_guards(), handle_control_attachstream(), orconn_target_get_name(), rend_services_introduce(), rep_hist_dump_stats(), rep_hist_get_router_stability_doc(), rep_hist_record_mtbf_data(), router_digest_version_as_new_as(), router_get_by_hexdigest(), router_set_status(), router_supports_extrainfo(), routerstatus_format_entry(), smartlist_choose_by_bandwidth(), update_consensus_router_descriptor_downloads(), and update_extrainfo_downloads().
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 | |||
) |
Return the router in our routerlist whose (case-insensitive) nickname or (case-sensitive) hexadecimal key digest is nickname. Return NULL if no such router is known.
References base16_decode(), DIGEST_LEN, get_options(), HEX_DIGEST_LEN, routerlist_t::identity_map, networkstatus_get_router_digest_by_nickname(), networkstatus_nickname_is_unnamed(), router_get_by_hexdigest(), router_get_my_routerinfo(), routerlist, routerlist_t::routers, server_mode(), and tor_assert.
Referenced by add_nickname_list_to_smartlist(), circuit_discard_optional_exit_enclaves(), circuit_get_open_circ_or_launch(), connection_ap_can_use_exit(), connection_ap_handshake_attach_circuit(), getinfo_helper_dir(), handle_control_extendcircuit(), rend_client_get_random_intro(), rend_service_introduce(), router_rebuild_descriptor(), routerlist_add_family(), and routerset_get_all_routers().
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 | ) |
Return the current list of all known routers.
References routerlist_t::desc_by_eid_map, routerlist_t::desc_digest_map, routerlist_t::desc_store, desc_store_t::description, routerlist_t::extra_info_map, routerlist_t::extrainfo_store, desc_store_t::fname_alt_base, desc_store_t::fname_base, routerlist_t::identity_map, routerlist_t::old_routers, routerlist, routerlist_t::routers, smartlist_create(), and desc_store_t::type.
Referenced by choose_good_entry_server(), directory_remove_invalid(), dirserv_generate_networkstatus_vote_obj(), dirserv_get_routerdesc_fingerprints(), dirserv_get_routerdescs(), dirserv_orconn_tls_done(), dirserv_test_reachability(), format_networkstatus_vote(), generate_v2_networkstatus_opinion(), getinfo_helper_dir(), networkstatus_getinfo_by_purpose(), onion_pick_cpath_exit(), router_add_extrainfo_to_routerlist(), router_add_to_routerlist(), router_choose_random_node(), router_load_extrainfo_from_string(), router_parse_list_from_string(), router_reload_router_list(), routerlist_refresh_countries(), routers_update_all_from_networkstatus(), signed_descriptor_get_body_impl(), and update_extrainfo_downloads().
smartlist_t* router_get_trusted_dir_servers | ( | void | ) |
Return a smartlist containing a list of trusted_dir_server_t * for all known trusted dirservers. Callers must not modify the list or its contents.
References smartlist_create(), and trusted_dir_servers.
Referenced by connection_dir_client_reached_eof(), connection_dir_download_networkstatus_failed(), consider_adding_dir_authorities(), directories_have_accepted_server_descriptor(), directory_get_consensus_url(), directory_get_from_all_authorities(), directory_post_to_dirservers(), dirserv_get_networkstatus_v2_fingerprints(), dirserv_set_cached_networkstatus_v2(), dirvote_fetch_missing_votes(), list_v3_auth_ids(), networkstatus_check_consensus_signature(), and update_v2_networkstatus_cache_downloads().
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 | |||
) |
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().
References base16_encode(), DIGEST_LEN, HEX_DIGEST_LEN, LD_DIR, router_add_extrainfo_to_routerlist(), router_get_routerlist(), router_parse_list_from_string(), router_rebuild_store(), routerlist, routerlist_assert_ok(), SAVED_NOWHERE, smartlist_create(), smartlist_free(), smartlist_string_remove(), and WRA_WAS_ADDED().
Referenced by connection_dir_client_reached_eof(), and router_reload_router_list_impl().
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] |
Choose randomly from among the trusted dirservers that are up. Flags are as for router_pick_directory_server_impl().
References tor_addr_t::addr, CONN_TYPE_DIR, connection_get_by_type_addr_port_purpose(), DIR_503_TIMEOUT, DIR_PURPOSE_FETCH_EXTRAINFO, DIR_PURPOSE_FETCH_SERVERDESC, EXTRAINFO_CACHE, fascist_firewall_allows_address_dir(), fascist_firewall_allows_address_or(), PDS_ALLOW_SELF, PDS_IGNORE_FASCISTFIREWALL, PDS_NO_EXISTING_SERVERDESC_FETCH, router_digest_is_me(), router_get_my_routerinfo(), router_supports_extrainfo(), smartlist_add(), smartlist_choose(), smartlist_create(), smartlist_free(), tor_addr_from_ipv4h, and trusted_dir_servers.
Referenced by router_pick_trusteddirserver().
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.
References _compare_signed_descriptors_by_age(), sized_chunk_t::bytes, extrainfo_t::cache_info, desc_store_t::description, routerlist_t::extra_info_map, desc_store_t::fname_base, get_datadir_fname, get_datadir_fname_suffix, LD_BUG, LD_DIR, LD_FS, sized_chunk_t::len, desc_store_t::mmap, routerlist_t::old_routers, replace_file(), router_should_rebuild_store(), routerlist, routerlist_remove_old_routers(), routerlist_t::routers, SAVED_IN_CACHE, signed_descriptor_get_body(), signed_descriptor_get_body_impl(), smartlist_add(), smartlist_create(), smartlist_sort(), tor_free, tor_mmap_file(), tor_munmap_file(), desc_store_t::type, and write_chunks_to_file().
Referenced by router_load_extrainfo_from_string(), router_load_routers_from_string(), router_reload_router_list_impl(), and routerlist_remove_old_routers().
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] |
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.
References tor_mmap_t::data, file_status(), desc_store_t::fname_alt_base, desc_store_t::fname_base, get_datadir_fname, get_datadir_fname_suffix, desc_store_t::journal_len, LD_DIR, desc_store_t::mmap, read_file_to_str(), remove_file_if_very_old(), RFTS_BIN, RFTS_IGNORE_MISSING, router_load_extrainfo_from_string(), router_load_routers_from_string(), router_rebuild_store(), routerlist_remove_old_routers(), SAVED_IN_CACHE, SAVED_IN_JOURNAL, tor_mmap_t::size, desc_store_t::store_len, tor_free, tor_mmap_file(), tor_munmap_file(), and desc_store_t::type.
Referenced by router_reload_router_list().
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 | |||
) |
Mark the router with ID digest as running or non-running in our routerlist.
References routerinfo_t::address, control_event_networkstatus_changed_single(), DIGEST_LEN, routerstatus_t::is_running, routerinfo_t::is_running, LD_DIR, LD_NET, routerinfo_t::nickname, router_dir_info_changed(), router_get_by_digest(), router_get_consensus_status_by_id(), router_is_me(), tor_assert, trusted_dir_servers, and we_are_hibernating().
Referenced by connection_dir_request_failed(), and connection_or_set_state_open().
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 | ) |
Free all storage held by router.
References addr_policy_list_free(), routerinfo_t::address, routerinfo_t::cache_info, routerinfo_t::contact_info, crypto_free_pk_env(), routerinfo_t::declared_family, routerinfo_t::exit_policy, routerinfo_t::identity_pkey, routerinfo_t::nickname, routerinfo_t::onion_pkey, routerinfo_t::platform, signed_descriptor_t::signed_descriptor_body, smartlist_free(), and tor_free.
Referenced by dirserv_add_descriptor(), router_add_to_routerlist(), router_dump_router_to_string(), router_free_all(), router_load_routers_from_string(), router_load_single_router(), router_parse_entry_from_string(), router_rebuild_descriptor(), routerlist_free(), routerlist_insert_old(), routerlist_remove(), routerlist_replace(), and signed_descriptor_from_routerinfo().
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 | ) |
Assert that the internal representation of rl is self-consistent.
References routerlist_t::desc_digest_map, routerlist_t::identity_map, routerlist_t::routers, and tor_assert.
Referenced by directory_remove_invalid(), extrainfo_insert(), router_load_extrainfo_from_string(), router_load_routers_from_string(), routerlist_insert(), routerlist_insert_old(), routerlist_remove(), routerlist_remove_old(), and routerlist_replace().
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 | ) |
Free all storage held by a routerlist rl.
References _extrainfo_free(), routerlist_t::desc_by_eid_map, routerlist_t::desc_digest_map, routerlist_t::desc_store, routerlist_t::extra_info_map, routerlist_t::extrainfo_store, routerlist_t::identity_map, desc_store_t::mmap, routerlist_t::old_routers, router_dir_info_changed(), routerinfo_free(), routerlist, routerlist_t::routers, signed_descriptor_free(), smartlist_free(), tor_free, and tor_munmap_file().
Referenced by routerlist_free_all().
void routerlist_free_all | ( | void | ) |
Free all memory held by the routerlist module.
References authority_cert_free(), digestmap_free(), routerlist, routerlist_free(), smartlist_free(), tor_free, trusted_dir_certs, trusted_dir_server_free(), trusted_dir_servers, and warned_nicknames.
Referenced by tor_free_all().
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.
References routerinfo_t::cache_info, routerlist_t::desc_by_eid_map, routerlist_t::desc_digest_map, signed_descriptor_t::extra_info_digest, signed_descriptor_t::identity_digest, routerlist_t::identity_map, router_dir_info_changed(), router_get_my_routerinfo(), routerlist_assert_ok(), signed_descriptor_t::routerlist_index, routerlist_t::routers, signed_descriptor_t::signed_descriptor_digest, smartlist_add(), tor_assert, and tor_digest_is_zero().
Referenced by router_add_to_routerlist(), and routerlist_replace().
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.
References routerinfo_t::cache_info, routerlist_t::desc_by_eid_map, routerlist_t::desc_digest_map, signed_descriptor_t::extra_info_digest, routerlist_t::old_routers, routerinfo_t::purpose, router_get_my_routerinfo(), ROUTER_PURPOSE_GENERAL, routerinfo_free(), routerlist_assert_ok(), signed_descriptor_t::routerlist_index, signed_descriptor_t::signed_descriptor_digest, signed_descriptor_from_routerinfo(), smartlist_add(), tor_assert, and tor_digest_is_zero().
Referenced by router_add_to_routerlist().
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 | |||
) |
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.
References desc_store_t::bytes_dropped, extrainfo_t::cache_info, routerinfo_t::cache_info, routerlist_t::desc_by_eid_map, routerlist_t::desc_digest_map, routerlist_t::desc_store, signed_descriptor_t::extra_info_digest, routerlist_t::extra_info_map, extrainfo_free(), routerlist_t::extrainfo_store, signed_descriptor_t::identity_digest, routerlist_t::identity_map, routerlist_t::old_routers, routerinfo_t::purpose, rep_hist_note_router_unreachable(), router_dir_info_changed(), ROUTER_PURPOSE_GENERAL, routerinfo_free(), routerlist_assert_ok(), signed_descriptor_t::routerlist_index, routerlist_t::routers, signed_descriptor_t::signed_descriptor_digest, signed_descriptor_from_routerinfo(), signed_descriptor_t::signed_descriptor_len, smartlist_add(), smartlist_del(), tor_assert, and tor_digest_is_zero().
Referenced by directory_remove_invalid(), and routerlist_remove_old_routers().
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.
References desc_store_t::bytes_dropped, extrainfo_t::cache_info, routerlist_t::desc_by_eid_map, routerlist_t::desc_digest_map, desc_get_store(), signed_descriptor_t::extra_info_digest, routerlist_t::extra_info_map, extrainfo_free(), routerlist_t::extrainfo_store, routerlist_t::old_routers, routerlist_assert_ok(), signed_descriptor_t::routerlist_index, signed_descriptor_t::signed_descriptor_digest, signed_descriptor_free(), signed_descriptor_t::signed_descriptor_len, smartlist_del(), tor_assert, and tor_digest_is_zero().
Referenced by routerlist_remove_old_cached_routers_with_id(), routerlist_remove_old_routers(), and routerlist_reparse_old().
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 | ) |
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.
References _compare_old_routers_by_identity(), routerinfo_t::cache_info, routerlist_t::desc_store, DIGEST_LEN, digestset_free(), digestset_new(), directory_caches_dir_info(), routerlist_t::extrainfo_store, get_options(), signed_descriptor_t::identity_digest, signed_descriptor_t::last_listed_as_valid_until, LD_DIR, networkstatus_get_latest_consensus(), networkstatus_get_v2_list(), networkstatus_v2_list, routerinfo_t::nickname, OLD_ROUTER_DESC_MAX_AGE, routerlist_t::old_routers, signed_descriptor_t::published_on, ROUTER_MAX_AGE, router_rebuild_store(), routerlist, signed_descriptor_t::routerlist_index, routerlist_remove(), routerlist_remove_old(), routerlist_remove_old_cached_routers_with_id(), routerlist_t::routers, networkstatus_t::routerstatus_list, signed_descriptor_t::signed_descriptor_digest, smartlist_sort(), and trusted_dirs_remove_old_certs().
Referenced by router_rebuild_store(), router_reload_router_list_impl(), and run_scheduled_events().
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.
References signed_descriptor_t::annotations_len, routerinfo_t::cache_info, router_parse_entry_from_string(), signed_descriptor_t::routerlist_index, routerlist_remove_old(), signed_descriptor_t::signed_descriptor_body, signed_descriptor_get_annotations(), and signed_descriptor_t::signed_descriptor_len.
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.
References _routerlist_find_elt(), desc_store_t::bytes_dropped, extrainfo_t::cache_info, routerinfo_t::cache_info, routerlist_t::desc_by_eid_map, routerlist_t::desc_digest_map, routerlist_t::desc_store, DIGEST_LEN, signed_descriptor_t::extra_info_digest, routerlist_t::extra_info_map, extrainfo_free(), routerlist_t::extrainfo_store, signed_descriptor_t::identity_digest, routerlist_t::identity_map, LD_BUG, routerlist_t::old_routers, routerinfo_t::purpose, router_dir_info_changed(), router_get_my_routerinfo(), ROUTER_PURPOSE_GENERAL, routerinfo_free(), routerlist_assert_ok(), signed_descriptor_t::routerlist_index, routerlist_insert(), routerlist_t::routers, signed_descriptor_t::signed_descriptor_digest, signed_descriptor_from_routerinfo(), signed_descriptor_t::signed_descriptor_len, smartlist_add(), tor_assert, and tor_digest_is_zero().
Referenced by router_add_to_routerlist().
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 | |||
) |
Return true iff r1 and r2 are in the same family, but not the same router.
References routerinfo_t::declared_family, or_options_t::EnforceDistinctSubnets, get_options(), config_line_t::next, or_options_t::NodeFamilies, router_in_nickname_smartlist(), router_nickname_is_in_list(), routers_in_same_network_family(), and config_line_t::value.
Referenced by circuit_find_to_cannibalize().
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 | |||
) |
Return true iff we can tell that ei is a member of set.
References extend_info_t::addr, extend_info_t::identity_digest, extend_info_t::nickname, extend_info_t::port, and routerset_contains().
Referenced by circuit_conforms_to_options(), and warn_if_last_router_excluded().
int routerset_contains_router | ( | const routerset_t * | set, | |
routerinfo_t * | ri | |||
) |
Return true iff ri is in set.
References routerinfo_t::addr, routerinfo_t::cache_info, routerinfo_t::country, signed_descriptor_t::identity_digest, routerinfo_t::is_named, routerinfo_t::nickname, routerinfo_t::or_port, routerset_contains(), and tor_addr_from_ipv4h.
Referenced by choose_good_exit_server_general(), choose_random_entry(), connection_ap_can_use_exit(), entry_guard_set_status(), entry_is_live(), routerset_subtract_routers(), and routersets_get_disjunction().
int routerset_contains_routerstatus | ( | const routerset_t * | set, | |
routerstatus_t * | rs | |||
) |
Return true iff rs is in set.
References routerstatus_t::addr, routerstatus_t::identity_digest, routerstatus_t::is_named, routerstatus_t::nickname, routerstatus_t::or_port, routerset_contains(), and tor_addr_from_ipv4h.
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 | ) |
Free all storage held in routerset.
References addr_policy_free(), routerset_t::countries, routerset_t::country_names, digestmap_free(), routerset_t::digests, routerset_t::list, routerset_t::names, routerset_t::policies, smartlist_free(), strmap_free(), and tor_free.
Referenced by config_assign_value(), option_clear(), and or_options_free().
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 | ) |
Return a new empty routerset.
References routerset_t::country_names, digestmap_new(), routerset_t::digests, routerset_t::list, routerset_t::names, routerset_t::policies, and smartlist_create().
Referenced by config_assign_value(), and options_validate().
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] |
Add the signed_descriptor_t in desc to the router journal; change its saved_location to SAVED_IN_JOURNAL and set its offset appropriately.
References signed_descriptor_t::annotations_len, append_bytes_to_file(), desc_store_t::fname_base, get_datadir_fname_suffix, desc_store_t::journal_len, LD_FS, SAVED_IN_JOURNAL, signed_descriptor_t::saved_location, signed_descriptor_t::saved_offset, signed_descriptor_get_body_impl(), signed_descriptor_t::signed_descriptor_len, and tor_free.
Referenced by router_add_extrainfo_to_routerlist(), and router_add_to_routerlist().
static int signed_desc_digest_is_recognized | ( | signed_descriptor_t * | desc | ) | [static] |
Return true iff any networkstatus includes a descriptor whose digest is that of desc.
References routerstatus_t::descriptor_digest, DIGEST_LEN, directory_caches_dir_info(), get_options(), signed_descriptor_t::identity_digest, networkstatus_get_latest_consensus(), networkstatus_get_v2_list(), networkstatus_v2_find_entry(), networkstatus_v2_list, networkstatus_vote_find_entry(), and signed_descriptor_t::signed_descriptor_digest.
Referenced by router_add_to_routerlist().
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] |
Extract a signed_descriptor_t from a routerinfo, and free the routerinfo.
References routerinfo_t::cache_info, routerinfo_free(), signed_descriptor_t::routerlist_index, and signed_descriptor_t::signed_descriptor_body.
Referenced by routerlist_insert_old(), routerlist_remove(), and routerlist_replace().
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] |
Free storage held in ds.
References trusted_dir_server_t::address, trusted_dir_server_t::description, trusted_dir_server_t::nickname, and tor_free.
Referenced by clear_trusted_dir_servers(), and routerlist_free_all().
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 | |||
) |
Load a bunch of new key certificates from the string contents. If from_store is true, the certificates are from the cache, and we don't need to flush them to disk. If flush is true, we need to flush any changed certificates to disk now. Return 0 on success, -1 if any certs fail to parse.
References trusted_dir_server_t::addr, authority_cert_t::addr, trusted_dir_server_t::addr_current_at, trusted_dir_server_t::address, already_have_cert(), authority_cert_dl_failed(), authority_cert_free(), authority_cert_parse_from_string(), authority_cert_t::cache_info, cert_list_t::certs, DIGEST_LEN, trusted_dir_server_t::dir_port, authority_cert_t::dir_port, directory_caches_dir_info(), get_cert_list(), get_options(), hex_str(), signed_descriptor_t::identity_digest, LD_DIR, networkstatus_note_certs_arrived(), trusted_dir_server_t::nickname, signed_descriptor_t::published_on, authority_cert_t::signing_key_digest, smartlist_add(), tor_dup_ip(), tor_free, trusted_dir_servers_certs_changed, trusted_dirs_flush_certs_to_disk(), and trusteddirserver_get_by_v3_auth_digest().
Referenced by connection_dir_client_reached_eof(), dirvote_add_vote(), init_keys(), and trusted_dirs_reload_certs().
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 | |||
) |
For any descriptor that we want that's currently listed in consensus, download it as appropriate.
References authdir_mode(), DIGEST_LEN, digestmap_new(), directory_too_idle_to_fetch_descriptors(), trusted_dir_server_t::fake_status, get_options(), networkstatus_voter_info_t::identity_digest, LD_DIR, list_pending_descriptor_downloads(), router_get_by_descriptor_digest(), router_get_by_digest(), networkstatus_t::routerstatus_list, smartlist_add(), smartlist_create(), tor_assert, trusteddirserver_get_by_v3_auth_digest(), and networkstatus_t::voters.
Referenced by dirvote_add_vote(), and update_router_descriptor_downloads().
void update_extrainfo_downloads | ( | time_t | now | ) |
Launch extrainfo downloads as needed.
References digestmap_free(), digestmap_get(), digestmap_new(), DIR_PURPOSE_FETCH_EXTRAINFO, download_status_is_ready(), or_options_t::DownloadExtraInfo, signed_descriptor_t::ei_dl_status, signed_descriptor_t::extra_info_digest, routerlist_t::extra_info_map, signed_descriptor_t::extrainfo_is_bogus, get_options(), signed_descriptor_t::identity_digest, initiate_descriptor_downloads(), signed_descriptor_t::is_extrainfo, LD_DIR, list_pending_descriptor_downloads(), MAX_DL_PER_REQUEST, MAX_ROUTERDESC_DOWNLOAD_FAILURES, routerlist_t::old_routers, PDS_NO_EXISTING_SERVERDESC_FETCH, PDS_RETRY_IF_NO_SERVERS, router_get_by_digest(), router_get_routerlist(), router_have_minimum_dir_info(), routerlist_t::routers, should_delay_dir_fetches(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_shuffle(), and tor_digest_is_zero().
Referenced by directory_info_has_arrived(), and run_scheduled_events().
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 | ) |
Launch downloads for router status as needed.
References or_options_t::Address, DIR_PURPOSE_FETCH_SERVERDESC, directory_fetches_dir_info_early(), directory_get_from_dirserver(), DUMMY_DOWNLOAD_INTERVAL, get_options(), last_routerdesc_download_attempted, networkstatus_get_reasonably_live_consensus(), PDS_RETRY_IF_NO_SERVERS, ROUTER_PURPOSE_GENERAL, server_mode(), should_delay_dir_fetches(), update_consensus_router_descriptor_downloads(), and update_router_descriptor_cache_downloads_v2().
Referenced by directory_info_has_arrived(), routerlist_retry_directory_downloads(), and run_scheduled_events().
static void update_router_have_minimum_dir_info | ( | void | ) | [static] |
Change the value of have_min_dir_info, setting it true iff we have enough network and router information to build circuits. Clear the value of need_to_update_have_min_dir_info.
References control_event_bootstrap(), control_event_client_status(), count_usable_descriptors(), dir_info_status, directory_too_idle_to_fetch_descriptors(), get_options(), have_min_dir_info, LD_DIR, need_to_update_have_min_dir_info, networkstatus_get_latest_consensus(), networkstatus_get_reasonably_live_consensus(), should_delay_dir_fetches(), and tor_snprintf().
Referenced by router_have_minimum_dir_info().
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().
time_t last_routerdesc_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.
Referenced by launch_router_descriptor_downloads(), router_reset_descriptor_download_failures(), and update_router_descriptor_downloads().
int need_to_update_have_min_dir_info = 1 [static] |
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] |
Global list of all of the routers that we know about.
Referenced by dump_routerlist_mem_usage(), extrainfo_get_by_descriptor_digest(), getinfo_helper_dir(), mark_all_trusteddirservers_up(), router_add_extrainfo_to_routerlist(), router_add_running_routers_to_smartlist(), router_add_to_routerlist(), router_exit_policy_all_routers_reject(), router_find_exact_exit_enclave(), router_get_by_descriptor_digest(), router_get_by_digest(), router_get_by_extrainfo_digest(), router_get_by_hexdigest(), router_get_by_nickname(), router_get_routerlist(), router_load_extrainfo_from_string(), router_load_routers_from_string(), router_pick_directory_server(), router_rebuild_store(), router_reset_descriptor_download_failures(), routerlist_add_network_family(), routerlist_find_my_routerinfo(), routerlist_free(), routerlist_free_all(), routerlist_remove_old_cached_routers_with_id(), routerlist_remove_old_routers(), and signed_descriptor_get_body_impl().
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] |
Map from v3 identity key digest to cert_list_t.
Referenced by authority_cert_dl_failed(), authority_cert_get_all(), authority_cert_get_by_digests(), authority_cert_get_by_sk_digest(), authority_cert_get_newest_by_id(), routerlist_free_all(), trusted_dirs_flush_certs_to_disk(), and trusted_dirs_remove_old_certs().
smartlist_t* trusted_dir_servers = NULL [static] |
Global list of a trusted_dir_server_t object for each trusted directory server.
Referenced by add_trusted_dir_server(), any_trusted_dir_is_v1_authority(), authority_certs_fetch_missing(), clear_trusted_dir_servers(), router_addr_is_trusted_dir(), router_digest_is_trusted_dir_type(), router_get_trusted_dir_servers(), router_get_trusteddirserver_by_digest(), router_pick_trusteddirserver_impl(), router_set_status(), routerlist_free_all(), trusteddirserver_get_by_v3_auth_digest(), and update_v2_networkstatus_cache_downloads().
int trusted_dir_servers_certs_changed = 0 [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().