29 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
34 #define MAX_HASH_KEY 8200
64 m_aktAlloc=m_maxAlloc=0;
126 FINISH_STACK(
"CAFirstMixChannelList::add (null socket)");
132 FINISH_STACK(
"CAFirstMixChannelList::add (invalid hash key)");
139 FINISH_STACK(
"CAFirstMixChannelList::add (socket exists)");
146 pHashTableEntry->channelOpenedLastIntervalTS = 0;
154 #ifdef LOG_TRAFFIC_PER_USER
155 pHashTableEntry->trafficIn=0;
156 pHashTableEntry->trafficOut=0;
160 pHashTableEntry->strDialog=
new UINT8[strlen((
char*)strDialog)+1];
161 strcpy((
char*)pHashTableEntry->strDialog,(
char*)strDialog);
171 SAVE_STACK(
"CAFirstMixChannelList::add",
"copying peer IP");
172 memcpy(pHashTableEntry->
peerIP,peerIP,4);
173 #if defined(DATA_RETENTION_LOG) || defined(LOG_CRIME)
177 m_pMutexDelayChannel->lock();
178 pHashTableEntry->
delayBucket=m_u32DelayChannelUnlimitTraffic;
181 if(m_pDelayBuckets[i]==NULL)
188 m_pMutexDelayChannel->unlock();
191 SAVE_STACK(
"CAFirstMixChannelList::add",
"inserting in connection list");
193 if(m_listHashTableHead==NULL)
203 m_listHashTableHead=pHashTableEntry;
205 SAVE_STACK(
"CAFirstMixChannelList::add",
"inserting in timout list");
219 return pHashTableEntry;
223 #define MAX_NUMBER_OF_CHANNELS CHANNELS_PER_CLIENT
237 if(pMuxSocket==NULL||channelOut==NULL)
246 #define ERR_MSG_TO_MANY_CHANNELS "More than " STR(MAX_NUMBER_OF_CHANNELS) " channels!\n"
267 pNewEntry->
pHead=pHashTableEntry;
270 pNewEntry->packetsInFromUser=0;
271 pNewEntry->packetsOutToUser=0;
274 pNewEntry->downStreamBytes = 0;
276 #ifdef ANON_DEBUG_MODE
277 pNewEntry->bDebug =
false;
297 hashkey=(*channelOut)&0x0000FFFF;
327 return pHashTableEntry;
445 CAMsg::printMsg(LOG_WARNING,
"Try to switch back from forced kickout. A forced kickout cannot be undone!\n");
469 return pHashTableEntry;
474 "CAFirstMixChannelList:popTimeoutEntry_internal: Could not remove expired entry from timeout list!\n");
514 if (pHashTableEntry == NULL)
526 BEGIN_STACK(
"CAFirstMixChannelList::pushTimeoutEntry_internal");
556 FINISH_STACK(
"CAFirstMixChannelList::pushTimeoutEntry_internal");
566 if (pHashTableEntry == NULL)
614 CAMsg::printMsg(LOG_CRIT,
"CAFirstMixChannelList:removeFromTimeoutList: No previous element!!\n");
622 CAMsg::printMsg(LOG_CRIT,
"CAFirstMixChanelList:removeFromTimeoutList: No next element!!\n");
707 while(pTmpEntry!=NULL)
745 deleteChannelListEntry(pEntry);
756 delete[] pHashTableEntry->strDialog;
757 pHashTableEntry->strDialog = NULL;
847 pEntry->
pHead = NULL;
865 if (pEntry != NULL) {
866 if (pEntry->
pHead == NULL) {
873 while (pTmpEntry != NULL) {
907 deleteChannelListEntry(pEntry);
918 void CAFirstMixChannelList::cleanVacantOutChannels() {
923 while (pTmpEntry != NULL) {
924 if (pTmpEntry->
pHead == NULL) {
958 deleteChannelListEntry(pEntry);
969 hashkey = (hashkey + 1) & 0x0000FFFF;
971 while (hashkey != 0);
1004 while(pTmpEntry!=NULL)
1067 deleteChannelListEntry(pEntry);
1118 if(pMuxSocket==NULL)
1147 pList->
add(pMuxSocket,peerIP,NULL,NULL,NULL);
1149 pList->
add(pMuxSocket,peerIP,NULL,(
UINT8*)
"1");
1151 #if defined(HAVE_CRTDBG)
1152 _CrtMemState s1, s2, s3;
1153 _CrtMemCheckpoint( &s1 );
1157 pList->
addChannel(pMuxSocket,i,NULL,&channelOut);
1160 #if defined(HAVE_CRTDBG)
1161 _CrtMemCheckpoint( &s2 );
1162 if ( _CrtMemDifference( &s3, &s1, &s2 ) )
1163 _CrtMemDumpStatistics( &s3 );
1166 pList->
remove(pMuxSocket);
1178 BEGIN_STACK(
"CAFirstMixChannelList::fml_loopDelayBuckets");
1186 UINT32 u32MaxBucket=u32BucketGrow*10;
1189 if(pDelayBuckets[i]!=NULL&&*(pDelayBuckets[i])<u32MaxBucket)
1191 *(pDelayBuckets[i])+=u32BucketGrow;
1198 FINISH_STACK(
"CAFirstMixChannelList::fml_loopDelayBuckets");
1236 CAMsg::printMsg(LOG_DEBUG,
"CAFirstMixChannelList - Set new traffic limit per user- unlimit: %u bucketgrow: %u intervall %u\n",
1237 unlimitTraffic,bucketGrow,intervall);
THREAD_RETURN fml_loopDelayBuckets(void *param)
#define MAX_NUMBER_OF_CHANNELS
The maximum number of channels allowed per connection.
#define ERR_MSG_TO_MANY_CHANNELS
struct t_firstmixchannellist fmChannelListEntry
struct t_fmhashtableentry fmHashTableEntry
#define MAX_KICKOUT_RETRIES
#define BEGIN_STACK(methodName)
#define FINISH_STACK(methodName)
#define SAVE_STACK(methodName, methodPosition)
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
#define DELAY_USERS_BUCKET_GROW
#define THREAD_RETURN_SUCCESS
#define DELAY_USERS_BUCKET_GROW_INTERVALL
#define DELAY_USERS_TRAFFIC
SINT32 sendXMLMessage(const XERCES_CPP_NAMESPACE::DOMDocument *pDocMsg) const
Call to send a XML message via this control channel.
static SINT32 cleanupTableEntry(fmHashTableEntry *pHashEntry)
This should always be called when closing a JAP connection to cleanup the data structures.
SINT32 signal()
Signals this object.
This class "dispatches" messages which it receives via proccessMixPacket() to the associated control ...
void deleteAllControlChannels(void)
Deregisters all control channels and calls delete on every registered control channel object.
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)
CAThread * m_pThreadDelayBucketsLoop
fmHashTableEntry * getFirst()
Gets the first connection of all connections in the list.
LP_fmChannelListEntry * m_HashTableOutChannels
The Hash-Table of all out-channels.
volatile UINT32 ** m_pDelayBuckets
bool isKickoutForced(fmHashTableEntry *pHashTableEntry)
bool isTimedOut_internal(fmHashTableEntry *pHashTableEntry)
SINT32 removeFromTimeoutList(fmHashTableEntry *pHashTableEntry)
fmHashTableEntry * m_listTimoutHead
Pointer to the head of the timout list of all connections.
SINT32 addChannel(CAMuxSocket *pMuxSocket, HCHANNEL channelIn, CASymChannelCipher *pCipher, HCHANNEL *channelOut)
Adds a new channel for a given connection to the channel list.
static const SINT32 EXPIRATION_TIME_SECS
fmChannelListEntry * get(CAMuxSocket *pMuxSocket, HCHANNEL channelIn)
Returns the information for a given Input-Channel-ID.
fmHashTableEntry * m_listHashTableNext
Next Element in the enumeration of all connections.
CAMutex * m_pMutexDelayChannel
fmHashTableEntry * getNext()
Gets the next entry in the connections-list.
fmChannelListEntry * get_intern_without_lock(HCHANNEL channelOut)
Gets the in-channel and all associated information for the given out-channel.
fmHashTableEntry * m_listHashTableHead
Pointer to the head of a list of all connections.
friend THREAD_RETURN fml_loopDelayBuckets(void *)
bool forceKickout(fmHashTableEntry *pHashTableEntry, const XERCES_CPP_NAMESPACE::DOMDocument *pErrDoc)
forces a kickout for this entry if the entry is still valid and sends an errorMessage via the control...
fmHashTableEntry * popTimeoutEntry_internal(bool a_bForce)
SINT32 removeChannel(CAMuxSocket *pMuxSocket, HCHANNEL channelIn)
Removes a single channel from the list.
bool isTimedOut(fmHashTableEntry *pHashTableEntry)
fmHashTableEntry * m_listTimoutFoot
bool isKickoutForced_internal(fmHashTableEntry *pHashTableEntry)
void decDelayBuckets(UINT32 delayBucketID)
volatile UINT32 m_u32DelayChannelBucketGrowIntervall
fmChannelListEntry * getNextChannel(fmChannelListEntry *pEntry)
Gets the next channel for a given connection.
fmHashTableEntry * add(CAMuxSocket *pMuxSocket, const UINT8 peerIP[4], CAQueue *pQueueSend, UINT8 *controlChannelKeyRecv, UINT8 *controlChannelKeySent)
Adds a new TCP/IP connection (a new user) to the channel list.
volatile UINT32 m_u32DelayChannelBucketGrow
SINT32 remove(CAMuxSocket *pMuxSocket)
Removes all channels, which belongs to the given connection and the connection itself from the list.
void setKickoutForced_internal(fmHashTableEntry *pHashTableEntry, bool kickoutForced)
void setKickoutForced(fmHashTableEntry *pHashTableEntry, bool kickoutForced)
bool m_bDelayBucketsLoopRun
UINT32 countTimeoutEntries()
LP_fmHashTableEntry * m_HashTable
The Hash-Table of all connections.
fmHashTableEntry * popTimeoutEntry()
SINT32 pushTimeoutEntry(fmHashTableEntry *pHashTableEntry, bool kickoutForced=!KICKOUT_FORCED)
adds the entry to the timeout queue with mutex
bool hasDelayBuckets(UINT32 delayBucketID)
CAMutex m_Mutex
This mutex is used in all functions and makes them thread safe.
SINT32 pushTimeoutEntry_internal(fmHashTableEntry *pHashTableEntry, bool kickoutForced=!KICKOUT_FORCED)
adds the entry to the timeout queue
volatile UINT32 m_u32DelayChannelUnlimitTraffic
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
SINT32 getHashKey()
Returns a Hashkey which uniquely identifies this socket.
This is a simple FIFO-Queue.
virtual SINT32 getPeerPort()
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.
CAAccountingControlChannel * pControlChannel
a pointer to the user-specific control channel object
CASymChannelCipher * pCipher
struct t_firstmixchannellist * prev
struct t_firstmixchannellist * next
struct t_firstmixchannellist::@2 list_OutChannelHashTable
struct t_firstmixchannellist::@3 list_InChannelPerSocket
volatile UINT32 delayBucketID
struct t_fmhashtableentry * prev
CAQueue * pControlMessageQueue
CAControlChannelDispatcher * pControlChannelDispatcher
SINT32 kickoutSendRetries
volatile UINT32 delayBucket
CountryID of this IP Address.
CAConditionVariable * cleanupNotifier
struct t_fmhashtableentry::@1 list_TimeoutHashEntries
struct t_firstmixchannellist * pChannelList
tAiAccountingInfo * pAccountingInfo
SINT32 uAlreadySendPacketSize
struct t_fmhashtableentry * next
struct t_fmhashtableentry::@0 list_HashEntries