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

[Tor Trac #25885]: count_acceptable_nodes() would be more accurate using node_has_preferred_descriptor() #271

Merged
merged 1 commit into from Nov 7, 2018

Conversation

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

@neelchauhan neelchauhan commented Aug 12, 2018

For the bug here.

@coveralls
Copy link

@coveralls coveralls commented Aug 12, 2018

Pull Request Test Coverage Report for Build 2802

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • 4 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.002%) to 62.032%

Files with Coverage Reduction New Missed Lines %
src/core/or/circuitbuild.c 1 42.5%
src/feature/nodelist/nodelist.c 3 61.1%
Totals Coverage Status
Change from base Build 2775: -0.002%
Covered Lines: 44111
Relevant Lines: 71110

💛 - Coveralls

* 3, return the route length. Else, return 0 to signify that we do not
* have a complete circuit.
*
* Keep in mind that this function can succeed if direct is greater than
Copy link
Contributor

@nmathewson nmathewson Oct 16, 2018

This seems to be an unwanted property....

* Keep in mind that this function can succeed if direct is greater than
* 1 but indirect isn't because guard nodes can also be middle or exit
* nodes if configured so on the relay side. */
return (direct >= 1) && (direct + indirect >= 3) ? direct + indirect : 0;
Copy link
Contributor

@nmathewson nmathewson Oct 16, 2018

I think this calculation isn't what we actually want.

After all, we only use this function in one place: to tell if we have enough routers to build a path. Maybe the right solution here is to have this function return the direct and indirect counts separately, and let new_route_len() decide whether it likes it?

@@ -2418,17 +2414,29 @@ count_acceptable_nodes, (smartlist_t *nodes))
if (! node->is_valid)
// log_debug(LD_CIRC,"Nope, the directory says %d is not valid.",i);
continue;
if (! node_has_any_descriptor(node))
/* If we can use the node, check if we can connect directly. */
if (node_has_preferred_descriptor(node, 1))
Copy link
Contributor

@nmathewson nmathewson Oct 16, 2018

Here you treat "indirect" and "direct" as having a logical relation to one another, as if it's okay to count every "direct" node as also being "indirect" later on (when you do direct+indirect). That isn't exactly the case, though: for the nodes in the "direct" count, we might not be willing to use them indirectly if we don't have the right descriptor for them.

Probably direct and indirect should be computed separately; maybe "direct" should be an argument to this function?

Copy link
Contributor

@teor2345 teor2345 Oct 17, 2018

It's also worth noting that bridges are used as entry nodes (direct) but not middle or end nodes (indirect).
The one exception is when a public relay is set as a bridge.

Copy link
Contributor Author

@neelchauhan neelchauhan Oct 17, 2018

So would it be okay to make count_acceptable_nodes() take in a direct, and make num_acceptable_routers in new_route_len() a sum of count_acceptable_nodes() with direct as 1 plus count_acceptable_nodes() with direct as 0?

Copy link
Contributor

@teor2345 teor2345 Oct 18, 2018

To make a path of length N, tor needs at least 1 direct entry node (guard, or bridge, or any node if not using entry guards) and at least N-1 indirect non-entry nodes.

We need to replace the simple test in new_route_len() with separate tests for direct and indirect, and update the log message as well.


if (num_acceptable_routers < routelen) {
if (num_acceptable_direct < 1 && num_acceptable_indirect < routelen - 1) {
Copy link
Contributor

@nmathewson nmathewson Oct 23, 2018

Should this be || instead of &&?

Copy link
Contributor

@teor2345 teor2345 Nov 5, 2018

I agree, it should be ||.
We need to fail if there are no entry nodes, or if there are not enough non-entry nodes to fill the route.

Copy link
Contributor

@teor2345 teor2345 left a comment

Looks good, just needs a few minor fixes.


if (num_acceptable_routers < routelen) {
if (num_acceptable_direct < 1 && num_acceptable_indirect < routelen - 1) {
Copy link
Contributor

@teor2345 teor2345 Nov 5, 2018

I agree, it should be ||.
We need to fail if there are no entry nodes, or if there are not enough non-entry nodes to fill the route.

log_info(LD_CIRC,
"Not enough acceptable routers (%d/%d). Discarding this circuit.",
num_acceptable_routers, routelen);
"Not enough acceptable routers (%d direct and %d indirect "
Copy link
Contributor

@teor2345 teor2345 Nov 5, 2018

Can you make this log entry say %d/%d direct and %d/%d indirect?

@torproject-pusher torproject-pusher merged commit 45b2816 into torproject:master Nov 7, 2018
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment