[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r10601: Added exit_country as a configuration option in GeoIPConfig (torflow/trunk/TorCtl)
Author: renner
Date: 2007-06-14 10:03:09 -0400 (Thu, 14 Jun 2007)
New Revision: 10601
Modified:
torflow/trunk/TorCtl/GeoIPSupport.py
torflow/trunk/TorCtl/PathSupport.py
Log:
Added exit_country as a configuration option in GeoIPConfig and a SingleCountryRestriction
to create paths using nodes that are located in the same country.
Modified: torflow/trunk/TorCtl/GeoIPSupport.py
===================================================================
--- torflow/trunk/TorCtl/GeoIPSupport.py 2007-06-14 11:02:41 UTC (rev 10600)
+++ torflow/trunk/TorCtl/GeoIPSupport.py 2007-06-14 14:03:09 UTC (rev 10601)
@@ -86,15 +86,17 @@
def get_ip_dotted(self):
return socket.inet_ntoa(struct.pack('>I', self.ip))
-# Class to configure GeoIP-based path building
class GeoIPConfig:
- def __init__(self, unique_countries, src_country, crossings, excludes):
+ """ Class to configure GeoIP-based path building """
+ def __init__(self, unique_countries, entry_country, exit_country, max_crossings, excludes):
+ # TODO: Somehow ensure validity of the configuration
# Do not use a country twice in a route
self.unique_countries = unique_countries
- # Pass the country we are staying at for getting
- # Entry in src_country, None if not wished
- self.src_country = src_country
+ # entry in entry_country
+ self.entry_country = entry_country
+ # exit in exit_country
+ self.exit_country = exit_country
# Configure max continent crossings in one path
- self.max_cont_crossings = crossings
+ self.max_crossings = max_crossings
# List of countries to not use in routes
self.excludes = excludes
Modified: torflow/trunk/TorCtl/PathSupport.py
===================================================================
--- torflow/trunk/TorCtl/PathSupport.py 2007-06-14 11:02:41 UTC (rev 10600)
+++ torflow/trunk/TorCtl/PathSupport.py 2007-06-14 14:03:09 UTC (rev 10601)
@@ -18,7 +18,8 @@
"UniqueRestriction", "UniformGenerator", "OrderedExitGenerator",
"PathSelector", "Connection", "NickRestriction", "IdHexRestriction",
"PathBuilder", "SelectionManager", "CountryCodeRestriction",
-"CountryRestriction", "UniqueCountryRestriction", "ContinentRestriction",
+"CountryRestriction", "UniqueCountryRestriction",
+"SingleCountryRestriction", "ContinentRestriction",
"ContinentJumperRestriction"]
#################### Path Support Interfaces #####################
@@ -330,6 +331,14 @@
return False
return True
+# Ensure every router to have the same country
+class SingleCountryRestriction(PathRestriction):
+ def r_is_ok(self, path, router):
+ for r in path:
+ if router.country_code != r.country_code:
+ return False
+ return True
+
# Do not more than n continent crossings
class ContinentRestriction(PathRestriction):
def __init__(self, n):
@@ -504,21 +513,31 @@
entry_rstr.add_restriction(CountryCodeRestriction())
mid_rstr.add_restriction(CountryCodeRestriction())
self.exit_rstr.add_restriction(CountryCodeRestriction())
- # First hop in our country?
- src = self.geoip_config.src_country
- if src:
- entry_rstr.add_restriction(CountryRestriction(src))
- # Excludes
- plog("INFO", "Excluded countries: " + str(self.geoip_config.excludes))
- if len(self.geoip_config.excludes) > 0:
- entry_rstr.add_restriction(ExcludeCountriesRestriction(self.geoip_config.excludes))
- mid_rstr.add_restriction(ExcludeCountriesRestriction(self.geoip_config.excludes))
- self.exit_rstr.add_restriction(ExcludeCountriesRestriction(self.geoip_config.excludes))
- # Unique countries?
- if self.geoip_config.unique_countries:
- self.path_rstr.add_restriction(UniqueCountryRestriction())
+ # First hop in a specified country?
+ entry_country = self.geoip_config.entry_country
+ if entry_country:
+ entry_rstr.add_restriction(CountryRestriction(entry_country))
+ # Last hop in a specified country?
+ exit_country = self.geoip_config.exit_country
+ if exit_country:
+ self.exit_rstr.add_restriction(CountryRestriction(exit_country))
+ # Excluded countries
+ if self.geoip_config.excludes:
+ plog("INFO", "Excluded countries: " + str(self.geoip_config.excludes))
+ if len(self.geoip_config.excludes) > 0:
+ entry_rstr.add_restriction(ExcludeCountriesRestriction(self.geoip_config.excludes))
+ mid_rstr.add_restriction(ExcludeCountriesRestriction(self.geoip_config.excludes))
+ self.exit_rstr.add_restriction(ExcludeCountriesRestriction(self.geoip_config.excludes))
+ # Unique countries set? None --> pass
+ if self.geoip_config.unique_countries != None:
+ if self.geoip_config.unique_countries:
+ # If True: unique countries
+ self.path_rstr.add_restriction(UniqueCountryRestriction())
+ else:
+ # False: use the same country for all nodes in a path
+ self.path_rstr.add_restriction(SingleCountryRestriction())
# Specify max number of crossings here, None means ContinentJumper
- n = self.geoip_config.max_cont_crossings
+ n = self.geoip_config.max_crossings
if n == None:
self.path_rstr.add_restriction(ContinentJumperRestriction())
else: self.path_rstr.add_restriction(ContinentRestriction(n))