28 #include "../StdAfx.h"
29 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
31 #include "../CALibProxytest.hpp"
32 #include "../CAThread.hpp"
33 #include "../CASingleSocketGroup.hpp"
34 #include "../CAInfoService.hpp"
35 #include "../CAPool.hpp"
36 #include "../CACmdLnOptions.hpp"
37 #include "../CAAccountingInstance.hpp"
38 #include "../CAStatusManager.hpp"
40 #include "../CASocketGroupEpoll.hpp"
42 #include "../CASymChannelCipherFactory.hpp"
49 UINT32 connectionsClosed = 0;
72 CAMsg::printMsg(LOG_DEBUG,
"Shutting down, closing client connection.\n");
76 CAMsg::printMsg(LOG_DEBUG,
"Closed %i client connections.\n", connectionsClosed);
83 #ifndef MULTI_THREADED_PACKET_PROCESSING
87 if (pHashEntry == NULL)
100 #ifdef LOG_TRAFFIC_PER_USER
103 CAMsg::printMsg(LOG_DEBUG,
"Removing Connection wiht ID: %Lu -- login time [ms] %Lu -- logout time [ms] %Lu -- Traffic was: IN: %u -- OUT: %u\n",pHashEntry->
id,pHashEntry->timeCreated,current_time,pHashEntry->trafficIn,pHashEntry->trafficOut);
116 #ifdef LOG_PACKET_TIMES
117 setZero64(pQueueEntry->timestamp_proccessing_start);
124 nrOfChOpMutex->lock();
125 currentOpenedChannels--;
126 nrOfChOpMutex->unlock();
156 #define FIRST_MIX_SIZE_OF_SYMMETRIC_KEYS 2*KEY_SIZE
185 #ifdef LOG_TRAFFIC_PER_USER
189 CAMsg::printMsg(LOG_DEBUG,
"1. Close received from user (times in micros) - 1:Channel-ID,Connection-ID,Channel open timestamp (microseconds),PacketsIn (only data and open),PacketsOut (only data),ChannelDuration (open packet received --> close packet put into send queue to next mix)\n");
190 CAMsg::printMsg(LOG_DEBUG,
"2. Channel close from Mix(times in micros)- 2.:Channel-ID,Connection-ID,Channel open timestamp (microseconds),PacketsIn (only data and open), PacketsOut (only data),ChannelDuration (open packet received)--> close packet put into send queue to next user\n");
196 pLogThread->
start(
this);
238 while(pHashEntry!=NULL)
246 while(pHashEntry!=NULL&&countRead>0)
258 ret=pMuxSocket->
receive(pMixPacket,0);
260 #if defined LOG_PACKET_TIMES||defined(LOG_CHANNEL)
262 set64(pQueueEntry->timestamp_proccessing_start_OP,pQueueEntry->timestamp_proccessing_start);
264 #ifdef DATA_RETENTION_LOG
265 pQueueEntry->dataRetentionLogEntry.t_in=htonl(time(NULL));
267 if(ret<0&&ret!=E_AGAIN/*||pHashEntry->accessUntil<time()*/)
281 #ifdef LOG_TRAFFIC_PER_USER
282 pHashEntry->trafficIn++;
296 CAMsg::printMsg(LOG_DEBUG,
"Control channel packet is invalid and could not be processed!\n");
301 #ifdef ANON_DEBUG_MODE
302 bool bIsDebugPacket=
false;
320 #ifdef LOG_PACKET_TIMES
321 setZero64(pQueueEntry->timestamp_proccessing_start);
323 #ifdef LOG_TRAFFIC_PER_USER
324 pHashEntry->trafficOut++;
344 #ifdef LOG_PACKET_TIMES
355 diff_time=
diff64(current_time,pEntry->timeCreated);
357 pEntry->
channelIn,pEntry->
pHead->
id,pEntry->timeCreated,pEntry->packetsInFromUser,pEntry->packetsOutToUser,
365 nrOfChOpMutex->lock();
366 currentOpenedChannels--;
367 nrOfChOpMutex->unlock();
388 #ifdef LOG_PACKET_TIMES
394 crimeSurveillance(surveillanceIPs, nrOfSurveillanceIPs, pEntry->
pHead->
peerIP,pEntry->
pHead->peerPort, pMixPacket);
396 #ifdef ANON_DEBUG_MODE
409 pEntry->packetsInFromUser++;
425 #ifdef REPLAY_DETECTION
439 for(
int i=0;i<16;i++)
444 #if defined (LOG_CHANNEL) ||defined(DATA_RETENTION_LOG)
447 #if defined LOG_CRIME || defined _DEBUG
458 nrOfChOpMutex->
lock();
459 if(pHashEntry->channelOpenedLastIntervalTS !=
462 pHashEntry->channelOpenedLastIntervalTS =
464 nrOfOpenedChannels++;
466 currentOpenedChannels++;
467 nrOfChOpMutex->unlock();
470 #ifdef LOG_PACKET_TIMES
475 pTmpEntry->packetsInFromUser++;
476 set64(pTmpEntry->timeCreated,pQueueEntry->timestamp_proccessing_start);
478 #ifdef DATA_RETENTION_LOG
479 pQueueEntry->dataRetentionLogEntry.entity.first.channelid=htonl(pMixPacket->
channel);
481 memcpy(pQueueEntry->dataRetentionLogEntry.entity.first.ip_in,pTmpEntry1->
pHead->
peerIP,4);
482 pQueueEntry->dataRetentionLogEntry.entity.first.port_in=(
UINT16)pTmpEntry1->
pHead->peerPort;
483 pQueueEntry->dataRetentionLogEntry.entity.first.port_in=htons(pQueueEntry->dataRetentionLogEntry.entity.first.port_in);
492 crimeSurveillance(surveillanceIPs, nrOfSurveillanceIPs, pEntry->
pHead->
peerIP,pEntry->
pHead->peerPort, pMixPacket);
495 #ifdef ANON_DEBUG_MODE
500 pEntry->bDebug =
true;
536 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixA::loop() - read from user --> countRead >0 after processing all connections!\n");
556 #ifdef LOG_PACKET_TIMES
559 #ifdef ANON_DEBUG_MODE
564 CAMsg::printMsg(LOG_DEBUG,
"Dequeued Downstream AN.ON packet from previous Mix debug: %s\n", base64Payload);
572 #if defined(_DEBUG) && !defined(__MIX_TEST)
589 #ifdef LOG_PACKET_TIMES
593 #ifdef LOG_TRAFFIC_PER_USER
594 pEntry->
pHead->trafficOut++;
606 pEntry->packetsOutToUser++;
608 diff_time=
diff64(current_time,pEntry->timeCreated);
610 pEntry->
channelIn,pEntry->
pHead->
id,pEntry->timeCreated,pEntry->packetsInFromUser,pEntry->packetsOutToUser,
626 nrOfChOpMutex->lock();
627 currentOpenedChannels--;
628 nrOfChOpMutex->unlock();
639 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixA: close channel -> client but channel does not exist.\n");
646 #if defined(_DEBUG) && !defined(__MIX_TEST)
660 CAMsg::printMsg(log,
"Detecting crime activity - next mix channel: %u -- "
661 "Incoming (User) IP:Port is: %u.%u.%u.%u:%u \n", pMixPacket->
channel,
666 pEntry->
pHead->peerPort);
680 #ifdef LOG_PACKET_TIMES
683 #ifdef ANON_DEBUG_MODE
689 CAMsg::printMsg(LOG_DEBUG,
"Send Dowwstream AN.ON packet debug: %s\n", base64Payload);
697 #ifdef LOG_TRAFFIC_PER_USER
698 pEntry->
pHead->trafficOut++;
704 pEntry->packetsOutToUser++;
746 #ifndef FAST_PROCESSING
781 CAQueue *controlMessageUserQueue = NULL;
782 CAQueue *dataMessageUserQueue = NULL;
784 CAQueue *processedQueue = NULL;
796 while(pfmHashEntry != NULL)
801 while( (countRead > 0) && (pfmHashEntry != NULL) )
809 processedQueue = NULL;
812 dataMessageUserQueue = pfmHashEntry->
pQueueSend;
815 if(controlMessageUserQueue->
getSize() > 0)
817 processedQueue = controlMessageUserQueue;
820 else if( (dataMessageUserQueue->
getSize() > 0)
826 processedQueue = dataMessageUserQueue;
830 if(processedQueue != NULL)
832 extractSize = packetSize;
837 processedQueue->
get((
UINT8*) packetToSend, &extractSize);
843 #ifdef ANON_DEBUG_MODE
848 CAMsg::printMsg(LOG_DEBUG,
"Send Downstream AN.ON packet to user debug: %s\n", base64Payload);
876 if(processedQueue != controlMessageUserQueue)
882 #ifdef LOG_PACKET_TIMES
902 SOCKET sock=clientSocket->getSocket();
919 if (iSocketErrors > 1)
921 CAMsg::printMsg(LOG_ERR,
"CAFirstMixA::sendtoUser() - %d send errors on a socket occured!\n", iSocketErrors);
945 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixA: 1. setting bRecover timout to false for entry %x!\n", pHashEntry);
989 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixA: Closing JAP connection due to illegal payment status!\n", ret);
1006 if(pfmHashEntry == NULL)
1014 while(pEntry != NULL)
1040 if(cListEntry != NULL)
1043 cListEntry->downStreamBytes -=
sizeof(
tQueueEntry);
1045 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixA: channels of current packet, in: %u, out: %u, count: %u, flags: 0x%x\n",
1055 nrOfChOpMutex->lock();
1056 currentOpenedChannels--;
1057 nrOfChOpMutex->unlock();
1071 bool currentEntryKickoutForced =
false;
1076 if(firstIteratorEntry == timeoutHashEntry)
1082 if (!currentEntryKickoutForced)
1087 CAMsg::printMsg(LOG_DEBUG,
"Client connection closed due to timeout.\n");
1100 CAMsg::printMsg(LOG_WARNING,
"Kickout immediately owner %x!\n", timeoutHashEntry);
1104 CAMsg::printMsg(LOG_WARNING,
"Client connection closed due to forced timeout! Payment auth flags: %u\n", authFlags);
1108 CAMsg::printMsg(LOG_WARNING,
"Client connection closed due to forced timeout!\n");
1120 CAMsg::printMsg(LOG_INFO,
"Size of control message queue for user to be kicked out: %u bytes, retries %d.\n",
1125 CAMsg::printMsg(LOG_WARNING,
"A kickout is supposed to happen. Let the user get his %u control message bytes before...\n",
1128 if(firstIteratorEntry == NULL)
1130 firstIteratorEntry = timeoutHashEntry;
1140 if( (nrOfSurveillanceIPs > 0) && (surveillanceIPs != NULL) )
1142 for(
UINT32 i = 0; i < nrOfSurveillanceIPs; i++)
1144 if(surveillanceIPs[i].
equals(peerIP))
1146 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, IP %u.%u.%u.%u Port %i with next mix channel %u\n",peerIP[0], peerIP[1], peerIP[2], peerIP[3],peerPort,pMixPacket->
channel);
1173 if (pHashEntry == NULL)
1186 #ifdef LOG_TRAFFIC_PER_USER
1189 CAMsg::printMsg(LOG_DEBUG,
"Removing Connection wiht ID: %Lu -- login time [ms] %Lu -- logout time [ms] %Lu -- Traffic was: IN: %u -- OUT: %u\n",pHashEntry->
id,pHashEntry->timeCreated,current_time,pHashEntry->trafficIn,pHashEntry->trafficOut);
1201 m_pChannelToQueueList->removeChannel(pEntry->
channelOut);
1203 #ifdef LOG_PACKET_TIMES
1204 setZero64(pQueueEntry->timestamp_proccessing_start);
1211 nrOfChOpMutex->lock();
1212 currentOpenedChannels--;
1213 nrOfChOpMutex->unlock();
1222 #ifdef COUNTRY_STATS
1243 #define FIRST_MIX_SIZE_OF_SYMMETRIC_KEYS 2*KEY_SIZE
1246 struct fm_packet_proccessing_loop_args_t
1249 CAQueue* pIncomingPacketQueue;
1259 typedef struct fm_packet_proccessing_loop_args_t tPacketProcessingLoopArgs;
1264 #ifndef NEW_MIX_TYPE
1265 m_pthreadsPacketProccessingLoop =
new CAThreadPool(m_numThreads, m_numThreads,
false);
1267 for (
UINT32 i = 0; i < m_numThreads; i++)
1274 tPacketProcessingLoopArgs* params =
new tPacketProcessingLoopArgs;
1275 params->pFirstMix =
this;
1276 params->pChannelList = m_arpChannelList[i];
1277 params->psocketgroupUsersRead = m_arpsocketgroupUsersRead[i];
1278 params->psocketgroupUsersWrite = m_arpsocketgroupUsersWrite[i];
1279 params->pIncomingPacketQueue =
new CAQueue();
1298 #ifdef LOG_TRAFFIC_PER_USER
1302 CAMsg::printMsg(LOG_DEBUG,
"1. Close received from user (times in micros) - 1:Channel-ID,Connection-ID,Channel open timestamp (microseconds),PacketsIn (only data and open),PacketsOut (only data),ChannelDuration (open packet received --> close packet put into send queue to next mix)\n");
1303 CAMsg::printMsg(LOG_DEBUG,
"2. Channel close from Mix(times in micros)- 2.:Channel-ID,Connection-ID,Channel open timestamp (microseconds),PacketsIn (only data and open), PacketsOut (only data),ChannelDuration (open packet received)--> close packet put into send queue to next user\n");
1333 pQueue->
add(pQueueEntry, ret);
1334 #ifdef LOG_PACKET_TIMES
1337 #ifdef ANON_DEBUG_MODE
1341 EVP_EncodeBlock(base64Payload, pMixPacket->
data,
DATA_SIZE);
1342 CAMsg::printMsg(LOG_DEBUG,
"Dequeued Downstream AN.ON packet from previous Mix debug: %s\n", base64Payload);
1348 #ifndef FAST_PROCESSING
1374 #ifndef NEW_MIX_TYPE
1375 CAFirstMixA*
pMix =
static_cast<tPacketProcessingLoopArgs*
>(params)->pFirstMix;
1377 CASocketGroupEpoll* psocketgroupUsersRead =
static_cast<tPacketProcessingLoopArgs*
>(params)->psocketgroupUsersRead;
1378 CASocketGroupEpoll* psocketgroupUsersWrite=
static_cast<tPacketProcessingLoopArgs*
>(params)->psocketgroupUsersWrite;
1380 CASocketGroup* psocketgroupUsersRead =
static_cast<tPacketProcessingLoopArgs*
>(params)->psocketgroupUsersRead;
1381 CASocketGroup* psocketgroupUsersWrite=
static_cast<tPacketProcessingLoopArgs*
>(params)->psocketgroupUsersWrite;
1383 CAQueue* pQueueReadFromMix =
static_cast<tPacketProcessingLoopArgs*
>(params)->pIncomingPacketQueue;
1384 CAFirstMixChannelList* pChannelList =
static_cast<tPacketProcessingLoopArgs*
>(params)->pChannelList;
1412 #ifdef LOG_TRAFFIC_PER_USER
1416 CAMsg::printMsg(LOG_DEBUG,
"1. Close received from user (times in micros) - 1:Channel-ID,Connection-ID,Channel open timestamp (microseconds),PacketsIn (only data and open),PacketsOut (only data),ChannelDuration (open packet received --> close packet put into send queue to next mix)\n");
1417 CAMsg::printMsg(LOG_DEBUG,
"2. Channel close from Mix(times in micros)- 2.:Channel-ID,Connection-ID,Channel open timestamp (microseconds),PacketsIn (only data and open), PacketsOut (only data),ChannelDuration (open packet received)--> close packet put into send queue to next user\n");
1428 while(!
pMix->m_bRestart)
1451 countRead=psocketgroupUsersRead->
select(0);
1459 while(pHashEntry!=NULL)
1467 while(pHashEntry!=NULL&&countRead>0)
1470 if(psocketgroupUsersRead->
isSignaled(*pMuxSocket))
1479 ret=pMuxSocket->
receive(pMixPacket,0);
1481 #if defined LOG_PACKET_TIMES||defined(LOG_CHANNEL)
1483 set64(pQueueEntry->timestamp_proccessing_start_OP,pQueueEntry->timestamp_proccessing_start);
1485 #ifdef DATA_RETENTION_LOG
1486 pQueueEntry->dataRetentionLogEntry.t_in=htonl(time(NULL));
1488 if(ret<0&&ret!=E_AGAIN/*||pHashEntry->accessUntil<time()*/)
1491 pMix->closeConnection(pHashEntry,psocketgroupUsersRead,psocketgroupUsersRead,pChannelList);
1502 #ifdef LOG_TRAFFIC_PER_USER
1503 pHashEntry->trafficIn++;
1505 #ifdef COUNTRY_STATS
1517 CAMsg::printMsg(LOG_DEBUG,
"Control channel packet is invalid and could not be processed!\n");
1518 pMix->closeConnection(pHashEntry,psocketgroupUsersRead,psocketgroupUsersRead,pChannelList);
1522 #ifdef ANON_DEBUG_MODE
1523 bool bIsDebugPacket=
false;
1526 bIsDebugPacket=
true;
1528 EVP_EncodeBlock(base64Payload, pMixPacket->
data,
DATA_SIZE);
1530 CAMsg::printMsg(LOG_DEBUG,
"AN.ON packet debug: %s\n", base64Payload);
1541 #ifdef LOG_PACKET_TIMES
1542 setZero64(pQueueEntry->timestamp_proccessing_start);
1544 #ifdef LOG_TRAFFIC_PER_USER
1545 pHashEntry->trafficOut++;
1547 #ifdef COUNTRY_STATS
1554 psocketgroupUsersWrite->
add(*pMuxSocket);
1561 pEntry=pChannelList->
get(pMuxSocket,pMixPacket->
channel);
1567 #ifdef LOG_PACKET_TIMES
1578 diff_time=
diff64(current_time,pEntry->timeCreated);
1580 pEntry->
channelIn,pEntry->
pHead->
id,pEntry->timeCreated,pEntry->packetsInFromUser,pEntry->packetsOutToUser,
1588 nrOfChOpMutex->lock();
1589 currentOpenedChannels--;
1590 nrOfChOpMutex->unlock();
1604 pEntry=pChannelList->
get(pMuxSocket,pMixPacket->
channel);
1611 #ifdef LOG_PACKET_TIMES
1617 crimeSurveillance(surveillanceIPs, nrOfSurveillanceIPs, pEntry->
pHead->
peerIP,pEntry->
pHead->peerPort, pMixPacket);
1619 #ifdef ANON_DEBUG_MODE
1630 pMix->incMixedPackets();
1632 pEntry->packetsInFromUser++;
1639 #ifdef REPLAY_DETECTION
1650 for(
int i=0;i<16;i++)
1652 pCipher->
setIV2(rsaBuff);
1655 #if defined (LOG_CHANNEL) ||defined(DATA_RETENTION_LOG)
1667 pMix->m_pChannelToQueueList->add(pMixPacket->
channel, pQueueReadFromMix);
1669 nrOfChOpMutex->lock();
1670 if(pHashEntry->channelOpenedLastIntervalTS !=
1673 pHashEntry->channelOpenedLastIntervalTS =
1675 nrOfOpenedChannels++;
1677 currentOpenedChannels++;
1678 nrOfChOpMutex->unlock();
1681 #ifdef LOG_PACKET_TIMES
1686 pTmpEntry->packetsInFromUser++;
1687 set64(pTmpEntry->timeCreated,pQueueEntry->timestamp_proccessing_start);
1689 #ifdef DATA_RETENTION_LOG
1690 pQueueEntry->dataRetentionLogEntry.entity.first.channelid=htonl(pMixPacket->
channel);
1692 memcpy(pQueueEntry->dataRetentionLogEntry.entity.first.ip_in,pTmpEntry1->
pHead->
peerIP,4);
1693 pQueueEntry->dataRetentionLogEntry.entity.first.port_in=(
UINT16)pTmpEntry1->
pHead->peerPort;
1694 pQueueEntry->dataRetentionLogEntry.entity.first.port_in=htons(pQueueEntry->dataRetentionLogEntry.entity.first.port_in);
1703 crimeSurveillance(surveillanceIPs, nrOfSurveillanceIPs, pEntry->
pHead->
peerIP,pEntry->
pHead->peerPort, pMixPacket);
1706 #ifdef ANON_DEBUG_MODE
1711 pEntry->bDebug =
true;
1719 pMix->incMixedPackets();
1736 pHashEntry=pChannelList->
getNext();
1741 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixA::loop() - read from user --> countRead >0 after processing all connections!\n");
1753 countRead=
pMix->m_nUser+1;
1761 #ifdef LOG_PACKET_TIMES
1764 #ifdef ANON_DEBUG_MODE
1768 EVP_EncodeBlock(base64Payload, pMixPacket->
data,
DATA_SIZE);
1769 CAMsg::printMsg(LOG_DEBUG,
"Dequeued Downstream AN.ON packet from previous Mix debug: %s\n", base64Payload);
1777 #if defined(_DEBUG) && !defined(__MIX_TEST)
1780 pMix->m_pChannelToQueueList->removeChannel(pMixPacket->
channel);
1795 #ifdef LOG_PACKET_TIMES
1799 #ifdef LOG_TRAFFIC_PER_USER
1800 pEntry->
pHead->trafficOut++;
1802 #ifdef COUNTRY_STATS
1812 pEntry->packetsOutToUser++;
1814 diff_time=
diff64(current_time,pEntry->timeCreated);
1816 pEntry->
channelIn,pEntry->
pHead->
id,pEntry->timeCreated,pEntry->packetsInFromUser,pEntry->packetsOutToUser,
1832 nrOfChOpMutex->lock();
1833 currentOpenedChannels--;
1834 nrOfChOpMutex->unlock();
1845 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixA: close channel -> client but channel does not exist.\n");
1852 #if defined(_DEBUG) && !defined(__MIX_TEST)
1866 CAMsg::printMsg(log,
"Detecting crime activity - next mix channel: %u -- "
1867 "Incoming (User) IP:Port is: %u.%u.%u.%u:%u \n", pMixPacket->
channel,
1872 pEntry->
pHead->peerPort);
1886 #ifdef LOG_PACKET_TIMES
1889 #ifdef ANON_DEBUG_MODE
1894 EVP_EncodeBlock(base64Payload, pMixPacket->
data,
DATA_SIZE);
1895 CAMsg::printMsg(LOG_DEBUG,
"Send Dowwstream AN.ON packet debug: %s\n", base64Payload);
1903 #ifdef LOG_TRAFFIC_PER_USER
1904 pEntry->
pHead->trafficOut++;
1906 #ifdef COUNTRY_STATS
1910 pEntry->packetsOutToUser++;
1930 pMix->incMixedPackets();
1951 bAktiv =
pMix->sendToUsers(psocketgroupUsersWrite,psocketgroupUsersRead,pChannelList);
1952 #ifndef FAST_PROCESSING
1981 CAQueue *controlMessageUserQueue = NULL;
1982 CAQueue *dataMessageUserQueue = NULL;
1984 CAQueue *processedQueue = NULL;
1986 bool bAktiv =
false;
1987 UINT32 iSocketErrors = 0;
1996 while(pfmHashEntry != NULL)
2001 while( (countRead > 0) && (pfmHashEntry != NULL) )
2009 processedQueue = NULL;
2012 dataMessageUserQueue = pfmHashEntry->
pQueueSend;
2015 if(controlMessageUserQueue->
getSize() > 0)
2017 processedQueue = controlMessageUserQueue;
2020 else if( (dataMessageUserQueue->
getSize() > 0)
2026 processedQueue = dataMessageUserQueue;
2030 if(processedQueue != NULL)
2032 extractSize = packetSize;
2037 processedQueue->
get((
UINT8*) packetToSend, &extractSize);
2043 #ifdef ANON_DEBUG_MODE
2048 CAMsg::printMsg(LOG_DEBUG,
"Send Downstream AN.ON packet to user debug: %s\n", base64Payload);
2076 if(processedQueue != controlMessageUserQueue)
2082 #ifdef LOG_PACKET_TIMES
2102 SOCKET sock=clientSocket->getSocket();
2106 closeConnection(pfmHashEntry,psocketgroupUsersRead,psocketgroupUsersWrite,pChannelList);
2112 pfmHashEntry=(
fmHashTableEntry*)psocketgroupUsersWrite->getNextSignaledSocketData();
2116 pfmHashEntry=pChannelList->
getNext();
2119 if (iSocketErrors > 1)
2121 CAMsg::printMsg(LOG_ERR,
"CAFirstMixA::sendtoUser() - %d send errors on a socket occured!\n", iSocketErrors);
#define FIRST_MIX_SIZE_OF_SYMMETRIC_KEYS
#define BEGIN_STACK(methodName)
#define FINISH_STACK(methodName)
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
SINT32 getcurrentTimeMicros(UINT64 &u64Time)
Gets the current Systemtime in micros seconds.
bool equals(const XMLCh *const e1, const char *const e2)
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 GET_NET_ERROR_STR(x)
#define THREAD_RETURN_SUCCESS
#define ERR_INTERN_SOCKET_CLOSED
#define MAX_NEXT_MIX_QUEUE_SIZE
#define ASSERT(cond, msg)
static const SINT32 HANDLE_PACKET_CONNECTION_OK
static const SINT32 HANDLE_PACKET_CLOSE_CONNECTION
static SINT32 handleJapPacket(fmHashTableEntry *pHashEntry, bool a_bControlMessage, bool a_bMessageToJAP)
This should be called by the FirstMix for every incoming Jap packet.
static UINT32 getAuthFlags(fmHashTableEntry *pHashEntry)
static const SINT32 HANDLE_PACKET_PREPARE_FOR_CLOSING_CONNECTION
UINT32 getDelayChannelBucketGrow()
UINT32 getDelayChannelBucketGrowIntervall()
UINT32 getDelayChannelUnlimitTraffic()
bool proccessMixPacket(const MIXPACKET *pPacket)
SINT32 insert(UINT8 key[16], UINT64 timestamp)
Inserts this key in the replay DB.
void checkUserConnections()
void finishPacket(fmHashTableEntry *pfmHashEntry)
friend THREAD_RETURN fm_loopPacketProcessing(void *params)
SINT32 closeConnection(fmHashTableEntry *pHashEntry)
SINT32 accountTrafficDownstream(fmHashTableEntry *pfmHashEntry)
SINT32 accountTrafficUpstream(fmHashTableEntry *pHashEntry)
void notifyAllUserChannels(fmHashTableEntry *pfmHashEntry, UINT16 flags)
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.
bool isKickoutForced(fmHashTableEntry *pHashTableEntry)
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.
bool isTimedOut(fmHashTableEntry *pHashTableEntry)
void decDelayBuckets(UINT32 delayBucketID)
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.
void setKickoutForced(fmHashTableEntry *pHashTableEntry, bool kickoutForced)
fmHashTableEntry * popTimeoutEntry()
SINT32 pushTimeoutEntry(fmHashTableEntry *pHashTableEntry, bool kickoutForced=!KICKOUT_FORCED)
adds the entry to the timeout queue with mutex
bool hasDelayBuckets(UINT32 delayBucketID)
CAThread * m_pthreadAcceptUsers
CAQueue * m_pQueueSendToMix
friend THREAD_RETURN fm_loopLog(void *)
CASocketGroupEpoll * m_psocketgroupUsersWrite
CASocketGroupEpoll * m_psocketgroupUsersRead
tUINT32withLock * m_PacketsPerCountryOUT
SINT32 decUsers(LP_fmHashTableEntry pHashEntry)
CAFirstMixChannelList * m_pChannelList
tUINT32withLock * m_PacketsPerCountryIN
CAQueue * m_pQueueReadFromMix
SINT32 removeIP(const UINT8 ip[4])
Removes the IP-Address from the list.
static CACmdLnOptions * getOptions()
SINT32 lock()
Locks the lockable object by threadsafe incrementing a reference counter.
CAInfoService * m_pInfoService
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
SINT32 receive(MIXPACKET *pPacket)
Receives a whole MixPacket.
SINT32 prepareForSend(MIXPACKET *inoutPacket)
This is a simple FIFO-Queue.
SINT32 add(const void *buff, UINT32 size)
Adds data to the Queue.
SINT32 clean()
Removes any stored data from 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()
bool isSignaled(CASocket &s)
SINT32 remove(CASocket &s)
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
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 setIV2(const UINT8 *p_iv)=0
Sets iv2 to p_iv.
virtual SINT32 crypt2(const UINT8 *in, UINT8 *out, UINT32 len)=0
virtual SINT32 crypt1(const UINT8 *in, UINT8 *out, UINT32 len)=0
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.
CASymChannelCipher * pCipher
volatile UINT32 delayBucketID
CAQueue * pControlMessageQueue
CASymChannelCipher * pSymCipher
CAControlChannelDispatcher * pControlChannelDispatcher
SINT32 kickoutSendRetries
SINT32 uAlreadySendPacketSize
struct t_queue_entry tQueueEntry
#define CHANNEL_SIG_CRIME