131 ret = write(
_pipe[1], &ch, 1);
144 for (
int role = 0; role < 4; role++)
235 int countHandler = 0;
248 countListen += tsaListen.
set[i].
fValid ? 1 : 0;
249 countHandler += tsaHandler.
set[i].
fValid ? 1 : 0;
320 void* pRetValueFromThread = NULL;
330 ::pthread_join(
_pthread, &pRetValueFromThread);
441 if ((ppConn == NULL) || (*ppConn == NULL))
443 Logging::LogMsg(
LL_DEBUG,
"Warning - ProcessConnectionEvent could not resolve socket into connection (socket == %d)", sock);
490 sockaddr_storage addrClient;
491 socklen_t socklen =
sizeof(addrClient);
496 bool allowed_to_pass =
true;
501 socktmp = ::accept(listensock, (sockaddr*)&addrClient, &socklen);
513 clientsock = socktmp;
532 char szIPRemote[100];
563 bool allowed_to_pass =
true;
577 bytesread = recv(sock, buffer, bytesneeded, 0);
583 if ((bytesread < 0) && ((err == EWOULDBLOCK) || (err==EAGAIN)) )
650 uint8_t* pData = NULL;
651 size_t bytestotal, bytesremaining;
652 bool fForceClose =
false;
668 bytesremaining = bytestotal - pConn->
_txCount;
670 sent = ::send(sock, pData + pConn->
_txCount, bytesremaining, 0);
675 ChkIf( ((sent == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))),
S_OK);
705 if ((
FAILED(hr) || fForceClose))
755 time_t timeCurrent = time(NULL);
793 for (
size_t i = 0; i <
ARRAYSIZE(_threads); i++)
819 pTSA->
set[role].
addr = addrListen;
823 pTSA->
set[role].
addr = addrAdvertise;
835 boost::shared_ptr<RateLimiter> spLimiter;
869 for (
int threadindex = 0; threadindex < 4; threadindex++)
878 for (
int temp = 0; temp < 4; temp++)
880 if (temp != threadindex)
904 for (
int role = (
int)
RolePP; role <= (int)
RoleAA; role++)
907 delete _threads[role];
908 _threads[role] = NULL;
920 for (
int role = (
int)
RolePP; role <= (int)
RoleAA; role++)
const uint32_t MAX_STUN_MESSAGE_SIZE
bool IsValidSocketRole(SocketRole sr)
void CloseAllConnections(StunThreadConnectionMap *pConnMap)
void CloseConnection(StunConnection *pConn)
HRESULT NotifyThreadViaPipe()
virtual HRESULT WaitForNextEvent(PollEvent *pPollEvent, int timeoutMilliseconds)=0
const uint32_t IPOLLING_PRI
const uint32_t IPOLLING_RDHUP
virtual HRESULT ChangeEventSet(int fd, uint32_t eventflags)=0
static const int c_sweepTimeoutSeconds
HRESULT CreatePollingInstance(uint32_t type, size_t maxSockets, IPolling **ppPolling)
const uint32_t EPOLL_PIPE_EVENT_SET
void LogMsg(uint32_t level, const char *pszFormat,...)
StunThreadConnectionMap _hashConnections2
const uint32_t IPOLLING_TYPE_BEST
TransportAddressSet _tsaListen
const uint32_t IPOLLING_ERROR
void ProcessConnectionEvent(int sock, uint32_t eventflags)
bool _fListenSocketsOnEpoll
void SweepDeadConnections()
StunThreadConnectionMap * _pOldConnList
CStunMessageReader _reader
HRESULT WriteBytesForConnection(StunConnection *pConn)
CSocketAddress addrAlternateAdvertised
boost::shared_ptr< RateLimiter > _spLimiter
const uint32_t IPOLLING_WRITE
const uint32_t EPOLL_CLIENT_READ_EVENT_SET
int Insert(const K &key, V &value)
void CloseListenSockets()
HRESULT Initialize(const CStunServerConfig &config)
#define ERRNO_TO_HRESULT(err)
#define ChkIf(expr, hrerror)
ReaderParseState AddBytes(const uint8_t *pData, uint32_t size)
StunConnection * AcceptConnection(CStunSocket *pListenSocket)
void ReleaseConnection(StunConnection *pConn)
CStunSocket _socketListenArray[4]
CSocketAddress addrRemote
What local IP address the message was received on (useful if the socket binded to INADDR_ANY) ...
CSocketAddress addrLocal
which socket id did the message arrive on
virtual HRESULT Add(int fd, uint32_t eventflags)=0
Item * LookupByIndex(size_t index)
const uint32_t IPOLLING_READ
int GetSocketHandle() const
StunThreadConnectionMap * _pNewConnList
virtual HRESULT Remove(int fd)=0
const int c_MaxNumberOfConnectionsDefault
ReaderParseState GetState()
static void * ThreadFunction(void *pThis)
SocketRole GetRole() const
StunThreadConnectionMap _hashConnections1
FastHashBase< int, StunConnection * >::Item Item
CRefCountedBuffer _spOutputBuffer
HRESULT SetListenSocketsOnEpoll(bool fEnable)
HRESULT ReceiveBytesForConnection(StunConnection *pConn)
CStunSocket * GetListenSocket(int sock)
HRESULT CreateListenSockets()
HRESULT ToStringBuffer(char *pszAddrBytes, size_t length) const
bool IsConnectionCountAtMax()
CStunMessageReader * pReader
the address of the node that sent us the message
int InitTable(size_t fsize, size_t tsize)
static HRESULT ProcessRequest(const StunMessageIn &msgIn, StunMessageOut &msgOut, TransportAddressSet *pAddressSet, IStunAuth *pAuth)
HRESULT Init(const TransportAddressSet &tsaListen, const TransportAddressSet &tsaHandler, IStunAuth *pAuth, int maxConnections, boost::shared_ptr< RateLimiter > &spLimiter)
const CSocketAddress & GetRemoteAddress() const
CRefCountedPtr< IPolling > _spPolling
const uint32_t LL_VERBOSE
const uint32_t IPOLLING_HUP
CSocketAddress addrPrimaryAdvertised
CConnectionPool _connectionpool
bool fEnableDosProtection
StunConnection * GetConnection(int sock, SocketRole role)
const uint32_t EPOLL_CLIENT_WRITE_EVENT_SET
CRefCountedBuffer spBufferOut
HRESULT SetNonBlocking(bool fEnable)
CRefCountedPtr< IStunAuth > _spAuth
bool RateCheck(const CSocketAddress &addr)
void ResetConnection(StunConnection *pConn)
bool IsIPAddressZero() const
uint16_t HowManyBytesNeeded()
void InitTSA(TransportAddressSet *pTSA, SocketRole role, bool fValid, const CSocketAddress &addrListen, const CSocketAddress &addrAdvertise)
#define ChkIfA(expr, hrerror)
bool fConnectionOriented
reader containing a valid stun message
const CSocketAddress & GetLocalAddress() const
const uint32_t EPOLL_LISTEN_SOCKET_EVENT_SET
StunConnectionState _state