Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Private Attributes
CAIPList Class Reference

The purpose of this class is to store a list of IP-Addresses. More...

List of all members.

Public Member Functions

 CAIPList ()
 TODO: Fix LOG_TRAFFIC output which is not done anymore, as per default no log message are ommited...
 CAIPList (UINT32 allowedConnections)
 Constructs a empty CAIPList, there allowedConnections insertions are allowed, until an error is returned.
 ~CAIPList ()
 Deletes the IPList and frees all used resources.
SINT32 insertIP (const UINT8 ip[4])
 Inserts the IP-Address into the list.
SINT32 removeIP (const UINT8 ip[4])
 Removes the IP-Address from the list.

Private Attributes

UINT32 m_allowedConnections
volatile VOLATILE_PIPLISTm_HashTable
CAMutexm_pMutex

Detailed Description

The purpose of this class is to store a list of IP-Addresses.

If an IP-Address is inserted more than 'x' times, than an error is returned. The First mix uses this functionalty to do some basic Denial Of Service defense. If someone tries to do connection flooding to the First Mix, only 'x' connections are accepted and the others are droped. The internal organisation is a hash-table with overrun lists. The hashtable has 0x10000 buckets. The last two bytes of an IP-Address are the hash-key.

Note:
This class only supports IPv4.
Warning:
If there is less memory, CAIPList will crash!
Version:
1.0 first version

Constructor & Destructor Documentation

TODO: Fix LOG_TRAFFIC output which is not done anymore, as per default no log message are ommited...

Constructs an empty CAIPList. The default number MAX_IP_CONNECTIONS of allowed insertions is used

References getRandom(), m_allowedConnections, m_HashTable, m_pMutex, and MAX_IP_CONNECTIONS.

CAIPList::CAIPList ( UINT32  allowedConnections)

Constructs a empty CAIPList, there allowedConnections insertions are allowed, until an error is returned.

Parameters:
allowedConnectionsnumber of insertions of the same IP-Address, until an error is returned

References getRandom(), m_allowedConnections, m_HashTable, and m_pMutex.

Deletes the IPList and frees all used resources.

References m_HashTable, m_pMutex, and _iplist_t::next.


Member Function Documentation

SINT32 CAIPList::insertIP ( const UINT8  ip[4])

Inserts the IP-Address into the list.

If the IP-Address is already in the list then the number of insert() called for this IP-Adress is returned. If this number is larger than m_allowedConnections an error is returned. Intern handelt es sich um eine Hashtabelle mit Ueberlaufliste. Die letzten 16 Bit der IP-Adresse bilden dabei den Hashkey. Die Hashtabelle hat 16^2 Eintraege. In den Ueberlauflisten der einzelnen Hasheintraege sind die ersten 16 Bit der IP-Adresse gespeichert.

Parameters:
ipthe IP-Address to insert
Returns:
number of inserts for this IP-Address
Return values:
E_UNKNOWNif an error occured or an IP is inserted more than m_allowedConnections times

References _iplist_t::count, E_SUCCESS, E_UNKNOWN, _iplist_t::ip, CAMutex::lock(), m_allowedConnections, m_HashTable, m_pMutex, _iplist_t::next, CAMsg::printMsg(), and CAMutex::unlock().

Referenced by fm_loopAcceptUsers().

SINT32 CAIPList::removeIP ( const UINT8  ip[4])

Removes the IP-Address from the list.

Parameters:
ipIP-Address to remove
Returns:
the remaining count of inserts for this IP-Address.
Return values:
0if IP-Address is delete form the list

References _iplist_t::count, E_SUCCESS, _iplist_t::ip, CAMutex::lock(), m_HashTable, m_pMutex, _iplist_t::next, CAMsg::printMsg(), and CAMutex::unlock().

Referenced by CAFirstMixA::closeConnection(), CAFirstMix::doUserLogin_internal(), fm_loopAcceptUsers(), and CAFirstMixB::loop().


Member Data Documentation

Referenced by CAIPList(), and insertIP().