Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
CAMuxSocket Class Reference

Public Member Functions

 CAMuxSocket (SYMCHANNELCIPHER_ALGORITHM algCipher)
 
 ~CAMuxSocket ()
 
SINT32 getHashKey ()
 Returns a Hashkey which uniquely identifies this socket. More...
 
SINT32 accept (UINT16 port)
 
SINT32 accept (const CASocketAddr &oAddr)
 Waits for an incoming connection on oAddr. More...
 
SINT32 connect (CASocketAddr &psa)
 
SINT32 connect (CASocketAddr &psa, UINT retry, UINT32 time)
 
SINT32 close ()
 Closes the underlying socket. More...
 
SINT32 send (MIXPACKET *pPacket)
 Sends a MixPacket over the Network. More...
 
SINT32 send (MIXPACKET *pPacket, UINT8 *buff)
 
SINT32 prepareForSend (MIXPACKET *inoutPacket)
 
SINT32 receive (MIXPACKET *pPacket)
 Receives a whole MixPacket. More...
 
SINT32 receive (MIXPACKET *pPacket, UINT32 timeout)
 Trys to receive a Mix-Packet. More...
 
SINT32 receiveFully (UINT8 *buff, UINT32 len)
 Receives some "plain" bytes from the underlying socket - just a convenient function... More...
 
SINT32 receiveFully (UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 
CASocketgetCASocket ()
 
SINT32 setCASocket (CASocket *pSocket)
 This will set the underlying CASocket. More...
 
SOCKET getSocket ()
 
SINT32 setCrypt (bool b)
 
bool getIsEncrypted ()
 
SINT32 setCipher (SYMCHANNELCIPHER_ALGORITHM algCipher)
 
SINT32 setKey (UINT8 *key, UINT32 keyLen)
 Sets the symmetric keys used for de-/encrypting the Mux connection. More...
 
SINT32 setSendKey (UINT8 *key, UINT32 keyLen)
 
SINT32 setReceiveKey (UINT8 *key, UINT32 keyLen)
 

Static Public Member Functions

static SINT32 init ()
 
static SINT32 cleanup ()
 

Private Attributes

CASocketm_pSocket
 
UINT32 m_aktBuffPos
 
UINT8m_Buff
 
CASymCipherMuxSocketm_pCipherIn
 
CASymCipherMuxSocketm_pCipherOut
 
bool m_bIsCrypted
 
CAMutex m_csSend
 
CAMutex m_csReceive
 
t_hashkeylistEntrym_pHashKeyEntry
 

Static Private Attributes

static t_hashkeylistEntryms_phashkeylistAvailableHashKeys =NULL
 
static SINT32 ms_nMaxHashKeyValue =0
 
static CAMutexms_pcsHashKeyList =NULL
 

Constructor & Destructor Documentation

◆ CAMuxSocket()

CAMuxSocket::CAMuxSocket ( SYMCHANNELCIPHER_ALGORITHM  algCipher)

◆ ~CAMuxSocket()

CAMuxSocket::~CAMuxSocket ( )

Member Function Documentation

◆ accept() [1/2]

SINT32 CAMuxSocket::accept ( const CASocketAddr oAddr)

Waits for an incoming connection on oAddr.

Return values
E_SUCCESS,ifsuccessful
E_SOCKET_BIND,E_SOCKET_LISTEN
E_UNKOWN

References CASocket::accept(), CASocket::close(), CASocket::create(), E_SUCCESS, E_UNKNOWN, CASocketAddr::getType(), CASocket::listen(), m_aktBuffPos, m_pSocket, and CASocket::setReuseAddr().

◆ accept() [2/2]

SINT32 CAMuxSocket::accept ( UINT16  port)

◆ cleanup()

static SINT32 CAMuxSocket::cleanup ( )
static

◆ close()

SINT32 CAMuxSocket::close ( )

◆ connect() [1/2]

SINT32 CAMuxSocket::connect ( CASocketAddr psa)

◆ connect() [2/2]

SINT32 CAMuxSocket::connect ( CASocketAddr psa,
UINT  retry,
UINT32  time 
)

◆ getCASocket()

CASocket* CAMuxSocket::getCASocket ( )

◆ getHashKey()

SINT32 CAMuxSocket::getHashKey ( )

◆ getIsEncrypted()

bool CAMuxSocket::getIsEncrypted ( )

References m_bIsCrypted.

◆ getSocket()

SOCKET CAMuxSocket::getSocket ( )

◆ init()

static SINT32 CAMuxSocket::init ( )
static

References E_SUCCESS, and ms_pcsHashKeyList.

Referenced by CALibProxytest::init().

◆ prepareForSend()

SINT32 CAMuxSocket::prepareForSend ( MIXPACKET inoutPacket)

◆ receive() [1/2]

SINT32 CAMuxSocket::receive ( MIXPACKET pPacket)

Receives a whole MixPacket.

Blocks until a packet is received or a socket error occurs.

Parameters
pPacketon return stores the received MixPacket
Return values
SOCKET_ERROR,incase of an error
MIXPACKET_SIZEotherwise

References t_MixPacket::channel, E_SUCCESS, E_UNKNOWN, t_MixPacket::flags, CAMutex::lock(), m_bIsCrypted, m_csReceive, m_pCipherIn, m_pSocket, MIXPACKET_SIZE, CAMsg::printMsg(), CAClientSocket::receiveFully(), SOCKET_ERROR, and CAMutex::unlock().

Referenced by CAFirstMix::doUserLogin_internal(), CALocalProxy::loop(), CAFirstMixA::loop(), and CAFirstMixB::loop().

◆ receive() [2/2]

SINT32 CAMuxSocket::receive ( MIXPACKET pPacket,
UINT32  msTimeout 
)

Trys to receive a Mix-Packet.

If after timout milliseconds not a whole packet is available E_AGAIN will be returned. In this case you should later try to get the rest of the packet

References CASocketGroup::add(), add64(), t_MixPacket::channel, diff64(), E_AGAIN, E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, t_MixPacket::flags, GET_NET_ERROR, GET_NET_ERROR_STR, getcurrentTimeMillis(), CASocket::isClosed(), isEqual64(), isGreater64(), len, CAMutex::lock(), m_aktBuffPos, m_bIsCrypted, m_Buff, m_csReceive, m_pCipherIn, m_pSocket, MIXPACKET_SIZE, CAMsg::printMsg(), CASocket::receive(), CASocketGroup::select(), and CAMutex::unlock().

◆ receiveFully() [1/2]

SINT32 CAMuxSocket::receiveFully ( UINT8 buff,
UINT32  len 
)

Receives some "plain" bytes from the underlying socket - just a convenient function...

References len, m_pSocket, and CAClientSocket::receiveFully().

Referenced by CALastMix::processKeyExchange(), and CAMiddleMix::processKeyExchange().

◆ receiveFully() [2/2]

SINT32 CAMuxSocket::receiveFully ( UINT8 buff,
UINT32  len,
UINT32  msTimeOut 
)

◆ send() [1/2]

SINT32 CAMuxSocket::send ( MIXPACKET pPacket)

Sends a MixPacket over the Network.

Will block until the whole packet is send.

Parameters
pPacketMixPacket to send
Return values
MIXPACKET_SIZEif MixPacket was successful send
E_UNKNOWNotherwise

References t_MixPacket::channel, E_SUCCESS, E_UNKNOWN, t_MixPacket::flags, GET_NET_ERROR, CAMutex::lock(), m_bIsCrypted, m_csSend, m_pCipherOut, m_pSocket, MIXPACKET_SIZE, CAMsg::printMsg(), CASocket::sendFully(), and CAMutex::unlock().

Referenced by CALocalProxy::loop(), and CALocalProxy::processKeyExchange().

◆ send() [2/2]

SINT32 CAMuxSocket::send ( MIXPACKET pPacket,
UINT8 buff 
)

◆ setCASocket()

SINT32 CAMuxSocket::setCASocket ( CASocket pSocket)

This will set the underlying CASocket.

Note: The object will be under full controll of CAMuxSocket. It will be destroyed by CAMuxSocket, if not longer needed. Therefore it must have be dynamically allocated.

Parameters
pSocketthe new CASocket to use, should not be NULL
Returns
E_SUCCESS, if successful, E_UNKNOWN otherwise

References E_SUCCESS, E_UNKNOWN, and m_pSocket.

◆ setCipher()

SINT32 CAMuxSocket::setCipher ( SYMCHANNELCIPHER_ALGORITHM  algCipher)

◆ setCrypt()

SINT32 CAMuxSocket::setCrypt ( bool  b)

◆ setKey()

SINT32 CAMuxSocket::setKey ( UINT8 key,
UINT32  keyLen 
)

Sets the symmetric keys used for de-/encrypting the Mux connection.

Parameters
keybuffer conntaining the key bits
keyLensize of the buffer (keys) if keylen=16, then the key is used for incomming and outgoing direction (key only) if keylen=32, then the first bytes are used for incoming and the last bytes are used for outgoing
Return values
E_SUCCESSif successful
E_UNKNOWNotherwise

References E_SUCCESS, E_UNKNOWN, m_pCipherIn, and m_pCipherOut.

◆ setReceiveKey()

SINT32 CAMuxSocket::setReceiveKey ( UINT8 key,
UINT32  keyLen 
)

◆ setSendKey()

SINT32 CAMuxSocket::setSendKey ( UINT8 key,
UINT32  keyLen 
)

Member Data Documentation

◆ m_aktBuffPos

UINT32 CAMuxSocket::m_aktBuffPos
private

◆ m_bIsCrypted

bool CAMuxSocket::m_bIsCrypted
private

◆ m_Buff

UINT8* CAMuxSocket::m_Buff
private

Referenced by CAMuxSocket(), receive(), and ~CAMuxSocket().

◆ m_csReceive

CAMutex CAMuxSocket::m_csReceive
private

Referenced by receive(), and setCrypt().

◆ m_csSend

CAMutex CAMuxSocket::m_csSend
private

Referenced by prepareForSend(), send(), and setCrypt().

◆ m_pCipherIn

CASymCipherMuxSocket* CAMuxSocket::m_pCipherIn
private

◆ m_pCipherOut

CASymCipherMuxSocket* CAMuxSocket::m_pCipherOut
private

◆ m_pHashKeyEntry

t_hashkeylistEntry* CAMuxSocket::m_pHashKeyEntry
private

◆ m_pSocket

CASocket* CAMuxSocket::m_pSocket
private

◆ ms_nMaxHashKeyValue

SINT32 CAMuxSocket::ms_nMaxHashKeyValue =0
staticprivate

Referenced by CAMuxSocket().

◆ ms_pcsHashKeyList

CAMutex * CAMuxSocket::ms_pcsHashKeyList =NULL
staticprivate

◆ ms_phashkeylistAvailableHashKeys

t_hashkeylistEntry * CAMuxSocket::ms_phashkeylistAvailableHashKeys =NULL
staticprivate

Referenced by CAMuxSocket(), cleanup(), and ~CAMuxSocket().