diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-07-17 20:00:19 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-07-19 17:51:15 -0400 |
commit | 6208106c18c696756fe2be8f941992e31aa66a8d (patch) | |
tree | d3e964d00954bc8349fea9b0dbb4f6f21e810b0e /src/or/nodelist.c | |
parent | dee4f068ee8be3d424aaa300168564f4abd18a36 (diff) | |
download | tor-6208106c18c696756fe2be8f941992e31aa66a8d.tar.gz tor-6208106c18c696756fe2be8f941992e31aa66a8d.zip |
Try to re-approximate the older semantics of nodelist_add_routerinfo
Diffstat (limited to 'src/or/nodelist.c')
-rw-r--r-- | src/or/nodelist.c | 75 |
1 files changed, 30 insertions, 45 deletions
diff --git a/src/or/nodelist.c b/src/or/nodelist.c index bbbb9ebc3a..6ce8dcf2c7 100644 --- a/src/or/nodelist.c +++ b/src/or/nodelist.c @@ -115,63 +115,48 @@ node_get_or_create(const char *identity_digest) return node; } -/** Replace <b>old</b> router with <b>new</b> in nodelist. If - * <b>old</b> and <b>new</b> in fact are the same relays (having the - * same identity_digest) the node_t of <b>old</b> is used for - * <b>new</b>. Otherwise the node_t of <b>old</b> is dropped and - * <b>new</b> gets a new one (which might be a recycled node_t in - * case we already have one matching its identity). - */ -node_t * -nodelist_replace_routerinfo(routerinfo_t *old, routerinfo_t *new) -{ - node_t *node = NULL; - tor_assert(old); - tor_assert(new); - - if (tor_memeq(old->cache_info.identity_digest, - new->cache_info.identity_digest, DIGEST_LEN)) { - /* NEW == OLD, reuse node_t. */ - node = node_get_mutable_by_id(old->cache_info.identity_digest); - if (node) { - tor_assert(node->ri == old); - if (!routers_have_same_or_addrs(old, new)) { - /* These mustn't carry over when the address and orport - change. */ - node->last_reachable = node->last_reachable6 = 0; - node->testing_since = node->testing_since6 = 0; - } - } - } else { - /* NEW != OLD, get a new node_t. */ - nodelist_remove_routerinfo(old); - } - node = nodelist_add_routerinfo(node, new); - - return node; +/** Called when a node's address changes. */ +static void +node_addrs_changed(node_t *node) +{ + node->last_reachable = node->last_reachable6 = 0; + node->testing_since = node->testing_since6 = 0; + node->country = -1; } - -/** Add <b>ri</b> to the nodelist. If <b>node_in</b> is not NULL, use - that node rather than creating a new. */ +/** Add <b>ri</b> to an appropriate node in the nodelist. If we replace an + * old routerinfo, and <b>ri_old_out</b> is not NULL, set *<b>ri_old_out</b> + * to the previous routerinfo. + */ node_t * -nodelist_add_routerinfo(node_t *node_in, routerinfo_t *ri) +nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out) { - node_t *node = NULL; + node_t *node; + const char *id_digest; + int had_router = 0; + tor_assert(ri); - if (node_in) { - node = node_in; + init_nodelist(); + id_digest = ri->cache_info.identity_digest; + node = node_get_or_create(id_digest); + + if (node->ri) { + if (!routers_have_same_or_addrs(node->ri, ri)) { + node_addrs_changed(node); + } + had_router = 1; + if (ri_old_out) + *ri_old_out = node->ri; } else { - tor_assert(ri); - init_nodelist(); - node = node_get_or_create(ri->cache_info.identity_digest); + if (ri_old_out) + *ri_old_out = NULL; } node->ri = ri; if (node->country == -1) node_set_country(node); - if (authdir_mode(get_options())) { + if (authdir_mode(get_options()) && !had_router) { const char *discard=NULL; uint32_t status = dirserv_router_get_status(ri, &discard); dirserv_set_node_flags_from_authoritative_status(node, status); |