8#define RESIPROCATE_SUBSYSTEM ReTurnSubsystem::RETURN
15TcpConnection::TcpConnection(asio::io_context& ioService,
18 mConnectionManager(manager),
19 mRequestHandler(handler)
25 DebugLog(<<
"TcpConnection destroyed.");
37 DebugLog(<<
"TcpConnection started.");
78 if(((*data)[0] & 0xC0) == 0)
83 (
char*)&(*data)[0], (
unsigned int)data->size());
105 constexpr size_t RESPONSE_BUFFER_SIZE = 1024;
107 unsigned int responseSize;
108 responseSize = response.
stunEncodeMessage((
char*)buffer->data(), RESPONSE_BUFFER_SIZE);
109 buffer->truncate(responseSize);
115 WarningLog(<<
"Received invalid StunMessage. Dropping.");
120 unsigned short channelNumber;
121 memcpy(&channelNumber, &(*data)[0], 2);
122 channelNumber = ntohs(channelNumber);
133 WarningLog(<<
"Not enough data for stun message or framed message. Closing connection.");
144 if(e != asio::error::operation_aborted)
146 InfoLog(<<
"TcpConnection::onReceiveFailure: " << e.value() <<
"-" << e.message());
159 if(error != asio::error::operation_aborted)
161 InfoLog(<<
"TcpConnection::onSendFailure: " << error.value() <<
"-" << error.message());
#define WarningLog(args_)
#define resip_assert(x)
This file needs to work for both C and C++ code.
virtual void doFramedReceive()
static std::shared_ptr< DataBuffer > allocateBuffer(size_t size)
Utility API.
virtual void doSend(const StunTuple &destination, unsigned short channel, const std::shared_ptr< DataBuffer > &data, const std::size_t bufferStartPos=0)
Use these if you already operating within the ioService thread.
void startIdleTimer(unsigned int timeoutSeconds, std::function< bool()> inUse)
For server connections (TcpConnectionIdleTimeout): the connection is closed, with close(),...
virtual void setConnectedAddressAndPort()
asio::ip::tcp::socket mSocket
Manages open connections so that they may be cleanly stopped when the server needs to shut down,...
void stop(ConnectionPtr c)
Stop the specified connection.
unsigned long mTcpConnectionIdleTimeout
The common handler for all incoming requests.
void processTurnData(TurnAllocationManager &turnAllocationManager, unsigned short channelNumber, const StunTuple &localTuple, const StunTuple &remoteTuple, const std::shared_ptr< DataBuffer > &data)
const ReTurnConfig & getConfig()
ProcessResult processStunMessage(AsyncSocketBase *turnSocket, TurnAllocationManager &turnAllocationManager, StunMessage &request, StunMessage &response, bool isRFC3489BackwardsCompatServer=false)
Process a received StunMessage, and produce a reply Returns true if the response message is to be sen...
@ RespondFromAlternateIpPort
@ RespondFromAlternatePort
unsigned int stunEncodeMessage(char *buf, unsigned int bufLen)
virtual void stop()
Stop all asynchronous operations associated with the connection.
RequestHandler & mRequestHandler
The handler used to process the incoming request.
virtual void onSendFailure(const asio::error_code &e)
asio::ip::tcp::socket & socket()
Get the socket associated with the connection.
virtual void close()
Override close fn in AsyncTcpSocketBase so that we can remove ourselves from connection manager.
asio::ip::address mLocalAddress
virtual void onReceiveSuccess(const asio::ip::address &address, unsigned short port, const std::shared_ptr< DataBuffer > &data)
Handle completion of a receive operation.
unsigned short mLocalPort
virtual void start()
Start the first asynchronous operation for the connection.
virtual void onReceiveFailure(const asio::error_code &e)
virtual void onSendSuccess()
Handle completion of a send operation.
TurnAllocationManager mTurnAllocationManager
Manages turn allocations.
ConnectionManager & mConnectionManager
The connection manager for this connection.
dcm! – add UnusedChecking(_enum) below;