[tor-commits] [stem/master] Vastly lowering memory usage for exit policies

atagar at torproject.org atagar at torproject.org
Fri Dec 7 06:54:07 UTC 2012


commit bbd702c81e1923bfbab236d0d3649fd2f87b3d95
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Dec 6 22:05:07 2012 -0800

    Vastly lowering memory usage for exit policies
    
    A pox upon good indentions. When dealing with microdescriptor exit policies I
    enumerated all ports involved, the goal being to provide constant time
    is_match() lookups. We certainly did that, but there's quite a few valid ports
    and enumerating them for all relays has consistantly cost so much memory on my
    system that it triggers the OOM killer.
    
    Dropping the port set optimization. Memory usage trumps is_match() performance.
    Reading the full consensus into memory now takes 5.5% of the memory on my
    netbook, verses before where it would locked me up.
---
 stem/exit_policy.py |   12 ------------
 1 files changed, 0 insertions(+), 12 deletions(-)

diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index ce56551..a6ae028 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -264,7 +264,6 @@ class MicrodescriptorExitPolicy(ExitPolicy):
     BEGIN request, and might get end-reason-exit-policy if they guessed
     wrong, in which case they'll have to try elsewhere.
   
-  :var set ports: ports that this policy includes
   :var bool is_accept: **True** if these are ports that we accept, **False** if
     they're ports that we reject
   
@@ -279,7 +278,6 @@ class MicrodescriptorExitPolicy(ExitPolicy):
     #   PortList ::= PortList "," PortOrRange
     #   PortOrRange ::= INT "-" INT / INT
     
-    self.ports = set()
     self._policy = policy
     
     if policy.startswith("accept"):
@@ -305,7 +303,6 @@ class MicrodescriptorExitPolicy(ExitPolicy):
       
       try:
         rule = ExitPolicyRule(rule_str)
-        self.ports.update(range(rule.min_port, rule.max_port + 1))
         rules.append(rule)
       except ValueError, exc:
         exc_msg = "Policy '%s' is malformed. %s" % (self._policy, str(exc).replace(rule_str, port_entry))
@@ -313,15 +310,6 @@ class MicrodescriptorExitPolicy(ExitPolicy):
     
     super(MicrodescriptorExitPolicy, self).__init__(*rules)
   
-  def can_exit_to(self, address = None, port = None):
-    # we can greatly simplify our check since our policies don't concern
-    # addresses or masks
-    
-    if port in self.ports:
-      return self.is_accept
-    else:
-      return not self.is_accept
-  
   def __str__(self):
     return self._policy
   





More information about the tor-commits mailing list