I do know that there are other parts to #17835 (moved) and I will do them as separate pull requests. Changes to individual tickets will (probably) be done on the same PR as the original.
About testing:
I have tested this on a laptop running FreeBSD 12 connected to a router running Tomato Shibby and a Hurricane Electric IPv6 tunnel on a IPv4-only Verizon FiOS connection (FiOS is FTTH/GPON).
How I tested this: I used a custom torrc with ClientPreferIPv6ORPort to auto and EntryNodes to an IPv6-capable guard. As this is only the first step, there are times where I get IPv4 connections to the IPv6-supported guard and other times where I get IPv6 connections to the same guard.
I also set EntryNodes to an IPv4-only guard and get only IPv4 connections.
For the Tor developers reviewing this patch, you may or may not have IPv6 in your home or office to test this patch. If you don't, you could use HE's IPv6 tunnel or a testing network.
I do know that there are other parts to #17835 (moved) and I will do them as separate pull requests. Changes to individual tickets will (probably) be done on the same PR as the original.
About testing:
I have tested this on a laptop running FreeBSD 12 connected to a router running Tomato Shibby and a Hurricane Electric IPv6 tunnel on a IPv4-only Verizon FiOS connection (FiOS is FTTH/GPON).
How I tested this: I used a custom torrc with ClientPreferIPv6ORPort to auto and EntryNodes to an IPv6-capable guard. As this is only the first step, there are times where I get IPv4 connections to the IPv6-supported guard and other times where I get IPv6 connections to the same guard.
I also set EntryNodes to an IPv4-only guard and get only IPv4 connections.
What happens when you don't set EntryNodes?
For the Tor developers reviewing this patch, you may or may not have IPv6 in your home or office to test this patch. If you don't, you could use HE's IPv6 tunnel or a testing network.
Some Tor developers have native IPv6 on their servers, and they can give shell + compiler access.
Trac: Status: assigned to needs_revision Reviewer: N/Ato teor
The necessary changes have been made and committed. This has been done over a course of several days but I believe it can be reviewed now (and hopefully accepted, but it could also get rejected).
I am very confused by this branch, and I'm not sure if I can review it properly.
It seems to have:
one commit that makes most of the changes
three commits that make some log and comment changes
the same three commits that make some log and comment changes. Please don't add duplicate commits to a branch.
a merge
a bunch of extra commits that choose IP addresses randomly, but in different places all through the code
a commit that fixes the unit tests
Some of this is my fault, because I asked you to add ClientAutoIPv6ORPort, but then I talked about ClientPreferIPv6ORPort in the rest of my feedback.
Here's what this patch needs to do:
ClientPreferIPv6ORPort is an existing option, this patch must not change what it does
ClientAutoIPv6ORPort is a new option, it can do new things
Here's how we can move forward:
please open a new pull request like commit 1a98526, but using ClientAutoIPv6ORPort, rather than changing ClientPreferIPv6ORPort
please add the logging changes from commit 2311a42
please add new unit tests for ClientAutoIPv6ORPort (if the unit tests for ClientPreferIPv6ORPort fail, then you have changed how ClientPreferIPv6ORPort works)
Adding all those extra comments isn't as helpful as I thought it would be.
Let's just change the function comment on fascist_firewall_prefer_ipv6_orport().
I am not sure why the 4 "assign it a random preference" commits are needed.
I think it is enough for fascist_firewall_prefer_ipv6_orport() to return a random value when ClientAutoIPv6ORPort is 1.
Why do we need to choose at random in these places as well?
But we might need to change rewrite_node_address_for_bridge() so that we choose a random address when ClientAutoIPv6ORPort is 1.
But that is a simple change, because the code already calls fascist_firewall_prefer_ipv6_orport().
All we need to do it change:
"if (options->ClientPreferIPv6ORPort == -1) {"
to
"if (options->ClientPreferIPv6ORPort == -1 && options->ClientAutoIPv6ORPort == 0) {"
Then, when ClientAutoIPv6ORPort is 1, the code will choose at random.
However, this still lacks tests. At least right now, I don't see how I can fit tests into ClientAutoIPv6ORPort as the output can be random as a result of this function.
Also, should I check for ClientAutoIPv6ORPort is 1 in fascist_firewall_use_ipv6()? I have added an commit for it. If not, is it okay if I delete the commit 67e5a36?
However, this still lacks tests. At least right now, I don't see how I can fit tests into ClientAutoIPv6ORPort as the output can be random as a result of this function.
Here's how we can test functions with random outputs:
work out what the possible results are. Run the functions that have random results, and check that the actual result is one of the possible results.
mock the function that calls the random number generator, and check that other functions behave correctly with each of the possible inputs (in this case, 0 and 1)
test the tor binary in integration tests using shell scripts, python, or chutney
Also, should I check for ClientAutoIPv6ORPort is 1 in fascist_firewall_use_ipv6()? I have added an commit for it. If not, is it okay if I delete the commit 67e5a36?
fascist_firewall_use_ipv6() means "can this client use IPv6?"
So it needs to check for ClientAutoIPv6ORPort == 1. Let's keep the commit.