mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
Refactor to remove unnecessary check in circuit_is_available_for_use
This commit is contained in:
parent
cfb8363da9
commit
118bba7622
@ -4,3 +4,4 @@
|
|||||||
- Refactor circuit_predict_and_launch_new for readability and testability.
|
- Refactor circuit_predict_and_launch_new for readability and testability.
|
||||||
- Added unit tests for extracted functions.
|
- Added unit tests for extracted functions.
|
||||||
- Extracted magic numbers in circuituse.c into defined variables.
|
- Extracted magic numbers in circuituse.c into defined variables.
|
||||||
|
- Refactor circuit_is_available_for_use to remove unnecessary check
|
||||||
|
@ -1033,15 +1033,13 @@ circuit_is_available_for_use(const circuit_t *circ)
|
|||||||
const origin_circuit_t *origin_circ;
|
const origin_circuit_t *origin_circ;
|
||||||
cpath_build_state_t *build_state;
|
cpath_build_state_t *build_state;
|
||||||
|
|
||||||
if (!CIRCUIT_IS_ORIGIN(circ))
|
|
||||||
return 0;
|
|
||||||
if (circ->marked_for_close)
|
if (circ->marked_for_close)
|
||||||
return 0; /* Don't mess with marked circs */
|
return 0; /* Don't mess with marked circs */
|
||||||
if (circ->timestamp_dirty)
|
if (circ->timestamp_dirty)
|
||||||
return 0; /* Only count clean circs */
|
return 0; /* Only count clean circs */
|
||||||
if (circ->purpose != CIRCUIT_PURPOSE_C_GENERAL)
|
if (circ->purpose != CIRCUIT_PURPOSE_C_GENERAL)
|
||||||
return 0;/* Only pay attention to general
|
return 0; /* Only pay attention to general purpose circuits.
|
||||||
purpose circs */
|
General purpose circuits are always origin circuits. */
|
||||||
|
|
||||||
origin_circ = CONST_TO_ORIGIN_CIRCUIT(circ);
|
origin_circ = CONST_TO_ORIGIN_CIRCUIT(circ);
|
||||||
if (origin_circ->unusable_for_new_conns)
|
if (origin_circ->unusable_for_new_conns)
|
||||||
|
@ -46,7 +46,21 @@ test_circuit_is_available_for_use_ret_false_for_non_general_purpose(void *arg)
|
|||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
circuit_t *circ = tor_malloc(sizeof(circuit_t));
|
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));
|
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,
|
test_circuit_is_available_for_use_ret_false_for_non_general_purpose,
|
||||||
TT_FORK, NULL, NULL
|
TT_FORK, NULL, NULL
|
||||||
},
|
},
|
||||||
|
{ "non_general",
|
||||||
|
test_circuit_is_available_for_use_ret_false_for_non_general_origin,
|
||||||
|
TT_FORK, NULL, NULL
|
||||||
|
},
|
||||||
{ "origin",
|
{ "origin",
|
||||||
test_circuit_is_available_for_use_ret_false_for_non_origin_purpose,
|
test_circuit_is_available_for_use_ret_false_for_non_origin_purpose,
|
||||||
TT_FORK, NULL, NULL
|
TT_FORK, NULL, NULL
|
||||||
|
Loading…
Reference in New Issue
Block a user