From 4cc348e896f74a4e02ef15a77d22fc636b08afae Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 8 Nov 2010 14:21:32 -0500 Subject: Code to make clients fetch and use microdescriptors for circuit building To turn this on, set UseMicrodescriptors to "1" (or "auto" if you want it on-if-you're-a-client). It should go auto-by-default once 0.2.3.1-alpha is released. Because of our node logic, directory caches will never use microdescriptors when they have the right routerinfo available. --- src/or/routerlist.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'src/or/routerlist.c') diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 8bcfa05880..6f90a8baf3 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1127,6 +1127,9 @@ router_pick_directory_server_impl(dirinfo_type_t type, int flags) if ((type & EXTRAINFO_DIRINFO) && !router_supports_extrainfo(node->identity, 0)) continue; + if ((type & MICRODESC_DIRINFO) && !is_trusted && + !node->rs->version_supports_microdesc_cache) + continue; if (try_excluding && options->ExcludeNodes && routerset_contains_routerstatus(options->ExcludeNodes, status, country)) { @@ -2443,18 +2446,6 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed) #endif } -/** Try to find a routerinfo for digest. If we don't have one, - * return 1. If we do, ask tor_version_as_new_as() for the answer. - */ -int -router_digest_version_as_new_as(const char *digest, const char *cutoff) -{ - const routerinfo_t *router = router_get_by_id_digest(digest); - if (!router) - return 1; - return tor_version_as_new_as(router->platform, cutoff); -} - /** Return true iff digest is the digest of the identity key of a * trusted directory matching at least one bit of type. If type * is zero, any authority is okay. */ @@ -4726,6 +4717,8 @@ update_router_descriptor_downloads(time_t now) static time_t last_dummy_download = 0; if (should_delay_dir_fetches(options)) return; + if (!we_fetch_router_descriptors(options)) + return; if (directory_fetches_dir_info_early(options)) { update_router_descriptor_cache_downloads_v2(now); } @@ -4879,20 +4872,28 @@ count_usable_descriptors(int *num_present, int *num_usable, or_options_t *options, time_t now, routerset_t *in_set) { + const int md = (consensus->flavor == FLAV_MICRODESC); *num_present = 0, *num_usable=0; - SMARTLIST_FOREACH(consensus->routerstatus_list, routerstatus_t *, rs, - { + SMARTLIST_FOREACH_BEGIN(consensus->routerstatus_list, routerstatus_t *, rs) + { if (in_set && ! routerset_contains_routerstatus(in_set, rs, -1)) continue; if (client_would_use_router(rs, now, options)) { + const char * const digest = rs->descriptor_digest; + int present; ++*num_usable; /* the consensus says we want it. */ - if (router_get_by_descriptor_digest(rs->descriptor_digest)) { + if (md) + present = NULL != (microdesc_cache_lookup_by_digest256(NULL, digest)); + else + present = NULL != router_get_by_descriptor_digest(digest); + if (present) { /* we have the descriptor listed in the consensus. */ ++*num_present; } } - }); + } + SMARTLIST_FOREACH_END(rs); log_debug(LD_DIR, "%d usable, %d present.", *num_usable, *num_present); } @@ -4906,7 +4907,7 @@ count_loading_descriptors_progress(void) int num_present = 0, num_usable=0; time_t now = time(NULL); const networkstatus_t *consensus = - networkstatus_get_reasonably_live_consensus(now, FLAV_NS); + networkstatus_get_reasonably_live_consensus(now, usable_consensus_flavor()); double fraction; if (!consensus) @@ -4936,14 +4937,14 @@ update_router_have_minimum_dir_info(void) int res; or_options_t *options = get_options(); const networkstatus_t *consensus = - networkstatus_get_reasonably_live_consensus(now, FLAV_NS); + networkstatus_get_reasonably_live_consensus(now, usable_consensus_flavor()); if (!consensus) { if (!networkstatus_get_latest_consensus()) - strlcpy(dir_info_status, "We have no network-status consensus.", + strlcpy(dir_info_status, "We have no usable consensus.", sizeof(dir_info_status)); else - strlcpy(dir_info_status, "We have no recent network-status consensus.", + strlcpy(dir_info_status, "We have no recent usable consensus.", sizeof(dir_info_status)); res = 0; goto done; -- cgit v1.2.3-54-g00ecf