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

[tor-commits] [stem/master] Abort 'GETINFO ip-to-country' earlier if unavailable



commit 94c46dda15faac31cb9524edbe312491432ab5cc
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Sep 23 15:40:05 2017 -0700

    Abort 'GETINFO ip-to-country' earlier if unavailable
    
    Probably not really impactful, but little point in doing cache lookups when
    it's unavailable.
---
 stem/control.py                 | 8 ++++----
 test/unit/control/controller.py | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index a03835b9..796aa016 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1141,6 +1141,10 @@ class Controller(BaseController):
       is_multiple = True
       params = set(params)
 
+    for param in params:
+      if param.startswith('ip-to-country/') and param != 'ip-to-country/0.0.0.0' and self.is_geoip_unavailable():
+        raise stem.ProtocolError('Tor geoip database is unavailable')
+
     # check for cached results
 
     from_cache = [param.lower() for param in params]
@@ -1151,10 +1155,6 @@ class Controller(BaseController):
       reply[user_expected_key] = cached_results[key]
       params.remove(user_expected_key)
 
-    for param in params:
-      if param.startswith('ip-to-country/') and param != 'ip-to-country/0.0.0.0' and self.is_geoip_unavailable():
-        raise stem.ProtocolError('Tor geoip database is unavailable')
-
     # if everything was cached then short circuit making the query
     if not params:
       if LOG_CACHE_FETCHES:
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index ae5be387..8b5d6c8f 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -311,6 +311,7 @@ class TestControl(unittest.TestCase):
     )
 
     for response in invalid_responses:
+      self.controller.clear_cache()
       get_info_mock.return_value = response
       self.assertRaises(stem.ProtocolError, self.controller.get_socks_listeners)
 

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