Open fpietrosanti opened 9 years ago
Cool, let me know if you need any additional functionality from txtorcon.
I literally just released v0.12.0 so everything in master is now in a release. Lunar is pretty fast at getting these in Debian, so it should be in jessie and wheezy-backports shortly...
For options, TorConfig queries the running tor for available options (or allows anything if you're using it in "build a torrc from scratch" mode). So config.Tor2webRendezvousPoints = ['whatever']
should "just work".
A good starting point would be the bottom part of https://github.com/meejah/txtorcon/blob/master/examples/launch_tor.py#L56
You can check the version immediately via a TorControlProtocol.version
or by doing a GETCONF on version
. A better way to support features, rather than looking at the version, is to simply ask if the feature is there. So in your case, that's doing GETINFO on config/names
and confirming your option is in there.
However, tor gives an error on startup if you've configured tor2web mode, but lack the right torrc option -- so you'll have to pass that in. I'll post an example here using launch_tor()
in a little bit.
great! thank you @meejah.
from txtorcon is it possible somehow to read if tor is compiled with the tor2web mode on?
probably we should provide an upstream patch to Tor in order to make possible to read this setting.
\cc @fpietrosanti @hellais
Not really, but it exits with an error if you start up a tor2web-enabled tor and don't have Tor2WebMode=1 in torrc (or, in this case, set in TorConfig instance). AND luckily it also exits with an error if you have Tor2WebMode=1 in a non-tor2web-enabled tor.
So, you should be good with: set Tor2WebMode=1 and if it starts up without error, you have a tor2web thing running.
Here's a complete example:
# launch a tor with tor2web mode
import sys
from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks
import txtorcon
@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
config = yield txtorcon.launch_tor(
config,
reactor,
tor_binary=tor_binary,
stdout=sys.stdout
)
print "done."
# we can set more options after if we like
config.Tor2WebRendezvousPoints = 'xxxxxxxxxxxx'
yield config.save()
print "quitting in 5 seconds"
reactor.callLater(5, lambda: reactor.quit())
tor_binary = None
if len(sys.argv) > 1:
tor_binary = sys.argv[1]
# Twisted's newer task APIs are nice
react(main, (tor_binary,))
Oh, BTW, to answer your question, I think you could do so by simply asking the config if it has Tor2WebMode set to 1. So proto.get_conf('Tor2WebMode')
where proto is a TorControlProtocol instance. This would be in case you just connected to a running Tor instead of launching one from withing your Python program.
Currently the configuration and setup of Tor for Tor2web is managed by installation howto + startup script.
This ticket is to integrate txtorcon by @meejah in the tor2web code, in order to manage the Tor process properly by configuring it, starting it, stopping it.
Particular care should be done to: a) test that the Tor installed is the one compiled with Tor2web-mode b) configure it with relevant performance tuning c) configure it, if available the right version, with advanced performance tuning such as https://trac.torproject.org/projects/tor/ticket/12844