Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
CAMiddleMixChannelList Class Reference

Data structure that stores all information about the currently open Mix channels. More...

#include <CAMiddleMixChannelList.hpp>

Collaboration diagram for CAMiddleMixChannelList:
[legend]

List of all members.

Public Member Functions

 CAMiddleMixChannelList ()
 ~CAMiddleMixChannelList ()
SINT32 add (HCHANNEL channelIn, CASymCipher *pCipher, HCHANNEL *channelOut)
 Adds a new Channel to the Channellist.
SINT32 getInToOut (HCHANNEL channelIn, HCHANNEL *channelOut, CASymCipher **ppCipher)
SINT32 remove (HCHANNEL channelIn)
 Removes a channel form the channellist.
SINT32 getOutToIn (HCHANNEL *channelIn, HCHANNEL channelOut, CASymCipher **ppCipher)

Static Public Member Functions

static SINT32 test ()

Private Member Functions

SINT32 getOutToIn_intern_without_lock (HCHANNEL *channelIn, HCHANNEL channelOut, CASymCipher **ppCipher)

Private Attributes

LP_mmHashTableEntrym_pHashTableIn
LP_mmHashTableEntrym_pHashTableOut
CAMutex m_Mutex

Detailed Description

Data structure that stores all information about the currently open Mix channels.

See [MiddleMixChannelList] for more information.

Definition at line 101 of file CAMiddleMixChannelList.hpp.


Constructor & Destructor Documentation

Definition at line 104 of file CAMiddleMixChannelList.hpp.

References m_pHashTableIn, and m_pHashTableOut.

        {
          m_pHashTableIn=new LP_mmHashTableEntry[0x10000];
          memset(m_pHashTableIn,0,0x10000*sizeof(LP_mmHashTableEntry));
          m_pHashTableOut=new LP_mmHashTableEntry[0x10000];
          memset(m_pHashTableOut,0,0x10000*sizeof(LP_mmHashTableEntry));
        }

Definition at line 7 of file CAMiddleMixChannelList.cpp.

References t_middlemixchannellist::list_HashTableIn, CAMutex::lock(), m_Mutex, m_pHashTableIn, m_pHashTableOut, t_middlemixchannellist::dl_in::next, t_middlemixchannellist::pCipher, and CAMutex::unlock().

  {
    m_Mutex.lock();
    for(UINT32 i=0;i<0x10000;i++)
      {     
        mmChannelListEntry* pEntry=m_pHashTableIn[i];
        mmChannelListEntry* pTmpEntry;
        while(pEntry!=NULL)
          {
            pTmpEntry=pEntry;
            pEntry=pEntry->list_HashTableIn.next;
            delete pTmpEntry->pCipher;
            pTmpEntry->pCipher = NULL;
            delete pTmpEntry;
            pTmpEntry = NULL;
          }
      }
    delete m_pHashTableIn;
    m_pHashTableIn = NULL;
    delete m_pHashTableOut;
    m_pHashTableOut = NULL;
    m_Mutex.unlock();
  }

Here is the call graph for this function:


Member Function Documentation

SINT32 CAMiddleMixChannelList::add ( HCHANNEL  channelIn,
CASymCipher pCipher,
HCHANNEL channelOut 
)

Adds a new Channel to the Channellist.

Parameters:
channelInincoming Channel-ID
pCipherCipher for recoding
channelOuton return holds a newly created random outgoing Channel-ID
Return values:
E_SUCCESSif Channel was successfully added to the list

Definition at line 38 of file CAMiddleMixChannelList.cpp.

References t_middlemixchannellist::channelIn, t_middlemixchannellist::channelOut, E_SUCCESS, getOutToIn_intern_without_lock(), getRandom(), t_middlemixchannellist::list_HashTableIn, t_middlemixchannellist::list_HashTableOut, CAMutex::lock(), m_Mutex, m_pHashTableIn, m_pHashTableOut, t_middlemixchannellist::dl_in::next, t_middlemixchannellist::dl_out::next, t_middlemixchannellist::pCipher, t_middlemixchannellist::dl_in::prev, t_middlemixchannellist::dl_out::prev, and CAMutex::unlock().

Referenced by mm_loopReadFromMixBefore(), and test().

  {
    m_Mutex.lock();
    mmChannelListEntry* pEntry=new mmChannelListEntry;
    pEntry->pCipher=pCipher;
    pEntry->channelIn=channelIn;
    pEntry->list_HashTableIn.prev=NULL;
    pEntry->list_HashTableOut.prev=NULL;
    do
      {
        getRandom(channelOut);
      }while(*channelOut<256||getOutToIn_intern_without_lock(NULL,*channelOut,NULL)==E_SUCCESS);
    pEntry->channelOut=*channelOut;

    mmChannelListEntry* pTmpEntry=m_pHashTableIn[channelIn&0x0000FFFF];
    pEntry->list_HashTableIn.next=pTmpEntry;
    if(pTmpEntry!=NULL)
      pTmpEntry->list_HashTableIn.prev=pEntry;
    m_pHashTableIn[channelIn&0x0000FFFF]=pEntry;

    pTmpEntry=m_pHashTableOut[(*channelOut)&0x0000FFFF];
    pEntry->list_HashTableOut.next=pTmpEntry;
    if(pTmpEntry!=NULL)
      pTmpEntry->list_HashTableOut.prev=pEntry;
    m_pHashTableOut[(*channelOut)&0x0000FFFF]=pEntry;

    m_Mutex.unlock();
    return E_SUCCESS;
  }

Here is the call graph for this function:

SINT32 CAMiddleMixChannelList::getInToOut ( HCHANNEL  channelIn,
HCHANNEL channelOut,
CASymCipher **  ppCipher 
)

Definition at line 68 of file CAMiddleMixChannelList.cpp.

References t_middlemixchannellist::channelIn, t_middlemixchannellist::channelOut, E_SUCCESS, E_UNKNOWN, t_middlemixchannellist::list_HashTableIn, CAMutex::lock(), CALockAble::lock(), m_Mutex, m_pHashTableIn, t_middlemixchannellist::dl_in::next, t_middlemixchannellist::pCipher, and CAMutex::unlock().

Referenced by mm_loopReadFromMixBefore().

  {
    m_Mutex.lock();
    mmChannelListEntry* pEntry=m_pHashTableIn[channelIn&0x0000FFFF];
    while(pEntry!=NULL)
      {
        if(pEntry->channelIn==channelIn)
          {
            if(channelOut!=NULL)
              *channelOut=pEntry->channelOut;
            if(ppCipher!=NULL)
              {
                *ppCipher=pEntry->pCipher;
                (*ppCipher)->lock();
              }
            m_Mutex.unlock();
            return E_SUCCESS;
          }
        pEntry=pEntry->list_HashTableIn.next;
      }
    m_Mutex.unlock();
    return E_UNKNOWN;
  }

Here is the call graph for this function:

SINT32 CAMiddleMixChannelList::getOutToIn ( HCHANNEL channelIn,
HCHANNEL  channelOut,
CASymCipher **  ppCipher 
) [inline]

Definition at line 141 of file CAMiddleMixChannelList.hpp.

References getOutToIn_intern_without_lock(), CAMutex::lock(), m_Mutex, and CAMutex::unlock().

Referenced by mm_loopReadFromMixAfter().

        {
          m_Mutex.lock();
          SINT32 ret=getOutToIn_intern_without_lock(channelIn,channelOut,ppCipher);
          m_Mutex.unlock();
          return ret;
        }

Here is the call graph for this function:

SINT32 CAMiddleMixChannelList::getOutToIn_intern_without_lock ( HCHANNEL channelIn,
HCHANNEL  channelOut,
CASymCipher **  ppCipher 
) [inline, private]

Definition at line 120 of file CAMiddleMixChannelList.hpp.

References t_middlemixchannellist::channelIn, t_middlemixchannellist::channelOut, E_SUCCESS, E_UNKNOWN, t_middlemixchannellist::list_HashTableOut, CALockAble::lock(), m_pHashTableOut, t_middlemixchannellist::dl_out::next, and t_middlemixchannellist::pCipher.

Referenced by add(), and getOutToIn().

        {
          mmChannelListEntry* pEntry=m_pHashTableOut[channelOut&0x0000FFFF];
          while(pEntry!=NULL)
            {
              if(pEntry->channelOut==channelOut)
                {
                  if(channelIn!=NULL)
                    *channelIn=pEntry->channelIn;
                  if(ppCipher!=NULL)
                    {
                      *ppCipher=pEntry->pCipher;
                      (*ppCipher)->lock();
                    }
                  return E_SUCCESS;
                }
              pEntry=pEntry->list_HashTableOut.next;
            }
          return E_UNKNOWN;
        }

Here is the call graph for this function:

Removes a channel form the channellist.

Parameters:
channelInincoming Channel-ID of the channel which should be removed
Return values:
E_SUCCESSif channel was successfully removed from the list
E_UNKNOWNotherwise

Definition at line 97 of file CAMiddleMixChannelList.cpp.

References t_middlemixchannellist::channelIn, t_middlemixchannellist::channelOut, E_SUCCESS, E_UNKNOWN, t_middlemixchannellist::list_HashTableIn, t_middlemixchannellist::list_HashTableOut, CAMutex::lock(), m_Mutex, m_pHashTableIn, m_pHashTableOut, t_middlemixchannellist::dl_in::next, t_middlemixchannellist::dl_out::next, t_middlemixchannellist::pCipher, t_middlemixchannellist::dl_in::prev, t_middlemixchannellist::dl_out::prev, and CAMutex::unlock().

Referenced by mm_loopReadFromMixAfter(), mm_loopReadFromMixBefore(), and test().

  {
    m_Mutex.lock();
    mmChannelListEntry* pEntry=m_pHashTableIn[channelIn&0x0000FFFF];
    while(pEntry!=NULL)
      {
        if(pEntry->channelIn==channelIn)
          {
            delete pEntry->pCipher;
            pEntry->pCipher = NULL;
            if(pEntry->list_HashTableIn.prev==NULL)
              {
                if(pEntry->list_HashTableIn.next==NULL)
                  {
                    m_pHashTableIn[channelIn&0x0000FFFF]=NULL;
                  }
                else
                  {
                    m_pHashTableIn[channelIn&0x0000FFFF]=pEntry->list_HashTableIn.next;
                    pEntry->list_HashTableIn.next->list_HashTableIn.prev=NULL;
                  }
              }
            else
              {
                if(pEntry->list_HashTableIn.next==NULL)
                  {
                    pEntry->list_HashTableIn.prev->list_HashTableIn.next=NULL;
                  }
                else
                  {
                    pEntry->list_HashTableIn.prev->list_HashTableIn.next=pEntry->list_HashTableIn.next;
                    pEntry->list_HashTableIn.next->list_HashTableIn.prev=pEntry->list_HashTableIn.prev;
                  }               
              }
            if(pEntry->list_HashTableOut.prev==NULL)
              {
                if(pEntry->list_HashTableOut.next==NULL)
                  {
                    m_pHashTableOut[pEntry->channelOut&0x0000FFFF]=NULL;
                  }
                else
                  {
                    m_pHashTableOut[pEntry->channelOut&0x0000FFFF]=pEntry->list_HashTableOut.next;
                    pEntry->list_HashTableOut.next->list_HashTableOut.prev=NULL;
                  }
              }
            else
              {
                if(pEntry->list_HashTableOut.next==NULL)
                  {
                    pEntry->list_HashTableOut.prev->list_HashTableOut.next=NULL;
                  }
                else
                  {
                    pEntry->list_HashTableOut.prev->list_HashTableOut.next=pEntry->list_HashTableOut.next;
                    pEntry->list_HashTableOut.next->list_HashTableOut.prev=pEntry->list_HashTableOut.prev;
                  }               
              }
            delete pEntry;
            pEntry = NULL;
            m_Mutex.unlock();
            return E_SUCCESS;
          }
        pEntry=pEntry->list_HashTableIn.next;
      }
    m_Mutex.unlock();
    return E_UNKNOWN;
  }

Here is the call graph for this function:

Definition at line 166 of file CAMiddleMixChannelList.cpp.

References add(), getRandom(), and remove().

        {
          CAMiddleMixChannelList oList;
          UINT32 c;
          UINT32 d;
          UINT32 rand;
          int i,j;
          for(i=0;i<1000;i++)
            {
              getRandom(&c);
              oList.add(c,NULL,&d);
            }
          for(i=0;i<100;i++)
            {
              getRandom(&rand);
              if(rand<0x0FFFFFFF)
                for(j=0;j<5;j++)
                  {
                    getRandom(&c);
                    oList.add(c,NULL,&d);
                  }
              getRandom(&rand);
              if(rand<0x7FFFFFFF)
                for(int j=0;j<100000;j++)
                  {
                    getRandom(&c);
                    oList.remove(c);
                  }
            }
          return 0;
        }

Here is the call graph for this function:


Member Data Documentation


The documentation for this class was generated from the following files: