[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Kill redundant checks around routerset_contains_*()



commit 64c8e8edda5a7f3525a1ab365c4bd72b19212322
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Jul 7 11:52:13 2011 -0400

    Kill redundant checks around routerset_contains_*()
    
    All of the routerset_contains*() functions return 0 if their
    routerset_t argument is NULL.  Therefore, there's no point in
    doing "if (ExcludeNodes && routerset_contains*(ExcludeNodes...))",
    for example.
    
    This patch fixes every instance of
             if (X && routerstatus_contains*(X,...))
    
    Note that there are other patterns that _aren't_ redundant.  For
    example, we *don't* want to change:
            if (EntryNodes && !routerstatus_contains(EntryNodes,...))
    
    Fixes #2797.  No bug here; just needless code.
---
 src/or/circuitbuild.c    |    6 ++----
 src/or/connection_edge.c |    3 +--
 src/or/directory.c       |    2 +-
 src/or/rendclient.c      |    2 +-
 src/or/rendservice.c     |    2 +-
 src/or/routerlist.c      |    7 ++++---
 6 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 4ec45bc..90d9280 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2693,8 +2693,7 @@ choose_good_exit_server_general(int need_uptime, int need_capacity)
       n_supported[i] = -1;
       continue; /* skip routers that are known to be down or bad exits */
     }
-    if (options->_ExcludeExitNodesUnion &&
-        routerset_contains_node(options->_ExcludeExitNodesUnion, node)) {
+    if (routerset_contains_node(options->_ExcludeExitNodesUnion, node)) {
       n_supported[i] = -1;
       continue; /* user asked us not to use it, no matter what */
     }
@@ -3505,8 +3504,7 @@ entry_is_live(entry_guard_t *e, int need_uptime, int need_capacity,
       return NULL;
     }
   }
-  if (options->EntryNodes &&
-      routerset_contains_node(options->EntryNodes, node)) {
+  if (routerset_contains_node(options->EntryNodes, node)) {
     /* they asked for it, they get it */
     need_uptime = need_capacity = 0;
   }
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index c490148..3f6e87c 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -3146,8 +3146,7 @@ connection_ap_can_use_exit(edge_connection_t *conn, const node_t *exit)
     if (!conn->chosen_exit_name && node_exit_policy_rejects_all(exit))
       return 0;
   }
-  if (options->_ExcludeExitNodesUnion &&
-      routerset_contains_node(options->_ExcludeExitNodesUnion, exit)) {
+  if (routerset_contains_node(options->_ExcludeExitNodesUnion, exit)) {
     /* Not a suitable exit. Refuse it. */
     return 0;
   }
diff --git a/src/or/directory.c b/src/or/directory.c
index 9e1373d..17413ed 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -306,7 +306,7 @@ directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
       if (exclude_self && router_digest_is_me(ds->digest))
         continue;
 
-      if (options->ExcludeNodes && options->StrictNodes &&
+      if (options->StrictNodes &&
           routerset_contains_routerstatus(options->ExcludeNodes, rs, -1)) {
         log_warn(LD_DIR, "Wanted to contact authority '%s' for %s, but "
                  "it's in our ExcludedNodes list and StrictNodes is set. "
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index b618d0f..5164559 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -948,7 +948,7 @@ rend_client_get_random_intro_impl(const rend_cache_entry_t *entry,
     intro->extend_info = extend_info_from_node(node);
   }
   /* Check if we should refuse to talk to this router. */
-  if (options->ExcludeNodes && strict &&
+  if (strict &&
       routerset_contains_extendinfo(options->ExcludeNodes,
                                     intro->extend_info)) {
     n_excluded++;
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 4413ae9..47a9fc7 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -1079,7 +1079,7 @@ rend_service_introduce(origin_circuit_t *circuit, const uint8_t *request,
   }
 
   /* Check if we'd refuse to talk to this router */
-  if (options->ExcludeNodes && options->StrictNodes &&
+  if (options->StrictNodes &&
       routerset_contains_extendinfo(options->ExcludeNodes, extend_info)) {
     log_warn(LD_REND, "Client asked to rendezvous at a relay that we "
              "exclude, and StrictNodes is set. Refusing service.");
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 15f643c..00557a2 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1132,7 +1132,7 @@ router_pick_directory_server_impl(dirinfo_type_t type, int flags)
     if ((type & MICRODESC_DIRINFO) && !is_trusted &&
         !node->rs->version_supports_microdesc_cache)
       continue;
-    if (try_excluding && options->ExcludeNodes &&
+    if (try_excluding &&
         routerset_contains_routerstatus(options->ExcludeNodes, status,
                                         country)) {
       ++n_excluded;
@@ -1237,7 +1237,7 @@ router_pick_trusteddirserver_impl(dirinfo_type_t type, int flags,
         continue;
       if (requireother && me && router_digest_is_me(d->digest))
           continue;
-      if (try_excluding && options->ExcludeNodes &&
+      if (try_excluding &&
           routerset_contains_routerstatus(options->ExcludeNodes,
                                           &d->fake_status, -1)) {
         ++n_excluded;
@@ -5567,7 +5567,8 @@ routerset_contains(const routerset_t *set, const tor_addr_t *addr,
                    const char *nickname, const char *id_digest,
                    country_t country)
 {
-  if (!set || !set->list) return 0;
+  if (!set || !set->list)
+    return 0;
   if (nickname && strmap_get_lc(set->names, nickname))
     return 4;
   if (id_digest && digestmap_get(set->digests, id_digest))



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits