mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Refactor TestingDirAuthVote* into dirserv_set_routerstatus_testing
Make it easier to unit test TestingDirAuthVote{Exit,Guard,HSDir} by refactoring the code which sets flags based on them into a new function dirserv_set_routerstatus_testing.
This commit is contained in:
parent
359faf5e4b
commit
d1c94dcbea
@ -2187,31 +2187,41 @@ set_routerstatus_from_routerinfo(routerstatus_t *rs,
|
||||
rs->ipv6_orport = ri->ipv6_orport;
|
||||
}
|
||||
|
||||
/* Iff we are in a testing network, use TestingDirAuthVoteExit,
|
||||
TestingDirAuthVoteGuard, and TestingDirAuthVoteHSDir to
|
||||
give out the Exit, Guard, and HSDir flags, respectively.
|
||||
But don't set the corresponding node flags. */
|
||||
if (options->TestingTorNetwork) {
|
||||
if (routerset_contains_routerstatus(options->TestingDirAuthVoteExit,
|
||||
rs, 0)) {
|
||||
rs->is_exit = 1;
|
||||
} else if (options->TestingDirAuthVoteExitIsStrict) {
|
||||
rs->is_exit = 0;
|
||||
}
|
||||
dirserv_set_routerstatus_testing(rs);
|
||||
}
|
||||
}
|
||||
|
||||
if (routerset_contains_routerstatus(options->TestingDirAuthVoteGuard,
|
||||
rs, 0)) {
|
||||
rs->is_possible_guard = 1;
|
||||
} else if (options->TestingDirAuthVoteGuardIsStrict) {
|
||||
rs->is_possible_guard = 0;
|
||||
}
|
||||
/** Use TestingDirAuthVoteExit, TestingDirAuthVoteGuard, and
|
||||
* TestingDirAuthVoteHSDir to give out the Exit, Guard, and HSDir flags,
|
||||
* respectively. But don't set the corresponding node flags.
|
||||
* Should only be called if TestingTorNetwork is set. */
|
||||
STATIC void
|
||||
dirserv_set_routerstatus_testing(routerstatus_t *rs)
|
||||
{
|
||||
const or_options_t *options = get_options();
|
||||
|
||||
if (routerset_contains_routerstatus(options->TestingDirAuthVoteHSDir,
|
||||
rs, 0)) {
|
||||
rs->is_hs_dir = 1;
|
||||
} else if (options->TestingDirAuthVoteHSDirIsStrict) {
|
||||
rs->is_hs_dir = 0;
|
||||
}
|
||||
tor_assert(options->TestingTorNetwork);
|
||||
|
||||
if (routerset_contains_routerstatus(options->TestingDirAuthVoteExit,
|
||||
rs, 0)) {
|
||||
rs->is_exit = 1;
|
||||
} else if (options->TestingDirAuthVoteExitIsStrict) {
|
||||
rs->is_exit = 0;
|
||||
}
|
||||
|
||||
if (routerset_contains_routerstatus(options->TestingDirAuthVoteGuard,
|
||||
rs, 0)) {
|
||||
rs->is_possible_guard = 1;
|
||||
} else if (options->TestingDirAuthVoteGuardIsStrict) {
|
||||
rs->is_possible_guard = 0;
|
||||
}
|
||||
|
||||
if (routerset_contains_routerstatus(options->TestingDirAuthVoteHSDir,
|
||||
rs, 0)) {
|
||||
rs->is_hs_dir = 1;
|
||||
} else if (options->TestingDirAuthVoteHSDirIsStrict) {
|
||||
rs->is_hs_dir = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,8 @@ int validate_recommended_package_line(const char *line);
|
||||
|
||||
#ifdef DIRSERV_PRIVATE
|
||||
|
||||
STATIC void dirserv_set_routerstatus_testing(routerstatus_t *rs);
|
||||
|
||||
/* Put the MAX_MEASUREMENT_AGE #define here so unit tests can see it */
|
||||
#define MAX_MEASUREMENT_AGE (3*24*60*60) /* 3 days */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user