Author: atagar Date: 2011-04-03 04:00:48 +0000 (Sun, 03 Apr 2011) New Revision: 24540
Modified: arm/trunk/armrc.sample arm/trunk/src/util/torTools.py Log: Giving a warning and prematurely aborting geoip lookups when the database is unavailble.
Modified: arm/trunk/armrc.sample =================================================================== --- arm/trunk/armrc.sample 2011-04-02 23:51:15 UTC (rev 24539) +++ arm/trunk/armrc.sample 2011-04-03 04:00:48 UTC (rev 24540) @@ -271,6 +271,7 @@ log.cursesColorSupport INFO log.bsdJailFound INFO log.unknownBsdJailId WARN +log.geoipUnavailable WARN log.stats.failedProcResolution DEBUG log.stats.procResolutionFailover INFO log.stats.failedPsResolution INFO
Modified: arm/trunk/src/util/torTools.py =================================================================== --- arm/trunk/src/util/torTools.py 2011-04-02 23:51:15 UTC (rev 24539) +++ arm/trunk/src/util/torTools.py 2011-04-03 04:00:48 UTC (rev 24540) @@ -90,6 +90,10 @@ "NS": "information related to the consensus will grow stale", "NEWCONSENSUS": "information related to the consensus will grow stale"}
+# number of sequential attempts before we decide that the Tor geoip database +# is unavailable +GEOIP_FAILURE_THRESHOLD = 5 + # provides int -> str mappings for torctl event runlevels TORCTL_RUNLEVELS = dict([(val, key) for (key, val) in TorUtil.loglevels.items()])
@@ -310,6 +314,9 @@ # directs TorCtl to notify us of events TorUtil.logger = self TorUtil.loglevel = "DEBUG" + + # tracks the number of sequential geoip lookup failures + self.geoipFailureCount = 0
def init(self, conn=None): """ @@ -445,6 +452,8 @@
self.connLock.acquire()
+ isGeoipRequest = param.startswith("ip-to-country/") + # checks if this is an arg caching covers isCacheArg = param in CACHE_ARGS
@@ -462,13 +471,23 @@ if isCacheArg and cachedValue: result = cachedValue isFromCache = True + elif isGeoipRequest and self.geoipFailureCount == GEOIP_FAILURE_THRESHOLD: + # the geoip database aleady looks to be unavailable - abort the request + raisedExc = TorCtl.ErrorReply("Tor geoip database is unavailable.") else: try: getInfoVal = self.conn.get_info(param)[param] if getInfoVal != None: result = getInfoVal + if isGeoipRequest: self.geoipFailureCount = 0 except (socket.error, TorCtl.ErrorReply, TorCtl.TorCtlClosed), exc: if type(exc) == TorCtl.TorCtlClosed: self.close() raisedExc = exc + + if isGeoipRequest: + self.geoipFailureCount += 1 + + if self.geoipFailureCount == GEOIP_FAILURE_THRESHOLD: + log.log(CONFIG["log.geoipUnavailable"], "Tor geoip database is unavailable.")
if isCacheArg and result and not isFromCache: self._cachedParam[param] = result
tor-commits@lists.torproject.org