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

[tor-commits] [bridgedb/master] Fix bug in proxy.loadProxiesFromFile().



commit d9f44fabf0922f1d76a6d313b42ef7ed61ce4977
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Sat Mar 28 02:38:42 2015 +0000

    Fix bug in proxy.loadProxiesFromFile().
    
    Checking `if proxySet` when the ProxySet was empty (as at server
    startup, particularly when loading the PROXY_LIST_FILES), would evaluate
    to False, cause the proxies from the files *not* to be loaded into the
    empty ProxySet.
    
    This did not effect loading the list of Tor Exit relays, since we use
    scripts/get-tor-exits and load the list into memory while calling
    ProxySet.add() for each one (rather than loading Tor Exit relays from a
    downloaded file, like we used to do).
---
 lib/bridgedb/proxy.py |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/bridgedb/proxy.py b/lib/bridgedb/proxy.py
index fe575b3..3940ed6 100644
--- a/lib/bridgedb/proxy.py
+++ b/lib/bridgedb/proxy.py
@@ -79,14 +79,17 @@ def loadProxiesFromFile(filename, proxySet=None, removeStale=False):
     logging.info("Reloading proxy lists...")
 
     addresses = []
-    if proxySet:
+
+    # We have to check the instance because, if the ProxySet was newly
+    # created, it will likely be empty, causing it to evaluate to False:
+    if isinstance(proxySet, ProxySet):
         oldProxySet = proxySet.copy()
 
     try:
         with open(filename, 'r') as proxyFile:
             for line in proxyFile.readlines():
                 line = line.strip()
-                if proxySet:
+                if isinstance(proxySet, ProxySet):
                     # ProxySet.add() will validate the IP address
                     if proxySet.add(line, tag=filename):
                         logging.info("Added %s to the proxy list." % line)
@@ -98,7 +101,7 @@ def loadProxiesFromFile(filename, proxySet=None, removeStale=False):
     except Exception as error:
         logging.warn("Error while reading a proxy list file: %s" % str(error))
 
-    if proxySet:
+    if isinstance(proxySet, ProxySet):
         stale = list(oldProxySet.difference(addresses))
 
         if removeStale:



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