Do not realy close the connection - just inform the Queue that it is closed, so that the remaining data will be sent to the server
69 #ifdef DELAY_CHANNELS_LATENCY
89 #ifdef WITH_INTEGRITY_CHECK
100 pLogThread->
start(
this);
103 bool bUserSurveillance =
false;
106 #ifdef ANON_DEBUG_MODE
107 bool bIsDebugPacket =
false;
111 CAMsg::printMsg(LOG_DEBUG,
"Channel time log format is as follows: Channel-ID,Channel Start [micros], Channel End [micros], Upload (bytes), Download (bytes), DataAndOpenPacketsFromUser, DataPacketsToUser\n");
128 #if defined(LOG_PACKET_TIMES) || defined(LOG_CHANNEL)
131 #ifdef LOG_PACKET_TIMES
132 set64(pQueueEntry->timestamp_proccessing_start, pQueueEntry->timestamp_proccessing_start_OP);
141 #ifdef ANON_DEBUG_MODE
148 bIsDebugPacket =
true;
152 bIsDebugPacket =
false;
163 if (pChannelListEntry == NULL)
167 #if defined(ANON_DEBUG_MODE)
175 CAMsg::printMsg(LOG_DEBUG,
"Received a channel open packet for incoming channel: %u\n", pMixPacket->
channel);
180 CAMsg::printMsg(LOG_ERR,
"Error in channel open asym decryption - channel!\n");
184 #ifdef LOG_PACKET_TIMES
185 setZero64(pQueueEntry->timestamp_proccessing_start);
192 #ifdef REPLAY_DETECTION
203 #ifdef WITH_INTEGRITY_CHECK
208 UINT16 lengthAndFlagsField = 0;
210 payloadLen = ntohs(lengthAndFlagsField);
232 #ifdef LOG_PACKET_TIMES
235 #ifdef WITH_INTEGRITY_CHECK
243 newCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
247 #ifdef LOG_PACKET_TIMES
248 setZero64(pQueueEntry->timestamp_proccessing_start);
252 #if defined(ANON_DEBUG_MODE)
254 EVP_EncodeBlock(tmpPacketBase64, tmpPacketData,
DATA_SIZE);
255 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-open packet: %s\n", tmpPacketBase64);
257 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-open packet!\n");
262 #if defined(ANON_DEBUG_MODE)
264 EVP_EncodeBlock(tmpPacketBase64, tmpPacketData,
DATA_SIZE);
265 CAMsg::printMsg(LOG_ERR,
"Integrity check ok in channel-open packet: %s\n", tmpPacketBase64);
288 #if defined(_DEBUG) || defined(DELAY_CHANNELS_LATENCY)
298 #ifdef WITH_INTEGRITY_CHECK
299 newCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
304 #ifdef LOG_PACKET_TIMES
305 setZero64(pQueueEntry->timestamp_proccessing_start);
318 time_t timeChannelOpened = time(NULL);
319 bool bIsCrime =
false;
320 if (bUserSurveillance)
326 EVP_EncodeBlock(base64Payload, pMixPacket->
payload.
data, payLen);
327 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Upstream Payload (Base64 encoded): %s\n", timeChannelOpened, pMixPacket->
channel, base64Payload);
364 memcpy(crimeBuff, pMixPacket->
payload.
data, payLen);
372 "%u -- Proxy Connection source port: %u -- Content: \n%s\n",
390 #ifdef WITH_INTEGRITY_CHECK
391 newCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
396 #ifdef LOG_PACKET_TIMES
397 setZero64(pQueueEntry->timestamp_proccessing_start);
416 #if defined(DELAY_CHANNELS_LATENCY)
421 #ifdef LASTMIX_CHECK_MEMORY
422 pQueue->logIfSizeGreaterThen(100000);
425 #
if defined(LOG_CHANNEL)
427 pQueueEntry->timestamp_proccessing_start, payLen
429 #
if defined(DELAY_CHANNELS_LATENCY)
437 #ifdef ANON_DEBUG_MODE
445 psocketgroupCacheRead->
add(*tmpSocket);
447 #ifdef LOG_PACKET_TIMES
449 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_OPEN,
true);
451 #ifdef DATA_RETENTION_LOG
452 pQueueEntry->dataRetentionLogEntry.t_out = htonl(time(NULL));
453 pQueueEntry->dataRetentionLogEntry.entity.last.channelid = htonl(pMixPacket->
channel);
454 pQueueEntry->dataRetentionLogEntry.entity.last.port_out = tmpSocket->
getLocalPort();
455 pQueueEntry->dataRetentionLogEntry.entity.last.port_out = htons(pQueueEntry->dataRetentionLogEntry.entity.last.port_out);
456 tmpSocket->
getLocalIP(pQueueEntry->dataRetentionLogEntry.entity.last.ip_out);
457 m_pDataRetentionLog->log(&pQueueEntry->dataRetentionLogEntry);
461 #ifdef WITH_INTEGRITY_CHECK
486 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket),pChannelListEntry);
488 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket));
490 #if defined (LOG_PACKET_TIMES) ||defined (LOG_CHANNEL)
493 #if defined (LOG_PACKET_TIMES)
494 set64(pQueueEntry->timestamp_proccessing_end_OP,pQueueEntry->timestamp_proccessing_end);
495 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_CLOSE,
true);
498 pChannelListEntry->packetsDataInFromUser++;
499 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_USER
505 #if defined(ANON_DEBUG_MODE)
511 pChannelListEntry->packetsDataInFromUser++;
513 #ifdef WITH_INTEGRITY_CHECK
515 UINT16 lengthAndFlagsField=0;
516 pChannelListEntry->
pCipher->decryptMessage(pMixPacket->
data, 2,(
UINT8*) &lengthAndFlagsField,
false);
517 payloadLen = ntohs(lengthAndFlagsField);
523 retval = pChannelListEntry->
pCipher->decryptMessage(pMixPacket->
data, payloadLen + 3 +
GCM_MAC_SIZE, plaintextBuff,
true);
526 #if defined(ANON_DEBUG_MODE)
528 EVP_EncodeBlock(tmpPacketBase64, tmpPacket,
DATA_SIZE);
529 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-data packet: %s\n", tmpPacketBase64);
531 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-data packet!\n");
534 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
535 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
537 delete pChannelListEntry->
pSocket;
538 pChannelListEntry->
pSocket = NULL;
545 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
547 delete pChannelListEntry->
pCipher;
548 pChannelListEntry->
pCipher = NULL;
550 pChannelListEntry->packetsDataOutToUser++;
552 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
555 #ifdef LOG_PACKET_TIMES
556 setZero64(pQueueEntry->timestamp_proccessing_start);
561 memcpy(pMixPacket->
data, plaintextBuff, payloadLen + 3);
575 pChannelListEntry->trafficInFromUser+=ret;
577 #ifdef LOG_PACKET_TIMES
583 if(bUserSurveillance)
588 EVP_EncodeBlock(base64Payload,pMixPacket->
payload.
data,ret);
589 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Upstream Payload (Base64 encoded): %s\n", pChannelListEntry->timeChannelOpened,pMixPacket->
channel,base64Payload);
590 pChannelListEntry->bLogPayload=
true;
612 else if(checkCrime(pMixPacket->
payload.
data, ret,
false))
624 "%u -- Content: \n%s\n", pMixPacket->
channel,
636 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
637 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
639 delete pChannelListEntry->
pSocket;
640 pChannelListEntry->
pSocket = NULL;
648 #ifdef WITH_INTEGRITY_CHECK
649 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
652 delete pChannelListEntry->
pCipher;
653 pChannelListEntry->
pCipher = NULL;
655 pChannelListEntry->packetsDataOutToUser++;
657 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
660 #ifdef LOG_PACKET_TIMES
661 setZero64(pQueueEntry->timestamp_proccessing_start);
676 #ifdef WITH_INTEGRITY_CHECK
677 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
683 pChannelListEntry->packetsDataOutToUser++;
685 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
687 #ifdef LOG_PACKET_TIMES
688 setZero64(pQueueEntry->timestamp_proccessing_start);
696 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket),pChannelListEntry);
698 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket));
700 #ifdef LOG_PACKET_TIMES
702 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_DATA,
true);
705 #ifdef WITH_INTEGRITY_CHECK
715 countRead=psocketgroupCacheWrite->
select(0);
721 while(pChannelListEntry!=NULL)
725 while(pChannelListEntry!=NULL&&countRead>0)
745 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
746 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
748 delete pChannelListEntry->
pSocket;
749 pChannelListEntry->
pSocket = NULL;
750 delete pChannelListEntry->
pCipher;
751 pChannelListEntry->
pCipher = NULL;
758 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
766 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
767 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
769 delete pChannelListEntry->
pSocket;
770 pChannelListEntry->
pSocket = NULL;
776 #ifdef WITH_INTEGRITY_CHECK
777 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
780 delete pChannelListEntry->
pCipher;
781 pChannelListEntry->
pCipher = NULL;
785 #ifdef LOG_PACKET_TIMES
786 setZero64(pQueueEntry->timestamp_proccessing_start);
791 pChannelListEntry->packetsDataOutToUser++;
795 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
812 countRead=psocketgroupCacheRead->
select(0);
813 #ifdef DELAY_CHANNELS_LATENCY
814 UINT64 current_time_millis;
821 while(pChannelListEntry!=NULL)
825 while(pChannelListEntry!=NULL&&countRead>0)
833 #ifdef DELAY_CHANNELS
834 && ( pChannelListEntry->delayBucket>0)
836 #ifdef DELAY_CHANNELS_LATENCY
837 &&(
isGreater64(current_time_millis,pChannelListEntry->timeLatency))
841 #ifndef DELAY_CHANNELS
846 pChannelListEntry->delayBucket,
850 #ifdef LOG_PACKET_TIMES
852 set64(pQueueEntry->timestamp_proccessing_start_OP,pQueueEntry->timestamp_proccessing_start);
857 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
858 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
860 delete pChannelListEntry->
pSocket;
861 pChannelListEntry->
pSocket = NULL;
867 #ifdef WITH_INTEGRITY_CHECK
868 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
871 delete pChannelListEntry->
pCipher;
872 pChannelListEntry->
pCipher = NULL;
876 #ifdef LOG_PACKET_TIMES
882 pChannelListEntry->packetsDataOutToUser++;
886 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
893 #if defined(LOG_CHANNEL)
894 pChannelListEntry->trafficOutToUser+=ret;
896 #ifdef DELAY_CHANNELS
897 m_pChannelList->reduceDelayBuckets(pChannelListEntry->delayBucketID, ret);
909 if(pChannelListEntry->bLogPayload)
912 EVP_EncodeBlock(base64Payload,pMixPacket->
payload.
data,ret);
913 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Downstream Payload (Base64 encoded): %s\n", pChannelListEntry->timeChannelOpened,pChannelListEntry->
channelIn,base64Payload);
916 #ifdef WITH_INTEGRITY_CHECK
917 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, ret + 3, ciphertextBuff);
923 #ifdef LOG_PACKET_TIMES
926 #ifdef ANON_DEBUG_MODE
927 if (pChannelListEntry->bDebug )
931 EVP_EncodeBlock(tmpPacketBase64, pMixPacket->
data,
DATA_SIZE);
932 CAMsg::printMsg(LOG_ERR,
"Put AN.ON debug packet into send queue: %s\n", tmpPacketBase64);
938 #if defined(LOG_CHANNEL)
939 pChannelListEntry->packetsDataOutToUser++;
958 #ifndef FAST_PROCESSING
968 CAMsg::printMsg(LOG_CRIT,
"CALastMixA - loop() - Seems that we are restarting now!!\n");
972 delete pQueueEntryCrime;
973 pQueueEntryCrime = NULL;
979 delete []ciphertextBuff;
980 ciphertextBuff = NULL;
981 delete []plaintextBuff;
982 plaintextBuff = NULL;
988 delete psocketgroupCacheWrite;
989 psocketgroupCacheWrite = NULL;
990 delete psocketgroupCacheRead;
991 psocketgroupCacheRead = NULL;
#define LAST_MIX_SIZE_OF_SYMMETRIC_KEYS
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
SINT32 getcurrentTimeMicros(UINT64 &u64Time)
Gets the current Systemtime in micros seconds.
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
void setZero64(UINT64 &op1)
void add64(UINT64 &op1, UINT32 op2)
bool isGreater64(UINT64 &op1, UINT64 &op2)
void set64(UINT64 &op1, UINT32 op2)
#define MAX_MIXIN_SEND_QUEUE_SIZE
#define LAST_MIX_TO_PROXY_SEND_TIMEOUT
#define LAST_MIX_TO_PROXY_CONNECT_TIMEOUT
#define FLOW_CONTROL_SENDME_HARD_LIMIT
#define FLOW_CONTROL_SENDME_SOFT_LIMIT
SINT32 decryptOAEP(const UINT8 *from, UINT8 *to, UINT32 *len)
Decrypts one OAEP encoded 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.
bool proccessMixPacket(const MIXPACKET *pPacket)
SINT32 insert(UINT8 key[16], UINT64 timestamp)
Inserts this key in the replay DB.
lmChannelListEntry * get(HCHANNEL channelIn)
SINT32 add(HCHANNEL id, CASocket *pSocket, CASymChannelCipher *pCipher, CAQueue *pQueue)
lmChannelListEntry * getFirstSocket()
lmChannelListEntry * getNextSocket()
SINT32 removeChannel(HCHANNEL channelIn)
volatile UINT32 m_logDownloadedPackets
CAQueue * m_pQueueSendToMix
volatile UINT64 m_logDownloadedBytes
volatile UINT64 m_logUploadedBytes
CACacheLoadBalancing * m_pVPNLB
CALastMixChannelList * m_pChannelList
CAQueue * m_pQueueReadFromMix
CACacheLoadBalancing * m_pCacheLB
friend THREAD_RETURN lm_loopLog(void *)
volatile UINT32 m_logUploadedPackets
CACacheLoadBalancing * m_pSocksLB
static CACmdLnOptions * getOptions()
CAControlChannelDispatcher * m_pMuxInControlChannelDispatcher
UINT64 m_u64ReferenceTime
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
This is a simple FIFO-Queue.
SINT32 add(const void *buff, UINT32 size)
Adds data to the Queue.
SINT32 get(UINT8 *pbuff, UINT32 *psize)
Gets up to psize number of bytes from the Queue.
SINT32 peek(UINT8 *pbuff, UINT32 *psize)
Peeks data from the Queue.
SINT32 close()
Closes the Queue (for writing).
SINT32 remove(UINT32 *psize)
Removes data from the Queue.
UINT32 getSize()
Returns the size of stored data in byte.
bool isClosed()
Returns true, if the Queue is closed.
bool isEmpty()
Returns true, if the Queue is empty.
UINT32 getSizeLookFree()
Returns the size of stored data in byte.
SINT32 remove(CASocket &s)
bool isSignaled(CASocket &s)
SINT32 add(CASocket &s)
Adds the socket s to the socket group.
void * getFirstSignaledSocketData()
void * getNextSignaledSocketData()
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
virtual SINT32 setRecvBuff(UINT32 r)
virtual SINT32 sendTimeOut(const UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Sends some data over the network.
virtual SINT32 setNonBlocking(bool b)
virtual SINT32 setSendBuff(SINT32 r)
Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r)
virtual SINT32 getLocalIP(UINT8 r_Ip[4])
LERNGRUPPE Returns the source address of the socket.
virtual SINT32 connect(const CASocketAddr &psa)
virtual SINT32 getLocalPort()
static CASymChannelCipher * createCipher(SYMCHANNELCIPHER_ALGORITHM alg)
virtual SINT32 setKeys(const UINT8 *key, UINT32 keysize)=0
Sets the keys for crypt1() and crypt2() either to the same key (if keysize==KEY_SIZE) or to different...
virtual SINT32 crypt2(const UINT8 *in, UINT8 *out, UINT32 len)=0
virtual SINT32 crypt1(const UINT8 *in, UINT8 *out, UINT32 len)=0
This class could be used for encryption/decryption of data (streams) with AES using 128bit GCM mode.
void setGCMKeys(UINT8 *keyRecv, UINT8 *keySend)
SINT32 decryptMessage(const UINT8 *in, UINT32 inlen, UINT8 *out, bool integrityCheck)
SINT32 start(void *param, bool bDaemon=false, bool bSilent=false)
Starts the execution of the main function of this thread.
SINT32 setMainLoop(THREAD_MAIN_TYP fnc)
Sets the main function which will be executed within this thread.
SINT32 join()
Waits for the main function to finish execution.
struct t_MixPacketPayload payload
CASymChannelCipher * pCipher
SINT32 sendmeCounterDownstream
SINT32 sendmeCounterUpstream
#define MIX_PAYLOAD_SOCKS
#define NEW_FLOW_CONTROL_FLAG
struct t_queue_entry tQueueEntry
#define CHANNEL_SIG_CRIME
#define PAYLOAD_HEADER_SIZE
#define CONNECTION_ERROR_FLAG
#define INTEGRITY_ERROR_FLAG