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

[tor-commits] [tor/master] Refactor to remove unnecessary check in circuit_is_available_for_use



commit 118bba7622ab15ea5c58ff32be178820150423ba
Author: Chelsea H. Komlo <chelsea.komlo@xxxxxxxxx>
Date:   Wed Nov 2 09:45:02 2016 -0500

    Refactor to remove unnecessary check in circuit_is_available_for_use
---
 changes/ticket18873        |  1 +
 src/or/circuituse.c        |  6 ++----
 src/test/test_circuituse.c | 20 +++++++++++++++++++-
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/changes/ticket18873 b/changes/ticket18873
index e19a290..f1d9bef 100644
--- a/changes/ticket18873
+++ b/changes/ticket18873
@@ -4,3 +4,4 @@
     - Refactor circuit_predict_and_launch_new for readability and testability.
     - Added unit tests for extracted functions.
     - Extracted magic numbers in circuituse.c into defined variables.
+    - Refactor circuit_is_available_for_use to remove unnecessary check
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 9afe77b..6fb4f82 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -1033,15 +1033,13 @@ circuit_is_available_for_use(const circuit_t *circ)
   const origin_circuit_t *origin_circ;
   cpath_build_state_t *build_state;
 
-  if (!CIRCUIT_IS_ORIGIN(circ))
-    return 0;
   if (circ->marked_for_close)
     return 0; /* Don't mess with marked circs */
   if (circ->timestamp_dirty)
     return 0; /* Only count clean circs */
   if (circ->purpose != CIRCUIT_PURPOSE_C_GENERAL)
-    return 0;/* Only pay attention to general
-                purpose circs */
+    return 0; /* Only pay attention to general purpose circuits.
+                 General purpose circuits are always origin circuits. */
 
   origin_circ = CONST_TO_ORIGIN_CIRCUIT(circ);
   if (origin_circ->unusable_for_new_conns)
diff --git a/src/test/test_circuituse.c b/src/test/test_circuituse.c
index 23f1f9c..edbc9f6 100644
--- a/src/test/test_circuituse.c
+++ b/src/test/test_circuituse.c
@@ -46,7 +46,21 @@ test_circuit_is_available_for_use_ret_false_for_non_general_purpose(void *arg)
   (void)arg;
 
   circuit_t *circ = tor_malloc(sizeof(circuit_t));
-  circ->purpose = CIRCUIT_PURPOSE_OR;
+  circ->purpose = CIRCUIT_PURPOSE_REND_POINT_WAITING;
+
+  tt_int_op(0, ==, circuit_is_available_for_use(circ));
+
+  done:
+    tor_free(circ);
+}
+
+static void
+test_circuit_is_available_for_use_ret_false_for_non_general_origin(void *arg)
+{
+  (void)arg;
+
+  circuit_t *circ = tor_malloc(sizeof(circuit_t));
+  circ->purpose = CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT;
 
   tt_int_op(0, ==, circuit_is_available_for_use(circ));
 
@@ -235,6 +249,10 @@ struct testcase_t circuituse_tests[] = {
    test_circuit_is_available_for_use_ret_false_for_non_general_purpose,
    TT_FORK, NULL, NULL
  },
+ { "non_general",
+  test_circuit_is_available_for_use_ret_false_for_non_general_origin,
+   TT_FORK, NULL, NULL
+ },
  { "origin",
    test_circuit_is_available_for_use_ret_false_for_non_origin_purpose,
    TT_FORK, NULL, NULL



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