commit 6e225ce2e6fdd238f82a8b5a230052e1c423da00 Author: Arturo Filastò art@fuffa.org Date: Thu Aug 14 15:11:43 2014 +0200
Disconnect immediately after connecting to control and socks port so to leave the reactor clean. --- ooni/settings.py | 7 ++++--- ooni/tests/test_settings.py | 2 +- ooni/utils/net.py | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/ooni/settings.py b/ooni/settings.py index dd31801..08150f0 100644 --- a/ooni/settings.py +++ b/ooni/settings.py @@ -3,12 +3,13 @@ import sys import yaml import getpass
-from twisted.internet import defer, reactor, protocol +from twisted.internet import defer, reactor from twisted.internet.endpoints import TCP4ClientEndpoint, connectProtocol
from os.path import abspath, expanduser from scapy.all import get_if_list
+from ooni.utils.net import ConnectAndCloseProtocol from ooni import otime, geoip from ooni.utils import Storage, log from ooni import errors @@ -148,7 +149,7 @@ class OConfig(object): "localhost", self.tor.socks_port) try: - yield connectProtocol(socks_port_ep, protocol.Protocol()) + yield connectProtocol(socks_port_ep, ConnectAndCloseProtocol()) except Exception: incoherent.append('tor:socks_port')
@@ -157,7 +158,7 @@ class OConfig(object): "localhost", self.tor.control_port) try: - yield connectProtocol(control_port_ep, protocol.Protocol()) + yield connectProtocol(control_port_ep, ConnectAndCloseProtocol()) except Exception: incoherent.append('tor:control_port')
diff --git a/ooni/tests/test_settings.py b/ooni/tests/test_settings.py index 02a8503..e022a64 100644 --- a/ooni/tests/test_settings.py +++ b/ooni/tests/test_settings.py @@ -117,7 +117,7 @@ class TestSettings(ConfigTestCase): def test_check_tor_silly_listener(self): self.conf.advanced.start_tor = False self.conf.tor.socks_port = 9999 - self.conf.tor.control_port = 9998 + self.conf.tor.control_port = None self.run_silly_server() try: yield self.conf.check_tor() diff --git a/ooni/utils/net.py b/ooni/utils/net.py index 7580616..51d55e5 100644 --- a/ooni/utils/net.py +++ b/ooni/utils/net.py @@ -113,6 +113,10 @@ class Downloader(protocol.Protocol): self.finished.callback(None)
+class ConnectAndCloseProtocol(protocol.Protocol): + def connectionMade(self): + self.transport.loseConnection() + def getSystemResolver(): """ XXX implement a function that returns the resolver that is currently
tor-commits@lists.torproject.org