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

#include <CALastMixChannelList.hpp>

Collaboration diagram for CALastMixChannelList:

Public Member Functions

 CALastMixChannelList ()
 
 ~CALastMixChannelList ()
 
SINT32 add (HCHANNEL id, CASocket *pSocket, CASymChannelCipher *pCipher, CAQueue *pQueue)
 
lmChannelListEntryget (HCHANNEL channelIn)
 
lmChannelListEntrygetFirstSocket ()
 
lmChannelListEntrygetNextSocket ()
 
SINT32 removeChannel (HCHANNEL channelIn)
 
UINT32 getSize ()
 

Static Public Member Functions

static SINT32 test ()
 

Private Attributes

UINT32 m_nChannels
 
LP_lmChannelListEntrym_HashTable
 The Hash-Table of all channels. More...
 
lmChannelListm_listSockets
 Pointer to the head of a list of all sockets. More...
 
lmChannelListm_listSocketsNext
 Next Element in the enumeration of all sockets. More...
 

Detailed Description

Definition at line 106 of file CALastMixChannelList.hpp.

Constructor & Destructor Documentation

◆ CALastMixChannelList()

CALastMixChannelList::CALastMixChannelList ( )

Definition at line 34 of file CALastMixChannelList.cpp.

35  {
38  m_listSockets=NULL;
39  m_listSocketsNext=NULL;
40  m_nChannels=0;
41 #ifdef DELAY_CHANNELS
42  m_u32DelayChannelUnlimitTraffic=DELAY_CHANNEL_TRAFFIC;
43  m_u32DelayChannelBucketGrow=DELAY_BUCKET_GROW;
44  m_u32DelayChannelBucketGrowIntervall=DELAY_BUCKET_GROW_INTERVALL;
45  m_pDelayBuckets=new UINT32*[MAX_POLLFD];
46  memset(m_pDelayBuckets,0,sizeof(UINT32*)*MAX_POLLFD);
47  m_pMutexDelayChannel=new CAMutex();
48  m_pThreadDelayBucketsLoop=new CAThread((UINT8*)"Delay Buckets Thread");
49  m_bDelayBucketsLoopRun=true;
50  m_pThreadDelayBucketsLoop->setMainLoop(lml_loopDelayBuckets);
51  m_pThreadDelayBucketsLoop->start(this);
52 #endif
53 #ifdef DELAY_CHANNELS_LATENCY
54  m_u32DelayChannelLatency=DELAY_CHANNEL_LATENCY;
55 #endif
56 #ifdef LOG_CRIME
57  m_pMutex=new CAMutex();
58 #endif
59 }
#define HASHTABLE_SIZE
#define DELAY_CHANNEL_LATENCY
Definition: StdAfx.h:169
#define MAX_POLLFD
Definition: StdAfx.h:192
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
lmChannelList * m_listSockets
Pointer to the head of a list of all sockets.
lmChannelList * m_listSocketsNext
Next Element in the enumeration of all sockets.
LP_lmChannelListEntry * m_HashTable
The Hash-Table of all channels.

References DELAY_CHANNEL_LATENCY, HASHTABLE_SIZE, m_HashTable, m_listSockets, m_listSocketsNext, m_nChannels, and MAX_POLLFD.

◆ ~CALastMixChannelList()

CALastMixChannelList::~CALastMixChannelList ( )

Definition at line 61 of file CALastMixChannelList.cpp.

62  {
63 #ifdef DELAY_CHANNELS
64  m_bDelayBucketsLoopRun=false;
65  m_pThreadDelayBucketsLoop->join();
66  delete m_pThreadDelayBucketsLoop;
67  m_pThreadDelayBucketsLoop = NULL;
68  delete m_pMutexDelayChannel;
69  m_pMutexDelayChannel = NULL;
70  delete []m_pDelayBuckets;
71  m_pDelayBuckets = NULL;
72 #endif
73  for(UINT32 i=0;i < HASHTABLE_SIZE; i++)
74  {
76  lmChannelListEntry* tmp;
77  while(akt!=NULL)
78  {
79  tmp=akt;
80  akt=akt->list_Channels.next;
81  delete tmp;
82  tmp = NULL;
83  }
84  }
85  delete[] m_HashTable;
86  m_HashTable = NULL;
87 #ifdef LOG_CRIME
88  delete m_pMutex;
89 #endif
90 
91  }
struct t_lastmixchannellist::@4 list_Channels
struct t_lastmixchannellist * next

References HASHTABLE_SIZE, t_lastmixchannellist::list_Channels, m_HashTable, and t_lastmixchannellist::next.

Member Function Documentation

◆ add()

SINT32 CALastMixChannelList::add ( HCHANNEL  id,
CASocket pSocket,
CASymChannelCipher pCipher,
CAQueue pQueue 
)

Definition at line 93 of file CALastMixChannelList.cpp.

115  {
116  UINT32 hash=id & HASH_MASK;
117  lmChannelListEntry* pEntry=m_HashTable[hash];
118  lmChannelListEntry* pNewEntry=new lmChannelListEntry;
119  pNewEntry->channelIn=id;
120  pNewEntry->pCipher=pCipher;
121  pNewEntry->pSocket=pSocket;
122  pNewEntry->pQueueSend=pQueue;
123 #if defined (LOG_CHANNEL)
124  pNewEntry->timeCreated=timecreated;
125 #endif
126 #if defined (DELAY_CHANNELS_LATENCY)
127  pNewEntry->timeLatency=delaytime+m_u32DelayChannelLatency;
128 #endif
129 #ifdef LOG_CHANNEL
130  pNewEntry->trafficInFromUser=trafficInFromUser;
131  pNewEntry->packetsDataInFromUser=1;
132  pNewEntry->packetsDataOutToUser=0;
133  pNewEntry->trafficOutToUser=0;
134 #endif
135 #ifdef LOG_CRIME
136  pNewEntry->bIsCrime=bIsCrime;
137  pNewEntry->bLogPayload=bLogPayload;
138  pNewEntry->timeChannelOpened=timeChannelOpened;
139 #endif
140 #ifdef ANON_DEBUG_MODE
141  pNewEntry->bDebug = bDebug;
142 #endif
143  pNewEntry->sendmeCounterDownstream=0;
144  pNewEntry->sendmeCounterUpstream=0;
145 #ifdef DELAY_CHANNELS
146  pNewEntry->delayBucket=m_u32DelayChannelUnlimitTraffic; //can always send some first packets
147  for(UINT32 i=0;i<MAX_POLLFD;i++)
148  {
149  if(m_pDelayBuckets[i]==NULL)
150  {
151  pNewEntry->delayBucketID=i;
152  break;
153  }
154  }
155  m_pDelayBuckets[pNewEntry->delayBucketID]=&pNewEntry->delayBucket;
156 #endif
157  if(pEntry==NULL) //First Entry for Hash in HashTable
158  {
159  pNewEntry->list_Channels.next=NULL;
160  pNewEntry->list_Channels.prev=NULL;
161  }
162  else //insert in Hashlist for Hashtableentry
163  {
164  pNewEntry->list_Channels.prev=NULL;
165  pNewEntry->list_Channels.next=pEntry;
166  pEntry->list_Channels.prev=pNewEntry;
167  }
168  //Insert in SocketList
169 #ifdef LOG_CRIME
170  m_pMutex->lock();
171 #endif
172  if(m_listSockets==NULL)
173  {
174  m_listSockets=pNewEntry;
175  pNewEntry->list_Sockets.next=NULL;
176  pNewEntry->list_Sockets.prev=NULL;
177  }
178  else
179  {
180  pNewEntry->list_Sockets.prev=NULL;
181  pNewEntry->list_Sockets.next=m_listSockets;
182  m_listSockets->list_Sockets.prev=pNewEntry;
183  m_listSockets=pNewEntry;
184  }
185 #ifdef LOG_CRIME
186  m_pMutex->unlock();
187 #endif
188  m_HashTable[hash]=pNewEntry;
189  //if(m_listSocketsNext==NULL)
190  // m_listSocketsNext=m_listSockets;
191  m_nChannels++;
192  return E_SUCCESS;
193  }
#define HASH_MASK
struct t_lastmixchannellist lmChannelListEntry
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
CASymChannelCipher * pCipher
struct t_lastmixchannellist::@5 list_Sockets
struct t_lastmixchannellist * prev

References t_lastmixchannellist::channelIn, E_SUCCESS, HASH_MASK, t_lastmixchannellist::list_Channels, t_lastmixchannellist::list_Sockets, m_HashTable, m_listSockets, m_nChannels, MAX_POLLFD, t_lastmixchannellist::next, t_lastmixchannellist::pCipher, t_lastmixchannellist::pQueueSend, t_lastmixchannellist::prev, t_lastmixchannellist::pSocket, t_lastmixchannellist::sendmeCounterDownstream, and t_lastmixchannellist::sendmeCounterUpstream.

Referenced by CALastMixA::loop(), and test().

Here is the caller graph for this function:

◆ get()

lmChannelListEntry* CALastMixChannelList::get ( HCHANNEL  channelIn)
inline

Definition at line 135 of file CALastMixChannelList.hpp.

136  {
137  lmChannelListEntry* akt=m_HashTable[channelIn & HASH_MASK];
138  while(akt!=NULL)
139  {
140  if(akt->channelIn==channelIn)
141  return akt;
142  akt=akt->list_Channels.next;
143  }
144  return NULL;
145  }

References t_lastmixchannellist::channelIn, HASH_MASK, t_lastmixchannellist::list_Channels, m_HashTable, and t_lastmixchannellist::next.

Referenced by CALastMixA::loop().

Here is the caller graph for this function:

◆ getFirstSocket()

lmChannelListEntry* CALastMixChannelList::getFirstSocket ( )
inline

Definition at line 178 of file CALastMixChannelList.hpp.

179  {
180  if(m_listSockets!=NULL)
182  else
183  m_listSocketsNext=NULL;
184  return m_listSockets;
185  }

References t_lastmixchannellist::list_Sockets, m_listSockets, m_listSocketsNext, and t_lastmixchannellist::next.

Referenced by CALastMix::clean(), CALastMixA::loop(), and test().

Here is the caller graph for this function:

◆ getNextSocket()

lmChannelListEntry* CALastMixChannelList::getNextSocket ( )
inline

Definition at line 187 of file CALastMixChannelList.hpp.

188  {
190  if(m_listSocketsNext!=NULL)
192  return akt;
193  }

References t_lastmixchannellist::list_Sockets, m_listSocketsNext, and t_lastmixchannellist::next.

Referenced by CALastMix::clean(), CALastMixA::loop(), and test().

Here is the caller graph for this function:

◆ getSize()

UINT32 CALastMixChannelList::getSize ( )
inline

Definition at line 197 of file CALastMixChannelList.hpp.

197 {return m_nChannels;}

References m_nChannels.

Referenced by CALastMixA::loop().

Here is the caller graph for this function:

◆ removeChannel()

SINT32 CALastMixChannelList::removeChannel ( HCHANNEL  channelIn)

Definition at line 195 of file CALastMixChannelList.cpp.

196  {
197  UINT32 hash=channel & HASH_MASK;
198  lmChannelListEntry* pEntry=m_HashTable[hash];
199  while(pEntry!=NULL)
200  {
201  if(pEntry->channelIn==channel)
202  {
203  if(m_listSocketsNext==pEntry) //removing next enumeration Element...
205 //remove from HashTable
206  if(pEntry->list_Channels.prev==NULL)
207  m_HashTable[hash]=pEntry->list_Channels.next;
208  else
209  {
211  }
212  if(pEntry->list_Channels.next!=NULL)
213  {
215  }
216  //remove from SocketList
217 #ifdef LOG_CRIME
218  m_pMutex->lock();
219 #endif
220  if(pEntry->list_Sockets.prev==NULL)
222  else
224  if(pEntry->list_Sockets.next!=NULL)
226  #ifdef DELAY_CHANNELS
227  m_pMutexDelayChannel->lock();
228  m_pDelayBuckets[pEntry->delayBucketID]=NULL;
229  m_pMutexDelayChannel->unlock();
230  #endif
231 #ifdef LOG_CRIME
232  if (pEntry->bIsCrime)
233  {
234  int log=LOG_ENCRYPTED;
235  if(!CALibProxytest::getOptions()->isEncryptedLogEnabled())
236  log=LOG_CRIT;
237  char buff[255];
238  strftime(buff, 255, "%Y/%m/%d-%H:%M:%S", localtime(&pEntry->timeChannelOpened));
239  CAMsg::printMsg(log, "Crime channel closed (opened at: %s [unix timestamp: %u]) -- previous mix channel: %u\n", buff,pEntry->timeChannelOpened,pEntry->channelIn);
240  }
241 #endif
242 
243  delete pEntry;
244  pEntry = NULL;
245  m_nChannels--;
246 #ifdef LOG_CRIME
247  m_pMutex->unlock();
248 #endif
249  return E_SUCCESS;
250  }
251  pEntry=pEntry->list_Channels.next;
252  }
253  return E_SUCCESS;
254  }
#define LOG_ENCRYPTED
Definition: CAMsg.hpp:46
static CACmdLnOptions * getOptions()
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
HCHANNEL channel
Definition: typedefs.hpp:0

References channel, t_lastmixchannellist::channelIn, E_SUCCESS, CALibProxytest::getOptions(), HASH_MASK, t_lastmixchannellist::list_Channels, t_lastmixchannellist::list_Sockets, LOG_ENCRYPTED, m_HashTable, m_listSockets, m_listSocketsNext, m_nChannels, t_lastmixchannellist::next, t_lastmixchannellist::prev, and CAMsg::printMsg().

Referenced by CALastMixA::loop(), and test().

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

◆ test()

SINT32 CALastMixChannelList::test ( )
static

Definition at line 256 of file CALastMixChannelList.cpp.

257  {
258 #if !defined (LOG_CHANNEL)&&!defined(DELAY_CHANNELS_LATENCY)&&!defined(LOG_CRIME)&&!defined(ANON_DEBUG_MODE)
259  CALastMixChannelList oList;
260  UINT32 c;
261  UINT32 rand;
262  int i,j;
263  for(i=0;i<100;i++)
264  {
265  getRandom(&c);
266  oList.add(c,NULL,NULL,NULL);
267 
268  }
269  for(i=0;i < 10000;i++)
270  {
271  lmChannelListEntry* akt=oList.getFirstSocket();
272  while(akt!=NULL)
273  {
274  getRandom(&rand);
275  if(rand<0x7FFFFFFF)
276  {
277  getRandom(&c);
278  oList.add(c,NULL,NULL,NULL);
279  }
280  getRandom(&rand);
281  if(rand<0x7FFFFFFF)
282  oList.removeChannel(akt->channelIn);
283  getRandom(&rand);
284  if(rand<0x0FFFFFFF)
285  for(j=0;j<5;j++)
286  {
287  getRandom(&c);
288  oList.add(c,NULL,NULL,NULL);
289  }
290  getRandom(&rand);
291  if(rand<0x7FFFFFFF)
292  for(j=0;j<10000;j++)
293  {
294  getRandom(&c);
295  oList.removeChannel(c);
296  }
297  akt=oList.getNextSocket();
298  }
299  }
300 #endif
301  return 0;
302  }
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
SINT32 add(HCHANNEL id, CASocket *pSocket, CASymChannelCipher *pCipher, CAQueue *pQueue)
lmChannelListEntry * getFirstSocket()
lmChannelListEntry * getNextSocket()
SINT32 removeChannel(HCHANNEL channelIn)

References add(), t_lastmixchannellist::channelIn, getFirstSocket(), getNextSocket(), getRandom(), and removeChannel().

Here is the call graph for this function:

Member Data Documentation

◆ m_HashTable

LP_lmChannelListEntry* CALastMixChannelList::m_HashTable
private

The Hash-Table of all channels.

Definition at line 203 of file CALastMixChannelList.hpp.

Referenced by add(), CALastMixChannelList(), get(), removeChannel(), and ~CALastMixChannelList().

◆ m_listSockets

lmChannelList* CALastMixChannelList::m_listSockets
private

Pointer to the head of a list of all sockets.

Definition at line 206 of file CALastMixChannelList.hpp.

Referenced by add(), CALastMixChannelList(), getFirstSocket(), and removeChannel().

◆ m_listSocketsNext

lmChannelList* CALastMixChannelList::m_listSocketsNext
private

Next Element in the enumeration of all sockets.

Definition at line 208 of file CALastMixChannelList.hpp.

Referenced by CALastMixChannelList(), getFirstSocket(), getNextSocket(), and removeChannel().

◆ m_nChannels

UINT32 CALastMixChannelList::m_nChannels
private

Definition at line 201 of file CALastMixChannelList.hpp.

Referenced by add(), CALastMixChannelList(), getSize(), and removeChannel().


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