commit df1d0a17c2e920167a03f268c379700d9f559332 Merge: f34ac80 6d5cb08 Author: teor teor2345@gmail.com Date: Thu Oct 2 02:25:43 2014 +1000
Merge branch 'issue-13161-typos' into issue-13161-check-torrc-options
Fix a single typo in lib/chutney/TorNet.py
lib/chutney/TorNet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --cc lib/chutney/TorNet.py index 87f1abe,32dc173..f18503a --- a/lib/chutney/TorNet.py +++ b/lib/chutney/TorNet.py @@@ -223,68 -220,10 +223,68 @@@ class LocalNodeBuilder(NodeBuilder) torrc_template = self._getTorrcTemplate() output = torrc_template.format(self._env) if checkOnly: - # XXXX Is it time-cosuming to format? If so, cache here. + # XXXX Is it time-consuming to format? If so, cache here. return + # now filter the options we're about to write, commenting out + # the options that the current tor binary doesn't support + tor = self._env['tor'] + # find the options the current tor binary supports, and cache them + if tor not in _TORRC_OPTIONS: + # Note: some versions of tor (e.g. 0.2.4.23) require + # --list-torrc-options to be the first argument + cmdline = [ + tor, + "--list-torrc-options", + "--hush"] + try: + opts = subprocess.check_output(cmdline, + bufsize=-1, + universal_newlines=True) + except OSError as e: + # only catch file not found error + if e.errno == errno.ENOENT: + print ("Cannot find tor binary %r. Use " + "CHUTNEY_TOR environment variable to set the " + "path, or put the binary into $PATH.") % tor + sys.exit(0) + else: + raise + # check we received a list of options, and nothing else + assert re.match(r'(^\w+$)+', opts, flags=re.MULTILINE) + torrc_opts = opts.split() + # cache the options for this tor binary's path + _TORRC_OPTIONS[tor] = torrc_opts + else: + torrc_opts = _TORRC_OPTIONS[tor] + # check if each option is supported before writing it + # TODO: what about unsupported values? + # e.g. tor 0.2.4.23 doesn't support TestingV3AuthInitialVoteDelay 2 + # but later version do. I say throw this one to the user. with open(fn_out, 'w') as f: - f.write(output) + # we need to do case-insensitive option comparison + # even if this is a static whitelist, + # so we convert to lowercase as close to the loop as possible + lower_opts = [opt.lower() for opt in torrc_opts] + # keep ends when splitting lines, so we can write them out + # using writelines() without messing around with "\n"s + for line in output.splitlines(True): + # check if the first word on the line is a supported option, + # preserving empty lines and comment lines + sline = line.strip() + if (len(sline) == 0 + or sline[0] == '#' + or sline.split()[0].lower() in lower_opts): + f.writelines([line]) + else: + # well, this could get spammy + # TODO: warn once per option per tor binary + # TODO: print tor version? + print ("The tor binary at %r does not support the " + "option in the torrc line:\n" + "%r") % (tor, line.strip()) + # we could decide to skip these lines entirely + # TODO: write tor version? + f.writelines(["# " + tor + " unsupported: " + line])
def _getTorrcTemplate(self): """Return the template used to write the torrc for this node."""
tor-commits@lists.torproject.org