Mixe for Privacy and Anonymity in the Internet
CAMiddleMixChannelList.cpp
Go to the documentation of this file.
1 #include "StdAfx.h"
2 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
4 #include "CAUtil.hpp"
5 
6 
8  {
9  m_Mutex.lock();
10  for(UINT32 i=0;i<0x10000;i++)
11  {
13  mmChannelListEntry* pTmpEntry;
14  while(pEntry!=NULL)
15  {
16  pTmpEntry=pEntry;
17  pEntry=pEntry->list_HashTableIn.next;
18  delete pTmpEntry->pCipher;
19  pTmpEntry->pCipher = NULL;
20  delete pTmpEntry;
21  pTmpEntry = NULL;
22  }
23  }
24  delete m_pHashTableIn;
25  m_pHashTableIn = NULL;
26  delete m_pHashTableOut;
27  m_pHashTableOut = NULL;
28  m_Mutex.unlock();
29  }
30 
39  {
40  m_Mutex.lock();
42  pEntry->pCipher=pCipher;
43  pEntry->channelIn=channelIn;
44  pEntry->list_HashTableIn.prev=NULL;
45  pEntry->list_HashTableOut.prev=NULL;
46  do
47  {
48  getRandom(channelOut);
49  }while(*channelOut<256||getOutToIn_intern_without_lock(NULL,*channelOut,NULL)==E_SUCCESS);
50  pEntry->channelOut=*channelOut;
51 
52  mmChannelListEntry* pTmpEntry=m_pHashTableIn[channelIn&0x0000FFFF];
53  pEntry->list_HashTableIn.next=pTmpEntry;
54  if(pTmpEntry!=NULL)
55  pTmpEntry->list_HashTableIn.prev=pEntry;
56  m_pHashTableIn[channelIn&0x0000FFFF]=pEntry;
57 
58  pTmpEntry=m_pHashTableOut[(*channelOut)&0x0000FFFF];
59  pEntry->list_HashTableOut.next=pTmpEntry;
60  if(pTmpEntry!=NULL)
61  pTmpEntry->list_HashTableOut.prev=pEntry;
62  m_pHashTableOut[(*channelOut)&0x0000FFFF]=pEntry;
63 
64  m_Mutex.unlock();
65  return E_SUCCESS;
66  }
67 
69  {
70  m_Mutex.lock();
71  mmChannelListEntry* pEntry=m_pHashTableIn[channelIn&0x0000FFFF];
72  while(pEntry!=NULL)
73  {
74  if(pEntry->channelIn==channelIn)
75  {
76  if(channelOut!=NULL)
77  *channelOut=pEntry->channelOut;
78  if(ppCipher!=NULL)
79  {
80  *ppCipher=pEntry->pCipher;
81  (*ppCipher)->lock();
82  }
83  m_Mutex.unlock();
84  return E_SUCCESS;
85  }
86  pEntry=pEntry->list_HashTableIn.next;
87  }
88  m_Mutex.unlock();
89  return E_UNKNOWN;
90  }
91 
98  {
99  m_Mutex.lock();
100  mmChannelListEntry* pEntry=m_pHashTableIn[channelIn&0x0000FFFF];
101  while(pEntry!=NULL)
102  {
103  if(pEntry->channelIn==channelIn)
104  {
105  delete pEntry->pCipher;
106  pEntry->pCipher = NULL;
107  if(pEntry->list_HashTableIn.prev==NULL)
108  {
109  if(pEntry->list_HashTableIn.next==NULL)
110  {
111  m_pHashTableIn[channelIn&0x0000FFFF]=NULL;
112  }
113  else
114  {
115  m_pHashTableIn[channelIn&0x0000FFFF]=pEntry->list_HashTableIn.next;
117  }
118  }
119  else
120  {
121  if(pEntry->list_HashTableIn.next==NULL)
122  {
124  }
125  else
126  {
129  }
130  }
131  if(pEntry->list_HashTableOut.prev==NULL)
132  {
133  if(pEntry->list_HashTableOut.next==NULL)
134  {
135  m_pHashTableOut[pEntry->channelOut&0x0000FFFF]=NULL;
136  }
137  else
138  {
139  m_pHashTableOut[pEntry->channelOut&0x0000FFFF]=pEntry->list_HashTableOut.next;
141  }
142  }
143  else
144  {
145  if(pEntry->list_HashTableOut.next==NULL)
146  {
148  }
149  else
150  {
153  }
154  }
155  delete pEntry;
156  pEntry = NULL;
157  m_Mutex.unlock();
158  return E_SUCCESS;
159  }
160  pEntry=pEntry->list_HashTableIn.next;
161  }
162  m_Mutex.unlock();
163  return E_UNKNOWN;
164  }
165 
167  {
169  UINT32 c;
170  UINT32 d;
171  UINT32 rand;
172  int i,j;
173  for(i=0;i<1000;i++)
174  {
175  getRandom(&c);
176  oList.add(c,NULL,&d);
177  }
178  for(i=0;i<100;i++)
179  {
180  getRandom(&rand);
181  if(rand<0x0FFFFFFF)
182  for(j=0;j<5;j++)
183  {
184  getRandom(&c);
185  oList.add(c,NULL,&d);
186  }
187  getRandom(&rand);
188  if(rand<0x7FFFFFFF)
189  for(int j=0;j<100000;j++)
190  {
191  getRandom(&c);
192  oList.remove(c);
193  }
194  }
195  return 0;
196  }
197 #endif //ONLY_LOCAL_PROXY
struct t_middlemixchannellist mmChannelListEntry
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
signed int SINT32
Definition: basetypedefs.h:132
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 lock()
Locks the lockable object by threadsafe incrementing a reference counter.
Definition: CALockAble.hpp:55
Data structure that stores all information about the currently open Mix channels.
LP_mmHashTableEntry * m_pHashTableOut
LP_mmHashTableEntry * m_pHashTableIn
SINT32 add(HCHANNEL channelIn, CASymChannelCipher *pCipher, HCHANNEL *channelOut)
Adds a new Channel to the Channellist.
SINT32 getInToOut(HCHANNEL channelIn, HCHANNEL *channelOut, CASymChannelCipher **ppCipher)
SINT32 getOutToIn_intern_without_lock(HCHANNEL *channelIn, HCHANNEL channelOut, CASymChannelCipher **ppCipher)
SINT32 remove(HCHANNEL channelIn)
Removes a channel form the channellist.
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
struct t_middlemixchannellist * prev
struct t_middlemixchannellist * next
struct t_middlemixchannellist * prev
struct t_middlemixchannellist * next
CASymChannelCipher * pCipher
struct t_middlemixchannellist::dl_out list_HashTableOut
struct t_middlemixchannellist::dl_in list_HashTableIn
UINT32 HCHANNEL
Definition: typedefs.hpp:34