Mixe for Privacy and Anonymity in the Internet
CAMiddleMixChannelList.hpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2000, The JAP-Team
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 __CAMIDDLEMIXCHANNELLIST__
00029 #define __CAMIDDLEMIXCHANNELLIST__
00030 #ifndef ONLY_LOCAL_PROXY
00031 #include "CASymCipher.hpp"
00032 #include "CAMuxSocket.hpp"
00033 #include "CAMutex.hpp"
00034
00035
00036 struct t_middlemixchannellist
00037   {
00038     HCHANNEL channelIn;
00039     HCHANNEL channelOut;
00040     CASymCipher* pCipher;
00041     struct dl_in
00042       {
00043         struct t_middlemixchannellist* next,*prev;
00044       } list_HashTableIn;
00045
00046     struct dl_out
00047       {
00048         struct t_middlemixchannellist* next,*prev;
00049       } list_HashTableOut;
00050
00051   };
00052 typedef struct t_middlemixchannellist mmChannelList;
00053 typedef struct t_middlemixchannellist mmChannelListEntry;
00054 typedef struct t_middlemixchannellist mmHashTableEntry;
00055 typedef struct t_middlemixchannellist* LP_mmHashTableEntry;
00056
00101 class CAMiddleMixChannelList
00102   {
00103     public:
00104       CAMiddleMixChannelList()
00105         {
00106           m_pHashTableIn=new LP_mmHashTableEntry[0x10000];
00107           memset(m_pHashTableIn,0,0x10000*sizeof(LP_mmHashTableEntry));
00108           m_pHashTableOut=new LP_mmHashTableEntry[0x10000];
00109           memset(m_pHashTableOut,0,0x10000*sizeof(LP_mmHashTableEntry));
00110         }
00111
00112       ~CAMiddleMixChannelList();
00113
00114       SINT32 add(HCHANNEL channelIn,CASymCipher* pCipher,HCHANNEL* channelOut);
00115
00116       SINT32 getInToOut(HCHANNEL channelIn, HCHANNEL* channelOut,CASymCipher** ppCipher);
00117       SINT32 remove(HCHANNEL channelIn);
00118       static SINT32 test();
00119     private:
00120       SINT32 getOutToIn_intern_without_lock(HCHANNEL* channelIn, HCHANNEL channelOut,CASymCipher** ppCipher)
00121         {
00122           mmChannelListEntry* pEntry=m_pHashTableOut[channelOut&0x0000FFFF];
00123           while(pEntry!=NULL)
00124             {
00125               if(pEntry->channelOut==channelOut)
00126                 {
00127                   if(channelIn!=NULL)
00128                     *channelIn=pEntry->channelIn;
00129                   if(ppCipher!=NULL)
00130                     {
00131                       *ppCipher=pEntry->pCipher;
00132                       (*ppCipher)->lock();
00133                     }
00134                   return E_SUCCESS;
00135                 }
00136               pEntry=pEntry->list_HashTableOut.next;
00137             }
00138           return E_UNKNOWN;
00139         }
00140     public:
00141       SINT32 getOutToIn(HCHANNEL* channelIn, HCHANNEL channelOut,CASymCipher** ppCipher)
00142         {
00143           m_Mutex.lock();
00144           SINT32 ret=getOutToIn_intern_without_lock(channelIn,channelOut,ppCipher);
00145           m_Mutex.unlock();
00146           return ret;
00147         }
00148
00149     private:
00150       LP_mmHashTableEntry* m_pHashTableIn;
00151       LP_mmHashTableEntry* m_pHashTableOut;
00152       CAMutex m_Mutex;
00153   };
00154 #endif
00155 #endif //ONLY_LOCAL_PROXY