Vidalia 0.3.1
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
UPNPControlThread Class Reference

#include <UPNPControlThread.h>

Inheritance diagram for UPNPControlThread:

Public Member Functions

 UPNPControlThread (UPNPControl *control)
 
 ~UPNPControlThread ()
 
void stop ()
 
void wakeup ()
 

Static Public Attributes

static const int UPNPCONTROL_DISCOVER_TIMEOUT = 2000
 

Protected Member Functions

void run ()
 

Private Member Functions

void configurePorts ()
 
UPNPControl::UPNPError initializeUPNP ()
 
UPNPControl::UPNPError updatePort (quint16 oldPort, quint16 newPort)
 
UPNPControl::UPNPError forwardPort (quint16 port)
 
UPNPControl::UPNPError disablePort (quint16 port)
 

Private Attributes

QTime _upnpInitialized
 
bool _keepRunning
 
UPNPControl_control
 
QWaitCondition * _waitCondition
 
QMutex * _waitMutex
 
quint16 _dirPort
 
quint16 _orPort
 
struct UPNPUrls urls
 
struct IGDdatas data
 
char lanaddr [16]
 

Detailed Description

Definition at line 33 of file UPNPControlThread.h.

Constructor & Destructor Documentation

◆ UPNPControlThread()

UPNPControlThread::UPNPControlThread ( UPNPControl control)

Constructor. control will be used for retrieving the desired port forwarding state.

Definition at line 33 of file UPNPControlThread.cpp.

References _control, _dirPort, _keepRunning, _orPort, _upnpInitialized, _waitCondition, and _waitMutex.

◆ ~UPNPControlThread()

UPNPControlThread::~UPNPControlThread ( )

Destructor. The UPnP control thread must be stopped prior to destroying this object.

Destructor. The UPnP control thread must be stopped prior to destroying this object.

See also
stop()

Definition at line 50 of file UPNPControlThread.cpp.

References _waitCondition, and _waitMutex.

Member Function Documentation

◆ configurePorts()

void UPNPControlThread::configurePorts ( )
private

Sets up port forwarding according the previously-configured desired state. The desired state is set using UPNPControl's setDesiredState() method.

Sets up port forwarding according the previously-configured desired state. The desired state is set using UPNPControl's setDesiredState() method.

See also
UPNPControl::setDesiredState

Definition at line 99 of file UPNPControlThread.cpp.

References _control, _dirPort, _orPort, _upnpInitialized, err(), UPNPControl::ErrorState, UPNPControl::ForwardingCompleteState, UPNPControl::getDesiredState(), UPNPControl::instance(), UPNPControl::setError(), UPNPControl::setState(), UPNPControl::Success, updatePort(), UPNPControl::UpdatingDirPortState, UPNPControl::UpdatingORPortState, and UPNPCONTROL_REINIT_MSEC.

Referenced by run().

◆ disablePort()

UPNPControl::UPNPError UPNPControlThread::disablePort ( quint16  port)
private

Removes the port mapping for port. Returns 0 on success or non-zero on failure.

Definition at line 314 of file UPNPControlThread.cpp.

References UPNPUrls::controlURL, data, UPNPControl::DeletePortMappingFailed, IGDdatas::first, IGDdatas_service::servicetype, UPNPControl::Success, UPNP_DeletePortMapping(), UPNPCOMMAND_SUCCESS, urls, vInfo, and vWarn.

Referenced by updatePort().

◆ forwardPort()

UPNPControl::UPNPError UPNPControlThread::forwardPort ( quint16  port)
private

Adds a port forwarding mapping from external:port to internal:port. Returns 0 on success, or non-zero on failure.

Definition at line 270 of file UPNPControlThread.cpp.

References UPNPControl::AddPortMappingFailed, UPNPUrls::controlURL, data, IGDdatas::first, UPNPControl::GetPortMappingFailed, lanaddr, IGDdatas_service::servicetype, UPNPControl::Success, UPNP_AddPortMapping(), UPNP_GetSpecificPortMappingEntry(), UPNPCOMMAND_SUCCESS, urls, vInfo, and vWarn.

Referenced by updatePort().

◆ initializeUPNP()

UPNPControl::UPNPError UPNPControlThread::initializeUPNP ( )
private

Discovers UPnP-enabled IGDs on the network. This method will block for UPNPCONTROL_DISCOVER_TIMEOUT milliseconds.

Discovers UPnP-enabled IGDs on the network. Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch This method will block for UPNPCONTROL_DISCOVER_TIMEOUT milliseconds.

Definition at line 239 of file UPNPControlThread.cpp.

References data, UPNPControl::DiscoverState, freeUPNPDevlist(), UPNPControl::instance(), lanaddr, UPNPControl::NoUPNPDevicesFound, UPNPControl::NoValidIGDsFound, UPNPControl::setState(), UPNPControl::Success, UPNP_GetValidIGD(), UPNPCONTROL_DISCOVER_TIMEOUT, upnpDiscover(), urls, vInfo, and vWarn.

Referenced by updatePort().

◆ run()

void UPNPControlThread::run ( )
protected

Thread entry point. The thread has a main loop that periodically wakes up and updates the configured port mappings. Upon exiting, all port mappings will be removed.

Definition at line 60 of file UPNPControlThread.cpp.

References _dirPort, _keepRunning, _orPort, _waitCondition, _waitMutex, configurePorts(), UPNPControl::IdleState, UPNPControl::instance(), UPNPControl::setState(), updatePort(), and UPNPCONTROL_MAX_WAIT_MSEC.

◆ stop()

void UPNPControlThread::stop ( )

Terminates the UPnP control thread's run() loop.

Terminates the UPnP control thread's run() loop.

See also
run()

Definition at line 167 of file UPNPControlThread.cpp.

References _keepRunning, _waitCondition, and _waitMutex.

Referenced by UPNPControl::cleanup().

◆ updatePort()

UPNPControl::UPNPError UPNPControlThread::updatePort ( quint16  oldPort,
quint16  newPort 
)
private

Updates the port mapping for oldPort, changing it to newPort.

Definition at line 199 of file UPNPControlThread.cpp.

References _upnpInitialized, disablePort(), forwardPort(), initializeUPNP(), UPNPControl::Success, vWarn, and UPNPControl::WSAStartupFailed.

Referenced by configurePorts(), and run().

◆ wakeup()

void UPNPControlThread::wakeup ( )

Wakes up the UPnP control thread's run() loop.

Wakes up the UPnP control thread's run() loop.

See also
run()

Definition at line 189 of file UPNPControlThread.cpp.

References _waitCondition, and _waitMutex.

Referenced by UPNPControl::setDesiredState().

Member Data Documentation

◆ _control

UPNPControl* UPNPControlThread::_control
private

Stores desired UPnP state.

Definition at line 79 of file UPNPControlThread.h.

Referenced by configurePorts(), and UPNPControlThread().

◆ _dirPort

quint16 UPNPControlThread::_dirPort
private

Desired DirPort.

Definition at line 82 of file UPNPControlThread.h.

Referenced by configurePorts(), run(), and UPNPControlThread().

◆ _keepRunning

bool UPNPControlThread::_keepRunning
private

True if the control thread should keep running.

Definition at line 78 of file UPNPControlThread.h.

Referenced by run(), stop(), and UPNPControlThread().

◆ _orPort

quint16 UPNPControlThread::_orPort
private

Desired ORPort.

Definition at line 83 of file UPNPControlThread.h.

Referenced by configurePorts(), run(), and UPNPControlThread().

◆ _upnpInitialized

QTime UPNPControlThread::_upnpInitialized
private

Time at which the UPnP state was last set.

Definition at line 77 of file UPNPControlThread.h.

Referenced by configurePorts(), updatePort(), and UPNPControlThread().

◆ _waitCondition

QWaitCondition* UPNPControlThread::_waitCondition
private

Used to wake up the control thread.

Definition at line 80 of file UPNPControlThread.h.

Referenced by run(), stop(), UPNPControlThread(), wakeup(), and ~UPNPControlThread().

◆ _waitMutex

QMutex* UPNPControlThread::_waitMutex
private

Mutex around shared variables.

Definition at line 81 of file UPNPControlThread.h.

Referenced by run(), stop(), UPNPControlThread(), wakeup(), and ~UPNPControlThread().

◆ data

struct IGDdatas UPNPControlThread::data
private

Definition at line 87 of file UPNPControlThread.h.

Referenced by disablePort(), forwardPort(), and initializeUPNP().

◆ lanaddr

char UPNPControlThread::lanaddr[16]
private

Definition at line 88 of file UPNPControlThread.h.

Referenced by forwardPort(), and initializeUPNP().

◆ UPNPCONTROL_DISCOVER_TIMEOUT

const int UPNPControlThread::UPNPCONTROL_DISCOVER_TIMEOUT = 2000
static

Specifies the number of milliseconds to wait for devices to respond when attempting to discover UPnP-enabled IGDs.

Definition at line 40 of file UPNPControlThread.h.

Referenced by UPNPControl::discoverTimeout(), and initializeUPNP().

◆ urls

struct UPNPUrls UPNPControlThread::urls
private

Definition at line 86 of file UPNPControlThread.h.

Referenced by disablePort(), forwardPort(), and initializeUPNP().


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