|
Mixe for Privacy and Anonymity in the Internet
|
#include <CALastMixChannelList.hpp>
Public Member Functions | |
| CALastMixChannelList () | |
| ~CALastMixChannelList () | |
| SINT32 | add (HCHANNEL id, CASocket *pSocket, CASymCipher *pCipher, CAQueue *pQueue) |
| lmChannelListEntry * | get (HCHANNEL channelIn) |
| lmChannelListEntry * | getFirstSocket () |
| lmChannelListEntry * | getNextSocket () |
| SINT32 | removeChannel (HCHANNEL channelIn) |
| UINT32 | getSize () |
Static Public Member Functions | |
| static SINT32 | test () |
Private Attributes | |
| UINT32 | m_nChannels |
| LP_lmChannelListEntry * | m_HashTable |
| The Hash-Table of all channels. | |
| lmChannelList * | m_listSockets |
| Pointer to the head of a list of all sockets. | |
| lmChannelList * | m_listSocketsNext |
| Next Element in the enumeration of all sockets. | |
| CAMutex | m_Mutex |
| This mutex is used in all functions and makes them thread safe. | |
Definition at line 92 of file CALastMixChannelList.hpp.
Definition at line 33 of file CALastMixChannelList.cpp.
References HASHTABLE_SIZE, m_HashTable, m_listSockets, m_listSocketsNext, m_nChannels, and MAX_POLLFD.
{
m_HashTable=new LP_lmChannelListEntry[HASHTABLE_SIZE];
memset(m_HashTable,0, HASHTABLE_SIZE*sizeof(LP_lmChannelListEntry));
m_listSockets=NULL;
m_listSocketsNext=NULL;
m_nChannels=0;
#ifdef DELAY_CHANNELS
m_u32DelayChannelUnlimitTraffic=DELAY_CHANNEL_TRAFFIC;
m_u32DelayChannelBucketGrow=DELAY_BUCKET_GROW;
m_u32DelayChannelBucketGrowIntervall=DELAY_BUCKET_GROW_INTERVALL;
m_pDelayBuckets=new UINT32*[MAX_POLLFD];
memset(m_pDelayBuckets,0,sizeof(UINT32*)*MAX_POLLFD);
m_pMutexDelayChannel=new CAMutex();
m_pThreadDelayBucketsLoop=new CAThread((UINT8*)"Delay Buckets Thread");
m_bDelayBucketsLoopRun=true;
m_pThreadDelayBucketsLoop->setMainLoop(lml_loopDelayBuckets);
m_pThreadDelayBucketsLoop->start(this);
#endif
#ifdef DELAY_CHANNELS_LATENCY
m_u32DelayChannelLatency=DELAY_CHANNEL_LATENCY;
#endif
}
Definition at line 57 of file CALastMixChannelList.cpp.
References HASHTABLE_SIZE, t_lastmixchannellist::list_Channels, m_HashTable, and t_lastmixchannellist::next.
{
#ifdef DELAY_CHANNELS
m_bDelayBucketsLoopRun=false;
m_pThreadDelayBucketsLoop->join();
delete m_pThreadDelayBucketsLoop;
m_pThreadDelayBucketsLoop = NULL;
delete m_pMutexDelayChannel;
m_pMutexDelayChannel = NULL;
delete []m_pDelayBuckets;
m_pDelayBuckets = NULL;
#endif
for(UINT32 i=0;i < HASHTABLE_SIZE; i++)
{
lmChannelListEntry* akt=m_HashTable[i];
lmChannelListEntry* tmp;
while(akt!=NULL)
{
tmp=akt;
akt=akt->list_Channels.next;
delete tmp;
tmp = NULL;
}
}
delete[] m_HashTable;
m_HashTable = NULL;
}
| SINT32 CALastMixChannelList::add | ( | HCHANNEL | id, |
| CASocket * | pSocket, | ||
| CASymCipher * | pCipher, | ||
| CAQueue * | pQueue | ||
| ) |
Definition at line 85 of file CALastMixChannelList.cpp.
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().
{
UINT32 hash=id & HASH_MASK;
lmChannelListEntry* pEntry=m_HashTable[hash];
lmChannelListEntry* pNewEntry=new lmChannelListEntry;
pNewEntry->channelIn=id;
pNewEntry->pCipher=pCipher;
pNewEntry->pSocket=pSocket;
pNewEntry->pQueueSend=pQueue;
#if defined (LOG_CHANNEL)
pNewEntry->timeCreated=timecreated;
#endif
#if defined (DELAY_CHANNELS_LATENCY)
pNewEntry->timeLatency=delaytime+m_u32DelayChannelLatency;
#endif
#ifdef LOG_CHANNEL
pNewEntry->trafficInFromUser=trafficInFromUser;
pNewEntry->packetsDataInFromUser=1;
pNewEntry->packetsDataOutToUser=0;
pNewEntry->trafficOutToUser=0;
#endif
pNewEntry->sendmeCounterDownstream=0;
pNewEntry->sendmeCounterUpstream=0;
#ifdef DELAY_CHANNELS
pNewEntry->delayBucket=m_u32DelayChannelUnlimitTraffic; //can always send some first packets
for(UINT32 i=0;i<MAX_POLLFD;i++)
{
if(m_pDelayBuckets[i]==NULL)
{
pNewEntry->delayBucketID=i;
break;
}
}
m_pDelayBuckets[pNewEntry->delayBucketID]=&pNewEntry->delayBucket;
#endif
if(pEntry==NULL) //First Entry for Hash in HashTable
{
pNewEntry->list_Channels.next=NULL;
pNewEntry->list_Channels.prev=NULL;
}
else //insert in Hashlist for Hashtableentry
{
pNewEntry->list_Channels.prev=NULL;
pNewEntry->list_Channels.next=pEntry;
pEntry->list_Channels.prev=pNewEntry;
}
//Insert in SocketList
if(m_listSockets==NULL)
{
m_listSockets=pNewEntry;
pNewEntry->list_Sockets.next=NULL;
pNewEntry->list_Sockets.prev=NULL;
}
else
{
pNewEntry->list_Sockets.prev=NULL;
pNewEntry->list_Sockets.next=m_listSockets;
m_listSockets->list_Sockets.prev=pNewEntry;
m_listSockets=pNewEntry;
}
m_HashTable[hash]=pNewEntry;
//if(m_listSocketsNext==NULL)
// m_listSocketsNext=m_listSockets;
m_nChannels++;
return E_SUCCESS;
}
| lmChannelListEntry* CALastMixChannelList::get | ( | HCHANNEL | channelIn | ) | [inline] |
Definition at line 108 of file CALastMixChannelList.hpp.
References t_lastmixchannellist::channelIn, HASH_MASK, t_lastmixchannellist::list_Channels, m_HashTable, and t_lastmixchannellist::next.
Referenced by CALastMixA::loop().
{
lmChannelListEntry* akt=m_HashTable[channelIn & HASH_MASK];
while(akt!=NULL)
{
if(akt->channelIn==channelIn)
return akt;
akt=akt->list_Channels.next;
}
return NULL;
}
| lmChannelListEntry* CALastMixChannelList::getFirstSocket | ( | ) | [inline] |
Definition at line 120 of file CALastMixChannelList.hpp.
References t_lastmixchannellist::list_Sockets, m_listSockets, m_listSocketsNext, and t_lastmixchannellist::next.
Referenced by CALastMix::clean(), CALastMixA::loop(), and test().
{
if(m_listSockets!=NULL)
m_listSocketsNext=m_listSockets->list_Sockets.next;
else
m_listSocketsNext=NULL;
return m_listSockets;
}
| lmChannelListEntry* CALastMixChannelList::getNextSocket | ( | ) | [inline] |
Definition at line 129 of file CALastMixChannelList.hpp.
References t_lastmixchannellist::list_Sockets, m_listSocketsNext, and t_lastmixchannellist::next.
Referenced by CALastMix::clean(), CALastMixA::loop(), and test().
{
lmChannelListEntry* akt=m_listSocketsNext;
if(m_listSocketsNext!=NULL)
m_listSocketsNext=m_listSocketsNext->list_Sockets.next;
return akt;
}
| UINT32 CALastMixChannelList::getSize | ( | ) | [inline] |
Definition at line 139 of file CALastMixChannelList.hpp.
References m_nChannels.
Referenced by CALastMixA::loop().
{return m_nChannels;}
| SINT32 CALastMixChannelList::removeChannel | ( | HCHANNEL | channelIn | ) |
Definition at line 159 of file CALastMixChannelList.cpp.
References t_lastmixchannellist::channelIn, E_SUCCESS, HASH_MASK, t_lastmixchannellist::list_Channels, t_lastmixchannellist::list_Sockets, m_HashTable, m_listSockets, m_listSocketsNext, m_nChannels, t_lastmixchannellist::next, and t_lastmixchannellist::prev.
Referenced by CALastMixA::loop(), and test().
{
UINT32 hash=channel & HASH_MASK;
lmChannelListEntry* pEntry=m_HashTable[hash];
while(pEntry!=NULL)
{
if(pEntry->channelIn==channel)
{
if(m_listSocketsNext==pEntry) //removing next enumeration Element...
m_listSocketsNext=m_listSocketsNext->list_Sockets.next; //adjusting!
//remove from HashTable
if(pEntry->list_Channels.prev==NULL)
m_HashTable[hash]=pEntry->list_Channels.next;
else
{
pEntry->list_Channels.prev->list_Channels.next=pEntry->list_Channels.next;
}
if(pEntry->list_Channels.next!=NULL)
{
pEntry->list_Channels.next->list_Channels.prev=pEntry->list_Channels.prev;
}
//remove from SocketList
if(pEntry->list_Sockets.prev==NULL)
m_listSockets=pEntry->list_Sockets.next;
else
pEntry->list_Sockets.prev->list_Sockets.next=pEntry->list_Sockets.next;
if(pEntry->list_Sockets.next!=NULL)
pEntry->list_Sockets.next->list_Sockets.prev=pEntry->list_Sockets.prev;
#ifdef DELAY_CHANNELS
m_pMutexDelayChannel->lock();
m_pDelayBuckets[pEntry->delayBucketID]=NULL;
m_pMutexDelayChannel->unlock();
#endif
delete pEntry;
pEntry = NULL;
m_nChannels--;
return E_SUCCESS;
}
pEntry=pEntry->list_Channels.next;
}
return E_SUCCESS;
}
| SINT32 CALastMixChannelList::test | ( | ) | [static] |
Definition at line 202 of file CALastMixChannelList.cpp.
References add(), t_lastmixchannellist::channelIn, getFirstSocket(), getNextSocket(), getRandom(), and removeChannel().
{
#if !defined (LOG_CHANNEL)&&!defined(DELAY_CHANNELS_LATENCY)
CALastMixChannelList oList;
UINT32 c;
UINT32 rand;
int i,j;
for(i=0;i<100;i++)
{
getRandom(&c);
oList.add(c,NULL,NULL,NULL);
}
for(i=0;i < 10000;i++)
{
lmChannelListEntry* akt=oList.getFirstSocket();
while(akt!=NULL)
{
getRandom(&rand);
if(rand<0x7FFFFFFF)
{
getRandom(&c);
oList.add(c,NULL,NULL,NULL);
}
getRandom(&rand);
if(rand<0x7FFFFFFF)
oList.removeChannel(akt->channelIn);
getRandom(&rand);
if(rand<0x0FFFFFFF)
for(j=0;j<5;j++)
{
getRandom(&c);
oList.add(c,NULL,NULL,NULL);
}
getRandom(&rand);
if(rand<0x7FFFFFFF)
for(j=0;j<10000;j++)
{
getRandom(&c);
oList.removeChannel(c);
}
akt=oList.getNextSocket();
}
}
#endif
return 0;
}
The Hash-Table of all channels.
Definition at line 145 of file CALastMixChannelList.hpp.
Referenced by add(), CALastMixChannelList(), get(), removeChannel(), and ~CALastMixChannelList().
lmChannelList* CALastMixChannelList::m_listSockets [private] |
Pointer to the head of a list of all sockets.
Definition at line 148 of file CALastMixChannelList.hpp.
Referenced by add(), CALastMixChannelList(), getFirstSocket(), and removeChannel().
Next Element in the enumeration of all sockets.
Definition at line 150 of file CALastMixChannelList.hpp.
Referenced by CALastMixChannelList(), getFirstSocket(), getNextSocket(), and removeChannel().
CAMutex CALastMixChannelList::m_Mutex [private] |
This mutex is used in all functions and makes them thread safe.
Definition at line 152 of file CALastMixChannelList.hpp.
UINT32 CALastMixChannelList::m_nChannels [private] |
Definition at line 143 of file CALastMixChannelList.hpp.
Referenced by add(), CALastMixChannelList(), getSize(), and removeChannel().
1.7.6.1