|
Mixe for Privacy and Anonymity in the Internet
|
This class stores Addresses off different Cache-Proxies. More...
#include <CACacheLoadBalancing.hpp>
Public Member Functions | |
| CACacheLoadBalancing () | |
| ~CACacheLoadBalancing () | |
| SINT32 | clean () |
| Deletes all information. | |
| SINT32 | add (CASocketAddr *const pAddr) |
| CASocketAddrINet * | get () |
| Gets the 'next' Address according to the Load-Balancing algorithm. | |
| UINT32 | getElementCount () |
Private Attributes | |
| CACHE_LB_ENTRY * | pSelectedEntry |
| UINT32 | m_ElementCount |
| CAMutex | m_csLock |
This class stores Addresses off different Cache-Proxies.
It can be used for Load Balancing between them. Currently a simple Ropund Robin is implemented.
Definition at line 45 of file CACacheLoadBalancing.hpp.
| CACacheLoadBalancing::CACacheLoadBalancing | ( | ) | [inline] |
Definition at line 48 of file CACacheLoadBalancing.hpp.
References m_ElementCount, and pSelectedEntry.
{
m_ElementCount=0;
pSelectedEntry=NULL;
}
| CACacheLoadBalancing::~CACacheLoadBalancing | ( | ) | [inline] |
Definition at line 53 of file CACacheLoadBalancing.hpp.
References clean().
{clean();}
| SINT32 CACacheLoadBalancing::add | ( | CASocketAddr *const | pAddr | ) |
Definition at line 36 of file CACacheLoadBalancing.cpp.
References CASocketAddr::clone(), E_SUCCESS, E_UNKNOWN, CASocketAddr::getType(), CAMutex::lock(), m_csLock, m_ElementCount, t_cachelb_list::next, t_cachelb_list::pAddr, pSelectedEntry, and CAMutex::unlock().
Referenced by CALastMix::setTargets().
{
if(pAddr->getType()!=AF_INET)
return E_UNKNOWN;
CACHE_LB_ENTRY* pEntry=new CACHE_LB_ENTRY;
if(pEntry==NULL)
return E_UNKNOWN;
pEntry->pAddr=(CASocketAddrINet*)pAddr->clone();
m_csLock.lock();
if(pSelectedEntry==NULL)
{
pSelectedEntry=pEntry;
pSelectedEntry->next=pSelectedEntry;
}
else
{
pEntry->next=pSelectedEntry->next;
pSelectedEntry->next=pEntry;
}
m_ElementCount++;
m_csLock.unlock();
return E_SUCCESS;
}
| SINT32 CACacheLoadBalancing::clean | ( | ) | [inline] |
Deletes all information.
Definition at line 56 of file CACacheLoadBalancing.hpp.
References E_SUCCESS, CAMutex::lock(), m_csLock, m_ElementCount, t_cachelb_list::next, t_cachelb_list::pAddr, pSelectedEntry, and CAMutex::unlock().
Referenced by CALastMix::setTargets(), and ~CACacheLoadBalancing().
{
m_csLock.lock();
CACHE_LB_ENTRY* pEntry;
CACHE_LB_ENTRY* pFirst=pSelectedEntry;
while(pSelectedEntry!=NULL)
{
if(pSelectedEntry->next==pFirst)
pEntry=NULL;
else
pEntry=pSelectedEntry->next;
delete pSelectedEntry->pAddr;
pSelectedEntry->pAddr = NULL;
delete pSelectedEntry;
pSelectedEntry = NULL;
pSelectedEntry=pEntry;
}
m_ElementCount=0;
m_csLock.unlock();
return E_SUCCESS;
}
| CASocketAddrINet* CACacheLoadBalancing::get | ( | ) | [inline] |
Gets the 'next' Address according to the Load-Balancing algorithm.
This is the Address which should be used for a connection to a cache proxy.
Definition at line 84 of file CACacheLoadBalancing.hpp.
References CAMutex::lock(), m_csLock, t_cachelb_list::next, t_cachelb_list::pAddr, pSelectedEntry, and CAMutex::unlock().
Referenced by CALastMixA::loop(), CALastMixB::loop(), and CALastMix::setTargets().
{
m_csLock.lock();
if(pSelectedEntry==NULL)
{
m_csLock.unlock();
return NULL;
}
pSelectedEntry=pSelectedEntry->next;
m_csLock.unlock();
return pSelectedEntry->pAddr;
}
| UINT32 CACacheLoadBalancing::getElementCount | ( | ) | [inline] |
Definition at line 100 of file CACacheLoadBalancing.hpp.
References m_ElementCount.
Referenced by CALastMixA::loop(), CALastMixB::loop(), and CALastMix::setTargets().
{
return m_ElementCount;
}
CAMutex CACacheLoadBalancing::m_csLock [private] |
Definition at line 108 of file CACacheLoadBalancing.hpp.
UINT32 CACacheLoadBalancing::m_ElementCount [private] |
Definition at line 107 of file CACacheLoadBalancing.hpp.
Referenced by add(), CACacheLoadBalancing(), clean(), and getElementCount().
Definition at line 106 of file CACacheLoadBalancing.hpp.
Referenced by add(), CACacheLoadBalancing(), clean(), and get().
1.7.6.1