commit 0237bcfb340498a45081f935642ac0e28db74e55 Author: Arturo Filastò art@fuffa.org Date: Sat Mar 1 13:04:36 2014 +0100
Rename bridget to bridge_reachability --- nettests/experimental/bridget.py | 89 ------------------------- ooni/nettests/blocking/bridge_reachability.py | 89 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 89 deletions(-)
diff --git a/nettests/experimental/bridget.py b/nettests/experimental/bridget.py deleted file mode 100644 index acce3d3..0000000 --- a/nettests/experimental/bridget.py +++ /dev/null @@ -1,89 +0,0 @@ -# -*- encoding: utf-8 -*- -import random -import string -import subprocess -from distutils.spawn import find_executable - -from twisted.python import usage -from twisted.internet import defer, reactor - -import txtorcon - -from ooni.utils import log -from ooni import nettest - -class UsageOptions(usage.Options): - optParameters = [['timeout', 't', 60, - 'Specify the timeout after which to consider the Tor bootstrapping process to have failed'], - ] - -class BridgeReachability(nettest.NetTestCase): - name = "BridgeReachability" - 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 - self.bridge = self.input - self.pyobfsproxy_bin = find_executable('obfsproxy') - - def test_full_tor_connection(self): - def getTransport(address): - """ - If the address of the bridge starts with a valid c identifier then - we consider it to be a bridge. - Returns: - The transport_name if it's a transport. - None if it's not a obfsproxy bridge. - """ - transport_name = address.split(' ')[0] - transport_name_chars = string.ascii_letters + string.digits - if all(c in transport_name_chars for c in transport_name): - return transport_name - else: - return None - - config = txtorcon.TorConfig() - config.ControlPort = random.randint(2**14, 2**16) - config.SocksPort = random.randint(2**14, 2**16) - - transport_name = getTransport(self.bridge) - if transport_name and self.pyobfsproxy_bin: - config.ClientTransportPlugin = "%s exec %s managed" % (transport_name, self.pyobfsproxy_bin) - self.report['transport_name'] = transport_name - elif transport_name and not self.pyobfsproxy_bin: - log.err("Unable to test bridge because pyobfsproxy is not installed") - self.report['success'] = None - return - - config.Bridge = self.bridge - config.UseBridges = 1 - config.save() - - def updates(prog, tag, summary): - print "Tor progress: %s%%" % prog - self.report['tor_progress'] = int(prog) - self.report['tor_progress_tag'] = tag - self.report['tor_progress_summary'] = summary - - d = txtorcon.launch_tor(config, reactor, timeout=self.timeout, - progress_updates=updates) - @d.addCallback - def setup_complete(proto): - print "Success" - self.report['success'] = True - - @d.addErrback - def setup_failed(failure): - print "Failed" - log.exception(failure) - self.report['success'] = False - - return d diff --git a/ooni/nettests/blocking/bridge_reachability.py b/ooni/nettests/blocking/bridge_reachability.py new file mode 100644 index 0000000..acce3d3 --- /dev/null +++ b/ooni/nettests/blocking/bridge_reachability.py @@ -0,0 +1,89 @@ +# -*- encoding: utf-8 -*- +import random +import string +import subprocess +from distutils.spawn import find_executable + +from twisted.python import usage +from twisted.internet import defer, reactor + +import txtorcon + +from ooni.utils import log +from ooni import nettest + +class UsageOptions(usage.Options): + optParameters = [['timeout', 't', 60, + 'Specify the timeout after which to consider the Tor bootstrapping process to have failed'], + ] + +class BridgeReachability(nettest.NetTestCase): + name = "BridgeReachability" + 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 + self.bridge = self.input + self.pyobfsproxy_bin = find_executable('obfsproxy') + + def test_full_tor_connection(self): + def getTransport(address): + """ + If the address of the bridge starts with a valid c identifier then + we consider it to be a bridge. + Returns: + The transport_name if it's a transport. + None if it's not a obfsproxy bridge. + """ + transport_name = address.split(' ')[0] + transport_name_chars = string.ascii_letters + string.digits + if all(c in transport_name_chars for c in transport_name): + return transport_name + else: + return None + + config = txtorcon.TorConfig() + config.ControlPort = random.randint(2**14, 2**16) + config.SocksPort = random.randint(2**14, 2**16) + + transport_name = getTransport(self.bridge) + if transport_name and self.pyobfsproxy_bin: + config.ClientTransportPlugin = "%s exec %s managed" % (transport_name, self.pyobfsproxy_bin) + self.report['transport_name'] = transport_name + elif transport_name and not self.pyobfsproxy_bin: + log.err("Unable to test bridge because pyobfsproxy is not installed") + self.report['success'] = None + return + + config.Bridge = self.bridge + config.UseBridges = 1 + config.save() + + def updates(prog, tag, summary): + print "Tor progress: %s%%" % prog + self.report['tor_progress'] = int(prog) + self.report['tor_progress_tag'] = tag + self.report['tor_progress_summary'] = summary + + d = txtorcon.launch_tor(config, reactor, timeout=self.timeout, + progress_updates=updates) + @d.addCallback + def setup_complete(proto): + print "Success" + self.report['success'] = True + + @d.addErrback + def setup_failed(failure): + print "Failed" + log.exception(failure) + self.report['success'] = False + + return d