[tor-commits] [arm/master] Dropping locales when geoip db is unavailable

atagar at torproject.org atagar at torproject.org
Tue Apr 26 02:15:57 UTC 2011


commit 1161a6a6e72dff62fe019b9d15cc0943958359f7
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Apr 25 19:13:43 2011 -0700

    Dropping locales when geoip db is unavailable
    
    Previously the connection panel showed '??' for all locales when the geoip
    database was unavailable. Dropping these entries from the interface entirely
    instead.
---
 src/interface/connections/connEntry.py |    3 ++-
 src/util/torTools.py                   |   14 +++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/interface/connections/connEntry.py b/src/interface/connections/connEntry.py
index f613fc2..e6c0d92 100644
--- a/src/interface/connections/connEntry.py
+++ b/src/interface/connections/connEntry.py
@@ -824,8 +824,9 @@ class ConnectionLine(entries.ConnectionPanelLine):
           dstAddress += " (%s)" % purpose
       elif not connections.isIpAddressPrivate(self.foreign.getIpAddr()):
         extraInfo = []
+        conn = torTools.getConn()
         
-        if includeLocale:
+        if includeLocale and not conn.isGeoipUnavailable():
           foreignLocale = self.foreign.getLocale("??")
           extraInfo.append(foreignLocale)
           spaceAvailable -= len(foreignLocale) + 2
diff --git a/src/util/torTools.py b/src/util/torTools.py
index 31a7061..0eebd20 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -474,19 +474,19 @@ class Controller(TorCtl.PostEventListener):
       if isCacheArg and cachedValue:
         result = cachedValue
         isFromCache = True
-      elif isGeoipRequest and self.geoipFailureCount == GEOIP_FAILURE_THRESHOLD:
+      elif isGeoipRequest and self.isGeoipUnavailable():
         # 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
+          if isGeoipRequest: self.geoipFailureCount = -1
         except (socket.error, TorCtl.ErrorReply, TorCtl.TorCtlClosed), exc:
           if type(exc) == TorCtl.TorCtlClosed: self.close()
           raisedExc = exc
           
-          if isGeoipRequest:
+          if isGeoipRequest and not self.geoipFailureCount == -1:
             self.geoipFailureCount += 1
             
             if self.geoipFailureCount == GEOIP_FAILURE_THRESHOLD:
@@ -833,6 +833,14 @@ class Controller(TorCtl.PostEventListener):
     
     return result
   
+  def isGeoipUnavailable(self):
+    """
+    Provides true if we've concluded that our geoip database is unavailable,
+    false otherwise.
+    """
+    
+    return self.geoipFailureCount == GEOIP_FAILURE_THRESHOLD
+  
   def getMyPid(self):
     """
     Provides the pid of the attached tor process (None if no controller exists



More information about the tor-commits mailing list