Handle lifetime short than 2 minutes for TURN allocations

This patch modifies behaviour when TurnPort gets a lifetime
back from server that is shorter than 2 minutes.

Before the patch such lifetime resulted in TurnPort not scheduling any
refresh, leading to timeout on the turn allocation.

After then patch lifetime shorter then 2 minutes leads to refresh
after half stipulated lifetime.

BUG=webrtc:8826

Change-Id: I80561100f2307bd9a6a91af0924bb2814102ddd3
Reviewed-on: https://webrtc-review.googlesource.com/46741
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21891}
This commit is contained in:
Jonas Oreland
2018-02-05 10:41:41 +01:00
committed by Commit Bot
parent f105325a55
commit 19651c3ef2
2 changed files with 24 additions and 7 deletions

View File

@ -976,15 +976,32 @@ void TurnPort::DispatchPacket(const char* data, size_t size,
}
}
bool TurnPort::ScheduleRefresh(int lifetime) {
// Lifetime is in seconds; we schedule a refresh for one minute less.
bool TurnPort::ScheduleRefresh(uint32_t lifetime) {
// Lifetime is in seconds, delay is in milliseconds.
int delay = 1 * 60 * 1000;
// Cutoff lifetime bigger than 1h.
constexpr uint32_t max_lifetime = 60 * 60;
if (lifetime < 2 * 60) {
LOG_J(LS_WARNING, this) << "Received response with lifetime that was "
<< "too short, lifetime=" << lifetime;
return false;
// The RFC does not mention a lower limit on lifetime.
// So if server sends a value less than 2 minutes, we schedule a refresh
// for half lifetime.
LOG_J(LS_WARNING, this) << "Received response with short lifetime="
<< lifetime << " seconds.";
delay = (lifetime * 1000) / 2;
} else if (lifetime > max_lifetime) {
// Make 1 hour largest delay, and then sce
// we schedule a refresh for one minute less than max lifetime.
LOG_J(LS_WARNING, this) << "Received response with long lifetime="
<< lifetime << " seconds.";
delay = (max_lifetime - 60) * 1000;
} else {
// Normal case,
// we schedule a refresh for one minute less than requested lifetime.
delay = (lifetime - 60) * 1000;
}
int delay = (lifetime - 60) * 1000;
SendRequest(new TurnRefreshRequest(this), delay);
LOG_J(LS_INFO, this) << "Scheduled refresh in " << delay << "ms.";
return true;

View File

@ -260,7 +260,7 @@ class TurnPort : public Port {
const rtc::SocketAddress& remote_addr,
ProtocolType proto, const rtc::PacketTime& packet_time);
bool ScheduleRefresh(int lifetime);
bool ScheduleRefresh(uint32_t lifetime);
void SendRequest(StunRequest* request, int delay);
int Send(const void* data, size_t size,
const rtc::PacketOptions& options);