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;
247 size_t total_expected_len = 0;
249 int force = flags & RRS_FORCE;
260 if (store->
type == EXTRAINFO_STORE)
267 if (!(flags & RRS_DONT_REMOVE_OLD))
272 fname = get_cachedir_fname(store->
fname_base);
273 fname_tmp = get_cachedir_fname_suffix(store->
fname_base,
".tmp");
279 if (store->
type == EXTRAINFO_STORE) {
282 !eimap_iter_done(iter);
286 eimap_iter_get(iter, &key, &ei);
303 log_warn(
LD_BUG,
"No descriptor available for router.");
306 if (sd->do_not_cache) {
312 c->len = sd->signed_descriptor_len + sd->annotations_len;
313 total_expected_len += c->len;
315 } SMARTLIST_FOREACH_END(sd);
317 if (write_chunks_to_file(fname_tmp, chunk_list, 1, 1)<0) {
318 log_warn(
LD_FS,
"Error writing router store to disk.");
324 int res = tor_munmap_file(store->
mmap);
327 log_warn(
LD_FS,
"Unable to munmap route store in %s", fname);
332 log_warn(
LD_FS,
"Error replacing old router store: %s", strerror(errno));
337 store->
mmap = tor_mmap_file(fname);
339 if (errno == ERANGE) {
341 if (total_expected_len) {
342 log_warn(
LD_FS,
"We wrote some bytes to a new descriptor file at '%s',"
343 " but when we went to mmap it, it was empty!", fname);
344 }
else if (had_any) {
345 log_info(
LD_FS,
"We just removed every descriptor in '%s'. This is "
346 "okay if we're just starting up after a long time. "
347 "Otherwise, it's a bug.", fname);
350 log_warn(
LD_FS,
"Unable to mmap new descriptor file at '%s'.",fname);
354 log_info(
LD_DIR,
"Reconstructing pointers into cache");
358 if (sd->do_not_cache)
362 tor_free(sd->signed_descriptor_body);
363 sd->saved_offset = offset;
365 offset += sd->signed_descriptor_len + sd->annotations_len;
367 } SMARTLIST_FOREACH_END(sd);
370 fname = get_cachedir_fname_suffix(store->
fname_base,
".new");
378 smartlist_free(signed_descriptors);
383 smartlist_free(chunk_list);
395 char *fname = NULL, *contents = NULL;
397 int extrainfo = (store->
type == EXTRAINFO_STORE);
400 fname = get_cachedir_fname(store->
fname_base);
404 int res = tor_munmap_file(store->
mmap);
407 log_warn(
LD_FS,
"Failed to munmap %s", fname);
413 store->
mmap = tor_mmap_file(fname);
427 fname = get_cachedir_fname_suffix(store->
fname_base,
".new");
447 }
else if (!extrainfo) {
481 router_or_conn_should_skip_reachable_address_check(
497 router_dir_conn_should_skip_reachable_address_check(
512 r1->ipv4_orport == r2->ipv4_orport &&
514 r1->ipv6_orport == r2->ipv6_orport;
552 router_can_choose_node(
const node_t *node,
int flags)
555 const bool need_uptime = (flags & CRN_NEED_UPTIME) != 0;
556 const bool need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
557 const bool need_guard = (flags & CRN_NEED_GUARD) != 0;
558 const bool need_desc = (flags & CRN_NEED_DESC) != 0;
559 const bool pref_addr = (flags & CRN_PREF_ADDR) != 0;
560 const bool direct_conn = (flags & CRN_DIRECT_CONN) != 0;
561 const bool rendezvous_v3 = (flags & CRN_RENDEZVOUS_V3) != 0;
562 const bool initiate_ipv6_extend = (flags & CRN_INITIATE_IPV6_EXTEND) != 0;
565 const bool check_reach =
566 !router_or_conn_should_skip_reachable_address_check(options, pref_addr);
567 const bool direct_bridge = direct_conn && options->
UseBridges;
582 if (node->rs && !routerstatus_version_supports_extend2_cells(node->rs, 1))
598 if (direct_conn && check_reach &&
600 FIREWALL_OR_CONNECTION,
618 if (!router_can_choose_node(node, flags))
621 } SMARTLIST_FOREACH_END(node);
634 if (router_is_me(router))
652 #define DEFAULT_MAX_BELIEVABLE_BANDWIDTH 10000000
686 char *nickname_qualifier_char_out,
692 if (hexdigest[0] ==
'$')
695 len = strlen(hexdigest);
721 const char *nickname)
730 if (nn_char ==
'=') {
734 if (nn_char ==
'~') {
737 if (strcasecmp(nn_buf, nickname))
751 if (hexdigest[0]==
'$')
816 return ei ? &ei->cache_info : NULL;
832 int with_annotations)
834 const char *r = NULL;
837 if (with_annotations)
845 if (store && store->
mmap) {
849 log_err(
LD_DIR,
"We couldn't read a descriptor that is supposedly "
850 "mmaped in our cache. Is another process running in our data "
851 "directory? Exiting.");
860 if (!with_annotations) {
862 char *cp = tor_strndup(r, 64);
863 log_err(
LD_DIR,
"descriptor at %p begins with unexpected string %s. "
864 "Is another process running in our data directory? Exiting.",
962 #define signed_descriptor_free(val) \
963 FREE_AND_NULL(signed_descriptor_t, signed_descriptor_free_, (val))
987 memset(sd, 0,
sizeof(*sd));
1015 routerinfo_free(ri);
1037 routerinfo_free(r));
1039 signed_descriptor_free(sd));
1045 log_warn(
LD_FS,
"Failed to munmap routerlist->desc_store.mmap");
1051 log_warn(
LD_FS,
"Failed to munmap routerlist->extrainfo_store.mmap");
1062 uint64_t livedescs = 0;
1063 uint64_t olddescs = 0;
1072 "In %d live descriptors: %"PRIu64
" bytes. "
1073 "In %d old descriptors: %"PRIu64
" bytes.",
1131 signed_descriptor_free(sd_old);
1141 #ifdef DEBUG_ROUTERLIST
1153 const char *compatibility_error_msg;
1168 r = ROUTER_NOT_IN_CONSENSUS;
1174 static ratelim_t no_sd_ratelim = RATELIM_INIT(1800);
1181 "No entry found in extrainfo map.");
1186 static ratelim_t digest_mismatch_ratelim = RATELIM_INIT(1800);
1191 "Mismatch in digest in extrainfo map.");
1195 &compatibility_error_msg)) {
1197 r = (ri->cache_info.extrainfo_is_bogus) ?
1198 ROUTER_BAD_EI : ROUTER_NOT_IN_CONSENSUS;
1204 "router info incompatible with extra info (ri id: %s, ei id %s, "
1205 "reason: %s)", d1, d2, compatibility_error_msg);
1216 r = ROUTER_ADDED_SUCCESSFULLY;
1220 extrainfo_free(ei_tmp);
1224 if (r != ROUTER_ADDED_SUCCESSFULLY)
1227 #ifdef DEBUG_ROUTERLIST
1233 #define should_cache_old_descriptors() \
1234 directory_caches_dir_info(get_options())
1248 if (should_cache_old_descriptors() &&
1259 routerinfo_free(ri);
1261 #ifdef DEBUG_ROUTERLIST
1290 if (idx < smartlist_len(rl->
routers)) {
1299 if (make_old && should_cache_old_descriptors() &&
1319 extrainfo_free(ei_tmp);
1323 routerinfo_free(ri);
1325 #ifdef DEBUG_ROUTERLIST
1367 extrainfo_free(ei_tmp);
1372 signed_descriptor_free(sd);
1373 #ifdef DEBUG_ROUTERLIST
1391 int same_descriptors;
1414 smartlist_set(rl->
routers, idx, ri_new);
1420 log_warn(
LD_BUG,
"Appending entry from routerlist_replace.");
1434 &(ri_new->cache_info));
1438 &ri_new->cache_info);
1445 if (should_cache_old_descriptors() &&
1447 !same_descriptors) {
1458 if (!same_descriptors) {
1470 extrainfo_free(ei_tmp);
1480 routerinfo_free(ri_old);
1482 #ifdef DEBUG_ROUTERLIST
1520 routerlist_free(rl);
1527 authcert_free_all();
1574 int from_cache,
int from_fetch)
1576 const char *id_digest;
1579 int authdir_believes_valid = 0;
1583 int in_consensus = 0;
1596 routerinfo_free(router);
1597 *msg =
"Some certs on this router are expired.";
1598 return ROUTER_CERTS_EXPIRED;
1610 const int was_bridge = old_router &&
1616 log_info(
LD_DIR,
"Replacing non-bridge descriptor with bridge "
1617 "descriptor for router %s",
1621 "Dropping descriptor that we already have for router %s",
1623 *msg =
"Router descriptor was not new.";
1624 routerinfo_free(router);
1625 return ROUTER_IS_ALREADY_KNOWN;
1631 !from_cache && !from_fetch,
1632 &authdir_believes_valid)) {
1634 routerinfo_free(router);
1635 return ROUTER_AUTHDIR_REJECTS;
1637 }
else if (from_fetch) {
1646 "Received a no-longer-recognized descriptor for router %s",
1648 *msg =
"Router descriptor is not referenced by any network-status.";
1651 if (!from_cache && should_cache_old_descriptors())
1655 return ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS;
1662 consensus, id_digest);
1671 consensus && !in_consensus && !authdir) {
1674 if (!from_cache && should_cache_old_descriptors())
1678 *msg =
"Skipping router descriptor: not in consensus.";
1679 return ROUTER_NOT_IN_CONSENSUS;
1689 log_info(
LD_DIR,
"Dropping bridge descriptor for %s because we have "
1690 "no bridge configured at that address.",
1692 *msg =
"Router descriptor was not a configured bridge.";
1693 routerinfo_free(router);
1694 return ROUTER_WAS_NOT_WANTED;
1699 if (!in_consensus && (router->cache_info.
published_on <=
1702 log_debug(
LD_DIR,
"Not-new descriptor for router %s",
1705 if (!from_cache && should_cache_old_descriptors())
1709 *msg =
"Router descriptor was not new.";
1710 return ROUTER_IS_ALREADY_KNOWN;
1713 log_debug(
LD_DIR,
"Replacing entry for router %s",
1720 *msg = authdir_believes_valid ?
"Valid server updated" :
1721 (
"Invalid server updated. (This dirserver is marking your "
1722 "server as unapproved.)");
1723 return ROUTER_ADDED_SUCCESSFULLY;
1727 if (!in_consensus && from_cache &&
1729 *msg =
"Router descriptor was really old.";
1730 routerinfo_free(router);
1731 return ROUTER_WAS_TOO_OLD;
1741 return ROUTER_ADDED_SUCCESSFULLY;
1750 int from_cache,
int from_fetch)
1754 if (msg) *msg = NULL;
1794 return d1->duration - d2->duration;
1807 time_t cutoff,
int lo,
int hi,
1808 digestset_t *retain)
1811 unsigned n_extra, n_rmv = 0;
1813 uint8_t *rmv, *must_keep;
1820 for (i = lo+1; i <= hi; ++i) {
1834 rmv = tor_calloc(n,
sizeof(uint8_t));
1835 must_keep = tor_calloc(n,
sizeof(uint8_t));
1838 for (i = lo; i <= hi; ++i) {
1841 lifespans[i-lo].idx = i;
1845 must_keep[i-lo] = 1;
1848 r_next = smartlist_get(lst, i+1);
1853 lifespans[i-lo].duration = INT_MAX;
1855 if (!must_keep[i-lo] && r->
published_on < cutoff && n_rmv < n_extra) {
1857 lifespans[i-lo].old = 1;
1862 if (n_rmv < n_extra) {
1869 for (i = 0; i < n && n_rmv < n_extra; ++i) {
1870 if (!must_keep[lifespans[i].idx-lo] && !lifespans[i].old) {
1871 rmv[lifespans[i].idx-lo] = 1;
1881 }
while (--i >= lo);
1895 const char *cur_id = NULL;
1896 time_t now = time(NULL);
1900 digestset_t *retain;
1924 if (rs->published_on >= cutoff)
1944 "Forgetting obsolete (too old) routerinfo for router %s",
1968 log_info(
LD_DIR,
"We have %d live routers and %d old router descriptors.",
2000 cutoff, i+1, hi, retain);
2010 digestset_free(retain);
2027 if (ri->needs_retest_if_added) {
2028 ri->needs_retest_if_added = 0;
2031 } SMARTLIST_FOREACH_END(ri);
2058 "@source controller\n"
2062 annotation_buf, NULL))) {
2063 log_warn(
LD_DIR,
"Error parsing router descriptor; dropping.");
2064 *msg =
"Couldn't parse router descriptor.";
2069 log_warn(
LD_DIR,
"Router's identity key matches mine; dropping.");
2070 *msg =
"Router's identity key matches mine.";
2071 routerinfo_free(ri);
2076 ri->cache_info.do_not_cache = 1;
2086 if (r == ROUTER_AUTHDIR_REJECTS)
2087 log_warn(
LD_DIR,
"Couldn't add router to list: %s Dropping.", *msg);
2088 smartlist_free(lst);
2092 smartlist_free(lst);
2093 log_debug(
LD_DIR,
"Added router to list");
2117 int descriptor_digests,
2118 const char *prepend_annotations)
2125 int any_changed = 0;
2129 allow_annotations, prepend_annotations,
2134 log_info(
LD_DIR,
"%d elements to add", smartlist_len(routers));
2139 if (requested_fingerprints) {
2141 ri->cache_info.signed_descriptor_digest :
2142 ri->cache_info.identity_digest,
2150 "We received a router descriptor with a fingerprint (%s) "
2151 "that we never requested. (We asked for: %s.) Dropping.",
2154 routerinfo_free(ri);
2159 memcpy(d, ri->cache_info.signed_descriptor_digest,
DIGEST_LEN);
2170 log_info(
LD_GENERAL,
"Marking router %s as never downloadable",
2175 } SMARTLIST_FOREACH_END(ri);
2180 if (requested_fingerprints && descriptor_digests) {
2190 log_info(
LD_GENERAL,
"Marking router with descriptor %s as unparseable, "
2191 "and therefore undownloadable", fp);
2194 } SMARTLIST_FOREACH_END(bad_digest);
2196 smartlist_free(invalid_digests);
2203 smartlist_free(routers);
2204 smartlist_free(changed);
2216 int descriptor_digests)
2224 NULL, invalid_digests);
2226 log_info(
LD_DIR,
"%d elements to add", smartlist_len(extrainfo_list));
2230 memcpy(d, ei->cache_info.signed_descriptor_digest,
DIGEST_LEN);
2236 ei->cache_info.signed_descriptor_digest :
2237 ei->cache_info.identity_digest,
2247 log_info(
LD_GENERAL,
"Marking extrainfo with descriptor %s as "
2248 "unparseable, and therefore undownloadable",
2253 } SMARTLIST_FOREACH_END(ei);
2259 if (requested_fingerprints) {
2269 log_info(
LD_GENERAL,
"Marking extrainfo with descriptor %s as "
2270 "unparseable, and therefore undownloadable", fp);
2273 } SMARTLIST_FOREACH_END(bad_digest);
2275 smartlist_free(invalid_digests);
2280 smartlist_free(extrainfo_list);
2320 "In routerlist_retry_directory_downloads()");
2343 int purpose,
const char *prefix)
2345 const size_t p_len = strlen(prefix);
2348 int flags = DSR_HEX;
2350 flags = DSR_DIGEST256|DSR_BASE64;
2356 conn->purpose == purpose &&
2357 !conn->marked_for_close) {
2363 } SMARTLIST_FOREACH_END(conn);
2368 digestmap_set(result, d, (
void*)1);
2371 }
else if (result256) {
2374 digest256map_set(result256, d, (
void*)1);
2378 smartlist_free(tmp);
2409 int lo,
int hi,
int pds_flags))
2411 char *resource, *cp;
2412 int digest_len, enc_digest_len;
2433 if (hi > smartlist_len(digests))
2434 hi = smartlist_len(digests);
2441 for (; lo < hi; ++lo) {
2442 cp = tor_malloc(enc_digest_len);
2446 base16_encode(cp, enc_digest_len, smartlist_get(digests, lo),
2456 smartlist_free(tmp);
2465 directory_request_free(req);
2468 pds_flags, DL_WANT_ANY_DIRSERVER);
2496 if (dirclient_must_use_begindir(options)) {
2505 #define MIN_DL_PER_REQUEST 32
2508 #define MIN_REQUESTS 3
2511 #define MAX_DL_TO_DELAY 16
2525 const char *descname;
2527 int n_downloadable = smartlist_len(downloadable);
2529 int i, n_per_request, max_dl_per_req;
2530 const char *req_plural =
"", *rtr_plural =
"";
2534 descname = fetch_microdesc ?
"microdesc" :
"routerdesc";
2536 if (!n_downloadable)
2542 "There are enough downloadable %ss to launch requests.",
2546 "We are only missing %d %ss, but we'll fetch anyway, since "
2547 "we don't yet have enough directory info.",
2548 n_downloadable, descname);
2558 "There are not many downloadable %ss, but we've "
2559 "been waiting long enough (%d seconds). Downloading.",
2564 "There are not many downloadable %ss, but we haven't "
2565 "tried downloading descriptors recently. Downloading.",
2582 pds_flags |= fetch_microdesc ?
2587 n_per_request = CEIL_DIV(n_downloadable,
MIN_REQUESTS);
2590 if (n_per_request > max_dl_per_req)
2591 n_per_request = max_dl_per_req;
2597 if (n_downloadable > n_per_request)
2598 req_plural = rtr_plural =
"s";
2599 else if (n_downloadable > 1)
2603 "Launching %d request%s for %d %s%s, %d at a time",
2604 CEIL_DIV(n_downloadable, n_per_request), req_plural,
2605 n_downloadable, descname, rtr_plural, n_per_request);
2607 for (i=0; i < n_downloadable; i += n_per_request) {
2609 downloadable, i, i+n_per_request,
2622 digestmap_t *map = NULL;
2627 int n_delayed=0, n_have=0, n_would_reject=0, n_wouldnt_use=0,
2628 n_inprogress=0, n_in_oldrouters=0;
2644 log_warn(
LD_DIR,
"couldn't lookup source from vote?");
2647 map = digestmap_new();
2692 if (is_vote && source) {
2693 char time_bufnew[ISO_TIME_LEN+1];
2694 char time_bufold[ISO_TIME_LEN+1];
2700 log_info(
LD_DIR,
"Learned about %s (%s vs %s) from %s's vote (%s)",
2703 oldrouter ? time_bufold :
"none",
2704 source->
nickname, oldrouter ?
"known" :
"unknown");
2707 } SMARTLIST_FOREACH_END(rsp);
2709 if (!authdir_mode_v3(options)
2710 && smartlist_len(no_longer_old)) {
2712 log_info(
LD_DIR,
"%d router descriptors listed in consensus are "
2713 "currently in old_routers; making them current.",
2714 smartlist_len(no_longer_old));
2718 time_t tmp_cert_expiration_time;
2721 log_warn(
LD_BUG,
"Failed to re-parse a router.");
2729 log_warn(
LD_DIR,
"Couldn't add re-parsed router: %s. This isn't "
2730 "usually a big deal, but you should make sure that your "
2731 "clock and timezone are set correctly.",
2733 if (r == ROUTER_CERTS_EXPIRED) {
2734 char time_cons[ISO_TIME_LEN+1];
2735 char time_cert_expires[ISO_TIME_LEN+1];
2738 log_warn(
LD_DIR,
" (I'm looking at a consensus from %s; This "
2739 "router's certificates began expiring at %s.)",
2740 time_cons, time_cert_expires);
2743 } SMARTLIST_FOREACH_END(sd);
2748 "%d router descriptors downloadable. %d delayed; %d present "
2749 "(%d of those were in old_routers); %d would_reject; "
2750 "%d wouldnt_use; %d in progress.",
2751 smartlist_len(downloadable), n_delayed, n_have, n_in_oldrouters,
2752 n_would_reject, n_wouldnt_use, n_inprogress);
2755 downloadable, source, now);
2757 digestmap_free(map, NULL);
2759 smartlist_free(downloadable);
2760 smartlist_free(no_longer_old);
2784 digestmap_t *pending;
2785 int old_routers, i, max_dl_per_req;
2786 int n_no_ei = 0, n_pending = 0, n_have = 0, n_delay = 0, n_bogus[2] = {0,0};
2794 pending = digestmap_new();
2798 for (old_routers = 0; old_routers < 2; ++old_routers) {
2800 for (i = 0; i < smartlist_len(lst); ++i) {
2804 sd = smartlist_get(lst, i);
2806 sd = &((
routerinfo_t*)smartlist_get(lst, i))->cache_info;
2807 if (sd->is_extrainfo)
2811 if (sd->extrainfo_is_bogus)
2826 if (digestmap_get(pending, d)) {
2841 log_info(
LD_DIR,
"Found an entry in %s with mismatched "
2842 "router_get_by_extrainfo_digest() value. This has ID %s "
2843 "but the entry in the map has ID %s. This has EI digest "
2844 "%s and the entry in the map has EI digest %s.",
2845 old_routers?
"old_routers":
"routers",
2852 log_info(
LD_DIR,
"Found an entry in %s with NULL "
2853 "router_get_by_extrainfo_digest() value. This has ID %s "
2854 "and EI digest %s.",
2855 old_routers?
"old_routers":
"routers",
2858 ++n_bogus[old_routers];
2864 digestmap_free(pending, NULL);
2866 log_info(
LD_DIR,
"Extrainfo download status: %d router with no ei, %d "
2867 "with present ei, %d delaying, %d pending, %d downloadable, %d "
2868 "bogus in routers, %d bogus in old_routers",
2869 n_no_ei, n_have, n_delay, n_pending, smartlist_len(wanted),
2870 n_bogus[0], n_bogus[1]);
2875 for (i = 0; i < smartlist_len(wanted); i += max_dl_per_req) {
2877 wanted, i, i+max_dl_per_req,
2881 smartlist_free(wanted);
2893 "In router_reset_descriptor_download_failures()");
2903 download_status_reset(&ri->cache_info.ei_dl_status);
2907 download_status_reset(&sd->ei_dl_status);
2913 #define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE (2*60*60)
2916 #define ROUTER_ALLOW_UPTIME_DRIFT (6*60*60)
2924 time_t r1pub, r2pub;
2925 time_t time_difference;
2938 r1->ipv4_orport != r2->ipv4_orport ||
2940 r1->ipv6_orport != r2->ipv6_orport ||
2941 r1->ipv4_dirport != r2->ipv4_dirport ||
2963 for (i=0; i < n; ++i) {
2989 time_difference = r2->
uptime - (r1->
uptime + (r2pub - r1pub));
2990 if (time_difference < 0)
2991 time_difference = - time_difference;
2993 time_difference > r1->
uptime * .05 &&
2994 time_difference > r2->
uptime * .05)
3023 int digest_matches, digest256_matches, r=1;
3029 if (msg) *msg =
"Extrainfo signature was bad, or signed with wrong key.";
3039 digest256_matches |=
3047 if (msg) *msg =
"Extrainfo nickname or identity did not match routerinfo";
3053 if (msg) *msg =
"Extrainfo signing key cert didn't match routerinfo";
3058 char signed_digest[128];
3060 signed_digest,
sizeof(signed_digest),
3066 if (msg) *msg =
"Extrainfo signature bad, or signed with wrong key";
3070 ei->cache_info.send_unencrypted = sd->send_unencrypted;
3075 if (msg) *msg =
"Extrainfo published time did not match routerdesc";
3078 if (msg) *msg =
"Extrainfo published time did not match routerdesc";
3083 if (!digest256_matches && !digest_matches) {
3084 if (msg) *msg =
"Neither digest256 or digest matched "
3085 "digest from routerdesc";
3089 if (!digest256_matches) {
3090 if (msg) *msg =
"Extrainfo digest did not match digest256 from routerdesc";
3094 if (!digest_matches) {
3095 if (msg) *msg =
"Extrainfo digest did not match value from routerdesc";
3101 if (digest_matches) {
3105 sd->extrainfo_is_bogus = 1;
3114 routerinfo_has_curve25519_onion_key(
const routerinfo_t *ri)
3138 routerstatus_version_supports_extend2_cells(
const routerstatus_t *rs,
3139 int allow_unknown_versions)
3142 return allow_unknown_versions;
3146 return allow_unknown_versions;
3162 r2 = rimap_get(rl->
identity_map, r->cache_info.identity_digest);
3165 r->cache_info.signed_descriptor_digest);
3167 tor_assert(r->cache_info.routerlist_index == r_sl_idx);
3191 } SMARTLIST_FOREACH_END(r);
3197 tor_assert(sd->routerlist_index == sd_sl_idx);
3205 } SMARTLIST_FOREACH_END(sd);
3223 ei->cache_info.signed_descriptor_digest);
3245 static char *info=NULL;
3246 char *esc_contact, *esc_platform;
3255 tor_asprintf(&info,
"Contact %s, Platform %s", esc_contact, esc_platform);
3269 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)
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)
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