#include <controlconnection.h>
Public Types | |
enum | Status { Unknown, Launched, Built, Extended, Failed, Closed, Disconnected, Connecting, Connected, Unknown, New, Launched, Connected, Failed, Closed, Unknown, New, NewResolve, SentConnect, SentResolve, Succeeded, Failed, Closed, Detached } |
Signals | |
void | connected () |
void | disconnected () |
void | connectFailed (QString errmsg) |
Public Member Functions | |
ControlConnection (TorEvents *events=0) | |
~ControlConnection () | |
void | connect (QHostAddress addr, quint16 port) |
void | cancelConnect () |
void | disconnect () |
Status | status () |
bool | send (ControlCommand cmd, ControlReply &reply, QString *errmsg=0) |
bool | send (ControlCommand cmd, QString *errmsg=0) |
Protected Member Functions | |
bool | eventFilter (QObject *obj, QEvent *event) |
Private Slots | |
void | onReadyRead () |
Private Member Functions | |
void | setStatus (Status status) |
bool | connect () |
void | run () |
Private Attributes | |
ControlSocket * | _sock |
TorEvents * | _events |
Status | _status |
QHostAddress | _addr |
quint16 | _port |
QMutex | _connMutex |
QMutex | _recvMutex |
QQueue< ReceiveWaiter * > | _recvQueue |
Classes | |
class | ReceiveWaiter |
class | SendCommandEvent |
class | SendWaiter |
Definition at line 42 of file controlconnection.h.
Control connection status
Unknown | Unknown circuit status |
Launched | Circuit ID assigned to new circuit |
Built | All hops finished |
Extended | Circuit extended by one hop |
Failed | Circuit closed (was not built) |
Closed | Circuit closed (was built) |
Disconnected | Control connection disconnected. |
Connecting | Control connection attempt pending. |
Connected | Control connection established. |
Unknown | Unknown OR status. |
New | Incoming connection. |
Launched | Outgoing connection. |
Connected | TLS handshake finished. |
Failed | Connection closed before handshake completed. |
Closed | Connection closed that had previously handshaked. |
Unknown | Unknown status type given |
New | New request to connect |
NewResolve | New request to resolve an address |
SentConnect | Sent a connect cell |
SentResolve | Sent a resolve cell |
Succeeded | Stream established |
Failed | Stream failed |
Closed | Stream closed |
Detached | Detached from circuit |
Definition at line 48 of file controlconnection.h.
ControlConnection::ControlConnection | ( | TorEvents * | events = 0 |
) |
Default constructor.
Definition at line 42 of file controlconnection.cpp.
ControlConnection::~ControlConnection | ( | ) |
Destructor.
Definition at line 49 of file controlconnection.cpp.
void ControlConnection::connect | ( | QHostAddress | addr, | |
quint16 | port | |||
) |
Connect to the specified Tor control interface.
Definition at line 59 of file controlconnection.cpp.
Referenced by TorControl::connect().
void ControlConnection::cancelConnect | ( | ) |
Cancels a pending control connection to Tor.
Definition at line 110 of file controlconnection.cpp.
References _connMutex, _status, and Disconnected.
Referenced by TorControl::onStopped().
void ControlConnection::disconnect | ( | ) |
Disconnect from Tor's control interface.
Definition at line 102 of file controlconnection.cpp.
Referenced by TorControl::disconnect().
ControlConnection::Status ControlConnection::status | ( | ) |
Returns the status of the control connection.
Definition at line 118 of file controlconnection.cpp.
References _connMutex, and _status.
Referenced by connect(), TorControl::isConnected(), and TorControl::onStopped().
bool ControlConnection::send | ( | ControlCommand | cmd, | |
ControlReply & | reply, | |||
QString * | errmsg = 0 | |||
) |
Sends a control command to Tor and waits for the reply.
Definition at line 134 of file controlconnection.cpp.
References _recvMutex, _recvQueue, and ControlConnection::ReceiveWaiter::getResult().
Referenced by TorControl::send(), and TorControl::signal().
bool ControlConnection::send | ( | ControlCommand | cmd, | |
QString * | errmsg = 0 | |||
) |
Sends a control command to Tor and does not wait for a reply.
Definition at line 156 of file controlconnection.cpp.
References _connMutex, _sock, _status, Connected, err(), ControlConnection::SendWaiter::getResult(), ControlSocket::sendCommand(), and CustomEventType::SendCommandEvent.
void ControlConnection::connected | ( | ) | [signal] |
Emitted when a control connection has been established.
Referenced by connect().
void ControlConnection::disconnected | ( | ) | [signal] |
Emitted when a control connection has been closed.
Referenced by run().
void ControlConnection::connectFailed | ( | QString | errmsg | ) | [signal] |
Emitted when a control connection fails.
Referenced by connect().
bool ControlConnection::eventFilter | ( | QObject * | obj, | |
QEvent * | event | |||
) | [protected] |
Catches events for the control socket.
Definition at line 217 of file controlconnection.cpp.
References _connMutex, _sock, ControlSocket::sendCommand(), and ControlConnection::SendWaiter::setResult().
void ControlConnection::onReadyRead | ( | ) | [private, slot] |
Called when there is data on the control socket.
Definition at line 189 of file controlconnection.cpp.
References _connMutex, _events, _recvMutex, _recvQueue, _sock, ControlSocket::readReply(), and ControlConnection::ReceiveWaiter::setResult().
Referenced by run().
void ControlConnection::setStatus | ( | Status | status | ) | [private] |
Sets the control connection status.
Definition at line 126 of file controlconnection.cpp.
References _connMutex, and _status.
bool ControlConnection::connect | ( | ) | [private] |
Connects to Tor's control interface.
Definition at line 72 of file controlconnection.cpp.
References _addr, _connMutex, _port, _sock, ControlSocket::connect(), CONNECT_RETRY_DELAY, connected(), Connected, connectFailed(), Connecting, Disconnected, i(), MAX_CONNECT_ATTEMPTS, setStatus(), and status().
Referenced by run().
void ControlConnection::run | ( | ) | [private] |
Main thread implementation.
Definition at line 252 of file controlconnection.cpp.
References _connMutex, _recvMutex, _recvQueue, _sock, connect(), disconnected(), Disconnected, onReadyRead(), ControlConnection::ReceiveWaiter::setResult(), and setStatus().
ControlSocket* ControlConnection::_sock [private] |
Socket used to communicate with Tor.
Definition at line 96 of file controlconnection.h.
Referenced by connect(), ControlConnection(), eventFilter(), 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().
Status ControlConnection::_status [private] |
Status of the control connection.
Definition at line 98 of file controlconnection.h.
Referenced by cancelConnect(), send(), setStatus(), and status().
QHostAddress ControlConnection::_addr [private] |
Address of Tor's control interface.
Definition at line 99 of file controlconnection.h.
Referenced by connect().
quint16 ControlConnection::_port [private] |
Port of Tor's control interface.
Definition at line 100 of file controlconnection.h.
Referenced by connect().
QMutex ControlConnection::_connMutex [private] |
Mutex around the control socket.
Definition at line 101 of file controlconnection.h.
Referenced by cancelConnect(), connect(), eventFilter(), onReadyRead(), run(), send(), setStatus(), and status().
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 122 of file controlconnection.h.
Referenced by onReadyRead(), run(), and send().