summaryrefslogtreecommitdiff
path: root/src/or/shared_random.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2016-05-13 13:42:33 -0400
committerDavid Goulet <dgoulet@torproject.org>2016-07-01 14:01:41 -0400
commitedea0441477cf7f1293ce848abf59b3f1033b28a (patch)
treebb51c26be081a4f1a4879c4a1b1f39047d87907f /src/or/shared_random.c
parent545b77e2f8fac6cf5909bb6b69b52d9cb4f8f397 (diff)
downloadtor-edea0441477cf7f1293ce848abf59b3f1033b28a.tar.gz
tor-edea0441477cf7f1293ce848abf59b3f1033b28a.zip
prop250: Sort smartlist before you get most frequent SRV.
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/shared_random.c')
-rw-r--r--src/or/shared_random.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/or/shared_random.c b/src/or/shared_random.c
index d409d109ac..c5a62a754a 100644
--- a/src/or/shared_random.c
+++ b/src/or/shared_random.c
@@ -779,6 +779,15 @@ smartlist_get_most_frequent_srv(const smartlist_t *sl, int *count_out)
return smartlist_get_most_frequent_(sl, compare_srvs_, count_out);
}
+/** Compare two SRVs. Used in smartlist sorting. */
+static int
+compare_srv_(const void **_a, const void **_b)
+{
+ const sr_srv_t *a = *_a, *b = *_b;
+ return fast_memcmp(a->value, b->value,
+ sizeof(a->value));
+}
+
/* Using a list of <b>votes</b>, return the SRV object from them that has
* been voted by the majority of dirauths. If <b>current</b> is set, we look
* for the current SRV value else the previous one. The returned pointer is
@@ -813,6 +822,7 @@ get_majority_srv_from_votes(const smartlist_t *votes, int current)
smartlist_add(srv_list, srv_tmp);
} SMARTLIST_FOREACH_END(v);
+ smartlist_sort(srv_list, compare_srv_);
most_frequent_srv = smartlist_get_most_frequent_srv(srv_list, &count);
if (!most_frequent_srv) {
goto end;