39#define NETWORKSTATUS_PRIVATE
47#include "core/or/channelpadding.h"
57#include "core/or/dos.h"
153 { 0, 0, 0, DL_SCHED_CONSENSUS, DL_WANT_ANY_DIRSERVER,
154 DL_SCHED_INCREMENT_FAILURE, 0, 0 },
155 { 0, 0, 0, DL_SCHED_CONSENSUS, DL_WANT_ANY_DIRSERVER,
156 DL_SCHED_INCREMENT_FAILURE, 0, 0 },
159#define N_CONSENSUS_BOOTSTRAP_SCHEDULES 2
160#define CONSENSUS_BOOTSTRAP_SOURCE_AUTHORITY 0
161#define CONSENSUS_BOOTSTRAP_SOURCE_ANY_DIRSERVER 1
170 consensus_bootstrap_dl_status[N_CONSENSUS_BOOTSTRAP_SCHEDULES] =
172 { 0, 0, 0, DL_SCHED_CONSENSUS, DL_WANT_AUTHORITY,
173 DL_SCHED_INCREMENT_ATTEMPT, 0, 0 },
175 { 0, 0, 0, DL_SCHED_CONSENSUS, DL_WANT_ANY_DIRSERVER,
176 DL_SCHED_INCREMENT_ATTEMPT, 0, 0 },
195 const char *source_dir);
218 "In networkstatus_reset_download_failures()");
223 for (i=0; i < N_CONSENSUS_BOOTSTRAP_SCHEDULES; ++i)
230 const char *flavorname,
231 int unverified_consensus))
235 if (unverified_consensus) {
236 prefix =
"unverified";
240 if (flav == FLAV_NS) {
243 tor_snprintf(buf,
sizeof(buf),
"%s-%s-consensus", prefix, flavorname);
246 return get_cachedir_fname(buf);
255 const char *flavorname,
256 int unverified_consensus)
260 unverified_consensus);
281 const unsigned int flags = NSSET_FROM_CACHE | NSSET_DONT_DOWNLOAD_CERTS;
293 flags | NSSET_WAS_WAITING_FOR_CERTS,
361 tor_free(ns->recommended_client_protocols);
363 tor_free(ns->required_client_protocols);
364 tor_free(ns->required_relay_protocols);
393 document_signature_free(sig));
394 smartlist_free(voter->sigs);
397 } SMARTLIST_FOREACH_END(voter);
398 smartlist_free(ns->
voters);
400 authority_cert_free(ns->
cert);
403 if (ns->
type == NS_TYPE_VOTE || ns->
type == NS_TYPE_OPINION) {
405 vote_routerstatus_free(rs));
408 routerstatus_free(rs));
422 dirvote_clear_commits(ns);
436 const char *identity)
438 if (!vote || !vote->
voters)
472 size_t signed_digest_len;
485 log_warn(
LD_DIR,
"Ignoring a consensus signature made with deprecated"
493 signed_digest = tor_malloc(signed_digest_len);
500 log_warn(
LD_DIR,
"Got a bad signature on a networkstatus vote");
522 int n_missing_key = 0, n_dl_failed_key = 0;
525 int n_no_signature = 0;
527 int n_required = n_v3_authorities/2 + 1;
534 time_t now = time(NULL);
542 int unknown_here = 0;
543 int missing_key_here = 0, dl_failed_key_here = 0;
545 if (!sig->good_signature && !sig->bad_signature &&
549 sig->identity_digest) != NULL;
552 sig->signing_key_digest);
560 }
else if (!cert || cert->
expires < now) {
564 ++dl_failed_key_here;
571 ++dl_failed_key_here;
575 if (sig->good_signature)
577 else if (sig->bad_signature)
579 } SMARTLIST_FOREACH_END(sig);
584 }
else if (bad_here) {
586 }
else if (missing_key_here) {
588 if (dl_failed_key_here)
590 }
else if (unknown_here) {
596 } SMARTLIST_FOREACH_END(voter);
607 if (warn > 1 || (warn >= 0 &&
608 (n_good + n_missing_key - n_dl_failed_key < n_required))) {
617 tor_log(severity,
LD_DIR,
"Consensus includes unrecognized authority "
618 "'%s' at %s:%" PRIu16
" (contact %s; identity %s)",
619 voter->nickname, voter->address, voter->ipv4_dirport,
620 voter->contact?voter->contact:
"n/a",
625 tor_log(severity,
LD_DIR,
"Looks like we need to download a new "
626 "certificate from authority '%s' at %s:%" PRIu16
627 " (contact %s; identity %s)",
628 voter->nickname, voter->address, voter->ipv4_dirport,
629 voter->contact?voter->contact:
"n/a",
634 tor_log(severity,
LD_DIR,
"Consensus does not include configured "
635 "authority '%s' at %s:%" PRIu16
" (identity %s)",
636 ds->nickname, ds->address, ds->ipv4_dirport,
644 "A consensus needs %d good signatures from recognized "
645 "authorities for us to accept it. "
646 "This %s one has %d (%s).",
651 if (n_no_signature) {
654 "%d (%s) of the authorities we know didn't sign it.",
655 n_no_signature, tmp);
660 "It has %d signatures from authorities we don't "
661 "recognize.", n_unknown);
665 "correctly.", n_bad);
669 "We were unable to check %d of the signatures, "
670 "because we were missing the keys.", n_missing_key);
680 smartlist_free(list_good);
681 smartlist_free(list_no_signature);
682 smartlist_free(unrecognized);
683 smartlist_free(need_certs_from);
684 smartlist_free(missing_authorities);
686 if (n_good == n_v3_authorities)
688 else if (n_good >= n_required)
690 else if (n_good + n_missing_key >= n_required)
698#define NETWORKSTATUS_ALLOW_SKEW (24*60*60)
705 const char *key = _key;
714 const void **_member)
716 const char *key = _key;
743 const char *digest,
int *found_out)
766 digestmap_set(m, rs->descriptor_digest, rs);
794 !(digestmap_iter_done(i));
796 digestmap_iter_get(i, &digest, &rs);
830 return &rs->dl_status;
857#define AUTHORITY_NS_CACHE_INTERVAL (10*60)
861#define NONAUTHORITY_NS_CACHE_INTERVAL (60*60)
899 if (authdir_mode_v3(options) ||
915#define DELAY_WHILE_FETCHING_CERTS (20*60)
919#define MIN_DELAY_FOR_FETCH_CERT_STATUS_FAILURE (1*60)
927check_consensus_waiting_for_certs(
int flavor, time_t now,
964 const int use_multi_conn =
972 const char *resource;
974 int max_in_progress_conns = 1;
980 if (! (c && c->
valid_after <= now && now <= c->valid_until)) {
991 if (we_are_bootstrapping && use_multi_conn) {
992 max_in_progress_conns =
998 >= max_in_progress_conns) {
1004 if (we_are_bootstrapping && use_multi_conn
1008 if (networkstatus_consensus_is_already_downloading(resource))
1031 log_info(
LD_DIR,
"Launching %s standard networkstatus consensus "
1061 log_info(
LD_DIR,
"Launching %s bootstrap %s networkstatus consensus "
1062 "download.", resource, (want_authority == DL_WANT_AUTHORITY
1107 &consensus_bootstrap_dl_status[CONSENSUS_BOOTSTRAP_SOURCE_ANY_DIRSERVER];
1109 if (!check_consensus_waiting_for_certs(usable_flavor, now, dls_f)) {
1112 DL_WANT_ANY_DIRSERVER);
1118 &consensus_bootstrap_dl_status[CONSENSUS_BOOTSTRAP_SOURCE_AUTHORITY];
1120 if (!check_consensus_waiting_for_certs(usable_flavor, now, dls_a)) {
1143#define CONSENSUS_MIN_SECONDS_BEFORE_CACHING 120
1156 if (c && c->
valid_after <= now && now <= c->valid_until) {
1162 if (min_sec_before_caching > interval/16) {
1167 min_sec_before_caching = interval/16;
1169 if (min_sec_before_caching == 0) {
1170 min_sec_before_caching = 1;
1177 start = (time_t)(c->
fresh_until + min_sec_before_caching);
1181 if (min_sec_before_caching + dl_interval > interval)
1182 dl_interval = interval/2;
1185 dl_interval = interval/2;
1190 start = (time_t)(c->
fresh_until + (interval*3)/4);
1198 start = (time_t)(start + dl_interval + min_sec_before_caching);
1200 dl_interval = (c->
valid_until - start) - min_sec_before_caching;
1204 if (dl_interval < 1)
1210 "fresh_until: %ld start: %ld "
1211 "dl_interval: %ld valid_until: %ld ",
1217 tor_assert(start+dl_interval < c->valid_until);
1221 char tbuf1[ISO_TIME_LEN+1];
1222 char tbuf2[ISO_TIME_LEN+1];
1223 char tbuf3[ISO_TIME_LEN+1];
1227 log_info(
LD_DIR,
"Live %s consensus %s the most recent until %s and "
1228 "will expire at %s; fetching the next one at %s.",
1229 flavor, (c->
fresh_until > now) ?
"will be" :
"was",
1230 tbuf1, tbuf2, tbuf3);
1234 log_info(
LD_DIR,
"No live %s consensus; we should fetch one immediately.",
1268 *msg_out =
"DisableNetwork is set.";
1270 log_info(
LD_DIR,
"Delaying dir fetches (DisableNetwork is set)");
1276 *msg_out =
"We are hibernating or shutting down.";
1278 log_info(
LD_DIR,
"Delaying dir fetches (Hibernating or shutting down)");
1287 *msg_out =
"No running bridges";
1289 log_info(
LD_DIR,
"Delaying dir fetches (no running bridges known)");
1295 *msg_out =
"Pluggable transport proxies still configuring";
1297 log_info(
LD_DIR,
"Delaying dir fetches (pt proxies still configuring)");
1355 const int we_are_bootstrapping =
1359 dl = &((we_are_bootstrapping ?
1374 dl = &(consensus_bootstrap_dl_status[flavor]);
1412 else if (f == FLAV_MICRODESC)
1437 return (ns->
valid_after <= now && now <= ns->valid_until);
1450 if (BUG(!consensus))
1459#define REASONABLY_LIVE_TIME (24*60*60)
1468 return (now >= valid_after - REASONABLY_LIVE_TIME);
1478 return (now <= valid_until + REASONABLY_LIVE_TIME);
1545 tor_assert(smartlist_len(router_get_fallback_dir_servers())
1546 >= smartlist_len(router_get_trusted_dir_servers()));
1550 && (smartlist_len(router_get_fallback_dir_servers())
1551 > smartlist_len(router_get_trusted_dir_servers())));
1557networkstatus_consensus_is_already_downloading(
const char *resource)
1583 } SMARTLIST_FOREACH_END(dirconn);
1584 smartlist_free(fetching_conns);
1621 a->is_v2_dir != b->is_v2_dir ||
1649 SMARTLIST_FOREACH_JOIN(
1657 } SMARTLIST_FOREACH_JOIN_END(rs_old, rs_new);
1660 smartlist_free(changed);
1669 dos_consensus_has_changed(new_c);
1670 relay_consensus_has_changed(new_c);
1680notify_after_networkstatus_changes(
void)
1738 rs_new->last_dir_503_at = rs_old->last_dir_503_at;
1740 if (
tor_memeq(rs_old->descriptor_digest, rs_new->descriptor_digest,
1745 } SMARTLIST_FOREACH_JOIN_END(rs_old, rs_new);
1748#ifdef TOR_UNIT_TESTS
1768 case FLAV_MICRODESC:
1789 const char *source_dir)
1796 flavor, flags, source_dir);
1798 if (rv < 0 && tor_memstr(map->
data, map->
size,
"\r\n")) {
1799 log_notice(
LD_GENERAL,
"Looks like the above failures are probably "
1800 "because of a CRLF in consensus file %s; falling back to "
1801 "read_file_to_string. Nothing to worry about: this file "
1802 "was probably saved by an earlier version of Tor.",
1806 flavor, flags, source_dir);
1811 log_warn(
LD_GENERAL,
"Couldn't set consensus from cache file %s",
1814 tor_munmap_file(map);
1826 char *protocol_warning = NULL;
1831 if (protocol_warning) {
1834 "%s", protocol_warning);
1837 tor_assert_nonfatal(protocol_warning);
1882 char tbuf[ISO_TIME_LEN+1];
1885 char *flavormsg = NULL;
1890#define EARLY_CONSENSUS_NOTICE_SKEW 60
1903 log_warn(
LD_GENERAL,
"Our clock is %s behind the time published in the "
1904 "consensus network status document (%s UTC). Tor needs an "
1905 "accurate clock to work correctly. Please check your time and "
1906 "date settings!", dbuf, tbuf);
1907 tor_asprintf(&flavormsg,
"%s flavor consensus", flavor);
1935 size_t consensus_len,
1938 const char *source_dir)
1944 char *unverified_fname = NULL, *consensus_fname = NULL;
1946 const unsigned from_cache = flags & NSSET_FROM_CACHE;
1947 const unsigned was_waiting_for_certs = flags & NSSET_WAS_WAITING_FOR_CERTS;
1948 const unsigned dl_certs = !(flags & NSSET_DONT_DOWNLOAD_CERTS);
1949 const unsigned accept_obsolete = flags & NSSET_ACCEPT_OBSOLETE;
1950 const unsigned require_flavor = flags & NSSET_REQUIRE_FLAVOR;
1953 time_t current_valid_after = 0;
1954 int free_consensus = 1;
1955 int checked_protocols_already = 0;
1959 log_warn(
LD_BUG,
"Unrecognized consensus flavor %s", flavor);
1966 NULL, NS_TYPE_CONSENSUS);
1968 log_warn(
LD_DIR,
"Unable to parse networkstatus consensus");
1973 if (from_cache && !was_waiting_for_certs) {
1979 checked_protocols_already = 1;
1983 if ((
int)c->
flavor != flav) {
1985 if (require_flavor) {
1986 log_warn(
LD_DIR,
"Got consensus with unexpected flavor %s (wanted %s)",
2001 if (from_cache && !accept_obsolete &&
2003 log_info(
LD_DIR,
"Loaded an expired consensus. Discarding.");
2007 if (!strcmp(flavor,
"ns")) {
2008 consensus_fname = get_cachedir_fname(
"cached-consensus");
2009 unverified_fname = get_cachedir_fname(
"unverified-consensus");
2014 }
else if (!strcmp(flavor,
"microdesc")) {
2015 consensus_fname = get_cachedir_fname(
"cached-microdesc-consensus");
2016 unverified_fname = get_cachedir_fname(
"unverified-microdesc-consensus");
2027 if (current_digests &&
2030 log_info(
LD_DIR,
"Got a %s consensus we already have", flavor);
2034 if (current_valid_after && c->
valid_after <= current_valid_after) {
2037 log_info(
LD_DIR,
"Got a %s consensus at least as old as the one we have",
2046 if (!was_waiting_for_certs) {
2048 "Not enough certificates to check networkstatus consensus");
2050 if (!current_valid_after ||
2053 networkstatus_vote_free(waiting->
consensus);
2069 if (was_waiting_for_certs && from_cache)
2070 if (unlink(unverified_fname) != 0) {
2072 "Failed to unlink %s: %s",
2073 unverified_fname, strerror(errno));
2079 if (!was_waiting_for_certs) {
2080 log_warn(
LD_DIR,
"Not enough good signatures on networkstatus "
2084 if (was_waiting_for_certs && (r < -1) && from_cache) {
2085 if (unlink(unverified_fname) != 0) {
2087 "Failed to unlink %s: %s",
2088 unverified_fname, strerror(errno));
2096 if (from_cache && was_waiting_for_certs) {
2100 log_info(
LD_DIR,
"Unverified consensus signatures verified.");
2101 tor_rename(unverified_fname, consensus_fname);
2107 if (!checked_protocols_already) {
2112 if (r != 1 && dl_certs)
2119 if (is_usable_flavor) {
2123 if (flav == FLAV_NS) {
2134 }
else if (flav == FLAV_MICRODESC) {
2148 networkstatus_vote_free(waiting->
consensus);
2152 if (unlink(unverified_fname) != 0) {
2154 "Failed to unlink %s: %s",
2155 unverified_fname, strerror(errno));
2159 if (is_usable_flavor) {
2162 notify_after_networkstatus_changes();
2166 if (c->
valid_after <= now && now <= c->valid_until) {
2200 networkstatus_vote_free(c);
2225 NSSET_WAS_WAITING_FOR_CERTS, source_dir);
2243 if (!consensus || dir_version < 3)
2259 const char *recommended = is_server ?
2264 log_info(
LD_GENERAL,
"The directory authorities say my version is ok.");
2267 "The directory authorities don't recommend any versions.");
2270 log_notice(
LD_GENERAL,
"This version of Tor (%s) is newer than any "
2271 "recommended version%s, according to the directory "
2272 "authorities. Recommended versions are: %s",
2278 "CURRENT=%s REASON=%s RECOMMENDED=\"%s\"",
2279 VERSION,
"NEW", recommended);
2283 "This version of Tor (%s) is %s, according to the directory "
2284 "authorities. Recommended versions are: %s",
2286 status ==
VS_OLD ?
"obsolete" :
"not recommended",
2290 "CURRENT=%s REASON=%s RECOMMENDED=\"%s\"",
2291 VERSION, status ==
VS_OLD ?
"OBSOLETE" :
"UNRECOMMENDED",
2305 int authdir = authdir_mode_v3(options);
2315 router->cache_info.identity_digest,
DIGEST_LEN),
2319 if (
tor_memeq(router->cache_info.signed_descriptor_digest,
2321 if (ns->
valid_until > router->cache_info.last_listed_as_valid_until)
2322 router->cache_info.last_listed_as_valid_until = ns->
valid_until;
2330 if (old_router != router) {
2331 router->needs_retest_if_added =
2335 if (reset_failures) {
2338 } SMARTLIST_FOREACH_JOIN_END(rs, router);
2355 memset(dummy, 0,
sizeof(dummy));
2361 d->signed_descriptor_digest);
2363 if (ns->
valid_until > d->last_listed_as_valid_until)
2439 log_info(
LD_DIR,
"Unrecognized purpose '%s' when listing router statuses.",
2449 if (ri->cache_info.published_on < cutoff)
2451 if (ri->purpose != purpose)
2457 } SMARTLIST_FOREACH_END(ri);
2461 smartlist_free(statuses);
2473 int32_t default_val, int32_t min_val, int32_t max_val)
2475 int32_t res = default_val;
2476 size_t name_len = strlen(param_name);
2483 if (!
strcmpstart(p, param_name) && p[name_len] ==
'=') {
2486 INT32_MAX, &ok, NULL);
2492 } SMARTLIST_FOREACH_END(p);
2494 if (res < min_val) {
2495 log_warn(
LD_DIR,
"Consensus parameter %s is too small. Got %d, raising to "
2496 "%d.", param_name, res, min_val);
2498 }
else if (res > max_val) {
2499 log_warn(
LD_DIR,
"Consensus parameter %s is too large. Got %d, capping to "
2500 "%d.", param_name, res, max_val);
2518 int32_t default_val, int32_t min_val, int32_t max_val))
2527 default_val, min_val, max_val);
2537 int32_t torrc_value,
2538 const char *param_name,
2539 int32_t default_val,
2540 int32_t min_val, int32_t max_val)
2542 if (torrc_value >= min_val && torrc_value <= max_val)
2546 ns, param_name, default_val, min_val, max_val);
2560 BW_MIN_WEIGHT_SCALE,
2561 BW_MAX_WEIGHT_SCALE);
2570 int32_t default_val)
2583 BW_MAX_WEIGHT_SCALE);
2585 log_warn(
LD_DIR,
"Value of consensus weight %s was too large, capping "
2586 "to %d", weight_name, max);
2600 case FLAV_MICRODESC:
2613 if (!strcmp(flavname,
"ns"))
2615 else if (!strcmp(flavname,
"microdesc"))
2616 return FLAV_MICRODESC;
2633 if (!routerstatus_version_supports_extend2_cells(rs, 1)) {
2648 const char *question,
char **answer,
2649 const char **errmsg)
2655 *answer = tor_strdup(
"");
2659 if (!strcmp(question,
"ns/all")) {
2668 smartlist_free(statuses);
2672 const char *q = question + 6;
2677 *errmsg =
"Data not decodeable as hex";
2683 status = n ? n->rs : NULL;
2684 }
else if (!
strcmpstart(question,
"ns/purpose/")) {
2686 return *answer ? 0 : -1;
2687 }
else if (!strcmp(question,
"consensus/packages")) {
2692 *errmsg =
"No consensus available";
2693 return *answer ? 0 : -1;
2694 }
else if (!strcmp(question,
"consensus/valid-after") ||
2695 !strcmp(question,
"consensus/fresh-until") ||
2696 !strcmp(question,
"consensus/valid-until")) {
2700 if (!strcmp(question,
"consensus/valid-after"))
2702 else if (!strcmp(question,
"consensus/fresh-until"))
2707 char tbuf[ISO_TIME_LEN+1];
2709 *answer = tor_strdup(tbuf);
2711 *errmsg =
"No consensus available";
2713 return *answer ? 0 : -1;
2734 const char *func = client_mode ?
"client" :
"relay";
2735 const char *required, *recommended;
2736 char *missing = NULL;
2738 const bool consensus_postdates_this_release =
2741 if (! consensus_postdates_this_release) {
2751 required = ns->required_client_protocols;
2752 recommended = ns->recommended_client_protocols;
2754 required = ns->required_relay_protocols;
2759 tor_asprintf(warning_out,
"At least one protocol listed as required in "
2760 "the consensus is not supported by this version of Tor. "
2761 "You should upgrade. This version of Tor will not work as a "
2762 "%s on the Tor network. The missing protocols are: %s",
2769 tor_asprintf(warning_out,
"At least one protocol listed as recommended in "
2770 "the consensus is not supported by this version of Tor. "
2771 "You should upgrade. This version of Tor will eventually "
2772 "stop working as a %s on the Tor network. The missing "
2773 "protocols are: %s",
2778 tor_assert_nonfatal(missing == NULL);
2795 networkstatus_vote_free(waiting->
consensus);
2811 time_t midnight_today=0;
2812 time_t midnight_tomorrow;
2822 log_warn(
LD_BUG,
"Ran into an invalid time when trying to find midnight.");
2825 midnight_tomorrow = midnight_today + (24*60*60);
2827 next = midnight_today + ((now-midnight_today)/interval + 1)*interval;
2830 if (next > midnight_tomorrow)
2831 next = midnight_tomorrow;
2835 if (next + interval/2 > midnight_tomorrow)
2836 next = midnight_tomorrow;
2839 if (next - interval > now)
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
int tor_addr_compare(const tor_addr_t *addr1, const tor_addr_t *addr2, tor_addr_comparison_t how)
#define tor_addr_eq(a, b)
void authority_certs_fetch_missing(networkstatus_t *status, time_t now, const char *dir_hint)
int authority_cert_is_denylisted(const authority_cert_t *cert)
int authority_cert_dl_looks_uncertain(const char *id_digest)
authority_cert_t * authority_cert_get_by_digests(const char *id_digest, const char *sk_digest)
Header file for authcert.c.
Header file for directory authority mode.
Authority certificate structure.
const char * hex_str(const char *from, size_t fromlen)
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
Header file for circuitbuild.c.
Header file for channel.c.
void channelpadding_new_consensus_params(const networkstatus_t *ns)
Header file for circuitmux.c.
void cmux_ewma_set_options(const or_options_t *options, const networkstatus_t *consensus)
Header file for circuitmux_ewma.c.
void circpad_new_consensus_params(const networkstatus_t *ns)
Header file for circuitpadding.c.
circuit_build_times_t * get_circuit_build_times_mutable(void)
void circuit_build_times_new_consensus_params(circuit_build_times_t *cbt, const networkstatus_t *ns)
Header file for circuitstats.c.
int options_any_client_port_set(const or_options_t *options)
const or_options_t * get_options(void)
Header file for config.c.
Header file for conflux_params.c.
void conflux_params_new_consensus(const networkstatus_t *ns)
void congestion_control_new_consensus_params(const networkstatus_t *ns)
Public APIs for congestion control.
void flow_control_new_consensus_params(const networkstatus_t *ns)
APIs for stream flow control on congestion controlled circuits.
void clock_skew_warning(const connection_t *conn, long apparent_skew, int trusted, log_domain_mask_t domain, const char *received, const char *source)
smartlist_t * connection_dir_list_by_purpose_resource_and_state(int purpose, const char *resource, int state)
Header file for connection.c.
static int connection_dir_count_by_purpose_and_resource(int purpose, const char *resource)
Header file for connection_edge.c.
#define AP_CONN_STATE_IS_UNATTACHED(s)
void connection_or_update_token_buckets(smartlist_t *conns, const or_options_t *options)
Header file for connection_or.c.
int consdiffmgr_add_consensus(const char *consensus, size_t consensus_len, const networkstatus_t *as_parsed)
Header for consdiffmgr.c.
int control_event_general_status(int severity, const char *format,...)
int control_event_networkstatus_changed(smartlist_t *statuses)
int control_event_is_interesting(int event)
int control_event_client_status(int severity, const char *format,...)
int control_event_newconsensus(const networkstatus_t *consensus)
Header file for control_events.c.
void cpuworker_consensus_has_changed(const networkstatus_t *ns)
Header file for cpuworker.c.
Common functions for using (pseudo-)random number generators.
int crypto_rand_int(unsigned int max)
int crypto_pk_get_digest(const crypto_pk_t *pk, char *digest_out)
size_t crypto_pk_keysize(const crypto_pk_t *env)
int crypto_pk_public_checksig(const crypto_pk_t *env, char *to, size_t tolen, const char *from, size_t fromlen)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
int tor_memeq(const void *a, const void *b, size_t sz)
int tor_memcmp(const void *a, const void *b, size_t len)
#define fast_memeq(a, b, c)
#define tor_memneq(a, b, sz)
#define fast_memneq(a, b, c)
Client/server directory connection structure.
Trusted/fallback directory server structure.
void reschedule_dirvote(const or_options_t *options)
Header for dirauth_periodic.c.
void directory_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose, const char *resource, int pds_flags, download_want_authority_t want_authority)
Header file for dirclient.c.
int dirclient_fetches_dir_info_later(const or_options_t *options)
int dirclient_fetches_dir_info_early(const or_options_t *options)
int dirclient_fetches_from_authorities(const or_options_t *options)
Header for feature/dirclient/dirclient_modes.c.
Header file for directory.c.
#define DIR_CONN_STATE_CLIENT_READING
#define DIR_PURPOSE_FETCH_CONSENSUS
int get_n_authorities(dirinfo_type_t type)
dir_server_t * trusteddirserver_get_by_v3_auth_digest(const char *digest)
Header file for dirlist.c.
int directory_caches_dir_info(const or_options_t *options)
int directory_caches_unknown_auth_certs(const or_options_t *options)
void dirserv_set_cached_consensus_networkstatus(const char *networkstatus, size_t networkstatus_len, const char *flavor_name, const common_digests_t *digests, const uint8_t *sha3_as_signed, time_t published)
Header file for dirserv.c.
Header file for dirvote.c.
int download_status_is_ready(download_status_t *dls, time_t now)
time_t download_status_increment_attempt(download_status_t *dls, const char *item, time_t now)
void download_status_reset(download_status_t *dls)
Header file for dlstatus.c.
#define download_status_failed(dls, sc)
void dns_new_consensus_params(const networkstatus_t *ns)
Authority signature structure.
int num_bridges_usable(int use_maybe_reachable)
void maintain_layer2_guards(void)
Header file for circuitbuild.c.
const char * escaped(const char *s)
#define RFTS_IGNORE_MISSING
int write_bytes_to_file(const char *fname, const char *str, size_t len, int bin)
int tor_rename(const char *path_old, const char *path_new)
Format routerstatus entries for controller, vote, or consensus.
char * routerstatus_format_entry(const routerstatus_t *rs, const char *version, const char *protocols, routerstatus_format_type_t format, const vote_routerstatus_t *vrs, time_t declared_publish_time)
int we_are_hibernating(void)
Header file for hibernate.c.
void hs_dos_consensus_has_changed(const networkstatus_t *ns)
Header file containing denial of service defenses for the HS subsystem for all versions.
void hs_service_new_consensus_params(const networkstatus_t *ns)
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
smartlist_t * get_connection_array(void)
Header file for mainloop.c.
void microdesc_reset_outdated_dirservers_list(void)
int usable_consensus_flavor(void)
void update_microdescs_from_networkstatus(time_t now)
int we_use_microdescriptors_for_circuits(const or_options_t *options)
Header file for microdesc.c.
networkstatus_t * networkstatus_get_latest_consensus_by_flavor(consensus_flavor_t f)
int networkstatus_valid_after_is_reasonably_live(time_t valid_after, time_t now)
void update_networkstatus_downloads(time_t now)
int networkstatus_consensus_can_use_multiple_directories(const or_options_t *options)
int getinfo_helper_networkstatus(control_connection_t *conn, const char *question, char **answer, const char **errmsg)
download_status_t * networkstatus_get_dl_status_by_flavor_bootstrap(consensus_flavor_t flavor)
static tor_mmap_t * networkstatus_map_cached_consensus_impl(int flav, const char *flavorname, int unverified_consensus)
int networkstatus_check_document_signature(const networkstatus_t *consensus, document_signature_t *sig, const authority_cert_t *cert)
void routers_update_all_from_networkstatus(time_t now, int dir_version)
int networkstatus_parse_flavor_name(const char *flavname)
STATIC networkstatus_t * current_md_consensus
const char * networkstatus_get_flavor_name(consensus_flavor_t flav)
int networkstatus_set_current_consensus(const char *consensus, size_t consensus_len, const char *flavor, unsigned flags, const char *source_dir)
STATIC int routerstatus_has_visibly_changed(const routerstatus_t *a, const routerstatus_t *b)
int compare_digest_to_vote_routerstatus_entry(const void *_key, const void **_member)
static int reload_consensus_from_file(const char *fname, const char *flavor, unsigned flags, const char *source_dir)
static void notify_control_networkstatus_changed(const networkstatus_t *old_c, const networkstatus_t *new_c)
void signed_descs_update_status_from_consensus_networkstatus(smartlist_t *descs)
document_signature_t * networkstatus_get_voter_sig_by_alg(const networkstatus_voter_info_t *voter, digest_algorithm_t alg)
int networkstatus_consensus_reasonably_live(const networkstatus_t *consensus, time_t now)
download_status_t * networkstatus_get_dl_status_by_flavor_running(consensus_flavor_t flavor)
int we_want_to_fetch_flavor(const or_options_t *options, int flavor)
int32_t networkstatus_get_overridable_param(const networkstatus_t *ns, int32_t torrc_value, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
download_status_t * router_get_dl_status_by_descriptor_digest(const char *d)
networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor)
time_t voting_sched_get_start_of_interval_after(time_t now, int interval, int offset)
int client_would_use_router(const routerstatus_t *rs, time_t now)
networkstatus_t * networkstatus_get_latest_consensus(void)
static void handle_missing_protocol_warning(const networkstatus_t *c, const or_options_t *options)
const routerstatus_t * router_get_consensus_status_by_descriptor_digest(networkstatus_t *consensus, const char *digest)
static void update_consensus_bootstrap_attempt_downloads(time_t now, download_status_t *dls, download_want_authority_t want_authority)
int networkstatus_vote_find_entry_idx(networkstatus_t *ns, const char *digest, int *found_out)
static void networkstatus_copy_old_consensus_info(networkstatus_t *new_c, const networkstatus_t *old_c)
static download_status_t consensus_dl_status[N_CONSENSUS_FLAVORS]
void document_signature_free_(document_signature_t *sig)
networkstatus_voter_info_t * networkstatus_get_voter_by_id(networkstatus_t *vote, const char *identity)
STATIC networkstatus_t * current_ns_consensus
void networkstatus_free_all(void)
static void update_consensus_networkstatus_downloads(time_t now)
static int32_t get_net_param_from_list(smartlist_t *net_params, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
download_status_t * networkstatus_get_dl_status_by_flavor(consensus_flavor_t flavor)
routerstatus_t * router_get_mutable_consensus_status_by_descriptor_digest(networkstatus_t *consensus, const char *digest)
char * networkstatus_getinfo_helper_single(const routerstatus_t *rs)
void networkstatus_note_certs_arrived(const char *source_dir)
tor_mmap_t * networkstatus_map_cached_consensus(const char *flavorname)
int32_t networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight_name, int32_t default_val)
int networkstatus_consensus_is_bootstrapping(time_t now)
const routerstatus_t * networkstatus_vote_find_entry(networkstatus_t *ns, const char *digest)
int networkstatus_check_consensus_signature(networkstatus_t *consensus, int warn)
static int have_warned_about_old_version
document_signature_t * document_signature_dup(const document_signature_t *sig)
int networkstatus_valid_until_is_reasonably_live(time_t valid_until, time_t now)
int networkstatus_is_live(const networkstatus_t *ns, time_t now)
int compare_digest_to_routerstatus_entry(const void *_key, const void **_member)
routerstatus_t * networkstatus_vote_find_mutable_entry(networkstatus_t *ns, const char *digest)
void vote_routerstatus_free_(vote_routerstatus_t *rs)
static void update_consensus_bootstrap_multiple_downloads(time_t now, const or_options_t *options)
int should_delay_dir_fetches(const or_options_t *options, const char **msg_out)
static int networkstatus_check_required_protocols(const networkstatus_t *ns, int client_mode, char **warning_out)
int router_reload_consensus_networkstatus(void)
void update_certificate_downloads(time_t now)
int networkstatus_consensus_can_use_extra_fallbacks(const or_options_t *options)
static void handle_missing_protocol_warning_impl(const networkstatus_t *c, int is_client)
const routerstatus_t * router_get_consensus_status_by_id(const char *digest)
smartlist_t * router_get_descriptor_digests(void)
char * networkstatus_get_cache_fname(int flav, const char *flavorname, int unverified_consensus)
static smartlist_t * router_get_descriptor_digests_in_consensus(networkstatus_t *consensus)
char * networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now)
static time_t time_to_download_next_consensus[N_CONSENSUS_FLAVORS]
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
networkstatus_t * networkstatus_get_live_consensus(time_t now)
void set_routerstatus_from_routerinfo(routerstatus_t *rs, const node_t *node, const routerinfo_t *ri)
STATIC void warn_early_consensus(const networkstatus_t *c, const char *flavor, time_t now)
#define MIN_DELAY_FOR_FETCH_CERT_STATUS_FAILURE
void networkstatus_vote_free_(networkstatus_t *ns)
#define DELAY_WHILE_FETCHING_CERTS
static int have_warned_about_new_version
static void update_consensus_networkstatus_fetch_time_impl(time_t now, int flav)
void update_consensus_networkstatus_fetch_time(time_t now)
void networkstatus_reset_download_failures(void)
void networkstatus_reset_warnings(void)
int we_want_to_fetch_unknown_auth_certs(const or_options_t *options)
routerstatus_t * router_get_mutable_consensus_status_by_id(const char *digest)
#define CONSENSUS_MIN_SECONDS_BEFORE_CACHING
static consensus_waiting_for_certs_t consensus_waiting_for_certs[N_CONSENSUS_FLAVORS]
int consensus_is_waiting_for_certs(void)
void routerstatus_free_(routerstatus_t *rs)
void networkstatus_consensus_download_failed(int status_code, const char *flavname)
void routers_update_status_from_consensus_networkstatus(smartlist_t *routers, int reset_failures)
int networkstatus_get_weight_scale_param(networkstatus_t *ns)
Header file for networkstatus.c.
Networkstatus consensus/vote structure.
Single consensus voter structure.
Header file for node_select.c.
#define PDS_RETRY_IF_NO_SERVERS
Node information structure.
void router_dir_info_changed(void)
const smartlist_t * nodelist_get_list(void)
const node_t * node_get_by_nickname(const char *nickname, unsigned flags)
void nodelist_set_consensus(const networkstatus_t *ns)
node_t * node_get_mutable_by_id(const char *identity_digest)
Header file for nodelist.c.
Detached consensus signatures structure.
Header file for ns_parse.c.
networkstatus_t * networkstatus_parse_vote_from_string(const char *s, size_t len, const char **eos_out, enum networkstatus_type_t ns_type)
void onion_consensus_has_changed(const networkstatus_t *ns)
Header file for onion_queue.c.
Master header file for Tor-specific functionality.
#define OLD_ROUTER_DESC_MAX_AGE
download_want_authority_t
#define ROUTER_MAX_AGE_TO_PUBLISH
#define N_CONSENSUS_FLAVORS
long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next)
int tor_asprintf(char **strp, const char *fmt,...)
int tor_snprintf(char *str, size_t size, const char *format,...)
int protover_all_supported(const char *s, char **missing_out)
Headers and type declarations for protover.c.
int dirserv_should_launch_reachability_test(const routerinfo_t *ri, const routerinfo_t *ri_old)
Header file for reachability.c.
void rep_hist_consensus_has_changed(const networkstatus_t *ns)
Header file for rephist.c.
void router_new_consensus_params(const networkstatus_t *ns)
uint8_t router_purpose_from_string(const char *s)
Header file for routerinfo.c.
Router descriptor structure.
#define ROUTER_PURPOSE_UNKNOWN
#define ROUTER_PURPOSE_GENERAL
routerlist_t * router_get_routerlist(void)
void routers_sort_by_identity(smartlist_t *routers)
routerinfo_t * router_get_mutable_by_digest(const char *digest)
Header file for routerlist.c.
Router descriptor list structure.
int public_server_mode(const or_options_t *options)
int dir_server_mode(const or_options_t *options)
int server_mode(const or_options_t *options)
Header file for routermode.c.
Routerstatus (consensus entry) structure.
void scheduler_notify_networkstatus_changed(void)
Header file for scheduler*.c.
This file contains ABI/API of the shared random protocol defined in proposal #250....
void * smartlist_bsearch(const smartlist_t *sl, const void *key, int(*compare)(const void *key, const void **member))
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
int smartlist_bsearch_idx(const smartlist_t *sl, const void *key, int(*compare)(const void *key, const void **member), int *found_out)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
crypto_pk_t * signing_key
char signing_key_digest[DIGEST_LEN]
signed_descriptor_t cache_info
char d[N_COMMON_DIGEST_ALGORITHMS][DIGEST256_LEN]
struct connection_t * linked_conn
networkstatus_t * consensus
unsigned int good_signature
unsigned int bad_signature
char identity_digest[DIGEST_LEN]
char signing_key_digest[DIGEST_LEN]
download_schedule_bitfield_t schedule
smartlist_t * known_flags
char * recommended_relay_protocols
digestmap_t * desc_digest_map
smartlist_t * weight_params
smartlist_t * package_lines
smartlist_t * supported_methods
smartlist_t * routerstatus_list
networkstatus_sr_info_t sr_info
uint8_t digest_sha3_as_signed[DIGEST256_LEN]
struct authority_cert_t * cert
consensus_flavor_t flavor
networkstatus_type_t type
smartlist_t * bw_file_headers
char identity[DIGEST_LEN]
unsigned int is_possible_guard
unsigned int name_lookup_warned
int ClientBootstrapConsensusMaxInProgressTries
int FetchDirInfoExtraEarly
int FetchUselessDescriptors
unsigned int supports_tunnelled_dir_requests
smartlist_t * old_routers
unsigned int is_staledesc
char descriptor_digest[DIGEST256_LEN]
char identity_digest[DIGEST_LEN]
char nickname[MAX_NICKNAME_LEN+1]
unsigned int has_bandwidth
unsigned int is_possible_guard
unsigned int is_flagged_running
unsigned int is_authority
char signed_descriptor_digest[DIGEST_LEN]
char identity_digest[DIGEST_LEN]
struct vote_microdesc_hash_t * next
char * microdesc_hash_line
vote_microdesc_hash_t * microdesc
#define MOCK_IMPL(rv, funcname, arglist)
struct tm * tor_gmtime_r(const time_t *timep, struct tm *result)
void format_iso_time(char *buf, time_t t)
void format_local_iso_time(char *buf, time_t t)
int tor_timegm(const struct tm *tm, time_t *time_out)
int format_time_interval(char *out, size_t out_len, long interval)
int pt_proxies_configuration_pending(void)
Headers for transports.c.
#define tor_assert_nonfatal_unreached()
#define tor_fragile_assert()
int strcmpstart(const char *s1, const char *s2)
time_t tor_get_approx_release_date(void)
version_status_t tor_version_is_obsolete(const char *myversion, const char *versionlist)
Header file for versions.c.
Microdescriptor-hash voting structure.
Routerstatus (vote entry) structure.
Header file for voteflags.c.
void dirauth_sched_recalculate_timing(const or_options_t *options, time_t now)
Header file for voting_schedule.c.