Vidalia  0.3.1
Classes | Public Types | Signals | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
ControlConnection Class Reference

#include <ControlConnection.h>

Inheritance diagram for ControlConnection:

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
 

Detailed Description

Definition at line 32 of file ControlConnection.h.

Member Enumeration Documentation

◆ Status

Control connection status

Enumerator
Unset 

Control connection status is not yet set.

Disconnected 

Control connection disconnected.

Disconnecting 

Control connection is disconnecting.

Connecting 

Control connection attempt pending.

Connected 

Control connection established.

Definition at line 38 of file ControlConnection.h.

Constructor & Destructor Documentation

◆ ControlConnection()

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::~ControlConnection ( )

Destructor.

Definition at line 41 of file ControlConnection.cpp.

References _sendWaiter.

Member Function Documentation

◆ cancelConnect()

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().

◆ connect [1/3]

void ControlConnection::connect ( )
privateslot

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, tc::DebugMessage::arg(), ControlSocket::connectToHost(), ControlSocket::connectToServer(), tc::debug(), MAX_CONNECT_ATTEMPTS, ControlMethod::Port, and ControlMethod::Socket.

Referenced by run().

◆ connect() [2/3]

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().

◆ connect() [3/3]

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().

◆ connected

void ControlConnection::connected ( )
signal

Emitted when a control connection has been established.

Referenced by onConnected(), and run().

◆ connectFailed

void ControlConnection::connectFailed ( QString  errmsg)
signal

Emitted when a control connection fails.

Referenced by onError().

◆ disconnect()

void ControlConnection::disconnect ( )

◆ disconnected

void ControlConnection::disconnected ( )
signal

Emitted when a control connection has been closed.

Referenced by onDisconnected(), and run().

◆ isConnected()

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().

◆ onConnected

void ControlConnection::onConnected ( )
privateslot

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().

◆ onDisconnected

void ControlConnection::onDisconnected ( )
privateslot

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().

◆ onError

void ControlConnection::onError ( QAbstractSocket::SocketError  error)
privateslot

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, tc::DebugMessage::arg(), CONNECT_RETRY_DELAY, connectFailed(), Connecting, tc::debug(), Disconnected, tc::error(), MAX_CONNECT_ATTEMPTS, setStatus(), status(), ControlSocket::toString(), and tc::warn().

Referenced by run().

◆ onReadyRead

void ControlConnection::onReadyRead ( )
privateslot

◆ run()

void ControlConnection::run ( )
private

◆ send() [1/2]

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::DebugMessage::arg(), tc::error(), ControlConnection::ReceiveWaiter::getResult(), and ControlCommand::keyword().

Referenced by TorControl::send(), and TorControl::signal().

◆ send() [2/2]

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().

◆ setStatus()

void ControlConnection::setStatus ( Status  status)
private

Sets the control connection status.

Definition at line 228 of file ControlConnection.cpp.

References _status, _statusMutex, tc::DebugMessage::arg(), tc::debug(), status(), and statusString().

Referenced by cancelConnect(), connect(), disconnect(), onConnected(), onDisconnected(), and onError().

◆ status()

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(), setStatus(), and statusString().

◆ statusString()

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, status(), and Unset.

Referenced by setStatus().

Member Data Documentation

◆ _addr

QHostAddress ControlConnection::_addr
private

Address of Tor's control interface.

Definition at line 101 of file ControlConnection.h.

Referenced by connect().

◆ _connectAttempt

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.

Referenced by connect(), and onError().

◆ _connectTimer

QTimer* ControlConnection::_connectTimer
private

Timer used to delay connect attempts.

Definition at line 108 of file ControlConnection.h.

Referenced by onError(), and run().

◆ _connMutex

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().

◆ _events

TorEvents* ControlConnection::_events
private

Dispatches asynchronous events from Tor.

Definition at line 99 of file ControlConnection.h.

Referenced by ControlConnection(), and onReadyRead().

◆ _method

ControlMethod::Method ControlConnection::_method
private

Definition at line 97 of file ControlConnection.h.

Referenced by connect(), ControlConnection(), disconnect(), and run().

◆ _path

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().

◆ _port

quint16 ControlConnection::_port
private

Port of Tor's control interface.

Definition at line 102 of file ControlConnection.h.

Referenced by connect().

◆ _recvMutex

QMutex ControlConnection::_recvMutex
private

Mutex around the queue of ReceiveWaiters.

Definition at line 104 of file ControlConnection.h.

Referenced by onReadyRead(), run(), and send().

◆ _recvQueue

QQueue<ReceiveWaiter *> ControlConnection::_recvQueue
private

Objects waiting for a reply.

Definition at line 128 of file ControlConnection.h.

Referenced by onReadyRead(), run(), and send().

◆ _sendWaiter

SendCommandEvent::SendWaiter* ControlConnection::_sendWaiter
private

Definition at line 129 of file ControlConnection.h.

Referenced by ControlConnection(), run(), send(), and ~ControlConnection().

◆ _sock

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

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().

◆ _statusMutex

QMutex ControlConnection::_statusMutex
private

Mutex around the connection status value.

Definition at line 105 of file ControlConnection.h.

Referenced by setStatus(), and status().


The documentation for this class was generated from the following files: