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

[tor-commits] [onionperf/master] Handles get_ip_address() output in case of dns failure



commit 2ea0296ebe7accd9842589902c0c6668cd8b8d5e
Author: Ana Custura <ana@xxxxxxxxxxxxx>
Date:   Thu Feb 28 15:52:10 2019 +0100

    Handles get_ip_address() output in case of dns failure
---
 onionperf/util.py | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/onionperf/util.py b/onionperf/util.py
index d4aebcf..c35e638 100644
--- a/onionperf/util.py
+++ b/onionperf/util.py
@@ -129,10 +129,29 @@ def find_ip_address_local():
     return ip_address
  
 def get_ip_address():
-    data = urllib.urlopen('https://check.torproject.org/').read()
-    ip_address = find_ip_address_url(data) 
-    if ip_address is None:
-        ip_address = find_ip_address_local() 
+    """
+    Determines the public IPv4 address of the vantage point using the
+    check.torproject.org service. If it is not possible to reach the service,
+    or to parse the result recieved, it will fall back to determining the local
+    IP address used for outbound connections.
+    """
+    ip_address = None
+    try:
+        data = urllib.urlopen('https://check.torproject.org/').read()
+        ip_address = find_ip_address_url(data)
+        if ip_address is None:
+            logging.error(
+                "Unable to determine IP address from check.torproject.org. "
+                "The site was successfully contacted but the result could "
+                "not be parsed. Maybe the service is down? Falling back to "
+                "finding your IP locally...")
+            ip_address = find_ip_address_local()
+    except IOError:
+        logging.warning(
+            "An IOError occured attempting to contact check.torproject.org. "
+            "This will affect measurements unless your machine has a public "
+            "IP address. Falling back to finding your IP locally...")
+        ip_address = find_ip_address_local()
     return ip_address
 
 def get_random_free_port():

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