Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Unified Diff: webrtc/p2p/base/stunport.cc

Issue 1465843004: Stop sending stun binding requests after certain amount of time. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/stunport.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/stunport.cc
diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc
index 13ecca4a3a1cb90b2640e45ebee708d47cc2bf37..f079c117aa79f92caa68a57d80c73c02481757c0 100644
--- a/webrtc/p2p/base/stunport.cc
+++ b/webrtc/p2p/base/stunport.cc
@@ -24,15 +24,20 @@ namespace cricket {
// TODO: Move these to a common place (used in relayport too)
const int KEEPALIVE_DELAY = 10 * 1000; // 10 seconds - sort timeouts
-const int RETRY_DELAY = 50; // 50ms, from ICE spec
const int RETRY_TIMEOUT = 50 * 1000; // ICE says 50 secs
+// Stop sending STUN binding request after this amount of time (in milliseconds)
pthatcher1 2015/12/03 21:00:19 request => requests
honghaiz3 2015/12/03 22:21:21 Done.
+// because the connection binding requests should keep the NAT binding alive.
+const int KEEP_ALIVE_DEADLINE = 120 * 1000;
pthatcher1 2015/12/03 21:00:19 2 * 60 * 1000; // 2 minutes Might be more clear
honghaiz3 2015/12/03 22:21:21 Done.
// Handles a binding request sent to the STUN server.
class StunBindingRequest : public StunRequest {
public:
- StunBindingRequest(UDPPort* port, bool keep_alive,
+ StunBindingRequest(UDPPort* port,
+ int keep_alive_deadline,
const rtc::SocketAddress& addr)
- : port_(port), keep_alive_(keep_alive), server_addr_(addr) {
+ : port_(port),
+ keep_alive_deadline_(keep_alive_deadline),
+ server_addr_(addr) {
start_time_ = rtc::Time();
}
@@ -60,7 +65,7 @@ class StunBindingRequest : public StunRequest {
// We will do a keep-alive regardless of whether this request succeeds.
// This should have almost no impact on network usage.
- if (keep_alive_) {
+ if (rtc::TimeSince(port_->start_time()) <= keep_alive_deadline_) {
pthatcher1 2015/12/03 21:00:19 I was thinking that "deadline" would be more an ab
honghaiz3 2015/12/03 22:21:21 Done.
port_->requests_.SendDelayed(
new StunBindingRequest(port_, true, server_addr_),
port_->stun_keepalive_delay());
@@ -80,8 +85,8 @@ class StunBindingRequest : public StunRequest {
port_->OnStunBindingOrResolveRequestFailed(server_addr_);
- if (keep_alive_
- && (rtc::TimeSince(start_time_) <= RETRY_TIMEOUT)) {
+ if (rtc::TimeSince(port_->start_time()) <= keep_alive_deadline_ &&
+ rtc::TimeSince(start_time_) <= RETRY_TIMEOUT) {
port_->requests_.SendDelayed(
new StunBindingRequest(port_, true, server_addr_),
port_->stun_keepalive_delay());
@@ -94,18 +99,11 @@ class StunBindingRequest : public StunRequest {
<< " (" << port_->Network()->name() << ")";
port_->OnStunBindingOrResolveRequestFailed(server_addr_);
-
- if (keep_alive_
- && (rtc::TimeSince(start_time_) <= RETRY_TIMEOUT)) {
- port_->requests_.SendDelayed(
- new StunBindingRequest(port_, true, server_addr_),
- RETRY_DELAY);
- }
}
private:
UDPPort* port_;
- bool keep_alive_;
+ int keep_alive_deadline_;
const rtc::SocketAddress server_addr_;
uint32_t start_time_;
};
@@ -182,6 +180,7 @@ UDPPort::UDPPort(rtc::Thread* thread,
error_(0),
ready_(false),
stun_keepalive_delay_(KEEPALIVE_DELAY),
+ start_time_(rtc::Time()),
emit_local_for_anyaddress_(emit_local_for_anyaddress) {
requests_.set_origin(origin);
}
@@ -210,6 +209,7 @@ UDPPort::UDPPort(rtc::Thread* thread,
error_(0),
ready_(false),
stun_keepalive_delay_(KEEPALIVE_DELAY),
+ start_time_(rtc::Time()),
emit_local_for_anyaddress_(emit_local_for_anyaddress) {
requests_.set_origin(origin);
}
@@ -397,7 +397,8 @@ void UDPPort::SendStunBindingRequest(const rtc::SocketAddress& stun_addr) {
} else if (socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND) {
// Check if |server_addr_| is compatible with the port's ip.
if (IsCompatibleAddress(stun_addr)) {
- requests_.Send(new StunBindingRequest(this, true, stun_addr));
+ requests_.Send(
+ new StunBindingRequest(this, KEEP_ALIVE_DEADLINE, stun_addr));
} else {
// Since we can't send stun messages to the server, we should mark this
// port ready.
« no previous file with comments | « webrtc/p2p/base/stunport.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698