[Pkg-privacy-commits] [txtorcon] 52/96: An example of launching a tor2web-enabled tor

Jérémy Bobbio lunar at moszumanska.debian.org
Sun Sep 6 18:33:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository txtorcon.

commit af1c9bc8e969861cb95e236e7d2bfb3f60dc2f7e
Author: meejah <meejah at meejah.ca>
Date:   Thu Feb 5 17:14:01 2015 -0700

    An example of launching a tor2web-enabled tor
---
 examples/launch_tor2web.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/examples/launch_tor2web.py b/examples/launch_tor2web.py
new file mode 100644
index 0000000..cf13b41
--- /dev/null
+++ b/examples/launch_tor2web.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+# launch a tor, and then connect a TorConfig object to it and
+# re-configure it. This allows us to determine what features the
+# running tor supports, *without* resorting to looking at version
+# numbers.
+
+import sys
+from twisted.internet.task import react
+from twisted.internet.defer import inlineCallbacks, Deferred
+import txtorcon
+
+
+ at inlineCallbacks
+def main(reactor, tor_binary):
+    config = txtorcon.TorConfig()
+    config.ORPort = 0
+    config.SOCKSPort = 0
+    config.Tor2WebMode = 1
+    # leaving ControlPort unset; launch_tor will choose one
+
+    print "Launching tor...", tor_binary
+    try:
+        yield txtorcon.launch_tor(
+            config,
+            reactor,
+            tor_binary=tor_binary,
+            stdout=sys.stdout
+        )
+        print "success! We support Tor2Web mode"
+
+    except RuntimeError as e:
+        print "There was a problem:", str(e)
+        print "We do NOT support Tor2Web mode"
+        return
+
+    print "quitting in 5 seconds"
+    reactor.callLater(5, lambda: reactor.stop())
+    yield Deferred()  # wait forever because we never .callback()
+
+
+if __name__ == '__main__':
+    tor_binary = None
+    if len(sys.argv) > 1:
+        tor_binary = sys.argv[1]
+    # Twisted's newer task APIs are nice
+    react(main, (tor_binary,))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/txtorcon.git



More information about the Pkg-privacy-commits mailing list