Mixe for Privacy and Anonymity in the Internet
CALastMixChannelList.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 __CALASTMIXCHANNELLIST__
29 #define __CALASTMIXCHANNELLIST__
30 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_LAST_MIX
31 #include "CASocket.hpp"
32 #include "CAMuxSocket.hpp"
33 #include "CAQueue.hpp"
34 #include "CASymChannelCipher.hpp"
35 #ifdef WITH_INTEGRITY_CHECK
36 #include "CASymCipherGCM.hpp"
37 #endif
38 #include "CAMutex.hpp"
39 #include "CAMsg.hpp"
40 #include "CAThread.hpp"
41 
42 #define HASHTABLE_SIZE 0x00010000
43 #define HASH_MASK 0x0000FFFF
44 
46  {
47  public:
48 
50 #ifdef WITH_INTEGRITY_CHECK
52 #else
54 #endif
57  SINT32 sendmeCounterDownstream; //this counts how many packets are sent to the user without an ack recevied yet.
58  SINT32 sendmeCounterUpstream; //this counts how many packets are recieved from the user without sending an ack yet.
59 #ifdef DELAY_CHANNELS
60  UINT32 delayBucket;
61  UINT32 delayBucketID;
62 #endif
63 #if defined (LOG_CHANNEL)
64  UINT64 timeCreated;
65 #endif
66 #if defined (DELAY_CHANNELS_LATENCY)
67  UINT64 timeLatency;
68 #endif
69 #ifdef LOG_CHANNEL
70  UINT32 trafficInFromUser;
71  UINT32 packetsDataOutToUser;
72  UINT32 packetsDataInFromUser;
73  UINT32 trafficOutToUser;
74 #endif
75 #ifdef LOG_CRIME
76  bool bIsCrime;
77  bool bLogPayload;
78  time_t timeChannelOpened;
79 #endif
80 #ifdef ANON_DEBUG_MODE
81  bool bDebug;
82 #endif
83  private:
84  struct
85  {
89 
90  struct
91  {
92  struct t_lastmixchannellist* prev;
93  struct t_lastmixchannellist* next;
95 
96  friend class CALastMixChannelList;
97  };
98 
99 typedef struct t_lastmixchannellist lmChannelList;
102 
103  #ifdef DELAY_CHANNELS
104  THREAD_RETURN lml_loopDelayBuckets(void*);
105  #endif
107  {
108  public:
111 
112 
113  SINT32 add(HCHANNEL id,CASocket* pSocket,
114 #ifdef WITH_INTEGRITY_CHECK
115  CASymCipherGCM* pCipher
116 #else
117  CASymChannelCipher* pCipher
118 #endif
119  ,CAQueue* pQueue
120 #ifdef LOG_CHANNEL
121  ,UINT64 timecreated,UINT32 trafficIn
122 #endif
123 #if defined(DELAY_CHANNELS_LATENCY)
124  ,UINT64 delaytime
125 #endif
126 #ifdef LOG_CRIME
127  ,bool bIsCrime,bool bLogPayload, time_t timeChannelOpend
128 #endif
129 #ifdef ANON_DEBUG_MODE
130  , bool bDebug
131 #endif
132 
133  );
134 
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  }
146 #ifdef LOG_CRIME
147  SINT32 getChannelAndSetCrime(UINT8 lastMixToProxyConnectionSrcIP[4],
148  UINT16 lastMixToProxyConnectionSrcPort,
149  UINT8 lastMixToProxyConnectionDstIP[4],
150  UINT16 lastMixToProxyConnectionDstPort, HCHANNEL& channel)
151  {
152  m_pMutex->lock();
154  while (pEntry != NULL)
155  {
156  CASocket* pSocket = pEntry->pSocket;
157  if (pSocket->getLocalPort() == lastMixToProxyConnectionSrcPort &&
158  pSocket->getPeerPort() == lastMixToProxyConnectionDstPort)
159  { //Ports match --> check IPs
160  UINT8 ip[4];
161  if (pSocket->getPeerIP(ip) == E_SUCCESS && memcmp(ip, lastMixToProxyConnectionDstIP,4) == 0)
162  {
163  if (pSocket->getLocalIP(ip) == E_SUCCESS && memcmp(ip, lastMixToProxyConnectionSrcIP,4) == 0)
164  {
165  channel = pEntry->channelIn;
166  pEntry->bIsCrime = true;
167  m_pMutex->unlock();
168  return E_SUCCESS;
169  }
170  }
171  }
172  pEntry = pEntry->list_Sockets.next;
173  }
174  m_pMutex->unlock();
175  return E_UNKNOWN;
176  }
177 #endif
179  {
180  if(m_listSockets!=NULL)
182  else
183  m_listSocketsNext=NULL;
184  return m_listSockets;
185  }
186 
188  {
190  if(m_listSocketsNext!=NULL)
192  return akt;
193  }
194 
195 // SINT32 removeChannel(CASocket* pSocket);
196  SINT32 removeChannel(HCHANNEL channelIn);
198  static SINT32 test();
199 
200  private:
201  UINT32 m_nChannels; //Number of channels in list
204 
210 #ifdef LOG_CRIME
211  CAMutex* m_pMutex;
212 #endif
213  #ifdef DELAY_CHANNELS
214  UINT32** m_pDelayBuckets;
215  CAThread* m_pThreadDelayBucketsLoop;
216  CAMutex* m_pMutexDelayChannel;
217  bool m_bDelayBucketsLoopRun;
218  friend THREAD_RETURN lml_loopDelayBuckets(void*);
219  //Parameters
220  volatile UINT32 m_u32DelayChannelUnlimitTraffic; //how much traffic without any delay?
221  volatile UINT32 m_u32DelayChannelBucketGrow; //how many bytes to put in each bucket per time intervall
222  volatile UINT32 m_u32DelayChannelBucketGrowIntervall; //duration of one time intervall in ms
223  //therefore the allowed bandwith=BucketGrow/Intervall*1000 [bytes/s]
224  public:
225  void setDelayParameters(UINT32 unlimitTraffic,UINT32 bucketGrow,UINT32 intervall);
226  void reduceDelayBuckets(UINT32 delayBucketID, UINT32 amount);
227  //bool hasDelayBuckets(UINT32 delayBucketID);
228  //UINT32 getDelayBuckets(UINT32 delayBucketID);
229  #endif
230  #ifdef DELAY_CHANNELS_LATENCY
231  //Parameters
232  volatile UINT32 m_u32DelayChannelLatency; //min latency in ms
233  public:
234  void setDelayLatencyParameters(UINT32 latency);
235  #endif
236  };
237 #endif
238 #endif //ONLY_LOCAL_PROXY
lmChannelListEntry * LP_lmChannelListEntry
#define HASH_MASK
#define THREAD_RETURN
Definition: StdAfx.h:540
unsigned short UINT16
Definition: basetypedefs.h:133
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
lmChannelListEntry * get(HCHANNEL channelIn)
SINT32 add(HCHANNEL id, CASocket *pSocket, CASymChannelCipher *pCipher, CAQueue *pQueue)
lmChannelList * m_listSockets
Pointer to the head of a list of all sockets.
lmChannelListEntry * getFirstSocket()
lmChannelListEntry * getNextSocket()
lmChannelList * m_listSocketsNext
Next Element in the enumeration of all sockets.
SINT32 removeChannel(HCHANNEL channelIn)
LP_lmChannelListEntry * m_HashTable
The Hash-Table of all channels.
This is a simple FIFO-Queue.
Definition: CAQueue.hpp:50
virtual SINT32 getPeerPort()
Definition: CASocket.cpp:830
virtual SINT32 getPeerIP(UINT8 ip[4])
Definition: CASocket.cpp:820
virtual SINT32 getLocalIP(UINT8 r_Ip[4])
LERNGRUPPE Returns the source address of the socket.
Definition: CASocket.cpp:801
virtual SINT32 getLocalPort()
Definition: CASocket.cpp:811
This class could be used for encryption/decryption of data (streams) with AES using 128bit GCM mode.
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3
struct t_lastmixchannellist::@4 list_Channels
CASymChannelCipher * pCipher
struct t_lastmixchannellist::@5 list_Sockets
struct t_lastmixchannellist * next
struct t_lastmixchannellist * prev
HCHANNEL channel
Definition: typedefs.hpp:0
UINT32 HCHANNEL
Definition: typedefs.hpp:34