TorEvents Class Reference

#include <torevents.h>

List of all members.

Public Types

enum  TorEvent {
  Unknown, Bandwidth, LogDebug, LogInfo,
  LogNotice, LogWarn, LogError, CircuitStatus,
  StreamStatus, OrConnStatus, NewDescriptor, AddressMap,
  GeneralStatus, ClientStatus, ServerStatus
}

Public Member Functions

 TorEvents ()
void add (TorEvent event, QObject *obj)
void remove (TorEvent event, QObject *obj)
bool contains (TorEvent event)
QList< TorEventeventList ()
void handleEvent (const ControlReply &reply)
void dispatch (TorEvent e, QEvent *event)

Static Public Member Functions

static QString toString (TorEvents::TorEvent e)
static TorEvent toTorEvent (LogEvent::Severity severity)

Private Member Functions

void handleBandwidthUpdate (const ReplyLine &line)
void handleCircuitStatus (const ReplyLine &line)
void handleStreamStatus (const ReplyLine &line)
void handleLogMessage (const ReplyLine &line)
void handleOrConnStatus (const ReplyLine &line)
void handleNewDescriptor (const ReplyLine &line)
void handleAddressMap (const ReplyLine &line)
void handleStatusEvent (TorEvent type, const ReplyLine &line)
void dispatchClientStatusEvent (tc::Severity severity, const QString &action, const QHash< QString, QString > &args)
void dispatchServerStatusEvent (tc::Severity severity, const QString &action, const QHash< QString, QString > &args)
void dispatchGeneralStatusEvent (tc::Severity severity, const QString &action, const QHash< QString, QString > &args)

Static Private Member Functions

static TorEvent parseEventType (const ReplyLine &line)
static TorEvent toTorEvent (const QString &event)

Private Attributes

QMultiHash< TorEvent, QObject * > _eventList

Detailed Description

Definition at line 36 of file torevents.h.


Member Enumeration Documentation

Asynchronous events sent from Tor to the controller

Enumerator:
Unknown 
Bandwidth 
LogDebug 
LogInfo 
LogNotice 
LogWarn 
LogError 
CircuitStatus 
StreamStatus 
OrConnStatus 
NewDescriptor 
AddressMap 
GeneralStatus 
ClientStatus 
ServerStatus 

Definition at line 42 of file torevents.h.


Constructor & Destructor Documentation

TorEvents::TorEvents (  ) 

Default Constructor

Default constructor

Definition at line 35 of file torevents.cpp.


Member Function Documentation

void TorEvents::add ( TorEvent  e,
QObject *  obj 
)

Adds an event and interested object to the event list

Adds an event and interested object to the list

Definition at line 41 of file torevents.cpp.

References _eventList.

Referenced by TorControl::setEvent().

bool TorEvents::contains ( TorEvent  event  ) 

Returns true if an event has any registered handlers

Definition at line 64 of file torevents.cpp.

References _eventList.

void TorEvents::dispatch ( TorEvent  e,
QEvent *  event 
)
void TorEvents::dispatchClientStatusEvent ( tc::Severity  severity,
const QString &  action,
const QHash< QString, QString > &  args 
) [private]
void TorEvents::dispatchGeneralStatusEvent ( tc::Severity  severity,
const QString &  action,
const QHash< QString, QString > &  args 
) [private]
void TorEvents::dispatchServerStatusEvent ( tc::Severity  severity,
const QString &  action,
const QHash< QString, QString > &  args 
) [private]

Parses and posts a Tor server status event.

Definition at line 429 of file torevents.cpp.

References dispatch(), ServerStatus, and ServerStatusEvent::statusFromString().

Referenced by handleStatusEvent().

QList< TorEvents::TorEvent > TorEvents::eventList (  ) 

Returns the list of events in which we're interested

Definition at line 74 of file torevents.cpp.

References _eventList.

Referenced by TorControl::setEvents().

void TorEvents::handleAddressMap ( const ReplyLine line  )  [private]

Handles a new or updated address map event.

Handles a new or updated address mapping event. The format for event messages of this type is:

"650" SP "ADDRMAP" SP Address SP Address SP Expiry Expiry = DQUOTE ISOTime DQUOTE / "NEVER"

Expiry is expressed as the local time (rather than GMT).

Definition at line 350 of file torevents.cpp.

References CustomEventType::AddressMapEvent, DATE_FMT, dispatch(), and ReplyLine::getMessage().

Referenced by handleEvent().

void TorEvents::handleBandwidthUpdate ( const ReplyLine line  )  [private]

Handle a bandwidth update event

Handle a bandwidth update event, to inform the controller of the bandwidth used in the last second. The format of this message is:

"650" SP "BW" SP BytesRead SP BytesWritten BytesRead = 1*DIGIT BytesWritten = 1*DIGIT

Definition at line 219 of file torevents.cpp.

References Bandwidth, CustomEventType::BandwidthEvent, dispatch(), and ReplyLine::getMessage().

Referenced by handleEvent().

void TorEvents::handleCircuitStatus ( const ReplyLine line  )  [private]

Handle a circuit status event

Handle a circuit status event. The format of this message is:

"650" SP "CIRC" SP CircuitID SP CircStatus SP Path CircStatus = "LAUNCHED" / ; circuit ID assigned to new circuit "BUILT" / ; all hops finished, can now accept streams "EXTENDED" / ; one more hop has been completed "FAILED" / ; circuit closed (was not built) "CLOSED" ; circuit closed (was built) Path = ServerID *("," ServerID)

Definition at line 243 of file torevents.cpp.

References CustomEventType::CircuitEvent, CircuitStatus, dispatch(), ReplyLine::getMessage(), and i().

Referenced by handleEvent().

void TorEvents::handleEvent ( const ControlReply reply  ) 

Parses an event message and emits the proper signal

Handles an event message from Tor. An event message can potentially have more than one line, so we will iterate through them all and dispatch the necessary events.

Definition at line 182 of file torevents.cpp.

References Bandwidth, CircuitStatus, ClientStatus, GeneralStatus, ControlReply::getLines(), handleAddressMap(), handleBandwidthUpdate(), handleCircuitStatus(), handleLogMessage(), handleNewDescriptor(), handleOrConnStatus(), handleStatusEvent(), handleStreamStatus(), LogDebug, LogError, LogInfo, LogNotice, LogWarn, NewDescriptor, OrConnStatus, parseEventType(), ServerStatus, and StreamStatus.

Referenced by ControlConnection::onReadyRead().

void TorEvents::handleLogMessage ( const ReplyLine line  )  [private]

Handle a log message event

Handle a log message event. The format of this message is: The syntax is:

"650" SP Severity SP ReplyText or "650+" Severity CRLF Data Severity = "DEBUG" / "INFO" / "NOTICE" / "WARN"/ "ERR"

Definition at line 291 of file torevents.cpp.

References dispatch(), ReplyLine::getData(), ReplyLine::getMessage(), i(), CustomEventType::LogEvent, tc::toSeverity(), and toTorEvent().

Referenced by handleEvent().

void TorEvents::handleNewDescriptor ( const ReplyLine line  )  [private]

Handles a new list of descriptors event.

Handles a new descriptor event. The format for event messages of this type is:

"650" SP "NEWDESC" 1*(SP ServerID)

Definition at line 332 of file torevents.cpp.

References dispatch(), ReplyLine::getMessage(), NewDescriptor, and CustomEventType::NewDescriptorEvent.

Referenced by handleEvent().

void TorEvents::handleOrConnStatus ( const ReplyLine line  )  [private]

Handle an OR connection status event.

Handle an OR Connection Status event. The syntax is: "650" SP "ORCONN" SP (ServerID / Target) SP ORStatus

ORStatus = "NEW" / "LAUNCHED" / "CONNECTED" / "FAILED" / "CLOSED"

NEW is for incoming connections, and LAUNCHED is for outgoing connections. CONNECTED means the TLS handshake has finished (in either direction). FAILED means a connection is being closed that hasn't finished its handshake, and CLOSED is for connections that have handshaked.

A ServerID is specified unless it's a NEW connection, in which case we don't know what server it is yet, so we use Address:Port.

Definition at line 317 of file torevents.cpp.

References dispatch(), ReplyLine::getMessage(), CustomEventType::OrConnEvent, OrConnStatus, and OrConnEvent::toStatus().

Referenced by handleEvent().

void TorEvents::handleStatusEvent ( TorEvent  type,
const ReplyLine line 
) [private]

Handles a Tor status event.

Handles a Tor status event. The format for event messages of this type is:

"650" SP StatusType SP StatusSeverity SP StatusAction [SP StatusArguments] CRLF

StatusType = "STATUS_GENERAL" / "STATUS_CLIENT" / "STATUS_SERVER" StatusSeverity = "NOTICE" / "WARN" / "ERR" StatusAction = 1*ALPHA StatusArguments = StatusArgument *(SP StatusArgument) StatusArgument = StatusKeyword '=' StatusValue StatusKeyword = 1*(ALNUM / "_") StatusValue = 1*(ALNUM / '_') / QuotedString

Definition at line 375 of file torevents.cpp.

References ClientStatus, dispatchClientStatusEvent(), dispatchGeneralStatusEvent(), dispatchServerStatusEvent(), ReplyLine::getMessage(), ServerStatus, string_parse_keyvals(), and tc::toSeverity().

Referenced by handleEvent().

void TorEvents::handleStreamStatus ( const ReplyLine line  )  [private]

Handle a stream status event

Handle a stream status event. The format of this message is:

"650" SP "STREAM" SP StreamID SP StreamStatus SP CircID SP Target SP StreamStatus = "NEW" / ; New request to connect "NEWRESOLVE" / ; New request to resolve an address "SENTCONNECT" / ; Sent a connect cell along a circuit "SENTRESOLVE" / ; Sent a resolve cell along a circuit "SUCCEEDED" / ; Received a reply; stream established "FAILED" / ; Stream failed and not retriable. "CLOSED" / ; Stream closed "DETACHED" ; Detached from circuit; still retriable. Target = Address ":" Port

If the circuit ID is 0, then the stream is unattached.

Definition at line 272 of file torevents.cpp.

References dispatch(), Stream::fromString(), ReplyLine::getMessage(), i(), CustomEventType::StreamEvent, and StreamStatus.

Referenced by handleEvent().

TorEvents::TorEvent TorEvents::parseEventType ( const ReplyLine line  )  [static, private]

Parses the event type from the event message

Parse the event type out of a message line and return the corresponding Event enum value

Definition at line 171 of file torevents.cpp.

References ReplyLine::getMessage(), i(), and toTorEvent().

Referenced by handleEvent().

void TorEvents::remove ( TorEvent  e,
QObject *  obj 
)

Removes obj from the list of target objects for event e.

Definition at line 50 of file torevents.cpp.

References _eventList, and i().

Referenced by TorControl::setEvent().

QString TorEvents::toString ( TorEvents::TorEvent  e  )  [static]

Converts an Event to a string

Converts an event type to a string Tor understands

Definition at line 90 of file torevents.cpp.

References Bandwidth, CircuitStatus, ClientStatus, GeneralStatus, LogDebug, LogError, LogInfo, LogNotice, LogWarn, NewDescriptor, OrConnStatus, ServerStatus, and StreamStatus.

Referenced by TorControl::setEvents().

TorEvents::TorEvent TorEvents::toTorEvent ( const QString &  event  )  [static, private]

Converts a string to an Event

Converts an event in the string form sent by Tor to its enum value

Definition at line 131 of file torevents.cpp.

References Bandwidth, CircuitStatus, ClientStatus, GeneralStatus, LogDebug, LogError, LogInfo, LogNotice, LogWarn, NewDescriptor, OrConnStatus, ServerStatus, StreamStatus, and Unknown.

TorEvents::TorEvent TorEvents::toTorEvent ( LogEvent::Severity  severity  )  [static]

Converts a log severity to an event

Converts a log severity to its related Tor event

Definition at line 115 of file torevents.cpp.

References LogEvent::Debug, LogEvent::Error, LogEvent::Info, LogDebug, LogError, LogInfo, LogNotice, LogWarn, LogEvent::Notice, Unknown, and LogEvent::Warn.

Referenced by handleLogMessage(), TorControl::onLogStdout(), and parseEventType().


Member Data Documentation

QMultiHash<TorEvent, QObject*> TorEvents::_eventList [private]

Stores a mapping of Tor events to a list of the objects interested in hearing about those events.

Definition at line 84 of file torevents.h.

Referenced by add(), contains(), dispatch(), eventList(), and remove().


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

Generated on Wed Dec 23 21:06:56 2009 for Vidalia by  doxygen 1.6.1