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
CASocket Class Reference
Inheritance diagram for CASocket:
CAClientSocket CATLSClientSocket

List of all members.

Public Member Functions

 CASocket (bool bIsReserved=false)
 ~CASocket ()
virtual SINT32 create ()
virtual SINT32 create (bool a_bShowTypicalError)
virtual SINT32 create (int type)
virtual SINT32 listen (const CASocketAddr &psa)
 Starts listening on address psa.
virtual SINT32 listen (UINT16 port)
virtual SINT32 accept (CASocket &s)
 Accepts a new connection.
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.
virtual SINT32 connect (const CASocketAddr &psa, UINT32 msTimeOut)
 Tries to connect to peer psa.
virtual SINT32 close ()
virtual SINT32 send (const UINT8 *buff, UINT32 len)
 Sends some data over the network.
virtual SINT32 sendFully (const UINT8 *buff, UINT32 len)
 Sends all data over the network.
virtual SINT32 sendFullyTimeOut (const UINT8 *buff, UINT32 len, UINT32 msTimeOut, UINT32 msTimeOutSingleSend)
 Sends all data over the network.
virtual SINT32 sendTimeOut (const UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 Sends some data over the network.
virtual SINT32 receive (UINT8 *buff, UINT32 len)
 Will receive some bytes from the socket.
virtual SINT32 receiveFullyT (UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 Trys to receive all bytes.
virtual SINT32 receiveLine (UINT8 *line, UINT32 maxLen, UINT32 msTimeOut)
SOCKET getSocket ()
 Returns the number of the Socket used.
virtual SINT32 getLocalIP (UINT8 r_Ip[4])
 LERNGRUPPE Returns the source address of the socket.
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)
virtual SINT32 getSendBuff ()
virtual SINT32 setKeepAlive (bool b)
 Enables/disables the socket keep-alive option.
virtual SINT32 setKeepAlive (UINT32 sec)
 Enables the socket keep-alive option with a given ping time (in seconds).
virtual SINT32 setNonBlocking (bool b)
virtual SINT32 getNonBlocking (bool *b)
virtual bool isClosed ()

Static Public Member Functions

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

Protected Attributes

volatile bool m_bSocketIsClosed
 check
SOCKET m_Socket

Private Member Functions

SINT32 create (int type, bool a_bShowTypicalError)

Private Attributes

CAMutex m_csClose
bool m_bIsReservedSocket

Static Private Attributes

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

Constructor & Destructor Documentation

CASocket::CASocket ( bool  bIsReserved = false)

References close().


Member Function Documentation

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_csClose, m_Socket, m_u32MaxNormalSockets, m_u32NormalSocketsOpen, CAMsg::printMsg(), SOCKET_ERROR, and CAMutex::unlock().

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

SINT32 CASocket::close ( ) [virtual]
virtual SINT32 CASocket::connect ( const CASocketAddr psa) [virtual]
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().

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

Tries to connect to peer psa.

Parameters:
psa- peer
msTimeOut- abort after msTimeOut milli seconds

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().

static UINT32 CASocket::countOpenSockets ( ) [static]

References m_u32NormalSocketsOpen.

Referenced by fm_loopAcceptUsers().

SINT32 CASocket::create ( ) [virtual]
SINT32 CASocket::create ( bool  a_bShowTypicalError) [virtual]

References create().

SINT32 CASocket::create ( int  type) [virtual]

References create().

SINT32 CASocket::create ( int  type,
bool  a_bShowTypicalError 
) [private]
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().

References m_Socket, and SOCKET_ERROR.

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

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.

Referenced by main().

SINT32 CASocket::getNonBlocking ( bool *  b) [virtual]
SINT32 CASocket::getPeerIP ( UINT8  ip[4]) [virtual]

References m_Socket, and SOCKET_ERROR.

Referenced by CAFirstMixChannelList::add().

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

Referenced by CAFirstMix::init().

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

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

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

Referenced by sendFullyTimeOut(), and sendTimeOut().

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

References m_Socket.

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

virtual bool CASocket::isClosed ( ) [virtual]
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 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().

SINT32 CASocket::listen ( UINT16  port) [virtual]

References listen().

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, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.

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

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 CASocketGroup::add(), add64(), diff64(), E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTimeMillis(), isLesser64(), receive(), CASocketGroup::select(), set64(), and SET_NET_ERROR.

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

SINT32 CASocket::receiveLine ( UINT8 line,
UINT32  maxLen,
UINT32  msTimeOut 
) [virtual]
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, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.

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

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 E_AGAIN, E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, CAMsg::printMsg(), CASingleSocketGroup::select_once(), and send().

Referenced by CAMuxSocket::send(), and 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 E_AGAIN, E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTimeMillis(), getNonBlocking(), getSendTimeOut(), CAMsg::printMsg(), CASingleSocketGroup::select_once(), send(), sendFully(), SET_NET_ERROR, and setSendTimeOut().

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

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(), msSleep(), CAMsg::printMsg(), send(), setNonBlocking(), and setSendTimeOut().

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

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(), CAMiddleMix::init(), CALastMix::init(), CAFirstMix::init(), and setKeepAlive().

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.

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().

SINT32 CASocket::setNonBlocking ( bool  b) [virtual]
SINT32 CASocket::setReuseAddr ( bool  b) [virtual]

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

References E_UNKNOWN, getSendBuff(), and m_Socket.

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

SINT32 CASocket::setSendTimeOut ( UINT32  msTimeOut) [virtual]

References m_Socket.

Referenced by sendFullyTimeOut(), and sendTimeOut().


Member Data Documentation

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

volatile bool CASocket::m_bSocketIsClosed [protected]

check

end check

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

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

UINT32 CASocket::m_u32MaxNormalSockets = 0xFFFFFFFF [static, private]

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

volatile UINT32 CASocket::m_u32NormalSocketsOpen = 0 [static, private]

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().