39 #define NETWORKSTATUS_PRIVATE
46 #include "core/or/channelpadding.h"
53 #include "core/or/dos.h"
146 { 0, 0, 0, DL_SCHED_CONSENSUS, DL_WANT_ANY_DIRSERVER,
147 DL_SCHED_INCREMENT_FAILURE, 0, 0 },
148 { 0, 0, 0, DL_SCHED_CONSENSUS, DL_WANT_ANY_DIRSERVER,
149 DL_SCHED_INCREMENT_FAILURE, 0, 0 },
152 #define N_CONSENSUS_BOOTSTRAP_SCHEDULES 2
153 #define CONSENSUS_BOOTSTRAP_SOURCE_AUTHORITY 0
154 #define CONSENSUS_BOOTSTRAP_SOURCE_ANY_DIRSERVER 1
163 consensus_bootstrap_dl_status[N_CONSENSUS_BOOTSTRAP_SCHEDULES] =
165 { 0, 0, 0, DL_SCHED_CONSENSUS, DL_WANT_AUTHORITY,
166 DL_SCHED_INCREMENT_ATTEMPT, 0, 0 },
168 { 0, 0, 0, DL_SCHED_CONSENSUS, DL_WANT_ANY_DIRSERVER,
169 DL_SCHED_INCREMENT_ATTEMPT, 0, 0 },
188 const char *source_dir);
211 "In networkstatus_reset_download_failures()");
216 for (i=0; i < N_CONSENSUS_BOOTSTRAP_SCHEDULES; ++i)
223 const char *flavorname,
224 int unverified_consensus))
228 if (unverified_consensus) {
229 prefix =
"unverified";
233 if (flav == FLAV_NS) {
236 tor_snprintf(buf,
sizeof(buf),
"%s-%s-consensus", prefix, flavorname);
239 return get_cachedir_fname(buf);
248 const char *flavorname,
249 int unverified_consensus)
253 unverified_consensus);
274 const unsigned int flags = NSSET_FROM_CACHE | NSSET_DONT_DOWNLOAD_CERTS;
286 flags | NSSET_WAS_WAITING_FOR_CERTS,
354 tor_free(ns->recommended_client_protocols);
356 tor_free(ns->required_client_protocols);
357 tor_free(ns->required_relay_protocols);
386 document_signature_free(sig));
387 smartlist_free(voter->sigs);
390 } SMARTLIST_FOREACH_END(voter);
391 smartlist_free(ns->
voters);
393 authority_cert_free(ns->
cert);
396 if (ns->
type == NS_TYPE_VOTE || ns->
type == NS_TYPE_OPINION) {
398 vote_routerstatus_free(rs));
401 routerstatus_free(rs));
415 dirvote_clear_commits(ns);
429 const char *identity)
431 if (!vote || !vote->
voters)
465 size_t signed_digest_len;
478 log_warn(
LD_DIR,
"Ignoring a consensus signature made with deprecated"
486 signed_digest = tor_malloc(signed_digest_len);
493 log_warn(
LD_DIR,
"Got a bad signature on a networkstatus vote");
515 int n_missing_key = 0, n_dl_failed_key = 0;
518 int n_no_signature = 0;
520 int n_required = n_v3_authorities/2 + 1;
527 time_t now = time(NULL);
535 int unknown_here = 0;
536 int missing_key_here = 0, dl_failed_key_here = 0;
538 if (!sig->good_signature && !sig->bad_signature &&
542 sig->identity_digest) != NULL;
545 sig->signing_key_digest);
553 }
else if (!cert || cert->
expires < now) {
557 ++dl_failed_key_here;
564 ++dl_failed_key_here;
568 if (sig->good_signature)
570 else if (sig->bad_signature)
572 } SMARTLIST_FOREACH_END(sig);
577 }
else if (bad_here) {
579 }
else if (missing_key_here) {
581 if (dl_failed_key_here)
583 }
else if (unknown_here) {
589 } SMARTLIST_FOREACH_END(voter);
600 if (warn > 1 || (warn >= 0 &&
601 (n_good + n_missing_key - n_dl_failed_key < n_required))) {
610 tor_log(severity,
LD_DIR,
"Consensus includes unrecognized authority "
611 "'%s' at %s:%" PRIu16
" (contact %s; identity %s)",
612 voter->nickname, voter->address, voter->ipv4_dirport,
613 voter->contact?voter->contact:
"n/a",
618 tor_log(severity,
LD_DIR,
"Looks like we need to download a new "
619 "certificate from authority '%s' at %s:%" PRIu16
620 " (contact %s; identity %s)",
621 voter->nickname, voter->address, voter->ipv4_dirport,
622 voter->contact?voter->contact:
"n/a",
627 tor_log(severity,
LD_DIR,
"Consensus does not include configured "
628 "authority '%s' at %s:%" PRIu16
" (identity %s)",
629 ds->nickname, ds->address, ds->ipv4_dirport,
637 "A consensus needs %d good signatures from recognized "
638 "authorities for us to accept it. "
639 "This %s one has %d (%s).",
644 if (n_no_signature) {
647 "%d (%s) of the authorities we know didn't sign it.",
648 n_no_signature, tmp);
653 "It has %d signatures from authorities we don't "
654 "recognize.", n_unknown);
658 "correctly.", n_bad);
662 "We were unable to check %d of the signatures, "
663 "because we were missing the keys.", n_missing_key);
673 smartlist_free(list_good);
674 smartlist_free(list_no_signature);
675 smartlist_free(unrecognized);
676 smartlist_free(need_certs_from);
677 smartlist_free(missing_authorities);
679 if (n_good == n_v3_authorities)
681 else if (n_good >= n_required)
683 else if (n_good + n_missing_key >= n_required)
691 #define NETWORKSTATUS_ALLOW_SKEW (24*60*60)
698 const char *key = _key;
707 const void **_member)
709 const char *key = _key;
736 const char *digest,
int *found_out)
759 digestmap_set(m, rs->descriptor_digest, rs);
787 !(digestmap_iter_done(i));
789 digestmap_iter_get(i, &digest, &rs);
823 return &rs->dl_status;
850 #define AUTHORITY_NS_CACHE_INTERVAL (10*60)
854 #define NONAUTHORITY_NS_CACHE_INTERVAL (60*60)
892 if (authdir_mode_v3(options) ||
908 #define DELAY_WHILE_FETCHING_CERTS (20*60)
912 #define MIN_DELAY_FOR_FETCH_CERT_STATUS_FAILURE (1*60)
920 check_consensus_waiting_for_certs(
int flavor, time_t now,
957 const int use_multi_conn =
965 const char *resource;
967 int max_in_progress_conns = 1;
973 if (! (c && c->
valid_after <= now && now <= c->valid_until)) {
984 if (we_are_bootstrapping && use_multi_conn) {
985 max_in_progress_conns =
991 >= max_in_progress_conns) {
997 if (we_are_bootstrapping && use_multi_conn
1001 if (networkstatus_consensus_is_already_downloading(resource))
1024 log_info(
LD_DIR,
"Launching %s standard networkstatus consensus "
1054 log_info(
LD_DIR,
"Launching %s bootstrap %s networkstatus consensus "
1055 "download.", resource, (want_authority == DL_WANT_AUTHORITY
1100 &consensus_bootstrap_dl_status[CONSENSUS_BOOTSTRAP_SOURCE_ANY_DIRSERVER];
1102 if (!check_consensus_waiting_for_certs(usable_flavor, now, dls_f)) {
1105 DL_WANT_ANY_DIRSERVER);
1111 &consensus_bootstrap_dl_status[CONSENSUS_BOOTSTRAP_SOURCE_AUTHORITY];
1113 if (!check_consensus_waiting_for_certs(usable_flavor, now, dls_a)) {
1136 #define CONSENSUS_MIN_SECONDS_BEFORE_CACHING 120
1149 if (c && c->
valid_after <= now && now <= c->valid_until) {
1155 if (min_sec_before_caching > interval/16) {
1160 min_sec_before_caching = interval/16;
1162 if (min_sec_before_caching == 0) {
1163 min_sec_before_caching = 1;
1170 start = (time_t)(c->
fresh_until + min_sec_before_caching);
1174 if (min_sec_before_caching + dl_interval > interval)
1175 dl_interval = interval/2;
1178 dl_interval = interval/2;
1183 start = (time_t)(c->
fresh_until + (interval*3)/4);
1191 start = (time_t)(start + dl_interval + min_sec_before_caching);
1193 dl_interval = (c->
valid_until - start) - min_sec_before_caching;
1197 if (dl_interval < 1)
1203 "fresh_until: %ld start: %ld "
1204 "dl_interval: %ld valid_until: %ld ",
1210 tor_assert(start+dl_interval < c->valid_until);
1214 char tbuf1[ISO_TIME_LEN+1];
1215 char tbuf2[ISO_TIME_LEN+1];
1216 char tbuf3[ISO_TIME_LEN+1];
1220 log_info(
LD_DIR,
"Live %s consensus %s the most recent until %s and "
1221 "will expire at %s; fetching the next one at %s.",
1222 flavor, (c->
fresh_until > now) ?
"will be" :
"was",
1223 tbuf1, tbuf2, tbuf3);
1227 log_info(
LD_DIR,
"No live %s consensus; we should fetch one immediately.",
1261 *msg_out =
"DisableNetwork is set.";
1263 log_info(
LD_DIR,
"Delaying dir fetches (DisableNetwork is set)");
1269 *msg_out =
"We are hibernating or shutting down.";
1271 log_info(
LD_DIR,
"Delaying dir fetches (Hibernating or shutting down)");
1280 *msg_out =
"No running bridges";
1282 log_info(
LD_DIR,
"Delaying dir fetches (no running bridges known)");
1288 *msg_out =
"Pluggable transport proxies still configuring";
1290 log_info(
LD_DIR,
"Delaying dir fetches (pt proxies still configuring)");
1348 const int we_are_bootstrapping =
1352 dl = &((we_are_bootstrapping ?
1367 dl = &(consensus_bootstrap_dl_status[flavor]);
1405 else if (f == FLAV_MICRODESC)
1430 return (ns->
valid_after <= now && now <= ns->valid_until);
1443 if (BUG(!consensus))
1452 #define REASONABLY_LIVE_TIME (24*60*60)
1461 return (now >= valid_after - REASONABLY_LIVE_TIME);
1471 return (now <= valid_until + REASONABLY_LIVE_TIME);
1538 tor_assert(smartlist_len(router_get_fallback_dir_servers())
1539 >= smartlist_len(router_get_trusted_dir_servers()));
1543 && (smartlist_len(router_get_fallback_dir_servers())
1544 > smartlist_len(router_get_trusted_dir_servers())));
1550 networkstatus_consensus_is_already_downloading(
const char *resource)
1576 } SMARTLIST_FOREACH_END(dirconn);
1577 smartlist_free(fetching_conns);
1615 a->is_v2_dir != b->is_v2_dir ||
1643 SMARTLIST_FOREACH_JOIN(
1651 } SMARTLIST_FOREACH_JOIN_END(rs_old, rs_new);
1654 smartlist_free(changed);
1663 dos_consensus_has_changed(new_c);
1664 relay_consensus_has_changed(new_c);
1671 notify_after_networkstatus_changes(
void)
1721 rs_new->last_dir_503_at = rs_old->last_dir_503_at;
1723 if (
tor_memeq(rs_old->descriptor_digest, rs_new->descriptor_digest,
1728 } SMARTLIST_FOREACH_JOIN_END(rs_old, rs_new);
1731 #ifdef TOR_UNIT_TESTS
1751 case FLAV_MICRODESC:
1772 const char *source_dir)
1779 flavor, flags, source_dir);
1781 if (rv < 0 && tor_memstr(map->
data, map->
size,
"\r\n")) {
1782 log_notice(
LD_GENERAL,
"Looks like the above failures are probably "
1783 "because of a CRLF in consensus file %s; falling back to "
1784 "read_file_to_string. Nothing to worry about: this file "
1785 "was probably saved by an earlier version of Tor.",
1789 flavor, flags, source_dir);
1794 log_warn(
LD_GENERAL,
"Couldn't set consensus from cache file %s",
1797 tor_munmap_file(map);
1809 char *protocol_warning = NULL;
1814 if (protocol_warning) {
1817 "%s", protocol_warning);
1820 tor_assert_nonfatal(protocol_warning);
1865 char tbuf[ISO_TIME_LEN+1];
1868 char *flavormsg = NULL;
1873 #define EARLY_CONSENSUS_NOTICE_SKEW 60
1886 log_warn(
LD_GENERAL,
"Our clock is %s behind the time published in the "
1887 "consensus network status document (%s UTC). Tor needs an "
1888 "accurate clock to work correctly. Please check your time and "
1889 "date settings!", dbuf, tbuf);
1890 tor_asprintf(&flavormsg,
"%s flavor consensus", flavor);
1918 size_t consensus_len,
1921 const char *source_dir)
1927 char *unverified_fname = NULL, *consensus_fname = NULL;
1929 const unsigned from_cache = flags & NSSET_FROM_CACHE;
1930 const unsigned was_waiting_for_certs = flags & NSSET_WAS_WAITING_FOR_CERTS;
1931 const unsigned dl_certs = !(flags & NSSET_DONT_DOWNLOAD_CERTS);
1932 const unsigned accept_obsolete = flags & NSSET_ACCEPT_OBSOLETE;
1933 const unsigned require_flavor = flags & NSSET_REQUIRE_FLAVOR;
1936 time_t current_valid_after = 0;
1937 int free_consensus = 1;
1938 int checked_protocols_already = 0;
1942 log_warn(
LD_BUG,
"Unrecognized consensus flavor %s", flavor);
1949 NULL, NS_TYPE_CONSENSUS);
1951 log_warn(
LD_DIR,
"Unable to parse networkstatus consensus");
1956 if (from_cache && !was_waiting_for_certs) {
1962 checked_protocols_already = 1;
1966 if ((
int)c->
flavor != flav) {
1968 if (require_flavor) {
1969 log_warn(
LD_DIR,
"Got consensus with unexpected flavor %s (wanted %s)",
1984 if (from_cache && !accept_obsolete &&
1986 log_info(
LD_DIR,
"Loaded an expired consensus. Discarding.");
1990 if (!strcmp(flavor,
"ns")) {
1991 consensus_fname = get_cachedir_fname(
"cached-consensus");
1992 unverified_fname = get_cachedir_fname(
"unverified-consensus");
1997 }
else if (!strcmp(flavor,
"microdesc")) {
1998 consensus_fname = get_cachedir_fname(
"cached-microdesc-consensus");
1999 unverified_fname = get_cachedir_fname(
"unverified-microdesc-consensus");
2010 if (current_digests &&
2013 log_info(
LD_DIR,
"Got a %s consensus we already have", flavor);
2017 if (current_valid_after && c->
valid_after <= current_valid_after) {
2020 log_info(
LD_DIR,
"Got a %s consensus at least as old as the one we have",
2029 if (!was_waiting_for_certs) {
2031 "Not enough certificates to check networkstatus consensus");
2033 if (!current_valid_after ||
2036 networkstatus_vote_free(waiting->
consensus);
2052 if (was_waiting_for_certs && from_cache)
2053 if (unlink(unverified_fname) != 0) {
2055 "Failed to unlink %s: %s",
2056 unverified_fname, strerror(errno));
2062 if (!was_waiting_for_certs) {
2063 log_warn(
LD_DIR,
"Not enough good signatures on networkstatus "
2067 if (was_waiting_for_certs && (r < -1) && from_cache) {
2068 if (unlink(unverified_fname) != 0) {
2070 "Failed to unlink %s: %s",
2071 unverified_fname, strerror(errno));
2079 if (from_cache && was_waiting_for_certs) {
2083 log_info(
LD_DIR,
"Unverified consensus signatures verified.");
2084 tor_rename(unverified_fname, consensus_fname);
2090 if (!checked_protocols_already) {
2095 if (r != 1 && dl_certs)
2102 if (is_usable_flavor) {
2106 if (flav == FLAV_NS) {
2117 }
else if (flav == FLAV_MICRODESC) {
2131 networkstatus_vote_free(waiting->
consensus);
2135 if (unlink(unverified_fname) != 0) {
2137 "Failed to unlink %s: %s",
2138 unverified_fname, strerror(errno));
2142 if (is_usable_flavor) {
2145 notify_after_networkstatus_changes();
2149 if (c->
valid_after <= now && now <= c->valid_until) {
2183 networkstatus_vote_free(c);
2208 NSSET_WAS_WAITING_FOR_CERTS, source_dir);
2226 if (!consensus || dir_version < 3)
2242 const char *recommended = is_server ?
2247 log_info(
LD_GENERAL,
"The directory authorities say my version is ok.");
2250 "The directory authorities don't recommend any versions.");
2253 log_notice(
LD_GENERAL,
"This version of Tor (%s) is newer than any "
2254 "recommended version%s, according to the directory "
2255 "authorities. Recommended versions are: %s",
2261 "CURRENT=%s REASON=%s RECOMMENDED=\"%s\"",
2262 VERSION,
"NEW", recommended);
2266 "This version of Tor (%s) is %s, according to the directory "
2267 "authorities. Recommended versions are: %s",
2269 status ==
VS_OLD ?
"obsolete" :
"not recommended",
2273 "CURRENT=%s REASON=%s RECOMMENDED=\"%s\"",
2274 VERSION, status ==
VS_OLD ?
"OBSOLETE" :
"UNRECOMMENDED",
2288 int authdir = authdir_mode_v3(options);
2298 router->cache_info.identity_digest,
DIGEST_LEN),
2302 if (
tor_memeq(router->cache_info.signed_descriptor_digest,
2304 if (ns->
valid_until > router->cache_info.last_listed_as_valid_until)
2305 router->cache_info.last_listed_as_valid_until = ns->
valid_until;
2313 if (old_router != router) {
2314 router->needs_retest_if_added =
2318 if (reset_failures) {
2321 } SMARTLIST_FOREACH_JOIN_END(rs, router);
2338 memset(dummy, 0,
sizeof(dummy));
2344 d->signed_descriptor_digest);
2346 if (ns->
valid_until > d->last_listed_as_valid_until)
2423 log_info(
LD_DIR,
"Unrecognized purpose '%s' when listing router statuses.",
2433 if (ri->cache_info.published_on < cutoff)
2435 if (ri->purpose != purpose)
2439 } SMARTLIST_FOREACH_END(ri);
2443 smartlist_free(statuses);
2455 int32_t default_val, int32_t min_val, int32_t max_val)
2457 int32_t res = default_val;
2458 size_t name_len = strlen(param_name);
2465 if (!
strcmpstart(p, param_name) && p[name_len] ==
'=') {
2468 INT32_MAX, &ok, NULL);
2474 } SMARTLIST_FOREACH_END(p);
2476 if (res < min_val) {
2477 log_warn(
LD_DIR,
"Consensus parameter %s is too small. Got %d, raising to "
2478 "%d.", param_name, res, min_val);
2480 }
else if (res > max_val) {
2481 log_warn(
LD_DIR,
"Consensus parameter %s is too large. Got %d, capping to "
2482 "%d.", param_name, res, max_val);
2500 int32_t default_val, int32_t min_val, int32_t max_val))
2509 default_val, min_val, max_val);
2519 int32_t torrc_value,
2520 const char *param_name,
2521 int32_t default_val,
2522 int32_t min_val, int32_t max_val)
2524 if (torrc_value >= min_val && torrc_value <= max_val)
2528 ns, param_name, default_val, min_val, max_val);
2542 BW_MIN_WEIGHT_SCALE,
2543 BW_MAX_WEIGHT_SCALE);
2552 int32_t default_val)
2565 BW_MAX_WEIGHT_SCALE);
2567 log_warn(
LD_DIR,
"Value of consensus weight %s was too large, capping "
2568 "to %d", weight_name, max);
2582 case FLAV_MICRODESC:
2595 if (!strcmp(flavname,
"ns"))
2597 else if (!strcmp(flavname,
"microdesc"))
2598 return FLAV_MICRODESC;
2618 if (!routerstatus_version_supports_extend2_cells(rs, 1)) {
2633 const char *question,
char **answer,
2634 const char **errmsg)
2640 *answer = tor_strdup(
"");
2644 if (!strcmp(question,
"ns/all")) {
2653 smartlist_free(statuses);
2657 const char *q = question + 6;
2662 *errmsg =
"Data not decodeable as hex";
2668 status = n ? n->rs : NULL;
2669 }
else if (!
strcmpstart(question,
"ns/purpose/")) {
2671 return *answer ? 0 : -1;
2672 }
else if (!strcmp(question,
"consensus/packages")) {
2677 *errmsg =
"No consensus available";
2678 return *answer ? 0 : -1;
2679 }
else if (!strcmp(question,
"consensus/valid-after") ||
2680 !strcmp(question,
"consensus/fresh-until") ||
2681 !strcmp(question,
"consensus/valid-until")) {
2685 if (!strcmp(question,
"consensus/valid-after"))
2687 else if (!strcmp(question,
"consensus/fresh-until"))
2692 char tbuf[ISO_TIME_LEN+1];
2694 *answer = tor_strdup(tbuf);
2696 *errmsg =
"No consensus available";
2698 return *answer ? 0 : -1;
2719 const char *func = client_mode ?
"client" :
"relay";
2720 const char *required, *recommended;
2721 char *missing = NULL;
2723 const bool consensus_postdates_this_release =
2726 if (! consensus_postdates_this_release) {
2736 required = ns->required_client_protocols;
2737 recommended = ns->recommended_client_protocols;
2739 required = ns->required_relay_protocols;
2744 tor_asprintf(warning_out,
"At least one protocol listed as required in "
2745 "the consensus is not supported by this version of Tor. "
2746 "You should upgrade. This version of Tor will not work as a "
2747 "%s on the Tor network. The missing protocols are: %s",
2754 tor_asprintf(warning_out,
"At least one protocol listed as recommended in "
2755 "the consensus is not supported by this version of Tor. "
2756 "You should upgrade. This version of Tor will eventually "
2757 "stop working as a %s on the Tor network. The missing "
2758 "protocols are: %s",
2763 tor_assert_nonfatal(missing == NULL);
2780 networkstatus_vote_free(waiting->
consensus);
2796 time_t midnight_today=0;
2797 time_t midnight_tomorrow;
2807 log_warn(
LD_BUG,
"Ran into an invalid time when trying to find midnight.");
2810 midnight_tomorrow = midnight_today + (24*60*60);
2812 next = midnight_today + ((now-midnight_today)/interval + 1)*interval;
2815 if (next > midnight_tomorrow)
2816 next = midnight_tomorrow;
2820 if (next + interval/2 > midnight_tomorrow)
2821 next = midnight_tomorrow;
2824 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)
authority_cert_t * authority_cert_get_by_digests(const char *id_digest, const char *sk_digest)
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)
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.
void circuit_build_times_new_consensus_params(circuit_build_times_t *cbt, const networkstatus_t *ns)
circuit_build_times_t * get_circuit_build_times_mutable(void)
Header file for circuitstats.c.
const or_options_t * get_options(void)
int options_any_client_port_set(const or_options_t *options)
Header file for config.c.
smartlist_t * connection_dir_list_by_purpose_resource_and_state(int purpose, const char *resource, int state)
void clock_skew_warning(const connection_t *conn, long apparent_skew, int trusted, log_domain_mask_t domain, const char *received, const char *source)
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.
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)
Authority signature structure.
int num_bridges_usable(int use_maybe_reachable)
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)
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 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.
routerstatus_t * networkstatus_vote_find_mutable_entry(networkstatus_t *ns, const char *digest)
char * networkstatus_getinfo_helper_single(const routerstatus_t *rs)
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)
int networkstatus_check_document_signature(const networkstatus_t *consensus, document_signature_t *sig, const authority_cert_t *cert)
networkstatus_t * networkstatus_get_latest_consensus_by_flavor(consensus_flavor_t f)
void routers_update_all_from_networkstatus(time_t now, int dir_version)
int networkstatus_parse_flavor_name(const char *flavname)
download_status_t * networkstatus_get_dl_status_by_flavor_bootstrap(consensus_flavor_t flavor)
STATIC networkstatus_t * current_md_consensus
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)
smartlist_t * router_get_descriptor_digests(void)
int networkstatus_consensus_reasonably_live(const networkstatus_t *consensus, time_t now)
const char * networkstatus_get_flavor_name(consensus_flavor_t flav)
int we_want_to_fetch_flavor(const or_options_t *options, int flavor)
static smartlist_t * router_get_descriptor_digests_in_consensus(networkstatus_t *consensus)
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)
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_reasonably_live_consensus(time_t now, int flavor)
networkstatus_voter_info_t * networkstatus_get_voter_by_id(networkstatus_t *vote, const char *identity)
static void handle_missing_protocol_warning(const networkstatus_t *c, const or_options_t *options)
download_status_t * networkstatus_get_dl_status_by_flavor(consensus_flavor_t flavor)
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)
char * networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now)
STATIC networkstatus_t * current_ns_consensus
void networkstatus_free_all(void)
static void update_consensus_networkstatus_downloads(time_t now)
networkstatus_t * networkstatus_get_latest_consensus(void)
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 * router_get_dl_status_by_descriptor_digest(const char *d)
void networkstatus_note_certs_arrived(const char *source_dir)
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)
int networkstatus_check_consensus_signature(networkstatus_t *consensus, int warn)
static int have_warned_about_old_version
const routerstatus_t * router_get_consensus_status_by_id(const char *digest)
download_status_t * networkstatus_get_dl_status_by_flavor_running(consensus_flavor_t flavor)
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)
void vote_routerstatus_free_(vote_routerstatus_t *rs)
static void update_consensus_bootstrap_multiple_downloads(time_t now, const or_options_t *options)
document_signature_t * document_signature_dup(const document_signature_t *sig)
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)
const routerstatus_t * networkstatus_vote_find_entry(networkstatus_t *ns, const char *digest)
tor_mmap_t * networkstatus_map_cached_consensus(const char *flavorname)
static void handle_missing_protocol_warning_impl(const networkstatus_t *c, int is_client)
document_signature_t * networkstatus_get_voter_sig_by_alg(const networkstatus_voter_info_t *voter, digest_algorithm_t alg)
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)
void set_routerstatus_from_routerinfo(routerstatus_t *rs, const node_t *node, const routerinfo_t *ri)
routerstatus_t * router_get_mutable_consensus_status_by_id(const char *digest)
STATIC void warn_early_consensus(const networkstatus_t *c, const char *flavor, time_t now)
routerstatus_t * router_get_mutable_consensus_status_by_descriptor_digest(networkstatus_t *consensus, const char *digest)
#define MIN_DELAY_FOR_FETCH_CERT_STATUS_FAILURE
void networkstatus_vote_free_(networkstatus_t *ns)
static tor_mmap_t * networkstatus_map_cached_consensus_impl(int flav, const char *flavorname, int unverified_consensus)
#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)
char * networkstatus_get_cache_fname(int flav, const char *flavorname, int unverified_consensus)
const routerstatus_t * router_get_consensus_status_by_descriptor_digest(networkstatus_t *consensus, const char *digest)
int we_want_to_fetch_unknown_auth_certs(const or_options_t *options)
#define CONSENSUS_MIN_SECONDS_BEFORE_CACHING
networkstatus_t * networkstatus_get_live_consensus(time_t now)
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.
node_t * node_get_mutable_by_id(const char *identity_digest)
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)
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)
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 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
routerinfo_t * router_get_mutable_by_digest(const char *digest)
routerlist_t * router_get_routerlist(void)
void routers_sort_by_identity(smartlist_t *routers)
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_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
void * smartlist_bsearch(const smartlist_t *sl, const void *key, int(*compare)(const void *key, const void **member))
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)
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)
struct tm * tor_gmtime_r(const time_t *timep, struct tm *result)
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.