diff options
author | Christopher Baines <cb15g11@soton.ac.uk> | 2014-03-02 22:35:49 +0000 |
---|---|---|
committer | Christopher Baines <cb15g11@soton.ac.uk> | 2014-03-02 22:35:49 +0000 |
commit | a1154731c83395f28c87a251de17d039f53eda7e (patch) | |
tree | 63d523ccf0e4a13e5eb9de37747d7297e8bbb62e /lib | |
parent | dfebf391444ce8d9deb622b6d53262439ff9270c (diff) | |
download | chutney-a1154731c83395f28c87a251de17d039f53eda7e.tar chutney-a1154731c83395f28c87a251de17d039f53eda7e.tar.gz |
Currently does get requests directly
Need to use
https://stem.torproject.org/tutorials/to_russia_with_love.html to go
through tor
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chutney/TorNet.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py index eb8c310..f1ebc08 100644 --- a/lib/chutney/TorNet.py +++ b/lib/chutney/TorNet.py @@ -23,6 +23,11 @@ import time import stem.control +from twisted.web import server, resource +from twisted.internet import reactor + +from treq import get + import chutney.Templating import chutney.Traffic @@ -420,6 +425,8 @@ class LocalNodeController(NodeController): if pid is None: return False + print("checking if " + str(pid) + " is running") + try: os.kill(pid, 0) # "kill 0" == "are you there?" except OSError, e: @@ -648,6 +655,7 @@ class Network(object): def start(self): print "Starting network" self._dfltEnv['start_time'] = time.time() + return self._start() def hup(self): @@ -655,6 +663,14 @@ class Network(object): return all([n.getController().hup() for n in self._nodes]) def stop(self): + + print("Closing all stem controllers") + for n in self._nodes: + if n._stemcontroller: + print("Closed stem controller") + n._stemcontroller.close() + print("Closed all stem controllers") + controllers = [ n.getController() for n in self._nodes ] for sig, desc in [(signal.SIGINT, "SIGINT"), (signal.SIGINT, "another SIGINT"), @@ -664,10 +680,13 @@ class Network(object): if c.isRunning(): c.stop(sig=sig) print "Waiting for nodes to finish." - for n in xrange(15): + for n in xrange(10): + print("loop " + str(n)) time.sleep(1) + print("after sleep") if all(not c.isRunning() for c in controllers): return + print("printing dot") sys.stdout.write(".") sys.stdout.flush() for c in controllers: @@ -707,6 +726,11 @@ def runConfigFile(verb, f): _GLOBALS = dict(_BASE_ENVIRON = _BASE_ENVIRON, Node=Node, EventType=stem.control.EventType, + server=server, + resource=resource, + reactor=reactor, + get=get, + time=time, _THE_NETWORK=_THE_NETWORK) exec f in _GLOBALS @@ -728,6 +752,7 @@ def runConfigFile(verb, f): def signal_handler(signal, frame): _THE_NETWORK.stop() + print("Network stoped, exiting") sys.exit(0) def main(): @@ -743,11 +768,13 @@ def main(): f = open(sys.argv[2]) result = runConfigFile(sys.argv[1], f) + print("run config file returns " + str(result)) if result is False: sys.exit(-1) - signal.signal(signal.SIGINT, signal_handler) - signal.pause() + if sys.argv[1] == "start": + signal.signal(signal.SIGINT, signal_handler) + signal.pause() return 0 |