Refactor to remove unnecessary check in circuit_is_available_for_use

This commit is contained in:
Chelsea H. Komlo 2016-11-02 09:45:02 -05:00
parent cfb8363da9
commit 118bba7622
No known key found for this signature in database
GPG Key ID: 1138332F98B52EE7
3 changed files with 22 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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