nodelist: Replace int with bool

Make some interfaces and implementations consistent by replacing int
with bool.

Part of 34200.
This commit is contained in:
teor 2020-05-11 18:10:07 +10:00
parent 3f7f976d48
commit a3244c03fb
5 changed files with 31 additions and 32 deletions

View file

@ -980,10 +980,10 @@ router_choose_random_node(smartlist_t *excludedsmartlist,
{ {
/* A limited set of flags, used for fallback node selection. /* A limited set of flags, used for fallback node selection.
*/ */
const int need_uptime = (flags & CRN_NEED_UPTIME) != 0; const bool need_uptime = (flags & CRN_NEED_UPTIME) != 0;
const int need_capacity = (flags & CRN_NEED_CAPACITY) != 0; const bool need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
const int need_guard = (flags & CRN_NEED_GUARD) != 0; const bool need_guard = (flags & CRN_NEED_GUARD) != 0;
const int pref_addr = (flags & CRN_PREF_ADDR) != 0; const bool pref_addr = (flags & CRN_PREF_ADDR) != 0;
smartlist_t *excludednodes=smartlist_new(); smartlist_t *excludednodes=smartlist_new();
const node_t *choice = NULL; const node_t *choice = NULL;

View file

@ -1158,9 +1158,9 @@ node_get_protover_summary_flags(const node_t *node)
* by ed25519 ID during the link handshake. If <b>compatible_with_us</b>, * by ed25519 ID during the link handshake. If <b>compatible_with_us</b>,
* it needs to be using a link authentication method that we understand. * it needs to be using a link authentication method that we understand.
* If not, any plausible link authentication method will do. */ * If not, any plausible link authentication method will do. */
MOCK_IMPL(int, MOCK_IMPL(bool,
node_supports_ed25519_link_authentication,(const node_t *node, node_supports_ed25519_link_authentication,(const node_t *node,
int compatible_with_us)) bool compatible_with_us))
{ {
if (! node_get_ed25519_id(node)) if (! node_get_ed25519_id(node))
return 0; return 0;
@ -1175,7 +1175,7 @@ node_supports_ed25519_link_authentication,(const node_t *node,
/** Return true iff <b>node</b> supports the hidden service directory version /** Return true iff <b>node</b> supports the hidden service directory version
* 3 protocol (proposal 224). */ * 3 protocol (proposal 224). */
int bool
node_supports_v3_hsdir(const node_t *node) node_supports_v3_hsdir(const node_t *node)
{ {
tor_assert(node); tor_assert(node);
@ -1185,7 +1185,7 @@ node_supports_v3_hsdir(const node_t *node)
/** Return true iff <b>node</b> supports ed25519 authentication as an hidden /** Return true iff <b>node</b> supports ed25519 authentication as an hidden
* service introduction point.*/ * service introduction point.*/
int bool
node_supports_ed25519_hs_intro(const node_t *node) node_supports_ed25519_hs_intro(const node_t *node)
{ {
tor_assert(node); tor_assert(node);
@ -1195,7 +1195,7 @@ node_supports_ed25519_hs_intro(const node_t *node)
/** Return true iff <b>node</b> can be a rendezvous point for hidden /** Return true iff <b>node</b> can be a rendezvous point for hidden
* service version 3 (HSRend=2). */ * service version 3 (HSRend=2). */
int bool
node_supports_v3_rendezvous_point(const node_t *node) node_supports_v3_rendezvous_point(const node_t *node)
{ {
tor_assert(node); tor_assert(node);
@ -1210,7 +1210,7 @@ node_supports_v3_rendezvous_point(const node_t *node)
/** Return true iff <b>node</b> supports the DoS ESTABLISH_INTRO cell /** Return true iff <b>node</b> supports the DoS ESTABLISH_INTRO cell
* extenstion. */ * extenstion. */
int bool
node_supports_establish_intro_dos_extension(const node_t *node) node_supports_establish_intro_dos_extension(const node_t *node)
{ {
tor_assert(node); tor_assert(node);

View file

@ -74,17 +74,16 @@ MOCK_DECL(const struct ed25519_public_key_t *,node_get_ed25519_id,
(const node_t *node)); (const node_t *node));
int node_ed25519_id_matches(const node_t *node, int node_ed25519_id_matches(const node_t *node,
const struct ed25519_public_key_t *id); const struct ed25519_public_key_t *id);
MOCK_DECL(int,node_supports_ed25519_link_authentication, MOCK_DECL(bool,node_supports_ed25519_link_authentication,
(const node_t *node, (const node_t *node,
int compatible_with_us)); bool compatible_with_us));
int node_supports_v3_hsdir(const node_t *node); bool node_supports_v3_hsdir(const node_t *node);
int node_supports_ed25519_hs_intro(const node_t *node); bool node_supports_ed25519_hs_intro(const node_t *node);
int node_supports_v3_rendezvous_point(const node_t *node); bool node_supports_v3_rendezvous_point(const node_t *node);
int node_supports_establish_intro_dos_extension(const node_t *node); bool node_supports_establish_intro_dos_extension(const node_t *node);
bool node_supports_initiating_ipv6_extends(const node_t *node); bool node_supports_initiating_ipv6_extends(const node_t *node);
bool node_supports_accepting_ipv6_extends( bool node_supports_accepting_ipv6_extends(const node_t *node,
const node_t *node, bool need_canonical_ipv6_conn);
bool need_canonical_ipv6_conn);
const uint8_t *node_get_rsa_id_digest(const node_t *node); const uint8_t *node_get_rsa_id_digest(const node_t *node);
MOCK_DECL(smartlist_t *,node_get_link_specifier_smartlist,(const node_t *node, MOCK_DECL(smartlist_t *,node_get_link_specifier_smartlist,(const node_t *node,

View file

@ -542,18 +542,18 @@ void
router_add_running_nodes_to_smartlist(smartlist_t *sl, int flags) router_add_running_nodes_to_smartlist(smartlist_t *sl, int flags)
{ {
/* The full set of flags used for node selection. */ /* The full set of flags used for node selection. */
const int need_uptime = (flags & CRN_NEED_UPTIME) != 0; const bool need_uptime = (flags & CRN_NEED_UPTIME) != 0;
const int need_capacity = (flags & CRN_NEED_CAPACITY) != 0; const bool need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
const int need_guard = (flags & CRN_NEED_GUARD) != 0; const bool need_guard = (flags & CRN_NEED_GUARD) != 0;
const int need_desc = (flags & CRN_NEED_DESC) != 0; const bool need_desc = (flags & CRN_NEED_DESC) != 0;
const int pref_addr = (flags & CRN_PREF_ADDR) != 0; const bool pref_addr = (flags & CRN_PREF_ADDR) != 0;
const int direct_conn = (flags & CRN_DIRECT_CONN) != 0; const bool direct_conn = (flags & CRN_DIRECT_CONN) != 0;
const int rendezvous_v3 = (flags & CRN_RENDEZVOUS_V3) != 0; const bool rendezvous_v3 = (flags & CRN_RENDEZVOUS_V3) != 0;
const bool initiate_ipv6_extend = (flags & CRN_INITIATE_IPV6_EXTEND) != 0; const bool initiate_ipv6_extend = (flags & CRN_INITIATE_IPV6_EXTEND) != 0;
const int check_reach = !router_or_conn_should_skip_reachable_address_check( const bool check_reach =
get_options(), !router_or_conn_should_skip_reachable_address_check(get_options(),
pref_addr); pref_addr);
SMARTLIST_FOREACH_BEGIN(nodelist_get_list(), const node_t *, node) { SMARTLIST_FOREACH_BEGIN(nodelist_get_list(), const node_t *, node) {
if (!node->is_running || !node->is_valid) if (!node->is_running || !node->is_valid)

View file

@ -281,10 +281,10 @@ mock_node_get_by_id(const char *identity_digest)
return mocked_node; return mocked_node;
} }
static int mocked_supports_ed25519_link_authentication = 0; static bool mocked_supports_ed25519_link_authentication = 0;
static int static bool
mock_node_supports_ed25519_link_authentication(const node_t *node, mock_node_supports_ed25519_link_authentication(const node_t *node,
int compatible_with_us) bool compatible_with_us)
{ {
(void)node; (void)node;
(void)compatible_with_us; (void)compatible_with_us;