Mixe for Privacy and Anonymity in the Internet
|
#include <CASocket.hpp>
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 |
CASingleSocketGroup * | m_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 CAMutex * | m_pcsClose =NULL |
static volatile UINT32 | m_u32NormalSocketsOpen =0 |
The following two variables are use to realise "reserved" sockets. More... | |
static UINT32 | m_u32MaxNormalSockets =0xFFFFFFFF |
Definition at line 37 of file CASocket.hpp.
CASocket::CASocket | ( | bool | bIsReserved = false | ) |
Definition at line 49 of file CASocket.cpp.
References m_bIsReservedSocket, m_bSocketIsClosed, m_pSingleSocketGroupRead, and m_Socket.
|
inline |
Definition at line 41 of file CASocket.hpp.
References close().
Accepts a new connection.
The new socket is returned in s.
E_SUCCESS | if successful |
E_SOCKETCLOSED | if the listening socket was closed |
E_SOCKET_LIMIT | if the could not create a new socket for the new connection |
E_UNKNOWN | otherwise |
Definition at line 192 of file CASocket.cpp.
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().
|
inlinestatic |
Definition at line 49 of file CASocket.hpp.
References E_SUCCESS, and m_pcsClose.
Referenced by CALibProxytest::cleanup().
|
virtual |
Reimplemented in CATLSClientSocket.
Definition at line 351 of file CASocket.cpp.
References closesocket, E_SUCCESS, GET_NET_ERROR, CAMutex::lock(), m_bIsReservedSocket, m_bSocketIsClosed, m_pcsClose, m_Socket, m_u32NormalSocketsOpen, CAMsg::printMsg(), setSocket(), and CAMutex::unlock().
Referenced by CAMuxSocket::accept(), CAFirstMix::clean(), CALastMix::clean(), CALocalProxy::clean(), CAMuxSocket::close(), CATLSClientSocket::close(), CAChain::closeChainInternal(), connect(), CATLSClientSocket::connect(), getMaxOpenSockets(), CAInfoService::getPaymentInstance(), listen(), CALocalProxy::loop(), CALastMixA::loop(), CALastMixB::loop(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), CACmdLnOptions::setListenerInterfaces(), CACmdLnOptions::setTargetInterfaces(), CAChain::~CAChain(), and ~CASocket().
|
inlinevirtual |
Definition at line 64 of file CASocket.hpp.
Referenced by CAMuxSocket::connect(), CATLSClientSocket::connect(), connect(), CAInfoService::getPaymentInstance(), CALastMixA::loop(), CALastMixB::loop(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), and CACmdLnOptions::setTargetInterfaces().
|
virtual |
Tries to connect to peer psa.
psa | - peer |
msTimeOut | - abort after msTimeOut milli seconds |
Reimplemented in CATLSClientSocket.
Definition at line 270 of file CASocket.cpp.
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().
|
virtual |
Tries to connect to the peer described by psa.
psa | - peer |
retry | - number of retries |
time | - time between retries in seconds |
Definition at line 227 of file CASocket.cpp.
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().
|
inlinestatic |
Definition at line 128 of file CASocket.hpp.
References m_u32NormalSocketsOpen.
|
virtual |
Definition at line 73 of file CASocket.cpp.
Referenced by CAMuxSocket::accept(), connect(), create(), CACmdLnOptions::createSockets(), getMaxOpenSockets(), CAFirstMix::init(), CALocalProxy::init(), CAMiddleMix::init(), listen(), CALastMixA::loop(), CALastMixB::loop(), CACmdLnOptions::parse(), and CAFirstMixChannelList::test().
|
virtual |
Definition at line 83 of file CASocket.cpp.
References create().
Definition at line 78 of file CASocket.cpp.
References create(), and type.
Definition at line 89 of file CASocket.cpp.
References E_SOCKET_CREATE, E_SOCKET_LIMIT, E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, GET_NET_ERROR_STR, INVALID_SOCKET, CAMutex::lock(), m_bIsReservedSocket, m_bSocketIsClosed, m_pcsClose, m_u32MaxNormalSockets, m_u32NormalSocketsOpen, CAMsg::printMsg(), setSocket(), SOCKET, type, and CAMutex::unlock().
LERNGRUPPE Returns the source address of the socket.
E_SUCCESS | upon success |
SOCKET_ERROR | otherwise |
Definition at line 801 of file CASocket.cpp.
References E_SUCCESS, m_Socket, and SOCKET_ERROR.
Referenced by CALastMixA::loop().
|
virtual |
Definition at line 811 of file CASocket.cpp.
References m_Socket, and SOCKET_ERROR.
Referenced by CALocalProxy::loop(), and CALastMixA::loop().
|
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.
max | numbers of sockets we can have open at the same time |
E_UNKNOWN | in case of some unexpected error |
Definition at line 983 of file CASocket.cpp.
References close(), create(), and E_SUCCESS.
|
virtual |
Definition at line 972 of file CASocket.cpp.
References E_SUCCESS, flags, m_Socket, and SOCKET_ERROR.
Referenced by connect(), CAHttpClient::parseHTTPHeader(), sendFullyTimeOut(), and sendTimeOut().
Definition at line 820 of file CASocket.cpp.
References E_SUCCESS, m_Socket, and SOCKET_ERROR.
Referenced by isAllowedToPassRestrictions().
|
virtual |
Definition at line 830 of file CASocket.cpp.
References m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMixChannelList::add().
|
virtual |
Definition at line 852 of file CASocket.cpp.
References E_UNKNOWN, m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMix::init().
|
virtual |
Definition at line 873 of file CASocket.cpp.
References E_UNKNOWN, m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMix::init(), and setSendBuff().
|
virtual |
Definition at line 891 of file CASocket.cpp.
References E_UNKNOWN, m_Socket, and SOCKET_ERROR.
Referenced by sendFullyTimeOut(), and sendTimeOut().
|
inlinevirtual |
Returns the number of the Socket used.
Which will be always the same number, even after close(), until the Socket is recreated using create()
Implements CAClientSocket.
Definition at line 87 of file CASocket.hpp.
References m_Socket.
Referenced by CASocketGroup::add(), CASocketGroupEpoll::add(), CAMuxSocket::getSocket(), CASocketGroup::isSignaled(), CASocketGroupEpoll::isSignaled(), CASocketGroup::remove(), CASocketGroupEpoll::remove(), and CASingleSocketGroup::select_once().
|
inlinestatic |
Definition at line 43 of file CASocket.hpp.
References E_SUCCESS, and m_pcsClose.
Referenced by CALibProxytest::init().
|
inlinevirtual |
Definition at line 132 of file CASocket.hpp.
References m_bSocketIsClosed.
Referenced by CAFirstMix::doUserLogin_internal(), and CAMuxSocket::receive().
|
virtual |
Starts listening on address psa.
E_SUCCESS,if | successful |
E_SOCKET_LISTEN,if | call to listen() returns an error |
E_SOCKET_BIND,if | call to bind() returns an error |
E_UNKNOWN,otherwise |
Definition at line 142 of file CASocket.cpp.
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().
Definition at line 180 of file CASocket.cpp.
References listen().
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!
buff | the buffer which get the peeked data |
len | size of buff |
E_AGAIN,if | socket was in non-blocking mode and receive would block or a timeout was reached |
0 | if socket was gracefully closed |
Definition at line 770 of file CASocket.cpp.
References E_AGAIN, ERR_INTERN_WOULDBLOCK, GET_NET_ERROR, GET_NET_ERROR_STR, len, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.
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!
buff | the buffer which get the received data |
len | size of buff |
E_AGAIN,if | socket was in non-blocking mode and receive would block or a timeout was reached |
0 | if socket was gracefully closed |
Implements CAClientSocket.
Reimplemented in CATLSClientSocket.
Definition at line 645 of file CASocket.cpp.
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().
Trys to receive all bytes.
If after the timeout value has elapsed, not all bytes are received the error E_TIMEDOUT is returned.
buff | byte array, where the received bytes would be stored |
len | on input holds the number of bytes which should be read, |
msTimeOut | the timout in milli seconds |
E_TIMEDOUT | if not all byts could be read |
E_UNKNOWN | if an error occured |
E_SUCCESS | if all bytes could be read |
Definition at line 677 of file CASocket.cpp.
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().
Definition at line 714 of file CASocket.cpp.
References add64(), diff64(), E_TIMEDOUT, getcurrentTimeMillis(), isLesser64(), m_pSingleSocketGroupRead, receive(), CASocketGroup::select(), set64(), and SET_NET_ERROR.
Sends some data over the network.
This may block, if socket is in blocking mode.
buff | the buffer of data to send |
len | content length |
E_AGAIN | if non blocking socket would block or a timeout was reached |
E_UNKNOWN | if an error occured |
Reimplemented in CATLSClientSocket.
Definition at line 400 of file CASocket.cpp.
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().
Sends all data over the network.
This may block until all data is send.
buff | - the buffer of data to send |
len | - content length |
E_UNKNOWN,if | an error occured |
E_SUCCESS,if | successful |
Implements CAClientSocket.
Reimplemented in CATLSClientSocket.
Definition at line 587 of file CASocket.cpp.
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().
|
virtual |
Sends all data over the network.
This may block until all data is send.
buff | - the buffer of data to send |
len | - content length |
E_UNKNOWN,if | an error occured |
E_TIMEDOUT | if the timeout was reached |
E_SUCCESS,if | successful |
Definition at line 488 of file CASocket.cpp.
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().
Sends some data over the network.
Using a Timeout if socket is in blocking mode. Otherwise E_AGAIN may returned
buff | the buffer to send |
len | content length |
msTimeOut | Maximum MilliSeconds to wait |
E_AGAIN | if Operation would block on a non-blocking socket |
E_TIMEDOUT | if the timeout was reached |
Definition at line 442 of file CASocket.cpp.
References E_AGAIN, E_SUCCESS, getNonBlocking(), getSendTimeOut(), len, msSleep(), CAMsg::printMsg(), send(), setNonBlocking(), and setSendTimeOut().
Referenced by CALastMixA::loop(), and CALastMixB::loop().
|
virtual |
Enables/disables the socket keep-alive option.
b | true if option should be enabled, false otherwise |
Definition at line 906 of file CASocket.cpp.
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().
Enables the socket keep-alive option with a given ping time (in seconds).
sec | the time intervall(in seconds) of a keep-alive message |
Definition at line 924 of file CASocket.cpp.
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.
E_SUCCESS | if call was successful |
E_UNKNOWN | otherwise |
Definition at line 116 of file CASocket.hpp.
References E_SUCCESS, and m_u32MaxNormalSockets.
Referenced by main().
|
virtual |
Definition at line 947 of file CASocket.cpp.
References E_SUCCESS, flags, ioctlsocket, and m_Socket.
Referenced by connect(), CAFirstMix::doUserLogin_internal(), CAFirstMix::init(), CALastMix::init(), CALastMixA::loop(), CALastMixB::loop(), CAHttpClient::parseHTTPHeader(), sendTimeOut(), CAAccountingBIInterface::settle(), and CAAccountingBIInterface::settleAll().
Definition at line 846 of file CASocket.cpp.
References m_Socket.
Referenced by CAFirstMix::init(), CALastMix::init(), CALocalProxy::init(), CAMiddleMix::init(), CALastMixA::loop(), CALastMixB::loop(), CAInfoService::sendMixHelo(), and CACmdLnOptions::setTargetInterfaces().
|
virtual |
Definition at line 839 of file CASocket.cpp.
References m_Socket.
Referenced by CAMuxSocket::accept(), CACmdLnOptions::createSockets(), and CALocalProxy::init().
Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r)
Definition at line 862 of file CASocket.cpp.
References E_UNKNOWN, getSendBuff(), and m_Socket.
Referenced by CAFirstMix::init(), CALastMix::init(), CALocalProxy::init(), CAMiddleMix::init(), CALastMixA::loop(), CALastMixB::loop(), and CACmdLnOptions::setTargetInterfaces().
Definition at line 883 of file CASocket.cpp.
References m_Socket.
Referenced by sendFullyTimeOut(), and sendTimeOut().
Definition at line 57 of file CASocket.cpp.
References CASocketGroup::add(), E_SUCCESS, m_pSingleSocketGroupRead, and m_Socket.
Referenced by accept(), close(), and create().
|
private |
Definition at line 164 of file CASocket.hpp.
Referenced by CASocket(), close(), and create().
|
protected |
check
end check
Definition at line 145 of file CASocket.hpp.
Referenced by accept(), CASocket(), close(), connect(), create(), isClosed(), and listen().
|
staticprivate |
|
protected |
Definition at line 151 of file CASocket.hpp.
Referenced by CASocket(), receiveFullyT(), receiveLine(), and setSocket().
|
protected |
Definition at line 150 of file CASocket.hpp.
Referenced by accept(), CASocket(), close(), connect(), CATLSClientSocket::doTLSConnect(), getLocalIP(), getLocalPort(), getNonBlocking(), getPeerIP(), getPeerPort(), getRecvBuff(), getSendBuff(), getSendTimeOut(), getSocket(), listen(), peek(), receive(), send(), setKeepAlive(), setNonBlocking(), setRecvBuff(), setReuseAddr(), setSendBuff(), setSendTimeOut(), and setSocket().
|
staticprivate |
Definition at line 163 of file CASocket.hpp.
Referenced by accept(), create(), and setMaxNormalSockets().
|
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
Definition at line 162 of file CASocket.hpp.
Referenced by accept(), close(), countOpenSockets(), and create().