[tor-commits] [tor/master] Only call tor_addr_parse() in circuit_is_acceptable() when needed

nickm at torproject.org nickm at torproject.org
Tue May 14 15:44:22 UTC 2019


commit 3cafdeb8c0f1dfa60a964e4fba04b54d1ad97d15
Author: Neel Chauhan <neel at neelc.org>
Date:   Tue May 7 11:24:53 2019 -0400

    Only call tor_addr_parse() in circuit_is_acceptable() when needed
---
 changes/bug22210                         |  7 +++++++
 scripts/maint/practracker/exceptions.txt |  4 ++--
 src/core/or/circuituse.c                 | 17 ++++++++++-------
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/changes/bug22210 b/changes/bug22210
new file mode 100644
index 000000000..d7a00fd72
--- /dev/null
+++ b/changes/bug22210
@@ -0,0 +1,7 @@
+  o Minor bugfixes (onion services, performance):
+    - If we are building circuits to onion services, in circuit_is_acceptable()
+      we only call tor_addr_parse() in places where we use the returned
+      family and address values from this function. Previously, we called
+      tor_addr_parse() in circuit_is_acceptable() even if it wasn't used.
+      This change will improve performance when building circuits. Fixes
+      bug 22210; bugfix on 0.2.8.12. Patch by Neel Chauhan
diff --git a/scripts/maint/practracker/exceptions.txt b/scripts/maint/practracker/exceptions.txt
index 21fe9ec35..8623b00a2 100644
--- a/scripts/maint/practracker/exceptions.txt
+++ b/scripts/maint/practracker/exceptions.txt
@@ -92,8 +92,8 @@ problem function-size /src/core/or/circuitlist.c:circuits_handle_oom() 117
 problem function-size /src/core/or/circuitmux.c:circuitmux_set_policy() 110
 problem function-size /src/core/or/circuitmux.c:circuitmux_attach_circuit() 114
 problem function-size /src/core/or/circuitstats.c:circuit_build_times_parse_state() 124
-problem file-size /src/core/or/circuituse.c 3152
-problem function-size /src/core/or/circuituse.c:circuit_is_acceptable() 129
+problem file-size /src/core/or/circuituse.c 3155
+problem function-size /src/core/or/circuituse.c:circuit_is_acceptable() 133
 problem function-size /src/core/or/circuituse.c:circuit_expire_building() 394
 problem function-size /src/core/or/circuituse.c:circuit_log_ancient_one_hop_circuits() 126
 problem function-size /src/core/or/circuituse.c:circuit_build_failed() 149
diff --git a/src/core/or/circuituse.c b/src/core/or/circuituse.c
index 2f27cf996..226295425 100644
--- a/src/core/or/circuituse.c
+++ b/src/core/or/circuituse.c
@@ -178,7 +178,6 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
       purpose == CIRCUIT_PURPOSE_S_HSDIR_POST ||
       purpose == CIRCUIT_PURPOSE_C_HSDIR_GET) {
     tor_addr_t addr;
-    const int family = tor_addr_parse(&addr, conn->socks_request->address);
     if (!exitnode && !build_state->onehop_tunnel) {
       log_debug(LD_CIRC,"Not considering circuit with unknown router.");
       return 0; /* this circuit is screwed and doesn't know it yet,
@@ -199,6 +198,8 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
           return 0; /* this is a circuit to somewhere else */
         if (tor_digest_is_zero(digest)) {
           /* we don't know the digest; have to compare addr:port */
+          const int family = tor_addr_parse(&addr,
+                                            conn->socks_request->address);
           if (family < 0 ||
               !tor_addr_eq(&build_state->chosen_exit->addr, &addr) ||
               build_state->chosen_exit->port != conn->socks_request->port)
@@ -211,12 +212,14 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
         return 0;
       }
     }
-    if (origin_circ->prepend_policy && family != -1) {
-      int r = compare_tor_addr_to_addr_policy(&addr,
-                                              conn->socks_request->port,
-                                              origin_circ->prepend_policy);
-      if (r == ADDR_POLICY_REJECTED)
-        return 0;
+    if (origin_circ->prepend_policy) {
+      if (tor_addr_parse(&addr, conn->socks_request->address) != -1) {
+        int r = compare_tor_addr_to_addr_policy(&addr,
+                                                conn->socks_request->port,
+                                                origin_circ->prepend_policy);
+        if (r == ADDR_POLICY_REJECTED)
+          return 0;
+      }
     }
     if (exitnode && !connection_ap_can_use_exit(conn, exitnode)) {
       /* can't exit from this router */





More information about the tor-commits mailing list