The parameter router_purpose for purpose_needs_anonymity did not change the logic flow. In every case, unless the dir_purpose matched specific cases, the function would return true.
The cases in is_sensitive_dir_purpose are compatible with purpose_needs_anonymity, so these two functions could easily be merged.The logic is in purpose_needs_anonymity is inverted- purpose_needs_anonymity returns true by default, unless in the specified cases, whereas is_sensitive_dir_purpose returned false unless certain cases were met.
I struggled to write a clean/simple comment for purpose_needs_anonymity is accurate, please review!
I wrote the unit tests to have names which describe their intended behavior. In each test, it states the expected behavior, under the given condition. However, because of column length, the wording for the test names is abbreviated, please let me know if the naming is confusing.
In general, it looks great, and I would really like to get rid of is_sensitive_dir_purpose. But I think we need to keep router_purpose in purpose_needs_anonymity.
Otherwise, we change the logic from:
if you're a bridge, do everything anonymously,
otherwise, do some things non-anonymously,
otherwise, do everything else anonymously,
to:
regardless of whether you're a bridge or not,
do some things non-anonymously,
otherwise, do everything else anonymously,
Trac: Reviewer: N/Ato teor Status: new to needs_revision Keywords: N/Adeleted, 030-proposed, TorCoreTeam201610 added
Hey! It isn't clear what cases should be tested for router_purpose in purpose_needs_anonymity.
In the previous code, purpose_needs_anonymity returned true by default, and the only router_purpose case that was tested would return also true. So removing this case doesn't (from what I can see!) change the logic flow.
Outside of directory.c, this functionality is used in two other places, neither of which test whether the router purpose is a bridge (as is done throughout directory.c).
This refactor also assumes that the same conditions met by purpose_needs_anonymity also hold for is_sensitive_dir_purpose. is_sensitive_dir_purpose was more restrictive though.
One minor nitpick on the switch refactor:
Some compilers will complain if a switch statement doesn't have a default: case. I'm not sure whether we have that warning turned on by default, but let's be nice to people who do.