Exemple #1
0
    def experiment(self, args):
        log.msg("Doing test")
        # What you return here gets handed as input to control
        from ooni.lib.txtorcon import TorProtocolFactory, TorConfig, TorState
        from ooni.lib.txtorcon import DEFAULT_VALUE, launch_tor
        def updates(prog, tag, summary):
            log.msg("%d%%: %s" % (prog, summary))

        def setup_failed(args):
            log.msg("Setup Failed.")
            report.update({'failed': args})
            return report

        def setup_complete(proto):
            log.msg("Setup Complete.")
            report.update({'success': args})
            return report

        config = TorConfig()
        config.SocksPort = 9999
        config.OrPort = 1234
        if 'bridge' in args:
            config.UseBridges = 1
            config.Bridge = args['bridge']
        config.save()
        report = {'tor_config': config.config}
        log.msg("Starting Tor")
        d = launch_tor(config, reactor, progress_updates=updates)
        d.addCallback(setup_complete)
        d.addErrback(setup_failed)
        return d