diff options
author | Linus Nordberg <linus@nordberg.se> | 2012-03-27 15:00:34 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2012-03-29 22:01:06 +0200 |
commit | 20eb38a588313bba2fd35c32dc0e1c63ef4b8497 (patch) | |
tree | a6146a5e5f85e5b5a05c4bb742eeb6f19042c1e7 /src/or/dirserv.c | |
parent | f348daa6fb58295d876495ba875b826e87917ec9 (diff) | |
download | tor-20eb38a588313bba2fd35c32dc0e1c63ef4b8497.tar.gz tor-20eb38a588313bba2fd35c32dc0e1c63ef4b8497.zip |
Refactor dirserv_orconn_tls_done().
Look up the router using the digest instead of looping over all routers.
Diffstat (limited to 'src/or/dirserv.c')
-rw-r--r-- | src/or/dirserv.c | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index a7bbe983c0..01a083369e 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -3264,8 +3264,8 @@ dirserv_get_routerdescs(smartlist_t *descs_out, const char *key, * router listening at <b>address</b>:<b>or_port</b>, and has yielded * a certificate with digest <b>digest_rcvd</b>. * - * Also, if as_advertised is 1, then inform the reachability checker - * that we could get to this guy. + * If as_advertised is 1, then inform the reachability checker that we + * could get to this guy. */ void dirserv_orconn_tls_done(const char *address, @@ -3273,37 +3273,40 @@ dirserv_orconn_tls_done(const char *address, const char *digest_rcvd, int as_advertised) { - routerlist_t *rl = router_get_routerlist(); + routerinfo_t *ri = NULL; time_t now = time(NULL); - int bridge_auth = authdir_mode_bridge(get_options()); tor_assert(address); tor_assert(digest_rcvd); - /* XXX023 Doing a loop like this is stupid. We should just look up the - * router by digest_rcvd, and see if address, orport, and as_advertised - * match up. -NM */ - SMARTLIST_FOREACH_BEGIN(rl->routers, routerinfo_t *, ri) { - if (!strcasecmp(address, ri->address) && or_port == ri->or_port && - as_advertised && - fast_memeq(ri->cache_info.identity_digest, digest_rcvd, DIGEST_LEN)) { - /* correct digest. mark this router reachable! */ - if (!bridge_auth || ri->purpose == ROUTER_PURPOSE_BRIDGE) { - tor_addr_t addr, *addrp=NULL; - log_info(LD_DIRSERV, "Found router %s to be reachable at %s:%d. Yay.", - router_describe(ri), - address, ri->or_port); - if (tor_addr_parse(&addr, ri->address) != -1) - addrp = &addr; - else - log_warn(LD_BUG, "Couldn't parse IP address \"%s\"", ri->address); - rep_hist_note_router_reachable(digest_rcvd, addrp, or_port, now); - ri->last_reachable = now; - } - } - } SMARTLIST_FOREACH_END(ri); /* FFFF Maybe we should reinstate the code that dumps routers with the same * addr/port but with nonmatching keys, but instead of dumping, we should * skip testing. */ + + if (!as_advertised) + return; + + ri = router_get_mutable_by_digest(digest_rcvd); + if (ri == NULL) + return; + + if (!strcasecmp(address, ri->address) && or_port == ri->or_port) { + /* Found the right router. */ + if (!authdir_mode_bridge(get_options()) || + ri->purpose == ROUTER_PURPOSE_BRIDGE) { + /* This is a bridge or we're not a bridge authorititative -- + mark it as reachable. */ + tor_addr_t addr, *addrp=NULL; + log_info(LD_DIRSERV, "Found router %s to be reachable at %s:%d. Yay.", + router_describe(ri), + address, ri->or_port); + if (tor_addr_parse(&addr, ri->address) != -1) + addrp = &addr; + else + log_warn(LD_BUG, "Couldn't parse IP address \"%s\"", ri->address); + rep_hist_note_router_reachable(digest_rcvd, addrp, or_port, now); + ri->last_reachable = now; + } + } } /** Called when we, as an authority, receive a new router descriptor either as |