Mixe for Privacy and Anonymity in the Internet
CAReplayDatabase.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef ONLY_LOCAL_PROXY
29 #include "CAMutex.hpp"
30 #include "CAThread.hpp"
31 #ifndef __CA_REPLAYDATABASE__
32 #define __CA_REPLAYDATABASE__
34  {
39 
41 
42 #define REPLAY_DB_ENTRIES_PER_HEAP 1000
43 
45  {
49 
50 //Stores management info for this database
51 typedef struct __t_database_info
52  {
59 
60 #define SECONDS_PER_INTERVALL 600
61 
63 
65  {
66  public:
69  SINT32 insert(UINT8 key[16]);
70  SINT32 start();
71  SINT32 stop();
73  SINT32 getCurrentReplayTimestamp(tReplayTimestamp& replayTimestamp) const;
74 
77  {
78  return m_refTime;
79  }
80 
82  static SINT32 getReplayTimestampForTime(tReplayTimestamp& replayTimestamp,UINT32 aktTime,UINT32 refTime);
83 
85  static SINT32 getTimeForReplayTimestamp(UINT32& refTime,tReplayTimestamp replayTimestamp)
86  {
87  time_t now=time(NULL);
88  refTime=(UINT32)(now-replayTimestamp.interval*SECONDS_PER_INTERVALL-replayTimestamp.offset);
89  return E_SUCCESS;
90  }
91 
92  static SINT32 test();
104  static SINT32 measurePerformance( UINT8* strLogFile,
105  UINT32 lowerBoundEntries,
106  UINT32 upperBoundEntries,
107  UINT32 stepBy,
108  UINT32 meassuresPerStep,
109  UINT32 insertsPerMeasure);
110  private:
111  friend THREAD_RETURN replaydb_loopMaintenance(void *param);
113  {
114  if(pDB->m_pHeap==NULL)
115  {
117  pDB->m_pHeap->next=NULL;
118  pDB->m_pLastHeap=pDB->m_pHeap;
120  }
121  else if(pDB->m_s32FreeEntries==0)
122  {
124  pDB->m_pLastHeap=pDB->m_pLastHeap->next;
125  pDB->m_pLastHeap->next=NULL;
127  }
128  return &pDB->m_pLastHeap->m_pEntries[--pDB->m_s32FreeEntries];
129  }
130 
133 
138 
143 
144  SINT32 nextClock();
148  SINT32 fill(UINT32 nrOfEntries);
149 
153  SINT32 simulateInsert(UINT8 key[16]);
154 
158  volatile bool m_bRun;
159  UINT32 m_refTime; //the seconds since epoch for the start of interval 0
160  volatile SINT32 m_currentClock; //the current 'interval' since m_refTimer
163  };
164 #endif //__CA_REPLAY_DATABASE__
165 #endif //ONLY_LOCAL_PROXY
THREAD_RETURN replaydb_loopMaintenance(void *param)
struct __t_replay_database_heap t_replay_databaseHeap
struct __t_database_info t_replay_databaseInfo
#define REPLAY_DB_ENTRIES_PER_HEAP
struct __t_replay_database_entry t_replay_databaseEntry
t_replay_databaseEntry * LP_replay_databaseEntry
#define SECONDS_PER_INTERVALL
#define THREAD_RETURN
Definition: StdAfx.h:540
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
static SINT32 test()
SINT32 getCurrentReplayTimestamp(tReplayTimestamp &replayTimestamp) const
Returns the current Replay timestamp for this database.
UINT32 getRefTime() const
Returns the local time in seconds since epoch for replay timestamp='0' for this database.
t_replay_databaseInfo * m_currDatabase
t_replay_databaseInfo * m_prevDatabase
friend THREAD_RETURN replaydb_loopMaintenance(void *param)
static SINT32 getTimeForReplayTimestamp(UINT32 &refTime, tReplayTimestamp replayTimestamp)
Returns the refernce time (seconds since epoch) for the given replay timestamp.
SINT32 insert(UINT8 key[16])
Inserts this key in the replay DB.
static SINT32 measurePerformance(UINT8 *strLogFile, UINT32 lowerBoundEntries, UINT32 upperBoundEntries, UINT32 stepBy, UINT32 meassuresPerStep, UINT32 insertsPerMeasure)
This mehtod can be used to measure the performance of the Replay database.
SINT32 deleteDB(t_replay_databaseInfo *&pDB)
Deletes the whole database pDB.
t_replay_databaseInfo * createDBInfo()
Creates and initialises a dbinfo struct.
SINT32 simulateInsert(UINT8 key[16])
This is a modified copy of insert() which simulates the insert() function as close as possible withou...
t_replay_databaseInfo * m_nextDatabase
SINT32 clearDB(t_replay_databaseInfo *pDB)
clears the whole database pDB - but does not delete the hashtable pDB
SINT32 fill(UINT32 nrOfEntries)
Pre fills the database with nrOfEntries random entries.
volatile bool m_bRun
LP_replay_databaseEntry getNewDBEntry(t_replay_databaseInfo *pDB)
volatile SINT32 m_currentClock
static SINT32 getReplayTimestampForTime(tReplayTimestamp &replayTimestamp, UINT32 aktTime, UINT32 refTime)
Returns the replay timestamp for this reference time (seconds since epoch) and time.
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
t_replay_databaseHeap * m_pHeap
t_replay_databaseHeap * m_pLastHeap
LP_replay_databaseEntry m_pHashTable[0x10000]
__t_replay_database_entry * right
UINT32 key
__t_replay_database_entry * left
__t_replay_database_heap * next
t_replay_databaseEntry m_pEntries[REPLAY_DB_ENTRIES_PER_HEAP]
the Replaytimestamp type
Definition: typedefs.hpp:206