[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Lazyloading server descriptor exit policy



commit eff8ecec5381f852317638b1ebc8f6893a955761
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Jan 5 07:40:19 2015 -0800

    Lazyloading server descriptor exit policy
    
    Oops, missed this attribute since it's not part of our parse method.
    Lazyloading this one's actually pretty impaceful, shaving off another 0.5s from
    my runtimes (a 13% improvement).
---
 stem/descriptor/server_descriptor.py |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index f936d13..e8d6e74 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -457,16 +457,17 @@ class ServerDescriptor(Descriptor):
 
     entries, policy = _get_descriptor_components(raw_contents, validate, ('accept', 'reject'))
 
-    if policy == [str_type('reject *:*')]:
-      self.exit_policy = REJECT_ALL_POLICY
-    else:
-      self.exit_policy = stem.exit_policy.ExitPolicy(*policy)
-
     if validate:
+      if policy == [str_type('reject *:*')]:
+        self.exit_policy = REJECT_ALL_POLICY
+      else:
+        self.exit_policy = stem.exit_policy.ExitPolicy(*policy)
+
       self._parse(entries, validate)
       self._check_constraints(entries)
     else:
       self._entries = entries
+      self._exit_policy_list = policy
 
   def digest(self):
     """
@@ -717,6 +718,13 @@ class ServerDescriptor(Descriptor):
           _parse_history_line(self, self._entries['read-history'][0][0], True)
         elif name in ('write_history_end', 'write_history_interval', 'write_history_values'):
           _parse_history_line(self, self._entries['write-history'][0][0], False)
+        elif name == 'exit_policy':
+          if self._exit_policy_list == [str_type('reject *:*')]:
+            self.exit_policy = REJECT_ALL_POLICY
+          else:
+            self.exit_policy = stem.exit_policy.ExitPolicy(*self._exit_policy_list)
+
+          del self._exit_policy_list
       except (ValueError, KeyError):
         if name == 'exit_policy_v6':
           default = DEFAULT_IPV6_EXIT_POLICY



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits