Vidalia 0.2.12
|
#include <ControlConnection.h>
Classes | |
class | ReceiveWaiter |
Public Types | |
enum | Status { Unset, Disconnected, Disconnecting, Connecting, Connected } |
Signals | |
void | connected () |
void | disconnected () |
void | connectFailed (QString errmsg) |
Public Member Functions | |
ControlConnection (ControlMethod::Method method, TorEvents *events=0) | |
~ControlConnection () | |
void | connect (const QHostAddress &addr, quint16 port) |
void | connect (const QString &addr) |
void | cancelConnect () |
void | disconnect () |
bool | isConnected () |
Status | status () |
bool | send (const ControlCommand &cmd, ControlReply &reply, QString *errmsg=0) |
bool | send (const ControlCommand &cmd, QString *errmsg=0) |
Private Slots | |
void | connect () |
void | onReadyRead () |
void | onConnected () |
void | onDisconnected () |
void | onError (QAbstractSocket::SocketError error) |
Private Member Functions | |
void | setStatus (Status status) |
QString | statusString (Status status) |
void | run () |
Private Attributes | |
ControlSocket * | _sock |
ControlMethod::Method | _method |
QString | _path |
TorEvents * | _events |
Status | _status |
QHostAddress | _addr |
quint16 | _port |
QMutex | _connMutex |
QMutex | _recvMutex |
QMutex | _statusMutex |
int | _connectAttempt |
QTimer * | _connectTimer |
QQueue< ReceiveWaiter * > | _recvQueue |
SendCommandEvent::SendWaiter * | _sendWaiter |
Definition at line 32 of file ControlConnection.h.
Control connection status
Definition at line 38 of file ControlConnection.h.
ControlConnection::ControlConnection | ( | ControlMethod::Method | method, |
TorEvents * | events = 0 |
||
) |
Default constructor.
Definition at line 31 of file ControlConnection.cpp.
References _events, _method, _sendWaiter, _sock, _status, and Unset.
ControlConnection::~ControlConnection | ( | ) |
void ControlConnection::cancelConnect | ( | ) |
Cancels a pending control connection to Tor.
Definition at line 187 of file ControlConnection.cpp.
References Disconnected, setStatus(), and tc::warn().
Referenced by TorControl::onStopped().
void ControlConnection::connect | ( | const QString & | addr | ) |
Connect to the specified Tor control socket interface.
Definition at line 74 of file ControlConnection.cpp.
References _connectAttempt, _path, Connecting, tc::error(), and setStatus().
void ControlConnection::connect | ( | const QHostAddress & | addr, |
quint16 | port | ||
) |
Connect to the specified Tor control interface.
Definition at line 53 of file ControlConnection.cpp.
References _addr, _connectAttempt, _port, _sock, Connecting, tc::error(), and setStatus().
Referenced by TorControl::connect().
void ControlConnection::connect | ( | ) | [private, slot] |
Connects to Tor's control interface.
Attempt to establish a connection to Tor's control interface. We will try a maximum of MAX_CONNECT_ATTEMPTS, waiting CONNECT_RETRY_DELAY between each attempt, to give slow Tors a chance to finish binding their control port.
Definition at line 94 of file ControlConnection.cpp.
References _addr, _connectAttempt, _connMutex, _method, _path, _port, _sock, ControlSocket::connectToHost(), ControlSocket::connectToServer(), tc::debug(), MAX_CONNECT_ATTEMPTS, ControlMethod::Port, and ControlMethod::Socket.
Referenced by run().
void ControlConnection::connected | ( | ) | [signal] |
Emitted when a control connection has been established.
Referenced by onConnected(), and run().
void ControlConnection::connectFailed | ( | QString | errmsg | ) | [signal] |
Emitted when a control connection fails.
Referenced by onError().
void ControlConnection::disconnect | ( | ) |
Disconnect from Tor's control interface.
Definition at line 116 of file ControlConnection.cpp.
References _connMutex, _method, _sock, ControlSocket::disconnectFromHost(), ControlSocket::disconnectFromServer(), Disconnecting, ControlMethod::Port, setStatus(), and ControlMethod::Socket.
Referenced by TorControl::disconnect().
void ControlConnection::disconnected | ( | ) | [signal] |
Emitted when a control connection has been closed.
Referenced by onDisconnected(), and run().
bool ControlConnection::isConnected | ( | ) |
Returns true if the control socket is connected to Tor.
Definition at line 196 of file ControlConnection.cpp.
References Connected, and status().
Referenced by TorControl::isConnected(), TorControl::isRunning(), and TorControl::stop().
void ControlConnection::onConnected | ( | ) | [private, slot] |
Called when the control socket is connected.
Called when the control socket is connected. This method checks that the control protocol version of the Tor we connected to is at least V1.
Definition at line 136 of file ControlConnection.cpp.
References connected(), Connected, and setStatus().
Referenced by run().
void ControlConnection::onDisconnected | ( | ) | [private, slot] |
Called when the control socket is disconnected.
Called when the control socket is disconnected and stops the control thread's event loop.
Definition at line 145 of file ControlConnection.cpp.
References disconnected(), Disconnected, and setStatus().
Referenced by run().
void ControlConnection::onError | ( | QAbstractSocket::SocketError | error | ) | [private, slot] |
Called when the control socket encounters an error.
Called when the control socket encounters error.
Definition at line 154 of file ControlConnection.cpp.
References _connectAttempt, _connectTimer, CONNECT_RETRY_DELAY, connectFailed(), Connecting, tc::debug(), Disconnected, tc::error(), MAX_CONNECT_ATTEMPTS, setStatus(), status(), ControlSocket::toString(), and tc::warn().
Referenced by run().
void ControlConnection::onReadyRead | ( | ) | [private, slot] |
Called when there is data on the control socket.
Definition at line 287 of file ControlConnection.cpp.
References _connMutex, _events, _recvMutex, _recvQueue, _sock, ControlSocket::canReadLine(), tc::debug(), tc::error(), ControlReply::getStatus(), TorEvents::handleEvent(), ControlSocket::readReply(), ControlConnection::ReceiveWaiter::setResult(), and ControlReply::toString().
Referenced by run().
void ControlConnection::run | ( | ) | [private] |
Main thread implementation.
Main thread implementation. Creates and connects a control socket, then spins up an event loop.
Definition at line 323 of file ControlConnection.cpp.
References _connectTimer, _connMutex, _method, _recvMutex, _recvQueue, _sendWaiter, _sock, connect(), connected(), tc::debug(), disconnected(), tc::error(), onConnected(), onDisconnected(), onError(), onReadyRead(), ControlConnection::ReceiveWaiter::setResult(), SendCommandEvent::SendWaiter::setResult(), SendCommandEvent::SendWaiter::status(), and SendCommandEvent::SendWaiter::Waiting.
bool ControlConnection::send | ( | const ControlCommand & | cmd, |
ControlReply & | reply, | ||
QString * | errmsg = 0 |
||
) |
Sends a control command to Tor and waits for the reply.
Definition at line 239 of file ControlConnection.cpp.
References _recvMutex, _recvQueue, tc::error(), ControlConnection::ReceiveWaiter::getResult(), and ControlCommand::keyword().
Referenced by TorControl::send(), and TorControl::signal().
bool ControlConnection::send | ( | const ControlCommand & | cmd, |
QString * | errmsg = 0 |
||
) |
Sends a control command to Tor and does not wait for a reply.
Sends a control command to Tor and returns true if the command was sent successfully. Otherwise, returns false and *errmsg (if supplied) will be set.
Definition at line 272 of file ControlConnection.cpp.
References _connMutex, _sendWaiter, _sock, err(), SendCommandEvent::SendWaiter::getResult(), and ControlSocket::isConnected().
void ControlConnection::setStatus | ( | Status | status | ) | [private] |
Sets the control connection status.
Definition at line 228 of file ControlConnection.cpp.
References _status, _statusMutex, tc::debug(), status(), and statusString().
Referenced by cancelConnect(), connect(), disconnect(), onConnected(), onDisconnected(), and onError().
ControlConnection::Status ControlConnection::status | ( | ) |
Returns the status of the control connection.
Definition at line 203 of file ControlConnection.cpp.
References _status, and _statusMutex.
Referenced by isConnected(), onError(), TorControl::onStopped(), and setStatus().
QString ControlConnection::statusString | ( | Status | status | ) | [private] |
Returns the string description of status.
Returns a string description of the control Status value status.
Definition at line 212 of file ControlConnection.cpp.
References Connected, Connecting, Disconnected, Disconnecting, and Unset.
Referenced by setStatus().
QHostAddress ControlConnection::_addr [private] |
Address of Tor's control interface.
Definition at line 101 of file ControlConnection.h.
Referenced by connect().
int ControlConnection::_connectAttempt [private] |
How many times we've tried to connect to Tor while waiting for Tor to start.
Definition at line 106 of file ControlConnection.h.
QTimer* ControlConnection::_connectTimer [private] |
Timer used to delay connect attempts.
Definition at line 108 of file ControlConnection.h.
QMutex ControlConnection::_connMutex [private] |
Mutex around the control socket.
Definition at line 103 of file ControlConnection.h.
Referenced by connect(), disconnect(), onReadyRead(), run(), and send().
TorEvents* ControlConnection::_events [private] |
Dispatches asynchronous events from Tor.
Definition at line 99 of file ControlConnection.h.
Referenced by ControlConnection(), and onReadyRead().
Definition at line 97 of file ControlConnection.h.
Referenced by connect(), ControlConnection(), disconnect(), and run().
QString ControlConnection::_path [private] |
Method used to communicate with Tor. Path to the socket
Definition at line 98 of file ControlConnection.h.
Referenced by connect().
quint16 ControlConnection::_port [private] |
Port of Tor's control interface.
Definition at line 102 of file ControlConnection.h.
Referenced by connect().
QMutex ControlConnection::_recvMutex [private] |
Mutex around the queue of ReceiveWaiters.
Definition at line 104 of file ControlConnection.h.
Referenced by onReadyRead(), run(), and send().
QQueue<ReceiveWaiter *> ControlConnection::_recvQueue [private] |
Objects waiting for a reply.
Definition at line 128 of file ControlConnection.h.
Referenced by onReadyRead(), run(), and send().
Definition at line 129 of file ControlConnection.h.
Referenced by ControlConnection(), run(), send(), and ~ControlConnection().
ControlSocket* ControlConnection::_sock [private] |
Socket used to communicate with Tor.
Definition at line 96 of file ControlConnection.h.
Referenced by connect(), ControlConnection(), disconnect(), onReadyRead(), run(), and send().
Status ControlConnection::_status [private] |
Status of the control connection.
Definition at line 100 of file ControlConnection.h.
Referenced by ControlConnection(), ControlConnection::ReceiveWaiter::setResult(), setStatus(), and status().
QMutex ControlConnection::_statusMutex [private] |
Mutex around the connection status value.
Definition at line 105 of file ControlConnection.h.
Referenced by setStatus(), and status().