Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CASocket Class Reference
Inheritance diagram for CASocket:
CAClientSocket CATLSClientSocket

Public Member Functions

 CASocket (bool bIsReserved=false)
 
 ~CASocket ()
 
virtual SINT32 create ()
 
virtual SINT32 create (bool a_bShowTypicalError)
 
virtual SINT32 create (SINT32 type)
 
virtual SINT32 listen (const CASocketAddr &psa)
 Starts listening on address psa. More...
 
virtual SINT32 listen (UINT16 port)
 
virtual SINT32 accept (CASocket &s)
 Accepts a new connection. More...
 
virtual SINT32 connect (const CASocketAddr &psa)
 
virtual SINT32 connect (const CASocketAddr &psa, UINT32 retry, UINT32 sWaitTime)
 Tries to connect to the peer described by psa. More...
 
virtual SINT32 connect (const CASocketAddr &psa, UINT32 msTimeOut)
 Tries to connect to peer psa. More...
 
virtual SINT32 close ()
 
virtual SINT32 send (const UINT8 *buff, UINT32 len)
 Sends some data over the network. More...
 
virtual SINT32 sendFully (const UINT8 *buff, UINT32 len)
 Sends all data over the network. More...
 
virtual SINT32 sendFullyTimeOut (const UINT8 *buff, UINT32 len, UINT32 msTimeOut, UINT32 msTimeOutSingleSend)
 Sends all data over the network. More...
 
virtual SINT32 sendTimeOut (const UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 Sends some data over the network. More...
 
virtual SINT32 receive (UINT8 *buff, UINT32 len)
 Will receive some bytes from the socket. More...
 
virtual SINT32 receiveFullyT (UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 Trys to receive all bytes. More...
 
virtual SINT32 receiveLine (UINT8 *line, UINT32 maxLen, UINT32 msTimeOut)
 
virtual SINT32 peek (UINT8 *buff, UINT32 len)
 Will peek some bytes from the socket read queue. More...
 
SOCKET getSocket ()
 Returns the number of the Socket used. More...
 
virtual SINT32 getLocalIP (UINT8 r_Ip[4])
 LERNGRUPPE Returns the source address of the socket. More...
 
virtual SINT32 getLocalPort ()
 
virtual SINT32 getPeerIP (UINT8 ip[4])
 
virtual SINT32 getPeerPort ()
 
virtual SINT32 setReuseAddr (bool b)
 
virtual SINT32 setSendTimeOut (UINT32 msTimeOut)
 
virtual SINT32 getSendTimeOut ()
 
virtual SINT32 setRecvBuff (UINT32 r)
 
virtual SINT32 getRecvBuff ()
 
virtual SINT32 setSendBuff (SINT32 r)
 Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r) More...
 
virtual SINT32 getSendBuff ()
 
virtual SINT32 setKeepAlive (bool b)
 Enables/disables the socket keep-alive option. More...
 
virtual SINT32 setKeepAlive (UINT32 sec)
 Enables the socket keep-alive option with a given ping time (in seconds). More...
 
virtual SINT32 setNonBlocking (bool b)
 
virtual SINT32 getNonBlocking (bool *b)
 
virtual bool isClosed ()
 
- Public Member Functions inherited from CAClientSocket
virtual ~CAClientSocket ()
 
SINT32 receiveFully (UINT8 *buff, UINT32 len)
 Receives all len bytes. More...
 

Static Public Member Functions

static SINT32 init ()
 
static SINT32 cleanup ()
 
static SINT32 setMaxNormalSockets (UINT32 u)
 Sets the max number of allowed "normal" sockets. More...
 
static SINT32 getMaxOpenSockets ()
 Tries to find out how many socket we can open by open as many socket as possible witthout errors. More...
 
static UINT32 countOpenSockets ()
 

Protected Attributes

volatile bool m_bSocketIsClosed
 check More...
 
SOCKET m_Socket
 
CASingleSocketGroupm_pSingleSocketGroupRead
 

Private Member Functions

virtual SINT32 setSocket (SOCKET s)
 
virtual SINT32 create (SINT32 type, bool a_bShowTypicalError)
 

Private Attributes

bool m_bIsReservedSocket
 

Static Private Attributes

static CAMutexm_pcsClose =NULL
 
static volatile UINT32 m_u32NormalSocketsOpen =0
 The following two variables are use to realise "reserved" sockets. More...
 
static UINT32 m_u32MaxNormalSockets =0xFFFFFFFF
 

Constructor & Destructor Documentation

◆ CASocket()

CASocket::CASocket ( bool  bIsReserved = false)

◆ ~CASocket()

CASocket::~CASocket ( )

References close().

Member Function Documentation

◆ accept()

SINT32 CASocket::accept ( CASocket s)
virtual

Accepts a new connection.

The new socket is returned in s.

Return values
E_SUCCESSif successful
E_SOCKETCLOSEDif the listening socket was closed
E_SOCKET_LIMITif the could not create a new socket for the new connection
E_UNKNOWNotherwise

References E_SOCKET_LIMIT, E_SOCKETCLOSED, E_SUCCESS, E_UNKNOWN, ERR_INTERN_SOCKET_CLOSED, GET_NET_ERROR, CAMutex::lock(), m_bSocketIsClosed, m_pcsClose, m_Socket, m_u32MaxNormalSockets, m_u32NormalSocketsOpen, CAMsg::printMsg(), setSocket(), SOCKET, SOCKET_ERROR, and CAMutex::unlock().

Referenced by CAMuxSocket::accept(), and CALocalProxy::loop().

◆ cleanup()

static SINT32 CASocket::cleanup ( )
static

References E_SUCCESS, and m_pcsClose.

Referenced by CALibProxytest::cleanup().

◆ close()

SINT32 CASocket::close ( )
virtual

◆ connect() [1/3]

virtual SINT32 CASocket::connect ( const CASocketAddr psa)
virtual

◆ connect() [2/3]

SINT32 CASocket::connect ( const CASocketAddr psa,
UINT32  msTimeOut 
)
virtual

Tries to connect to peer psa.

Parameters
psa- peer
msTimeOut- abort after msTimeOut milli seconds

Reimplemented in CATLSClientSocket.

References close(), connect(), create(), E_SOCKET_CONNECT, E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, getNonBlocking(), CASocketAddr::getSize(), CASocketAddr::getType(), len, CASocketAddr::LPSOCKADDR(), m_bSocketIsClosed, m_Socket, SET_NET_ERROR, and setNonBlocking().

◆ connect() [3/3]

SINT32 CASocket::connect ( const CASocketAddr psa,
UINT32  retry,
UINT32  time 
)
virtual

Tries to connect to the peer described by psa.

Parameters
psa- peer
retry- number of retries
time- time between retries in seconds

References connect(), create(), E_SUCCESS, E_UNKNOWN, ERR_INTERN_CONNREFUSED, ERR_INTERN_TIMEDOUT, GET_NET_ERROR, CASocketAddr::getSize(), CASocketAddr::LPSOCKADDR(), m_bSocketIsClosed, m_Socket, CAMsg::printMsg(), and sSleep().

◆ countOpenSockets()

static UINT32 CASocket::countOpenSockets ( )
static

◆ create() [1/4]

SINT32 CASocket::create ( )
virtual

◆ create() [2/4]

SINT32 CASocket::create ( bool  a_bShowTypicalError)
virtual

References create().

◆ create() [3/4]

SINT32 CASocket::create ( SINT32  type)
virtual

References create(), and type.

◆ create() [4/4]

SINT32 CASocket::create ( SINT32  type,
bool  a_bShowTypicalError 
)
privatevirtual

◆ getLocalIP()

SINT32 CASocket::getLocalIP ( UINT8  r_Ip[4])
virtual

LERNGRUPPE Returns the source address of the socket.

Returns
r_Ip the source IP address
Return values
E_SUCCESSupon success
SOCKET_ERRORotherwise
Todo:
: Question: Correct for Unix domain sockets?

References E_SUCCESS, m_Socket, and SOCKET_ERROR.

Referenced by CALastMixA::loop().

◆ getLocalPort()

SINT32 CASocket::getLocalPort ( )
virtual

References m_Socket, and SOCKET_ERROR.

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

◆ getMaxOpenSockets()

SINT32 CASocket::getMaxOpenSockets ( )
static

Tries to find out how many socket we can open by open as many socket as possible witthout errors.

If we can open more than 10.000 sockets we stop the test and return 10000.

Return values
maxnumbers of sockets we can have open at the same time
E_UNKNOWNin case of some unexpected error

References close(), create(), and E_SUCCESS.

◆ getNonBlocking()

SINT32 CASocket::getNonBlocking ( bool *  b)
virtual

◆ getPeerIP()

SINT32 CASocket::getPeerIP ( UINT8  ip[4])
virtual

◆ getPeerPort()

SINT32 CASocket::getPeerPort ( )
virtual

References m_Socket, and SOCKET_ERROR.

Referenced by CAFirstMixChannelList::add().

◆ getRecvBuff()

SINT32 CASocket::getRecvBuff ( )
virtual

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

Referenced by CAFirstMix::init().

◆ getSendBuff()

SINT32 CASocket::getSendBuff ( )
virtual

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

Referenced by CAFirstMix::init(), and setSendBuff().

◆ getSendTimeOut()

SINT32 CASocket::getSendTimeOut ( )
virtual

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

Referenced by sendFullyTimeOut(), and sendTimeOut().

◆ getSocket()

SOCKET CASocket::getSocket ( )
virtual

Returns the number of the Socket used.

Which will be always the same number, even after close(), until the Socket is recreated using create()

Returns
number of the associated socket

Implements CAClientSocket.

References m_Socket.

Referenced by CASocketGroup::add(), CASocketGroupEpoll::add(), CAMuxSocket::getSocket(), CASocketGroup::isSignaled(), CASocketGroupEpoll::isSignaled(), CASocketGroup::remove(), CASocketGroupEpoll::remove(), and CASingleSocketGroup::select_once().

◆ init()

static SINT32 CASocket::init ( )
static

References E_SUCCESS, and m_pcsClose.

Referenced by CALibProxytest::init().

◆ isClosed()

virtual bool CASocket::isClosed ( )
virtual

◆ listen() [1/2]

SINT32 CASocket::listen ( const CASocketAddr psa)
virtual

Starts listening on address psa.

Return values
E_SUCCESS,ifsuccessful
E_SOCKET_LISTEN,ifcall to listen() returns an error
E_SOCKET_BIND,ifcall to bind() returns an error
E_UNKNOWN,otherwise

References AF_LOCAL, close(), create(), E_SOCKET_BIND, E_SOCKET_LISTEN, E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, CASocketAddr::getSize(), CASocketAddr::getType(), CASocketAddr::LPSOCKADDR(), m_bSocketIsClosed, m_Socket, CAMsg::printMsg(), SET_NET_ERROR, SOCKET_ERROR, and type.

Referenced by CAMuxSocket::accept(), CACmdLnOptions::createSockets(), CALocalProxy::init(), and listen().

◆ listen() [2/2]

SINT32 CASocket::listen ( UINT16  port)
virtual

References listen().

◆ peek()

SINT32 CASocket::peek ( UINT8 buff,
UINT32  len 
)
virtual

Will peek some bytes from the socket read queue.

May block or not depending on whatever this socket was set to blocking or non-blocking mode. Warning: If socket is in blocking mode and peek() is called, peek() will block until some data is available, EVEN IF AN OTHER THREAD WILL CLOSE THIS SOCKET!

Parameters
buffthe buffer which get the peeked data
lensize of buff
Returns
SOCKET_ERROR if an error occured
Return values
E_AGAIN,ifsocket was in non-blocking mode and receive would block or a timeout was reached
0if socket was gracefully closed
Returns
the number of bytes received (always >0)

References E_AGAIN, ERR_INTERN_WOULDBLOCK, GET_NET_ERROR, GET_NET_ERROR_STR, len, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.

◆ receive()

SINT32 CASocket::receive ( UINT8 buff,
UINT32  len 
)
virtual

Will receive some bytes from the socket.

May block or not depending on whatever this socket was set to blocking or non-blocking mode. Warning: If socket is in blocking mode and receive is called, receive will block until some data is available, EVEN IF AN OTHER THREAD WILL CLOSE THIS SOCKET!

Parameters
buffthe buffer which get the received data
lensize of buff
Returns
SOCKET_ERROR if an error occured
Return values
E_AGAIN,ifsocket was in non-blocking mode and receive would block or a timeout was reached
0if socket was gracefully closed
Returns
the number of bytes received (always >0)

Implements CAClientSocket.

Reimplemented in CATLSClientSocket.

References E_AGAIN, ERR_INTERN_WOULDBLOCK, GET_NET_ERROR, GET_NET_ERROR_STR, len, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.

Referenced by CAHttpClient::getContent(), CALocalProxy::loop(), CALastMixA::loop(), CAHttpClient::parseHTTPHeader(), CAChain::processDownstream(), CAMuxSocket::receive(), receiveFullyT(), and receiveLine().

◆ receiveFullyT()

SINT32 CASocket::receiveFullyT ( UINT8 buff,
UINT32  len,
UINT32  msTimeOut 
)
virtual

Trys to receive all bytes.

If after the timeout value has elapsed, not all bytes are received the error E_TIMEDOUT is returned.

Parameters
buffbyte array, where the received bytes would be stored
lenon input holds the number of bytes which should be read,
msTimeOutthe timout in milli seconds
Return values
E_TIMEDOUTif not all byts could be read
E_UNKNOWNif an error occured
E_SUCCESSif all bytes could be read

References add64(), diff64(), E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTimeMillis(), isLesser64(), len, m_pSingleSocketGroupRead, receive(), CASocketGroup::select(), set64(), and SET_NET_ERROR.

Referenced by CAFirstMix::doUserLogin_internal(), CAMuxSocket::receiveFully(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAAccountingBIInterface::settle(), and CAAccountingBIInterface::settleAll().

◆ receiveLine()

SINT32 CASocket::receiveLine ( UINT8 line,
UINT32  maxLen,
UINT32  msTimeOut 
)
virtual

◆ send()

SINT32 CASocket::send ( const UINT8 buff,
UINT32  len 
)
virtual

Sends some data over the network.

This may block, if socket is in blocking mode.

Parameters
buffthe buffer of data to send
lencontent length
Return values
E_AGAINif non blocking socket would block or a timeout was reached
E_UNKNOWNif an error occured
Returns
number of bytes send

Reimplemented in CATLSClientSocket.

References E_AGAIN, E_UNKNOWN, ERR_INTERN_WOULDBLOCK, GET_NET_ERROR, len, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.

Referenced by CALocalProxy::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), sendFully(), sendFullyTimeOut(), sendTimeOut(), CAFirstMixA::sendToUsers(), and CAChain::sendUpstreamDataInternal().

◆ sendFully()

SINT32 CASocket::sendFully ( const UINT8 buff,
UINT32  len 
)
virtual

Sends all data over the network.

This may block until all data is send.

Parameters
buff- the buffer of data to send
len- content length
Return values
E_UNKNOWN,ifan error occured
E_SUCCESS,ifsuccessful

Implements CAClientSocket.

Reimplemented in CATLSClientSocket.

References CASocketGroup::add(), E_AGAIN, E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, len, CAMsg::printMsg(), CASocketGroup::select(), and send().

Referenced by CALocalProxy::processKeyExchange(), CAMuxSocket::send(), and sendFullyTimeOut().

◆ sendFullyTimeOut()

SINT32 CASocket::sendFullyTimeOut ( const UINT8 buff,
UINT32  len,
UINT32  msTimeOut,
UINT32  msTimeOutSingleSend 
)
virtual

Sends all data over the network.

This may block until all data is send.

Parameters
buff- the buffer of data to send
len- content length
Return values
E_UNKNOWN,ifan error occured
E_TIMEDOUTif the timeout was reached
E_SUCCESS,ifsuccessful

References CASocketGroup::add(), E_AGAIN, E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTimeMillis(), getNonBlocking(), getSendTimeOut(), len, CAMsg::printMsg(), CASocketGroup::select(), send(), sendFully(), SET_NET_ERROR, and setSendTimeOut().

Referenced by CAFirstMix::doUserLogin_internal(), CAInfoService::sendCascadeHelo(), CAHttpClient::sendGetRequest(), CAInfoService::sendMixHelo(), CAHttpClient::sendPostRequest(), and CAInfoService::sendStatus().

◆ sendTimeOut()

SINT32 CASocket::sendTimeOut ( const UINT8 buff,
UINT32  len,
UINT32  msTimeOut 
)
virtual

Sends some data over the network.

Using a Timeout if socket is in blocking mode. Otherwise E_AGAIN may returned

Parameters
buffthe buffer to send
lencontent length
msTimeOutMaximum MilliSeconds to wait
Return values
E_AGAINif Operation would block on a non-blocking socket
E_TIMEDOUTif the timeout was reached
Returns
number of bytes send, or -1 in case of an error /FIXME really buggy!!!!

References E_AGAIN, E_SUCCESS, getNonBlocking(), getSendTimeOut(), len, msSleep(), CAMsg::printMsg(), send(), setNonBlocking(), and setSendTimeOut().

Referenced by CALastMixA::loop(), and CALastMixB::loop().

◆ setKeepAlive() [1/2]

SINT32 CASocket::setKeepAlive ( bool  b)
virtual

Enables/disables the socket keep-alive option.

Parameters
btrue if option should be enabled, false otherwise
Returns
E_SUCCESS if no error occured
E_UNKOWN otherwise

References E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, GET_NET_ERROR_STR, m_Socket, CAMsg::printMsg(), and SOCKET_ERROR.

Referenced by CAFirstMix::doUserLogin_internal(), CAFirstMix::init(), CALastMix::init(), CAMiddleMix::init(), and setKeepAlive().

◆ setKeepAlive() [2/2]

SINT32 CASocket::setKeepAlive ( UINT32  sec)
virtual

Enables the socket keep-alive option with a given ping time (in seconds).

Parameters
secthe time intervall(in seconds) of a keep-alive message
Returns
E_SUCCESS if no error occured
E_UNKOWN otherwise

References E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, GET_NET_ERROR_STR, m_Socket, CAMsg::printMsg(), setKeepAlive(), and SOCKET_ERROR.

◆ setMaxNormalSockets()

static SINT32 CASocket::setMaxNormalSockets ( UINT32  u)
static

Sets the max number of allowed "normal" sockets.

Return values
E_SUCCESSif call was successful
E_UNKNOWNotherwise

References E_SUCCESS, and m_u32MaxNormalSockets.

Referenced by main().

◆ setNonBlocking()

SINT32 CASocket::setNonBlocking ( bool  b)
virtual

◆ setRecvBuff()

SINT32 CASocket::setRecvBuff ( UINT32  r)
virtual

◆ setReuseAddr()

SINT32 CASocket::setReuseAddr ( bool  b)
virtual

◆ setSendBuff()

SINT32 CASocket::setSendBuff ( SINT32  r)
virtual

Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r)

References E_UNKNOWN, getSendBuff(), and m_Socket.

Referenced by CAFirstMix::init(), CALastMix::init(), CALocalProxy::init(), CAMiddleMix::init(), CALastMixA::loop(), CALastMixB::loop(), and CACmdLnOptions::setTargetInterfaces().

◆ setSendTimeOut()

SINT32 CASocket::setSendTimeOut ( UINT32  msTimeOut)
virtual

References m_Socket.

Referenced by sendFullyTimeOut(), and sendTimeOut().

◆ setSocket()

SINT32 CASocket::setSocket ( SOCKET  s)
privatevirtual

Member Data Documentation

◆ m_bIsReservedSocket

bool CASocket::m_bIsReservedSocket
private

Referenced by CASocket(), close(), and create().

◆ m_bSocketIsClosed

volatile bool CASocket::m_bSocketIsClosed
protected

check

end check

Referenced by accept(), CASocket(), close(), connect(), create(), isClosed(), and listen().

◆ m_pcsClose

CAMutex * CASocket::m_pcsClose =NULL
staticprivate

Referenced by accept(), cleanup(), close(), create(), and init().

◆ m_pSingleSocketGroupRead

CASingleSocketGroup* CASocket::m_pSingleSocketGroupRead
protected

◆ m_Socket

SOCKET CASocket::m_Socket
protected

◆ m_u32MaxNormalSockets

UINT32 CASocket::m_u32MaxNormalSockets =0xFFFFFFFF
staticprivate

Referenced by accept(), create(), and setMaxNormalSockets().

◆ m_u32NormalSocketsOpen

volatile UINT32 CASocket::m_u32NormalSocketsOpen =0
staticprivate

The following two variables are use to realise "reserved" sockets.

The rational behind is to ensure that we could allway crate "reserved" socket why we may fail to create normal sockets because of to many open files related restrictions

Referenced by accept(), close(), countOpenSockets(), and create().