Now here's a challenge: sbws should set ConnectionPadding 0 if the option is supported by Tor.
If the option isn't supported by Tor, then sbws should just continue.
You can test with Tor 0.2.9 (no padding support) and Tor 0.3.3 or later (padding support).
Here's a few things to try:
set the config option, and ignore the exception that stem returns for unsupported config options
use GETINFO config/names to see if the option is supported
Then the pull request adds custom code to ignore the ConnectionPadding option if tor doesn't support it. This code is more complicated than it needs to be, and it has bugs.
Here's a simpler design:
a list of torrc options in stem.py, containing 1., 2. and 4., with a flag saying when the option should be applied to tor (1. and 2. on launch, 4. after launch)
a custom list of torrc options that the user can configure for launch (same as 3.)
(There's an even simpler design in #28712 (moved) that makes 3. into a torrc file, but it's a breaking change.)
Once we refactor the torrc option code, we can add:
a flag to ignore failures when applying the option after launch
a torrc option table entry: ConnectionPadding, 0, apply after launch, ignore failures
Trac: Reviewer: N/Ato teor Status: needs_review to needs_revision
Which reminds me other refactoring i've been thinking for long ago: #28718 (moved).
Again, changing all the options system would be backwards-incompatible and would take same time.
Even if only stem.py uses these options, i think they should be in globals.py, since we might need to change them and globals.py should be the place where to change sbws defaults.
containing 1., 2. and 4., with a flag saying when the option should be applied to tor (1. and 2. on launch, 4. after launch)
a custom list of torrc options that the user can configure for launch (same as 3.)
(There's an even simpler design in #28712 (moved) that makes 3. into a torrc file, but it's a breaking change.)
we use stem.util.conf, let tor launch fail when options can't be parsed and inform the operator
we extend stem.util.conf to become a torrc parser
we implement a full torrc parser
we accept torrc options only in the form of an INI file, which would be parsed by ConfigParser and converted to the stem's torrc dictionary (i'm not sure which cases might fail here either)
Even if only stem.py uses these options, i think they should be in globals.py, since we might need to change them and globals.py should be the place where to change sbws defaults.
Why write a parser, when tor will parse lines for us?
Options:
we use stem.util.conf, let tor launch fail when options can't be parsed and inform the operator
we extend stem.util.conf to become a torrc parser
we implement a full torrc parser
we accept torrc options only in the form of an INI file, which would be parsed by ConfigParser and converted to the stem's torrc dictionary (i'm not sure which cases might fail here either)
Option 4 is #28737 (moved), and it should work reasonably well. But it's a new feature, so it belongs in sbws 1.1.
stop trying to merge sbws options with the same name (#28738 (moved)), until we refactor in sbws 1.1 (#28737 (moved))
Then tell the operator if tor doesn't like the options.
Now the option bugs are dealt with in other tickets, let's talk about this ticket.
Here's a simple algorithm for ignoring failing options:
sbws has OPTIONS, a hard-coded list of options and values, and CAN_FAIL, a hard-coded, ordered list of options that are allowed to fail
Try launching tor with OPTIONS
If tor fails to launch:
if CAN_FAIL is not empty, remove the first option in CAN_FAIL from OPTIONS, and go to step 2
otherwise, exit sbws with an error
Log a message with the Tor version, and the CAN_FAIL options that were removed from OPTIONS
Let's put this new code in a new function. launch_tor is already almost 100 lines long.