Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prop 310 #1773

Closed
wants to merge 13 commits into from
Closed

Prop 310 #1773

wants to merge 13 commits into from

Conversation

Labels
None yet
Projects
None yet
5 participants
@frochet
Copy link
Contributor

@frochet frochet commented Mar 1, 2020

Implements Proposal 310 issued from trac ticket 32088.

This patch also covers Nickm's bucket list from the ticket, i.e.:

  • tests or the changed behavior. (Note: existing tests have been adapted to support the new behavior)
  • a "changes" file
  • editing such that "make check-spaces" passes
  • Updates to the documentation and names of all the functions whose behavior has changed.
@coveralls
Copy link

@coveralls coveralls commented Mar 1, 2020

Pull Request Test Coverage Report for Build 8778

  • 73 of 77 (94.81%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.03%) to 64.206%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/feature/client/entrynodes.c 73 77 94.81%
Files with Coverage Reduction New Missed Lines %
src/feature/client/entrynodes.c 1 86.35%
src/feature/hs/hs_common.c 1 84.48%
Totals Coverage Status
Change from base Build 8768: 0.03%
Covered Lines: 50905
Relevant Lines: 79284

💛 - Coveralls

src/feature/client/entrynodes.h Outdated Show resolved Hide resolved
frochet and others added 3 commits Mar 2, 2020
Straight apply of suggestion from github feature

Co-Authored-By: teor <teor@torproject.org>
src/feature/client/entrynodes.c Show resolved Hide resolved
} else {
log_warn(LD_GUARD, "The state file seems to be into a status that could"
" yield to weird entry node selection. It might be better to delete"
" it");
Copy link
Contributor

@nmathewson nmathewson Apr 9, 2020

Let's not suggest that people delete their state files. Instead let's warn, and set the sampled_idx to something. Leaving sampled_idx at zero seems like a worst-case idea, since it makes the guard get selected before any others.

Copy link
Contributor Author

@frochet frochet Apr 12, 2020

idem as above

@@ -3184,13 +3237,22 @@ entry_guards_load_guards_from_state(or_state_t *state, int set)
tor_assert(gs);
smartlist_add(gs->sampled_entry_guards, guard);
guard->in_selection = gs;
/* Recompute the next_sampled_id from the state */
if (gs->next_sampled_idx <= guard->sampled_idx) {
gs->next_sampled_idx = ++guard->sampled_idx;
Copy link
Contributor

@nmathewson nmathewson Apr 9, 2020

Wait -- why are you incrementing guard->sampled_idx here? Don't you just want to say "guard->sampled_idx + 1"?

Copy link
Contributor Author

@frochet frochet Apr 12, 2020

Wait -- yes. Now I wonder why a test did not catch it. Looking into it.

@@ -1849,6 +1868,9 @@ make_guard_confirmed(guard_selection_t *gs, entry_guard_t *guard)

guard->confirmed_idx = gs->next_confirmed_idx++;
smartlist_add(gs->confirmed_entry_guards, guard);
/** The confirmation ordering might not be the sample ording. We need to
* reorder */
Copy link
Contributor

@nmathewson nmathewson Apr 9, 2020

Let's document this new requirement in the documentation for confirmed_entry_guards.

Copy link
Contributor Author

@frochet frochet Apr 12, 2020

ok, done in struct guard_selection_t

Copy link
Member

@asn-d6 asn-d6 Apr 29, 2020

Hmm, compare_guards_by_sampled_idx() only talks about sampled set but here we do it in the confirmed set. So perhaps we should update documentation?

src/feature/client/entrynodes.c Show resolved Hide resolved
@@ -1771,7 +1773,7 @@ sample_reachable_filtered_entry_guards(guard_selection_t *gs,
flags, smartlist_len(reachable_filtered_sample));

if (smartlist_len(reachable_filtered_sample)) {
result = smartlist_choose(reachable_filtered_sample);
result = smartlist_get(reachable_filtered_sample, 0);
Copy link
Contributor

@nmathewson nmathewson Apr 9, 2020

Let's have a comment here that refers to proposal 310.

In particular, let's explain why this is safe, and why it won't just return the same guard over and over whether it's working or not.

Copy link
Contributor Author

@frochet frochet Apr 12, 2020

Ok, done. I've also noticed that functions calling first_reachable_filtered_entry_guard needed documentation updates. Function select_filtered_guard_for_circuit documented to look into confirmed guards while excluding them; I believe the documentation was wrong but the code was ok (i.e., we had to exclude confirmed guards).

Copy link
Member

@asn-d6 asn-d6 Apr 29, 2020

Hmm, I'd like to echo this. While prop310 is noted now, it's still not clear to me why the same guard wont be returned over and over. Perhaps some additional documentation or spec patch is in order here to increase comprehension?

@frochet
Copy link
Contributor Author

@frochet frochet commented Apr 12, 2020

I am not sure to get what's going on regarding the mem leak. It looks like some memory is leaking while parsing the config lines of the state file (the 8 lines of sampled_idx). This should be handled by config_free_lines, right? I don't see why this line is not freed.

=================================================================
==3923==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 17 byte(s) in 8 object(s) allocated from:
#0 0x7f99c20b6538 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x77538)
#1 0x559e3df5ea40 in tor_strdup_ src/lib/malloc/malloc.c:165
#2 0x559e3dc9488b in entry_guard_parse_from_state src/feature/client/entrynodes.c:2981
#3 0x559e3dc9d2d5 in entry_guards_load_guards_from_state src/feature/client/entrynodes.c:3233
#4 0x559e3dc9d2d5 in entry_guards_parse_state src/feature/client/entrynodes.c:3456
#5 0x559e3d8a41fb in test_entry_guard_parse_from_state_full src/test/test_entrynodes.c:697
#6 0x559e3db7bdc5 in testcase_run_bare_ src/ext/tinytest.c:107

Direct leak of 17 byte(s) in 8 object(s) allocated from:
#0 0x7f99c20b6538 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x77538)
#1 0x559e3df5ea40 in tor_strdup_ src/lib/malloc/malloc.c:165
#2 0x559e3dc9488b in entry_guard_parse_from_state src/feature/client/entrynodes.c:2981
#3 0x559e3dc9d2d5 in entry_guards_load_guards_from_state src/feature/client/entrynodes.c:3233
#4 0x559e3dc9d2d5 in entry_guards_parse_state src/feature/client/entrynodes.c:3456
#5 0x559e3d8a47ef in test_entry_guard_parse_from_state_full src/test/test_entrynodes.c:714
#6 0x559e3db7bdc5 in testcase_run_bare_ src/ext/tinytest.c:107

Direct leak of 17 byte(s) in 8 object(s) allocated from:
#0 0x7f99c20b6538 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x77538)
#1 0x559e3df5ea40 in tor_strdup_ src/lib/malloc/malloc.c:165
#2 0x559e3dc9488b in entry_guard_parse_from_state src/feature/client/entrynodes.c:2981
#3 0x559e3dc9d2d5 in entry_guards_load_guards_from_state src/feature/client/entrynodes.c:3233
#4 0x559e3dc9d2d5 in entry_guards_parse_state src/feature/client/entrynodes.c:3456
#5 0x559e3d8a3ff9 in test_entry_guard_parse_from_state_full src/test/test_entrynodes.c:691
#6 0x559e3db7bdc5 in testcase_run_bare_ src/ext/tinytest.c:107

@@ -182,10 +182,10 @@ problem function-size /src/feature/client/addressmap.c:addressmap_rewrite() 109
problem function-size /src/feature/client/bridges.c:rewrite_node_address_for_bridge() 125
problem function-size /src/feature/client/circpathbias.c:pathbias_measure_close_rate() 108
problem function-size /src/feature/client/dnsserv.c:evdns_server_callback() 153
problem file-size /src/feature/client/entrynodes.c 3827
problem file-size /src/feature/client/entrynodes.c 4000
Copy link
Contributor

@teor2345 teor2345 Apr 29, 2020

Notes for the reviewer:

173 unchecked extra lines seems a bit high.

Suggested change
problem file-size /src/feature/client/entrynodes.c 4000
problem file-size /src/feature/client/entrynodes.c 3900

@@ -1771,7 +1773,7 @@ sample_reachable_filtered_entry_guards(guard_selection_t *gs,
flags, smartlist_len(reachable_filtered_sample));

if (smartlist_len(reachable_filtered_sample)) {
result = smartlist_choose(reachable_filtered_sample);
result = smartlist_get(reachable_filtered_sample, 0);
Copy link
Member

@asn-d6 asn-d6 Apr 29, 2020

Hmm, I'd like to echo this. While prop310 is noted now, it's still not clear to me why the same guard wont be returned over and over. Perhaps some additional documentation or spec patch is in order here to increase comprehension?

@@ -1849,6 +1868,9 @@ make_guard_confirmed(guard_selection_t *gs, entry_guard_t *guard)

guard->confirmed_idx = gs->next_confirmed_idx++;
smartlist_add(gs->confirmed_entry_guards, guard);
/** The confirmation ordering might not be the sample ording. We need to
* reorder */
Copy link
Member

@asn-d6 asn-d6 Apr 29, 2020

Hmm, compare_guards_by_sampled_idx() only talks about sampled set but here we do it in the confirmed set. So perhaps we should update documentation?

src/feature/client/entrynodes.c Show resolved Hide resolved
src/feature/client/entrynodes.h Show resolved Hide resolved
/**
* In what order was this guard sampled without replacement? Guards with
* lower indices appear earlier on the sampled list
*/
Copy link
Member

@asn-d6 asn-d6 Apr 29, 2020

I think we need a patch for guard-spec.txt to explain how this new field should work. Our guard spec is quite engineering oriented and basically explains how these fields tie together, so I think mentioning sampled_idx and next_sampled_idx there is important.

Copy link
Contributor Author

@frochet frochet Apr 29, 2020

I can send a PR to the torspec repository (I guess guard-spec.txt is there)

Copy link
Member

@asn-d6 asn-d6 May 4, 2020

Yes please!

src/feature/client/entrynodes.c Show resolved Hide resolved
@frochet frochet closed this Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment