Mixe for Privacy and Anonymity in the Internet
CAPool.cpp
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 #include "StdAfx.h"
29 #include "CAPool.hpp"
30 #include "CAUtil.hpp"
31 #include "CAMsg.hpp"
32 #ifdef USE_POOL
34  {
35  m_uPoolSize=poolsize;
36  m_uRandMax=0xFFFFFFFF;
42 #ifdef LOG_PACKET_TIMES
43  setZero64(m_pPoolList->poolentry.timestamp_proccessing_start);
44  setZero64(m_pPoolList->poolentry.pool_timestamp_in);
45 #endif
46  m_pPoolList->next=NULL;
48  m_arChannelIDs=new HCHANNEL[poolsize];
49  m_arChannelIDs[0]=0;
50  for(UINT32 i=1;i<poolsize;i++)
51  {
52  tPoolListEntry* tmpEntry=new tPoolListEntry;
56  #ifdef LOG_PACKET_TIMES
57  setZero64(tmpEntry->poolentry.timestamp_proccessing_start);
58  setZero64(tmpEntry->poolentry.pool_timestamp_in);
59  #endif
60  tmpEntry->next=m_pPoolList;
61  m_pPoolList=tmpEntry;
62  m_arChannelIDs[i]=0;
63  }
65  }
66 
68  {
69  tPoolListEntry* tmpEntry;
70  while(m_pPoolList!=NULL)
71  {
72  tmpEntry=m_pPoolList;
74  delete tmpEntry;
75  tmpEntry = NULL;
76  }
77  delete m_pEntry;
78  m_pEntry = NULL;
79  delete[] m_arChannelIDs;
80  m_arChannelIDs = NULL;
81  }
82 
84  {
85  UINT32 v;
86  for(;;)
87  {
88  getRandom(&v);
89  if(v<m_uRandMax)
90  {
91  v%=m_uPoolSize;
92  break;
93  }
94  }
96  m_arChannelIDs[v]=pPoolEntry->packet.channel;
97  tPoolListEntry* pPrevEntry=NULL;
98  tPoolListEntry* pEntryOut=m_pPoolList;
99  while(pEntryOut->poolentry.packet.channel!=id)
100  {
101  pPrevEntry=pEntryOut;
102  pEntryOut=pEntryOut->next;
103  }
104 
105  if(pEntryOut==m_pPoolList) //first element to remove)
106  {
107  memcpy(&m_pEntry->poolentry,pPoolEntry,sizeof(tPoolEntry));
108  memcpy(pPoolEntry,&pEntryOut->poolentry,sizeof(tPoolEntry));
112  m_pLastEntry->next=NULL;
113  m_pEntry=pEntryOut;
114  }
115  else
116  {
117  memcpy(&m_pEntry->poolentry,pPoolEntry,sizeof(tPoolEntry));
118  memcpy(pPoolEntry,&pEntryOut->poolentry,sizeof(tPoolEntry));
121  m_pLastEntry->next=NULL;
122  pPrevEntry->next=pEntryOut->next;
123  m_pEntry=pEntryOut;
124  }
125  return E_SUCCESS;
126  }
127 #endif
t_pool_list tPoolListEntry
Definition: CAPool.hpp:38
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
void setZero64(UINT64 &op1)
Definition: CAUtil.hpp:355
#define DUMMY_CHANNEL
Definition: StdAfx.h:246
signed int SINT32
Definition: basetypedefs.h:132
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 pool(tPoolEntry *pPoolEntry)
Definition: CAPool.cpp:83
tPoolListEntry * m_pEntry
Definition: CAPool.hpp:53
tPoolListEntry * m_pPoolList
Definition: CAPool.hpp:51
CAPool(UINT32 poolsize)
Definition: CAPool.cpp:33
tPoolListEntry * m_pLastEntry
Definition: CAPool.hpp:52
HCHANNEL * m_arChannelIDs
Definition: CAPool.hpp:54
UINT32 m_uRandMax
Definition: CAPool.hpp:56
~CAPool()
Definition: CAPool.cpp:67
UINT32 m_uPoolSize
Definition: CAPool.hpp:55
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
HCHANNEL channel
Definition: typedefs.hpp:117
UINT8 data[DATA_SIZE]
Definition: typedefs.hpp:121
UINT16 flags
Definition: typedefs.hpp:118
tPoolEntry poolentry
Definition: CAPool.hpp:35
struct t_pool_list * next
Definition: CAPool.hpp:34
Definition: typedefs.hpp:169
MIXPACKET packet
Definition: typedefs.hpp:170
#define CHANNEL_DUMMY
Definition: typedefs.hpp:50
UINT32 HCHANNEL
Definition: typedefs.hpp:34
#define DATA_SIZE
Definition: typedefs.hpp:69