Mixe for Privacy and Anonymity in the Internet
CALastMixBChannelList.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, The JAP-Team
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, 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
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * - Neither the name of the University of Technology Dresden, Germany nor
15  * the names of its contributors may be used to endorse or promote
16  * products derived from this software without specific prior written
17  * permission.
18  *
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE
31  */
32 #include "../StdAfx.h"
34 #include "../CAUtil.hpp"
35 
38  for (UINT32 i = 0; i < 0x10000; i++) {
39  m_pChannelTable[i] = NULL;
40  }
42  m_pMutex = new CAMutex();
43 }
44 
46  delete m_pMutex;
47  m_pMutex = NULL;
48  delete []m_pChannelTable;
49  m_pChannelTable = NULL;
50 }
51 
52 t_lastMixBChannelListEntry* CALastMixBChannelList::add(HCHANNEL a_channelId, CASymChannelCipher* a_channelCipher, CAChain* a_associatedChain) {
53  m_pMutex->lock();
54  /* check whether we have not already an entry with the same ID */
55  if (getEntryInternal(a_channelId) != NULL) {
56  m_pMutex->unlock();
57  return NULL;
58  }
60  newEntry->channelId = a_channelId;
61  newEntry->channelCipher = a_channelCipher;
62  newEntry->associatedChain = a_associatedChain;
63  newEntry->associatedChannelList = this;
64  newEntry->firstResponseDeadline = NULL;
65  /* take the lower 16 bits of the ID as key for the hashtable */
66  UINT16 hashKey = (UINT16)(a_channelId & 0x0000FFFF);
67  /* now add the entry at the begin of the hashtable-line */
68  newEntry->rightEntry = m_pChannelTable[hashKey];
69  newEntry->rightEntryPointerOfLeftEntry = &(m_pChannelTable[hashKey]);
70  m_pChannelTable[hashKey] = newEntry;
71  if (newEntry->rightEntry != NULL) {
72  newEntry->rightEntry->rightEntryPointerOfLeftEntry = &(newEntry->rightEntry);
73  }
75  m_pMutex->unlock();
76  return newEntry;
77 }
78 
80  m_pMutex->lock();
81  if (a_channelEntry->associatedChannelList == this) {
82  /* only remove entries which are in the table */
83  *(a_channelEntry->rightEntryPointerOfLeftEntry) = a_channelEntry->rightEntry;
84  if (a_channelEntry->rightEntry != NULL) {
85  a_channelEntry->rightEntry->rightEntryPointerOfLeftEntry = a_channelEntry->rightEntryPointerOfLeftEntry;
86  }
87  a_channelEntry->rightEntry = NULL;
88  a_channelEntry->rightEntryPointerOfLeftEntry = NULL;
89  a_channelEntry->associatedChannelList = NULL;
90  }
91  m_pMutex->unlock();
92 }
93 
95  t_lastMixBChannelListEntry* returnedEntry = NULL;
96  m_pMutex->lock();
97  returnedEntry = getEntryInternal(a_channelId);
98  m_pMutex->unlock();
99  return returnedEntry;
100 }
101 
102 
104  /* mutex must be already locked */
105  /* take the lower 16 bits of the ID as key for the hashtable */
106  UINT16 hashKey = (UINT16)(a_channelId & 0x0000FFFF);
107  bool entryFound = false;
108  t_lastMixBChannelListEntry* currentEntry = m_pChannelTable[hashKey];
109  while ((currentEntry != NULL) && !entryFound) {
110  /* compare the Channel-IDs */
111  if (currentEntry->channelId == a_channelId) {
112  /* we have found the entry */
113  entryFound = true;
114  }
115  else {
116  currentEntry = currentEntry->rightEntry;
117  }
118  }
119  return currentEntry;
120 }
unsigned short UINT16
Definition: basetypedefs.h:133
unsigned int UINT32
Definition: basetypedefs.h:131
void removeFromTable(t_lastMixBChannelListEntry *a_channelEntry)
t_lastMixBChannelListEntry * getEntryInternal(HCHANNEL a_channelId)
t_lastMixBChannelListEntry * add(HCHANNEL a_channelId, CASymChannelCipher *a_channelCipher, CAChain *a_associatedChain)
t_lastMixBChannelListEntry * get(HCHANNEL a_channelId)
t_lastMixBChannelListEntry ** m_pChannelTable
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
class CAChain * associatedChain
t_deadlineEntry * firstResponseDeadline
HCHANNEL channelId
t_lastMixBChannelListEntry * rightEntry
t_lastMixBChannelListEntry ** rightEntryPointerOfLeftEntry
class CALastMixBChannelList * associatedChannelList
CASymChannelCipher * channelCipher
UINT32 HCHANNEL
Definition: typedefs.hpp:34