#include "or.h"
Data Structures | |
struct | router_status_t |
struct | authdir_config_t |
Defines | |
#define | DIRSERV_PRIVATE |
#define | ROUTER_ALLOW_SKEW (60*60*12) |
#define | DIR_REGEN_SLACK_TIME 30 |
#define | MAX_UNTRUSTED_NETWORKSTATUSES 16 |
#define | MAX_V1_DIRECTORY_AGE (30*24*60*60) |
#define | MAX_V1_RR_AGE (7*24*60*60) |
#define | MAX_MEASUREMENT_AGE (3*24*60*60) |
#define | FP_NAMED 1 |
#define | FP_INVALID 2 |
#define | FP_REJECT 4 |
#define | FP_BADDIR 8 |
#define | FP_BADEXIT 16 |
#define | FP_UNNAMED 32 |
#define | STUB_REGENERATE_INTERVAL (8*60*60) |
#define | REACHABLE_TIMEOUT (45*60) |
#define | UPTIME_TO_GUARANTEE_STABLE (3600*24*30) |
#define | MTBF_TO_GUARANTEE_STABLE (60*60*24*5) |
#define | BANDWIDTH_TO_GUARANTEE_FAST ROUTER_REQUIRED_MIN_BANDWIDTH |
#define | BANDWIDTH_TO_GUARANTEE_GUARD (250*1024) |
#define | TIME_KNOWN_TO_GUARANTEE_FAMILIAR (8*24*60*60) |
#define | WFU_TO_GUARANTEE_GUARD (0.995) |
#define | V_LINE_OVERHEAD 7 |
#define | DIRSERV_BUFFER_MIN 16384 |
Functions | |
static void | directory_remove_invalid (void) |
static cached_dir_t * | dirserv_regenerate_directory (void) |
static char * | format_versions_list (config_line_t *ln) |
static int | add_fingerprint_to_dir (const char *nickname, const char *fp, struct authdir_config_t *list) |
static uint32_t | dirserv_router_get_status (const routerinfo_t *router, const char **msg) |
static uint32_t | dirserv_get_status_impl (const char *fp, const char *nickname, const char *address, uint32_t addr, uint16_t or_port, const char *platform, const char *contact, const char **msg, int should_log) |
static void | clear_cached_dir (cached_dir_t *d) |
static signed_descriptor_t * | get_signed_descriptor_by_fp (const char *fp, int extrainfo, time_t publish_cutoff) |
static int | dirserv_add_extrainfo (extrainfo_t *ei, const char **msg) |
static authdir_config_t * | authdir_config_new (void) |
int | dirserv_add_own_fingerprint (const char *nickname, crypto_pk_env_t *pk) |
int | dirserv_load_fingerprint_file (void) |
int | dirserv_would_reject_router (routerstatus_t *rs) |
static uint32_t | dirserv_get_name_status (const char *id_digest, const char *nickname) |
const char * | dirserv_get_nickname_by_digest (const char *digest) |
void | dirserv_free_fingerprint_list (void) |
static int | dirserv_router_has_valid_address (routerinfo_t *ri) |
int | authdir_wants_to_reject_router (routerinfo_t *ri, const char **msg, int complain) |
static int | WRA_MORE_SEVERE (was_router_added_t a, was_router_added_t b) |
was_router_added_t | dirserv_add_multiple_descriptors (const char *desc, uint8_t purpose, const char *source, const char **msg) |
was_router_added_t | dirserv_add_descriptor (routerinfo_t *ri, const char **msg, const char *source) |
void | directory_set_dirty (void) |
static char * | list_single_server_status (routerinfo_t *desc, int is_live) |
static INLINE int | running_long_enough_to_decide_unreachable (void) |
void | dirserv_set_router_is_running (routerinfo_t *router, time_t now) |
int | list_server_status_v1 (smartlist_t *routers, char **router_status_out, int for_controller) |
static int | router_is_active (routerinfo_t *ri, time_t now) |
int | dirserv_dump_directory_to_string (char **dir_out, crypto_pk_env_t *private_key) |
int | directory_fetches_from_authorities (or_options_t *options) |
int | directory_fetches_dir_info_early (or_options_t *options) |
int | directory_fetches_dir_info_later (or_options_t *options) |
int | directory_caches_v2_dir_info (or_options_t *options) |
int | directory_caches_dir_info (or_options_t *options) |
int | directory_permits_begindir_requests (or_options_t *options) |
int | directory_permits_controller_requests (or_options_t *options) |
int | directory_too_idle_to_fetch_descriptors (or_options_t *options, time_t now) |
static void | set_cached_dir (cached_dir_t *d, char *directory, time_t when) |
void | cached_dir_decref (cached_dir_t *d) |
cached_dir_t * | new_cached_dir (char *s, time_t published) |
static void | _free_cached_dir (void *_d) |
void | dirserv_set_cached_directory (const char *directory, time_t published, int is_running_routers) |
void | dirserv_set_cached_networkstatus_v2 (const char *networkstatus, const char *identity, time_t published) |
void | dirserv_set_cached_consensus_networkstatus (const char *networkstatus, const char *flavor_name, const digests_t *digests, time_t published) |
void | dirserv_clear_old_networkstatuses (time_t cutoff) |
void | dirserv_clear_old_v1_info (time_t now) |
static cached_dir_t * | dirserv_pick_cached_dir_obj (cached_dir_t *cache_src, cached_dir_t *auth_src, time_t dirty, cached_dir_t *(*regenerate)(void), const char *name, authority_type_t auth_type) |
cached_dir_t * | dirserv_get_directory (void) |
static cached_dir_t * | generate_runningrouters (void) |
cached_dir_t * | dirserv_get_runningrouters (void) |
cached_dir_t * | dirserv_get_consensus (const char *flavor_name) |
static int | should_generate_v2_networkstatus (void) |
static INLINE long | real_uptime (routerinfo_t *router, time_t now) |
static int | dirserv_thinks_router_is_unreliable (time_t now, routerinfo_t *router, int need_uptime, int need_capacity) |
static int | dirserv_thinks_router_is_hs_dir (routerinfo_t *router, time_t now) |
static void | dirserv_compute_performance_thresholds (routerlist_t *rl) |
static char * | version_from_platform (const char *platform) |
int | routerstatus_format_entry (char *buf, size_t buf_len, routerstatus_t *rs, const char *version, routerstatus_format_type_t format) |
static int | _compare_routerinfo_by_ip_and_bw (const void **a, const void **b) |
static digestmap_t * | get_possible_sybil_list (const smartlist_t *routers) |
void | set_routerstatus_from_routerinfo (routerstatus_t *rs, routerinfo_t *ri, time_t now, int naming, int exits_can_be_guards, int listbadexits, int listbaddirs) |
static void | clear_status_flags_on_sybil (routerstatus_t *rs) |
void | router_clear_status_flags (routerinfo_t *router) |
int | measured_bw_line_parse (measured_bw_line_t *out, const char *orig_line) |
int | measured_bw_line_apply (measured_bw_line_t *parsed_line, smartlist_t *routerstatuses) |
int | dirserv_read_measured_bandwidths (const char *from_file, smartlist_t *routerstatuses) |
networkstatus_t * | dirserv_generate_networkstatus_vote_obj (crypto_pk_env_t *private_key, authority_cert_t *cert) |
static cached_dir_t * | generate_v2_networkstatus_opinion (void) |
void | dirserv_get_networkstatus_v2_fingerprints (smartlist_t *result, const char *key) |
void | dirserv_get_networkstatus_v2 (smartlist_t *result, const char *key) |
int | dirserv_get_routerdesc_fingerprints (smartlist_t *fps_out, const char *key, const char **msg, int for_unencrypted_conn, int is_extrainfo) |
int | dirserv_get_routerdescs (smartlist_t *descs_out, const char *key, const char **msg) |
void | dirserv_orconn_tls_done (const char *address, uint16_t or_port, const char *digest_rcvd, int as_advertised) |
void | dirserv_single_reachability_test (time_t now, routerinfo_t *router) |
void | dirserv_test_reachability (time_t now) |
static cached_dir_t * | lookup_cached_dir_by_fp (const char *fp) |
int | dirserv_remove_old_statuses (smartlist_t *fps, time_t cutoff) |
int | dirserv_have_any_serverdesc (smartlist_t *fps, int spool_src) |
int | dirserv_have_any_microdesc (const smartlist_t *fps) |
size_t | dirserv_estimate_data_size (smartlist_t *fps, int is_serverdescs, int compressed) |
size_t | dirserv_estimate_microdesc_size (const smartlist_t *fps, int compressed) |
static int | connection_dirserv_finish_spooling (dir_connection_t *conn) |
static int | connection_dirserv_add_servers_to_outbuf (dir_connection_t *conn) |
static int | connection_dirserv_add_microdescs_to_outbuf (dir_connection_t *conn) |
static int | connection_dirserv_add_dir_bytes_to_outbuf (dir_connection_t *conn) |
static int | connection_dirserv_add_networkstatus_bytes_to_outbuf (dir_connection_t *conn) |
int | connection_dirserv_flushed_some (dir_connection_t *conn) |
void | dirserv_free_all (void) |
Variables | |
time_t | time_of_process_start |
static time_t | the_directory_is_dirty = 1 |
static time_t | runningrouters_is_dirty = 1 |
static time_t | the_v2_networkstatus_is_dirty = 1 |
static cached_dir_t * | the_directory = NULL |
static cached_dir_t | the_runningrouters |
static authdir_config_t * | fingerprint_list = NULL |
static cached_dir_t * | cached_directory = NULL |
static cached_dir_t | cached_runningrouters |
static digestmap_t * | cached_v2_networkstatus = NULL |
static strmap_t * | cached_consensuses = NULL |
static cached_dir_t * | the_v2_networkstatus = NULL |
static uint32_t | stable_uptime = 0 |
static double | stable_mtbf = 0.0 |
static int | enough_mtbf_info = 0 |
static double | guard_wfu = 0.0 |
static long | guard_tk = 0 |
static uint32_t | fast_bandwidth = 0 |
static uint32_t | guard_bandwidth_including_exits = 0 |
static uint32_t | guard_bandwidth_excluding_exits = 0 |
static uint64_t | total_bandwidth = 0 |
static uint64_t | total_exit_bandwidth = 0 |
#define BANDWIDTH_TO_GUARANTEE_FAST ROUTER_REQUIRED_MIN_BANDWIDTH |
Similarly, we protect sufficiently fast nodes from being pushed out of the set of Fast nodes.
#define BANDWIDTH_TO_GUARANTEE_GUARD (250*1024) |
Similarly, every node with sufficient bandwidth can be considered for Guard status.
Referenced by set_routerstatus_from_routerinfo().
#define DIR_REGEN_SLACK_TIME 30 |
How many seconds do we wait before regenerating the directory?
Referenced by dirserv_pick_cached_dir_obj(), and should_generate_v2_networkstatus().
#define DIRSERV_BUFFER_MIN 16384 |
When we're spooling data onto our outbuf, add more whenever we dip below this threshold.
Referenced by connection_dirserv_add_dir_bytes_to_outbuf(), connection_dirserv_add_microdescs_to_outbuf(), connection_dirserv_add_networkstatus_bytes_to_outbuf(), connection_dirserv_add_servers_to_outbuf(), and connection_dirserv_flushed_some().
#define FP_BADDIR 8 |
We'll tell clients to avoid using this as a dir.
Referenced by add_fingerprint_to_dir(), authdir_wants_to_reject_router(), directory_remove_invalid(), and dirserv_get_status_impl().
#define FP_BADEXIT 16 |
We'll tell clients not to use this as an exit.
Referenced by add_fingerprint_to_dir(), authdir_wants_to_reject_router(), directory_remove_invalid(), and dirserv_get_status_impl().
#define FP_INVALID 2 |
Believed invalid.
Referenced by add_fingerprint_to_dir(), authdir_wants_to_reject_router(), directory_remove_invalid(), and dirserv_get_status_impl().
#define FP_NAMED 1 |
Listed in fingerprint file.
Referenced by add_fingerprint_to_dir(), authdir_wants_to_reject_router(), directory_remove_invalid(), dirserv_get_name_status(), dirserv_get_status_impl(), and set_routerstatus_from_routerinfo().
#define FP_REJECT 4 |
We will not publish this router.
Referenced by add_fingerprint_to_dir(), authdir_wants_to_reject_router(), directory_remove_invalid(), dirserv_get_status_impl(), dirserv_router_get_status(), and dirserv_would_reject_router().
#define FP_UNNAMED 32 |
Another router has this name in fingerprint file.
Referenced by dirserv_get_name_status(), dirserv_get_status_impl(), and set_routerstatus_from_routerinfo().
#define MAX_UNTRUSTED_NETWORKSTATUSES 16 |
If we're a cache, keep this many networkstatuses around from non-trusted directory authorities.
Referenced by dirserv_set_cached_networkstatus_v2().
#define MAX_V1_DIRECTORY_AGE (30*24*60*60) |
If a v1 directory is older than this, discard it.
Referenced by dirserv_clear_old_v1_info(), and dirserv_set_cached_directory().
#define MAX_V1_RR_AGE (7*24*60*60) |
If a v1 running-routers is older than this, discard it.
Referenced by dirserv_clear_old_v1_info(), and dirserv_set_cached_directory().
#define MTBF_TO_GUARANTEE_STABLE (60*60*24*5) |
If a router's MTBF is at least this value, then it is always stable. See above. (Corresponds to about 7 days for current decay rates.)
Referenced by dirserv_thinks_router_is_unreliable().
#define REACHABLE_TIMEOUT (45*60) |
Each server needs to have passed a reachability test no more than this number of seconds ago, or he is listed as down in the directory.
Referenced by dirserv_set_router_is_running().
#define ROUTER_ALLOW_SKEW (60*60*12) |
How far in the future do we allow a router to get? (seconds)
Referenced by authdir_wants_to_reject_router().
#define TIME_KNOWN_TO_GUARANTEE_FAMILIAR (8*24*60*60) |
Similarly, every node with at least this much weighted time known can be considered familiar enough to be a guard. Corresponds to about 20 days for current decay rates.
#define UPTIME_TO_GUARANTEE_STABLE (3600*24*30) |
If a router's uptime is at least this value, then it is always considered stable, regardless of the rest of the network. This way we resist attacks where an attacker doubles the size of the network using allegedly high-uptime nodes, displacing all the current guards.
Referenced by dirserv_thinks_router_is_unreliable().
#define WFU_TO_GUARANTEE_GUARD (0.995) |
Similarly, every node with sufficient WFU is around enough to be a guard.
static int _compare_routerinfo_by_ip_and_bw | ( | const void ** | a, | |
const void ** | b | |||
) | [static] |
Helper for sorting: compares two routerinfos first by address, and then by descending order of "usefulness". (An authority is more useful than a non-authority; a running router is more useful than a non-running router; and a router with more bandwidth is more useful than one with less.)
References routerinfo_t::addr, routerinfo_t::cache_info, DIGEST_LEN, signed_descriptor_t::identity_digest, routerinfo_t::is_running, and router_get_advertised_bandwidth().
Referenced by get_possible_sybil_list().
static void _free_cached_dir | ( | void * | _d | ) | [static] |
Free all storage held by the cached_dir_t in d.
References cached_dir_decref().
Referenced by dirserv_free_all().
int add_fingerprint_to_dir | ( | const char * | nickname, | |
const char * | fp, | |||
authdir_config_t * | list | |||
) | [static] |
Add the fingerprint fp for nickname to the smartlist of fingerprint_entry_t's list. Return 0 if it's new, or 1 if we replaced the old value.
References base16_decode(), DIGEST_LEN, digestmap_get(), digestmap_set(), escaped(), FP_BADDIR, FP_BADEXIT, authdir_config_t::fp_by_name, FP_INVALID, FP_NAMED, FP_REJECT, LD_DIRSERV, router_status_t::nickname, router_status_t::status, authdir_config_t::status_by_digest, strmap_get_lc(), strmap_set_lc(), tor_assert, tor_free, and tor_strstrip().
Referenced by dirserv_add_own_fingerprint(), and dirserv_load_fingerprint_file().
static authdir_config_t* authdir_config_new | ( | void | ) | [static] |
Allocate and return a new, empty, authdir_config_t.
References digestmap_new(), authdir_config_t::fp_by_name, and authdir_config_t::status_by_digest.
Referenced by dirserv_add_own_fingerprint(), dirserv_get_status_impl(), and dirserv_load_fingerprint_file().
int authdir_wants_to_reject_router | ( | routerinfo_t * | ri, | |
const char ** | msg, | |||
int | complain | |||
) |
Check whether we, as a directory server, want to accept ri. If so, set its is_valid,named,running fields and return 0. Otherwise, return -1.
If the router is rejected, set *msg to an explanation of why.
If complain then explain at log-level 'notice' why we refused a descriptor; else explain at log-level 'info'.
References routerinfo_t::address, routerinfo_t::cache_info, routerinfo_t::contact_info, dirserv_router_get_status(), dirserv_router_has_valid_address(), esc_router_info(), FP_BADDIR, FP_BADEXIT, FP_INVALID, FP_NAMED, FP_REJECT, routerinfo_t::is_bad_directory, routerinfo_t::is_bad_exit, routerinfo_t::is_named, routerinfo_t::is_valid, LD_DIRSERV, routerinfo_t::nickname, signed_descriptor_t::published_on, ROUTER_ALLOW_SKEW, ROUTER_MAX_AGE_TO_PUBLISH, and tor_assert.
Referenced by router_add_to_routerlist().
void cached_dir_decref | ( | cached_dir_t * | d | ) |
Decrement the reference count on d, and free it if it no longer has any references.
References clear_cached_dir(), cached_dir_t::refcnt, and tor_free.
Referenced by _connection_free(), _free_cached_dir(), connection_dirserv_add_dir_bytes_to_outbuf(), dirserv_clear_old_networkstatuses(), dirserv_clear_old_v1_info(), dirserv_free_all(), dirserv_regenerate_directory(), dirserv_set_cached_consensus_networkstatus(), dirserv_set_cached_directory(), dirserv_set_cached_networkstatus_v2(), dirvote_add_vote(), and dirvote_clear_votes().
static void clear_cached_dir | ( | cached_dir_t * | d | ) | [static] |
Remove all storage held in d, but do not free d itself.
References cached_dir_t::dir, cached_dir_t::dir_z, and tor_free.
Referenced by cached_dir_decref(), dirserv_clear_old_v1_info(), and dirserv_free_all().
static void clear_status_flags_on_sybil | ( | routerstatus_t * | rs | ) | [static] |
Routerstatus rs is part of a group of routers that are on too narrow an IP-space. Clear out its flags: we don't want people using it.
References 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_v2_dir, and routerstatus_t::is_valid.
static int connection_dirserv_add_dir_bytes_to_outbuf | ( | dir_connection_t * | conn | ) | [static] |
Spooling helper: Called when we're sending a directory or networkstatus, and the outbuf has become too empty. Pulls some bytes from conn->cached_dir->dir_z, uncompresses them if appropriate, and puts them on the outbuf. If we run out of entries, flushes the zlib state and sets the spool source to NONE. Returns 0 on success, negative on failure.
References dir_connection_t::_base, buf_datalen(), dir_connection_t::cached_dir, cached_dir_decref(), dir_connection_t::cached_dir_offset, connection_dirserv_finish_spooling(), cached_dir_t::dir_z, cached_dir_t::dir_z_len, DIRSERV_BUFFER_MIN, connection_t::outbuf, TO_CONN, tor_assert, and dir_connection_t::zlib_state.
Referenced by connection_dirserv_add_networkstatus_bytes_to_outbuf(), and connection_dirserv_flushed_some().
static int connection_dirserv_add_microdescs_to_outbuf | ( | dir_connection_t * | conn | ) | [static] |
Spooling helper: called when we're sending a bunch of microdescriptors, and the outbuf has become too empty. Pulls some entries from fingerprint_stack, and writes the corresponding microdescs onto outbuf. If we run out of entries, flushes the zlib state and sets the spool source to NONE. Returns 0 on success, negative on failure.
References dir_connection_t::_base, microdesc_t::body, microdesc_t::bodylen, buf_datalen(), dir_connection_t::dir_spool_src, DIRSERV_BUFFER_MIN, dir_connection_t::fingerprint_stack, connection_t::outbuf, smartlist_free(), smartlist_pop_last(), TO_CONN, tor_free, tor_zlib_free(), and dir_connection_t::zlib_state.
Referenced by connection_dirserv_flushed_some().
static int connection_dirserv_add_networkstatus_bytes_to_outbuf | ( | dir_connection_t * | conn | ) | [static] |
Spooling helper: Called when we're spooling networkstatus objects on conn, and the outbuf has become too empty. If the current networkstatus object (in conn->cached_dir) has more data, pull data from there. Otherwise, pop the next fingerprint from fingerprint_stack, and start spooling the next networkstatus. (A digest of all 0 bytes is treated as a request for the current consensus.) If we run out of entries, flushes the zlib state and sets the spool source to NONE. Returns 0 on success, negative on failure.
References dir_connection_t::_base, buf_datalen(), dir_connection_t::cached_dir, dir_connection_t::cached_dir_offset, connection_dirserv_add_dir_bytes_to_outbuf(), connection_dirserv_finish_spooling(), dir_connection_t::dir_spool_src, DIRSERV_BUFFER_MIN, dir_connection_t::fingerprint_stack, lookup_cached_dir_by_fp(), connection_t::outbuf, cached_dir_t::refcnt, smartlist_free(), smartlist_pop_last(), tor_free, tor_zlib_new(), and dir_connection_t::zlib_state.
Referenced by connection_dirserv_flushed_some().
static int connection_dirserv_add_servers_to_outbuf | ( | dir_connection_t * | conn | ) | [static] |
Spooling helper: called when we're sending a bunch of server descriptors, and the outbuf has become too empty. Pulls some entries from fingerprint_stack, and writes the corresponding servers onto outbuf. If we run out of entries, flushes the zlib state and sets the spool source to NONE. Returns 0 on success, negative on failure.
References dir_connection_t::_base, buf_datalen(), connection_dir_is_encrypted(), dir_connection_t::dir_spool_src, DIRSERV_BUFFER_MIN, extrainfo_get_by_descriptor_digest(), dir_connection_t::fingerprint_stack, get_signed_descriptor_by_fp(), connection_t::outbuf, router_get_by_descriptor_digest(), ROUTER_MAX_AGE_TO_PUBLISH, signed_descriptor_t::send_unencrypted, signed_descriptor_get_body(), signed_descriptor_t::signed_descriptor_len, smartlist_free(), smartlist_pop_last(), TO_CONN, tor_free, tor_zlib_free(), and dir_connection_t::zlib_state.
Referenced by connection_dirserv_flushed_some().
static int connection_dirserv_finish_spooling | ( | dir_connection_t * | conn | ) | [static] |
Spooling helper: called when we have no more data to spool to conn. Flushes any remaining data to be (un)compressed, and changes the spool source to NONE. Returns 0 on success, negative on failure.
References dir_connection_t::dir_spool_src, tor_zlib_free(), and dir_connection_t::zlib_state.
Referenced by connection_dirserv_add_dir_bytes_to_outbuf(), and connection_dirserv_add_networkstatus_bytes_to_outbuf().
int connection_dirserv_flushed_some | ( | dir_connection_t * | conn | ) |
Called whenever we have flushed some directory data in state SERVER_WRITING.
References dir_connection_t::_base, buf_datalen(), connection_dirserv_add_dir_bytes_to_outbuf(), connection_dirserv_add_microdescs_to_outbuf(), connection_dirserv_add_networkstatus_bytes_to_outbuf(), connection_dirserv_add_servers_to_outbuf(), DIR_CONN_STATE_SERVER_WRITING, dir_connection_t::dir_spool_src, DIRSERV_BUFFER_MIN, connection_t::outbuf, connection_t::state, and tor_assert.
Referenced by connection_flushed_some(), and directory_handle_command_get().
int directory_caches_dir_info | ( | or_options_t * | options | ) |
Return 1 if we want to keep descriptors, networkstatuses, etc around and we're willing to serve them to others. Else return 0.
References advertised_server_mode(), or_options_t::BridgeRelay, or_options_t::DirPort, or_options_t::RefuseUnknownExits, and server_mode().
Referenced by authority_certs_fetch_missing(), directory_too_idle_to_fetch_descriptors(), networkstatus_set_current_consensus(), routerlist_remove_old_cached_routers_with_id(), routerlist_remove_old_routers(), signed_desc_digest_is_recognized(), and trusted_dirs_load_certs_from_string().
int directory_caches_v2_dir_info | ( | or_options_t * | options | ) |
Return 1 if we want to cache v2 dir info (each status file).
References or_options_t::DirPort.
Referenced by add_networkstatus_to_cache(), networkstatus_v2_list_clean(), options_act_reversible(), router_reload_v2_networkstatus(), and router_set_networkstatus_v2().
int directory_fetches_dir_info_early | ( | or_options_t * | options | ) |
Return 1 if we should fetch new networkstatuses, descriptors, etc on the "mirror" schedule rather than the "client" schedule.
References directory_fetches_from_authorities().
Referenced by launch_router_descriptor_downloads(), options_act(), update_consensus_networkstatus_fetch_time(), update_networkstatus_downloads(), update_router_descriptor_cache_downloads_v2(), and update_router_descriptor_downloads().
int directory_fetches_dir_info_later | ( | or_options_t * | options | ) |
Return 1 if we should fetch new networkstatuses, descriptors, etc on a very passive schedule -- waiting long enough for ordinary clients to probably have the info we want. These would include bridge users, and maybe others in the future e.g. if a Tor client uses another Tor client as a directory guard.
References or_options_t::UseBridges.
Referenced by options_act(), and update_consensus_networkstatus_fetch_time().
int directory_fetches_from_authorities | ( | or_options_t * | options | ) |
Return 1 if we fetch our directory material directly from the authorities, rather than from a mirror.
References advertised_server_mode(), or_options_t::BridgeRelay, routerinfo_t::dir_port, or_options_t::DirPort, or_options_t::FetchDirInfoEarly, or_options_t::RefuseUnknownExits, router_get_my_routerinfo(), router_pick_published_address(), and server_mode().
Referenced by dir_routerdesc_download_failed(), directory_command_should_use_begindir(), directory_fetches_dir_info_early(), directory_get_from_dirserver(), and directory_info_has_arrived().
int directory_permits_begindir_requests | ( | or_options_t * | options | ) |
Return 1 if we want to allow remote people to ask us directory requests via the "begin_dir" interface, which doesn't require having any separate port open.
References or_options_t::BridgeRelay, and or_options_t::DirPort.
Referenced by connection_exit_begin_conn().
int directory_permits_controller_requests | ( | or_options_t * | options | ) |
Return 1 if we want to allow controllers to ask us directory requests via the controller interface, which doesn't require having any separate port open.
References or_options_t::DirPort.
static void directory_remove_invalid | ( | void | ) | [static] |
Remove all descriptors whose nicknames or fingerprints no longer are allowed by our fingerprint list. (Descriptors that used to be good can become bad when we reload the fingerprint list.)
References bool_neq, directory_set_dirty(), dirserv_router_get_status(), FP_BADDIR, FP_BADEXIT, FP_INVALID, FP_NAMED, FP_REJECT, routerinfo_t::is_bad_directory, routerinfo_t::is_bad_exit, routerinfo_t::is_named, routerinfo_t::is_valid, LD_DIRSERV, routerinfo_t::nickname, router_get_routerlist(), routerlist_assert_ok(), routerlist_remove(), and routerlist_t::routers.
Referenced by dirserv_load_fingerprint_file().
void directory_set_dirty | ( | void | ) |
Mark the directory as dirty -- when we're next asked for a directory, we will rebuild it instead of reusing the most recently generated one.
References cached_dir_t::dir, cached_dir_t::published, runningrouters_is_dirty, the_directory_is_dirty, and the_v2_networkstatus_is_dirty.
Referenced by connection_tls_finish_handshake(), directory_remove_invalid(), and router_add_to_routerlist().
int directory_too_idle_to_fetch_descriptors | ( | or_options_t * | options, | |
time_t | now | |||
) |
Return 1 if we have no need to fetch new descriptors. This generally happens when we're not a dir cache and we haven't built any circuits lately.
References directory_caches_dir_info(), or_options_t::FetchUselessDescriptors, and rep_hist_circbuilding_dormant().
Referenced by directory_info_has_arrived(), update_consensus_router_descriptor_downloads(), and update_router_have_minimum_dir_info().
was_router_added_t dirserv_add_descriptor | ( | routerinfo_t * | ri, | |
const char ** | msg, | |||
const char * | source | |||
) |
Examine the parsed server descriptor in ri and maybe insert it into the list of server descriptors. Set *msg to a message that should be passed back to the origin of this descriptor, or NULL if there is no such message. Use source to produce better log messages.
Return the status of the operation
This function is only called when fresh descriptors are posted, not when we re-load the cache.
References routerinfo_t::cache_info, control_event_descriptors_changed(), control_event_or_authdir_new_descriptor(), signed_descriptor_t::identity_digest, routerinfo_t::is_valid, LD_DIR, LD_DIRSERV, MAX_DESCRIPTOR_UPLOAD_SIZE, routerinfo_t::nickname, signed_descriptor_t::published_on, router_add_to_routerlist(), router_differences_are_cosmetic(), router_get_by_digest(), router_is_me(), routerinfo_free(), signed_descriptor_t::signed_descriptor_body, signed_descriptor_t::signed_descriptor_len, smartlist_add(), smartlist_create(), smartlist_free(), tor_free, WRA_WAS_ADDED(), and WRA_WAS_REJECTED().
Referenced by dirserv_add_multiple_descriptors(), and init_keys().
static was_router_added_t dirserv_add_extrainfo | ( | extrainfo_t * | ei, | |
const char ** | msg | |||
) | [static] |
As dirserv_add_descriptor, but for an extrainfo_t ei.
References extrainfo_t::cache_info, extrainfo_free(), signed_descriptor_t::identity_digest, LD_DIR, MAX_EXTRAINFO_UPLOAD_SIZE, router_add_extrainfo_to_routerlist(), router_get_by_digest(), routerinfo_incompatible_with_extrainfo(), signed_descriptor_t::signed_descriptor_len, and tor_assert.
Referenced by dirserv_add_multiple_descriptors().
was_router_added_t dirserv_add_multiple_descriptors | ( | const char * | desc, | |
uint8_t | purpose, | |||
const char * | source, | |||
const char ** | msg | |||
) |
As for dirserv_add_descriptor(), but accepts multiple documents, and returns the most severe error that occurred for any one of them.
References dirserv_add_descriptor(), dirserv_add_extrainfo(), escaped(), format_iso_time(), ROUTER_ANNOTATION_BUF_LEN, router_parse_list_from_string(), ROUTER_PURPOSE_GENERAL, router_purpose_to_string(), SAVED_NOWHERE, smartlist_clear(), smartlist_create(), smartlist_free(), tor_assert, tor_snprintf(), WRA_MORE_SEVERE(), and WRA_WAS_ADDED().
Referenced by directory_handle_command_post().
int dirserv_add_own_fingerprint | ( | const char * | nickname, | |
crypto_pk_env_t * | pk | |||
) |
Add the nickname and fingerprint for this OR to the global list of recognized identity key fingerprints.
References add_fingerprint_to_dir(), authdir_config_new(), crypto_pk_get_fingerprint(), FINGERPRINT_LEN, and LD_BUG.
Referenced by init_keys().
void dirserv_clear_old_networkstatuses | ( | time_t | cutoff | ) |
Remove any v2 networkstatus from the directory cache that was published before cutoff.
References cached_dir_decref(), cached_v2_networkstatus, file_status(), LD_DIR, networkstatus_get_cache_filename(), and tor_free.
Referenced by networkstatus_v2_list_clean().
void dirserv_clear_old_v1_info | ( | time_t | now | ) |
Remove any v1 info from the directory cache that was published too long ago.
References cached_dir_decref(), clear_cached_dir(), MAX_V1_DIRECTORY_AGE, MAX_V1_RR_AGE, and cached_dir_t::published.
Referenced by networkstatus_v2_list_clean().
static void dirserv_compute_performance_thresholds | ( | routerlist_t * | rl | ) | [static] |
Look through the routerlist, the Mean Time Between Failure history, and the Weighted Fractional Uptime history, and use them to set thresholds for the Stable, Fast, and Guard flags. Update the fields stable_uptime, stable_mtbf, enough_mtbf_info, guard_wfu, guard_tk, fast_bandwidth, guard_bandwidh_including_exits, guard_bandwidth_excluding_exits, total_bandwidth, and total_exit_bandwidth.
Also, set the is_exit flag of each router appropriately.
References exit_policy_is_general_exit(), real_uptime(), rep_hist_get_stability(), rep_hist_get_weighted_time_known(), router_exit_policy_rejects_all(), router_get_advertised_bandwidth(), router_is_active(), and routerlist_t::routers.
int dirserv_dump_directory_to_string | ( | char ** | dir_out, | |
crypto_pk_env_t * | private_key | |||
) |
Generate a new v1 directory and write it into a newly allocated string. Point *dir_out to the allocated string. Sign the directory with private_key. Return 0 on success, -1 on failure. If complete is set, give us all the descriptors; otherwise leave out non-running and non-valid ones.
References crypto_pk_write_public_key_to_string(), DIGEST_LEN, format_iso_time(), format_versions_list(), get_options(), LD_BUG, note_crypto_pk_op(), router_append_dirobj_signature(), router_get_dir_hash(), tor_assert, tor_free, and tor_snprintf().
Referenced by dirserv_regenerate_directory().
size_t dirserv_estimate_data_size | ( | smartlist_t * | fps, | |
int | is_serverdescs, | |||
int | compressed | |||
) |
Return an approximate estimate of the number of bytes that will be needed to transmit the server descriptors (if is_serverdescs -- they can be either d/ or fp/ queries) or networkstatus objects (if !is_serverdescs) listed in fps. If compressed is set, we guess how large the data will be after compression.
The return value is an estimate; it might be larger or smaller.
References routerinfo_t::cache_info, cached_dir_t::dir_len, cached_dir_t::dir_z_len, lookup_cached_dir_by_fp(), router_get_my_routerinfo(), signed_descriptor_t::signed_descriptor_len, and tor_assert.
Referenced by directory_handle_command_get().
size_t dirserv_estimate_microdesc_size | ( | const smartlist_t * | fps, | |
int | compressed | |||
) |
Given a list of microdescriptor hashes, guess how many bytes will be needed to transmit them, and return the guess.
Referenced by directory_handle_command_get().
void dirserv_free_all | ( | void | ) |
Release all storage used by the directory server.
References _free_cached_dir(), cached_consensuses, cached_dir_decref(), cached_v2_networkstatus, clear_cached_dir(), digestmap_free(), dirserv_free_fingerprint_list(), and strmap_free().
Referenced by tor_free_all().
void dirserv_free_fingerprint_list | ( | void | ) |
Clear the current fingerprint list.
References _tor_free(), digestmap_free(), authdir_config_t::fp_by_name, authdir_config_t::status_by_digest, strmap_free(), and tor_free.
Referenced by dirserv_free_all(), and dirserv_load_fingerprint_file().
networkstatus_t* dirserv_generate_networkstatus_vote_obj | ( | crypto_pk_env_t * | private_key, | |
authority_cert_t * | cert | |||
) |
Return a new networkstatus_t* containing our current opinion. (For v3 authorities)
References or_options_t::AuthDirListBadDirs, or_options_t::AuthDirListBadExits, or_options_t::ContactInfo, crypto_pk_get_digest(), DIGEST_LEN, dirserv_set_router_is_running(), format_versions_list(), get_options(), authority_cert_t::identity_key, LD_BUG, LD_NET, or_options_t::NamingAuthoritativeDir, or_options_t::RecommendedClientVersions, or_options_t::RecommendedServerVersions, resolve_my_address(), router_get_routerlist(), ROUTER_MAX_AGE_TO_PUBLISH, routerlist_t::routers, tor_assert, tor_dup_ip(), tor_free, and or_options_t::VersioningAuthoritativeDir.
Referenced by dirvote_perform_vote().
cached_dir_t* dirserv_get_consensus | ( | const char * | flavor_name | ) |
Return the latest downloaded consensus networkstatus in encoded, signed, optionally compressed format, suitable for sending to clients.
References cached_consensuses, and strmap_get().
Referenced by networkstatus_set_current_consensus().
cached_dir_t* dirserv_get_directory | ( | void | ) |
Return the most recently generated encoded signed v1 directory, generating a new one as necessary. If not a v1 authoritative directory may return NULL if no directory is yet cached.
References dirserv_pick_cached_dir_obj(), dirserv_regenerate_directory(), the_directory_is_dirty, and V1_AUTHORITY.
Referenced by directory_handle_command_get(), and directory_handle_command_post().
static uint32_t dirserv_get_name_status | ( | const char * | id_digest, | |
const char * | nickname | |||
) | [static] |
Helper: Based only on the ID/Nickname combination, return FP_UNNAMED (unnamed), FP_NAMED (named), or 0 (neither).
References base16_encode(), DIGEST_LEN, authdir_config_t::fp_by_name, FP_NAMED, FP_UNNAMED, HEX_DIGEST_LEN, and strmap_get_lc().
Referenced by dirserv_get_status_impl(), and set_routerstatus_from_routerinfo().
void dirserv_get_networkstatus_v2 | ( | smartlist_t * | result, | |
const char * | key | |||
) |
Look for a network status object as specified by key, which should be either "authority" (to find a network status generated by us), a hex identity digest (to find a network status generated by given directory), or "all" (to return all the v2 network status objects we have).
References base16_encode(), cached_v2_networkstatus, DIGEST_LEN, digestmap_get(), digestmap_new(), dirserv_get_networkstatus_v2_fingerprints(), generate_v2_networkstatus_opinion(), HEX_DIGEST_LEN, LD_DIRSERV, router_digest_is_me(), should_generate_v2_networkstatus(), smartlist_add(), smartlist_create(), smartlist_free(), tor_assert, and tor_free.
void dirserv_get_networkstatus_v2_fingerprints | ( | smartlist_t * | result, | |
const char * | key | |||
) |
Given the portion of a networkstatus request URL after "tor/status/" in key, append to result the digests of the identity keys of the networkstatus objects that the client has requested.
References authdir_mode_v2(), routerinfo_t::cache_info, cached_v2_networkstatus, DIGEST_LEN, digestmap_iter_done(), digestmap_iter_get(), digestmap_iter_init(), digestmap_iter_next(), digestmap_new(), digestmap_size(), dir_split_resource_into_fingerprints(), generate_v2_networkstatus_opinion(), get_options(), signed_descriptor_t::identity_digest, LD_DIRSERV, router_get_my_routerinfo(), router_get_trusted_dir_servers(), should_generate_v2_networkstatus(), smartlist_add(), smartlist_sort_digests(), strcmpstart(), tor_assert, and V2_AUTHORITY.
Referenced by directory_handle_command_get(), and dirserv_get_networkstatus_v2().
const char* dirserv_get_nickname_by_digest | ( | const char * | digest | ) |
If we are an authoritative dirserver, and the list of approved servers contains one whose identity key digest is digest, return that router's nickname. Otherwise return NULL.
References digestmap_get(), router_status_t::nickname, authdir_config_t::status_by_digest, and tor_assert.
Referenced by connection_or_init_conn_from_address().
int dirserv_get_routerdesc_fingerprints | ( | smartlist_t * | fps_out, | |
const char * | key, | |||
const char ** | msg, | |||
int | for_unencrypted_conn, | |||
int | is_extrainfo | |||
) |
As dirserv_get_routerdescs(), but instead of getting signed_descriptor_t pointers, adds copies of digests to fps_out, and doesn't use the /tor/server/ prefix. For a /d/ request, adds descriptor digests; for other requests, adds identity digests.
References routerinfo_t::cache_info, DIGEST_LEN, dir_split_resource_into_fingerprints(), extrainfo_get_by_descriptor_digest(), get_signed_descriptor_by_fp(), signed_descriptor_t::identity_digest, router_get_by_descriptor_digest(), router_get_my_routerinfo(), router_get_routerlist(), routerlist_t::routers, signed_descriptor_t::send_unencrypted, smartlist_add(), strcmpstart(), and tor_free.
Referenced by directory_handle_command_get().
int dirserv_get_routerdescs | ( | smartlist_t * | descs_out, | |
const char * | key, | |||
const char ** | msg | |||
) |
Add a signed_descriptor_t to descs_out for each router matching key. The key should be either
Return 0 if we found some matching descriptors, or -1 if we do not have any descriptors, no matching descriptors, or if we did not recognize the key (URL). If -1 is returned *msg will be set to an appropriate error message.
XXXX rename this function. It's only called from the controller. XXXX in fact, refactor this function, merging as much as possible.
References routerinfo_t::cache_info, dir_split_resource_into_fingerprints(), signed_descriptor_t::published_on, router_digest_is_me(), router_get_by_descriptor_digest(), router_get_by_digest(), router_get_my_routerinfo(), router_get_routerlist(), ROUTER_MAX_AGE_TO_PUBLISH, routerlist_t::routers, smartlist_add(), smartlist_create(), smartlist_free(), strcmpstart(), and tor_free.
cached_dir_t* dirserv_get_runningrouters | ( | void | ) |
Set *rr to the most recently generated encoded signed running-routers list, generating a new one as necessary. Return the size of the directory on success, and 0 on failure.
References dirserv_pick_cached_dir_obj(), generate_runningrouters(), runningrouters_is_dirty, and V1_AUTHORITY.
Referenced by directory_handle_command_get().
static uint32_t dirserv_get_status_impl | ( | const char * | id_digest, | |
const char * | nickname, | |||
const char * | address, | |||
uint32_t | addr, | |||
uint16_t | or_port, | |||
const char * | platform, | |||
const char * | contact, | |||
const char ** | msg, | |||
int | should_log | |||
) | [static] |
Helper: As dirserv_get_router_status, but takes the router fingerprint (hex, no spaces), nickname, address (used for logging only), IP address, OR port, platform (logging only) and contact info (logging only) as arguments.
If should_log is false, do not log messages. (There's not much point in logging that we're rejecting servers we'll not download.)
References authdir_config_new(), authdir_policy_baddir_address(), authdir_policy_badexit_address(), authdir_policy_permits_address(), authdir_policy_valid_address(), or_options_t::AuthDirRejectUnlisted, digestmap_get(), digestmap_size(), dirserv_get_name_status(), esc_for_log(), escaped(), FP_BADDIR, FP_BADEXIT, authdir_config_t::fp_by_name, FP_INVALID, FP_NAMED, FP_REJECT, FP_UNNAMED, get_options(), LD_DIRSERV, router_status_t::status, authdir_config_t::status_by_digest, strmap_size(), tor_free, and tor_version_as_new_as().
Referenced by dirserv_router_get_status(), and dirserv_would_reject_router().
int dirserv_have_any_microdesc | ( | const smartlist_t * | fps | ) |
Return true iff any of the 256-bit elements in fps is the digest of a microdescriptor we have.
Referenced by directory_handle_command_get().
int dirserv_have_any_serverdesc | ( | smartlist_t * | fps, | |
int | spool_src | |||
) |
Return true iff we have any of the documents (extrainfo or routerdesc) specified by the fingerprints in fps and spool_src. Used to decide whether to send a 404.
References extrainfo_get_by_descriptor_digest(), get_signed_descriptor_by_fp(), router_get_by_descriptor_digest(), and ROUTER_MAX_AGE_TO_PUBLISH.
Referenced by directory_handle_command_get().
int dirserv_load_fingerprint_file | ( | void | ) |
Load the nickname->fingerprint mappings stored in the approved-routers file. The file format is line-based, with each non-blank holding one nickname, some space, and a fingerprint for that nickname. On success, replace the current fingerprint list with the new list and return 0. On failure, leave the current fingerprint list untouched, and return -1.
References add_fingerprint_to_dir(), authdir_config_new(), base16_decode(), config_free_lines(), config_get_lines(), DEFAULT_CLIENT_NICKNAME, DIGEST_LEN, directory_remove_invalid(), dirserv_free_fingerprint_list(), get_datadir_fname, get_options(), HEX_DIGEST_LEN, is_legal_nickname(), LD_CONFIG, LD_FS, LD_GENERAL, MAX_NICKNAME_LEN, or_options_t::NamingAuthoritativeDir, config_line_t::next, read_file_to_str(), RFTS_IGNORE_MISSING, tor_free, and tor_strstrip().
Referenced by do_hup(), and init_keys().
void dirserv_orconn_tls_done | ( | const char * | address, | |
uint16_t | or_port, | |||
const char * | digest_rcvd, | |||
int | as_advertised | |||
) |
Called when a TLS handshake has completed successfully with a router listening at address:or_port, and has yielded a certificate with digest digest_rcvd.
Also, if as_advertised is 1, then inform the reachability checker that we could get to this guy.
References authdir_mode_bridge(), DIGEST_LEN, get_options(), LD_DIRSERV, rep_hist_note_router_reachable(), router_get_routerlist(), ROUTER_PURPOSE_BRIDGE, routerlist_t::routers, and tor_assert.
Referenced by connection_or_check_valid_tls_handshake().
static cached_dir_t* dirserv_pick_cached_dir_obj | ( | cached_dir_t * | cache_src, | |
cached_dir_t * | auth_src, | |||
time_t | dirty, | |||
cached_dir_t *(*)(void) | regenerate, | |||
const char * | name, | |||
authority_type_t | auth_type | |||
) | [static] |
Helper: If we're an authority for the right directory version (v1 or v2) (based on auth_type), try to regenerate auth_src as appropriate and return it, falling back to cache_src on failure. If we're a cache, simply return cache_src.
References authdir_mode_bridge(), authdir_mode_v1(), authdir_mode_v2(), DIR_REGEN_SLACK_TIME, get_options(), LD_BUG, LD_DIRSERV, V1_AUTHORITY, and V2_AUTHORITY.
Referenced by dirserv_get_directory(), and dirserv_get_runningrouters().
int dirserv_read_measured_bandwidths | ( | const char * | from_file, | |
smartlist_t * | routerstatuses | |||
) |
Read the measured bandwidth file and apply it to the list of routerstatuses. Returns -1 on error, 0 otherwise.
References compare_routerstatus_entries(), escaped(), LD_CONFIG, LD_DIRSERV, measured_bw_line_apply(), measured_bw_line_parse(), smartlist_sort(), and tor_parse_ulong().
Referenced by options_validate().
static cached_dir_t * dirserv_regenerate_directory | ( | void | ) | [static] |
Only called by v1 auth dirservers. Generate a fresh v1 directory; set the_directory and return a pointer to the new value.
References cached_dir_decref(), cached_dir_t::dir, cached_dir_t::dir_len, dirserv_dump_directory_to_string(), dirserv_set_cached_directory(), get_identity_key(), LD_BUG, LD_DIRSERV, new_cached_dir(), the_directory_is_dirty, and tor_free.
Referenced by dirserv_get_directory().
int dirserv_remove_old_statuses | ( | smartlist_t * | fps, | |
time_t | cutoff | |||
) |
Remove from fps every networkstatus key where both a) we have a networkstatus document and b) it is not newer than cutoff.
Return 1 if any items were present at all; else return 0.
References lookup_cached_dir_by_fp(), cached_dir_t::published, and tor_free.
Referenced by directory_handle_command_get().
static uint32_t dirserv_router_get_status | ( | const routerinfo_t * | router, | |
const char ** | msg | |||
) | [static] |
Check whether router has a nickname/identity key combination that we recognize from the fingerprint list, or an IP we automatically act on according to our configuration. Return the appropriate router status.
If the status is 'FP_REJECT' and msg is provided, set *msg to an explanation of why.
References routerinfo_t::addr, routerinfo_t::address, routerinfo_t::contact_info, crypto_pk_get_digest(), DIGEST_LEN, dirserv_get_status_impl(), FP_REJECT, routerinfo_t::identity_pkey, LD_BUG, routerinfo_t::nickname, routerinfo_t::or_port, and routerinfo_t::platform.
Referenced by authdir_wants_to_reject_router(), and directory_remove_invalid().
static int dirserv_router_has_valid_address | ( | routerinfo_t * | ri | ) | [static] |
Return -1 if ri has a private or otherwise bad address, unless we're configured to not care. Return 0 if all ok.
References routerinfo_t::address, get_options(), is_internal_IP(), LD_DIRSERV, routerinfo_t::nickname, and tor_inet_aton().
Referenced by authdir_wants_to_reject_router().
void dirserv_set_cached_consensus_networkstatus | ( | const char * | networkstatus, | |
const char * | flavor_name, | |||
const digests_t * | digests, | |||
time_t | published | |||
) |
Replace the v3 consensus networkstatus of type flavor_name that we're serving with networkstatus, published at published. No validation is performed.
References cached_consensuses, cached_dir_decref(), cached_dir_t::digests, new_cached_dir(), and strmap_set().
Referenced by networkstatus_set_current_consensus().
void dirserv_set_cached_directory | ( | const char * | directory, | |
time_t | published, | |||
int | is_running_routers | |||
) |
If we have no cached v1 directory, or it is older than published, then replace it with directory, published at published.
If published is too old, do nothing.
If is_running_routers, this is really a v1 running_routers document rather than a v1 directory.
References cached_dir_decref(), MAX_V1_DIRECTORY_AGE, MAX_V1_RR_AGE, new_cached_dir(), and set_cached_dir().
Referenced by dirserv_regenerate_directory(), router_parse_directory(), and router_parse_runningrouters().
void dirserv_set_cached_networkstatus_v2 | ( | const char * | networkstatus, | |
const char * | identity, | |||
time_t | published | |||
) |
If networkstatus is non-NULL, we've just received a v2 network-status for an authoritative directory with identity digest identity published at published -- store it so we can serve it to others.
If networkstatus is NULL, remove the entry with the given identity fingerprint from the v2 cache.
References cached_dir_decref(), cached_v2_networkstatus, digestmap_get(), digestmap_iter_done(), digestmap_iter_get(), digestmap_iter_init(), digestmap_iter_next(), digestmap_new(), digestmap_remove(), digestmap_set(), digestmap_size(), MAX_UNTRUSTED_NETWORKSTATUSES, new_cached_dir(), cached_dir_t::published, router_get_trusted_dir_servers(), and tor_assert.
Referenced by add_networkstatus_to_cache(), and networkstatus_v2_list_clean().
void dirserv_set_router_is_running | ( | routerinfo_t * | router, | |
time_t | now | |||
) |
Treat a router as alive if
References or_options_t::AssumeReachable, routerinfo_t::cache_info, get_options(), signed_descriptor_t::identity_digest, routerinfo_t::is_running, routerinfo_t::last_reachable, REACHABLE_TIMEOUT, rep_hist_note_router_unreachable(), router_is_me(), and we_are_hibernating().
Referenced by dirserv_generate_networkstatus_vote_obj(), generate_v2_networkstatus_opinion(), list_server_status_v1(), and networkstatus_getinfo_by_purpose().
void dirserv_single_reachability_test | ( | time_t | now, | |
routerinfo_t * | router | |||
) |
Helper function for dirserv_test_reachability(). Start a TLS connection to router, and annotate it with when we started the test.
References routerinfo_t::addr, routerinfo_t::address, routerinfo_t::cache_info, connection_or_connect(), signed_descriptor_t::identity_digest, LD_OR, routerinfo_t::nickname, routerinfo_t::or_port, routerinfo_t::testing_since, and tor_addr_from_ipv4h.
Referenced by dirserv_test_reachability(), and router_add_to_routerlist().
void dirserv_test_reachability | ( | time_t | now | ) |
Auth dir server only: load balance such that we only try a few connections per call.
The load balancing is such that if we get called once every ten seconds, we will cycle through all the tests in 1280 seconds (a bit over 20 minutes).
References authdir_mode_bridge(), dirserv_single_reachability_test(), get_options(), router_get_routerlist(), router_is_me(), ROUTER_PURPOSE_BRIDGE, and routerlist_t::routers.
Referenced by run_scheduled_events().
static int dirserv_thinks_router_is_hs_dir | ( | routerinfo_t * | router, | |
time_t | now | |||
) | [static] |
Return true iff router should be assigned the "HSDir" flag. Right now this means it advertises support for it, it has a high uptime, and it's currently considered Running.
This function needs to be called after router->is_running has been set.
References get_options(), routerinfo_t::is_running, real_uptime(), and routerinfo_t::wants_to_be_hs_dir.
Referenced by set_routerstatus_from_routerinfo().
static int dirserv_thinks_router_is_unreliable | ( | time_t | now, | |
routerinfo_t * | router, | |||
int | need_uptime, | |||
int | need_capacity | |||
) | [static] |
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.
References routerinfo_t::cache_info, signed_descriptor_t::identity_digest, MTBF_TO_GUARANTEE_STABLE, real_uptime(), rep_hist_get_stability(), router_get_advertised_bandwidth(), and UPTIME_TO_GUARANTEE_STABLE.
Referenced by set_routerstatus_from_routerinfo().
int dirserv_would_reject_router | ( | routerstatus_t * | rs | ) |
Return true if there is no point in downloading the router described by rs because this directory would reject it.
References routerstatus_t::addr, dirserv_get_status_impl(), FP_REJECT, routerstatus_t::identity_digest, routerstatus_t::nickname, and routerstatus_t::or_port.
Referenced by update_router_descriptor_cache_downloads_v2().
static char * format_versions_list | ( | config_line_t * | ln | ) | [static] |
Given a (possibly empty) list of config_line_t, each line of which contains a list of comma-separated version numbers surrounded by optional space, allocate and return a new string containing the version numbers, in order, separated by commas. Used to generate Recommended(Client|Server)?Versions
References config_line_t::next, smartlist_create(), smartlist_free(), smartlist_join_strings(), smartlist_split_string(), sort_version_list(), tor_free, and config_line_t::value.
Referenced by dirserv_dump_directory_to_string(), dirserv_generate_networkstatus_vote_obj(), and generate_v2_networkstatus_opinion().
static cached_dir_t* generate_runningrouters | ( | void | ) | [static] |
Only called by v1 auth dirservers. Replace the current running-routers list with a newly generated one.
References crypto_pk_write_public_key_to_string(), DIGEST_LEN, format_iso_time(), get_identity_key(), get_options(), LD_BUG, note_crypto_pk_op(), router_append_dirobj_signature(), router_get_runningrouters_hash(), runningrouters_is_dirty, set_cached_dir(), tor_free, and tor_snprintf().
Referenced by dirserv_get_runningrouters().
static cached_dir_t* generate_v2_networkstatus_opinion | ( | void | ) | [static] |
For v2 authoritative directories only: Replace the contents of the_v2_networkstatus with a newly generated network status object.
References or_options_t::AuthDirListBadDirs, or_options_t::AuthDirListBadExits, or_options_t::ContactInfo, crypto_pk_get_fingerprint(), crypto_pk_write_public_key_to_string(), DIGEST_LEN, or_options_t::DirPort, dirserv_set_router_is_running(), FINGERPRINT_LEN, format_iso_time(), format_versions_list(), get_identity_key(), get_options(), INET_NTOA_BUF_LEN, LD_BUG, LD_NET, or_options_t::NamingAuthoritativeDir, or_options_t::RecommendedClientVersions, or_options_t::RecommendedServerVersions, resolve_my_address(), router_get_routerlist(), ROUTER_MAX_AGE_TO_PUBLISH, routerlist_t::routers, RS_ENTRY_LEN, tor_inet_ntoa(), tor_snprintf(), and or_options_t::VersioningAuthoritativeDir.
Referenced by dirserv_get_networkstatus_v2(), and dirserv_get_networkstatus_v2_fingerprints().
static digestmap_t* get_possible_sybil_list | ( | const smartlist_t * | routers | ) | [static] |
Given a list of routerinfo_t in routers, return a new digestmap_t whose keys are the identity digests of those routers that we're going to exclude for Sybil-like appearance.
References _compare_routerinfo_by_ip_and_bw(), or_options_t::AuthDirMaxServersPerAddr, or_options_t::AuthDirMaxServersPerAuthAddr, digestmap_new(), digestmap_set(), get_options(), router_addr_is_trusted_dir(), smartlist_add_all(), smartlist_create(), and smartlist_sort().
static signed_descriptor_t * get_signed_descriptor_by_fp | ( | const char * | fp, | |
int | extrainfo, | |||
time_t | publish_cutoff | |||
) | [static] |
Return the cache-info for identity fingerprint fp, or its extra-info document if extrainfo is true. Return NULL if not found or if the descriptor is older than publish_cutoff.
References routerinfo_t::cache_info, extrainfo_t::cache_info, signed_descriptor_t::extra_info_digest, extrainfo_get_by_descriptor_digest(), signed_descriptor_t::published_on, router_digest_is_me(), router_get_by_digest(), router_get_my_extrainfo(), and router_get_my_routerinfo().
Referenced by connection_dirserv_add_servers_to_outbuf(), dirserv_get_routerdesc_fingerprints(), and dirserv_have_any_serverdesc().
int list_server_status_v1 | ( | smartlist_t * | routers, | |
char ** | router_status_out, | |||
int | for_controller | |||
) |
Based on the routerinfo_ts in routers, allocate the contents of a v1-style router-status line, and store it in *router_status_out. Return 0 on success, -1 on failure.
If for_controller is true, include the routers with very old descriptors.
References authdir_mode_publishes_statuses(), dirserv_set_router_is_running(), get_options(), list_single_server_status(), MAX_VERBOSE_NICKNAME_LEN, router_get_verbose_nickname(), ROUTER_MAX_AGE_TO_PUBLISH, smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_assert, and tor_free.
static char* list_single_server_status | ( | routerinfo_t * | desc, | |
int | is_live | |||
) | [static] |
Allocate and return a description of the status of the server desc, for use in a v1-style router-status line. The server is listed as running iff is_live is true.
References base16_encode(), routerinfo_t::cache_info, DIGEST_LEN, HEX_DIGEST_LEN, signed_descriptor_t::identity_digest, routerinfo_t::is_valid, MAX_NICKNAME_LEN, routerinfo_t::nickname, and tor_assert.
Referenced by list_server_status_v1().
static cached_dir_t* lookup_cached_dir_by_fp | ( | const char * | fp | ) | [static] |
Given a fingerprint fp which is either set if we're looking for a v2 status, or zeroes if we're looking for a v3 status, or a NUL-padded flavor name if we want a flavored v3 status, return a pointer to the appropriate cached dir object, or NULL if there isn't one available.
References cached_consensuses, cached_v2_networkstatus, DIGEST_LEN, digestmap_get(), router_digest_is_me(), strmap_get(), and tor_digest_is_zero().
Referenced by connection_dirserv_add_networkstatus_bytes_to_outbuf(), dirserv_estimate_data_size(), and dirserv_remove_old_statuses().
int measured_bw_line_apply | ( | measured_bw_line_t * | parsed_line, | |
smartlist_t * | routerstatuses | |||
) |
Helper function to apply a parsed measurement line to a list of bandwidth statuses. Returns true if a line is found, false otherwise.
References compare_digest_to_routerstatus_entry(), routerstatus_t::has_measured_bw, LD_DIRSERV, routerstatus_t::measured_bw, and smartlist_bsearch().
Referenced by dirserv_read_measured_bandwidths().
int measured_bw_line_parse | ( | measured_bw_line_t * | out, | |
const char * | orig_line | |||
) |
Helper function to parse out a line in the measured bandwidth file into a measured_bw_line_t output structure. Returns -1 on failure or 0 on success.
References base16_decode(), DIGEST_LEN, escaped(), HEX_DIGEST_LEN, LD_DIRSERV, strcmpstart(), tor_free, and tor_parse_long().
Referenced by dirserv_read_measured_bandwidths().
cached_dir_t* new_cached_dir | ( | char * | s, | |
time_t | published | |||
) |
Allocate and return a new cached_dir_t containing the string s, published at published.
References cached_dir_t::dir, cached_dir_t::dir_len, cached_dir_t::dir_z, cached_dir_t::dir_z_len, LD_BUG, cached_dir_t::published, cached_dir_t::refcnt, and tor_gzip_compress().
Referenced by dirserv_regenerate_directory(), dirserv_set_cached_consensus_networkstatus(), dirserv_set_cached_directory(), dirserv_set_cached_networkstatus_v2(), and dirvote_add_vote().
static INLINE long real_uptime | ( | routerinfo_t * | router, | |
time_t | now | |||
) | [static] |
Helper: estimate the uptime of a router given its stated uptime and the amount of time since it last stated its stated uptime.
References routerinfo_t::cache_info, signed_descriptor_t::published_on, and routerinfo_t::uptime.
Referenced by dirserv_compute_performance_thresholds(), dirserv_thinks_router_is_hs_dir(), and dirserv_thinks_router_is_unreliable().
void router_clear_status_flags | ( | routerinfo_t * | router | ) |
Clear all the status flags in routerinfo router. We put this function here because it's eerily similar to clear_status_flags_on_sybil() above. One day we should merge them.
References routerinfo_t::is_bad_directory, routerinfo_t::is_bad_exit, routerinfo_t::is_exit, routerinfo_t::is_fast, routerinfo_t::is_hs_dir, routerinfo_t::is_possible_guard, routerinfo_t::is_running, routerinfo_t::is_stable, and routerinfo_t::is_valid.
Referenced by routers_update_status_from_consensus_networkstatus().
static int router_is_active | ( | routerinfo_t * | ri, | |
time_t | now | |||
) | [static] |
Return 1 if ri's descriptor is "active" -- running, valid, not hibernating, and not too old. Else return 0.
References routerinfo_t::cache_info, routerinfo_t::is_hibernating, routerinfo_t::is_running, routerinfo_t::is_valid, signed_descriptor_t::published_on, and ROUTER_MAX_AGE_TO_PUBLISH.
Referenced by dirserv_compute_performance_thresholds(), and set_routerstatus_from_routerinfo().
int routerstatus_format_entry | ( | char * | buf, | |
size_t | buf_len, | |||
routerstatus_t * | rs, | |||
const char * | version, | |||
routerstatus_format_type_t | format | |||
) |
Helper: write the router-status information in rs into buf, which has at least buf_len free characters. Do NUL-termination. Use the same format as in network-status documents. If version is non-NULL, add a "v" line for the platform. Return 0 on success, -1 on failure.
The format argument has three possible values: NS_V2 - Output an entry suitable for a V2 NS opinion document NS_V3_CONSENSUS - Output the first portion of a V3 NS consensus entry NS_V3_CONSENSUS_MICRODESC - Output the first portion of a V3 microdesc consensus entry. NS_V3_VOTE - Output a complete V3 NS vote NS_CONTROL_PORT - Output a NS document for the control port
References routerstatus_t::addr, routerstatus_t::bandwidth, base16_encode(), BASE64_DIGEST_LEN, routerinfo_t::cache_info, routerstatus_t::descriptor_digest, DIGEST_LEN, digest_to_base64(), routerstatus_t::dir_port, routerinfo_t::exit_policy, format_iso_time(), routerstatus_t::has_bandwidth, routerstatus_t::has_measured_bw, HEX_DIGEST_LEN, routerstatus_t::identity_digest, INET_NTOA_BUF_LEN, 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, LD_BUG, MAX_V_LINE_LEN, routerstatus_t::measured_bw, routerstatus_t::nickname, routerstatus_t::or_port, policy_summarize(), routerstatus_t::published_on, router_get_advertised_bandwidth_capped(), router_get_by_digest(), signed_descriptor_t::signed_descriptor_digest, tor_assert, tor_free, tor_inet_ntoa(), and tor_snprintf().
Referenced by format_networkstatus_vote(), and networkstatus_getinfo_helper_single().
static void set_cached_dir | ( | cached_dir_t * | d, | |
char * | directory, | |||
time_t | when | |||
) | [static] |
Possibly replace the contents of d with the value of directory published on when, unless when is older than the last value, or too far in the future.
Does not copy directory; frees it if it isn't used.
References cached_dir_t::dir, cached_dir_t::dir_len, cached_dir_t::dir_z, cached_dir_t::dir_z_len, LD_BUG, LD_DIRSERV, cached_dir_t::published, ROUTER_MAX_AGE_TO_PUBLISH, tor_free, and tor_gzip_compress().
Referenced by dirserv_set_cached_directory(), and generate_runningrouters().
void set_routerstatus_from_routerinfo | ( | routerstatus_t * | rs, | |
routerinfo_t * | ri, | |||
time_t | now, | |||
int | naming, | |||
int | exits_can_be_guards, | |||
int | listbadexits, | |||
int | listbaddirs | |||
) |
Extract status information from ri and from other authority functions and store it in rs>. If naming, consider setting the named flag in rs. If not exits_can_be_guards, never mark an exit as a guard. If listbadexits, consider setting the badexit flag.
We assume that ri->is_running has already been set, e.g. by dirserv_set_router_is_running(ri, now);
References routerinfo_t::addr, routerstatus_t::addr, BANDWIDTH_TO_GUARANTEE_GUARD, routerinfo_t::cache_info, routerstatus_t::descriptor_digest, DIGEST_LEN, routerstatus_t::dir_port, routerinfo_t::dir_port, dirserv_get_name_status(), dirserv_thinks_router_is_hs_dir(), dirserv_thinks_router_is_unreliable(), FP_NAMED, FP_UNNAMED, routerstatus_t::identity_digest, signed_descriptor_t::identity_digest, routerstatus_t::is_authority, routerinfo_t::is_bad_directory, routerstatus_t::is_bad_directory, routerinfo_t::is_bad_exit, routerstatus_t::is_bad_exit, routerinfo_t::is_exit, routerstatus_t::is_exit, routerinfo_t::is_fast, routerstatus_t::is_fast, routerstatus_t::is_hs_dir, routerinfo_t::is_hs_dir, routerstatus_t::is_named, routerstatus_t::is_possible_guard, routerinfo_t::is_running, routerstatus_t::is_running, routerinfo_t::is_stable, routerstatus_t::is_stable, routerstatus_t::is_unnamed, routerstatus_t::is_v2_dir, routerinfo_t::is_valid, routerstatus_t::is_valid, routerstatus_t::nickname, routerinfo_t::nickname, routerinfo_t::or_port, routerstatus_t::or_port, routerinfo_t::platform, signed_descriptor_t::published_on, routerstatus_t::published_on, rep_hist_get_weighted_fractional_uptime(), rep_hist_get_weighted_time_known(), router_get_advertised_bandwidth(), router_is_active(), signed_descriptor_t::signed_descriptor_digest, and tor_version_as_new_as().
Referenced by networkstatus_getinfo_by_purpose().
static int should_generate_v2_networkstatus | ( | void | ) | [static] |
Return true iff our opinion of the routers has been stale for long enough that we should generate a new v2 network status doc.
References authdir_mode_v2(), DIR_REGEN_SLACK_TIME, get_options(), and the_v2_networkstatus_is_dirty.
Referenced by dirserv_get_networkstatus_v2(), and dirserv_get_networkstatus_v2_fingerprints().
static char* version_from_platform | ( | const char * | platform | ) | [static] |
Given a platform string as in a routerinfo_t (possibly null), return a newly allocated version string for a networkstatus document, or NULL if the platform doesn't give a Tor version.
References find_whitespace(), and strcmpstart().
static int WRA_MORE_SEVERE | ( | was_router_added_t | a, | |
was_router_added_t | b | |||
) | [static] |
True iff a is more severe than b.
Referenced by dirserv_add_multiple_descriptors().
strmap_t* cached_consensuses = NULL [static] |
Map from flavor name to the v3 consensuses that we're currently serving.
Referenced by dirserv_free_all(), dirserv_get_consensus(), dirserv_set_cached_consensus_networkstatus(), and lookup_cached_dir_by_fp().
cached_dir_t* cached_directory = NULL [static] |
The v1 directory we'll serve (as a cache or as an authority) if requested.
cached_dir_t cached_runningrouters [static] |
The v1 runningrouters document we'll serve (as a cache or as an authority) if requested.
digestmap_t* cached_v2_networkstatus = NULL [static] |
Used for other dirservers' v2 network statuses. Map from hexdigest to cached_dir_t.
Referenced by dirserv_clear_old_networkstatuses(), dirserv_free_all(), dirserv_get_networkstatus_v2(), dirserv_get_networkstatus_v2_fingerprints(), dirserv_set_cached_networkstatus_v2(), and lookup_cached_dir_by_fp().
int enough_mtbf_info = 0 [static] |
If true, we have measured enough mtbf info to look at stable_mtbf rather than stable_uptime.
uint32_t fast_bandwidth = 0 [static] |
Any router with a bandwidth at least this high is "Fast"
authdir_config_t* fingerprint_list = NULL [static] |
Should be static; exposed for testing.
uint32_t guard_bandwidth_excluding_exits = 0 [static] |
If exits can't be guards, then all guards must have a bandwidth this high.
uint32_t guard_bandwidth_including_exits = 0 [static] |
If exits can be guards, then all guards must have a bandwidth this high.
long guard_tk = 0 [static] |
Don't call a router a guard unless we've known about it for at least this many seconds.
double guard_wfu = 0.0 [static] |
Any router with a weighted fractional uptime of at least this much might be good as a guard.
time_t runningrouters_is_dirty = 1 [static] |
Do we need to regenerate the v1 runningrouters document when somebody asks for it?
Referenced by directory_set_dirty(), dirserv_get_runningrouters(), and generate_runningrouters().
double stable_mtbf = 0.0 [static] |
Any router with an mtbf of at least this value is stable.
uint32_t stable_uptime = 0 [static] |
Any router with an uptime of at least this value is stable.
cached_dir_t* the_directory = NULL [static] |
Most recently generated encoded signed v1 directory. (v1 auth dirservers only.)
time_t the_directory_is_dirty = 1 [static] |
Do we need to regenerate the v1 directory when someone asks for it?
Referenced by directory_set_dirty(), dirserv_get_directory(), and dirserv_regenerate_directory().
cached_dir_t the_runningrouters [static] |
For authoritative directories: the current (v1) network status.
cached_dir_t* the_v2_networkstatus = NULL [static] |
For authoritative directories: the current (v2) network status.
time_t the_v2_networkstatus_is_dirty = 1 [static] |
Do we need to regenerate our v2 networkstatus document when somebody asks for it?
Referenced by directory_set_dirty(), and should_generate_v2_networkstatus().
time_t time_of_process_start |
What time did this process start up?
Referenced by dumpstats(), and tor_init().
uint64_t total_bandwidth = 0 [static] |
Total bandwidth of all the routers we're considering.
uint64_t total_exit_bandwidth = 0 [static] |
Total bandwidth of all the exit routers we're considering.