Mixe for Privacy and Anonymity in the Internet
CAFirstMixChannelList.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef __CAFRISTMIXCHANNELLIST__
29 #define __CAFRISTMIXCHANNELLIST__
30 #include "doxygen.h"
31 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
32 #include "CAMuxSocket.hpp"
33 #include "CAQueue.hpp"
34 #include "CASymCipher.hpp"
35 #include "CAMutex.hpp"
36 #include "CAMsg.hpp"
38 #include "CASymChannelCipher.hpp"
39 #ifdef DELAY_USERS
40  #include "CAThread.hpp"
41 #endif
42 #ifdef PAYMENT
43 
45 
46 #endif
47 
48 #define KICKOUT_FORCED true
49 #define MAX_KICKOUT_RETRIES 4
50 
52  {
53  public:
56  /* Separate handling of control messages allows to assign control messages a higher priority. */
62 #ifdef CH_LOG_STUDY
63  time_t channelOpenedLastIntervalTS;
64 #endif
65 
66 #ifdef LOG_TRAFFIC_PER_USER
67  UINT32 trafficIn;
68  UINT32 trafficOut;
69  UINT64 timeCreated;
70 #endif
72 
74  UINT8 peerIP[4]; //needed for flooding control
75 #if defined(DATA_RETENTION_LOG) || defined(LOG_CRIME)
76  UINT32 peerPort;
77 #endif
78 #ifdef COUNTRY_STATS
80 #endif
81 
82 #ifdef LOG_DIALOG
83  UINT8* strDialog;
84 #endif
85 
86 #ifdef DELAY_USERS
87  volatile UINT32 delayBucket;
89 #endif
90  // if false, the entry should be deleted the next time it is read from the queue
93  private:
96 
97  struct
98  {
102 
103  // the timeout list
104  // At the moement only enabled for payment Mixes (to be changed iff new mix protcol supports this for all clients)
105 #ifdef PAYMENT
106  struct
107  {
108  struct t_fmhashtableentry* prev;
109  struct t_fmhashtableentry* next;
112 
114 #endif
115  friend class CAFirstMixChannelList;
116 
117  public:
119 #ifdef PAYMENT
120  private:
122  friend class CAAccountingInstance;
124  friend class CAFirstMixA;
125 #endif
126  };
127 
128 typedef struct t_fmhashtableentry fmHashTableEntry;
130 
131 
132 
134  {
135  public:
137 
140 
143 
144 #ifdef LOG_CHANNEL
145  UINT32 packetsInFromUser;
146  UINT64 timeCreated;
147  UINT32 packetsOutToUser;
148 #endif
149 #ifdef ANON_DEBUG_MODE
150  bool bDebug;
151 #endif
152 
153 #ifdef SSL_HACK
154  UINT32 downStreamBytes; /* a hack to solve the SSL problem */
155 #endif
156  private:
157  struct
158  {
162 
163  struct
164  {
165  struct t_firstmixchannellist* prev;
166  struct t_firstmixchannellist* next;
168 
169  friend class CAFirstMixChannelList;
170  };
171 
172 typedef struct t_firstmixchannellist fmChannelList;
175 
177 
226  {
227  public:
230 
231 #ifndef LOG_DIALOG
232  fmHashTableEntry* add(CAMuxSocket* pMuxSocket,const UINT8 peerIP[4],CAQueue* pQueueSend,
233  UINT8* controlChannelKeyRecv,UINT8* controlChannelKeySent);
234 #else
235  fmHashTableEntry* add(CAMuxSocket* pMuxSocket,const UINT8 peerIP[4],CAQueue* pQueueSend,UINT8* strDialog);
236 #endif
237  SINT32 addChannel(CAMuxSocket* pMuxSocket,HCHANNEL channelIn,CASymChannelCipher* pCipher,HCHANNEL* channelOut);
238 
239  fmChannelListEntry* get(CAMuxSocket* pMuxSocket,HCHANNEL channelIn);
240 
241 #ifdef PAYMENT
247 
254  fmHashTableEntry* popTimeoutEntry(bool a_bForce);
255 
256 
257  bool isTimedOut(fmHashTableEntry* pHashTableEntry);
258  bool isKickoutForced(fmHashTableEntry* pHashTableEntry);
259  void setKickoutForced(fmHashTableEntry* pHashTableEntry, bool kickoutForced);
260 
261  bool forceKickout(fmHashTableEntry* pHashTableEntry, const XERCES_CPP_NAMESPACE::DOMDocument *pErrDoc);
265  SINT32 pushTimeoutEntry(fmHashTableEntry* pHashTableEntry, bool kickoutForced = !KICKOUT_FORCED);
266 #endif
267 
268  SINT32 remove(CAMuxSocket* pMuxSocket);
269  SINT32 removeChannel(CAMuxSocket* pMuxSocket,HCHANNEL channelIn);
270 
273  fmHashTableEntry* get(CAMuxSocket* pMuxSocket);
274 
275 
278 
279  static SINT32 test();
280 
281  #ifdef NEW_MIX_TYPE
282  /* additional methods for TypeB first mixes */
283  SINT32 removeClientPart(CAMuxSocket* pMuxSocket);
284  void removeVacantOutChannel(fmChannelListEntry* pEntry);
285  void cleanVacantOutChannels();
286  #endif
287 
288  private:
289 #ifdef PAYMENT
294  SINT32 pushTimeoutEntry_internal(fmHashTableEntry* pHashTableEntry, bool kickoutForced = !KICKOUT_FORCED);
295 
296  inline bool isKickoutForced_internal(fmHashTableEntry* pHashTableEntry);
297  inline void setKickoutForced_internal(fmHashTableEntry* pHashTableEntry, bool kickoutForced);
298 
300 
302 #endif
311  {
312  fmChannelListEntry* pEntry=m_HashTableOutChannels[channelOut&0x0000FFFF];
313  while(pEntry!=NULL)
314  {
315  if(pEntry->channelOut==channelOut)
316  {
317  return pEntry;
318  }
319  pEntry=pEntry->list_OutChannelHashTable.next;
320  }
321  return NULL;
322  }
323 
324  //not thread-safe check if a ChannelList hash entry is timed out. */
325  inline bool isTimedOut_internal(fmHashTableEntry* pHashTableEntry);
326 
327  public:
334  {
335  m_Mutex.lock();
336  fmChannelListEntry* pEntry=get_intern_without_lock(channelOut);
337  m_Mutex.unlock();
338  return pEntry;
339  }
340  private:
342 
347 
352 #ifdef PAYMENT
356 #endif
359 //#ifdef PAYMENT
360 // CAAccountingInstance *m_pAccountingInstance;
361 //#endif
362  #ifdef DELAY_USERS
367  friend THREAD_RETURN fml_loopDelayBuckets(void*);
368  //Parameters
369  volatile UINT32 m_u32DelayChannelUnlimitTraffic; //how many packets without any delay?
370  volatile UINT32 m_u32DelayChannelBucketGrow; //how many packets to put in each bucket per time intervall
371  volatile UINT32 m_u32DelayChannelBucketGrowIntervall; //duration of one time intervall in ms
372  //therefore the allowed max bandwith=BucketGrow/Intervall*1000 *PAYLOAD_SIZE[bytes/s]
373  public:
374  void setDelayParameters(UINT32 unlimitTraffic,UINT32 bucketGrow,UINT32 intervall);
375  void decDelayBuckets(UINT32 delayBucketID);
376  bool hasDelayBuckets(UINT32 delayBucketID);
377  #endif
378 #ifdef DO_TRACE
379  UINT32 m_aktAlloc;
380  UINT32 m_maxAlloc;
381  LP_fmChannelListEntry newChannelListEntry()
382  {
383  m_aktAlloc+=sizeof(fmChannelListEntry);
384  if(m_maxAlloc<m_aktAlloc)
385  {
386  m_maxAlloc=m_aktAlloc;
387  CAMsg::printMsg(LOG_DEBUG,"FirstMixChannelList current alloc: %u\n",m_aktAlloc);
388  }
390  }
391  void deleteChannelListEntry(LP_fmChannelListEntry entry)
392  {
393  m_aktAlloc-=sizeof(fmChannelListEntry);
394  delete entry;
395  entry = NULL;
396  }
397 #endif
398  };
399 #endif
400 #endif //ONLY_LOCAL_PROXY
struct t_firstmixchannellist fmChannelListEntry
#define KICKOUT_FORCED
fmChannelListEntry * LP_fmChannelListEntry
THREAD_RETURN fml_loopDelayBuckets(void *param)
fmHashTableEntry * LP_fmHashTableEntry
#define THREAD_RETURN
Definition: StdAfx.h:540
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
implementation of a per-user control-channel for the AccountingInstance.
This is the AI (accounting instance or abrechnungsinstanz in german) class.
This class "dispatches" messages which it receives via proccessMixPacket() to the associated control ...
Data structure that stores all information about the currently open Mix channels.
fmChannelListEntry * getFirstChannelForSocket(CAMuxSocket *pMuxSocket)
Gets the first channel for a given connection.
void setDelayParameters(UINT32 unlimitTraffic, UINT32 bucketGrow, UINT32 intervall)
fmHashTableEntry * getFirst()
Gets the first connection of all connections in the list.
LP_fmChannelListEntry * m_HashTableOutChannels
The Hash-Table of all out-channels.
volatile UINT32 ** m_pDelayBuckets
bool isKickoutForced(fmHashTableEntry *pHashTableEntry)
bool isTimedOut_internal(fmHashTableEntry *pHashTableEntry)
SINT32 removeFromTimeoutList(fmHashTableEntry *pHashTableEntry)
fmHashTableEntry * m_listTimoutHead
Pointer to the head of the timout list of all connections.
SINT32 addChannel(CAMuxSocket *pMuxSocket, HCHANNEL channelIn, CASymChannelCipher *pCipher, HCHANNEL *channelOut)
Adds a new channel for a given connection to the channel list.
static const SINT32 EXPIRATION_TIME_SECS
fmChannelListEntry * get(CAMuxSocket *pMuxSocket, HCHANNEL channelIn)
Returns the information for a given Input-Channel-ID.
fmHashTableEntry * m_listHashTableNext
Next Element in the enumeration of all connections.
fmHashTableEntry * getNext()
Gets the next entry in the connections-list.
fmChannelListEntry * get_intern_without_lock(HCHANNEL channelOut)
Gets the in-channel and all associated information for the given out-channel.
fmHashTableEntry * m_listHashTableHead
Pointer to the head of a list of all connections.
friend THREAD_RETURN fml_loopDelayBuckets(void *)
bool forceKickout(fmHashTableEntry *pHashTableEntry, const XERCES_CPP_NAMESPACE::DOMDocument *pErrDoc)
forces a kickout for this entry if the entry is still valid and sends an errorMessage via the control...
fmHashTableEntry * popTimeoutEntry_internal(bool a_bForce)
SINT32 removeChannel(CAMuxSocket *pMuxSocket, HCHANNEL channelIn)
Removes a single channel from the list.
bool isTimedOut(fmHashTableEntry *pHashTableEntry)
fmHashTableEntry * m_listTimoutFoot
bool isKickoutForced_internal(fmHashTableEntry *pHashTableEntry)
void decDelayBuckets(UINT32 delayBucketID)
volatile UINT32 m_u32DelayChannelBucketGrowIntervall
fmChannelListEntry * getNextChannel(fmChannelListEntry *pEntry)
Gets the next channel for a given connection.
fmChannelListEntry * get(HCHANNEL channelOut)
Gets the in-channel and all associated information for the given out-channel.
fmHashTableEntry * add(CAMuxSocket *pMuxSocket, const UINT8 peerIP[4], CAQueue *pQueueSend, UINT8 *controlChannelKeyRecv, UINT8 *controlChannelKeySent)
Adds a new TCP/IP connection (a new user) to the channel list.
volatile UINT32 m_u32DelayChannelBucketGrow
SINT32 remove(CAMuxSocket *pMuxSocket)
Removes all channels, which belongs to the given connection and the connection itself from the list.
void setKickoutForced_internal(fmHashTableEntry *pHashTableEntry, bool kickoutForced)
void setKickoutForced(fmHashTableEntry *pHashTableEntry, bool kickoutForced)
LP_fmHashTableEntry * m_HashTable
The Hash-Table of all connections.
fmHashTableEntry * popTimeoutEntry()
SINT32 pushTimeoutEntry(fmHashTableEntry *pHashTableEntry, bool kickoutForced=!KICKOUT_FORCED)
adds the entry to the timeout queue with mutex
bool hasDelayBuckets(UINT32 delayBucketID)
CAMutex m_Mutex
This mutex is used in all functions and makes them thread safe.
SINT32 pushTimeoutEntry_internal(fmHashTableEntry *pHashTableEntry, bool kickoutForced=!KICKOUT_FORCED)
adds the entry to the timeout queue
volatile UINT32 m_u32DelayChannelUnlimitTraffic
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
This is a simple FIFO-Queue.
Definition: CAQueue.hpp:50
Structure that holds all per-user payment information Included in CAFirstMixChannelList (struct fmHas...
Definition: typedefs.hpp:301
CASymChannelCipher * pCipher
struct t_firstmixchannellist * prev
struct t_firstmixchannellist * next
struct t_firstmixchannellist::@2 list_OutChannelHashTable
struct t_firstmixchannellist::@3 list_InChannelPerSocket
volatile UINT32 delayBucketID
struct t_fmhashtableentry * prev
CASymChannelCipher * pSymCipher
CAControlChannelDispatcher * pControlChannelDispatcher
volatile UINT32 delayBucket
CountryID of this IP Address.
CAConditionVariable * cleanupNotifier
struct t_fmhashtableentry::@1 list_TimeoutHashEntries
struct t_firstmixchannellist * pChannelList
tAiAccountingInfo * pAccountingInfo
struct t_fmhashtableentry * next
struct t_fmhashtableentry::@0 list_HashEntries
Definition: typedefs.hpp:169
UINT32 HCHANNEL
Definition: typedefs.hpp:34