How to use the txtorcon.launch_tor function in txtorcon

To help you get started, we’ve selected a few txtorcon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meejah / txtorcon / walkthrough / 1_launch.py View on Github external
def main(reactor):
    config = txtorcon.TorConfig()
    config.ORPort = 0
    config.SocksPort = 9998
    try:
        os.mkdir('tor-data')
    except OSError:
        pass
    config.DataDirectory = './tor-data'

    try:
        process = yield txtorcon.launch_tor(
            config, reactor, progress_updates=progress
        )
    except Exception as e:
        print("Error launching tor:", e)
        return

    protocol = process.tor_protocol
    print("Tor has launched.")
    print("Protocol:", protocol)
    info = yield protocol.get_info('traffic/read', 'traffic/written')
    print(info)

    # explicitly stop tor by either disconnecting our protocol or the
    # Twisted IProcessProtocol (or just exit our program)
    print("Killing our tor, PID={pid}".format(pid=process.transport.pid))
    yield process.transport.signalProcess('TERM')
github meejah / txtorcon / examples / launch_tor_with_simplehttpd.py View on Github external
# Add the hidden service to a blank configuration
    config = txtorcon.TorConfig()
    config.SOCKSPort = 0
    config.ORPort = 9089
    config.HiddenServices = [
        txtorcon.HiddenService(
            config, hs_temp,
            ports=['%i %s:%i' % (hs_public_port, web_host, web_port)]
        )
    ]
    config.save()

    # Now launch tor
    # Notice that we use a partial function as a callback so we have a
    # reference to the config object when tor is fully running.
    tordeferred = txtorcon.launch_tor(config, reactor,
                                      progress_updates=print_tor_updates)
    tordeferred.addCallback(functools.partial(setup_complete, config,
                                              hs_public_port))
    tordeferred.addErrback(setup_failed)

    reactor.run()
github meejah / txtorcon / apps / exit_scanner / guard-exit-coverage.py View on Github external
task.LoopingCall(probe.print_update).start(60.0)

def setup_failed(arg):
    print "SETUP FAILED",arg
    print arg
    reactor.stop()

def update(percent, tag, summary):
    print "  %d%% %s" % (int(percent), summary)

print "Launching new Tor instance:"
config = txtorcon.TorConfig()
config.ControlPort = 9876
config.ORPort = 9002
config.SocksPort = 0
d = txtorcon.launch_tor(config, reactor, progress_updates=update)
d.addCallback(setup).addErrback(setup_failed)
reactor.run()
github meejah / txtorcon / examples / webui_server.py View on Github external
# This only properly works with one client (the last one to load the
# page). To work with multiples, we'd have to track all clients so
# sending async updates to them worked properly.
top_level = TorPage()

# minimal Tor configuration
config = txtorcon.TorConfig()
config.OrPort = 1234
config.SocksPort = 9999

# launch a Tor based on the above config; the callback will trigger
# when the TorControlProtocol and TorState instances are up and
# running (i.e. Tor process is launched, and we connected to it via
# control protocol and bootstrapped our notion of its state).
d = txtorcon.launch_tor(config, reactor, progress_updates=top_level.tor_update)
d.addCallback(top_level.set_tor_state)
d.addErrback(setup_failed)

print("Launching Tor and providing a Web interface on: \nhttp://localhost:8080\n")

# Start up the Web server
site = NevowSite(top_level)
reactor.listenTCP(8080, site)
reactor.run()
github meejah / txtorcon / examples / launch_tor_with_hiddenservice.py View on Github external
# next we set up our service to listen on hs_port which is forwarded
# (via the HiddenService options) from the hidden service address on
# port hs_public_port
site = server.Site(Simple())
hs_endpoint = TCP4ServerEndpoint(reactor, hs_port, interface='127.0.0.1')
hs_endpoint.listen(site)

# we've got our Twisted service listening locally and our options
# ready to go, so we now launch Tor. Once it's done (see above
# callbacks) we print out the .onion URI and then do "nothing"
# (i.e. let the Web server do its thing). Note that the way we've set
# up the slave Tor process, when we close the connection to it tor
# will exit.

d = txtorcon.launch_tor(config, reactor, progress_updates=updates)
d.addCallback(functools.partial(setup_complete, config))
d.addErrback(setup_failed)
reactor.run()
github ooni / backend / oonib / runner.py View on Github external
print("%d%%: %s" % (prog, summary))

            torconfig.SocksPort = config.main.socks_port
            if config.main.tor2webmode:
                torconfig.Tor2webMode = 1
                torconfig.CircuitBuildTimeout = 60
            if config.main.tor_datadir is None:
                self.temporary_data_dir = tempfile.mkdtemp()
                log.warn("Option 'tor_datadir' in oonib.conf is unspecified!")
                log.warn("Using %s" % self.temporary_data_dir)
                torconfig.DataDirectory = self.temporary_data_dir
            else:
                torconfig.DataDirectory = config.main.tor_datadir
            torconfig.save()
            if config.main.tor_binary is not None:
                d = launch_tor(torconfig, reactor,
                               tor_binary=config.main.tor_binary,
                               progress_updates=updates)
            else:
                d = launch_tor(torconfig, reactor, progress_updates=updates)
            return d