[tor-commits] [tor/master] nodelist: Replace int with bool

nickm at torproject.org nickm at torproject.org
Tue Jun 9 19:45:23 UTC 2020


commit a3244c03fb586268da72fbe90bc8f4def85aaff7
Author: teor <teor at riseup.net>
Date:   Mon May 11 18:10:07 2020 +1000

    nodelist: Replace int with bool
    
    Make some interfaces and implementations consistent by replacing int
    with bool.
    
    Part of 34200.
---
 src/feature/nodelist/node_select.c |  8 ++++----
 src/feature/nodelist/nodelist.c    | 12 ++++++------
 src/feature/nodelist/nodelist.h    | 17 ++++++++---------
 src/feature/nodelist/routerlist.c  | 20 ++++++++++----------
 src/test/test_circuitbuild.c       |  6 +++---
 5 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/src/feature/nodelist/node_select.c b/src/feature/nodelist/node_select.c
index 85ef5ad56..25904d4c6 100644
--- a/src/feature/nodelist/node_select.c
+++ b/src/feature/nodelist/node_select.c
@@ -980,10 +980,10 @@ router_choose_random_node(smartlist_t *excludedsmartlist,
 {
   /* A limited set of flags, used for fallback node selection.
    */
-  const int need_uptime = (flags & CRN_NEED_UPTIME) != 0;
-  const int need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
-  const int need_guard = (flags & CRN_NEED_GUARD) != 0;
-  const int pref_addr = (flags & CRN_PREF_ADDR) != 0;
+  const bool need_uptime = (flags & CRN_NEED_UPTIME) != 0;
+  const bool need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
+  const bool need_guard = (flags & CRN_NEED_GUARD) != 0;
+  const bool pref_addr = (flags & CRN_PREF_ADDR) != 0;
 
   smartlist_t *excludednodes=smartlist_new();
   const node_t *choice = NULL;
diff --git a/src/feature/nodelist/nodelist.c b/src/feature/nodelist/nodelist.c
index a55339062..6b2c0d201 100644
--- a/src/feature/nodelist/nodelist.c
+++ b/src/feature/nodelist/nodelist.c
@@ -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>,
  * it needs to be using a link authentication method that we understand.
  * If not, any plausible link authentication method will do. */
-MOCK_IMPL(int,
+MOCK_IMPL(bool,
 node_supports_ed25519_link_authentication,(const node_t *node,
-                                           int compatible_with_us))
+                                           bool compatible_with_us))
 {
   if (! node_get_ed25519_id(node))
     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
  * 3 protocol (proposal 224). */
-int
+bool
 node_supports_v3_hsdir(const node_t *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
  * service introduction point.*/
-int
+bool
 node_supports_ed25519_hs_intro(const node_t *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
  * service version 3 (HSRend=2). */
-int
+bool
 node_supports_v3_rendezvous_point(const node_t *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
  * extenstion. */
-int
+bool
 node_supports_establish_intro_dos_extension(const node_t *node)
 {
   tor_assert(node);
diff --git a/src/feature/nodelist/nodelist.h b/src/feature/nodelist/nodelist.h
index 991cec319..4ba699d69 100644
--- a/src/feature/nodelist/nodelist.h
+++ b/src/feature/nodelist/nodelist.h
@@ -74,17 +74,16 @@ MOCK_DECL(const struct ed25519_public_key_t *,node_get_ed25519_id,
           (const node_t *node));
 int node_ed25519_id_matches(const node_t *node,
                             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,
-           int compatible_with_us));
-int node_supports_v3_hsdir(const node_t *node);
-int node_supports_ed25519_hs_intro(const node_t *node);
-int node_supports_v3_rendezvous_point(const node_t *node);
-int node_supports_establish_intro_dos_extension(const node_t *node);
+           bool compatible_with_us));
+bool node_supports_v3_hsdir(const node_t *node);
+bool node_supports_ed25519_hs_intro(const node_t *node);
+bool node_supports_v3_rendezvous_point(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_accepting_ipv6_extends(
-                                             const node_t *node,
-                                             bool need_canonical_ipv6_conn);
+bool node_supports_accepting_ipv6_extends(const node_t *node,
+                                          bool need_canonical_ipv6_conn);
 
 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,
diff --git a/src/feature/nodelist/routerlist.c b/src/feature/nodelist/routerlist.c
index 110622283..72ea48898 100644
--- a/src/feature/nodelist/routerlist.c
+++ b/src/feature/nodelist/routerlist.c
@@ -542,18 +542,18 @@ void
 router_add_running_nodes_to_smartlist(smartlist_t *sl, int flags)
 {
   /* The full set of flags used for node selection. */
-  const int need_uptime = (flags & CRN_NEED_UPTIME) != 0;
-  const int need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
-  const int need_guard = (flags & CRN_NEED_GUARD) != 0;
-  const int need_desc = (flags & CRN_NEED_DESC) != 0;
-  const int pref_addr = (flags & CRN_PREF_ADDR) != 0;
-  const int direct_conn = (flags & CRN_DIRECT_CONN) != 0;
-  const int rendezvous_v3 = (flags & CRN_RENDEZVOUS_V3) != 0;
+  const bool need_uptime = (flags & CRN_NEED_UPTIME) != 0;
+  const bool need_capacity = (flags & CRN_NEED_CAPACITY) != 0;
+  const bool need_guard = (flags & CRN_NEED_GUARD) != 0;
+  const bool need_desc = (flags & CRN_NEED_DESC) != 0;
+  const bool pref_addr = (flags & CRN_PREF_ADDR) != 0;
+  const bool direct_conn = (flags & CRN_DIRECT_CONN) != 0;
+  const bool rendezvous_v3 = (flags & CRN_RENDEZVOUS_V3) != 0;
   const bool initiate_ipv6_extend = (flags & CRN_INITIATE_IPV6_EXTEND) != 0;
 
-  const int check_reach = !router_or_conn_should_skip_reachable_address_check(
-                                                       get_options(),
-                                                       pref_addr);
+  const bool check_reach =
+    !router_or_conn_should_skip_reachable_address_check(get_options(),
+                                                        pref_addr);
 
   SMARTLIST_FOREACH_BEGIN(nodelist_get_list(), const node_t *, node) {
     if (!node->is_running || !node->is_valid)
diff --git a/src/test/test_circuitbuild.c b/src/test/test_circuitbuild.c
index 44d286e75..88e46af13 100644
--- a/src/test/test_circuitbuild.c
+++ b/src/test/test_circuitbuild.c
@@ -281,10 +281,10 @@ mock_node_get_by_id(const char *identity_digest)
   return mocked_node;
 }
 
-static int mocked_supports_ed25519_link_authentication = 0;
-static int
+static bool mocked_supports_ed25519_link_authentication = 0;
+static bool
 mock_node_supports_ed25519_link_authentication(const node_t *node,
-                                                int compatible_with_us)
+                                               bool compatible_with_us)
 {
   (void)node;
   (void)compatible_with_us;





More information about the tor-commits mailing list