[or-cvs] [torflow/master 69/92] Don't refetch on SOCKS errors

mikeperry at torproject.org mikeperry at torproject.org
Sat Aug 21 05:14:01 UTC 2010


Author: John M. Schanck <john at anomos.info>
Date: Wed, 11 Aug 2010 14:08:09 -0400
Subject: Don't refetch on SOCKS errors
Commit: 5f7d1e0863cdbb34039c07d2865521395438523d

---
 NetworkScanners/ExitAuthority/libsoat.py |    3 ++-
 NetworkScanners/ExitAuthority/soat.py    |   29 ++++++++++++++++-------------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/NetworkScanners/ExitAuthority/libsoat.py b/NetworkScanners/ExitAuthority/libsoat.py
index 476e54a..c80a2d0 100644
--- a/NetworkScanners/ExitAuthority/libsoat.py
+++ b/NetworkScanners/ExitAuthority/libsoat.py
@@ -54,7 +54,7 @@ __all__ = [ # Classes
            "FALSEPOSITIVE_HTTPERRORS", "FALSEPOSITIVE_DYNAMIC", "FALSEPOSITIVE_DYNAMIC_TOR",
            "FALSEPOSITIVE_DEADSITE",
            "E_SOCKS", "E_POLICY", "E_NETUNREACH", "E_HOSTUNREACH", "E_REFUSED",
-           "E_TIMEOUT", "E_SLOWXFER", "E_NOCONTENT", "E_CRYPTO", "E_URL", "E_MISC",
+           "E_TIMEOUT", "E_SLOWXFER", "E_NOCONTENT", "E_CRYPTO", "E_URL", "E_MISC", "SOCKS_ERRS",
            # Exception classes
            "SlowXferException", "RedirectException", "NoURLsFound",
           ]
@@ -135,6 +135,7 @@ E_CRYPTO = -14.0
 E_URL = -15.0
 E_MISC = -99.0
 
+SOCKS_ERRS = (E_SOCKS, E_POLICY, E_NETUNREACH, E_HOSTUNREACH, E_REFUSED, E_TIMEOUT, E_SOCKSIPY1, E_SOCKSIPY2, E_SOCKSIPY3)
 # classes to use with pickle to dump test results into files
 
 class TestResult(object):
diff --git a/NetworkScanners/ExitAuthority/soat.py b/NetworkScanners/ExitAuthority/soat.py
index 1e087fc..ba9d914 100755
--- a/NetworkScanners/ExitAuthority/soat.py
+++ b/NetworkScanners/ExitAuthority/soat.py
@@ -1116,28 +1116,30 @@ class BaseHTTPTest(Test):
     exit_node = "$"+exit_node.idhex
     if pcode - (pcode % 100) != 200:
       plog("NOTICE", exit_node+" had error "+str(pcode)+" fetching content for "+address)
-      # Restore cookie jars
-      # XXX: This is odd and possibly wrong for the refetch
-      self.cookie_jar = orig_cookie_jar
-      self.tor_cookie_jar = orig_tor_cookie_jar
-      BindingSocket.bind_to = refetch_ip
-      (code_new, resp_headers_new, new_cookies_new, mime_type_new, content_new) = http_request(address, orig_tor_cookie_jar, self.headers)
-      BindingSocket.bind_to = None
 
-      if code_new == pcode:
-        if 300 <= pcode < 400: # Redirects
+      if pcode not in SOCKS_ERRS: # Do a refetch for non-SOCKS errors only
+        # Restore cookie jars
+        # XXX: This is odd and possibly wrong for the refetch
+        self.cookie_jar = orig_cookie_jar
+        self.tor_cookie_jar = orig_tor_cookie_jar
+        BindingSocket.bind_to = refetch_ip
+        (code_new, resp_headers_new, new_cookies_new, mime_type_new, content_new) = http_request(address, orig_tor_cookie_jar, self.headers)
+        BindingSocket.bind_to = None
+
+        if code_new == pcode and 300 <= pcode < 400: # Target introduced a redirect
           plog("NOTICE", "Non-Tor HTTP "+str(code_new)+" redirect from "+address+" to "+str(content_new))
           # Remove the original URL and add the redirect to our targets (if it's of the right type)
           self.remove_target(address, INCONCLUSIVE_REDIRECT)
           self.add_target(content_new)
           return TEST_INCONCLUSIVE
-        else:
+        elif code_new == pcode: # Target introduced some other change
           plog("NOTICE", "Non-tor HTTP error "+str(code_new)+" fetching content for "+address)
           # Just remove it
           self.remove_target(address, FALSEPOSITIVE_HTTPERRORS)
           return TEST_INCONCLUSIVE
 
-      #  Error code      Failure reason         Register method                Set extra_info to pcontent?
+      # Error => behavior lookup table
+      #  Error code     (Failure reason,        Register method,               Set extra_info to pcontent?)
       err_lookup = \
         {E_SOCKS:       (FAILURE_CONNERROR,     self.register_connect_failure, True), # "General socks error"
          E_POLICY:      (FAILURE_EXITPOLICY,    self.register_connect_failure, True), # "connection not allowed aka ExitPolicy
@@ -1152,15 +1154,16 @@ class BaseHTTPTest(Test):
         }
       if pcode in err_lookup:
         fail_reason, register, extra_info = err_lookup[pcode]
-      elif 300 <= pcode < 400: # Redirects
+      elif 300 <= pcode < 400: # Exit node introduced a redirect
         plog("NOTICE", "Tor only HTTP "+str(pcode)+" redirect from "+address+" to "+str(pcontent))
         fail_reason = FAILURE_REDIRECT
         register = self.register_http_failure
         extra_info = True
-      else:
+      else: # Exit node introduced some other change
         fail_reason = FAILURE_BADHTTPCODE+str(pcode)
         register = self.register_exit_failure
         extra_info = True
+
       result = HttpTestResult(self.node_map[exit_node[1:]],
                             address, TEST_FAILURE, fail_reason)
       if extra_info:
-- 
1.7.1




More information about the tor-commits mailing list