53 unsigned short port = 0);
76 void connect(
const std::string& address,
unsigned short port);
101 virtual void send(
const char* buffer,
size_t size);
102 virtual void sendTo(
const asio::ip::address& address,
unsigned short port,
const char* buffer,
size_t size);
104 virtual void sendUnframed(
const std::shared_ptr<DataBuffer>& data);
105 virtual void sendFramed(
const std::shared_ptr<DataBuffer>& data);
106 virtual void sendToUnframed(
const asio::ip::address& address,
unsigned short port,
const std::shared_ptr<DataBuffer>& data);
107 virtual void sendToFramed(
const asio::ip::address& address,
unsigned short port,
const std::shared_ptr<DataBuffer>& data);
113 virtual void close();
121 void handleReceivedData(
const asio::ip::address& address,
unsigned short port,
const std::shared_ptr<DataBuffer>& data);
157 bool mCloseAfterDestroyAllocationFinishes;
160 class RequestEntry :
public std::enable_shared_from_this<RequestEntry>
168 void requestTimerExpired(
const asio::error_code&
e);
170 asio::io_context& mIOService;
173 asio::steady_timer mRequestTimer;
174 unsigned int mRequestsSent;
175 unsigned int mTimeout;
177 const unsigned int mRc;
178 const unsigned int mRetransIntervalMs;
180 typedef std::map<UInt128, std::shared_ptr<RequestEntry>> RequestMap;
181 RequestMap mActiveRequestMap;
183 void requestTimeout(
UInt128 tid);
184 void clearActiveRequestMap();
189 template <
typename P,
typename F >
class weak_bind
196 weak_bind(std::weak_ptr<P> parent, std::function<F>
func)
197 : mParent(std::
move(parent)), mFunction(std::
move(
func))
203 if (std::shared_ptr<P> ptr = mParent.lock())
210 void operator()(
const asio::error_code&
e)
212 if (std::shared_ptr<P> ptr = mParent.lock())
220 std::weak_ptr<P> mParent;
221 std::function<F> mFunction;
224 asio::steady_timer mAllocationTimer;
225 void startAllocationTimer();
226 void cancelAllocationTimer();
227 void allocationTimerExpired(
const asio::error_code&
e);
229 typedef std::map<unsigned short, asio::steady_timer*> ChannelBindingTimerMap;
230 ChannelBindingTimerMap mChannelBindingTimers;
231 void startChannelBindingTimer(
unsigned short channel);
232 void cancelChannelBindingTimers();
233 void channelBindingTimerExpired(
const asio::error_code&
e,
unsigned short channel);
235 void doRequestSharedSecret();
239 void doBindRequest();
246 void doRefreshAllocation(
unsigned int lifetime);
247 void doDestroyAllocation();
248 void doSetActiveDestination(
const asio::ip::address& address,
unsigned short port);
249 void doClearActiveDestination();
250 void doSendFramed(
const std::shared_ptr<DataBuffer>& data);
251 void doSendToFramed(
const asio::ip::address& address,
unsigned short port,
const std::shared_ptr<DataBuffer>& data);
254 void doChannelBinding(RemotePeer&
remotePeer);
258 void sendToRemotePeer(RemotePeer&
remotePeer,
const std::shared_ptr<DataBuffer>& data);
259 void sendOverChannel(
unsigned short channel,
const std::shared_ptr<DataBuffer>& data);
261 asio::error_code handleStunMessage(StunMessage&
stunMessage);
262 asio::error_code handleDataInd(StunMessage&
stunMessage);
263 asio::error_code handleChannelBindResponse(StunMessage &
request, StunMessage &
response);
264 asio::error_code handleSharedSecretResponse(StunMessage &
request, StunMessage &
response);
265 asio::error_code handleBindRequest(StunMessage&
stunMessage);
266 asio::error_code handleBindResponse(StunMessage &
request, StunMessage &
response);
267 asio::error_code handleAllocateResponse(StunMessage &
request, StunMessage &
response);
268 asio::error_code handleRefreshResponse(StunMessage &
request, StunMessage &
response);
void connectivityCheck(const StunTuple &targetAddr, uint32_t peerRflxPriority, bool setIceControlling, bool setIceControlled, unsigned int numRetransmits, unsigned int retrans_iterval_ms)
void createAllocation(unsigned int lifetimeSecs=UnspecifiedLifetime, unsigned int bandwidth=UnspecifiedBandwidth, unsigned char requestedPortProps=StunMessage::PropsNone, uint64_t reservationToken=UnspecifiedToken, StunTuple::TransportType requestedTransportType=StunTuple::None)