Mixes for Privacy and Anonymity in the Internet
|
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 |
CASocket::CASocket | ( | bool | bIsReserved = false | ) |
References m_bIsReservedSocket, m_bSocketIsClosed, m_pSingleSocketGroupRead, and m_Socket.
CASocket::~CASocket | ( | ) |
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 |
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().
|
static |
References E_SUCCESS, and m_pcsClose.
Referenced by CALibProxytest::cleanup().
|
virtual |
Reimplemented in CATLSClientSocket.
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().
|
virtual |
|
virtual |
Tries to connect to peer psa.
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().
|
virtual |
Tries to connect to the peer described by psa.
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().
|
static |
References m_u32NormalSocketsOpen.
|
virtual |
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 |
References E_SUCCESS, m_Socket, and SOCKET_ERROR.
Referenced by CALastMixA::loop().
|
virtual |
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 |
|
virtual |
References E_SUCCESS, flags, m_Socket, and SOCKET_ERROR.
Referenced by connect(), CAHttpClient::parseHTTPHeader(), sendFullyTimeOut(), and sendTimeOut().
References E_SUCCESS, m_Socket, and SOCKET_ERROR.
Referenced by isAllowedToPassRestrictions().
|
virtual |
References m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMixChannelList::add().
|
virtual |
References E_UNKNOWN, m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMix::init().
|
virtual |
References E_UNKNOWN, m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMix::init(), and setSendBuff().
|
virtual |
References E_UNKNOWN, m_Socket, and SOCKET_ERROR.
Referenced by sendFullyTimeOut(), and sendTimeOut().
|
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()
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().
|
static |
References E_SUCCESS, and m_pcsClose.
Referenced by CALibProxytest::init().
|
virtual |
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 |
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().
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 |
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.
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 |
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().
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.
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.
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 |
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 |
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 |
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 |
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 |
References E_SUCCESS, and m_u32MaxNormalSockets.
Referenced by main().
|
virtual |
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().
References m_Socket.
Referenced by CAFirstMix::init(), CALastMix::init(), CALocalProxy::init(), CAMiddleMix::init(), CALastMixA::loop(), CALastMixB::loop(), CAInfoService::sendMixHelo(), and CACmdLnOptions::setTargetInterfaces().
|
virtual |
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)
References E_UNKNOWN, getSendBuff(), and m_Socket.
Referenced by CAFirstMix::init(), CALastMix::init(), CALocalProxy::init(), CAMiddleMix::init(), CALastMixA::loop(), CALastMixB::loop(), and CACmdLnOptions::setTargetInterfaces().
References m_Socket.
Referenced by sendFullyTimeOut(), and sendTimeOut().
References CASocketGroup::add(), E_SUCCESS, m_pSingleSocketGroupRead, and m_Socket.
|
private |
Referenced by CASocket(), close(), and create().
|
protected |
check
end check
Referenced by accept(), CASocket(), close(), connect(), create(), isClosed(), and listen().
|
staticprivate |
|
protected |
Referenced by CASocket(), receiveFullyT(), receiveLine(), and setSocket().
|
protected |
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 |
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
Referenced by accept(), close(), countOpenSockets(), and create().