diff options
author | Linus Nordberg <linus@nordberg.se> | 2012-03-27 15:00:34 +0200 |
---|---|---|
committer | Linus Nordberg <linus@torproject.org> | 2012-07-19 18:21:20 +0200 |
commit | 631ec5c4fe4d5535d91e8e1e3597fbaa687b8790 (patch) | |
tree | 050aa6d4a7ab18ed66617412bfb31aeb709aaaf0 /src/or/nodelist.c | |
parent | 24451e6f7d6813642cc3b092bf085fdbb4a9aefc (diff) | |
download | tor-631ec5c4fe4d5535d91e8e1e3597fbaa687b8790.tar.gz tor-631ec5c4fe4d5535d91e8e1e3597fbaa687b8790.zip |
Move last_reachable and testing_since from routerinfo_t to node_t.
Diffstat (limited to 'src/or/nodelist.c')
-rw-r--r-- | src/or/nodelist.c | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/src/or/nodelist.c b/src/or/nodelist.c index d17850888d..1e07c82e35 100644 --- a/src/or/nodelist.c +++ b/src/or/nodelist.c @@ -115,13 +115,58 @@ node_get_or_create(const char *identity_digest) return node; } -/** Add <b>ri</b> to the nodelist. */ +/** 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); + /* XXXX prop186 we may have more than one address. */ + if (!routers_have_same_or_addr(old, new)) { + /* These mustn't carry over when the address and orport + change. */ + node->last_reachable = 0; + node->testing_since = 0; + } + } + } else { + /* NEW != OLD, get a new node_t. */ + nodelist_remove_routerinfo(old); + } + node = nodelist_add_routerinfo(node, new); + + return node; +} + + +/** Add <b>ri</b> to the nodelist. If <b>node_in</b> is not NULL, use + that node rather than creating a new. */ node_t * -nodelist_add_routerinfo(routerinfo_t *ri) +nodelist_add_routerinfo(node_t *node_in, routerinfo_t *ri) { - node_t *node; - init_nodelist(); - node = node_get_or_create(ri->cache_info.identity_digest); + node_t *node = NULL; + + if (node_in) { + node = node_in; + } else { + tor_assert(ri); + init_nodelist(); + node = node_get_or_create(ri->cache_info.identity_digest); + } node->ri = ri; if (node->country == -1) |