mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 14:51:11 +01:00
Tidy up compare_routerinfo_by_ipv{4,6} to match better.
This commit is contained in:
parent
81c05e1e98
commit
3196de33a5
1 changed files with 11 additions and 14 deletions
|
@ -4215,19 +4215,16 @@ MOCK_IMPL(uint32_t,dirserv_get_bandwidth_for_router_kb,
|
||||||
STATIC int
|
STATIC int
|
||||||
compare_routerinfo_by_ipv4(const void **a, const void **b)
|
compare_routerinfo_by_ipv4(const void **a, const void **b)
|
||||||
{
|
{
|
||||||
const routerinfo_t *first = *(routerinfo_t **)a;
|
const routerinfo_t *first = *(const routerinfo_t **)a;
|
||||||
const routerinfo_t *second = *(routerinfo_t **)b;
|
const routerinfo_t *second = *(const routerinfo_t **)b;
|
||||||
// If addresses are equal, use other comparison criterions
|
const tor_addr_t *first_ipv4 = &first->ipv4_addr;
|
||||||
int addr_comparison = tor_addr_compare(&(first->ipv4_addr),
|
const tor_addr_t *second_ipv4 = &first->ipv4_addr;
|
||||||
&(second->ipv4_addr), CMP_EXACT);
|
int comparison = tor_addr_compare(first_ipv4, second_ipv4, CMP_EXACT);
|
||||||
if (addr_comparison == 0) {
|
if (comparison == 0) {
|
||||||
|
// If addresses are equal, use other comparison criteria
|
||||||
return compare_routerinfo_usefulness(first, second);
|
return compare_routerinfo_usefulness(first, second);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, compare the addresses
|
return comparison;
|
||||||
if (addr_comparison < 0 )
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4238,12 +4235,12 @@ compare_routerinfo_by_ipv4(const void **a, const void **b)
|
||||||
STATIC int
|
STATIC int
|
||||||
compare_routerinfo_by_ipv6(const void **a, const void **b)
|
compare_routerinfo_by_ipv6(const void **a, const void **b)
|
||||||
{
|
{
|
||||||
const routerinfo_t *first = *(routerinfo_t **)a;
|
const routerinfo_t *first = *(const routerinfo_t **)a;
|
||||||
const routerinfo_t *second = *(routerinfo_t **)b;
|
const routerinfo_t *second = *(const routerinfo_t **)b;
|
||||||
const tor_addr_t *first_ipv6 = &(first->ipv6_addr);
|
const tor_addr_t *first_ipv6 = &(first->ipv6_addr);
|
||||||
const tor_addr_t *second_ipv6 = &(second->ipv6_addr);
|
const tor_addr_t *second_ipv6 = &(second->ipv6_addr);
|
||||||
int comparison = tor_addr_compare(first_ipv6, second_ipv6, CMP_EXACT);
|
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)
|
if (comparison == 0)
|
||||||
return compare_routerinfo_usefulness(first, second);
|
return compare_routerinfo_usefulness(first, second);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue