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

#include <CASocketList.hpp>

Collaboration diagram for CASocketList:

Public Member Functions

 CASocketList ()
 
 CASocketList (bool bThreadSafe)
 
 ~CASocketList ()
 
SINT32 add (CASocket *pSocket, CASymChannelCipher **pCiphers)
 Add a new channel to the channel-list. More...
 
SINT32 get (HCHANNEL in, CONNECTION *out)
 Gets a copy of an entry form the channel-list. More...
 
CASocketremove (HCHANNEL id)
 
SINT32 clear ()
 
CONNECTIONgetFirst ()
 Gets the first entry of the channel-list. More...
 
CONNECTIONgetNext ()
 Gets the next entry of the channel-list. More...
 
UINT32 getSize ()
 
SINT32 setThreadSafe (bool b)
 
SINT32 addSendMeCounter (HCHANNEL in, SINT32 value)
 

Protected Member Functions

SINT32 increasePool ()
 

Protected Attributes

CONNECTIONLISTm_Connections
 
CONNECTIONLISTm_Pool
 
CONNECTIONLISTm_AktEnumPos
 
t_MEMBLOCKm_Memlist
 
CAMutex cs
 
bool m_bThreadSafe
 
UINT32 m_Size
 

Detailed Description

Definition at line 47 of file CASocketList.hpp.

Constructor & Destructor Documentation

◆ CASocketList() [1/2]

CASocketList::CASocketList ( )

Definition at line 64 of file CASocketList.cpp.

65  {
66  m_Connections=NULL;
67  m_Pool=NULL;
68  m_Memlist=NULL;
69  m_AktEnumPos=NULL;
70  m_bThreadSafe=false;
71  setThreadSafe(false);
72  increasePool();
73  m_Size=0;
74  }
SINT32 setThreadSafe(bool b)
CONNECTIONLIST * m_AktEnumPos
SINT32 increasePool()
t_MEMBLOCK * m_Memlist
CONNECTIONLIST * m_Connections
CONNECTIONLIST * m_Pool

References increasePool(), m_AktEnumPos, m_bThreadSafe, m_Connections, m_Memlist, m_Pool, m_Size, and setThreadSafe().

Here is the call graph for this function:

◆ CASocketList() [2/2]

CASocketList::CASocketList ( bool  bThreadSafe)

Definition at line 76 of file CASocketList.cpp.

77  {
78  m_Connections=NULL;
79  m_Pool=NULL;
80  m_Memlist=NULL;
81  m_AktEnumPos=NULL;
82  m_bThreadSafe=false;
83  setThreadSafe(bThreadSafe);
84  increasePool();
85  }

References increasePool(), m_AktEnumPos, m_bThreadSafe, m_Connections, m_Memlist, m_Pool, and setThreadSafe().

Here is the call graph for this function:

◆ ~CASocketList()

CASocketList::~CASocketList ( )

Definition at line 87 of file CASocketList.cpp.

88  {
89  clear();
90  }
SINT32 clear()

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ add()

SINT32 CASocketList::add ( CASocket pSocket,
CASymChannelCipher **  pCiphers 
)

Add a new channel to the channel-list.

The id for that channel is randomly choosen.

Parameters
pSocketa CASocket assoziated with the channel
pCiphersan array of CASymCipher assoziated with the channel
Returns
E_SUCCESS if no error occurs E_UNKNOWN otherwise

Definition at line 125 of file CASocketList.cpp.

126  {
127  if(m_bThreadSafe)
128  cs.lock();
129  CONNECTIONLIST* tmp;
130  if(m_Pool==NULL)
131  {
132  if(increasePool()!=E_SUCCESS)
133  {
134  if(m_bThreadSafe)
135  cs.unlock();
136  return E_UNKNOWN;
137  }
138  }
139  tmp=m_Pool;
140  m_Pool=m_Pool->next;
141  tmp->next=m_Connections;
142  m_Connections=tmp;
143  m_Connections->pSocket=pSocket;
144  m_Connections->pCiphers=pCiphers;
147  for(;;)
148  {
149 SELECT_RANDOM_CHANNEL_ID:
151  tmp=m_Connections->next;
152  while(tmp!=NULL)
153  {
155  goto SELECT_RANDOM_CHANNEL_ID;
156  tmp=tmp->next;
157  }
158  break;
159  }
160  m_Size++;
161  if(m_bThreadSafe)
162  cs.unlock();
163  return E_SUCCESS;
164  }
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3
CASymChannelCipher ** pCiphers
UINT32 upstreamBytes
connlist * next
UINT32 currentSendMeCounter
HCHANNEL outChannel
CASocket * pSocket

References cs, connlist::currentSendMeCounter, E_SUCCESS, E_UNKNOWN, getRandom(), increasePool(), CAMutex::lock(), m_bThreadSafe, m_Connections, m_Pool, m_Size, connlist::next, connlist::outChannel, connlist::pCiphers, connlist::pSocket, CAMutex::unlock(), and connlist::upstreamBytes.

Referenced by CALocalProxy::loop().

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

◆ addSendMeCounter()

SINT32 CASocketList::addSendMeCounter ( HCHANNEL  in,
SINT32  value 
)

Definition at line 195 of file CASocketList.cpp.

196  {
197  if(m_bThreadSafe)
198  cs.lock();
199  CONNECTIONLIST* tmp;
200  tmp=m_Connections;
201  while(tmp!=NULL)
202  {
203  if(tmp->outChannel==in)
204  {
205  tmp->currentSendMeCounter+=value;
206  if(m_bThreadSafe)
207  cs.unlock();
208  return E_SUCCESS;
209  }
210  tmp=tmp->next;
211  }
212  if(m_bThreadSafe)
213  cs.unlock();
214  return E_UNKNOWN;
215  }

References cs, connlist::currentSendMeCounter, E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_bThreadSafe, m_Connections, connlist::next, connlist::outChannel, and CAMutex::unlock().

Referenced by CALocalProxy::loop().

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

◆ clear()

SINT32 CASocketList::clear ( )

Definition at line 92 of file CASocketList.cpp.

93  {
94  _MEMBLOCK* tmp;
95  tmp=m_Memlist;
96  while(tmp!=NULL)
97  {
98  delete []tmp->mem;
99  tmp->mem = NULL;
100  m_Memlist=tmp;
101  tmp=tmp->next;
102  delete m_Memlist;
103  m_Memlist = NULL;
104  }
105  m_Connections=NULL;
106  m_Pool=NULL;
107  m_Memlist=NULL;
108  m_AktEnumPos=NULL;
109  return E_SUCCESS;
110  }
t_MEMBLOCK * next
CONNECTIONLIST * mem

References E_SUCCESS, m_AktEnumPos, m_Connections, m_Memlist, m_Pool, t_MEMBLOCK::mem, and t_MEMBLOCK::next.

Referenced by ~CASocketList().

Here is the caller graph for this function:

◆ get()

SINT32 CASocketList::get ( HCHANNEL  in,
CONNECTION out 
)

Gets a copy of an entry form the channel-list.

Parameters
in- the channel-id for wich the entry is requested
out- the object, that will hold the copy
Returns
true - if the channel was found false - otherwise

Definition at line 173 of file CASocketList.cpp.

174  {
175  if(m_bThreadSafe)
176  cs.lock();
177  CONNECTIONLIST* tmp;
178  tmp=m_Connections;
179  while(tmp!=NULL)
180  {
181  if(tmp->outChannel==in)
182  {
183  memcpy(out,tmp,sizeof(CONNECTION));
184  if(m_bThreadSafe)
185  cs.unlock();
186  return E_SUCCESS;
187  }
188  tmp=tmp->next;
189  }
190  if(m_bThreadSafe)
191  cs.unlock();
192  return E_UNKNOWN;
193  }

References cs, E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_bThreadSafe, m_Connections, connlist::next, connlist::outChannel, and CAMutex::unlock().

Referenced by CALocalProxy::loop().

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

◆ getFirst()

CONNECTION* CASocketList::getFirst ( )
inline

Gets the first entry of the channel-list.

Returns
the first entry of the channel list (this is not a copy!!)

Definition at line 62 of file CASocketList.hpp.

63  {
65  return m_AktEnumPos;
66  }

References m_AktEnumPos, and m_Connections.

Referenced by CALocalProxy::loop().

Here is the caller graph for this function:

◆ getNext()

CONNECTION* CASocketList::getNext ( )
inline

Gets the next entry of the channel-list.

Returns
the next entry of the channel list (this is not a copy!!)

Definition at line 72 of file CASocketList.hpp.

73  {
74  if(m_AktEnumPos!=NULL)
76  return m_AktEnumPos;
77  }

References m_AktEnumPos, and connlist::next.

Referenced by CALocalProxy::loop().

Here is the caller graph for this function:

◆ getSize()

UINT32 CASocketList::getSize ( )
inline

Definition at line 79 of file CASocketList.hpp.

79 {return m_Size;}

References m_Size.

◆ increasePool()

SINT32 CASocketList::increasePool ( )
protected

Definition at line 39 of file CASocketList.cpp.

40  {
42  if(tmp==NULL)
43  return E_UNKNOWN;
44  _MEMBLOCK* tmpMem=new _MEMBLOCK;
45  if(tmpMem==NULL)
46  {
47  delete[] tmp;
48  tmp = NULL;
49  return E_UNKNOWN;
50  }
51  memset(tmp,0,sizeof(CONNECTIONLIST)*POOL_SIZE);
52  for(int i=1;i<POOL_SIZE;i++)
53  {
54  tmp[i-1].next=&tmp[i];
55  }
56  tmp[POOL_SIZE-1].next=m_Pool;
57  m_Pool=tmp;
58  tmpMem->next=m_Memlist;
59  tmpMem->mem=tmp;
60  m_Memlist=tmpMem;
61  return E_SUCCESS;
62  }
struct t_MEMBLOCK _MEMBLOCK
#define POOL_SIZE

References E_SUCCESS, E_UNKNOWN, m_Memlist, m_Pool, t_MEMBLOCK::mem, t_MEMBLOCK::next, connlist::next, and POOL_SIZE.

Referenced by add(), and CASocketList().

Here is the caller graph for this function:

◆ remove()

CASocket * CASocketList::remove ( HCHANNEL  id)

Definition at line 217 of file CASocketList.cpp.

218  {
219  if(m_bThreadSafe)
220  cs.lock();
221  CONNECTIONLIST* tmp,*before;
222  CASocket* ret;
223  tmp=m_Connections;
224  before=NULL;
225  while(tmp!=NULL)
226  {
227  if(tmp->outChannel==id)
228  {
229  if(m_AktEnumPos==tmp)
230  m_AktEnumPos=tmp->next;
231  if(before!=NULL)
232  before->next=tmp->next;
233  else
234  m_Connections=tmp->next;
235  tmp->next=m_Pool;
236  m_Pool=tmp;
237  ret=tmp->pSocket;
238  m_Size--;
239  if(m_bThreadSafe)
240  cs.unlock();
241  return ret;
242  }
243  before=tmp;
244  tmp=tmp->next;
245  }
246  if(m_bThreadSafe)
247  cs.unlock();
248  return NULL;
249  }

References cs, CAMutex::lock(), m_AktEnumPos, m_bThreadSafe, m_Connections, m_Pool, m_Size, connlist::next, connlist::outChannel, connlist::pSocket, and CAMutex::unlock().

Referenced by CALocalProxy::loop().

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

◆ setThreadSafe()

SINT32 CASocketList::setThreadSafe ( bool  b)

Definition at line 112 of file CASocketList.cpp.

113  {
114  m_bThreadSafe=b;
115  return E_SUCCESS;
116  }

References E_SUCCESS, and m_bThreadSafe.

Referenced by CASocketList().

Here is the caller graph for this function:

Member Data Documentation

◆ cs

CAMutex CASocketList::cs
protected

Definition at line 88 of file CASocketList.hpp.

Referenced by add(), addSendMeCounter(), get(), and remove().

◆ m_AktEnumPos

CONNECTIONLIST* CASocketList::m_AktEnumPos
protected

Definition at line 86 of file CASocketList.hpp.

Referenced by CASocketList(), clear(), getFirst(), getNext(), and remove().

◆ m_bThreadSafe

bool CASocketList::m_bThreadSafe
protected

Definition at line 89 of file CASocketList.hpp.

Referenced by add(), addSendMeCounter(), CASocketList(), get(), remove(), and setThreadSafe().

◆ m_Connections

CONNECTIONLIST* CASocketList::m_Connections
protected

Definition at line 84 of file CASocketList.hpp.

Referenced by add(), addSendMeCounter(), CASocketList(), clear(), get(), getFirst(), and remove().

◆ m_Memlist

t_MEMBLOCK* CASocketList::m_Memlist
protected

Definition at line 87 of file CASocketList.hpp.

Referenced by CASocketList(), clear(), and increasePool().

◆ m_Pool

CONNECTIONLIST* CASocketList::m_Pool
protected

Definition at line 85 of file CASocketList.hpp.

Referenced by add(), CASocketList(), clear(), increasePool(), and remove().

◆ m_Size

UINT32 CASocketList::m_Size
protected

Definition at line 90 of file CASocketList.hpp.

Referenced by add(), CASocketList(), getSize(), and remove().


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