[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Added connection timeout to geoIP requests.
commit 989910435a48a7df612807717fc56ece9ce52832
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Tue Nov 27 14:16:53 2012 +0000
Added connection timeout to geoIP requests.
---
ooni/reporter.py | 19 ++++++++++++-------
ooni/utils/geodata.py | 16 ++++++++++++++--
ooniprobe.conf | 8 ++++++--
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 05ea94a..aec1e1b 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -19,16 +19,12 @@ from twisted.python.util import untilConcludes
from twisted.trial import reporter
from twisted.internet import defer, reactor
+from ooni import config
from ooni.templates.httpt import BodyReceiver, StringProducer
from ooni.utils import otime, log, geodata
-
from ooni.utils.hacks import OSafeRepresenter, OSafeDumper
-from ooni import config
try:
- ## Get rid of the annoying "No route found for
- ## IPv6 destination warnings":
- logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import packet
except:
class FooClass:
@@ -54,8 +50,17 @@ def getTestDetails(options):
config.privacy.includeasn or \
config.privacy.includecountry or \
config.privacy.includecity:
- log.msg("Running geo IP lookup via check.torproject.org")
- client_ip = yield geodata.myIP()
+ log.msg("Running geoIP lookup via check.torproject.org")
+ if config.privacy.checktimeout is not None and \
+ isinstance(config.privacy.checktimeout, int):
+ my_ip_timeout = config.privacy.checktimeout
+ else:
+ log.debug(
+ "reporter.getTestDetails(): bad config.privacy.checktimeout %s"
+ % str(config.privacy.checktimeout)
+ )
+ my_ip_timeout = 15
+ client_ip = yield geodata.myIP(connectTimeout=my_ip_timeout)
client_location = geodata.IPToLocation(client_ip)
else:
client_ip = "127.0.0.1"
diff --git a/ooni/utils/geodata.py b/ooni/utils/geodata.py
index 447d2eb..29fa59d 100644
--- a/ooni/utils/geodata.py
+++ b/ooni/utils/geodata.py
@@ -23,10 +23,22 @@ except ImportError:
log.err("Unable to import pygeoip. We will not be able to run geo IP related measurements")
@defer.inlineCallbacks
-def myIP():
+def myIP(*args, **kwargs):
+ """
+ Get the client's public IP address.
+
+ @param:
+ All parameters are passed to the instantiation of
+ :class:`twisted.client.Agent`.
+ @ivar connectTimeout:
+ Seconds to timeout after for HTTP requests.
+ """
target_site = 'https://check.torproject.org/'
regexp = "Your IP address appears to be: <b>(.+?)<\/b>"
- myAgent = Agent(reactor)
+ if 'connectTimeout' in kwargs:
+ myAgent = Agent(reactor, connectTimeout=connectTimeout)
+ else:
+ myAgent = Agent(reactor, *args, **kwargs)
result = yield myAgent.request('GET', target_site)
diff --git a/ooniprobe.conf b/ooniprobe.conf
index 191d809..e3a7198 100644
--- a/ooniprobe.conf
+++ b/ooniprobe.conf
@@ -6,8 +6,12 @@ basic:
# Where OONIProbe should be writing it's log file
logfile: /tmp/ooniprobe.log
privacy:
- # Should we include the IP address of the probe in the report?
+ # Should we include the client's IP address of the probe in the report?
+ # (Client IP is obtained by an HTTP request to https://check.torproject.org)
includeip: false
+ # If we're including the client's IP address, how long should we wait for
+ # the connection to complete before timing out?
+ checktimeout: 15
# Should we include the ASN of the probe in the report?
includeasn: false
# Should we include the ASN of the probe in the report?
@@ -24,4 +28,4 @@ advanced:
geoip_data_dir: /home/x/code/networking/ooni-probe/data/
debug: true
threadpool_size: 10
-
+ # Connection timeout in seconds for
\ No newline at end of file
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits