Skip to content

Commit

Permalink
Merge 14e8ff4 into 3bf9974
Browse files Browse the repository at this point in the history
  • Loading branch information
asn-d6 committed Apr 19, 2018
2 parents 3bf9974 + 14e8ff4 commit 7305370
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changes/bug25843
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
o Minor bugfixes (entry guards):
- If the user has explicitly set NumEntryGuards or NumDirectoryGuards, set
the number of our primary guards to that. Fixes bug 25843; bugfix on
0.3.0.1-alpha.
12 changes: 8 additions & 4 deletions src/or/entrynodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,11 @@ get_n_primary_guards(void)
{
const int n = get_options()->NumEntryGuards;
const int n_dir = get_options()->NumDirectoryGuards;
if (n > 5) {
return MAX(n_dir, n + n / 2);
} else if (n >= 1) {
return MAX(n_dir, n * 2);

/* If the user has explicitly configured the number of guards, set the number
* of primary guards to that, since that's probably what the user wants. */
if (n || n_dir) {
return MAX(n, n_dir);
}

return networkstatus_get_param(NULL,
Expand All @@ -454,6 +455,9 @@ get_n_primary_guards_to_use(guard_usage_t usage)
int configured;
const char *param_name;
int param_default;

/* If the user has explicitly configured the amount of guards, use
that. Otherwise, fall back to the default value. */
if (usage == GUARD_USAGE_DIRGUARD) {
configured = get_options()->NumDirectoryGuards;
param_name = "guard-n-primary-dir-guards-to-use";
Expand Down
29 changes: 29 additions & 0 deletions src/test/test_entrynodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,33 @@ test_enty_guard_should_expire_waiting(void *arg)
tor_free(fake_state);
}

/** Test that the number of primary guards can be controlled using torrc */
static void
test_entry_guard_number_of_primaries(void *arg)
{
(void) arg;

/* Get default value */
tt_int_op(get_n_primary_guards(), OP_EQ, DFLT_N_PRIMARY_GUARDS);

/* Set number of entry guards, and check number of primaries */
get_options_mutable()->NumEntryGuards = 6;
tt_int_op(get_n_primary_guards(), OP_EQ, 6);

/* Check again with directory guards */
get_options_mutable()->NumEntryGuards = 0;
get_options_mutable()->NumDirectoryGuards = 4;
tt_int_op(get_n_primary_guards(), OP_EQ, 4);

/* Check that the max of the two is always picked */
get_options_mutable()->NumEntryGuards = 42;
get_options_mutable()->NumDirectoryGuards = 4;
tt_int_op(get_n_primary_guards(), OP_EQ, 42);

done:
;
}

static void
mock_directory_initiate_request(directory_request_t *req)
{
Expand Down Expand Up @@ -2826,6 +2853,8 @@ struct testcase_t entrynodes_tests[] = {
test_entry_guard_parse_from_state_broken, TT_FORK, NULL, NULL },
{ "get_guard_selection_by_name",
test_entry_guard_get_guard_selection_by_name, TT_FORK, NULL, NULL },
{ "number_of_primaries",
test_entry_guard_number_of_primaries, TT_FORK, NULL, NULL },
BFN_TEST(choose_selection_initial),
BFN_TEST(add_single_guard),
BFN_TEST(node_filter),
Expand Down

0 comments on commit 7305370

Please sign in to comment.