62 #define ROUTERLIST_PRIVATE
113 #ifdef HAVE_SYS_STAT_H
114 #include <sys/stat.h>
125 DECLARE_TYPED_DIGESTMAP_FNS(rimap, digest_ri_map_t,
routerinfo_t)
126 DECLARE_TYPED_DIGESTMAP_FNS(eimap, digest_ei_map_t,
extrainfo_t)
127 #define SDMAP_FOREACH(map, keyvar, valvar) \
128 DIGESTMAP_FOREACH(sdmap_to_digestmap(map), keyvar, signed_descriptor_t *, \
130 #define RIMAP_FOREACH(map, keyvar, valvar) \
131 DIGESTMAP_FOREACH(rimap_to_digestmap(map), keyvar, routerinfo_t *, valvar)
132 #define EIMAP_FOREACH(map, keyvar, valvar) \
133 DIGESTMAP_FOREACH(eimap_to_digestmap(map), keyvar, extrainfo_t *, valvar)
134 #define eimap_free(map, fn) MAP_FREE_AND_NULL(eimap, (map), (fn))
135 #define rimap_free(map, fn) MAP_FREE_AND_NULL(rimap, (map), (fn))
136 #define sdmap_free(map, fn) MAP_FREE_AND_NULL(sdmap, (map), (fn))
142 int with_annotations);
188 if (sd->is_extrainfo)
201 char *fname = get_cachedir_fname_suffix(store->
fname_base,
".new");
206 log_warn(
LD_FS,
"Unable to store router descriptor");
230 #define RRS_DONT_REMOVE_OLD 2
242 char *fname = NULL, *fname_tmp = NULL;
246 size_t total_expected_len = 0;
248 int force = flags & RRS_FORCE;
259 if (store->
type == EXTRAINFO_STORE)
266 if (!(flags & RRS_DONT_REMOVE_OLD))
271 fname = get_cachedir_fname(store->
fname_base);
272 fname_tmp = get_cachedir_fname_suffix(store->
fname_base,
".tmp");
278 if (store->
type == EXTRAINFO_STORE) {
281 !eimap_iter_done(iter);
285 eimap_iter_get(iter, &key, &ei);
302 log_warn(
LD_BUG,
"No descriptor available for router.");
305 if (sd->do_not_cache) {
310 c->len = sd->signed_descriptor_len + sd->annotations_len;
311 total_expected_len += c->len;
313 } SMARTLIST_FOREACH_END(sd);
315 if (write_chunks_to_file(fname_tmp, chunk_list, 1, 1)<0) {
316 log_warn(
LD_FS,
"Error writing router store to disk.");
322 int res = tor_munmap_file(store->
mmap);
325 log_warn(
LD_FS,
"Unable to munmap route store in %s", fname);
330 log_warn(
LD_FS,
"Error replacing old router store: %s", strerror(errno));
335 store->
mmap = tor_mmap_file(fname);
337 if (errno == ERANGE) {
339 if (total_expected_len) {
340 log_warn(
LD_FS,
"We wrote some bytes to a new descriptor file at '%s',"
341 " but when we went to mmap it, it was empty!", fname);
342 }
else if (had_any) {
343 log_info(
LD_FS,
"We just removed every descriptor in '%s'. This is "
344 "okay if we're just starting up after a long time. "
345 "Otherwise, it's a bug.", fname);
348 log_warn(
LD_FS,
"Unable to mmap new descriptor file at '%s'.",fname);
352 log_info(
LD_DIR,
"Reconstructing pointers into cache");
356 if (sd->do_not_cache)
360 tor_free(sd->signed_descriptor_body);
361 sd->saved_offset = offset;
363 offset += sd->signed_descriptor_len + sd->annotations_len;
365 } SMARTLIST_FOREACH_END(sd);
368 fname = get_cachedir_fname_suffix(store->
fname_base,
".new");
376 smartlist_free(signed_descriptors);
381 smartlist_free(chunk_list);
393 char *fname = NULL, *contents = NULL;
395 int extrainfo = (store->
type == EXTRAINFO_STORE);
398 fname = get_cachedir_fname(store->
fname_base);
402 int res = tor_munmap_file(store->
mmap);
405 log_warn(
LD_FS,
"Failed to munmap %s", fname);
411 store->
mmap = tor_mmap_file(fname);
425 fname = get_cachedir_fname_suffix(store->
fname_base,
".new");
445 }
else if (!extrainfo) {
479 router_or_conn_should_skip_reachable_address_check(
495 router_dir_conn_should_skip_reachable_address_check(
510 r1->ipv4_orport == r2->ipv4_orport &&
512 r1->ipv6_orport == r2->ipv6_orport;
550 router_can_choose_node(
const node_t *node,
int flags)
553 const bool need_uptime = (flags & CRN_NEED_UPTIME) != 0;
554 const bool need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
555 const bool need_guard = (flags & CRN_NEED_GUARD) != 0;
556 const bool need_desc = (flags & CRN_NEED_DESC) != 0;
557 const bool pref_addr = (flags & CRN_PREF_ADDR) != 0;
558 const bool direct_conn = (flags & CRN_DIRECT_CONN) != 0;
559 const bool rendezvous_v3 = (flags & CRN_RENDEZVOUS_V3) != 0;
560 const bool initiate_ipv6_extend = (flags & CRN_INITIATE_IPV6_EXTEND) != 0;
563 const bool check_reach =
564 !router_or_conn_should_skip_reachable_address_check(options, pref_addr);
565 const bool direct_bridge = direct_conn && options->
UseBridges;
580 if (node->rs && !routerstatus_version_supports_extend2_cells(node->rs, 1))
596 if (direct_conn && check_reach &&
598 FIREWALL_OR_CONNECTION,
616 if (!router_can_choose_node(node, flags))
619 } SMARTLIST_FOREACH_END(node);
632 if (router_is_me(router))
650 #define DEFAULT_MAX_BELIEVABLE_BANDWIDTH 10000000
684 char *nickname_qualifier_char_out,
690 if (hexdigest[0] ==
'$')
693 len = strlen(hexdigest);
719 const char *nickname)
728 if (nn_char ==
'=') {
732 if (nn_char ==
'~') {
735 if (strcasecmp(nn_buf, nickname))
749 if (hexdigest[0]==
'$')
814 return ei ? &ei->cache_info : NULL;
830 int with_annotations)
832 const char *r = NULL;
835 if (with_annotations)
843 if (store && store->
mmap) {
847 log_err(
LD_DIR,
"We couldn't read a descriptor that is supposedly "
848 "mmaped in our cache. Is another process running in our data "
849 "directory? Exiting.");
858 if (!with_annotations) {
860 char *cp = tor_strndup(r, 64);
861 log_err(
LD_DIR,
"descriptor at %p begins with unexpected string %s. "
862 "Is another process running in our data directory? Exiting.",
960 #define signed_descriptor_free(val) \
961 FREE_AND_NULL(signed_descriptor_t, signed_descriptor_free_, (val))
985 memset(sd, 0,
sizeof(*sd));
1013 routerinfo_free(ri);
1035 routerinfo_free(r));
1037 signed_descriptor_free(sd));
1043 log_warn(
LD_FS,
"Failed to munmap routerlist->desc_store.mmap");
1049 log_warn(
LD_FS,
"Failed to munmap routerlist->extrainfo_store.mmap");
1060 uint64_t livedescs = 0;
1061 uint64_t olddescs = 0;
1070 "In %d live descriptors: %"PRIu64
" bytes. "
1071 "In %d old descriptors: %"PRIu64
" bytes.",
1129 signed_descriptor_free(sd_old);
1139 #ifdef DEBUG_ROUTERLIST
1151 const char *compatibility_error_msg;
1166 r = ROUTER_NOT_IN_CONSENSUS;
1172 static ratelim_t no_sd_ratelim = RATELIM_INIT(1800);
1179 "No entry found in extrainfo map.");
1184 static ratelim_t digest_mismatch_ratelim = RATELIM_INIT(1800);
1189 "Mismatch in digest in extrainfo map.");
1193 &compatibility_error_msg)) {
1195 r = (ri->cache_info.extrainfo_is_bogus) ?
1196 ROUTER_BAD_EI : ROUTER_NOT_IN_CONSENSUS;
1202 "router info incompatible with extra info (ri id: %s, ei id %s, "
1203 "reason: %s)", d1, d2, compatibility_error_msg);
1214 r = ROUTER_ADDED_SUCCESSFULLY;
1218 extrainfo_free(ei_tmp);
1222 if (r != ROUTER_ADDED_SUCCESSFULLY)
1225 #ifdef DEBUG_ROUTERLIST
1231 #define should_cache_old_descriptors() \
1232 directory_caches_dir_info(get_options())
1246 if (should_cache_old_descriptors() &&
1257 routerinfo_free(ri);
1259 #ifdef DEBUG_ROUTERLIST
1288 if (idx < smartlist_len(rl->
routers)) {
1297 if (make_old && should_cache_old_descriptors() &&
1317 extrainfo_free(ei_tmp);
1321 routerinfo_free(ri);
1323 #ifdef DEBUG_ROUTERLIST
1365 extrainfo_free(ei_tmp);
1370 signed_descriptor_free(sd);
1371 #ifdef DEBUG_ROUTERLIST
1389 int same_descriptors;
1412 smartlist_set(rl->
routers, idx, ri_new);
1418 log_warn(
LD_BUG,
"Appending entry from routerlist_replace.");
1432 &(ri_new->cache_info));
1436 &ri_new->cache_info);
1443 if (should_cache_old_descriptors() &&
1445 !same_descriptors) {
1456 if (!same_descriptors) {
1468 extrainfo_free(ei_tmp);
1478 routerinfo_free(ri_old);
1480 #ifdef DEBUG_ROUTERLIST
1518 routerlist_free(rl);
1525 authcert_free_all();
1572 int from_cache,
int from_fetch)
1574 const char *id_digest;
1577 int authdir_believes_valid = 0;
1581 int in_consensus = 0;
1594 routerinfo_free(router);
1595 *msg =
"Some certs on this router are expired.";
1596 return ROUTER_CERTS_EXPIRED;
1608 const int was_bridge = old_router &&
1614 log_info(
LD_DIR,
"Replacing non-bridge descriptor with bridge "
1615 "descriptor for router %s",
1626 "Dropping descriptor that we already have for router %s",
1628 *msg =
"Router descriptor was not new.";
1629 routerinfo_free(router);
1630 return ROUTER_IS_ALREADY_KNOWN;
1636 !from_cache && !from_fetch,
1637 &authdir_believes_valid)) {
1639 routerinfo_free(router);
1640 return ROUTER_AUTHDIR_REJECTS;
1642 }
else if (from_fetch) {
1651 "Received a no-longer-recognized descriptor for router %s",
1653 *msg =
"Router descriptor is not referenced by any network-status.";
1656 if (!from_cache && should_cache_old_descriptors())
1660 return ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS;
1667 consensus, id_digest);
1676 consensus && !in_consensus && !authdir) {
1679 if (!from_cache && should_cache_old_descriptors())
1683 *msg =
"Skipping router descriptor: not in consensus.";
1684 return ROUTER_NOT_IN_CONSENSUS;
1694 log_info(
LD_DIR,
"Dropping bridge descriptor for %s because we have "
1695 "no bridge configured at that address.",
1697 *msg =
"Router descriptor was not a configured bridge.";
1698 routerinfo_free(router);
1699 return ROUTER_WAS_NOT_WANTED;
1704 if (!in_consensus && (router->cache_info.
published_on <=
1707 log_debug(
LD_DIR,
"Not-new descriptor for router %s",
1710 if (!from_cache && should_cache_old_descriptors())
1714 *msg =
"Router descriptor was not new.";
1715 return ROUTER_IS_ALREADY_KNOWN;
1718 log_debug(
LD_DIR,
"Replacing entry for router %s",
1725 *msg = authdir_believes_valid ?
"Valid server updated" :
1726 (
"Invalid server updated. (This dirserver is marking your "
1727 "server as unapproved.)");
1728 return ROUTER_ADDED_SUCCESSFULLY;
1732 if (!in_consensus && from_cache &&
1734 *msg =
"Router descriptor was really old.";
1735 routerinfo_free(router);
1736 return ROUTER_WAS_TOO_OLD;
1746 return ROUTER_ADDED_SUCCESSFULLY;
1755 int from_cache,
int from_fetch)
1759 if (msg) *msg = NULL;
1799 return d1->duration - d2->duration;
1812 time_t cutoff,
int lo,
int hi,
1813 digestset_t *retain)
1816 unsigned n_extra, n_rmv = 0;
1818 uint8_t *rmv, *must_keep;
1825 for (i = lo+1; i <= hi; ++i) {
1839 rmv = tor_calloc(n,
sizeof(uint8_t));
1840 must_keep = tor_calloc(n,
sizeof(uint8_t));
1843 for (i = lo; i <= hi; ++i) {
1846 lifespans[i-lo].idx = i;
1850 must_keep[i-lo] = 1;
1853 r_next = smartlist_get(lst, i+1);
1858 lifespans[i-lo].duration = INT_MAX;
1860 if (!must_keep[i-lo] && r->
published_on < cutoff && n_rmv < n_extra) {
1862 lifespans[i-lo].old = 1;
1867 if (n_rmv < n_extra) {
1874 for (i = 0; i < n && n_rmv < n_extra; ++i) {
1875 if (!must_keep[lifespans[i].idx-lo] && !lifespans[i].old) {
1876 rmv[lifespans[i].idx-lo] = 1;
1886 }
while (--i >= lo);
1900 const char *cur_id = NULL;
1901 time_t now = time(NULL);
1905 digestset_t *retain;
1947 "Forgetting obsolete (too old) routerinfo for router %s",
1971 log_info(
LD_DIR,
"We have %d live routers and %d old router descriptors.",
2003 cutoff, i+1, hi, retain);
2013 digestset_free(retain);
2022 routerlist_drop_bridge_descriptors(
void)
2034 "Dropping existing bridge descriptor for %s",
2054 if (ri->needs_retest_if_added) {
2055 ri->needs_retest_if_added = 0;
2058 } SMARTLIST_FOREACH_END(ri);
2085 "@source controller\n"
2089 annotation_buf, NULL))) {
2090 log_warn(
LD_DIR,
"Error parsing router descriptor; dropping.");
2091 *msg =
"Couldn't parse router descriptor.";
2096 log_warn(
LD_DIR,
"Router's identity key matches mine; dropping.");
2097 *msg =
"Router's identity key matches mine.";
2098 routerinfo_free(ri);
2103 ri->cache_info.do_not_cache = 1;
2113 if (r == ROUTER_AUTHDIR_REJECTS)
2114 log_warn(
LD_DIR,
"Couldn't add router to list: %s Dropping.", *msg);
2115 smartlist_free(lst);
2119 smartlist_free(lst);
2120 log_debug(
LD_DIR,
"Added router to list");
2144 int descriptor_digests,
2145 const char *prepend_annotations)
2152 int any_changed = 0;
2156 allow_annotations, prepend_annotations,
2161 log_info(
LD_DIR,
"%d elements to add", smartlist_len(routers));
2166 if (requested_fingerprints) {
2168 ri->cache_info.signed_descriptor_digest :
2169 ri->cache_info.identity_digest,
2177 "We received a router descriptor with a fingerprint (%s) "
2178 "that we never requested. (We asked for: %s.) Dropping.",
2181 routerinfo_free(ri);
2186 memcpy(d, ri->cache_info.signed_descriptor_digest,
DIGEST_LEN);
2197 log_info(
LD_GENERAL,
"Marking router %s as never downloadable",
2202 } SMARTLIST_FOREACH_END(ri);
2207 if (requested_fingerprints && descriptor_digests) {
2217 log_info(
LD_GENERAL,
"Marking router with descriptor %s as unparseable, "
2218 "and therefore undownloadable", fp);
2221 } SMARTLIST_FOREACH_END(bad_digest);
2223 smartlist_free(invalid_digests);
2230 smartlist_free(routers);
2231 smartlist_free(changed);
2243 int descriptor_digests)
2251 NULL, invalid_digests);
2253 log_info(
LD_DIR,
"%d elements to add", smartlist_len(extrainfo_list));
2257 memcpy(d, ei->cache_info.signed_descriptor_digest,
DIGEST_LEN);
2263 ei->cache_info.signed_descriptor_digest :
2264 ei->cache_info.identity_digest,
2274 log_info(
LD_GENERAL,
"Marking extrainfo with descriptor %s as "
2275 "unparseable, and therefore undownloadable",
2280 } SMARTLIST_FOREACH_END(ei);
2286 if (requested_fingerprints) {
2296 log_info(
LD_GENERAL,
"Marking extrainfo with descriptor %s as "
2297 "unparseable, and therefore undownloadable", fp);
2300 } SMARTLIST_FOREACH_END(bad_digest);
2302 smartlist_free(invalid_digests);
2307 smartlist_free(extrainfo_list);
2347 "In routerlist_retry_directory_downloads()");
2370 int purpose,
const char *prefix)
2372 const size_t p_len = strlen(prefix);
2375 int flags = DSR_HEX;
2377 flags = DSR_DIGEST256|DSR_BASE64;
2383 conn->purpose == purpose &&
2384 !conn->marked_for_close) {
2390 } SMARTLIST_FOREACH_END(conn);
2395 digestmap_set(result, d, (
void*)1);
2398 }
else if (result256) {
2401 digest256map_set(result256, d, (
void*)1);
2405 smartlist_free(tmp);
2436 int lo,
int hi,
int pds_flags))
2438 char *resource, *cp;
2439 int digest_len, enc_digest_len;
2460 if (hi > smartlist_len(digests))
2461 hi = smartlist_len(digests);
2468 for (; lo < hi; ++lo) {
2469 cp = tor_malloc(enc_digest_len);
2473 base16_encode(cp, enc_digest_len, smartlist_get(digests, lo),
2483 smartlist_free(tmp);
2492 directory_request_free(req);
2495 pds_flags, DL_WANT_ANY_DIRSERVER);
2523 if (dirclient_must_use_begindir(options)) {
2532 #define MIN_DL_PER_REQUEST 32
2535 #define MIN_REQUESTS 3
2538 #define MAX_DL_TO_DELAY 16
2552 const char *descname;
2554 int n_downloadable = smartlist_len(downloadable);
2556 int i, n_per_request, max_dl_per_req;
2557 const char *req_plural =
"", *rtr_plural =
"";
2561 descname = fetch_microdesc ?
"microdesc" :
"routerdesc";
2563 if (!n_downloadable)
2569 "There are enough downloadable %ss to launch requests.",
2573 "We are only missing %d %ss, but we'll fetch anyway, since "
2574 "we don't yet have enough directory info.",
2575 n_downloadable, descname);
2585 "There are not many downloadable %ss, but we've "
2586 "been waiting long enough (%d seconds). Downloading.",
2591 "There are not many downloadable %ss, but we haven't "
2592 "tried downloading descriptors recently. Downloading.",
2609 pds_flags |= fetch_microdesc ?
2614 n_per_request = CEIL_DIV(n_downloadable,
MIN_REQUESTS);
2617 if (n_per_request > max_dl_per_req)
2618 n_per_request = max_dl_per_req;
2624 if (n_downloadable > n_per_request)
2625 req_plural = rtr_plural =
"s";
2626 else if (n_downloadable > 1)
2630 "Launching %d request%s for %d %s%s, %d at a time",
2631 CEIL_DIV(n_downloadable, n_per_request), req_plural,
2632 n_downloadable, descname, rtr_plural, n_per_request);
2634 for (i=0; i < n_downloadable; i += n_per_request) {
2636 downloadable, i, i+n_per_request,
2649 digestmap_t *map = NULL;
2654 int n_delayed=0, n_have=0, n_would_reject=0, n_wouldnt_use=0,
2655 n_inprogress=0, n_in_oldrouters=0;
2677 log_warn(
LD_DIR,
"couldn't lookup source from vote?");
2681 map = digestmap_new();
2726 if (is_vote && source) {
2728 const char *old_digest =
"none";
2735 old_digest = old_digest_buf;
2737 log_info(
LD_DIR,
"Learned about %s (%s vs %s) from %s's vote (%s)",
2741 source->
nickname, oldrouter ?
"known" :
"unknown");
2744 } SMARTLIST_FOREACH_END(rsp);
2746 if (!authdir_mode_v3(options)
2747 && smartlist_len(no_longer_old)) {
2749 log_info(
LD_DIR,
"%d router descriptors listed in consensus are "
2750 "currently in old_routers; making them current.",
2751 smartlist_len(no_longer_old));
2755 time_t tmp_cert_expiration_time;
2758 log_warn(
LD_BUG,
"Failed to re-parse a router.");
2766 log_warn(
LD_DIR,
"Couldn't add re-parsed router: %s. This isn't "
2767 "usually a big deal, but you should make sure that your "
2768 "clock and timezone are set correctly.",
2770 if (r == ROUTER_CERTS_EXPIRED) {
2771 char time_cons[ISO_TIME_LEN+1];
2772 char time_cert_expires[ISO_TIME_LEN+1];
2775 log_warn(
LD_DIR,
" (I'm looking at a consensus from %s; This "
2776 "router's certificates began expiring at %s.)",
2777 time_cons, time_cert_expires);
2780 } SMARTLIST_FOREACH_END(sd);
2785 "%d router descriptors downloadable. %d delayed; %d present "
2786 "(%d of those were in old_routers); %d would_reject; "
2787 "%d wouldnt_use; %d in progress.",
2788 smartlist_len(downloadable), n_delayed, n_have, n_in_oldrouters,
2789 n_would_reject, n_wouldnt_use, n_inprogress);
2792 downloadable, source, now);
2794 digestmap_free(map, NULL);
2796 smartlist_free(downloadable);
2797 smartlist_free(no_longer_old);
2821 digestmap_t *pending;
2822 int old_routers, i, max_dl_per_req;
2823 int n_no_ei = 0, n_pending = 0, n_have = 0, n_delay = 0, n_bogus[2] = {0,0};
2831 pending = digestmap_new();
2835 for (old_routers = 0; old_routers < 2; ++old_routers) {
2837 for (i = 0; i < smartlist_len(lst); ++i) {
2841 sd = smartlist_get(lst, i);
2843 sd = &((
routerinfo_t*)smartlist_get(lst, i))->cache_info;
2844 if (sd->is_extrainfo)
2848 if (sd->extrainfo_is_bogus)
2863 if (digestmap_get(pending, d)) {
2878 log_info(
LD_DIR,
"Found an entry in %s with mismatched "
2879 "router_get_by_extrainfo_digest() value. This has ID %s "
2880 "but the entry in the map has ID %s. This has EI digest "
2881 "%s and the entry in the map has EI digest %s.",
2882 old_routers?
"old_routers":
"routers",
2889 log_info(
LD_DIR,
"Found an entry in %s with NULL "
2890 "router_get_by_extrainfo_digest() value. This has ID %s "
2891 "and EI digest %s.",
2892 old_routers?
"old_routers":
"routers",
2895 ++n_bogus[old_routers];
2901 digestmap_free(pending, NULL);
2903 log_info(
LD_DIR,
"Extrainfo download status: %d router with no ei, %d "
2904 "with present ei, %d delaying, %d pending, %d downloadable, %d "
2905 "bogus in routers, %d bogus in old_routers",
2906 n_no_ei, n_have, n_delay, n_pending, smartlist_len(wanted),
2907 n_bogus[0], n_bogus[1]);
2912 for (i = 0; i < smartlist_len(wanted); i += max_dl_per_req) {
2914 wanted, i, i+max_dl_per_req,
2918 smartlist_free(wanted);
2930 "In router_reset_descriptor_download_failures()");
2940 download_status_reset(&ri->cache_info.ei_dl_status);
2944 download_status_reset(&sd->ei_dl_status);
2950 #define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE (2*60*60)
2953 #define ROUTER_ALLOW_UPTIME_DRIFT (6*60*60)
2961 time_t r1pub, r2pub;
2962 time_t time_difference;
2975 r1->ipv4_orport != r2->ipv4_orport ||
2977 r1->ipv6_orport != r2->ipv6_orport ||
2978 r1->ipv4_dirport != r2->ipv4_dirport ||
3000 for (i=0; i < n; ++i) {
3026 time_difference = r2->
uptime - (r1->
uptime + (r2pub - r1pub));
3027 if (time_difference < 0)
3028 time_difference = - time_difference;
3030 time_difference > r1->
uptime * .05 &&
3031 time_difference > r2->
uptime * .05)
3060 int digest_matches, digest256_matches, r=1;
3066 if (msg) *msg =
"Extrainfo signature was bad, or signed with wrong key.";
3076 digest256_matches |=
3084 if (msg) *msg =
"Extrainfo nickname or identity did not match routerinfo";
3090 if (msg) *msg =
"Extrainfo signing key cert didn't match routerinfo";
3095 char signed_digest[128];
3097 signed_digest,
sizeof(signed_digest),
3103 if (msg) *msg =
"Extrainfo signature bad, or signed with wrong key";
3107 ei->cache_info.send_unencrypted = sd->send_unencrypted;
3112 if (msg) *msg =
"Extrainfo published time did not match routerdesc";
3115 if (msg) *msg =
"Extrainfo published time did not match routerdesc";
3120 if (!digest256_matches && !digest_matches) {
3121 if (msg) *msg =
"Neither digest256 or digest matched "
3122 "digest from routerdesc";
3126 if (!digest256_matches) {
3127 if (msg) *msg =
"Extrainfo digest did not match digest256 from routerdesc";
3131 if (!digest_matches) {
3132 if (msg) *msg =
"Extrainfo digest did not match value from routerdesc";
3138 if (digest_matches) {
3142 sd->extrainfo_is_bogus = 1;
3151 routerinfo_has_curve25519_onion_key(
const routerinfo_t *ri)
3175 routerstatus_version_supports_extend2_cells(
const routerstatus_t *rs,
3176 int allow_unknown_versions)
3179 return allow_unknown_versions;
3183 return allow_unknown_versions;
3199 r2 = rimap_get(rl->
identity_map, r->cache_info.identity_digest);
3202 r->cache_info.signed_descriptor_digest);
3204 tor_assert(r->cache_info.routerlist_index == r_sl_idx);
3228 } SMARTLIST_FOREACH_END(r);
3234 tor_assert(sd->routerlist_index == sd_sl_idx);
3242 } SMARTLIST_FOREACH_END(sd);
3260 ei->cache_info.signed_descriptor_digest);
3282 static char *info=NULL;
3283 char *esc_contact, *esc_platform;
3292 tor_asprintf(&info,
"Contact %s, Platform %s", esc_contact, esc_platform);
3306 second->cache_info.identity_digest,
#define tor_addr_eq(a, b)
void trusted_dirs_remove_old_certs(void)
Header file for authcert.c.
int authdir_mode(const or_options_t *options)
int authdir_mode_handles_descs(const or_options_t *options, int purpose)
int authdir_mode_bridge(const or_options_t *options)
Header file for directory authority mode.
const char * hex_str(const char *from, size_t fromlen)
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
int routerinfo_is_a_configured_bridge(const routerinfo_t *ri)
void learned_bridge_descriptor(routerinfo_t *ri, int from_cache, int desc_is_new)
Header file for circuitbuild.c.
Header file for circuitlist.c.
Header file for circuituse.c.
const or_options_t * get_options(void)
Header file for config.c.
Header file for connection.c.
int control_event_descriptors_changed(smartlist_t *routers)
Header file for control_events.c.
#define BASE64_DIGEST256_LEN
void smartlist_shuffle(smartlist_t *sl)
Common functions for using (pseudo-)random number generators.
int crypto_pk_eq_keys(const crypto_pk_t *a, const crypto_pk_t *b)
int crypto_pk_public_checksig(const crypto_pk_t *env, char *to, size_t tolen, const char *from, size_t fromlen)
const char * router_describe(const routerinfo_t *ri)
const char * routerstatus_describe(const routerstatus_t *rs)
Header file for describe.c.
int tor_memeq(const void *a, const void *b, size_t sz)
#define fast_memcmp(a, b, c)
#define tor_memneq(a, b, sz)
void digestset_add(digestset_t *set, const char *digest)
int digestset_probably_contains(const digestset_t *set, const char *digest)
digestset_t * digestset_new(int max_guess)
Types to handle sets of digests, based on bloom filters.
Client/server directory connection structure.
Trusted/fallback directory server structure.
void directory_request_set_resource(directory_request_t *req, const char *resource)
void directory_request_set_routerstatus(directory_request_t *req, const routerstatus_t *status)
directory_request_t * directory_request_new(uint8_t dir_purpose)
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)
void directory_initiate_request(directory_request_t *request)
Header file for dirclient.c.
struct directory_request_t directory_request_t
int dirclient_fetches_dir_info_early(const or_options_t *options)
int dirclient_too_idle_to_fetch_descriptors(const or_options_t *options, time_t now)
Header for feature/dirclient/dirclient_modes.c.
dir_connection_t * TO_DIR_CONN(connection_t *c)
int dir_split_resource_into_fingerprints(const char *resource, smartlist_t *fp_out, int *compressed_out, int flags)
Header file for directory.c.
#define DIR_PURPOSE_FETCH_EXTRAINFO
#define DIR_PURPOSE_FETCH_MICRODESC
#define DIR_PURPOSE_FETCH_SERVERDESC
dir_server_t * trusteddirserver_get_by_v3_auth_digest(const char *digest)
void router_reset_status_download_failures(void)
Header file for dirlist.c.
int directory_caches_dir_info(const or_options_t *options)
Header file for dirserv.c.
int download_status_is_ready(download_status_t *dls, time_t now)
void download_status_mark_impossible(download_status_t *dl)
Header file for dlstatus.c.
Authority signature structure.
const char * escaped(const char *s)
char * esc_for_log(const char *s)
Header for core/or/extendinfo.c.
int write_str_to_file(const char *fname, const char *str, int bin)
#define RFTS_IGNORE_MISSING
file_status_t file_status(const char *filename)
int append_bytes_to_file(const char *fname, const char *str, size_t len, int bin)
int replace_file(const char *from, const char *to)
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
#define log_fn(severity, domain, args,...)
#define log_fn_ratelim(ratelim, severity, domain, args,...)
void reschedule_directory_downloads(void)
smartlist_t * get_connection_array(void)
Header file for mainloop.c.
#define DIGESTMAP_FOREACH_END
int we_fetch_router_descriptors(const or_options_t *options)
void update_microdesc_downloads(time_t now)
Header file for microdesc.c.
routerstatus_t * networkstatus_vote_find_mutable_entry(networkstatus_t *ns, const char *digest)
networkstatus_t * networkstatus_get_latest_consensus_by_flavor(consensus_flavor_t f)
int we_want_to_fetch_flavor(const or_options_t *options, int flavor)
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_t * networkstatus_get_latest_consensus(void)
download_status_t * router_get_dl_status_by_descriptor_digest(const char *d)
const routerstatus_t * router_get_consensus_status_by_id(const char *digest)
int should_delay_dir_fetches(const or_options_t *options, const char **msg_out)
const routerstatus_t * networkstatus_vote_find_entry(networkstatus_t *ns, const char *digest)
void networkstatus_reset_download_failures(void)
void networkstatus_reset_warnings(void)
void routers_update_status_from_consensus_networkstatus(smartlist_t *routers, int reset_failures)
Header file for networkstatus.c.
Networkstatus consensus/vote structure.
Single consensus voter structure.
Header file for node_select.c.
#define PDS_NO_EXISTING_SERVERDESC_FETCH
#define PDS_NO_EXISTING_MICRODESC_FETCH
#define PDS_RETRY_IF_NO_SERVERS
Node information structure.
void nodelist_refresh_countries(void)
void router_dir_info_changed(void)
const smartlist_t * nodelist_get_list(void)
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
int node_is_unreliable(const node_t *node, int need_uptime, int need_capacity, int need_guard)
bool node_supports_v3_rendezvous_point(const node_t *node)
node_t * nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out)
int node_allows_single_hop_exits(const node_t *node)
void nodelist_remove_routerinfo(routerinfo_t *ri)
bool node_supports_initiating_ipv6_extends(const node_t *node)
int node_has_curve25519_onion_key(const node_t *node)
int router_have_minimum_dir_info(void)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
#define OLD_ROUTER_DESC_MAX_AGE
#define ROUTER_ANNOTATION_BUF_LEN
int addr_policies_eq(const smartlist_t *a, const smartlist_t *b)
int firewall_is_fascist_or(void)
int reachable_addr_allows_node(const node_t *node, firewall_connection_t fw_connection, int pref_only)
int firewall_is_fascist_dir(void)
Header file for policies.c.
int tor_asprintf(char **strp, const char *fmt,...)
int tor_snprintf(char *str, size_t size, const char *format,...)
int dirserv_would_reject_router(const routerstatus_t *rs, const vote_routerstatus_t *vrs)
int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg, int complain, int *valid_out)
Header file for process_descs.c.
void dirserv_single_reachability_test(time_t now, routerinfo_t *router)
Header file for reachability.c.
Header file for relay_find_addr.c.
void rep_hist_note_router_unreachable(const char *id, time_t when)
Header file for rephist.c.
extrainfo_t * router_get_my_extrainfo(void)
const routerinfo_t * router_get_my_routerinfo(void)
int router_is_me(const routerinfo_t *router)
const char * router_purpose_to_string(uint8_t p)
Header file for routerinfo.c.
Router descriptor structure.
#define ROUTER_PURPOSE_GENERAL
#define ROUTER_PURPOSE_BRIDGE
static void routerlist_insert(routerlist_t *rl, routerinfo_t *ri)
void routerinfo_free_(routerinfo_t *router)
void routerlist_free_all(void)
static void routerlist_remove_old_cached_routers_with_id(time_t now, time_t cutoff, int lo, int hi, digestset_t *retain)
void list_pending_microdesc_downloads(digest256map_t *result)
void update_consensus_router_descriptor_downloads(time_t now, int is_vote, networkstatus_t *consensus)
int router_exit_policy_rejects_all(const routerinfo_t *router)
void routerlist_free_(routerlist_t *rl)
int hex_digest_nickname_matches(const char *hexdigest, const char *identity_digest, const char *nickname)
#define DEFAULT_MAX_BELIEVABLE_BANDWIDTH
void launch_descriptor_downloads(int purpose, smartlist_t *downloadable, const routerstatus_t *source, time_t now)
void router_load_extrainfo_from_string(const char *s, const char *eos, saved_location_t saved_location, smartlist_t *requested_fingerprints, int descriptor_digests)
static void signed_descriptor_move(signed_descriptor_t *dest, signed_descriptor_t *src)
static void signed_descriptor_reset(signed_descriptor_t *sd)
static void routerlist_remove_old(routerlist_t *rl, signed_descriptor_t *sd, int idx)
STATIC void initiate_descriptor_downloads(const routerstatus_t *source, int purpose, smartlist_t *digests, int lo, int hi, int pds_flags)
void dump_routerlist_mem_usage(int severity)
uint32_t router_get_advertised_bandwidth(const routerinfo_t *router)
void routerlist_retry_directory_downloads(time_t now)
void router_add_running_nodes_to_smartlist(smartlist_t *sl, int flags)
static int routerlist_find_elt_(smartlist_t *sl, void *ri, int idx)
int hex_digest_nickname_decode(const char *hexdigest, char *digest_out, char *nickname_qualifier_char_out, char *nickname_out)
static void signed_descriptor_free_(signed_descriptor_t *sd)
static void extrainfo_free_void(void *e)
void routerlist_assert_ok(const routerlist_t *rl)
static void list_pending_descriptor_downloads(digestmap_t *result, int extrainfo)
int router_descriptor_is_older_than(const routerinfo_t *router, int seconds)
int router_load_single_router(const char *s, uint8_t purpose, int cache, const char **msg)
static routerlist_t * routerlist
static routerinfo_t * routerlist_reparse_old(routerlist_t *rl, signed_descriptor_t *sd)
routerinfo_t * router_get_mutable_by_digest(const char *digest)
STATIC was_router_added_t extrainfo_insert(routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible)
int router_reload_router_list(void)
static int max_dl_per_request(const or_options_t *options, int purpose)
void refresh_all_country_info(void)
void update_router_descriptor_downloads(time_t now)
int routerinfo_incompatible_with_extrainfo(const crypto_pk_t *identity_pkey, extrainfo_t *ei, signed_descriptor_t *sd, const char **msg)
void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old, time_t now)
routerlist_t * router_get_routerlist(void)
was_router_added_t router_add_extrainfo_to_routerlist(extrainfo_t *ei, const char **msg, int from_cache, int from_fetch)
static void routerlist_replace(routerlist_t *rl, routerinfo_t *ri_old, routerinfo_t *ri_new)
void extrainfo_free_(extrainfo_t *extrainfo)
int hexdigest_to_digest(const char *hexdigest, char *digest)
void list_pending_downloads(digestmap_t *result, digest256map_t *result256, int purpose, const char *prefix)
int routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2)
const routerinfo_t * router_get_by_id_digest(const char *digest)
const char * signed_descriptor_get_annotations(const signed_descriptor_t *desc)
signed_descriptor_t * router_get_by_descriptor_digest(const char *digest)
void routers_sort_by_identity(smartlist_t *routers)
was_router_added_t router_add_to_routerlist(routerinfo_t *router, const char **msg, int from_cache, int from_fetch)
signed_descriptor_t * extrainfo_get_by_descriptor_digest(const char *digest)
void update_extrainfo_downloads(time_t now)
static time_t last_descriptor_download_attempted
static const char * signed_descriptor_get_body_impl(const signed_descriptor_t *desc, int with_annotations)
static smartlist_t * warned_nicknames
int router_differences_are_cosmetic(const routerinfo_t *r1, const routerinfo_t *r2)
static int compare_old_routers_by_identity_(const void **_a, const void **_b)
static int compare_duration_idx_(const void *_d1, const void *_d2)
static int router_rebuild_store(int flags, desc_store_t *store)
#define MIN_DL_PER_REQUEST
#define ROUTER_ALLOW_UPTIME_DRIFT
static int router_reload_router_list_impl(desc_store_t *store)
void routerlist_descriptors_added(smartlist_t *sl, int from_cache)
static int router_should_rebuild_store(desc_store_t *store)
void routerlist_remove_old_routers(void)
void routerlist_reset_warnings(void)
uint32_t router_get_advertised_bandwidth_capped(const routerinfo_t *router)
static int compare_signed_descriptors_by_age_(const void **_a, const void **_b)
static int signed_desc_digest_is_recognized(signed_descriptor_t *desc)
void router_reset_descriptor_download_failures(void)
static void routerlist_insert_old(routerlist_t *rl, routerinfo_t *ri)
int router_load_routers_from_string(const char *s, const char *eos, saved_location_t saved_location, smartlist_t *requested_fingerprints, int descriptor_digests, const char *prepend_annotations)
signed_descriptor_t * router_get_by_extrainfo_digest(const char *digest)
static int compare_routerinfo_by_id_digest_(const void **a, const void **b)
static int signed_desc_append_to_journal(signed_descriptor_t *desc, desc_store_t *store)
const char * signed_descriptor_get_body(const signed_descriptor_t *desc)
#define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE
static desc_store_t * desc_get_store(routerlist_t *rl, const signed_descriptor_t *sd)
const routerinfo_t * routerlist_find_my_routerinfo(void)
const char * esc_router_info(const routerinfo_t *router)
void update_all_descriptor_downloads(time_t now)
static signed_descriptor_t * signed_descriptor_from_routerinfo(routerinfo_t *ri)
Header file for routerlist.c.
static int WRA_WAS_ADDED(was_router_added_t s)
static int WRA_WAS_OUTDATED(was_router_added_t s)
static int WRA_NEVER_DOWNLOADABLE(was_router_added_t s)
Router descriptor list structure.
int server_mode(const or_options_t *options)
Header file for routermode.c.
int router_parse_list_from_string(const char **s, const char *eos, smartlist_t *dest, saved_location_t saved_location, int want_extrainfo, int allow_annotations, const char *prepend_annotations, smartlist_t *invalid_digests_out)
routerinfo_t * router_parse_entry_from_string(const char *s, const char *end, int cache_copy, int allow_annotations, const char *prepend_annotations, int *can_dl_again_out)
Header file for routerparse.c.
void routerset_refresh_countries(routerset_t *target)
Header file for routerset.c.
void smartlist_sort_digests(smartlist_t *sl)
void smartlist_string_remove(smartlist_t *sl, const char *element)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
int smartlist_contains_string(const smartlist_t *sl, const char *element)
void smartlist_sort(smartlist_t *sl, int(*compare)(const void **a, const void **b))
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_clear(smartlist_t *sl)
void smartlist_del(smartlist_t *sl, int idx)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
char * requested_resource
routerstatus_t fake_status
smartlist_t * routerstatus_list
consensus_flavor_t flavor
char identity_digest[DIGEST_LEN]
struct routerset_t * ExcludeExitNodes
struct routerset_t * ExcludeExitNodesUnion_
int TestingClientMaxIntervalWithoutRequest
struct routerset_t * EntryNodes
struct routerset_t * ExcludeNodes
struct routerset_t * ExitNodes
struct routerset_t * MiddleNodes
unsigned int supports_extend2_cells
unsigned int protocols_known
smartlist_t * exit_policy
smartlist_t * declared_family
crypto_pk_t * identity_pkey
struct curve25519_public_key_t * onion_curve25519_pkey
unsigned int is_hibernating
unsigned int policy_is_reject_star
unsigned int supports_tunnelled_dir_requests
uint32_t bandwidthcapacity
time_t cert_expiration_time
struct short_policy_t * ipv6_exit_policy
struct digest_sd_map_t * desc_digest_map
desc_store_t extrainfo_store
smartlist_t * old_routers
struct digest_ei_map_t * extra_info_map
struct digest_ri_map_t * identity_map
struct digest_sd_map_t * desc_by_eid_map
protover_summary_flags_t pv
char descriptor_digest[DIGEST256_LEN]
char identity_digest[DIGEST_LEN]
char nickname[MAX_NICKNAME_LEN+1]
char signed_descriptor_digest[DIGEST_LEN]
char extra_info_digest[DIGEST_LEN]
char identity_digest[DIGEST_LEN]
download_status_t ei_dl_status
time_t last_listed_as_valid_until
struct tor_cert_st * signing_key_cert
char * signed_descriptor_body
char extra_info_digest256[DIGEST256_LEN]
size_t signed_descriptor_len
saved_location_t saved_location
#define MOCK_IMPL(rv, funcname, arglist)
void format_iso_time(char *buf, time_t t)
int tor_cert_opt_eq(const tor_cert_t *cert1, const tor_cert_t *cert2)
int strcmpstart(const char *s1, const char *s2)
int fast_mem_is_zero(const char *mem, size_t len)
int tor_digest_is_zero(const char *digest)
Routerstatus (vote entry) structure.
#define CURVE25519_PUBKEY_LEN