[tor-commits] [ooni-probe/master] Rename tcp_connect to be uniform to other names

art at torproject.org art at torproject.org
Tue Dec 3 17:09:39 UTC 2013


commit b7a263863dd3c62d915c18513c24e555a7a58fa0
Author: Arturo Filastò <art at fuffa.org>
Date:   Wed Nov 27 22:23:07 2013 +0100

    Rename tcp_connect to be uniform to other names
---
 ooni/nettests/blocking/tcp_connect.py |   69 +++++++++++++++++++++++++++++++++
 ooni/nettests/blocking/tcpconnect.py  |   69 ---------------------------------
 2 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/ooni/nettests/blocking/tcp_connect.py b/ooni/nettests/blocking/tcp_connect.py
new file mode 100644
index 0000000..5b432e0
--- /dev/null
+++ b/ooni/nettests/blocking/tcp_connect.py
@@ -0,0 +1,69 @@
+# -*- encoding: utf-8 -*-
+from twisted.internet.protocol import Factory, Protocol
+from twisted.internet.endpoints import TCP4ClientEndpoint
+
+from twisted.internet.error import ConnectionRefusedError
+from twisted.internet.error import TCPTimedOutError, TimeoutError
+
+from ooni import nettest
+from ooni.errors import handleAllFailures
+from ooni.utils import log
+
+class TCPFactory(Factory):
+    def buildProtocol(self, addr):
+        return Protocol()
+
+class TCPConnectTest(nettest.NetTestCase):
+    name = "TCP Connect"
+    author = "Arturo Filastò"
+    version = "0.1"
+    inputFile = ['file', 'f', None,
+            'File containing the IP:PORT combinations to be tested, one per line']
+
+    requiredOptions = ['file']
+    def test_connect(self):
+        """
+        This test performs a TCP connection to the remote host on the specified port.
+        the report will contains the string 'success' if the test has
+        succeeded, or the reason for the failure if it has failed.
+        """
+        host, port = self.input.split(":")
+        def connectionSuccess(protocol):
+            protocol.transport.loseConnection()
+            log.debug("Got a connection to %s" % self.input)
+            self.report["connection"] = 'success'
+
+        def connectionFailed(failure):
+            self.report['connection'] = handleAllFailures(failure)
+
+        from twisted.internet import reactor
+        point = TCP4ClientEndpoint(reactor, host, int(port))
+        d = point.connect(TCPFactory())
+        d.addCallback(connectionSuccess)
+        d.addErrback(connectionFailed)
+        return d
+
+    def inputProcessor(self, filename=None):
+        """
+        This inputProcessor extracts name:port pairs from urls
+        XXX: Does not support unusual port numbers
+        """
+        def strip_url(address):
+            proto, path = x.strip().split('://')
+            proto = proto.lower()
+            host = path.split('/')[0]
+            if proto == 'http':
+                return "%s:80" % host
+            if proto == 'https':
+                return "%s:443" % host
+
+        if filename:
+            fp = open(filename)
+            for x in fp.readlines():
+                if x.startswith("http"):
+                    yield strip_url(x)
+                else:
+                    yield x.strip()
+            fp.close()
+        else:
+            pass
diff --git a/ooni/nettests/blocking/tcpconnect.py b/ooni/nettests/blocking/tcpconnect.py
deleted file mode 100644
index 5b432e0..0000000
--- a/ooni/nettests/blocking/tcpconnect.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# -*- encoding: utf-8 -*-
-from twisted.internet.protocol import Factory, Protocol
-from twisted.internet.endpoints import TCP4ClientEndpoint
-
-from twisted.internet.error import ConnectionRefusedError
-from twisted.internet.error import TCPTimedOutError, TimeoutError
-
-from ooni import nettest
-from ooni.errors import handleAllFailures
-from ooni.utils import log
-
-class TCPFactory(Factory):
-    def buildProtocol(self, addr):
-        return Protocol()
-
-class TCPConnectTest(nettest.NetTestCase):
-    name = "TCP Connect"
-    author = "Arturo Filastò"
-    version = "0.1"
-    inputFile = ['file', 'f', None,
-            'File containing the IP:PORT combinations to be tested, one per line']
-
-    requiredOptions = ['file']
-    def test_connect(self):
-        """
-        This test performs a TCP connection to the remote host on the specified port.
-        the report will contains the string 'success' if the test has
-        succeeded, or the reason for the failure if it has failed.
-        """
-        host, port = self.input.split(":")
-        def connectionSuccess(protocol):
-            protocol.transport.loseConnection()
-            log.debug("Got a connection to %s" % self.input)
-            self.report["connection"] = 'success'
-
-        def connectionFailed(failure):
-            self.report['connection'] = handleAllFailures(failure)
-
-        from twisted.internet import reactor
-        point = TCP4ClientEndpoint(reactor, host, int(port))
-        d = point.connect(TCPFactory())
-        d.addCallback(connectionSuccess)
-        d.addErrback(connectionFailed)
-        return d
-
-    def inputProcessor(self, filename=None):
-        """
-        This inputProcessor extracts name:port pairs from urls
-        XXX: Does not support unusual port numbers
-        """
-        def strip_url(address):
-            proto, path = x.strip().split('://')
-            proto = proto.lower()
-            host = path.split('/')[0]
-            if proto == 'http':
-                return "%s:80" % host
-            if proto == 'https':
-                return "%s:443" % host
-
-        if filename:
-            fp = open(filename)
-            for x in fp.readlines():
-                if x.startswith("http"):
-                    yield strip_url(x)
-                else:
-                    yield x.strip()
-            fp.close()
-        else:
-            pass





More information about the tor-commits mailing list