#include <controlconnection.h>
Public Types | |
Unset | |
Disconnected | |
Disconnecting | |
Connecting | |
Connected | |
enum | Status { Unset, Disconnected, Disconnecting, Connecting, Connected } |
Signals | |
void | connected () |
void | disconnected () |
void | connectFailed (QString errmsg) |
Public Member Functions | |
ControlConnection (TorEvents *events=0) | |
~ControlConnection () | |
void | connect (const QHostAddress &addr, quint16 port) |
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 |
TorEvents * | _events |
Status | _status |
QHostAddress | _addr |
quint16 | _port |
QMutex | _connMutex |
QMutex | _recvMutex |
QMutex | _statusMutex |
int | _connectAttempt |
QTimer * | _connectTimer |
QQueue< ReceiveWaiter * > | _recvQueue |
SendCommandEvent::SendWaiter * | _sendWaiter |
Classes | |
class | ReceiveWaiter |
Definition at line 34 of file controlconnection.h.
Control connection status
Definition at line 40 of file controlconnection.h.
ControlConnection::ControlConnection | ( | TorEvents * | events = 0 |
) |
Default constructor.
Definition at line 32 of file controlconnection.cpp.
References _events, _sendWaiter, _sock, _status, and Unset.
ControlConnection::~ControlConnection | ( | ) |
void ControlConnection::cancelConnect | ( | ) |
Cancels a pending control connection to Tor.
Definition at line 151 of file controlconnection.cpp.
References Disconnected, setStatus(), and tc::warn().
Referenced by TorControl::onStopped().
void ControlConnection::connect | ( | ) | [private, slot] |
Connects to Tor's control interface.
Definition at line 76 of file controlconnection.cpp.
References _addr, _connectAttempt, _connMutex, _port, _sock, tc::debug(), and MAX_CONNECT_ATTEMPTS.
Referenced by run().
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::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 89 of file controlconnection.cpp.
References _connMutex, _sock, Disconnecting, and setStatus().
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 160 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.
Definition at line 100 of file controlconnection.cpp.
References connected(), Connected, and setStatus().
Referenced by run().
void ControlConnection::onDisconnected | ( | ) | [private, slot] |
Called when the control socket is disconnected.
Definition at line 109 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.
Definition at line 118 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 251 of file controlconnection.cpp.
References _connMutex, _events, _recvMutex, _recvQueue, _sock, tc::debug(), tc::error(), ControlSocket::readReply(), and ControlConnection::ReceiveWaiter::setResult().
Referenced by run().
void ControlConnection::run | ( | ) | [private] |
Main thread implementation.
Definition at line 287 of file controlconnection.cpp.
References _connectTimer, _connMutex, _recvMutex, _recvQueue, _sendWaiter, _sock, connect(), connected(), tc::debug(), disconnected(), tc::error(), onConnected(), onDisconnected(), onError(), onReadyRead(), SendCommandEvent::SendWaiter::setResult(), SendCommandEvent::SendWaiter::status(), and SendCommandEvent::SendWaiter::Waiting.
bool ControlConnection::send | ( | const ControlCommand & | cmd, | |
QString * | errmsg = 0 | |||
) |
Sends a control command to Tor and does not wait for a reply.
Definition at line 236 of file controlconnection.cpp.
References _connMutex, _sendWaiter, _sock, err(), SendCommandEvent::SendWaiter::getResult(), ControlSocket::isConnected(), and CustomEventType::SendCommandEvent.
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 203 of file controlconnection.cpp.
References _recvMutex, _recvQueue, tc::error(), ControlConnection::ReceiveWaiter::getResult(), and ControlCommand::keyword().
Referenced by TorControl::send(), and TorControl::signal().
void ControlConnection::setStatus | ( | Status | status | ) | [private] |
Sets the control connection status.
Definition at line 192 of file controlconnection.cpp.
References _status, _statusMutex, tc::debug(), 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 167 of file controlconnection.cpp.
References _status, and _statusMutex.
Referenced by isConnected(), onError(), and TorControl::onStopped().
QString ControlConnection::statusString | ( | Status | status | ) | [private] |
Returns the string description of status.
Definition at line 176 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 99 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 104 of file controlconnection.h.
QTimer* ControlConnection::_connectTimer [private] |
Timer used to delay connect attempts.
Definition at line 106 of file controlconnection.h.
QMutex ControlConnection::_connMutex [private] |
Mutex around the control socket.
Definition at line 101 of file controlconnection.h.
Referenced by connect(), disconnect(), onReadyRead(), run(), and send().
TorEvents* ControlConnection::_events [private] |
Dispatches asynchronous events from Tor.
Definition at line 97 of file controlconnection.h.
Referenced by ControlConnection(), and onReadyRead().
quint16 ControlConnection::_port [private] |
Port of Tor's control interface.
Definition at line 100 of file controlconnection.h.
Referenced by connect().
QMutex ControlConnection::_recvMutex [private] |
Mutex around the queue of ReceiveWaiters.
Definition at line 102 of file controlconnection.h.
Referenced by onReadyRead(), run(), and send().
QQueue<ReceiveWaiter *> ControlConnection::_recvQueue [private] |
Objects waiting for a reply.
Definition at line 126 of file controlconnection.h.
Referenced by onReadyRead(), run(), and send().
Definition at line 127 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 98 of file controlconnection.h.
Referenced by ControlConnection(), setStatus(), and status().
QMutex ControlConnection::_statusMutex [private] |
Mutex around the connection status value.
Definition at line 103 of file controlconnection.h.
Referenced by setStatus(), and status().