|
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 (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 |
| CASocket::CASocket | ( | bool | bIsReserved = false | ) |
References m_bIsReservedSocket, m_bSocketIsClosed, and m_Socket.
References close().
| SINT32 CASocket::accept | ( | CASocket & | s | ) | [virtual] |
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_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] |
Reimplemented in CATLSClientSocket.
References closesocket, E_SUCCESS, GET_NET_ERROR, CAMutex::lock(), m_bIsReservedSocket, m_bSocketIsClosed, m_csClose, m_Socket, m_u32NormalSocketsOpen, CAMsg::printMsg(), and CAMutex::unlock().
Referenced by CAMuxSocket::accept(), CALocalProxy::clean(), CALastMix::clean(), CAFirstMix::clean(), CAMuxSocket::close(), CAChain::closeChainInternal(), connect(), getMaxOpenSockets(), CAInfoService::getPaymentInstance(), listen(), CALastMixA::loop(), CALastMixB::loop(), CALocalProxy::loop(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), CACmdLnOptions::setListenerInterfaces(), CACmdLnOptions::setTargetInterfaces(), CAChain::~CAChain(), and ~CASocket().
| 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.
| 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.
| 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] |
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_csClose, m_Socket, m_u32MaxNormalSockets, m_u32NormalSocketsOpen, CAMsg::printMsg(), and CAMutex::unlock().
| SINT32 CASocket::getLocalIP | ( | UINT8 | r_Ip[4] | ) | [virtual] |
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().
| SINT32 CASocket::getLocalPort | ( | ) | [virtual] |
References m_Socket, and SOCKET_ERROR.
Referenced by CALastMixA::loop(), and CALocalProxy::loop().
| 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.
| max | numbers of sockets we can have open at the same time |
| E_UNKNOWN | in case of some unexpected error |
References close(), create(), and E_SUCCESS.
Referenced by main().
| SINT32 CASocket::getNonBlocking | ( | bool * | b | ) | [virtual] |
References E_SUCCESS, flags, m_Socket, and SOCKET_ERROR.
Referenced by connect(), CAHttpClient::parseHTTPHeader(), sendFullyTimeOut(), and sendTimeOut().
| SINT32 CASocket::getPeerIP | ( | UINT8 | ip[4] | ) | [virtual] |
References E_SUCCESS, m_Socket, and SOCKET_ERROR.
Referenced by fm_loopAcceptUsers(), and isAllowedToPassRestrictions().
| SINT32 CASocket::getPeerPort | ( | ) | [virtual] |
References m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMixChannelList::add().
| SINT32 CASocket::getRecvBuff | ( | ) | [virtual] |
References E_UNKNOWN, m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMix::init().
| SINT32 CASocket::getSendBuff | ( | ) | [virtual] |
References E_UNKNOWN, m_Socket, and SOCKET_ERROR.
Referenced by CAFirstMix::init(), and setSendBuff().
| SINT32 CASocket::getSendTimeOut | ( | ) | [virtual] |
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()
References m_Socket.
Referenced by CASocketGroupEpoll::add(), CASocketGroup::add(), CAMuxSocket::getSocket(), CASocketGroup::isSignaled(), CASocketGroup::remove(), and CASingleSocketGroup::select_once().
| virtual bool CASocket::isClosed | ( | ) | [virtual] |
References m_bSocketIsClosed.
Referenced by CAFirstMix::doUserLogin_internal(), and CAMuxSocket::receive().
| SINT32 CASocket::listen | ( | const CASocketAddr & | psa | ) | [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 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!
| 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, 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.
| 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 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] |
References CASocketGroup::add(), add64(), diff64(), E_TIMEDOUT, getcurrentTimeMillis(), isLesser64(), receive(), CASocketGroup::select(), set64(), and SET_NET_ERROR.
| SINT32 CASocket::send | ( | const UINT8 * | buff, |
| UINT32 | len | ||
| ) | [virtual] |
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, 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.
| 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 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.
| 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 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
| 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(), 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.
| 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(), 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).
| 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.
| static SINT32 CASocket::setMaxNormalSockets | ( | UINT32 | u | ) | [static] |
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().
| SINT32 CASocket::setNonBlocking | ( | bool | b | ) | [virtual] |
| SINT32 CASocket::setRecvBuff | ( | UINT32 | r | ) | [virtual] |
References m_Socket.
Referenced by CALocalProxy::init(), CAMiddleMix::init(), CALastMix::init(), CAFirstMix::init(), CALastMixA::loop(), CALastMixB::loop(), CAInfoService::sendMixHelo(), and CACmdLnOptions::setTargetInterfaces().
| SINT32 CASocket::setReuseAddr | ( | bool | b | ) | [virtual] |
References m_Socket.
Referenced by CAMuxSocket::accept(), CACmdLnOptions::createSockets(), and CALocalProxy::init().
| 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 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().
bool CASocket::m_bIsReservedSocket [private] |
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().
CAMutex CASocket::m_csClose [private] |
SOCKET CASocket::m_Socket [protected] |
Referenced by accept(), CASocket(), close(), connect(), create(), CATLSClientSocket::doTLSConnect(), getLocalIP(), getLocalPort(), getNonBlocking(), getPeerIP(), getPeerPort(), getRecvBuff(), getSendBuff(), getSendTimeOut(), getSocket(), listen(), receive(), send(), setKeepAlive(), setNonBlocking(), setRecvBuff(), setReuseAddr(), setSendBuff(), and setSendTimeOut().
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().
1.7.6.1