aboutsummaryrefslogtreecommitdiff
path: root/src/or/routerlist.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-07-11 11:21:47 -0400
committerNick Mathewson <nickm@torproject.org>2011-07-11 11:21:47 -0400
commite158f8de4b487450adeb89de204898263f6a87a5 (patch)
tree1fef7d1c700208ead34667200f138088635481b8 /src/or/routerlist.c
parent60832766ac19e8f027455d23254e376042c21ef2 (diff)
downloadtor-e158f8de4b487450adeb89de204898263f6a87a5.tar.gz
tor-e158f8de4b487450adeb89de204898263f6a87a5.zip
Rename and tweak nodelist_add_node_family() to add node
It's very easy for nodelist_add_node_family(sl,node) to accidentally add 'node', and kind of hard to make sure that it omits it. Instead of taking pains to leave 'node' out, let's instead make sure that we always include it. I also rename the function to nodelist_add_node_and_family, and audit its users so that they don't add the node itself any longer, since the function will take care of that for them. Resolves bug 2616, which was not actually a bug.
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r--src/or/routerlist.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 5aaa4a9614..c0a233ceed 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1357,12 +1357,17 @@ addrs_in_same_network_family(const tor_addr_t *a1,
return 0 == tor_addr_compare_masked(a1, a2, 16, CMP_SEMANTIC);
}
-/** Add all the family of <b>router</b> to the smartlist <b>sl</b>.
- * This is used to make sure we don't pick siblings in a single path,
- * or pick more than one relay from a family for our entry guard list.
+/**
+ * Add all the family of <b>node</b>, including <b>node</b> itself, to
+ * the smartlist <b>sl</b>.
+ *
+ * This is used to make sure we don't pick siblings in a single path, or
+ * pick more than one relay from a family for our entry guard list.
+ * Note that a node may be added to <b>sl</b> more than once if it is
+ * part of <b>node</b>'s family for more than one reason.
*/
void
-nodelist_add_node_family(smartlist_t *sl, const node_t *node)
+nodelist_add_node_and_family(smartlist_t *sl, const node_t *node)
{
/* XXXX MOVE */
const smartlist_t *all_nodes = nodelist_get_list();
@@ -1373,6 +1378,13 @@ nodelist_add_node_family(smartlist_t *sl, const node_t *node)
declared_family = node_get_declared_family(node);
+ /* Let's make sure that we have the node itself, if it's a real node. */
+ {
+ const node_t *real_node = node_get_by_id(node->identity);
+ if (real_node)
+ smartlist_add(sl, (node_t*)real_node);
+ }
+
/* First, add any nodes with similar network addresses. */
if (options->EnforceDistinctSubnets) {
tor_addr_t node_addr;
@@ -1417,13 +1429,14 @@ nodelist_add_node_family(smartlist_t *sl, const node_t *node)
}
}
-/** Given a <b>router</b>, add every node_t in its family to <b>sl</b>.
+/** Given a <b>router</b>, add every node_t in its family (including the
+ * node itself</b>) to <b>sl</b>.
*
* Note the type mismatch: This function takes a routerinfo, but adds nodes
* to the smartlist!
*/
static void
-routerlist_add_nodes_in_family(smartlist_t *sl, const routerinfo_t *router)
+routerlist_add_node_and_family(smartlist_t *sl, const routerinfo_t *router)
{
/* XXXX MOVE ? */
node_t fake_node;
@@ -1434,7 +1447,7 @@ routerlist_add_nodes_in_family(smartlist_t *sl, const routerinfo_t *router)
memcpy(fake_node.identity, router->cache_info.identity_digest, DIGEST_LEN);
node = &fake_node;
}
- nodelist_add_node_family(sl, node);
+ nodelist_add_node_and_family(sl, node);
}
/** Return true iff <b>node</b> is named by some nickname in <b>lst</b>. */
@@ -2171,12 +2184,8 @@ router_choose_random_node(smartlist_t *excludedsmartlist,
});
}
- if ((r = routerlist_find_my_routerinfo())) {
- const node_t *me = node_get_by_id(r->cache_info.identity_digest);
- if (me)
- smartlist_add(excludednodes, (void *)me);
- routerlist_add_nodes_in_family(excludednodes, r);
- }
+ if ((r = routerlist_find_my_routerinfo()))
+ routerlist_add_node_and_family(excludednodes, r);
router_add_running_nodes_to_smartlist(sl, allow_invalid,
need_uptime, need_capacity,