62#define ROUTERLIST_PRIVATE
113#ifdef HAVE_SYS_STAT_H
125DECLARE_TYPED_DIGESTMAP_FNS(rimap, digest_ri_map_t,
routerinfo_t)
126DECLARE_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) {
479router_or_conn_should_skip_reachable_address_check(
495router_dir_conn_should_skip_reachable_address_check(
510 r1->ipv4_orport == r2->ipv4_orport &&
512 r1->ipv6_orport == r2->ipv6_orport;
550router_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;
561 const bool need_conflux = (flags & CRN_CONFLUX) != 0;
564 const bool check_reach =
565 !router_or_conn_should_skip_reachable_address_check(options, pref_addr);
566 const bool direct_bridge = direct_conn && options->
UseBridges;
581 if (node->rs && !routerstatus_version_supports_extend2_cells(node->rs, 1))
601 if (direct_conn && check_reach &&
603 FIREWALL_OR_CONNECTION,
621 if (!router_can_choose_node(node, flags))
624 } SMARTLIST_FOREACH_END(node);
637 if (router_is_me(router))
655#define DEFAULT_MAX_BELIEVABLE_BANDWIDTH 10000000
689 char *nickname_qualifier_char_out,
695 if (hexdigest[0] ==
'$')
698 len = strlen(hexdigest);
724 const char *nickname)
733 if (nn_char ==
'=') {
737 if (nn_char ==
'~') {
740 if (strcasecmp(nn_buf, nickname))
754 if (hexdigest[0]==
'$')
819 return ei ? &ei->cache_info : NULL;
835 int with_annotations)
837 const char *r = NULL;
840 if (with_annotations)
848 if (store && store->
mmap) {
852 log_err(
LD_DIR,
"We couldn't read a descriptor that is supposedly "
853 "mmaped in our cache. Is another process running in our data "
854 "directory? Exiting.");
863 if (!with_annotations) {
865 char *cp = tor_strndup(r, 64);
866 log_err(
LD_DIR,
"descriptor at %p begins with unexpected string %s. "
867 "Is another process running in our data directory? Exiting.",
965#define signed_descriptor_free(val) \
966 FREE_AND_NULL(signed_descriptor_t, signed_descriptor_free_, (val))
990 memset(sd, 0,
sizeof(*sd));
1018 routerinfo_free(ri);
1040 routerinfo_free(r));
1042 signed_descriptor_free(sd));
1048 log_warn(
LD_FS,
"Failed to munmap routerlist->desc_store.mmap");
1054 log_warn(
LD_FS,
"Failed to munmap routerlist->extrainfo_store.mmap");
1065 uint64_t livedescs = 0;
1066 uint64_t olddescs = 0;
1075 "In %d live descriptors: %"PRIu64
" bytes. "
1076 "In %d old descriptors: %"PRIu64
" bytes.",
1134 signed_descriptor_free(sd_old);
1144#ifdef DEBUG_ROUTERLIST
1156 const char *compatibility_error_msg;
1171 r = ROUTER_NOT_IN_CONSENSUS;
1177 static ratelim_t no_sd_ratelim = RATELIM_INIT(1800);
1184 "No entry found in extrainfo map.");
1189 static ratelim_t digest_mismatch_ratelim = RATELIM_INIT(1800);
1194 "Mismatch in digest in extrainfo map.");
1198 &compatibility_error_msg)) {
1200 r = (ri->cache_info.extrainfo_is_bogus) ?
1201 ROUTER_BAD_EI : ROUTER_NOT_IN_CONSENSUS;
1207 "router info incompatible with extra info (ri id: %s, ei id %s, "
1208 "reason: %s)", d1, d2, compatibility_error_msg);
1219 r = ROUTER_ADDED_SUCCESSFULLY;
1223 extrainfo_free(ei_tmp);
1227 if (r != ROUTER_ADDED_SUCCESSFULLY)
1230#ifdef DEBUG_ROUTERLIST
1236#define should_cache_old_descriptors() \
1237 directory_caches_dir_info(get_options())
1251 if (should_cache_old_descriptors() &&
1262 routerinfo_free(ri);
1264#ifdef DEBUG_ROUTERLIST
1293 if (idx < smartlist_len(rl->
routers)) {
1302 if (make_old && should_cache_old_descriptors() &&
1322 extrainfo_free(ei_tmp);
1326 routerinfo_free(ri);
1328#ifdef DEBUG_ROUTERLIST
1370 extrainfo_free(ei_tmp);
1375 signed_descriptor_free(sd);
1376#ifdef DEBUG_ROUTERLIST
1394 int same_descriptors;
1417 smartlist_set(rl->
routers, idx, ri_new);
1423 log_warn(
LD_BUG,
"Appending entry from routerlist_replace.");
1437 &(ri_new->cache_info));
1441 &ri_new->cache_info);
1448 if (should_cache_old_descriptors() &&
1450 !same_descriptors) {
1461 if (!same_descriptors) {
1473 extrainfo_free(ei_tmp);
1483 routerinfo_free(ri_old);
1485#ifdef DEBUG_ROUTERLIST
1523 routerlist_free(rl);
1530 authcert_free_all();
1577 int from_cache,
int from_fetch)
1579 const char *id_digest;
1582 int authdir_believes_valid = 0;
1586 int in_consensus = 0;
1599 routerinfo_free(router);
1600 *msg =
"Some certs on this router are expired.";
1601 return ROUTER_CERTS_EXPIRED;
1613 const int was_bridge = old_router &&
1619 log_info(
LD_DIR,
"Replacing non-bridge descriptor with bridge "
1620 "descriptor for router %s",
1631 "Dropping descriptor that we already have for router %s",
1633 *msg =
"Router descriptor was not new.";
1634 routerinfo_free(router);
1635 return ROUTER_IS_ALREADY_KNOWN;
1641 !from_cache && !from_fetch,
1642 &authdir_believes_valid)) {
1644 routerinfo_free(router);
1645 return ROUTER_AUTHDIR_REJECTS;
1647 }
else if (from_fetch) {
1656 "Received a no-longer-recognized descriptor for router %s",
1658 *msg =
"Router descriptor is not referenced by any network-status.";
1661 if (!from_cache && should_cache_old_descriptors())
1665 return ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS;
1672 consensus, id_digest);
1681 consensus && !in_consensus && !authdir) {
1684 if (!from_cache && should_cache_old_descriptors())
1688 *msg =
"Skipping router descriptor: not in consensus.";
1689 return ROUTER_NOT_IN_CONSENSUS;
1699 log_info(
LD_DIR,
"Dropping bridge descriptor for %s because we have "
1700 "no bridge configured at that address.",
1702 *msg =
"Router descriptor was not a configured bridge.";
1703 routerinfo_free(router);
1704 return ROUTER_WAS_NOT_WANTED;
1709 if (!in_consensus && (router->cache_info.
published_on <=
1712 log_debug(
LD_DIR,
"Not-new descriptor for router %s",
1715 if (!from_cache && should_cache_old_descriptors())
1719 *msg =
"Router descriptor was not new.";
1720 return ROUTER_IS_ALREADY_KNOWN;
1723 log_debug(
LD_DIR,
"Replacing entry for router %s",
1730 *msg = authdir_believes_valid ?
"Valid server updated" :
1731 (
"Invalid server updated. (This dirserver is marking your "
1732 "server as unapproved.)");
1733 return ROUTER_ADDED_SUCCESSFULLY;
1737 if (!in_consensus && from_cache &&
1739 *msg =
"Router descriptor was really old.";
1740 routerinfo_free(router);
1741 return ROUTER_WAS_TOO_OLD;
1751 return ROUTER_ADDED_SUCCESSFULLY;
1760 int from_cache,
int from_fetch)
1764 if (msg) *msg = NULL;
1804 return d1->duration - d2->duration;
1817 time_t cutoff,
int lo,
int hi,
1818 digestset_t *retain)
1821 unsigned n_extra, n_rmv = 0;
1823 uint8_t *rmv, *must_keep;
1830 for (i = lo+1; i <= hi; ++i) {
1844 rmv = tor_calloc(n,
sizeof(uint8_t));
1845 must_keep = tor_calloc(n,
sizeof(uint8_t));
1848 for (i = lo; i <= hi; ++i) {
1851 lifespans[i-lo].idx = i;
1855 must_keep[i-lo] = 1;
1858 r_next = smartlist_get(lst, i+1);
1863 lifespans[i-lo].duration = INT_MAX;
1865 if (!must_keep[i-lo] && r->
published_on < cutoff && n_rmv < n_extra) {
1867 lifespans[i-lo].old = 1;
1872 if (n_rmv < n_extra) {
1879 for (i = 0; i < n && n_rmv < n_extra; ++i) {
1880 if (!must_keep[lifespans[i].idx-lo] && !lifespans[i].old) {
1881 rmv[lifespans[i].idx-lo] = 1;
1891 }
while (--i >= lo);
1905 const char *cur_id = NULL;
1906 time_t now = time(NULL);
1910 digestset_t *retain;
1952 "Forgetting obsolete (too old) routerinfo for router %s",
1976 log_info(
LD_DIR,
"We have %d live routers and %d old router descriptors.",
2008 cutoff, i+1, hi, retain);
2018 digestset_free(retain);
2027routerlist_drop_bridge_descriptors(
void)
2039 "Dropping existing bridge descriptor for %s",
2059 if (ri->needs_retest_if_added) {
2060 ri->needs_retest_if_added = 0;
2063 } SMARTLIST_FOREACH_END(ri);
2090 "@source controller\n"
2094 annotation_buf, NULL))) {
2095 log_warn(
LD_DIR,
"Error parsing router descriptor; dropping.");
2096 *msg =
"Couldn't parse router descriptor.";
2101 log_warn(
LD_DIR,
"Router's identity key matches mine; dropping.");
2102 *msg =
"Router's identity key matches mine.";
2103 routerinfo_free(ri);
2108 ri->cache_info.do_not_cache = 1;
2118 if (r == ROUTER_AUTHDIR_REJECTS)
2119 log_warn(
LD_DIR,
"Couldn't add router to list: %s Dropping.", *msg);
2120 smartlist_free(lst);
2124 smartlist_free(lst);
2125 log_debug(
LD_DIR,
"Added router to list");
2149 int descriptor_digests,
2150 const char *prepend_annotations)
2157 int any_changed = 0;
2161 allow_annotations, prepend_annotations,
2166 log_info(
LD_DIR,
"%d elements to add", smartlist_len(routers));
2171 if (requested_fingerprints) {
2173 ri->cache_info.signed_descriptor_digest :
2174 ri->cache_info.identity_digest,
2182 "We received a router descriptor with a fingerprint (%s) "
2183 "that we never requested. (We asked for: %s.) Dropping.",
2186 routerinfo_free(ri);
2191 memcpy(d, ri->cache_info.signed_descriptor_digest,
DIGEST_LEN);
2202 log_info(
LD_GENERAL,
"Marking router %s as never downloadable",
2207 } SMARTLIST_FOREACH_END(ri);
2212 if (requested_fingerprints && descriptor_digests) {
2222 log_info(
LD_GENERAL,
"Marking router with descriptor %s as unparseable, "
2223 "and therefore undownloadable", fp);
2226 } SMARTLIST_FOREACH_END(bad_digest);
2228 smartlist_free(invalid_digests);
2235 smartlist_free(routers);
2236 smartlist_free(changed);
2248 int descriptor_digests)
2256 NULL, invalid_digests);
2258 log_info(
LD_DIR,
"%d elements to add", smartlist_len(extrainfo_list));
2262 memcpy(d, ei->cache_info.signed_descriptor_digest,
DIGEST_LEN);
2268 ei->cache_info.signed_descriptor_digest :
2269 ei->cache_info.identity_digest,
2279 log_info(
LD_GENERAL,
"Marking extrainfo with descriptor %s as "
2280 "unparseable, and therefore undownloadable",
2285 } SMARTLIST_FOREACH_END(ei);
2291 if (requested_fingerprints) {
2301 log_info(
LD_GENERAL,
"Marking extrainfo with descriptor %s as "
2302 "unparseable, and therefore undownloadable", fp);
2305 } SMARTLIST_FOREACH_END(bad_digest);
2307 smartlist_free(invalid_digests);
2312 smartlist_free(extrainfo_list);
2352 "In routerlist_retry_directory_downloads()");
2375 int purpose,
const char *prefix)
2377 const size_t p_len = strlen(prefix);
2380 int flags = DSR_HEX;
2382 flags = DSR_DIGEST256|DSR_BASE64;
2388 conn->purpose == purpose &&
2389 !conn->marked_for_close) {
2395 } SMARTLIST_FOREACH_END(conn);
2400 digestmap_set(result, d, (
void*)1);
2403 }
else if (result256) {
2406 digest256map_set(result256, d, (
void*)1);
2410 smartlist_free(tmp);
2441 int lo,
int hi,
int pds_flags))
2443 char *resource, *cp;
2444 int digest_len, enc_digest_len;
2465 if (hi > smartlist_len(digests))
2466 hi = smartlist_len(digests);
2473 for (; lo < hi; ++lo) {
2474 cp = tor_malloc(enc_digest_len);
2478 base16_encode(cp, enc_digest_len, smartlist_get(digests, lo),
2488 smartlist_free(tmp);
2497 directory_request_free(req);
2500 pds_flags, DL_WANT_ANY_DIRSERVER);
2528 if (dirclient_must_use_begindir(options)) {
2537#define MIN_DL_PER_REQUEST 32
2540#define MIN_REQUESTS 3
2543#define MAX_DL_TO_DELAY 16
2557 const char *descname;
2559 int n_downloadable = smartlist_len(downloadable);
2561 int i, n_per_request, max_dl_per_req;
2562 const char *req_plural =
"", *rtr_plural =
"";
2566 descname = fetch_microdesc ?
"microdesc" :
"routerdesc";
2568 if (!n_downloadable)
2574 "There are enough downloadable %ss to launch requests.",
2578 "We are only missing %d %ss, but we'll fetch anyway, since "
2579 "we don't yet have enough directory info.",
2580 n_downloadable, descname);
2590 "There are not many downloadable %ss, but we've "
2591 "been waiting long enough (%d seconds). Downloading.",
2596 "There are not many downloadable %ss, but we haven't "
2597 "tried downloading descriptors recently. Downloading.",
2614 pds_flags |= fetch_microdesc ?
2619 n_per_request = CEIL_DIV(n_downloadable,
MIN_REQUESTS);
2622 if (n_per_request > max_dl_per_req)
2623 n_per_request = max_dl_per_req;
2629 if (n_downloadable > n_per_request)
2630 req_plural = rtr_plural =
"s";
2631 else if (n_downloadable > 1)
2635 "Launching %d request%s for %d %s%s, %d at a time",
2636 CEIL_DIV(n_downloadable, n_per_request), req_plural,
2637 n_downloadable, descname, rtr_plural, n_per_request);
2639 for (i=0; i < n_downloadable; i += n_per_request) {
2641 downloadable, i, i+n_per_request,
2654 digestmap_t *map = NULL;
2659 int n_delayed=0, n_have=0, n_would_reject=0, n_wouldnt_use=0,
2660 n_inprogress=0, n_in_oldrouters=0;
2682 log_warn(
LD_DIR,
"couldn't lookup source from vote?");
2686 map = digestmap_new();
2731 if (is_vote && source) {
2733 const char *old_digest =
"none";
2740 old_digest = old_digest_buf;
2742 log_info(
LD_DIR,
"Learned about %s (%s vs %s) from %s's vote (%s)",
2746 source->
nickname, oldrouter ?
"known" :
"unknown");
2749 } SMARTLIST_FOREACH_END(rsp);
2751 if (!authdir_mode_v3(options)
2752 && smartlist_len(no_longer_old)) {
2754 log_info(
LD_DIR,
"%d router descriptors listed in consensus are "
2755 "currently in old_routers; making them current.",
2756 smartlist_len(no_longer_old));
2760 time_t tmp_cert_expiration_time;
2763 log_warn(
LD_BUG,
"Failed to re-parse a router.");
2771 log_warn(
LD_DIR,
"Couldn't add re-parsed router: %s. This isn't "
2772 "usually a big deal, but you should make sure that your "
2773 "clock and timezone are set correctly.",
2775 if (r == ROUTER_CERTS_EXPIRED) {
2776 char time_cons[ISO_TIME_LEN+1];
2777 char time_cert_expires[ISO_TIME_LEN+1];
2780 log_warn(
LD_DIR,
" (I'm looking at a consensus from %s; This "
2781 "router's certificates began expiring at %s.)",
2782 time_cons, time_cert_expires);
2785 } SMARTLIST_FOREACH_END(sd);
2790 "%d router descriptors downloadable. %d delayed; %d present "
2791 "(%d of those were in old_routers); %d would_reject; "
2792 "%d wouldnt_use; %d in progress.",
2793 smartlist_len(downloadable), n_delayed, n_have, n_in_oldrouters,
2794 n_would_reject, n_wouldnt_use, n_inprogress);
2797 downloadable, source, now);
2799 digestmap_free(map, NULL);
2801 smartlist_free(downloadable);
2802 smartlist_free(no_longer_old);
2826 digestmap_t *pending;
2827 int old_routers, i, max_dl_per_req;
2828 int n_no_ei = 0, n_pending = 0, n_have = 0, n_delay = 0, n_bogus[2] = {0,0};
2836 pending = digestmap_new();
2840 for (old_routers = 0; old_routers < 2; ++old_routers) {
2842 for (i = 0; i < smartlist_len(lst); ++i) {
2846 sd = smartlist_get(lst, i);
2848 sd = &((
routerinfo_t*)smartlist_get(lst, i))->cache_info;
2849 if (sd->is_extrainfo)
2853 if (sd->extrainfo_is_bogus)
2868 if (digestmap_get(pending, d)) {
2883 log_info(
LD_DIR,
"Found an entry in %s with mismatched "
2884 "router_get_by_extrainfo_digest() value. This has ID %s "
2885 "but the entry in the map has ID %s. This has EI digest "
2886 "%s and the entry in the map has EI digest %s.",
2887 old_routers?
"old_routers":
"routers",
2894 log_info(
LD_DIR,
"Found an entry in %s with NULL "
2895 "router_get_by_extrainfo_digest() value. This has ID %s "
2896 "and EI digest %s.",
2897 old_routers?
"old_routers":
"routers",
2900 ++n_bogus[old_routers];
2906 digestmap_free(pending, NULL);
2908 log_info(
LD_DIR,
"Extrainfo download status: %d router with no ei, %d "
2909 "with present ei, %d delaying, %d pending, %d downloadable, %d "
2910 "bogus in routers, %d bogus in old_routers",
2911 n_no_ei, n_have, n_delay, n_pending, smartlist_len(wanted),
2912 n_bogus[0], n_bogus[1]);
2917 for (i = 0; i < smartlist_len(wanted); i += max_dl_per_req) {
2919 wanted, i, i+max_dl_per_req,
2923 smartlist_free(wanted);
2935 "In router_reset_descriptor_download_failures()");
2945 download_status_reset(&ri->cache_info.ei_dl_status);
2949 download_status_reset(&sd->ei_dl_status);
2955#define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE (2*60*60)
2958#define ROUTER_ALLOW_UPTIME_DRIFT (6*60*60)
2984 time_t r1pub, r2pub;
2985 time_t time_difference;
2998 r1->ipv4_orport != r2->ipv4_orport ||
3000 r1->ipv6_orport != r2->ipv6_orport ||
3001 r1->ipv4_dirport != r2->ipv4_dirport ||
3022 for (i=0; i < n; ++i) {
3048 time_difference = r2->
uptime - (r1->
uptime + (r2pub - r1pub));
3049 if (time_difference < 0)
3050 time_difference = - time_difference;
3052 time_difference > r1->
uptime * .05 &&
3053 time_difference > r2->
uptime * .05)
3082 int digest_matches, digest256_matches, r=1;
3088 if (msg) *msg =
"Extrainfo signature was bad, or signed with wrong key.";
3098 digest256_matches |=
3106 if (msg) *msg =
"Extrainfo nickname or identity did not match routerinfo";
3112 if (msg) *msg =
"Extrainfo signing key cert didn't match routerinfo";
3117 char signed_digest[128];
3119 signed_digest,
sizeof(signed_digest),
3125 if (msg) *msg =
"Extrainfo signature bad, or signed with wrong key";
3129 ei->cache_info.send_unencrypted = sd->send_unencrypted;
3134 if (msg) *msg =
"Extrainfo published time did not match routerdesc";
3137 if (msg) *msg =
"Extrainfo published time did not match routerdesc";
3142 if (!digest256_matches && !digest_matches) {
3143 if (msg) *msg =
"Neither digest256 or digest matched "
3144 "digest from routerdesc";
3148 if (!digest256_matches) {
3149 if (msg) *msg =
"Extrainfo digest did not match digest256 from routerdesc";
3153 if (!digest_matches) {
3154 if (msg) *msg =
"Extrainfo digest did not match value from routerdesc";
3160 if (digest_matches) {
3164 sd->extrainfo_is_bogus = 1;
3173routerinfo_has_curve25519_onion_key(
const routerinfo_t *ri)
3197routerstatus_version_supports_extend2_cells(
const routerstatus_t *rs,
3198 int allow_unknown_versions)
3201 return allow_unknown_versions;
3205 return allow_unknown_versions;
3221 r2 = rimap_get(rl->
identity_map, r->cache_info.identity_digest);
3224 r->cache_info.signed_descriptor_digest);
3226 tor_assert(r->cache_info.routerlist_index == r_sl_idx);
3250 } SMARTLIST_FOREACH_END(r);
3256 tor_assert(sd->routerlist_index == sd_sl_idx);
3264 } SMARTLIST_FOREACH_END(sd);
3282 ei->cache_info.signed_descriptor_digest);
3304 static char *info=NULL;
3305 char *esc_contact, *esc_platform;
3314 tor_asprintf(&info,
"Contact %s, Platform %s", esc_contact, esc_platform);
3328 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)
digestset_t * digestset_new(int max_guess)
int digestset_probably_contains(const digestset_t *set, const char *digest)
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)
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)
directory_request_t * directory_request_new(uint8_t dir_purpose)
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
void router_reset_status_download_failures(void)
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)
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.
char * esc_for_log(const char *s)
const char * escaped(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.
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)
download_status_t * router_get_dl_status_by_descriptor_digest(const char *d)
networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor)
int client_would_use_router(const routerstatus_t *rs, time_t now)
networkstatus_t * networkstatus_get_latest_consensus(void)
const routerstatus_t * networkstatus_vote_find_entry(networkstatus_t *ns, const char *digest)
routerstatus_t * networkstatus_vote_find_mutable_entry(networkstatus_t *ns, const char *digest)
int should_delay_dir_fetches(const or_options_t *options, const char **msg_out)
const routerstatus_t * router_get_consensus_status_by_id(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)
node_t * nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out)
bool node_supports_conflux(const node_t *node)
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)
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)
int router_is_me(const routerinfo_t *router)
const routerinfo_t * router_get_my_routerinfo(void)
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)
static desc_store_t * desc_get_store(routerlist_t *rl, const signed_descriptor_t *sd)
void routerinfo_free_(routerinfo_t *router)
void routerlist_free_all(void)
const char * esc_router_info(const routerinfo_t *router)
static void routerlist_remove_old_cached_routers_with_id(time_t now, time_t cutoff, int lo, int hi, digestset_t *retain)
const char * signed_descriptor_get_body(const signed_descriptor_t *desc)
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)
routerlist_t * router_get_routerlist(void)
signed_descriptor_t * router_get_by_extrainfo_digest(const char *digest)
signed_descriptor_t * router_get_by_descriptor_digest(const char *digest)
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)
const routerinfo_t * router_get_by_id_digest(const char *digest)
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)
const char * signed_descriptor_get_annotations(const signed_descriptor_t *desc)
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 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)
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)
static int router_tap_onion_keys_eq(const routerinfo_t *r1, const routerinfo_t *r2)
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)
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)
void update_extrainfo_downloads(time_t now)
signed_descriptor_t * extrainfo_get_by_descriptor_digest(const char *digest)
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)
static int compare_routerinfo_by_id_digest_(const void **a, const void **b)
routerinfo_t * router_get_mutable_by_digest(const char *digest)
static routerinfo_t * routerlist_reparse_old(routerlist_t *rl, signed_descriptor_t *sd)
static int signed_desc_append_to_journal(signed_descriptor_t *desc, desc_store_t *store)
#define ROUTER_MAX_COSMETIC_TIME_DIFFERENCE
const routerinfo_t * routerlist_find_my_routerinfo(void)
static signed_descriptor_t * signed_descriptor_from_routerinfo(routerinfo_t *ri)
void update_all_descriptor_downloads(time_t now)
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)
int smartlist_contains_string(const smartlist_t *sl, const char *element)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
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
size_t tap_onion_pkey_len
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