Chromium Code Reviews| 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. |