summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2018-02-08 14:35:22 -0500
committerDavid Goulet <dgoulet@torproject.org>2018-02-08 16:56:05 -0500
commita445327b80478c72093d8f1b0e205a279318f651 (patch)
treef75d99e7a05bc54cea6a20a8b5137563afe13ef7 /src/or
parent6892d3292121d02900ac9968e832353ecacca4ad (diff)
downloadtor-a445327b80478c72093d8f1b0e205a279318f651.tar.gz
tor-a445327b80478c72093d8f1b0e205a279318f651.zip
test: Add unit tests for addressset.c
This also adds one that tests the integration with the nodelist. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or')
-rw-r--r--src/or/nodelist.c14
-rw-r--r--src/or/nodelist.h2
2 files changed, 15 insertions, 1 deletions
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index c2080db12c..5a02648c5c 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -275,6 +275,17 @@ nodelist_add_microdesc(microdesc_t *md)
return node;
}
+/* Default value. */
+#define ESTIMATED_ADDRESS_PER_NODE 2
+
+/* Return the estimated number of address per node_t. This is used for the
+ * size of the bloom filter in the nodelist (node_addrs). */
+MOCK_IMPL(int,
+get_estimated_address_per_node, (void))
+{
+ return ESTIMATED_ADDRESS_PER_NODE;
+}
+
/** Tell the nodelist that the current usable consensus is <b>ns</b>.
* This makes the nodelist change all of the routerstatus entries for
* the nodes, drop nodes that no longer have enough info to get used,
@@ -294,7 +305,8 @@ nodelist_set_consensus(networkstatus_t *ns)
node->rs = NULL);
/* Conservatively estimate that every node will have 2 addresses. */
- const int estimated_addresses = smartlist_len(ns->routerstatus_list) * 2;
+ const int estimated_addresses = smartlist_len(ns->routerstatus_list) *
+ get_estimated_address_per_node();
address_set_free(the_nodelist->node_addrs);
the_nodelist->node_addrs = address_set_new(estimated_addresses);
diff --git a/src/or/nodelist.h b/src/or/nodelist.h
index 355057f398..098f1d1555 100644
--- a/src/or/nodelist.h
+++ b/src/or/nodelist.h
@@ -125,5 +125,7 @@ void router_dir_info_changed(void);
const char *get_dir_info_status_string(void);
int count_loading_descriptors_progress(void);
+MOCK_DECL(int, get_estimated_address_per_node, (void));
+
#endif