#include <torcontrol.h>
Signals | |
void | started () |
void | startFailed (QString errmsg) |
void | stopped (int exitCode, QProcess::ExitStatus exitStatus) |
void | connected () |
void | connectFailed (QString errmsg) |
void | disconnected () |
void | connected (bool connected) |
Public Member Functions | |
TorControl () | |
~TorControl () | |
void | start () |
bool | stop (QString *errmsg=0) |
bool | isRunning () |
bool | isVidaliaRunningTor () |
void | connect () |
void | disconnect () |
bool | isConnected () |
bool | authenticate (QString *errmsg=0) |
bool | getInfo (QHash< QString, QString > &map, QString *errmsg=0) |
bool | getInfo (QString key, QString &val, QString *errmsg=0) |
bool | signal (TorSignal::Signal sig, QString *errmsg=0) |
QString | getTorVersionString () |
quint32 | getTorVersion () |
bool | setEvent (TorEvents::TorEvent e, QObject *obj, bool add, bool set=true, QString *errmsg=0) |
bool | setLogEvents (uint filter, QObject *obj, QString *errmsg=0) |
bool | setEvents (QString *errmsg=0) |
bool | setConf (QHash< QString, QString > map, QString *errmsg=0) |
bool | setConf (QString key, QString value, QString *errmsg=0) |
bool | getConf (QHash< QString, QString > &map, QString *errmsg=0) |
bool | getConf (QString key, QString &value, QString *errmsg=0) |
bool | saveConf (QString *errmsg=0) |
bool | resetConf (QStringList keys, QString *errmsg=0) |
bool | resetConf (QString key, QString *errmsg=0) |
RouterDescriptor | getDescriptorByName (QString name, QString *errmsg=0) |
RouterDescriptor | getDescriptorById (QString id, QString *errmsg=0) |
QList< RouterDescriptor > | getDescriptorListByName (QStringList names, QString *errmsg=0) |
QList< RouterDescriptor > | getDescriptorListById (QStringList ids, QString *errmsg=0) |
QList< RouterDescriptor > | getRouterList (QString *errmsg=0) |
QStringList | getRouterIDList (QString *errmsg=0) |
QList< Circuit > | getCircuits (QString *errmsg=0) |
QList< Stream > | getStreams (QString *errmsg=0) |
Private Slots | |
void | onStarted () |
void | onStartFailed (QString errmsg) |
void | onStopped (int exitCode, QProcess::ExitStatus exitStatus) |
void | onConnected () |
void | onConnectFailed (QString errmsg) |
void | onDisconnected () |
void | onLogStdout (QString severity, QString message) |
Private Member Functions | |
bool | send (ControlCommand cmd, ControlReply &reply, QString *errmsg=0) |
bool | send (ControlCommand cmd, QString *errmsg=0) |
void | closeTorProcess () |
Private Attributes | |
ControlConnection * | _controlConn |
TorProcess * | _torProcess |
TorService * | _torService |
TorEvents | _torEvents |
QString | _torVersion |
Definition at line 42 of file torcontrol.h.
TorControl::TorControl | ( | ) |
Default constructor
Create an instance of a connection to Tor's control interface and give it an object to use to handle asynchronous events.
Definition at line 36 of file torcontrol.cpp.
References _controlConn, _torEvents, _torProcess, _torService, connected(), connectFailed(), disconnected(), onConnected(), onConnectFailed(), and onDisconnected().
TorControl::~TorControl | ( | ) |
Default destructor
Definition at line 60 of file torcontrol.cpp.
References _controlConn, disconnect(), isConnected(), isVidaliaRunningTor(), and stop().
void TorControl::start | ( | ) |
Start the Tor process
Definition at line 76 of file torcontrol.cpp.
References _torProcess, _torService, TorSettings::getArguments(), TorSettings::getExecutable(), TorSettings::getTorrc(), TorSettings::getUseService(), isRunning(), TorService::isSupported(), onLogStdout(), onStarted(), onStartFailed(), onStopped(), TorProcess::start(), TorService::start(), started(), startFailed(), and touch_file().
Referenced by MainWindow::start().
bool TorControl::stop | ( | QString * | errmsg = 0 |
) |
Stop the Tor process
Definition at line 141 of file torcontrol.cpp.
References _torProcess, isRunning(), TorSignal::Shutdown, TorProcess::stop(), and stopped().
Referenced by MainWindow::close(), MainWindow::connectFailed(), onConnected(), MainWindow::stop(), and ~TorControl().
bool TorControl::isRunning | ( | ) |
Detect if the Tor process is running
Definition at line 202 of file torcontrol.cpp.
References _torProcess, TorSettings::getControlAddress(), TorSettings::getControlPort(), net_test_connect(), and TorProcess::pid().
Referenced by MainWindow::MainWindow(), AboutDialog::show(), start(), and stop().
bool TorControl::isVidaliaRunningTor | ( | ) |
Detects if the Tor process is running under Vidalia.
Definition at line 192 of file torcontrol.cpp.
References _torProcess, and TorProcess::pid().
Referenced by MainWindow::close(), onDisconnected(), and ~TorControl().
void TorControl::connect | ( | ) |
Connect to Tor's control socket
Definition at line 227 of file torcontrol.cpp.
References _controlConn, ControlConnection::connect(), TorSettings::getControlAddress(), and TorSettings::getControlPort().
Referenced by MainWindow::connectFailed(), and MainWindow::started().
void TorControl::disconnect | ( | ) |
Disconnect from Tor's control socket
Definition at line 269 of file torcontrol.cpp.
References _controlConn, ControlConnection::disconnect(), and isConnected().
Referenced by MainWindow::close(), onStopped(), and ~TorControl().
bool TorControl::isConnected | ( | ) |
Check if we're connected to Tor's control socket
Definition at line 302 of file torcontrol.cpp.
References _controlConn, ControlConnection::Connected, and ControlConnection::status().
Referenced by MainWindow::close(), disconnect(), ServerSettings::isServerEnabled(), ServerPage::save(), setEvent(), setLogEvents(), ServerPage::updateServerIP(), ServerSettings::value(), and ~TorControl().
bool TorControl::authenticate | ( | QString * | errmsg = 0 |
) |
Sends an authentication token to Tor
Definition at line 339 of file torcontrol.cpp.
References TorSettings::getAuthToken(), and send().
Referenced by onConnected().
bool TorControl::getInfo | ( | QHash< QString, QString > & | map, | |
QString * | errmsg = 0 | |||
) |
Sends a GETINFO message to Tor based on the given keys
Definition at line 352 of file torcontrol.cpp.
References ControlCommand::addArgument(), ControlReply::getLines(), and send().
Referenced by getInfo(), and onConnected().
bool TorControl::getInfo | ( | QString | key, | |
QString & | val, | |||
QString * | errmsg = 0 | |||
) |
Sends a GETINFO message for a single info value to Tor
Definition at line 379 of file torcontrol.cpp.
References getInfo().
bool TorControl::signal | ( | TorSignal::Signal | sig, | |
QString * | errmsg = 0 | |||
) |
Sends a signal to Tor
Definition at line 393 of file torcontrol.cpp.
References _controlConn, ControlCommand::addArgument(), TorSignal::Halt, send(), ControlConnection::send(), TorSignal::Shutdown, and TorSignal::toString().
Referenced by MainWindow::initiateServerShutdown(), and MainWindow::newIdentity().
QString TorControl::getTorVersionString | ( | ) |
Returns Tor's version as a string.
Definition at line 405 of file torcontrol.cpp.
References _torVersion.
Referenced by getTorVersion(), and AboutDialog::show().
quint32 TorControl::getTorVersion | ( | ) |
Returns Tor's version as a numeric value.
Definition at line 413 of file torcontrol.cpp.
References getTorVersionString().
Referenced by NetViewer::circuitPathIDs().
bool TorControl::setEvent | ( | TorEvents::TorEvent | e, | |
QObject * | obj, | |||
bool | add, | |||
bool | set = true , |
|||
QString * | errmsg = 0 | |||
) |
Sets an event and its handler. If add is true, then the event is added, otherwise it is removed. If set is true, then the given event will be registered with Tor.
Definition at line 433 of file torcontrol.cpp.
References _torEvents, TorEvents::add(), isConnected(), TorEvents::remove(), and setEvents().
Referenced by BandwidthGraph::BandwidthGraph(), NetViewer::NetViewer(), and setLogEvents().
bool TorControl::setLogEvents | ( | uint | filter, | |
QObject * | obj, | |||
QString * | errmsg = 0 | |||
) |
Registers for a set of logging events according to the given filter.
Definition at line 451 of file torcontrol.cpp.
References LogEvent::Debug, LogEvent::Error, LogEvent::Info, isConnected(), TorEvents::LogDebug, TorEvents::LogError, TorEvents::LogInfo, TorEvents::LogNotice, TorEvents::LogWarn, LogEvent::Notice, setEvent(), setEvents(), and LogEvent::Warn.
Referenced by MessageLog::registerLogEvents().
bool TorControl::setEvents | ( | QString * | errmsg = 0 |
) |
Register events of interest with Tor
Definition at line 463 of file torcontrol.cpp.
References _torEvents, ControlCommand::addArgument(), TorEvents::eventList(), send(), and TorEvents::toString().
Referenced by onConnected(), setEvent(), and setLogEvents().
bool TorControl::setConf | ( | QHash< QString, QString > | map, | |
QString * | errmsg = 0 | |||
) |
Sets each configuration key in map to the value associated with its key.
Definition at line 477 of file torcontrol.cpp.
References ControlCommand::addArgument(), and send().
Referenced by ServerSettings::apply(), and setConf().
bool TorControl::setConf | ( | QString | key, | |
QString | value, | |||
QString * | errmsg = 0 | |||
) |
Sets a single configuration key to the given value.
Definition at line 496 of file torcontrol.cpp.
References setConf().
bool TorControl::getConf | ( | QHash< QString, QString > & | map, | |
QString * | errmsg = 0 | |||
) |
Gets a set of configuration keyvalues and stores them in map.
Definition at line 505 of file torcontrol.cpp.
References ControlCommand::addArgument(), ControlReply::getLines(), and send().
Referenced by getConf(), ServerSettings::isServerEnabled(), and ServerSettings::value().
bool TorControl::getConf | ( | QString | key, | |
QString & | value, | |||
QString * | errmsg = 0 | |||
) |
Gets a single configuration keyvalue.
Definition at line 532 of file torcontrol.cpp.
References getConf().
bool TorControl::saveConf | ( | QString * | errmsg = 0 |
) |
Asks Tor to save the current configuration to its torrc
Definition at line 546 of file torcontrol.cpp.
References send().
Referenced by ServerSettings::apply().
bool TorControl::resetConf | ( | QStringList | keys, | |
QString * | errmsg = 0 | |||
) |
Tells Tor to reset the given configuration keys back to defaults.
Definition at line 554 of file torcontrol.cpp.
References ControlCommand::addArgument(), and send().
Referenced by ServerSettings::apply(), and resetConf().
bool TorControl::resetConf | ( | QString | key, | |
QString * | errmsg = 0 | |||
) |
Tells Tor to reset a configuration key back to its default value.
Definition at line 568 of file torcontrol.cpp.
References resetConf().
RouterDescriptor TorControl::getDescriptorByName | ( | QString | name, | |
QString * | errmsg = 0 | |||
) |
Gets a descriptor for the given router name.
Definition at line 575 of file torcontrol.cpp.
References getDescriptorListByName().
Referenced by NetViewer::circuitPathIDs().
RouterDescriptor TorControl::getDescriptorById | ( | QString | id, | |
QString * | errmsg = 0 | |||
) |
Gets a descriptor for the given router ID.
Definition at line 590 of file torcontrol.cpp.
References getDescriptorListById().
Referenced by NetViewer::circuitPathNames().
QList< RouterDescriptor > TorControl::getDescriptorListByName | ( | QStringList | names, | |
QString * | errmsg = 0 | |||
) |
Gets descriptors for the given list of router names.
Definition at line 605 of file torcontrol.cpp.
References ControlCommand::addArgument(), ControlReply::getLines(), and send().
Referenced by getDescriptorByName().
QList< RouterDescriptor > TorControl::getDescriptorListById | ( | QStringList | ids, | |
QString * | errmsg = 0 | |||
) |
Gets descriptors for the given list of router IDs.
Definition at line 636 of file torcontrol.cpp.
References ControlCommand::addArgument(), ControlReply::getLines(), and send().
Referenced by getDescriptorById(), getRouterList(), and NetViewer::loadDescriptors().
QList< RouterDescriptor > TorControl::getRouterList | ( | QString * | errmsg = 0 |
) |
Gets a list of descriptors for all routers Tor knows about.
Definition at line 677 of file torcontrol.cpp.
References getDescriptorListById(), and getRouterIDList().
QStringList TorControl::getRouterIDList | ( | QString * | errmsg = 0 |
) |
Gets a list of router IDs for all routers Tor knows about.
Definition at line 687 of file torcontrol.cpp.
References ControlReply::getMessage(), and send().
Referenced by getRouterList(), and NetViewer::refresh().
QList< Circuit > TorControl::getCircuits | ( | QString * | errmsg = 0 |
) |
Gets a list of current circuits.
Definition at line 715 of file torcontrol.cpp.
References Circuit::fromString(), ControlReply::getData(), ControlReply::getMessage(), Circuit::isEmpty(), and send().
Referenced by NetViewer::loadConnections().
QList< Stream > TorControl::getStreams | ( | QString * | errmsg = 0 |
) |
Gets a list of current streams.
Definition at line 743 of file torcontrol.cpp.
References Stream::fromString(), ControlReply::getData(), ControlReply::getMessage(), Stream::isEmpty(), and send().
Referenced by NetViewer::loadConnections().
void TorControl::started | ( | ) | [signal] |
Emitted when the Tor process has started
Referenced by onStarted(), and start().
void TorControl::startFailed | ( | QString | errmsg | ) | [signal] |
Emitted when the Tor process fails to start.
Referenced by onStartFailed(), and start().
void TorControl::stopped | ( | int | exitCode, | |
QProcess::ExitStatus | exitStatus | |||
) | [signal] |
Emitted when the Tor process has stopped
Referenced by onDisconnected(), onStopped(), and stop().
void TorControl::connected | ( | ) | [signal] |
Emitted when the controller has connected to Tor
Referenced by onConnected(), onDisconnected(), and TorControl().
void TorControl::connectFailed | ( | QString | errmsg | ) | [signal] |
Emitted when the controller failed to connect to Tor.
Referenced by onConnected(), onConnectFailed(), and TorControl().
void TorControl::disconnected | ( | ) | [signal] |
Emitted when the controller has disconnected from Tor
Referenced by onDisconnected(), and TorControl().
void TorControl::connected | ( | bool | connected | ) | [signal] |
Emitted when the connection status changes.
bool TorControl::send | ( | ControlCommand | cmd, | |
ControlReply & | reply, | |||
QString * | errmsg = 0 | |||
) | [private] |
Send a message to Tor and read the response
Definition at line 312 of file torcontrol.cpp.
References _controlConn, ControlReply::getMessage(), ControlReply::getStatus(), and ControlConnection::send().
Referenced by authenticate(), getCircuits(), getConf(), getDescriptorListById(), getDescriptorListByName(), getInfo(), getRouterIDList(), getStreams(), resetConf(), saveConf(), send(), setConf(), setEvents(), and signal().
bool TorControl::send | ( | ControlCommand | cmd, | |
QString * | errmsg = 0 | |||
) | [private] |
Send a message to Tor and discard the response
Definition at line 327 of file torcontrol.cpp.
References send().
void TorControl::closeTorProcess | ( | ) | [private] |
Disconnects signals from the TorProcess and frees its memory.
Definition at line 177 of file torcontrol.cpp.
References _torProcess, and _torService.
Referenced by onStartFailed(), and onStopped().
void TorControl::onStarted | ( | ) | [private, slot] |
Emits a signal that the Tor process started
Definition at line 123 of file torcontrol.cpp.
References started().
Referenced by start().
void TorControl::onStartFailed | ( | QString | errmsg | ) | [private, slot] |
Emits a signal that the Tor process failed to start and includes an error message (hopefully) indicating why.
Definition at line 131 of file torcontrol.cpp.
References closeTorProcess(), and startFailed().
Referenced by start().
void TorControl::onStopped | ( | int | exitCode, | |
QProcess::ExitStatus | exitStatus | |||
) | [private, slot] |
Emits a signal that the Tor process stopped
Definition at line 162 of file torcontrol.cpp.
References _controlConn, ControlConnection::cancelConnect(), closeTorProcess(), ControlConnection::Connecting, disconnect(), ControlConnection::status(), and stopped().
Referenced by start().
void TorControl::onConnected | ( | ) | [private, slot] |
Emits a signal that the control socket successfully established a connection to Tor.
Definition at line 237 of file torcontrol.cpp.
References _torProcess, _torVersion, authenticate(), TorProcess::closeStdout(), connected(), connectFailed(), getInfo(), setEvents(), and stop().
Referenced by TorControl().
void TorControl::onConnectFailed | ( | QString | errmsg | ) | [private, slot] |
Emits a signal that the control connection to Tor failed.
Definition at line 262 of file torcontrol.cpp.
References connectFailed().
Referenced by TorControl().
void TorControl::onDisconnected | ( | ) | [private, slot] |
Emits a signal that the control socket disconnected from Tor
Definition at line 278 of file torcontrol.cpp.
References _torProcess, _torVersion, connected(), disconnected(), isVidaliaRunningTor(), TorProcess::openStdout(), and stopped().
Referenced by TorControl().
void TorControl::onLogStdout | ( | QString | severity, | |
QString | message | |||
) | [private, slot] |
Called when Tor has printed a log message to stdout.
Definition at line 218 of file torcontrol.cpp.
References _torEvents, TorEvents::dispatch(), CustomEventType::LogEvent, LogEvent::toSeverity(), and TorEvents::toTorEvent().
Referenced by start().
ControlConnection* TorControl::_controlConn [private] |
Instantiates a connection used to talk to Tor's control port
Definition at line 145 of file torcontrol.h.
Referenced by connect(), disconnect(), isConnected(), onStopped(), send(), signal(), TorControl(), and ~TorControl().
TorProcess* TorControl::_torProcess [private] |
Manages and monitors the Tor process
Definition at line 147 of file torcontrol.h.
Referenced by closeTorProcess(), isRunning(), isVidaliaRunningTor(), onConnected(), onDisconnected(), start(), stop(), and TorControl().
TorService* TorControl::_torService [private] |
Manages the Tor service, if supported and enabled
Definition at line 149 of file torcontrol.h.
Referenced by closeTorProcess(), start(), and TorControl().
TorEvents TorControl::_torEvents [private] |
Keep track of which events we're interested in
Definition at line 151 of file torcontrol.h.
Referenced by onLogStdout(), setEvent(), setEvents(), and TorControl().
QString TorControl::_torVersion [private] |
The version of Tor we're currently talking to.
Definition at line 153 of file torcontrol.h.
Referenced by getTorVersionString(), onConnected(), and onDisconnected().