Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Private Attributes | List of all members
CACacheLoadBalancing Class Reference

This class stores Addresses off different Cache-Proxies. More...

#include <CACacheLoadBalancing.hpp>

Collaboration diagram for CACacheLoadBalancing:

Public Member Functions

 CACacheLoadBalancing ()
 
 ~CACacheLoadBalancing ()
 
SINT32 clean ()
 Deletes all information. More...
 
SINT32 add (CASocketAddr *const pAddr)
 
CASocketAddrINetget ()
 Gets the 'next' Address according to the Load-Balancing algorithm. More...
 
UINT32 getElementCount ()
 

Private Attributes

CACHE_LB_ENTRYpSelectedEntry
 
UINT32 m_ElementCount
 
CAMutex m_csLock
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CACacheLoadBalancing()

CACacheLoadBalancing::CACacheLoadBalancing ( )
inline

Definition at line 48 of file CACacheLoadBalancing.hpp.

49  {
51  pSelectedEntry=NULL;
52  }
CACHE_LB_ENTRY * pSelectedEntry

References m_ElementCount, and pSelectedEntry.

◆ ~CACacheLoadBalancing()

CACacheLoadBalancing::~CACacheLoadBalancing ( )
inline

Definition at line 53 of file CACacheLoadBalancing.hpp.

53 {clean();}
SINT32 clean()
Deletes all information.

References clean().

Here is the call graph for this function:

Member Function Documentation

◆ add()

SINT32 CACacheLoadBalancing::add ( CASocketAddr *const  pAddr)

Definition at line 36 of file CACacheLoadBalancing.cpp.

37  {
38  if(pAddr->getType()!=AF_INET)
39  return E_UNKNOWN;
40  CACHE_LB_ENTRY* pEntry=new CACHE_LB_ENTRY;
41  if(pEntry==NULL)
42  return E_UNKNOWN;
43  pEntry->pAddr=(CASocketAddrINet*)pAddr->clone();
44  m_csLock.lock();
45  if(pSelectedEntry==NULL)
46  {
47  pSelectedEntry=pEntry;
49  }
50  else
51  {
52  pEntry->next=pSelectedEntry->next;
53  pSelectedEntry->next=pEntry;
54  }
56  m_csLock.unlock();
57  return E_SUCCESS;
58  }
t_cachelb_list CACHE_LB_ENTRY
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
virtual SINT32 getType() const =0
The type (family) of socket for which this address is useful.
virtual CASocketAddr * clone() const =0
Creates a copy of the Address.
This class represents a socket address for Internet (IP) connections.
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3
CASocketAddrINet * pAddr
struct t_cachelb_list * next

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean()

SINT32 CACacheLoadBalancing::clean ( )
inline

Deletes all information.

Definition at line 56 of file CACacheLoadBalancing.hpp.

57  {
58  m_csLock.lock();
59  CACHE_LB_ENTRY* pEntry;
61  while(pSelectedEntry!=NULL)
62  {
63  if(pSelectedEntry->next==pFirst)
64  pEntry=NULL;
65  else
66  pEntry=pSelectedEntry->next;
67  delete pSelectedEntry->pAddr;
68  pSelectedEntry->pAddr = NULL;
69  delete pSelectedEntry;
70  pSelectedEntry = NULL;
71  pSelectedEntry=pEntry;
72  }
74  m_csLock.unlock();
75  return E_SUCCESS;
76  }

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

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.

Returns
next Address of a Cache-Proxy

Definition at line 84 of file CACacheLoadBalancing.hpp.

85  {
86  m_csLock.lock();
87  if(pSelectedEntry==NULL)
88  {
89  m_csLock.unlock();
90  return NULL;
91  }
93  m_csLock.unlock();
94  return pSelectedEntry->pAddr;
95  }

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getElementCount()

UINT32 CACacheLoadBalancing::getElementCount ( )
inline

Definition at line 100 of file CACacheLoadBalancing.hpp.

101  {
102  return m_ElementCount;
103  }

References m_ElementCount.

Referenced by CALastMixA::loop(), CALastMixB::loop(), and CALastMix::setTargets().

Here is the caller graph for this function:

Member Data Documentation

◆ m_csLock

CAMutex CACacheLoadBalancing::m_csLock
private

Definition at line 108 of file CACacheLoadBalancing.hpp.

Referenced by add(), clean(), and get().

◆ m_ElementCount

UINT32 CACacheLoadBalancing::m_ElementCount
private

Definition at line 107 of file CACacheLoadBalancing.hpp.

Referenced by add(), CACacheLoadBalancing(), clean(), and getElementCount().

◆ pSelectedEntry

CACHE_LB_ENTRY* CACacheLoadBalancing::pSelectedEntry
private

Definition at line 106 of file CACacheLoadBalancing.hpp.

Referenced by add(), CACacheLoadBalancing(), clean(), and get().


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