10#include "../TurnSocket.hxx"
14#ifdef BOOST_ASIO_HAS_STD_CHRONO
15using namespace std::chrono;
18using namespace std::chrono;
25#define RESIPROCATE_SUBSYSTEM resip::Subsystem::TEST
27#define LOG_PREFIX << "[" << mClientNum << "] "
33 asio::io_context& ioService,
34 const Data& localAddress,
35 const Data& turnServerAddress,
36 unsigned short turnServerPort,
37 unsigned short relayPort,
39 mClientNum(clientNum),
41 mLocalAddress(
asio::ip::make_address(localAddress.c_str())),
42 mTurnServerAddress(turnServerAddress),
43 mTurnServerPort(turnServerPort),
44 mRelayPort(relayPort),
48 mNumReceiveSuccesses(0),
49 mNumReceiveFailures(0),
50 mDelayBetweenClientStartsMs(config.getConfigInt(
"DelayBetweenClientStartsMs", 2000)),
51 mAllocationTimeSecs(config.getConfigInt(
"AllocationTimeSecs", 60)),
52 mAllocationLifetimeSecs(config.getConfigInt(
"AllocationLifetimeSecs",
TurnSocket::UnspecifiedLifetime)),
53 mTimeBetweenAllocationsSecs(config.getConfigInt(
"TimeBetweenAllocationsSecs", 2)),
54 mPayloadIntervalMs(config.getConfigInt(
"PayloadIntervalMs", 20))
63 mTurnAsyncSocket->close();
69 mTurnAsyncSocket = turnAsyncSocket;
72 if (mDelayBetweenClientStartsMs > 0)
74 mTimer.expires_after(milliseconds(mDelayBetweenClientStartsMs * (mClientNum-1)));
87 mTurnAsyncSocket->connect(mTurnServerAddress.
c_str(), mTurnServerPort);
92 mTurnAsyncSocket->bindRequest();
99 mNumReceiveSuccesses = 0;
100 mNumReceiveFailures = 0;
102 mTurnAsyncSocket->createAllocation(mAllocationLifetimeSecs,
112 mStartTime = time(0);
118 time_t secondsElapsed = time(0) - mStartTime;
119 if (secondsElapsed < mAllocationTimeSecs)
121 mTimer.expires_after(milliseconds(mPayloadIntervalMs));
128 DebugLog(
LOG_PREFIX <<
"Configured AllocationTimeSecs has expired, configured=" << mAllocationTimeSecs <<
", secondsElapsed=" << secondsElapsed <<
" destroying allocation.");
129 mTurnAsyncSocket->destroyAllocation();
135 DebugLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onConnectSuccess: socketDest=" << socketDesc <<
", address=" << address.to_string() <<
", turnPort=" << port);
149 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onConnectFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
154 InfoLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onSharedSecretSuccess: socketDest=" << socketDesc <<
", username=" << username <<
", password=" << password);
159 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onSharedSecretFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
164 InfoLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onBindingSuccess: socketDest=" << socketDesc <<
", reflexive=" << reflexiveTuple <<
", stunServerTuple=" << stunServerTuple);
170 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onBindingFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
"), stunServerTuple=" << stunServerTuple);
175 DebugLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onAllocationSuccess: socketDest=" << socketDesc <<
176 ", reflexive=" << reflexiveTuple <<
177 ", relay=" << relayTuple <<
178 ", lifetimeSecs=" << lifetimeSecs <<
179 ", bandwidth=" << bandwidth <<
180 ", reservationToken=" << reservationToken);
182 DebugLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onAllocationSuccess: setting active destination to " << mLocalAddress <<
":" << mRelayPort);
183 mTurnAsyncSocket->setActiveDestination(mLocalAddress, mRelayPort);
188 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onAllocationFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
191 mTimer.expires_after(seconds(mTimeBetweenAllocationsSecs));
197 DebugLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onRefreshSuccess: socketDest=" << socketDesc <<
", lifetimeSecs=" << lifetimeSecs);
198 if (lifetimeSecs == 0)
200 InfoLog(
LOG_PREFIX <<
"Allocation was up for " << (time(0) - mStartTime) <<
" seconds, numSends=" << mNumSends <<
201 ", numReceiveSuccesses=" << mNumReceiveSuccesses <<
202 ", numSendFailures=" << mNumSendFailures <<
203 ", numReceiveFailures=" << mNumReceiveFailures <<
204 ", creating new allocation in " << mTimeBetweenAllocationsSecs <<
" secs.");
206 mTimer.expires_after(seconds(mTimeBetweenAllocationsSecs));
213 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onRefreshFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
216 mTimer.expires_after(seconds(mTimeBetweenAllocationsSecs));
222 DebugLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onSetActiveDestinationSuccess: socketDest=" << socketDesc);
228 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onSetActiveDestinationFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
233 InfoLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onClearActiveDestinationSuccess: socketDest=" << socketDesc);
238 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onClearActiveDestinationFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
243 DebugLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onChannelBindRequestSent: socketDest=" << socketDesc <<
" channelNumber=" << channelNumber);
248 DebugLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onChannelBindSuccess: socketDest=" << socketDesc <<
" channelNumber=" << channelNumber);
253 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onChannelBindFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
263 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onSendFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
270 ++mNumReceiveSuccesses;
275 ErrLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onReceiveFailure: socketDest=" << socketDesc <<
" error=" << e.value() <<
"(" << e.message() <<
").");
276 ++mNumReceiveFailures;
281 InfoLog(
LOG_PREFIX <<
"MyTurnAsyncSocketHandler::onIncomingBindRequestProcessed: socketDest=" << socketDesc <<
" sourceTuple=" << sourceTuple);
void sendAllocationRequest()
virtual void onSharedSecretSuccess(unsigned int socketDesc, const char *username, unsigned int usernameSize, const char *password, unsigned int passwordSize) override
virtual void onChannelBindRequestSent(unsigned int socketDesc, unsigned short channelNumber) override
virtual void onConnectSuccess(unsigned int socketDesc, const asio::ip::address &address, unsigned short port) override
virtual void onReceiveSuccess(unsigned int socketDesc, const asio::ip::address &address, unsigned short port, const std::shared_ptr< reTurn::DataBuffer > &data) override
virtual void onRefreshSuccess(unsigned int socketDesc, unsigned int lifetime) override
virtual void onAllocationSuccess(unsigned int socketDesc, const StunTuple &reflexiveTuple, const StunTuple &relayTuple, unsigned int lifetime, unsigned int bandwidth, uint64_t reservationToken) override
virtual void onSendFailure(unsigned int socketDesc, const asio::error_code &e) override
void startSendingPayload()
virtual void onSetActiveDestinationFailure(unsigned int socketDesc, const asio::error_code &e) override
virtual void onChannelBindSuccess(unsigned int socketDesc, unsigned short channelNumber) override
virtual void onChannelBindFailure(unsigned int socketDesc, const asio::error_code &e) override
virtual void onAllocationFailure(unsigned int socketDesc, const asio::error_code &e) override
virtual void onRefreshFailure(unsigned int socketDesc, const asio::error_code &e) override
virtual void onIncomingBindRequestProcessed(unsigned int socketDesc, const StunTuple &sourceTuple) override
virtual void onSendSuccess(unsigned int socketDesc) override
virtual void onReceiveFailure(unsigned int socketDesc, const asio::error_code &e) override
virtual void onClearActiveDestinationSuccess(unsigned int socketDesc) override
void setTurnAsyncSocket(std::shared_ptr< TurnAsyncSocket > &turnAsyncSocket)
TurnLoadGenAsyncSocketHandler(int clientNum, asio::io_context &ioService, const Data &localAddress, const Data &turnServerAddress, unsigned short turnServerPort, unsigned short relayPort, const ConfigParse &config)
virtual void onClearActiveDestinationFailure(unsigned int socketDesc, const asio::error_code &e) override
virtual void onBindFailure(unsigned int socketDesc, const asio::error_code &e, const StunTuple &stunServerTuple) override
virtual void onBindSuccess(unsigned int socketDesc, const StunTuple &reflexiveTuple, const StunTuple &stunServerTuple) override
virtual void onSetActiveDestinationSuccess(unsigned int socketDesc) override
virtual void onConnectFailure(unsigned int socketDesc, const asio::error_code &e) override
virtual void onSharedSecretFailure(unsigned int socketDesc, const asio::error_code &e) override
virtual ~TurnLoadGenAsyncSocketHandler()
static const uint8_t PropsPortPair
static unsigned short UnspecifiedToken
static unsigned int UnspecifiedBandwidth
bool getConfigBool(const resip::Data &name, bool defaultValue) const
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * c_str() const
Returns a null-terminated string representing.
size_type size() const noexcept
Returns the number of bytes in this Data.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
dcm! – add UnusedChecking(_enum) below;
unsigned long long uint64_t