#include "or.h"
#define AUTHORITY_NS_CACHE_INTERVAL (10*60) |
How frequently do directory authorities re-download fresh networkstatus documents?
Referenced by update_v2_networkstatus_cache_downloads().
#define CONSENSUS_MIN_SECONDS_BEFORE_CACHING 120 |
How long do we (as a cache) wait after a consensus becomes non-fresh before trying to fetch another?
Referenced by update_consensus_networkstatus_fetch_time().
#define CONSENSUS_NETWORKSTATUS_MAX_DL_TRIES 8 |
How many times will we try to fetch a consensus before we give up?
Referenced by update_consensus_networkstatus_downloads().
#define DELAY_WHILE_FETCHING_CERTS (20*60) |
How long will we hang onto a possibly live consensus for which we're fetching certs before we check whether there is a better one?
Referenced by update_consensus_networkstatus_downloads().
#define NETWORKSTATUS_ALLOW_SKEW (24*60*60) |
How far in the future do we allow a network-status to get before removing it? (seconds)
Referenced by router_set_networkstatus_v2().
#define NONAUTHORITY_NS_CACHE_INTERVAL (60*60) |
How frequently do non-authority directory caches re-download fresh networkstatus documents?
Referenced by update_v2_networkstatus_cache_downloads().
static int _compare_networkstatus_v2_published_on | ( | const void ** | _a, | |
const void ** | _b | |||
) | [static] |
Helper for smartlist_sort: Compare two networkstatus objects by publication date.
References networkstatus_v2_t::published_on.
static int add_networkstatus_to_cache | ( | const char * | s, | |
v2_networkstatus_source_t | source, | |||
networkstatus_v2_t * | ns | |||
) | [static] |
Add the parsed v2 networkstatus in ns (with original document in s) to the disk cache (and the in-memory directory server cache) as appropriate.
References directory_caches_v2_dir_info(), dirserv_set_cached_networkstatus_v2(), get_options(), networkstatus_v2_t::identity_digest, LD_FS, networkstatus_get_cache_filename(), networkstatus_v2_t::published_on, tor_free, and write_str_to_file().
Referenced by router_set_networkstatus_v2().
int compare_digest_to_routerstatus_entry | ( | const void * | _key, | |
const void ** | _member | |||
) |
Helper for bsearching a list of routerstatus_t pointers: compare a digest in the key to the identity digest of a routerstatus_t.
References DIGEST_LEN, and routerstatus_t::identity_digest.
Referenced by measured_bw_line_apply(), networkstatus_v2_find_entry(), networkstatus_vote_find_entry(), networkstatus_vote_find_entry_idx(), and router_get_consensus_status_by_id().
int consensus_is_waiting_for_certs | ( | void | ) |
Return 1 if we have a consensus but we don't have enough certificates to start using it yet.
References consensus_waiting_for_certs_t::consensus, and USABLE_CONSENSUS_FLAVOR.
Referenced by connection_edge_process_relay_cell_not_open().
document_signature_t* document_signature_dup | ( | const document_signature_t * | sig | ) |
Return a newly allocated copy of sig
References document_signature_t::signature, and document_signature_t::signature_len.
Referenced by networkstatus_add_detached_signatures().
void document_signature_free | ( | document_signature_t * | sig | ) |
Free all storage held in sig
References document_signature_t::signature, and tor_free.
Referenced by networkstatus_add_detached_signatures(), networkstatus_parse_vote_from_string(), networkstatus_vote_free(), and ns_detached_signatures_free().
static void download_status_map_update_from_v2_networkstatus | ( | void | ) | [static] |
Update v2_download_status_map to contain an entry for every router descriptor listed in the v2 networkstatuses.
References _tor_free(), digestmap_free(), digestmap_get(), digestmap_new(), digestmap_remove(), digestmap_set(), networkstatus_v2_list_has_changed, and v2_download_status_map.
Referenced by routers_update_all_from_networkstatus().
int getinfo_helper_networkstatus | ( | control_connection_t * | conn, | |
const char * | question, | |||
char ** | answer | |||
) |
If question is a string beginning with "ns/" in a format the control interface expects for a GETINFO question, set *answer to a newly-allocated string containing networkstatus lines for the appropriate ORs. Return 0 on success, -1 on unrecognized question format.
References networkstatus_getinfo_helper_single(), networkstatus_t::routerstatus_list, smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), and tor_free.
int networkstatus_check_consensus_signature | ( | networkstatus_t * | consensus, | |
int | warn | |||
) |
Given a v3 networkstatus consensus in consensus, check every as-yet-unchecked signature on consensus. Return 1 if there is a signature from every recognized authority on it, 0 if there are enough good signatures from recognized authorities on it, -1 if we might get enough good signatures by fetching missing certificates, and -2 otherwise. Log messages at INFO or WARN: if warn is over 1, warn about every problem; if warn is at least 1, warn only if we can't get enough signatures; if warn is negative, log nothing at all.
References authority_cert_get_by_digests(), DIGEST_LEN, authority_cert_t::expires, get_n_authorities(), hex_str(), LD_DIR, networkstatus_check_document_signature(), networkstatus_get_voter_by_id(), router_get_trusted_dir_servers(), smartlist_add(), smartlist_create(), smartlist_free(), tor_assert, trusteddirserver_get_by_v3_auth_digest(), networkstatus_t::type, V3_AUTHORITY, and networkstatus_t::voters.
Referenced by dirvote_compute_consensuses(), dirvote_fetch_missing_signatures(), dirvote_publish_consensus(), networkstatus_note_certs_arrived(), and networkstatus_set_current_consensus().
int networkstatus_check_document_signature | ( | const networkstatus_t * | consensus, | |
document_signature_t * | sig, | |||
const authority_cert_t * | cert | |||
) |
Check whether the signature sig is correctly signed with the signing key in cert. Return -1 if cert doesn't match the signing key; otherwise set the good_signature or bad_signature flag on voter, and return 0.
References document_signature_t::alg, document_signature_t::bad_signature, authority_cert_t::cache_info, crypto_pk_get_digest(), crypto_pk_keysize(), crypto_pk_public_checksig(), digests_t::d, DIGEST256_LEN, DIGEST_LEN, networkstatus_t::digests, document_signature_t::good_signature, signed_descriptor_t::identity_digest, document_signature_t::identity_digest, LD_DIR, document_signature_t::signature, document_signature_t::signature_len, authority_cert_t::signing_key, document_signature_t::signing_key_digest, and tor_free.
Referenced by networkstatus_add_detached_signatures(), and networkstatus_check_consensus_signature().
void networkstatus_consensus_download_failed | ( | int | status_code | ) |
Called when an attempt to download a consensus fails: note that the failure occurred, and possibly retry.
References download_status_failed, and update_consensus_networkstatus_downloads().
Referenced by connection_dir_client_reached_eof(), and connection_dir_request_failed().
static void networkstatus_copy_old_consensus_info | ( | networkstatus_t * | new_c, | |
const networkstatus_t * | old_c | |||
) | [static] |
Copy all the ancillary information (like router download status and so on) from old_c to new_c.
References DIGEST_LEN, and networkstatus_t::routerstatus_list.
Referenced by networkstatus_set_current_consensus().
void networkstatus_dump_bridge_status_to_file | ( | time_t | now | ) |
Write out router status entries for all our bridge descriptors.
References or_options_t::DataDirectory, get_options(), networkstatus_getinfo_by_purpose(), tor_free, tor_snprintf(), and write_str_to_file().
Referenced by run_scheduled_events().
void networkstatus_free_all | ( | void | ) |
Free all storage held locally in this module.
References _tor_free(), consensus_waiting_for_certs_t::body, consensus_waiting_for_certs_t::consensus, digestmap_free(), named_server_map, networkstatus_v2_free(), networkstatus_vote_free(), smartlist_free(), strmap_free(), tor_free, unnamed_server_map, and v2_download_status_map.
Referenced by tor_free_all().
int32_t networkstatus_get_bw_weight | ( | networkstatus_t * | ns, | |
const char * | weight_name, | |||
int32_t | default_val | |||
) |
Return the value of a integer bw weight parameter from the networkstatus ns whose name is weight_name. If ns is NULL, try loading the latest consensus ourselves. Return default_val if no latest consensus, or if it has no parameter called param_name.
References networkstatus_get_latest_consensus(), and networkstatus_t::weight_params.
Referenced by networkstatus_verify_bw_weights(), and smartlist_choose_by_bandwidth_weights().
char* networkstatus_get_cache_filename | ( | const char * | identity_digest | ) |
Helper: return a newly allocated string containing the name of the filename where we plan to cache the network status with the given identity digest.
References base16_encode(), DIGEST_LEN, get_datadir_fname2, and HEX_DIGEST_LEN.
Referenced by add_networkstatus_to_cache(), dirserv_clear_old_networkstatuses(), networkstatus_v2_list_clean(), and router_set_networkstatus_v2().
const char* networkstatus_get_flavor_name | ( | consensus_flavor_t | flav | ) |
Return the name of the consensus flavor flav as used to identify the flavor in directory documents.
References tor_fragile_assert.
Referenced by dirvote_add_signatures_to_pending_consensus(), dirvote_compute_consensuses(), dirvote_publish_consensus(), networkstatus_add_detached_signatures(), networkstatus_compute_consensus(), networkstatus_format_signatures(), networkstatus_get_detached_signatures(), networkstatus_note_certs_arrived(), networkstatus_set_current_consensus(), and router_reload_consensus_networkstatus().
networkstatus_t* networkstatus_get_latest_consensus | ( | void | ) |
Return the most recent consensus that we have downloaded, or NULL if we don't have one.
Referenced by directory_get_from_dirserver(), directory_handle_command_get(), getinfo_helper_events(), hid_serv_acting_as_directory(), hid_serv_get_responsible_directories(), networkstatus_get_bw_weight(), networkstatus_get_param(), options_act(), router_add_to_routerlist(), router_pick_directory_server_impl(), routerlist_remove_old_routers(), run_scheduled_events(), signed_desc_digest_is_recognized(), update_router_have_minimum_dir_info(), and upload_service_descriptor().
networkstatus_t* networkstatus_get_live_consensus | ( | time_t | now | ) |
Return the most recent consensus that we have downloaded, or NULL if it is no longer live.
References networkstatus_t::valid_after.
Referenced by dirvote_recalculate_timing(), routers_update_all_from_networkstatus(), update_consensus_networkstatus_downloads(), and update_consensus_networkstatus_fetch_time().
int32_t networkstatus_get_param | ( | networkstatus_t * | ns, | |
const char * | param_name, | |||
int32_t | default_val | |||
) |
Return the value of a integer parameter from the networkstatus ns whose name is param_name. If ns is NULL, try loading the latest consensus ourselves. Return default_val if no latest consensus, or if it has no parameter called param_name.
References networkstatus_t::net_params, and networkstatus_get_latest_consensus().
Referenced by cell_ewma_set_scale_factor(), circuit_build_times_new_consensus_params(), circuit_initial_package_window(), connection_or_init_conn_from_address(), networkstatus_verify_bw_weights(), and smartlist_choose_by_bandwidth_weights().
networkstatus_t* networkstatus_get_reasonably_live_consensus | ( | time_t | now | ) |
As networkstatus_get_live_consensus(), but is way more tolerant of expired consensuses.
References networkstatus_t::valid_after.
Referenced by count_loading_descriptors_progress(), update_router_descriptor_downloads(), and update_router_have_minimum_dir_info().
const char* networkstatus_get_router_digest_by_nickname | ( | const char * | nickname | ) |
Return the identity digest that's mapped to officially by nickname.
References named_server_map, and strmap_get_lc().
Referenced by router_get_by_nickname().
const smartlist_t* networkstatus_get_v2_list | ( | void | ) |
Return a list of the v2 networkstatus documents.
References smartlist_create().
Referenced by networkstatus_reset_download_failures(), router_add_to_routerlist(), routerlist_remove_old_routers(), signed_desc_digest_is_recognized(), and update_router_descriptor_cache_downloads_v2().
networkstatus_voter_info_t* networkstatus_get_voter_by_id | ( | networkstatus_t * | vote, | |
const char * | identity | |||
) |
Return the voter info from vote for the voter whose identity digest is identity, or NULL if no such voter is associated with vote.
References DIGEST_LEN, and networkstatus_t::voters.
Referenced by networkstatus_add_detached_signatures(), networkstatus_check_consensus_signature(), and networkstatus_parse_vote_from_string().
char* networkstatus_getinfo_by_purpose | ( | const char * | purpose_string, | |
time_t | now | |||
) |
Alloc and return a string describing routerstatuses for the most recent info of each router we know about that is of purpose purpose_string. Return NULL if unrecognized purpose.
Right now this function is oriented toward listing bridges (you shouldn't use this for general-purpose routers, since those should be listed from the consensus, not from the routers list).
References authdir_mode_bridge(), dirserv_set_router_is_running(), get_options(), LD_DIR, networkstatus_getinfo_helper_single(), router_get_routerlist(), ROUTER_MAX_AGE_TO_PUBLISH, ROUTER_PURPOSE_BRIDGE, router_purpose_from_string(), ROUTER_PURPOSE_UNKNOWN, routerlist_t::routers, set_routerstatus_from_routerinfo(), smartlist_add(), and smartlist_create().
Referenced by directory_handle_command_get(), and networkstatus_dump_bridge_status_to_file().
char* networkstatus_getinfo_helper_single | ( | routerstatus_t * | rs | ) |
Generate networkstatus lines for a single routerstatus_t object, and return the result in a newly allocated string. Used only by controller interface (for now.)
References routerstatus_format_entry(), and RS_ENTRY_LEN.
Referenced by control_event_networkstatus_changed_helper(), getinfo_helper_networkstatus(), and networkstatus_getinfo_by_purpose().
int networkstatus_nickname_is_unnamed | ( | const char * | nickname | ) |
Return true iff nickname is disallowed from being the nickname of any server.
References strmap_get_lc(), and unnamed_server_map.
Referenced by router_get_by_nickname().
void networkstatus_note_certs_arrived | ( | void | ) |
Called when we have gotten more certificates: see whether we can now verify a pending consensus.
References consensus_waiting_for_certs_t::body, consensus_waiting_for_certs_t::consensus, networkstatus_check_consensus_signature(), networkstatus_get_flavor_name(), networkstatus_set_current_consensus(), and tor_free.
Referenced by trusted_dirs_load_certs_from_string().
int networkstatus_parse_flavor_name | ( | const char * | flavname | ) |
Return the consensus_flavor_t value for the flavor called flavname, or -1 if the flavor is not recognized.
Referenced by networkstatus_parse_vote_from_string(), and networkstatus_set_current_consensus().
void networkstatus_reset_download_failures | ( | void | ) |
Reset the descriptor download failure count on all networkstatus docs, so that we can retry any long-failed documents immediately.
References networkstatus_get_v2_list(), and router_get_by_descriptor_digest().
Referenced by router_reset_descriptor_download_failures().
void networkstatus_reset_warnings | ( | void | ) |
Forget that we've warned about anything networkstatus-related, so we will give fresh warnings if the same behavior happens again.
References have_warned_about_new_version, have_warned_about_old_version, and networkstatus_t::routerstatus_list.
Referenced by routerlist_reset_warnings().
int networkstatus_set_current_consensus | ( | const char * | consensus, | |
const char * | flavor, | |||
unsigned | flags | |||
) |
Try to replace the current cached v3 networkstatus with the one in consensus. If we don't have enough certificates to validate it, store it in consensus_waiting_for_certs and launch a certificate fetch.
If flags & NSSET_FROM_CACHE, this networkstatus has come from the disk cache. If flags & NSSET_WAS_WAITING_FOR_CERTS, this networkstatus was already received, but we were waiting for certificates on it. If flags & NSSET_DONT_DOWNLOAD_CERTS, do not launch certificate downloads as needed. If flags & NSSET_ACCEPT_OBSOLETE, then we should be willing to take this consensus, even if it comes from many days in the past.
Return 0 on success, <0 on failure. On failure, caller should increment the failure count as appropriate.
We return -1 for mild failures that don't need to be reported to the user, and -2 for more serious problems.
References authority_certs_fetch_missing(), consensus_waiting_for_certs_t::body, cell_ewma_set_scale_factor(), circ_times, circuit_build_times_new_consensus_params(), consensus_waiting_for_certs_t::consensus, control_event_client_status(), control_event_general_status(), cached_dir_t::digests, networkstatus_t::digests, directory_caches_dir_info(), dirserv_get_consensus(), dirserv_set_cached_consensus_networkstatus(), dirvote_recalculate_timing(), consensus_waiting_for_certs_t::dl_failed, download_status_failed, download_status_reset(), networkstatus_t::flavor, format_iso_time(), format_time_interval(), ftime_definitely_before(), get_datadir_fname, get_options(), LD_BUG, LD_DIR, LD_GENERAL, networkstatus_check_consensus_signature(), networkstatus_copy_old_consensus_info(), networkstatus_get_flavor_name(), networkstatus_parse_flavor_name(), networkstatus_parse_vote_from_string(), networkstatus_vote_free(), notify_control_networkstatus_changed(), OLD_ROUTER_DESC_MAX_AGE, cached_dir_t::published, router_dir_info_changed(), routerstatus_list_update_named_server_map(), consensus_waiting_for_certs_t::set_at, tor_free, tor_snprintf(), update_consensus_networkstatus_fetch_time(), USABLE_CONSENSUS_FLAVOR, networkstatus_t::valid_after, networkstatus_t::valid_until, and write_str_to_file().
Referenced by connection_dir_client_reached_eof(), dirvote_publish_consensus(), networkstatus_note_certs_arrived(), and router_reload_consensus_networkstatus().
routerstatus_t* networkstatus_v2_find_entry | ( | networkstatus_v2_t * | ns, | |
const char * | digest | |||
) |
Return the entry in ns for the identity digest digest, or NULL if none was found.
References compare_digest_to_routerstatus_entry(), networkstatus_v2_t::entries, and smartlist_bsearch().
Referenced by router_add_to_routerlist(), and signed_desc_digest_is_recognized().
void networkstatus_v2_free | ( | networkstatus_v2_t * | ns | ) |
Free all storage held by the networkstatus object ns.
References networkstatus_v2_t::client_versions, networkstatus_v2_t::contact, crypto_free_pk_env(), networkstatus_v2_t::entries, routerstatus_free(), networkstatus_v2_t::server_versions, networkstatus_v2_t::signing_key, smartlist_free(), networkstatus_v2_t::source_address, and tor_free.
Referenced by networkstatus_free_all(), networkstatus_v2_list_clean(), networkstatus_v2_parse_from_string(), and router_set_networkstatus_v2().
networkstatus_v2_t* networkstatus_v2_get_by_digest | ( | const char * | digest | ) |
Return the network status with a given identity digest.
References DIGEST_LEN.
void networkstatus_v2_list_clean | ( | time_t | now | ) |
Remove all very-old network_status_t objects from memory and from the disk cache.
References directory_caches_v2_dir_info(), dirserv_clear_old_networkstatuses(), dirserv_clear_old_v1_info(), dirserv_set_cached_networkstatus_v2(), file_status(), get_options(), networkstatus_v2_t::identity_digest, LD_DIR, MAX_NETWORKSTATUS_AGE, networkstatus_get_cache_filename(), networkstatus_v2_free(), networkstatus_v2_t::published_on, smartlist_del(), and tor_free.
Referenced by router_reload_v2_networkstatus(), and run_scheduled_events().
routerstatus_t* networkstatus_vote_find_entry | ( | networkstatus_t * | ns, | |
const char * | digest | |||
) |
Return the entry in ns for the identity digest digest, or NULL if none was found.
References compare_digest_to_routerstatus_entry(), networkstatus_t::routerstatus_list, and smartlist_bsearch().
Referenced by hid_serv_acting_as_directory(), router_add_to_routerlist(), router_get_consensus_status_by_nickname(), and signed_desc_digest_is_recognized().
int networkstatus_vote_find_entry_idx | ( | networkstatus_t * | ns, | |
const char * | digest, | |||
int * | found_out | |||
) |
Search the routerstatuses in ns for one whose identity digest is digest. Return value and set *found_out as for smartlist_bsearch_idx().
References compare_digest_to_routerstatus_entry(), networkstatus_t::routerstatus_list, and smartlist_bsearch_idx().
Referenced by hid_serv_get_responsible_directories().
void networkstatus_vote_free | ( | networkstatus_t * | ns | ) |
Free all storage held in ns.
References authority_cert_free(), networkstatus_t::cert, networkstatus_t::client_versions, networkstatus_t::desc_digest_map, digestmap_free(), document_signature_free(), networkstatus_t::known_flags, networkstatus_t::net_params, routerstatus_free(), networkstatus_t::routerstatus_list, networkstatus_t::server_versions, smartlist_free(), networkstatus_t::supported_methods, tor_free, networkstatus_t::type, vote_routerstatus_free(), and networkstatus_t::voters.
Referenced by dirvote_add_signatures_to_pending_consensus(), dirvote_add_vote(), dirvote_clear_pending_consensuses(), dirvote_clear_votes(), dirvote_compute_consensuses(), dirvote_perform_vote(), format_networkstatus_vote(), networkstatus_free_all(), networkstatus_parse_vote_from_string(), and networkstatus_set_current_consensus().
static void notify_control_networkstatus_changed | ( | const networkstatus_t * | old_c, | |
const networkstatus_t * | new_c | |||
) | [static] |
Notify controllers of any router status entries that changed between old_c and new_c.
References control_event_is_interesting(), control_event_networkstatus_changed(), control_event_newconsensus(), DIGEST_LEN, routerstatus_has_changed(), networkstatus_t::routerstatus_list, smartlist_add(), smartlist_create(), and smartlist_free().
Referenced by networkstatus_set_current_consensus().
routerstatus_t* router_get_consensus_status_by_descriptor_digest | ( | const char * | digest | ) |
Return the consensus view of the status of the router whose current descriptor digest is digest, or NULL if no such router is known.
References networkstatus_t::desc_digest_map, digestmap_new(), digestmap_set(), and networkstatus_t::routerstatus_list.
Referenced by router_get_dl_status_by_descriptor_digest(), and signed_descs_update_status_from_consensus_networkstatus().
routerstatus_t* router_get_consensus_status_by_id | ( | const char * | digest | ) |
Return the consensus view of the status of the router whose identity digest is digest, or NULL if we don't know about any such router.
References compare_digest_to_routerstatus_entry(), networkstatus_t::routerstatus_list, and smartlist_bsearch().
Referenced by circuit_list_path_impl(), connection_dir_client_reached_eof(), connection_or_digest_is_known_relay(), router_get_my_share_of_directory_requests(), router_set_status(), router_supports_extrainfo(), smartlist_choose_by_bandwidth(), and smartlist_choose_by_bandwidth_weights().
routerstatus_t* router_get_consensus_status_by_nickname | ( | const char * | nickname, | |
int | warn_if_unnamed | |||
) |
Given a nickname (possibly verbose, possibly a hexadecimal digest), return the corresponding routerstatus_t, or NULL if none exists. Warn the user if warn_if_unnamed is set, and they have specified a router by nickname, but the Named flag isn't set for that router.
References base16_decode(), DIGEST_LEN, escaped(), HEX_DIGEST_LEN, LD_GENERAL, named_server_map, networkstatus_vote_find_entry(), networkstatus_t::routerstatus_list, smartlist_create(), smartlist_free(), strmap_get_lc(), tor_fragile_assert, and unnamed_server_map.
Referenced by add_nickname_list_to_smartlist().
download_status_t* router_get_dl_status_by_descriptor_digest | ( | const char * | d | ) |
Given the digest of a router descriptor, return its current download status, or NULL if the digest is unrecognized.
References digestmap_get(), routerstatus_t::dl_status, router_get_consensus_status_by_descriptor_digest(), and v2_download_status_map.
Referenced by dir_routerdesc_download_failed(), and router_load_routers_from_string().
int router_reload_consensus_networkstatus | ( | void | ) |
Read every cached v3 consensus networkstatus from the disk.
References get_datadir_fname, get_options(), LD_FS, named_server_map, networkstatus_get_flavor_name(), networkstatus_set_current_consensus(), read_file_to_str(), RFTS_IGNORE_MISSING, routers_update_all_from_networkstatus(), tor_free, tor_snprintf(), unnamed_server_map, update_certificate_downloads(), and networkstatus_t::valid_after.
Referenced by do_main_loop().
int router_reload_v2_networkstatus | ( | void | ) |
Repopulate our list of network_status_t objects from the list cached on disk. Return 0 on success, -1 on failure.
References base16_decode(), DIGEST_LEN, directory_caches_v2_dir_info(), get_datadir_fname, get_datadir_fname2, get_options(), HEX_DIGEST_LEN, LD_DIR, LD_FS, networkstatus_v2_list_clean(), read_file_to_str(), remove_file_if_very_old(), router_set_networkstatus_v2(), routers_update_all_from_networkstatus(), smartlist_create(), smartlist_free(), tor_free, and tor_listdir().
Referenced by do_main_loop().
int router_set_networkstatus_v2 | ( | const char * | s, | |
time_t | arrived_at, | |||
v2_networkstatus_source_t | source, | |||
smartlist_t * | requested_fingerprints | |||
) |
Given a string s containing a network status that we received at arrived_at from source, try to parse it, see if we want to store it, and put it into our cache as necessary.
If source is NS_FROM_DIR or NS_FROM_CACHE, do not replace our own networkstatus_t (if we're an authoritative directory server).
If source is NS_FROM_CACHE, do not write our networkstatus_t to the cache.
If requested_fingerprints is provided, it must contain a list of uppercased identity fingerprints. Do not update any networkstatus whose fingerprint is not on the list; after updating a networkstatus, remove its fingerprint from the list.
Return 0 on success, -1 on failure.
Callers should make sure that routers_update_all_from_networkstatus() is invoked after this function succeeds.
Retain any routerinfo mentioned in a V2 networkstatus for at least this long.
References add_networkstatus_to_cache(), base16_encode(), control_event_general_status(), trusted_dir_server_t::description, DIGEST_LEN, directory_caches_v2_dir_info(), download_status_failed, download_status_reset(), networkstatus_v2_t::entries, format_iso_time(), format_time_interval(), get_options(), HEX_DIGEST_LEN, networkstatus_v2_t::identity_digest, signed_descriptor_t::last_listed_as_valid_until, LD_DIR, LD_GENERAL, NETWORKSTATUS_ALLOW_SKEW, networkstatus_v2_t::networkstatus_digest, networkstatus_get_cache_filename(), networkstatus_v2_free(), networkstatus_v2_parse_from_string(), networkstatus_v2_t::published_on, networkstatus_v2_t::received_on, router_digest_is_me(), router_get_by_descriptor_digest(), router_get_trusteddirserver_by_digest(), smartlist_add(), smartlist_create(), smartlist_join_strings(), smartlist_string_isin(), smartlist_string_remove(), networkstatus_v2_t::source_address, networkstatus_v2_t::source_dirport, tor_assert, tor_free, touch_file(), trusted_dir_server_t::type, V2_AUTHORITY, and trusted_dir_server_t::v2_ns_dl_status.
Referenced by connection_dir_client_reached_eof(), and router_reload_v2_networkstatus().
void routers_update_all_from_networkstatus | ( | time_t | now, | |
int | dir_version | |||
) |
If the network-status list has changed since the last time we called this function, update the status of every routerinfo from the network-status list. If dir_version is 2, it's a v2 networkstatus that changed. If dir_version is 3, it's a v3 consensus that changed.
References networkstatus_t::client_versions, control_event_general_status(), download_status_map_update_from_v2_networkstatus(), get_options(), have_warned_about_new_version, have_warned_about_old_version, LD_GENERAL, networkstatus_get_live_consensus(), networkstatus_v2_list_has_changed, routerlist_t::old_routers, router_get_routerlist(), routerlist_t::routers, routers_update_status_from_consensus_networkstatus(), server_mode(), networkstatus_t::server_versions, signed_descs_update_status_from_consensus_networkstatus(), tor_version_is_obsolete(), VS_EMPTY, VS_NEW, VS_NEW_IN_SERIES, VS_OLD, and VS_RECOMMENDED.
Referenced by connection_dir_client_reached_eof(), router_reload_consensus_networkstatus(), and router_reload_v2_networkstatus().
void routers_update_status_from_consensus_networkstatus | ( | smartlist_t * | routers, | |
int | reset_failures | |||
) |
Given a list routers of routerinfo_t *, update each status field according to our current consensus networkstatus. May re-order routers.
References authdir_mode_v2(), authdir_mode_v3(), DIGEST_LEN, get_options(), or_options_t::NamingAuthoritativeDir, router_clear_status_flags(), ROUTER_PURPOSE_GENERAL, routers_sort_by_identity(), networkstatus_t::routerstatus_list, and smartlist_create().
Referenced by router_load_routers_from_string(), router_load_single_router(), and routers_update_all_from_networkstatus().
void routerstatus_free | ( | routerstatus_t * | rs | ) |
Free all storage held by the routerstatus object rs.
References routerstatus_t::exitsummary, and tor_free.
Referenced by _free_duplicate_routerstatus_entry(), networkstatus_v2_free(), networkstatus_vote_free(), and routerstatus_parse_entry_from_string().
static int routerstatus_has_changed | ( | const routerstatus_t * | a, | |
const routerstatus_t * | b | |||
) | [static] |
Given two router status entries for the same router identity, return 1 if if the contents have changed between them. Otherwise, return 0.
References routerstatus_t::addr, routerstatus_t::descriptor_digest, DIGEST_LEN, routerstatus_t::dir_port, routerstatus_t::identity_digest, routerstatus_t::is_authority, routerstatus_t::is_bad_directory, routerstatus_t::is_bad_exit, routerstatus_t::is_exit, routerstatus_t::is_fast, routerstatus_t::is_hs_dir, routerstatus_t::is_named, routerstatus_t::is_possible_guard, routerstatus_t::is_running, routerstatus_t::is_stable, routerstatus_t::is_unnamed, routerstatus_t::is_v2_dir, routerstatus_t::is_valid, routerstatus_t::nickname, routerstatus_t::or_port, tor_assert, routerstatus_t::version_known, routerstatus_t::version_supports_begindir, routerstatus_t::version_supports_conditional_consensus, routerstatus_t::version_supports_extrainfo_upload, and routerstatus_t::version_supports_v3_dir.
Referenced by notify_control_networkstatus_changed().
static void routerstatus_list_update_named_server_map | ( | void | ) | [static] |
Update our view of the list of named servers from the most recently retrieved networkstatus consensus.
References _tor_free(), DIGEST_LEN, named_server_map, networkstatus_t::routerstatus_list, strmap_free(), strmap_set_lc(), and unnamed_server_map.
Referenced by networkstatus_set_current_consensus().
int should_delay_dir_fetches | ( | or_options_t * | options | ) |
Return 1 if there's a reason we shouldn't try any directory fetches yet (e.g. we demand bridges and none are yet known). Else return 0.
References any_bridge_descriptors_known(), LD_DIR, and or_options_t::UseBridges.
Referenced by authority_certs_fetch_missing(), update_extrainfo_downloads(), update_networkstatus_downloads(), update_router_descriptor_downloads(), and update_router_have_minimum_dir_info().
void signed_descs_update_status_from_consensus_networkstatus | ( | smartlist_t * | descs | ) |
Given a list of signed_descriptor_t, update their fields (mainly, when they were last listed) from the most recent consensus.
References networkstatus_t::desc_digest_map, DIGEST_LEN, digestmap_get(), router_get_consensus_status_by_descriptor_digest(), and networkstatus_t::valid_until.
Referenced by routers_update_all_from_networkstatus().
void update_certificate_downloads | ( | time_t | now | ) |
Launch requests as appropriate for missing directory authority certificates.
References authority_certs_fetch_missing().
Referenced by connection_dir_download_cert_failed(), router_reload_consensus_networkstatus(), and update_networkstatus_downloads().
static void update_consensus_networkstatus_downloads | ( | time_t | now | ) | [static] |
If we want to download a fresh consensus, launch a new download as appropriate.
References authdir_mode_v3(), CONN_TYPE_DIR, connection_get_by_type_purpose(), consensus_waiting_for_certs_t::consensus, CONSENSUS_NETWORKSTATUS_MAX_DL_TRIES, DELAY_WHILE_FETCHING_CERTS, DIR_PURPOSE_FETCH_CONSENSUS, directory_get_from_dirserver(), consensus_waiting_for_certs_t::dl_failed, download_status_failed, download_status_is_ready(), get_options(), LD_DIR, networkstatus_get_live_consensus(), PDS_RETRY_IF_NO_SERVERS, ROUTER_PURPOSE_GENERAL, consensus_waiting_for_certs_t::set_at, and time_to_download_next_consensus.
Referenced by networkstatus_consensus_download_failed(), and update_networkstatus_downloads().
void update_consensus_networkstatus_fetch_time | ( | time_t | now | ) |
Update the time at which we'll consider replacing the current consensus.
References CONSENSUS_MIN_SECONDS_BEFORE_CACHING, crypto_rand_int(), directory_fetches_dir_info_early(), directory_fetches_dir_info_later(), or_options_t::FetchDirInfoExtraEarly, format_local_iso_time(), networkstatus_t::fresh_until, get_options(), LD_DIR, networkstatus_get_live_consensus(), time_to_download_next_consensus, tor_assert, networkstatus_t::valid_after, and networkstatus_t::valid_until.
Referenced by networkstatus_set_current_consensus(), and options_act().
void update_networkstatus_downloads | ( | time_t | now | ) |
Launch requests for networkstatus documents and authority certificates as appropriate.
References directory_fetches_dir_info_early(), get_options(), should_delay_dir_fetches(), update_certificate_downloads(), update_consensus_networkstatus_downloads(), and update_v2_networkstatus_cache_downloads().
Referenced by do_hup(), routerlist_retry_directory_downloads(), and run_scheduled_events().
static void update_v2_networkstatus_cache_downloads | ( | time_t | now | ) | [static] |
We are a directory server, and so cache network_status documents. Initiate downloads as needed to update them. For v2 authorities, this means asking each trusted directory for its network-status. For caches, this means asking a random v2 authority for all network-statuses.
References tor_addr_t::addr, authdir_mode_v2(), AUTHORITY_NS_CACHE_INTERVAL, base16_encode(), CONN_TYPE_DIR, connection_get_by_type_addr_port_purpose(), connection_get_by_type_purpose(), DIGEST_LEN, DIR_PURPOSE_FETCH_V2_NETWORKSTATUS, directory_get_from_dirserver(), directory_initiate_command_routerstatus(), get_options(), HEX_DIGEST_LEN, last_networkstatus_download_attempted, NONAUTHORITY_NS_CACHE_INTERVAL, PDS_RETRY_IF_NO_SERVERS, router_digest_is_me(), router_get_trusted_dir_servers(), ROUTER_PURPOSE_GENERAL, tor_addr_from_ipv4h, trusted_dir_servers, and V2_AUTHORITY.
Referenced by update_networkstatus_downloads().
static void vote_routerstatus_free | ( | vote_routerstatus_t * | rs | ) | [static] |
Free all storage held by the vote_routerstatus object rs.
References routerstatus_t::exitsummary, vote_routerstatus_t::microdesc, vote_routerstatus_t::status, tor_free, and vote_routerstatus_t::version.
Referenced by networkstatus_vote_free().
download_status_t consensus_dl_status[N_CONSENSUS_FLAVORS] [static] |
Download status for the current consensus networkstatus.
networkstatus_t* current_consensus = NULL [static] |
Most recently received and validated v3 consensus network status.
int have_warned_about_new_version = 0 [static] |
True iff we have logged a warning about this OR's version being newer than listed by the authorities.
Referenced by networkstatus_reset_warnings(), and routers_update_all_from_networkstatus().
int have_warned_about_old_version = 0 [static] |
True iff we have logged a warning about this OR's version being older than listed by the authorities.
Referenced by networkstatus_reset_warnings(), and routers_update_all_from_networkstatus().
time_t last_networkstatus_download_attempted = 0 [static] |
The last time we tried to download a networkstatus, or 0 for "never". We use this to rate-limit download attempts for directory caches (including mirrors). Clients don't use this now.
Referenced by update_v2_networkstatus_cache_downloads().
strmap_t* named_server_map = NULL [static] |
Map from lowercase nickname to identity digest of named server, if any.
Referenced by networkstatus_free_all(), networkstatus_get_router_digest_by_nickname(), router_get_consensus_status_by_nickname(), router_reload_consensus_networkstatus(), and routerstatus_list_update_named_server_map().
smartlist_t* networkstatus_v2_list = NULL [static] |
Global list of all of the current v2 network_status documents that we know about. This list is kept sorted by published_on.
Referenced by router_add_to_routerlist(), routerlist_remove_old_routers(), signed_desc_digest_is_recognized(), and update_router_descriptor_cache_downloads_v2().
int networkstatus_v2_list_has_changed = 0 [static] |
True iff any member of networkstatus_v2_list has changed since the last time we called download_status_map_update_from_v2_networkstatus()
Referenced by download_status_map_update_from_v2_networkstatus(), and routers_update_all_from_networkstatus().
time_t time_to_download_next_consensus = 0 [static] |
A time before which we shouldn't try to replace the current consensus: this will be at some point after the next consensus becomes valid, but before the current consensus becomes invalid.
Referenced by update_consensus_networkstatus_downloads(), and update_consensus_networkstatus_fetch_time().
strmap_t* unnamed_server_map = NULL [static] |
Map from lowercase nickname to (void*)1 for all names that are listed as unnamed for some server in the consensus.
Referenced by networkstatus_free_all(), networkstatus_nickname_is_unnamed(), router_get_consensus_status_by_nickname(), router_reload_consensus_networkstatus(), and routerstatus_list_update_named_server_map().
digestmap_t* v2_download_status_map = NULL [static] |
Map from descriptor digest of routers listed in the v2 networkstatus documents to download_status_t*
Referenced by download_status_map_update_from_v2_networkstatus(), networkstatus_free_all(), and router_get_dl_status_by_descriptor_digest().