diff options
author | Chelsea H. Komlo <chelsea.komlo@gmail.com> | 2016-11-02 09:45:02 -0500 |
---|---|---|
committer | Chelsea H. Komlo <chelsea.komlo@gmail.com> | 2016-11-24 08:12:33 -0500 |
commit | 118bba7622ab15ea5c58ff32be178820150423ba (patch) | |
tree | 84b46f7a30af14b70b8533102f6b6cb56f72c9dd | |
parent | cfb8363da9210ba3df92a0b6a572b8c3c5adcf9b (diff) | |
download | tor-118bba7622ab15ea5c58ff32be178820150423ba.tar.gz tor-118bba7622ab15ea5c58ff32be178820150423ba.zip |
Refactor to remove unnecessary check in circuit_is_available_for_use
-rw-r--r-- | changes/ticket18873 | 1 | ||||
-rw-r--r-- | src/or/circuituse.c | 6 | ||||
-rw-r--r-- | src/test/test_circuituse.c | 20 |
3 files changed, 22 insertions, 5 deletions
diff --git a/changes/ticket18873 b/changes/ticket18873 index e19a290e45..f1d9bef6d2 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 9afe77b77e..6fb4f82b6d 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 23f1f9c6d2..edbc9f6391 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 |