Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Protected Member Functions | Protected Attributes
CASocketList Class Reference

#include <CASocketList.hpp>

Collaboration diagram for CASocketList:
[legend]

List of all members.

Public Member Functions

 CASocketList ()
 CASocketList (bool bThreadSafe)
 ~CASocketList ()
SINT32 add (CASocket *pSocket, CASymCipher *pCiphers)
 Add a new channel to the channel-list.
SINT32 get (HCHANNEL in, CONNECTION *out)
 Gets a copy of an entry form the channel-list.
CASocketremove (HCHANNEL id)
SINT32 clear ()
CONNECTIONgetFirst ()
 Gets the first entry of the channel-list.
CONNECTIONgetNext ()
 Gets the next entry of the channel-list.
UINT32 getSize ()
SINT32 setThreadSafe (bool b)
SINT32 addSendMeCounter (HCHANNEL in, SINT32 value)

Protected Member Functions

SINT32 increasePool ()

Protected Attributes

CONNECTIONLISTm_Connections
CONNECTIONLISTm_Pool
CONNECTIONLISTm_AktEnumPos
t_MEMBLOCKm_Memlist
CAMutex cs
bool m_bThreadSafe
UINT32 m_Size

Detailed Description

Definition at line 47 of file CASocketList.hpp.


Constructor & Destructor Documentation

Definition at line 64 of file CASocketList.cpp.

References increasePool(), m_AktEnumPos, m_bThreadSafe, m_Connections, m_Memlist, m_Pool, m_Size, and setThreadSafe().

  {
    m_Connections=NULL;
    m_Pool=NULL;
    m_Memlist=NULL;
    m_AktEnumPos=NULL;
    m_bThreadSafe=false;
    setThreadSafe(false);
    increasePool();
    m_Size=0;
  }

Here is the call graph for this function:

CASocketList::CASocketList ( bool  bThreadSafe)

Definition at line 76 of file CASocketList.cpp.

References increasePool(), m_AktEnumPos, m_bThreadSafe, m_Connections, m_Memlist, m_Pool, and setThreadSafe().

  {
    m_Connections=NULL;
    m_Pool=NULL;
    m_Memlist=NULL;
    m_AktEnumPos=NULL;
    m_bThreadSafe=false;
    setThreadSafe(bThreadSafe);
    increasePool();
  }

Here is the call graph for this function:

Definition at line 87 of file CASocketList.cpp.

References clear().

  {
    clear();
  }

Here is the call graph for this function:


Member Function Documentation

SINT32 CASocketList::add ( CASocket pSocket,
CASymCipher pCiphers 
)

Add a new channel to the channel-list.

The id for that channel is randomly choosen.

Parameters:
pSocketa CASocket assoziated with the channel
pCiphersan array of CASymCipher assoziated with the channel
Returns:
E_SUCCESS if no error occurs E_UNKNOWN otherwise

Definition at line 125 of file CASocketList.cpp.

References cs, connlist::currentSendMeCounter, E_SUCCESS, E_UNKNOWN, getRandom(), increasePool(), CAMutex::lock(), m_bThreadSafe, m_Connections, m_Pool, m_Size, connlist::next, connlist::outChannel, connlist::pCiphers, connlist::pSocket, CAMutex::unlock(), and connlist::upstreamBytes.

Referenced by CALocalProxy::loop().

  {
    if(m_bThreadSafe)
      cs.lock();
    CONNECTIONLIST* tmp;
    if(m_Pool==NULL)
      {
        if(increasePool()!=E_SUCCESS)
          {
            if(m_bThreadSafe)
              cs.unlock();
            return E_UNKNOWN;
          }
       }
    tmp=m_Pool;
    m_Pool=m_Pool->next;
    tmp->next=m_Connections;
    m_Connections=tmp;
    m_Connections->pSocket=pSocket;
    m_Connections->pCiphers=pCiphers;
    m_Connections->currentSendMeCounter=0;
    m_Connections->upstreamBytes=0;
    for(;;)
      {
SELECT_RANDOM_CHANNEL_ID:
        getRandom(&m_Connections->outChannel);        
        tmp=m_Connections->next;
        while(tmp!=NULL)
          {
            if(tmp->outChannel==m_Connections->outChannel)
              goto SELECT_RANDOM_CHANNEL_ID;
            tmp=tmp->next;
          }
        break;
      }
    m_Size++;
    if(m_bThreadSafe)
      cs.unlock();
    return E_SUCCESS;
  }

Here is the call graph for this function:

Definition at line 195 of file CASocketList.cpp.

References cs, connlist::currentSendMeCounter, E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_bThreadSafe, m_Connections, connlist::next, connlist::outChannel, and CAMutex::unlock().

Referenced by CALocalProxy::loop().

  {
    if(m_bThreadSafe)
      cs.lock();
    CONNECTIONLIST* tmp;
    tmp=m_Connections;
    while(tmp!=NULL)
      {
        if(tmp->outChannel==in)
          {
            tmp->currentSendMeCounter+=value;
            if(m_bThreadSafe)
              cs.unlock();
            return E_SUCCESS;
          }
        tmp=tmp->next;
      }
    if(m_bThreadSafe)
      cs.unlock();
    return E_UNKNOWN;
  }

Here is the call graph for this function:

Definition at line 92 of file CASocketList.cpp.

References E_SUCCESS, m_AktEnumPos, m_Connections, m_Memlist, m_Pool, t_MEMBLOCK::mem, and t_MEMBLOCK::next.

Referenced by ~CASocketList().

  {
    _MEMBLOCK* tmp;
    tmp=m_Memlist;
    while(tmp!=NULL)
      {
        delete []tmp->mem;
        tmp->mem = NULL;
        m_Memlist=tmp;
        tmp=tmp->next;
        delete m_Memlist;
        m_Memlist = NULL;
      }
    m_Connections=NULL;
    m_Pool=NULL;
    m_Memlist=NULL;
    m_AktEnumPos=NULL;
    return E_SUCCESS;
  }

Gets a copy of an entry form the channel-list.

Parameters:
in- the channel-id for wich the entry is requested
out- the object, that will hold the copy
Returns:
true - if the channel was found false - otherwise

Definition at line 173 of file CASocketList.cpp.

References cs, E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_bThreadSafe, m_Connections, connlist::next, connlist::outChannel, and CAMutex::unlock().

Referenced by CALocalProxy::loop().

  {
    if(m_bThreadSafe)
      cs.lock();
    CONNECTIONLIST* tmp;
    tmp=m_Connections;
    while(tmp!=NULL)
      {
        if(tmp->outChannel==in)
          {
            memcpy(out,tmp,sizeof(CONNECTION));
            if(m_bThreadSafe)
              cs.unlock();
            return E_SUCCESS;
          }
        tmp=tmp->next;
      }
    if(m_bThreadSafe)
      cs.unlock();
    return E_UNKNOWN;
  }

Here is the call graph for this function:

Gets the first entry of the channel-list.

Returns:
the first entry of the channel list (this is not a copy!!)

Definition at line 62 of file CASocketList.hpp.

References m_AktEnumPos, and m_Connections.

Referenced by CALocalProxy::loop().

Gets the next entry of the channel-list.

Returns:
the next entry of the channel list (this is not a copy!!)

Definition at line 72 of file CASocketList.hpp.

References m_AktEnumPos, and connlist::next.

Referenced by CALocalProxy::loop().

Definition at line 79 of file CASocketList.hpp.

References m_Size.

{return m_Size;}

Definition at line 39 of file CASocketList.cpp.

References E_SUCCESS, E_UNKNOWN, m_Memlist, m_Pool, t_MEMBLOCK::mem, t_MEMBLOCK::next, connlist::next, and POOL_SIZE.

Referenced by add(), and CASocketList().

  {
    CONNECTIONLIST* tmp=new CONNECTIONLIST[POOL_SIZE];
    if(tmp==NULL)
      return E_UNKNOWN;
    _MEMBLOCK* tmpMem=new _MEMBLOCK;
    if(tmpMem==NULL)
      {
        delete[] tmp;
        tmp = NULL;
        return E_UNKNOWN;
      }
    memset(tmp,0,sizeof(CONNECTIONLIST)*POOL_SIZE);
    for(int i=1;i<POOL_SIZE;i++)
      {
        tmp[i-1].next=&tmp[i];
      }
    tmp[POOL_SIZE-1].next=m_Pool;
    m_Pool=tmp;
    tmpMem->next=m_Memlist;
    tmpMem->mem=tmp;
    m_Memlist=tmpMem;
    return E_SUCCESS;
  }

Definition at line 217 of file CASocketList.cpp.

References cs, CAMutex::lock(), m_AktEnumPos, m_bThreadSafe, m_Connections, m_Pool, m_Size, connlist::next, connlist::outChannel, connlist::pSocket, and CAMutex::unlock().

Referenced by CALocalProxy::loop().

  {
    if(m_bThreadSafe)
      cs.lock();
    CONNECTIONLIST* tmp,*before;
    CASocket* ret;
    tmp=m_Connections;
    before=NULL;
    while(tmp!=NULL)
      {
        if(tmp->outChannel==id)
          {
            if(m_AktEnumPos==tmp)
              m_AktEnumPos=tmp->next;
            if(before!=NULL)
              before->next=tmp->next;
            else
              m_Connections=tmp->next;
            tmp->next=m_Pool;
            m_Pool=tmp;
            ret=tmp->pSocket;
            m_Size--;
            if(m_bThreadSafe)
              cs.unlock();
            return ret;
          }
        before=tmp;
        tmp=tmp->next;
      }
    if(m_bThreadSafe)
      cs.unlock();
    return NULL;
  }

Here is the call graph for this function:

Definition at line 112 of file CASocketList.cpp.

References E_SUCCESS, and m_bThreadSafe.

Referenced by CASocketList().

  {
    m_bThreadSafe=b;
    return E_SUCCESS;
  }

Member Data Documentation

Definition at line 88 of file CASocketList.hpp.

Referenced by add(), addSendMeCounter(), get(), and remove().

Definition at line 86 of file CASocketList.hpp.

Referenced by CASocketList(), clear(), getFirst(), getNext(), and remove().

bool CASocketList::m_bThreadSafe [protected]

Definition at line 89 of file CASocketList.hpp.

Referenced by add(), addSendMeCounter(), CASocketList(), get(), remove(), and setThreadSafe().

Definition at line 84 of file CASocketList.hpp.

Referenced by add(), addSendMeCounter(), CASocketList(), clear(), get(), getFirst(), and remove().

Definition at line 87 of file CASocketList.hpp.

Referenced by CASocketList(), clear(), and increasePool().

Definition at line 85 of file CASocketList.hpp.

Referenced by add(), CASocketList(), clear(), increasePool(), and remove().

Definition at line 90 of file CASocketList.hpp.

Referenced by add(), CASocketList(), getSize(), and remove().


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