[or-cvs] r18687: {torctl} Fix up GeoIP support and exit setting to play with cookies e (torctl/trunk/python/TorCtl)

mikeperry at seul.org mikeperry at seul.org
Tue Feb 24 11:14:35 UTC 2009


Author: mikeperry
Date: 2009-02-24 06:14:34 -0500 (Tue, 24 Feb 2009)
New Revision: 18687

Modified:
   torctl/trunk/python/TorCtl/GeoIPSupport.py
   torctl/trunk/python/TorCtl/PathSupport.py
Log:

Fix up GeoIP support and exit setting to play with cookies
easier.



Modified: torctl/trunk/python/TorCtl/GeoIPSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/GeoIPSupport.py	2009-02-24 10:15:09 UTC (rev 18686)
+++ torctl/trunk/python/TorCtl/GeoIPSupport.py	2009-02-24 11:14:34 UTC (rev 18687)
@@ -3,6 +3,7 @@
 import struct
 import socket
 import TorCtl
+import StatsSupport
 
 from TorUtil import plog
 try:
@@ -86,7 +87,9 @@
   if record != None:
     return record['country_code']
 
-class GeoIPRouter(TorCtl.Router):  
+class GeoIPRouter(TorCtl.Router):
+  # TODO: Its really shitty that this has to be a TorCtl.Router
+  # and can't be a StatsRouter..
   """ Router class extended to GeoIP """
   def __init__(self, router):
     self.__dict__ = router.__dict__
@@ -105,9 +108,10 @@
     return socket.inet_ntoa(struct.pack('>I', self.ip))
 
 class GeoIPConfig:
-  """ Class to configure GeoIP-based path building """		    
-  def __init__(self, unique_countries, continent_crossings, ocean_crossings,
-     entry_country, middle_country, exit_country, excludes): 
+  """ Class to configure GeoIP-based path building """
+  def __init__(self, unique_countries=None, continent_crossings=4,
+     ocean_crossings=None, entry_country=None, middle_country=None,
+     exit_country=None, excludes=None):
     # TODO: Somehow ensure validity of a configuration:
     #   - continent_crossings >= ocean_crossings
     #   - unique_countries=False --> continent_crossings!=None

Modified: torctl/trunk/python/TorCtl/PathSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/PathSupport.py	2009-02-24 10:15:09 UTC (rev 18686)
+++ torctl/trunk/python/TorCtl/PathSupport.py	2009-02-24 11:14:34 UTC (rev 18687)
@@ -965,6 +965,7 @@
     )
 
     if self.exit_id:
+      self._set_exit(self.exit_id)
       plog("DEBUG", "Applying Setexit: "+self.exit_id)
       self.exit_rstr = NodeRestrictionList([IdHexRestriction(self.exit_id)])
     elif self.use_all_exits:
@@ -1045,22 +1046,25 @@
          exitgen, self.path_rstr)
       return
 
-  def set_exit(self, exit_name):
+  def _set_exit(self, exit_name):
     # sets an exit, if bad, sets bad_exit
     exit_id = None
-    self.exit_rstr.clear()
     if exit_name:
       if exit_name[0] == '$':
         exit_id = exit_name
       elif exit_name in self.consensus.name_to_key:
         exit_id = self.consensus.name_to_key[exit_name]
     self.exit_id = exit_id
-    if not exit_id or exit_id[1:] not in self.consensus.routers \
-            or self.consensus.routers[exit_id[1:]].down:
-      plog("NOTICE", "Requested downed exit "+str(exit_id))
+
+  def set_exit(self, exit_name):
+    self._set_exit(exit_name)
+    self.exit_rstr.clear()
+    if not self.exit_id or self.exit_id[1:] not in self.consensus.routers \
+            or self.consensus.routers[self.exit_id[1:]].down:
+      plog("NOTICE", "Requested downed exit "+str(self.exit_id))
       self.bad_restrictions = True
     else:
-      self.exit_rstr.add_restriction(IdHexRestriction(exit_id))
+      self.exit_rstr.add_restriction(IdHexRestriction(self.exit_id))
       try:
         self.path_selector.exit_gen.rebuild()
         self.bad_restrictions = False



More information about the tor-commits mailing list