Mixe for Privacy and Anonymity in the Internet
CALastMixChannelList.hpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2000, The JAP-Team 
00003 All rights reserved.
00004 Redistribution and use in source and binary forms, with or without modification, 
00005 are permitted provided that the following conditions are met:
00006 
00007   - Redistributions of source code must retain the above copyright notice, 
00008     this list of conditions and the following disclaimer.
00009 
00010   - Redistributions in binary form must reproduce the above copyright notice, 
00011     this list of conditions and the following disclaimer in the documentation and/or 
00012     other materials provided with the distribution.
00013 
00014   - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 
00015     may be used to endorse or promote products derived from this software without specific 
00016     prior written permission. 
00017 
00018   
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 
00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00027 */
00028 #ifndef __CALASTMIXCHANNELLIST__
00029 #define __CALASTMIXCHANNELLIST__
00030 #ifndef ONLY_LOCAL_PROXY
00031 #include "CASocket.hpp"
00032 #include "CAMuxSocket.hpp"
00033 #include "CAQueue.hpp"
00034 #include "CASymCipher.hpp"
00035 #include "CAMutex.hpp"
00036 #include "CAMsg.hpp"
00037 #include "CAThread.hpp"
00038 
00039 #define HASHTABLE_SIZE 0x00010000
00040 #define HASH_MASK 0x0000FFFF
00041 
00042 struct t_lastmixchannellist
00043   {
00044     public:
00045 
00046       HCHANNEL channelIn;
00047     
00048       CASymCipher*  pCipher;
00049       CASocket*     pSocket;
00050       CAQueue*      pQueueSend;
00051       SINT32        sendmeCounterDownstream; //this counts how many packets are sent to the user without an ack recevied yet.
00052       SINT32        sendmeCounterUpstream; //this counts how many packets are recieved from the user without sending an ack yet.
00053 #ifdef DELAY_CHANNELS
00054       UINT32        delayBucket;
00055       UINT32        delayBucketID;
00056 #endif
00057 #if defined (LOG_CHANNEL)
00058       UINT64        timeCreated;
00059 #endif
00060 #if defined (DELAY_CHANNELS_LATENCY)
00061       UINT64        timeLatency;
00062 #endif
00063 #ifdef LOG_CHANNEL
00064       UINT32        trafficInFromUser;
00065       UINT32        packetsDataOutToUser;
00066       UINT32        packetsDataInFromUser;
00067       UINT32        trafficOutToUser;
00068 #endif
00069     private:
00070       struct
00071         {
00072           struct t_lastmixchannellist* prev;
00073           struct t_lastmixchannellist* next;
00074         } list_Channels;
00075 
00076       struct
00077         {
00078           struct t_lastmixchannellist* prev;
00079           struct t_lastmixchannellist* next;
00080         } list_Sockets;
00081     
00082     friend class CALastMixChannelList;
00083   };
00084 
00085 typedef struct t_lastmixchannellist lmChannelList; 
00086 typedef struct t_lastmixchannellist lmChannelListEntry; 
00087 typedef lmChannelListEntry* LP_lmChannelListEntry;
00088 
00089       #ifdef DELAY_CHANNELS
00090         THREAD_RETURN lml_loopDelayBuckets(void*);
00091       #endif
00092 class CALastMixChannelList
00093   {
00094     public:
00095       CALastMixChannelList();
00096       ~CALastMixChannelList();
00097 
00098 
00099       SINT32 add(HCHANNEL id,CASocket* pSocket,CASymCipher* pCipher,CAQueue* pQueue
00100 #ifdef LOG_CHANNEL
00101                   ,UINT64 timecreated,UINT32 trafficIn
00102 #endif
00103 #if defined(DELAY_CHANNELS_LATENCY)
00104                   ,UINT64 delaytime
00105 #endif
00106                 );
00107 
00108       lmChannelListEntry* get(HCHANNEL channelIn)
00109         {
00110           lmChannelListEntry* akt=m_HashTable[channelIn & HASH_MASK];
00111           while(akt!=NULL)
00112             {
00113               if(akt->channelIn==channelIn)
00114                 return akt;
00115               akt=akt->list_Channels.next;
00116             }
00117           return NULL;
00118         }
00119 
00120       lmChannelListEntry* getFirstSocket()
00121         {
00122           if(m_listSockets!=NULL)
00123             m_listSocketsNext=m_listSockets->list_Sockets.next;
00124           else
00125             m_listSocketsNext=NULL;
00126           return m_listSockets;
00127         }
00128       
00129       lmChannelListEntry* getNextSocket()
00130         {
00131           lmChannelListEntry* akt=m_listSocketsNext;
00132           if(m_listSocketsNext!=NULL)
00133             m_listSocketsNext=m_listSocketsNext->list_Sockets.next;
00134           return akt;
00135         }
00136 
00137 //      SINT32 removeChannel(CASocket* pSocket);
00138       SINT32 removeChannel(HCHANNEL channelIn);
00139       UINT32 getSize(){return m_nChannels;}   
00140       static SINT32 test();
00141 
00142     private:
00143       UINT32 m_nChannels; //Number of channels in list
00145       LP_lmChannelListEntry* m_HashTable;
00146       
00148       lmChannelList* m_listSockets;
00150       lmChannelList* m_listSocketsNext;
00152       CAMutex m_Mutex;
00153       #ifdef DELAY_CHANNELS
00154         UINT32** m_pDelayBuckets;
00155         CAThread* m_pThreadDelayBucketsLoop;
00156         CAMutex* m_pMutexDelayChannel;
00157         bool m_bDelayBucketsLoopRun;
00158         friend THREAD_RETURN lml_loopDelayBuckets(void*);
00159         //Parameters
00160         volatile UINT32 m_u32DelayChannelUnlimitTraffic;  //how much traffic without any delay?
00161         volatile UINT32 m_u32DelayChannelBucketGrow; //how many bytes to put in each bucket per time intervall
00162         volatile UINT32 m_u32DelayChannelBucketGrowIntervall; //duration of one time intervall in ms
00163                                                               //therefore the allowed bandwith=BucketGrow/Intervall*1000 [bytes/s]
00164         public:
00165           void setDelayParameters(UINT32 unlimitTraffic,UINT32 bucketGrow,UINT32 intervall);
00166           void reduceDelayBuckets(UINT32 delayBucketID, UINT32 amount);
00167           bool hasDelayBuckets(UINT32 delayBucketID);
00168           UINT32 getDelayBuckets(UINT32 delayBucketID);
00169       #endif
00170       #ifdef DELAY_CHANNELS_LATENCY
00171         //Parameters
00172         volatile UINT32 m_u32DelayChannelLatency;  //min latency in ms
00173         public:
00174           void setDelayLatencyParameters(UINT32 latency);                                                       
00175       #endif
00176   };
00177 #endif
00178 #endif //ONLY_LOCAL_PROXY