Skip to content

Instantly share code, notes, and snippets.

@hellais
Created November 7, 2012 01:33
Show Gist options
  • Save hellais/4028998 to your computer and use it in GitHub Desktop.
Save hellais/4028998 to your computer and use it in GitHub Desktop.
Starting a tor process and not making it stop
import txtorcon
from twisted.internet import defer
from ooni.utils import log
from ooni import nettest
class ExampleTorProcess(nettest.NetTestCase):
name = "Example Tor Process"
def tearDown(self):
pass
def test_tor_process(self):
def state_complete(state):
for c in state.circuits.values():
print "These are my circuits"
print c
# Do here all your other stuff
# If you don't want the test run to finish keep returning 'em
# deferreds and the test will go on.
def setup_complete(proto):
state = txtorcon.TorState(proto.tor_protocol)
state.post_bootstrap.addCallback(state_complete)
state.post_bootstrap.addErrback(setup_failed)
return state.post_bootstrap
def setup_failed(arg):
print "SETUP FAILED",arg
config = txtorcon.TorConfig()
config.OrPort = 1234
config.SocksPort = 9999
def updates(prog, tag, summary):
print "%d%%: %s" % (prog, summary)
from twisted.internet import reactor
d = txtorcon.launch_tor(config, reactor, progress_updates=updates)
d.addCallback(setup_complete)
d.addErrback(setup_failed)
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment