28 #include "../StdAfx.h"
29 #ifndef ONLY_LOCAL_PROXY
31 #include "../CAThread.hpp"
32 #include "../CASingleSocketGroup.hpp"
33 #include "../CAInfoService.hpp"
34 #include "../CAPool.hpp"
35 #include "../CACmdLnOptions.hpp"
36 #include "../CAAccountingInstance.hpp"
38 #include "../CASocketGroupEpoll.hpp"
47 pglobalOptions->getDelayChannelBucketGrow(),
48 pglobalOptions->getDelayChannelBucketGrowIntervall());
68 #ifdef LOG_TRAFFIC_PER_USER
72 CAMsg::printMsg(LOG_DEBUG,
"1. Close received from user (times in micros) - 1:Channel-ID,Connection-ID,PacketsIn (only data and open),PacketsOut (only data),ChannelDuration (open packet received --> close packet put into send queue to next mix)\n");
73 CAMsg::printMsg(LOG_DEBUG,
"2. Channel close from Mix(times in micros)- 2.:Channel-ID,Connection-ID,PacketsIn (only data and open), PacketsOut (only data),ChannelDuration (open packet received)--> close packet put into send queue to next user\n");
92 #define MAX_NEXT_MIX_QUEUE_SIZE 10000000
103 while (pHashEntry != NULL)
111 while (pHashEntry != NULL&&countRead > 0)
118 ret = pMuxSocket->
receive(pMixPacket, 0);
119 #if defined LOG_PACKET_TIMES||defined(LOG_CHANNEL)
121 set64(pQueueEntry->timestamp_proccessing_start_OP, pQueueEntry->timestamp_proccessing_start);
126 #ifdef LOG_TRAFFIC_PER_USER
128 diff_time =
diff64(current_time, pHashEntry->timeCreated);
155 #ifdef LOG_TRAFFIC_PER_USER
156 pHashEntry->trafficIn++;
171 CAMsg::printMsg(LOG_DEBUG,
"Packet is invalid and could not be processed!\n");
189 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixB: Detected evil Jap.. closing connection! Removing IP..\n", ret);
192 while (pEntry != NULL)
197 #ifdef LOG_PACKET_TIMES
198 setZero64(pQueueEntry->timestamp_proccessing_start);
222 #ifdef LOG_PACKET_TIMES
223 setZero64(pQueueEntry->timestamp_proccessing_start);
243 #ifdef LOG_PACKET_TIMES
249 pEntry->packetsInFromUser++;
258 for (
int i = 0; i < 16; i++)
260 pCipher->setIV2(rsaBuff);
273 #ifdef LOG_PACKET_TIMES
278 pTmpEntry->packetsInFromUser++;
279 set64(pTmpEntry->timeCreated, pQueueEntry->timestamp_proccessing_start);
316 #ifdef LOG_PACKET_TIMES
321 #if defined(_DEBUG) && !defined(__MIX_TEST)
327 if (pEntry->
pHead != NULL) {
330 #ifdef LOG_PACKET_TIMES
334 #ifdef LOG_TRAFFIC_PER_USER
335 pEntry->
pHead->trafficOut++;
343 diff_time =
diff64(current_time, pEntry->timeCreated);
345 pEntry->
channelIn, pEntry->
pHead->
id, pEntry->packetsInFromUser, pEntry->packetsOutToUser,
363 #ifdef LOG_PACKET_TIMES
375 #if defined(_DEBUG) && !defined(__MIX_TEST)
379 if (pEntry != NULL) {
380 if (pEntry->
pHead != NULL) {
386 if (!pglobalOptions->isEncryptedLogEnabled())
395 #ifdef LOG_PACKET_TIMES
399 #ifdef LOG_TRAFFIC_PER_USER
400 pEntry->
pHead->trafficOut++;
406 pEntry->packetsOutToUser++;
429 if (!pglobalOptions->isEncryptedLogEnabled()) {
432 CAMsg::printMsg(log,
"Detecting crime activity - ID: %u -- In-IP is: not available (user has already closed connection)\n",
id);
436 #ifdef LOG_PACKET_TIMES
463 while (pfmHashEntry != NULL)
467 while (countRead > 0 && pfmHashEntry != NULL)
507 goto NEXT_USER_WRITING;
515 #ifdef LOG_PACKET_TIMES
559 #ifdef LOG_PACKET_TIMES
560 CAMsg::printMsg(LOG_CRIT,
"Wait for LoopLogPacketStats to terminate!\n");
561 m_pLogPacketStats->stop();
566 CAMsg::printMsg(LOG_CRIT,
"Before deleting CAFirstMixChannelList()!\n");
569 while (pHashEntry != NULL)
578 while (pEntry != NULL)
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.
UINT32 diff64(const UINT64 &bigop, const UINT64 &smallop)
void setZero64(UINT64 &op1)
bool isZero64(UINT64 &op1)
void set64(UINT64 &op1, UINT32 op2)
#define MAX_NEXT_MIX_QUEUE_SIZE
#define ASSERT(cond, msg)
static SINT32 handleJapPacket(fmHashTableEntry *pHashEntry, bool a_bControlMessage, bool a_bMessageToJAP)
This should be called by the FirstMix for every incoming Jap packet.
bool proccessMixPacket(const MIXPACKET *pPacket)
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.
SINT32 addChannel(CAMuxSocket *pMuxSocket, HCHANNEL channelIn, CASymChannelCipher *pCipher, HCHANNEL *channelOut)
Adds a new channel for a given connection to the channel list.
fmChannelListEntry * get(CAMuxSocket *pMuxSocket, HCHANNEL channelIn)
Returns the information for a given Input-Channel-ID.
fmHashTableEntry * getNext()
Gets the next entry in the connections-list.
SINT32 removeChannel(CAMuxSocket *pMuxSocket, HCHANNEL channelIn)
Removes a single channel from the list.
fmChannelListEntry * getNextChannel(fmChannelListEntry *pEntry)
Gets the next channel for a given connection.
SINT32 remove(CAMuxSocket *pMuxSocket)
Removes all channels, which belongs to the given connection and the connection itself from the list.
CAThread * m_pthreadReadFromMix
CASocket ** m_arrSocketsIn
CAThread * m_pthreadAcceptUsers
CAQueue * m_pQueueSendToMix
CASocketGroupEpoll * m_psocketgroupUsersWrite
CAThread * m_pthreadSendToMix
CASocketGroupEpoll * m_psocketgroupUsersRead
tUINT32withLock * m_PacketsPerCountryOUT
SINT32 decUsers(LP_fmHashTableEntry pHashEntry)
CAFirstMixChannelList * m_pChannelList
tUINT32withLock * m_PacketsPerCountryIN
CAThreadPool * m_pthreadsLogin
CAQueue * m_pQueueReadFromMix
SINT32 removeIP(const UINT8 ip[4])
Removes the IP-Address from the list.
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
SINT32 close()
Closes the underlying socket.
SINT32 receive(MIXPACKET *pPacket)
Receives a whole MixPacket.
SINT32 prepareForSend(MIXPACKET *inoutPacket)
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.
UINT32 getSize()
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 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
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 CBC mode.
SINT32 setKey(const UINT8 *key)
Sets the key for encryption.
SINT32 join()
Waits for the main function to finish execution.
SINT32 destroy(bool bWaitForFinish)
CASymChannelCipher * pCipher
CASymChannelCipher * pSymCipher
CAControlChannelDispatcher * pControlChannelDispatcher
volatile UINT32 delayBucket
CountryID of this IP Address.
SINT32 uAlreadySendPacketSize
struct t_queue_entry tQueueEntry
#define CHANNEL_SIG_CRIME