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
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;
{ /* Now put in 8 more votes. Let SRV_1 have majority. */
int i;
/* Now 7 votes believe in SRV_1 */
- for (i = 0; i < 6; i++) {
+ for (i = 0; i < 3; i++) {
networkstatus_t *vote = get_test_vote_with_curr_srv(SRV_1);
smartlist_add(votes, vote);
}
networkstatus_t *vote = get_test_vote_with_curr_srv(SRV_2);
smartlist_add(votes, vote);
}
+ for (i = 0; i < 3; i++) {
+ networkstatus_t *vote = get_test_vote_with_curr_srv(SRV_1);
+ smartlist_add(votes, vote);
+ }
tt_int_op(smartlist_len(votes), ==, 9);
}