Tidy up compare_routerinfo_by_ipv{4,6} to match better.

This commit is contained in:
Nick Mathewson 2020-09-23 11:48:20 -04:00
parent 81c05e1e98
commit 3196de33a5

View File

@ -4215,19 +4215,16 @@ MOCK_IMPL(uint32_t,dirserv_get_bandwidth_for_router_kb,
STATIC int
compare_routerinfo_by_ipv4(const void **a, const void **b)
{
const routerinfo_t *first = *(routerinfo_t **)a;
const routerinfo_t *second = *(routerinfo_t **)b;
// If addresses are equal, use other comparison criterions
int addr_comparison = tor_addr_compare(&(first->ipv4_addr),
&(second->ipv4_addr), CMP_EXACT);
if (addr_comparison == 0) {
const routerinfo_t *first = *(const routerinfo_t **)a;
const routerinfo_t *second = *(const routerinfo_t **)b;
const tor_addr_t *first_ipv4 = &first->ipv4_addr;
const tor_addr_t *second_ipv4 = &first->ipv4_addr;
int comparison = tor_addr_compare(first_ipv4, second_ipv4, CMP_EXACT);
if (comparison == 0) {
// If addresses are equal, use other comparison criteria
return compare_routerinfo_usefulness(first, second);
} else {
// Otherwise, compare the addresses
if (addr_comparison < 0 )
return -1;
else
return 1;
return comparison;
}
}
@ -4238,12 +4235,12 @@ compare_routerinfo_by_ipv4(const void **a, const void **b)
STATIC int
compare_routerinfo_by_ipv6(const void **a, const void **b)
{
const routerinfo_t *first = *(routerinfo_t **)a;
const routerinfo_t *second = *(routerinfo_t **)b;
const routerinfo_t *first = *(const routerinfo_t **)a;
const routerinfo_t *second = *(const routerinfo_t **)b;
const tor_addr_t *first_ipv6 = &(first->ipv6_addr);
const tor_addr_t *second_ipv6 = &(second->ipv6_addr);
int comparison = tor_addr_compare(first_ipv6, second_ipv6, CMP_EXACT);
// If addresses are equal, use other comparison criterions
// If addresses are equal, use other comparison criteria
if (comparison == 0)
return compare_routerinfo_usefulness(first, second);
else