commit 46d428c6547262c5632adc9f6fb7d922e80beb4b Author: Arturo Filastò art@fuffa.org Date: Sat Mar 16 01:18:26 2013 +0100
Write a quick and dirty implementation of bridget. --- nettests/experimental/bridget.py | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
diff --git a/nettests/experimental/bridget.py b/nettests/experimental/bridget.py new file mode 100644 index 0000000..8f31e80 --- /dev/null +++ b/nettests/experimental/bridget.py @@ -0,0 +1,59 @@ +import random + +from twisted.python import usage +from twisted.internet import defer + +import txtorcon +from txtorcon.torconfig import TorSetupTimeout + +from ooni.utils import log +from ooni import nettest + +class UsageOptions(usage.Options): + optParameters = [['timeout', 't', 30, + 'Specify the timeout after which to consider the Tor bootstrapping process to have failed'] + ] + +class KeywordFiltering(nettest.NetTestCase): + name = "Bridget, at it's bare minimum" + author = "Arturo Filastò" + version = "0.1" + + usageOptions = UsageOptions + + inputFile = ['file', 'f', None, + 'File containing bridges to test reachability for (they should be one per line IP:ORPort)'] + + def setUp(self): + self.tor_progress = 0 + self.timeout = int(self.localOptions['timeout']) + self.report['timeout'] = self.timeout + + def test_full_tor_connection(self): + config = txtorcon.TorConfig() + config.OrPort = random.randint(2**14, 2**16) + config.SocksPort = random.randint(2**14, 2**16) + config.Bridge = self.input + config.UseBridges = 1 + + def updates(prog, tag, summary): + self.report['tor_progress'] = int(prog) + + d = txtorcon.launch_tor(config, reactor, progress_updates=updates, self.timeout) + @d.addCallback + def setup_complete(proto): + self.report['failed'] = False + + @d.addErrback + def setup_failed(failure): + failure.trap(TorSetupTimeout) + if isinstance(failure, TorSetupTimeout): + self.report['failure'] = 'timedout' + else: + self.report['failure'] = 'unknown' + self.report['failed'] = True + + return d + + def test_connect_scan(self): + pass