Mixe for Privacy and Anonymity in the Internet
CAReplayDatabase.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 ONLY_LOCAL_PROXY
00029 #include "CAMutex.hpp"
00030 #include "CAThread.hpp"
00031 #ifndef __CA_REPLAYDATABASE__
00032 #define __CA_REPLAYDATABASE__
00033 typedef struct __t_replay_database_entry
00034   {
00035     __t_replay_database_entry* left;
00036     __t_replay_database_entry* right;
00037     UINT32 key;
00038   } t_replay_databaseEntry; 
00039 
00040 typedef t_replay_databaseEntry* LP_replay_databaseEntry;
00041 
00042 #define REPLAY_DB_ENTRIES_PER_HEAP 1000
00043 
00044 typedef struct __t_replay_database_heap
00045   {
00046     t_replay_databaseEntry m_pEntries[REPLAY_DB_ENTRIES_PER_HEAP];
00047     __t_replay_database_heap* next;
00048   } t_replay_databaseHeap;
00049   
00050 //Stores management info for this database
00051 typedef struct __t_database_info
00052   {
00053     LP_replay_databaseEntry m_pHashTable[0x10000];
00054     UINT32            m_u32Size;
00055     t_replay_databaseHeap*    m_pHeap;
00056     t_replay_databaseHeap*    m_pLastHeap;
00057     SINT32            m_s32FreeEntries;
00058   } t_replay_databaseInfo;
00059   
00060 #define SECONDS_PER_INTERVALL 600
00061 
00062 THREAD_RETURN replaydb_loopMaintenance(void *param);
00063 
00064 class CAReplayDatabase
00065   {
00066     public:
00067       CAReplayDatabase();
00068       ~CAReplayDatabase();
00069       SINT32 insert(UINT8 key[16]);
00070       SINT32 start();
00071       SINT32 stop();
00073       SINT32 getCurrentReplayTimestamp(tReplayTimestamp& replayTimestamp) const;
00074 
00076       UINT32 getRefTime() const
00077         {
00078           return m_refTime;
00079         }
00080       
00082       static SINT32 getReplayTimestampForTime(tReplayTimestamp& replayTimestamp,UINT32 aktTime,UINT32 refTime);
00083 
00085       static SINT32 getTimeForReplayTimestamp(UINT32& refTime,tReplayTimestamp replayTimestamp)
00086         {
00087           time_t now=time(NULL);
00088           refTime=(UINT32)(now-replayTimestamp.interval*SECONDS_PER_INTERVALL-replayTimestamp.offset);
00089           return E_SUCCESS;
00090         }
00091 
00092       static SINT32 test();
00104       static SINT32 measurePerformance( UINT8* strLogFile,
00105                                         UINT32 lowerBoundEntries,
00106                                         UINT32 upperBoundEntries,
00107                                         UINT32 stepBy,
00108                                         UINT32 meassuresPerStep,
00109                                         UINT32 insertsPerMeasure);
00110     private:
00111       friend THREAD_RETURN replaydb_loopMaintenance(void *param);
00112       LP_replay_databaseEntry getNewDBEntry(t_replay_databaseInfo* pDB)
00113         {
00114           if(pDB->m_pHeap==NULL)
00115             {
00116               pDB->m_pHeap=new t_replay_databaseHeap;
00117               pDB->m_pHeap->next=NULL;
00118               pDB->m_pLastHeap=pDB->m_pHeap;
00119               pDB->m_s32FreeEntries=REPLAY_DB_ENTRIES_PER_HEAP;
00120             }
00121           else if(pDB->m_s32FreeEntries==0)
00122             {
00123               pDB->m_pLastHeap->next=new t_replay_databaseHeap;
00124               pDB->m_pLastHeap=pDB->m_pLastHeap->next;
00125               pDB->m_pLastHeap->next=NULL;
00126               pDB->m_s32FreeEntries=REPLAY_DB_ENTRIES_PER_HEAP;
00127             }
00128           return &pDB->m_pLastHeap->m_pEntries[--pDB->m_s32FreeEntries];  
00129         }
00130        
00132       t_replay_databaseInfo* createDBInfo();
00133       
00137       SINT32 clearDB(t_replay_databaseInfo* pDB);
00138       
00142       SINT32 deleteDB(t_replay_databaseInfo*& pDB);
00143 
00144       SINT32 nextClock();
00148       SINT32 fill(UINT32 nrOfEntries);
00149 
00153       SINT32 simulateInsert(UINT8 key[16]);
00154 
00155       t_replay_databaseInfo* m_currDatabase;
00156       t_replay_databaseInfo* m_nextDatabase;
00157       t_replay_databaseInfo* m_prevDatabase;
00158       volatile bool m_bRun;
00159       UINT32 m_refTime; //the seconds since epoch for the start of interval 0
00160       volatile SINT32 m_currentClock; //the current 'interval' since m_refTimer
00161       CAMutex*  m_pMutex;
00162       CAThread* m_pThread;
00163   };
00164 #endif //__CA_REPLAY_DATABASE__
00165 #endif //ONLY_LOCAL_PROXY