[tor-commits] [stem/master] Better ExitPolicy handling for the 'private' keyword and default suffix
atagar at torproject.org
atagar at torproject.org
Sun Sep 7 19:31:10 UTC 2014
commit 09940b6f3c0fa2f883cf07a144d7e319511b8d0e
Merge: 54de59a e0aeefb
Author: Damian Johnson <atagar at torproject.org>
Date: Sun Sep 7 12:02:30 2014 -0700
Better ExitPolicy handling for the 'private' keyword and default suffix
While working on ticket #10067 and arm I realized that it was clunky dealing
with a couple exit policy oddities...
* Policies tor's 'private' keyword expands to. These prefix our policy by
default and includes our public address, so it makes all exit policies
unique. Often we want to strip this off to get what the user *really*
specified.
* If the policy lacks an accept-all or reject-all rule at the end then tor
appends a default policy.
This is for...
https://trac.torproject.org/projects/tor/ticket/10107
With it our script in...
https://trac.torproject.org/projects/tor/ticket/10067#comment:9
... becomes *much* simpler...
from stem.descriptor import remote
policy_counts = {}
for desc in remote.DescriptorDownloader().get_server_descriptors():
policy = str(desc.exit_policy.strip_private().strip_default())
if desc.exit_policy.is_default():
policy += ', default' if policy else 'default'
policy_counts[policy] = policy_counts.setdefault(policy, 0) + 1
# exit policies sorted by their count
counts = sorted(policy_counts.values(), reverse = True)
for count in counts:
for policy, policy_count in policy_counts.items():
if count == policy_count:
print "%i %s" % (count, policy)
docs/change_log.rst | 1 +
stem/control.py | 7 +-
stem/exit_policy.py | 172 +++++++++++++++++++++++++++++++++++++--
test/unit/exit_policy/policy.py | 56 ++++++++++++-
4 files changed, 222 insertions(+), 14 deletions(-)
More information about the tor-commits
mailing list