diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-11-08 14:21:32 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-05-05 20:54:12 -0400 |
commit | 4cc348e896f74a4e02ef15a77d22fc636b08afae (patch) | |
tree | b83bf38177b446230ee78363155a804bb4ede10f /src/or/microdesc.c | |
parent | 3df22887a3028318dc34a45984a8a195dfc0c026 (diff) | |
download | tor-4cc348e896f74a4e02ef15a77d22fc636b08afae.tar.gz tor-4cc348e896f74a4e02ef15a77d22fc636b08afae.zip |
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.
Diffstat (limited to 'src/or/microdesc.c')
-rw-r--r-- | src/or/microdesc.c | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/src/or/microdesc.c b/src/or/microdesc.c index 6209bbf33e..0e8aa836f1 100644 --- a/src/or/microdesc.c +++ b/src/or/microdesc.c @@ -9,6 +9,7 @@ #include "networkstatus.h" #include "nodelist.h" #include "policies.h" +#include "router.h" #include "routerlist.h" #include "routerparse.h" @@ -251,6 +252,9 @@ microdescs_add_list_to_cache(microdesc_cache_t *cache, SMARTLIST_FOREACH(added, microdesc_t *, md, nodelist_add_microdesc(md)); } + if (smartlist_len(added)) + router_dir_info_changed(); + return added; } @@ -570,6 +574,8 @@ microdesc_list_missing_digest256(networkstatus_t *ns, microdesc_cache_t *cache, continue; if (skip && digestmap_get(skip, rs->descriptor_digest)) continue; + if (tor_mem_is_zero(rs->descriptor_digest, DIGEST256_LEN)) + continue; /* This indicates a bug somewhere XXXX023*/ /* XXXX Also skip if we're a noncache and wouldn't use this router. * XXXX NM Microdesc */ @@ -602,11 +608,8 @@ update_microdesc_downloads(time_t now) if (!consensus) return; - if (!directory_caches_dir_info(options)) { - /* Right now, only caches fetch microdescriptors. - * XXXX NM Microdescs */ + if (!we_fetch_microdescriptors(options)) return; - } pending = digestmap_new(); list_pending_microdesc_downloads(pending); @@ -647,3 +650,45 @@ update_microdescs_from_networkstatus(time_t now) } SMARTLIST_FOREACH_END(rs); } +/** Return true iff we should prefer to use microdescriptors rather than + * routerdescs for building circuits. */ +int +we_use_microdescriptors_for_circuits(or_options_t *options) +{ + int ret = options->UseMicrodescriptors; + if (ret == -1) { + /* UseMicrodescriptors is "auto"; we need to decide: */ + /* So we decide that we'll use microdescriptors iff we are not a server */ + ret = ! server_mode(options); + } + return ret; +} + +/** Return true iff we should try to download microdescriptors at all. */ +int +we_fetch_microdescriptors(or_options_t *options) +{ + if (directory_caches_dir_info(options)) + return 1; + return we_use_microdescriptors_for_circuits(options); +} + +/** Return true iff we should try to download router descriptors at all. */ +int +we_fetch_router_descriptors(or_options_t *options) +{ + if (directory_caches_dir_info(options)) + return 1; + return ! we_use_microdescriptors_for_circuits(options); +} + +/** Return the consensus flavor we actually want to use to build circuits. */ +int +usable_consensus_flavor(void) +{ + if (we_use_microdescriptors_for_circuits(get_options())) { + return FLAV_MICRODESC; + } else { + return FLAV_NS; + } +} |