mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Refactor purpose_needs_anonymity to use switch statement
This commit is contained in:
parent
195ccce94e
commit
471b0c5175
@ -1,3 +1,5 @@
|
||||
o Code simplification and refactoring:
|
||||
- Remove redundant behavior of is_sensitive_dir_purpose, refactor to use
|
||||
only purpose_needs_anonymity
|
||||
- Refactor large if statement in purpose_needs_anonymity to use switch
|
||||
statement instead.
|
||||
|
@ -136,17 +136,22 @@ purpose_needs_anonymity(uint8_t dir_purpose, uint8_t router_purpose)
|
||||
return 1; /* if no circuits yet, this might break bootstrapping, but it's
|
||||
* needed to be safe. */
|
||||
|
||||
if (dir_purpose == DIR_PURPOSE_UPLOAD_DIR ||
|
||||
dir_purpose == DIR_PURPOSE_UPLOAD_VOTE ||
|
||||
dir_purpose == DIR_PURPOSE_UPLOAD_SIGNATURES ||
|
||||
dir_purpose == DIR_PURPOSE_FETCH_STATUS_VOTE ||
|
||||
dir_purpose == DIR_PURPOSE_FETCH_DETACHED_SIGNATURES ||
|
||||
dir_purpose == DIR_PURPOSE_FETCH_CONSENSUS ||
|
||||
dir_purpose == DIR_PURPOSE_FETCH_CERTIFICATE ||
|
||||
dir_purpose == DIR_PURPOSE_FETCH_SERVERDESC ||
|
||||
dir_purpose == DIR_PURPOSE_FETCH_EXTRAINFO ||
|
||||
dir_purpose == DIR_PURPOSE_FETCH_MICRODESC)
|
||||
return 0;
|
||||
switch (dir_purpose)
|
||||
{
|
||||
case DIR_PURPOSE_UPLOAD_DIR:
|
||||
case DIR_PURPOSE_UPLOAD_VOTE:
|
||||
case DIR_PURPOSE_UPLOAD_SIGNATURES:
|
||||
case DIR_PURPOSE_FETCH_STATUS_VOTE:
|
||||
case DIR_PURPOSE_FETCH_DETACHED_SIGNATURES:
|
||||
case DIR_PURPOSE_FETCH_CONSENSUS:
|
||||
case DIR_PURPOSE_FETCH_CERTIFICATE:
|
||||
case DIR_PURPOSE_FETCH_SERVERDESC:
|
||||
case DIR_PURPOSE_FETCH_EXTRAINFO:
|
||||
case DIR_PURPOSE_FETCH_MICRODESC:
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -3252,6 +3252,15 @@ test_dir_http_handling(void *args)
|
||||
tor_free(url);
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_purpose_needs_anonymity_returns_true_by_default(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
tt_int_op(1, ==, purpose_needs_anonymity(0, 0));
|
||||
done: ;
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_purpose_needs_anonymity_returns_true_for_bridges(void *arg)
|
||||
{
|
||||
@ -5500,6 +5509,7 @@ struct testcase_t dir_tests[] = {
|
||||
DIR(dirserv_set_routerstatus_testing, 0),
|
||||
DIR(http_handling, 0),
|
||||
DIR(purpose_needs_anonymity_returns_true_for_bridges, 0),
|
||||
DIR(purpose_needs_anonymity_returns_true_by_default, 0),
|
||||
DIR(purpose_needs_anonymity_returns_true_for_sensitive_purpose, 0),
|
||||
DIR(purpose_needs_anonymity_ret_false_for_non_sensitive_conn, 0),
|
||||
DIR(fetch_type, 0),
|
||||
|
Loading…
Reference in New Issue
Block a user