Mixe for Privacy and Anonymity in the Internet
CALastMixB.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, The JAP-Team
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, 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
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * - Neither the name of the University of Technology Dresden, Germany nor
15  * the names of its contributors may be used to endorse or promote
16  * products derived from this software without specific prior written
17  * permission.
18  *
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE
31  */
32 #include "../StdAfx.h"
33 #ifndef ONLY_LOCAL_PROXY
34 #include "CALastMixB.hpp"
35 #include "typedefsb.hpp"
37 #include "../CASingleSocketGroup.hpp"
38 #include "../CAPool.hpp"
39 #include "../CACmdLnOptions.hpp"
40 #include "../CAUtil.hpp"
41 #include "../CALibProxytest.hpp"
42 
43 #ifdef HAVE_EPOLL
44  #include "../CASocketGroupEpoll.hpp"
45 #endif
46 
48  m_pChainTable = NULL;
49  m_pChannelTable = NULL;
50 }
51 
53  #ifdef DELAY_CHANNELS
54  CAMsg::printMsg(LOG_DEBUG, "CALastMixB: Set new resources limitation parameters.\n");
55  if (m_pChainTable != NULL) {
56  m_pChainTable->setDelayParameters(CALibProxytest::getOptions()->getDelayChannelUnlimitTraffic(), CALibProxytest::getOptions()->getDelayChannelBucketGrow(),
57  CALibProxytest::getOptions()->getDelayChannelBucketGrowIntervall());
58  }
59  #endif
60 }
61 
62 
64 #ifdef NEW_MIX_TYPE
65  /* should only be compiled, if TypeB mixes are used */
68  #ifdef DELAY_CHANNELS
69  m_pChainTable->setDelayParameters(pglobalOptions->getDelayChannelUnlimitTraffic(), pglobalOptions->getDelayChannelBucketGrow(), pglobalOptions->getDelayChannelBucketGrowIntervall());
70  #endif
71 
72  #ifdef HAVE_EPOLL
73  CASocketGroupEpoll* psocketgroupCacheRead = new CASocketGroupEpoll(false);
74  CASocketGroupEpoll* psocketgroupCacheWrite = new CASocketGroupEpoll(true);
75  #else
76  CASocketGroup* psocketgroupCacheRead = new CASocketGroup(false);
77  CASocketGroup* psocketgroupCacheWrite = new CASocketGroup(true);
78  #endif
79 
80  UINT8 rsaOutputBuffer[RSA_SIZE];
85 
86  /* start logging */
87  CAThread* pLogThread = new CAThread((UINT8*)"CALastMixB - LogLoop");
88  pLogThread->setMainLoop(lm_loopLog);
89  pLogThread->start(this);
90 
91  /* initialize some pointers */
92  tQueueEntry* currentQueueEntry = new tQueueEntry;
93  MIXPACKET* currentMixPacket = &(currentQueueEntry->packet);
94  t_upstreamChainCell* pChainCell = (t_upstreamChainCell*)(currentMixPacket->data);
95 
96  #ifdef LOG_CHAIN_STATISTICS
97  CAMsg::printMsg(LOG_DEBUG, "Chain log format is: Chain-ID, Chain duration [micros], Upload (bytes), Download (bytes), Packets from user, Packets to user\n");
98  #endif
99 
100  while(!m_bRestart) {
101  /* begin of the mix-loop */
102  bool bAktiv = false;
103 
104 // Step 1a: reading from previous Mix --> now in separate thread
105 // Step 1b: processing MixPackets from previous mix
106 
107  if (m_pQueueReadFromMix->getSize() >= sizeof(tQueueEntry)) {
108  /* there is something to do in upstream-direction */
109  bAktiv = true;
110  UINT32 chains = m_pChainTable->getSize();
111  /* limit the number of processed upstream-packets depending on the
112  * number of currently forwarded data-chains
113  */
114  for (UINT32 k = 0; (k < (chains + 1)) && (m_pQueueReadFromMix->getSize() >= sizeof(tQueueEntry)); k++) {
115  UINT32 readBytes = sizeof(tQueueEntry);
116  m_pQueueReadFromMix->get((UINT8*)currentQueueEntry, &readBytes);
117  #ifdef LOG_PACKET_TIMES
118  getcurrentTimeMicros(currentQueueEntry->timestamp_proccessing_start_OP);
119  #endif
120  if ((currentMixPacket->channel > 0) && (currentMixPacket->channel < 256)) {
121  /* it's a control-channel packet */
123  /* process the next packet */
124  continue;
125  }
126  /* a data-channel packet received */
128  if (currentMixPacket->flags & CHANNEL_DUMMY) {
129  /* it's only a dummy-packet -> ignore it */
130  continue;
131  }
132  t_lastMixBChannelListEntry* pChannelListEntry = m_pChannelTable->get(currentMixPacket->channel);
133  if (pChannelListEntry == NULL) {
134  /* it's a new channel */
135  #ifdef _DEBUG1
136  CAMsg::printMsg(LOG_DEBUG, "New channel from previous Mix!\n");
137  #endif
138  m_pRSA->decrypt(currentMixPacket->data, rsaOutputBuffer);
139  #ifdef REPLAY_DETECTION
140  if (m_pReplayDB->insert(rsaOutputBuffer) != E_SUCCESS) {
141  /* we know such a packet already */
142  CAMsg::printMsg(LOG_INFO, "Replay: Duplicate packet ignored.\n");
143  /* currently we have to send at least a CHANNEL-CLOSE -> reuse
144  * our buffers for the response
145  */
146  getRandom(currentMixPacket->data, DATA_SIZE);
147  currentMixPacket->flags = CHANNEL_CLOSE;
148  #ifdef LOG_PACKET_TIMES
149  /* set invalid packet time for the response */
150  setZero64(currentQueueEntry->timestamp_proccessing_start);
151  #endif
152  m_pQueueSendToMix->add(currentMixPacket, sizeof(tQueueEntry));
154  /* process the next packet */
155  continue;
156  }
157  #endif
158  /* copy the RSA output-buffer back in the mix-packet (without the
159  * symmetric key -> decrypted data will start at the data-pointer
160  * of the packet)
161  */
162  memcpy(currentMixPacket->data, rsaOutputBuffer + KEY_SIZE, RSA_SIZE - KEY_SIZE);
163  /* initialize the channel-cipher */
164  CASymCipher* channelCipher = new CASymCipher();
165  channelCipher->setKey(rsaOutputBuffer);
166  /* uncrypt the packet (because the symmetric key at the begin is
167  * removed, we have to pull out the decrypted data)
168  */
169  channelCipher->crypt1((currentMixPacket->data) + RSA_SIZE, (currentMixPacket->data) + RSA_SIZE - KEY_SIZE, DATA_SIZE - RSA_SIZE);
170  #ifdef LOG_PACKET_TIMES
171  getcurrentTimeMicros(currentQueueEntry->timestamp_proccessing_end_OP);
172  #endif
173  UINT16 lengthAndFlags = ntohs(pChainCell->lengthAndFlags);
174  UINT16 payloadLength = lengthAndFlags & CHAINFLAG_LENGTH_MASK;
176  #ifdef _DEBUG1
177  CAMsg::printMsg(LOG_DEBUG, "Creating new chain.\n");
178  #endif
179  CAChain* currentChain = m_pChainTable->createEntry();
180  if (currentChain == NULL) {
181  /* we are unable to create a new chain (maximum number of
182  * chains - defined in MAX_POLLFD - is reached)
183  */
184  CAMsg::printMsg(LOG_INFO, "Unable to create more than %u chains - dropped new chain.\n", MAX_POLLFD);
185  delete channelCipher;
186  channelCipher = NULL;
187  /* currently we have to send at least a CHANNEL-CLOSE -> reuse
188  * our buffers for the response
189  */
190  getRandom(currentMixPacket->data, DATA_SIZE);
191  currentMixPacket->flags = CHANNEL_CLOSE;
192  #ifdef LOG_PACKET_TIMES
193  /* set invalid packet time for the response */
194  setZero64(pQueueEntry->timestamp_proccessing_start);
195  #endif
196  m_pQueueSendToMix->add(currentMixPacket, sizeof(tQueueEntry));
198  /* process the next packet */
199  continue;
200  }
201  currentChain->addChannel(m_pChannelTable->add(currentMixPacket->channel, channelCipher, currentChain), ((lengthAndFlags & CHAINFLAG_FAST_RESPONSE) == CHAINFLAG_FAST_RESPONSE));
202  /* Attention: The type-field is handled as part of the payload-
203  * data --> to get the useable payload we have to
204  * subtract the size of the type-field.
205  */
206  payloadLength = payloadLength - 1;
207  if (payloadLength <= MAX_FIRST_UPSTREAM_CHAINCELL_PAYLOAD) {
208  /* it's a valid new chain */
209  CASocket* tmpSocket = new CASocket;
210  CACacheLoadBalancing* pLoadBalancing = m_pCacheLB;
211  if (pChainCell->firstCell.type == MIX_PAYLOAD_SOCKS) {
212  pLoadBalancing = m_pSocksLB;
213  }
214  SINT32 errorCode = E_UNKNOWN;
215  /* build a new connection to one of the known proxy-servers */
216  for (UINT32 count=0; count < pLoadBalancing->getElementCount(); count++) {
217  tmpSocket->create();
218  tmpSocket->setRecvBuff(50000);
219  tmpSocket->setSendBuff(5000);
220  errorCode = tmpSocket->connect(*pLoadBalancing->get(), LAST_MIX_TO_PROXY_CONNECT_TIMEOUT);
221  if (errorCode == E_SUCCESS) {
222  break;
223  }
224  tmpSocket->close();
225  }
226  if (errorCode != E_SUCCESS) {
227  /* could not connect to any proxy */
228  CAMsg::printMsg(LOG_DEBUG,"Cannot connect to Squid!\n");
229  delete tmpSocket;
230  tmpSocket = NULL;
231  /* close the chain immediately */
232  currentChain->signalConnectionError();
233  }
234  else {
235  /* we have a connection to a proxy */
236  #ifdef LOG_CHAIN_STATISTICS
237  currentChain->setSocket(tmpSocket, 1, payloadLength);
238  #else
239  currentChain->setSocket(tmpSocket);
240  #endif
241  #ifdef _DEBUG1
242  /* log the first 30 byte of the chain-data */
243  UINT8 c = pChainCell->firstCell.data[30];
244  /* make a temporary string-cut after 30 byte */
245  pChainCell->firstCell.data[30] = 0;
246  CAMsg::printMsg(LOG_DEBUG, "Try sending data to Squid: %s\n", pChainCell->firstCell.data);
247  pChainCell->firstCell.data[30] = c;
248  #endif
249  #ifdef LOG_CRIME
250  if (checkCrime(pChainCell->firstCell.data, payloadLength)) {
251  /* we've captured a stupid gangsta, who sent a suspected
252  * webaddress completely in the first packet
253  */
255  /* ensure that there is a trailing 0 -> use one byte more
256  * than necessary for the plain data
257  */
258  memset(crimeBuff, 0, MAX_FIRST_UPSTREAM_CHAINCELL_PAYLOAD + 1);
259  memcpy(crimeBuff, pChainCell->firstCell.data, payloadLength);
260  /* for compatibility with the default mix-implementation
261  * we will send an extra-packet on the channel with a
262  * crime-signal (without using the channel-cipher)
263  */
264  tQueueEntry oSigCrimeQueueEntry;
265  memset(&oSigCrimeQueueEntry, 0, sizeof(tQueueEntry));
266  UINT32 id = m_pMuxIn->sigCrime(currentMixPacket->channel, &oSigCrimeQueueEntry.packet);
267  m_pQueueSendToMix->add(&oSigCrimeQueueEntry, sizeof(tQueueEntry));
269  int log = LOG_ENCRYPTED;
270  if (!pglobalOptions->isEncryptedLogEnabled()) {
271  log = LOG_CRIT;
272  CAMsg::printMsg(log,"Crime detected -- ID: %u -- Content: \n%s\n", id, crimeBuff);
273  }
274  }
275  #endif
276  if (tmpSocket->sendTimeOut(pChainCell->firstCell.data, payloadLength, LAST_MIX_TO_PROXY_SEND_TIMEOUT) == SOCKET_ERROR) {
277  #ifdef _DEBUG
278  CAMsg::printMsg(LOG_DEBUG,"Error sending data to Squid!\n");
279  #endif
280  currentChain->signalConnectionError();
281  }
282  else {
283  tmpSocket->setNonBlocking(true);
284  currentChain->addToSocketGroup(psocketgroupCacheRead);
285  #ifdef LOG_PACKET_TIMES
286  getcurrentTimeMicros(currentQueueEntry->timestamp_proccessing_end);
287  m_pLogPacketStats->addToTimeingStats(*currentQueueEntry, CHANNEL_OPEN, true);
288  #endif
290  /* close upstream (after sending data) */
291  currentChain->closeUpstream();
292  }
293  }
294  }
295  }
296  else {
297  /* invalid packet length */
298  currentChain->signalConnectionError();
299  }
300  }
301  else {
302  /* new-chain flag is not set */
303  CAChain* currentChain = m_pChainTable->getEntry(pChainCell->sequelCell.chainId);
304  if (currentChain != NULL) {
305  #ifdef _DEBUG1
306  CAMsg::printMsg(LOG_DEBUG, "Continue existent chain.\n");
307  #endif
308  /* we've found the specified chain in the table */
309  currentChain->addChannel(m_pChannelTable->add(currentMixPacket->channel, channelCipher, currentChain), ((lengthAndFlags & CHAINFLAG_FAST_RESPONSE) == CHAINFLAG_FAST_RESPONSE));
310  if (payloadLength <= MAX_SEQUEL_UPSTREAM_CHAINCELL_PAYLOAD) {
311  /* payload-length is valid */
312  if (payloadLength > 0) {
313  currentChain->addDataToUpstreamQueue(pChainCell->sequelCell.data, payloadLength);
314  currentChain->addToSocketGroup(psocketgroupCacheWrite);
315  }
316  #ifdef LOG_CHAIN_STATISTICS
317  /* also add empty packets to the queue (will do nothing, but
318  * adds the received packet to the statistics)
319  */
320  else {
321  currentChain->addDataToUpstreamQueue(pChainCell->sequelCell.data, payloadLength);
322  }
323  #endif
324  #ifdef LOG_PACKET_TIMES
325  getcurrentTimeMicros(currentQueueEntry->timestamp_proccessing_end);
326  m_pLogPacketStats->addToTimeingStats(*currentQueueEntry, CHANNEL_DATA, true);
327  #endif
329  /* close upstream (after sending data) */
330  currentChain->closeUpstream();
331  }
332  }
333  else {
334  /* invalid payload-length */
335  currentChain->signalConnectionError();
336  }
337  }
338  else {
339  #ifdef _DEBUG1
340  CAMsg::printMsg(LOG_DEBUG, "Unknown chain - cannot continue chain.\n");
341  #endif
342  /* we don't know a chain with the specified ID -> create a
343  * dummy-chain and signal an unknown-chain-error
344  */
345  currentChain = m_pChainTable->createEntry();
346  if (currentChain == NULL) {
347  /* we are unable to create a new chain (maximum number of
348  * chains - defined in MAX_POLLFD - is reached)
349  */
350  CAMsg::printMsg(LOG_INFO, "Unable to create more than %u chains - cannot send 'unknown chain' response.\n", MAX_POLLFD);
351  delete channelCipher;
352  channelCipher = NULL;
353  /* currently we have to send at least a CHANNEL-CLOSE -> reuse
354  * our buffers for the response
355  */
356  getRandom(currentMixPacket->data, DATA_SIZE);
357  currentMixPacket->flags = CHANNEL_CLOSE;
358  #ifdef LOG_PACKET_TIMES
359  /* set invalid packet time for the response */
360  setZero64(pQueueEntry->timestamp_proccessing_start);
361  #endif
362  m_pQueueSendToMix->add(currentMixPacket, sizeof(tQueueEntry));
364  /* process the next packet */
365  continue;
366  }
367  currentChain->addChannel(m_pChannelTable->add(currentMixPacket->channel, channelCipher, currentChain), ((lengthAndFlags & CHAINFLAG_FAST_RESPONSE) == CHAINFLAG_FAST_RESPONSE));
368  currentChain->signalUnknownChain();
369  }
370  }
371  }
372  else {
373  /* it's not the first channel-packet -> currently only one upstream-
374  * packet is allowed -> ignore this one
375  */
376  CAMsg::printMsg(LOG_INFO, "Received more than one packet on a channel.\n");
377  }
378  }
379  }
380 
381 //end Step 1
382 
383 //Step 2 Sending to Cache...
384 
385  /* check for chains which have data in the upstream-queue (only those
386  * chains are in the socket-group) and having also a send-ready socket
387  */
388  SINT32 sendReadySockets = psocketgroupCacheWrite->select(0);
389  if (sendReadySockets > 0) {
390  bAktiv=true;
391  #ifdef HAVE_EPOLL
392  CAChain* currentChain = (CAChain*)psocketgroupCacheWrite->getFirstSignaledSocketData();
393  while (currentChain != NULL) {
394  add64((UINT64&)m_logUploadedBytes, currentChain->sendUpstreamData(MIXPACKET_SIZE, psocketgroupCacheWrite));
395  currentChain = (CAChain*)(psocketgroupCacheWrite->getNextSignaledSocketData());
396  }
397  #else
398  CAChain* currentChain = m_pChainTable->getFirstEntry();
399  while ((currentChain != NULL) && (sendReadySockets > 0)) {
400  if (currentChain->isSignaledInSocketGroup(psocketgroupCacheWrite)) {
401  sendReadySockets--;
402  add64((UINT64&)m_logUploadedBytes, currentChain->sendUpstreamData(MIXPACKET_SIZE, psocketgroupCacheWrite));
403  }
404  currentChain = m_pChainTable->getNextEntry();
405  }
406  #endif
407  }
408 
409 //End Step 2
410 
411 //Step 3 Reading from Cache....
412 
413  #define MAX_MIXIN_SEND_QUEUE_SIZE 1000000
414  psocketgroupCacheRead->select(0);
416  /* we are able to send data to the previos mix -> ask every chain
417  * whether we can process something
418  */
419  CAChain* currentChain = m_pChainTable->getFirstEntry();
420  while (currentChain != NULL) {
421  #ifdef LOG_PACKET_TIMES
422  /* timestamps are only meaningful, if a packet is created and sent,
423  * in the other case they will be overwritten by the next chain
424  */
425  getcurrentTimeMicros(currentQueueEntry->timestamp_proccessing_start);
426  set64(currentQueueEntry->timestamp_proccessing_start_OP, currentQueueEntry->timestamp_proccessing_start);
427  #endif
428  UINT32 processedBytes;
429  SINT32 status = currentChain->processDownstream(psocketgroupCacheRead, currentMixPacket, &processedBytes);
430  add64((UINT64&)m_logDownloadedBytes, processedBytes);
431  if ((status == 0) || (status == 2)) {
432  /* there was a packet created -> send it */
433  #ifdef LOG_PACKET_TIMES
434  getcurrentTimeMicros(currentQueueEntry->timestamp_proccessing_end_OP);
435  #endif
436  m_pQueueSendToMix->add(currentMixPacket, sizeof(tQueueEntry));
438  }
439  if ((status == 2) || (status == 3)) {
440  /* chain can be removed from the table */
441  m_pChainTable->deleteEntry(currentChain->getChainId());
442  }
443  currentChain = m_pChainTable->getNextEntry();
444  }
445  }
446 
447 //end Step 3
448 
449 //Step 4 Writing to previous Mix
450 // Now in a separate Thread!
451 //end step 4
452 
453  if (!bAktiv) {
454  /* there was no data to process in upstream and downstream direction
455  * -> avoid senseless looping and sleep some time
456  */
457  msSleep(100);
458  }
459  /* go again to the begin */
460  }
461 
462  /* we have leaved the mix-loop */
463  CAMsg::printMsg(LOG_CRIT, "Seams that we are restarting now!\n");
464  m_bRestart=true;
465  m_pMuxIn->close();
466  /* write some bytes to the queue (ensure that m_pthreadSendToMix will stop)
467  */
468  UINT8 b[sizeof(tQueueEntry)+1];
469  m_pQueueSendToMix->add(b, sizeof(tQueueEntry)+1);
470  CAMsg::printMsg(LOG_CRIT, "Wait for LoopSendToMix...\n");
471  /* will not join if queue is empty (because thread is waiting)!!! */
473  m_bRunLog = false;
474  CAMsg::printMsg(LOG_CRIT, "Wait for LoopReadFromMix...\n");
476  #ifdef LOG_PACKET_TIMES
477  CAMsg::printMsg(LOG_CRIT, "Wait for LoopLogPacketStats to terminate...\n");
478  m_pLogPacketStats->stop();
479  #endif
480  /* delete the tables (will also remove all entries) */
481  delete m_pChainTable;
482  m_pChainTable = NULL;
483  delete m_pChannelTable;
484  m_pChannelTable = NULL;
485  delete currentQueueEntry;
486  currentQueueEntry = NULL;
487  pLogThread->join();
488  delete pLogThread;
489  pLogThread = NULL;
490  delete psocketgroupCacheWrite;
491  psocketgroupCacheWrite = NULL;
492  delete psocketgroupCacheRead;
493  psocketgroupCacheRead = NULL;
494 #endif //NEW_MIX_TYPE
495  return E_UNKNOWN;
496 }
497 #endif //ONLY_LOCAL_PROXY
#define RSA_SIZE
#define LOG_ENCRYPTED
Definition: CAMsg.hpp:46
#define KEY_SIZE
Definition: CASymCipher.hpp:31
SINT32 getcurrentTimeMicros(UINT64 &u64Time)
Gets the current Systemtime in micros seconds.
Definition: CAUtil.cpp:280
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
Definition: CAUtil.cpp:406
void setZero64(UINT64 &op1)
Definition: CAUtil.hpp:355
void add64(UINT64 &op1, UINT32 op2)
Definition: CAUtil.hpp:375
void set64(UINT64 &op1, UINT32 op2)
Definition: CAUtil.hpp:321
#define MAX_MIXIN_SEND_QUEUE_SIZE
Definition: StdAfx.h:228
#define LAST_MIX_TO_PROXY_SEND_TIMEOUT
Definition: StdAfx.h:200
#define LAST_MIX_TO_PROXY_CONNECT_TIMEOUT
Definition: StdAfx.h:198
#define SOCKET_ERROR
Definition: StdAfx.h:464
#define MAX_POLLFD
Definition: StdAfx.h:192
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
SINT32 decrypt(const UINT8 *from, UINT8 *to)
Decrypts exactly one block which is stored in from.
This class stores Addresses off different Cache-Proxies.
CASocketAddrINet * get()
Gets the 'next' Address according to the Load-Balancing algorithm.
UINT8 * getChainId()
Definition: CAChain.cpp:123
bool isSignaledInSocketGroup(CASocketGroupEpoll *a_socketGroup)
Definition: CAChain.cpp:356
void addToSocketGroup(CASocketGroupEpoll *a_socketGroup)
Definition: CAChain.cpp:372
void signalConnectionError()
Definition: CAChain.cpp:465
void setSocket(CASocket *a_socket)
Definition: CAChain.cpp:134
void addChannel(t_lastMixBChannelListEntry *a_channel, bool a_fastResponse)
Definition: CAChain.cpp:485
void addDataToUpstreamQueue(UINT8 *a_buffer, UINT32 a_size)
Definition: CAChain.cpp:444
UINT32 sendUpstreamData(UINT32 a_maxLength, CASocketGroupEpoll *a_removedSocketGroup)
Definition: CAChain.cpp:431
void closeUpstream()
Definition: CAChain.cpp:455
void signalUnknownChain()
Definition: CAChain.cpp:471
SINT32 processDownstream(CASocketGroupEpoll *a_signalingGroup, MIXPACKET *a_downstreamPacket, UINT32 *a_processedBytes)
Returns: 0, if a packet was created.
Definition: CAChain.cpp:146
CAChain * getNextEntry()
CAChain * getFirstEntry()
UINT32 getSize()
CAChain * createEntry()
CAChain * getEntry(UINT8 *a_chainId)
void deleteEntry(UINT8 *a_chainId)
bool proccessMixPacket(const MIXPACKET *pPacket)
SINT32 insert(UINT8 key[16], UINT64 timestamp)
Inserts this key in the replay DB.
Definition: CADatabase.cpp:93
t_lastMixBChannelListEntry * add(HCHANNEL a_channelId, CASymChannelCipher *a_channelCipher, CAChain *a_associatedChain)
t_lastMixBChannelListEntry * get(HCHANNEL a_channelId)
CAChainTable * m_pChainTable
Definition: CALastMixB.hpp:50
void reconfigureMix()
Definition: CALastMixB.cpp:52
CALastMixBChannelList * m_pChannelTable
Definition: CALastMixB.hpp:51
SINT32 loop()
Definition: CALastMixB.cpp:63
volatile bool m_bRunLog
Definition: CALastMix.hpp:189
volatile UINT32 m_logDownloadedPackets
Definition: CALastMix.hpp:192
CAQueue * m_pQueueSendToMix
Definition: CALastMix.hpp:153
volatile UINT64 m_logDownloadedBytes
Definition: CALastMix.hpp:193
volatile UINT64 m_logUploadedBytes
Definition: CALastMix.hpp:191
CAASymCipher * m_pRSA
Definition: CALastMix.hpp:161
CAQueue * m_pQueueReadFromMix
Definition: CALastMix.hpp:154
CAThread * m_pthreadReadFromMix
Definition: CALastMix.hpp:163
CAThread * m_pthreadSendToMix
Definition: CALastMix.hpp:162
CACacheLoadBalancing * m_pCacheLB
Definition: CALastMix.hpp:158
friend THREAD_RETURN lm_loopLog(void *)
Definition: CALastMix.cpp:591
volatile UINT32 m_logUploadedPackets
Definition: CALastMix.hpp:190
CAMuxSocket * m_pMuxIn
Definition: CALastMix.hpp:152
volatile bool m_bRestart
Definition: CALastMix.hpp:151
CACacheLoadBalancing * m_pSocksLB
Definition: CALastMix.hpp:159
static CACmdLnOptions * getOptions()
CAControlChannelDispatcher * m_pMuxInControlChannelDispatcher
Definition: CAMix.hpp:196
CADatabase * m_pReplayDB
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
SINT32 close()
Closes the underlying socket.
SINT32 add(const void *buff, UINT32 size)
Adds data to the Queue.
Definition: CAQueue.cpp:76
SINT32 get(UINT8 *pbuff, UINT32 *psize)
Gets up to psize number of bytes from the Queue.
Definition: CAQueue.cpp:148
UINT32 getSize()
Returns the size of stored data in byte.
Definition: CAQueue.hpp:101
virtual SINT32 setRecvBuff(UINT32 r)
Definition: CASocket.cpp:846
virtual SINT32 sendTimeOut(const UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Sends some data over the network.
Definition: CASocket.cpp:442
virtual SINT32 setNonBlocking(bool b)
Definition: CASocket.cpp:947
virtual SINT32 setSendBuff(SINT32 r)
Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r)
Definition: CASocket.cpp:862
virtual SINT32 create()
Definition: CASocket.cpp:73
virtual SINT32 close()
Definition: CASocket.cpp:351
virtual SINT32 connect(const CASocketAddr &psa)
Definition: CASocket.hpp:64
This class could be used for encryption/decryption of data (streams) with AES using 128bit CBC mode.
Definition: CASymCipher.hpp:42
SINT32 setKey(const UINT8 *key)
Sets the key for encryption.
Definition: CASymCipher.cpp:52
SINT32 start(void *param, bool bDaemon=false, bool bSilent=false)
Starts the execution of the main function of this thread.
Definition: CAThread.cpp:115
SINT32 setMainLoop(THREAD_MAIN_TYP fnc)
Sets the main function which will be executed within this thread.
Definition: CAThread.hpp:148
SINT32 join()
Waits for the main function to finish execution.
Definition: CAThread.cpp:187
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3
HCHANNEL channel
Definition: typedefs.hpp:117
UINT8 data[DATA_SIZE]
Definition: typedefs.hpp:121
UINT16 flags
Definition: typedefs.hpp:118
UINT8 data[MAX_FIRST_UPSTREAM_CHAINCELL_PAYLOAD]
Definition: typedefsb.hpp:100
Definition: typedefs.hpp:169
MIXPACKET packet
Definition: typedefs.hpp:170
UINT8 chainId[CHAIN_ID_LENGTH]
Definition: typedefsb.hpp:104
UINT8 data[MAX_SEQUEL_UPSTREAM_CHAINCELL_PAYLOAD]
Definition: typedefsb.hpp:105
t_sequel_upstream_chain_cell sequelCell
Definition: typedefsb.hpp:112
t_first_upstream_chain_cell firstCell
Definition: typedefsb.hpp:111
#define CHANNEL_DATA
Definition: typedefs.hpp:42
#define MIXPACKET_SIZE
Definition: typedefs.hpp:40
#define CHANNEL_DUMMY
Definition: typedefs.hpp:50
#define MIX_PAYLOAD_SOCKS
Definition: typedefs.hpp:36
#define CHANNEL_CLOSE
Definition: typedefs.hpp:47
struct t_queue_entry tQueueEntry
Definition: typedefs.hpp:188
#define CHANNEL_OPEN
Definition: typedefs.hpp:43
#define DATA_SIZE
Definition: typedefs.hpp:69
#define MAX_FIRST_UPSTREAM_CHAINCELL_PAYLOAD
Definition: typedefsb.hpp:71
#define CHAINFLAG_NEW_CHAIN
Definition: typedefsb.hpp:62
#define CHAINFLAG_FAST_RESPONSE
Definition: typedefsb.hpp:63
#define MAX_SEQUEL_UPSTREAM_CHAINCELL_PAYLOAD
Definition: typedefsb.hpp:72
UINT16 lengthAndFlags
Definition: typedefsb.hpp:0
#define CHAINFLAG_STREAM_CLOSED
Definition: typedefsb.hpp:59
#define CHAINFLAG_LENGTH_MASK
Definition: typedefsb.hpp:69