diff --git a/p2p/base/stun_request.cc b/p2p/base/stun_request.cc index 088cbc8a5c..afd276f225 100644 --- a/p2p/base/stun_request.cc +++ b/p2p/base/stun_request.cc @@ -19,6 +19,7 @@ #include "rtc_base/helpers.h" #include "rtc_base/logging.h" #include "rtc_base/time_utils.h" // For TimeMillis +#include "system_wrappers/include/field_trial.h" namespace cricket { @@ -34,6 +35,7 @@ const int STUN_INITIAL_RTO = 250; // milliseconds // RFC 5389 says SHOULD retransmit 7 times. // This has been 8 for years (not sure why). const int STUN_MAX_RETRANSMISSIONS = 8; // Total sends: 9 +const int STUN_MAX_RETRANSMISSIONS_RFC_5389 = 6; // Total sends: 7 // We also cap the doubling, even though the standard doesn't say to. // This has been 1.6 seconds for years, but for networks that @@ -41,6 +43,10 @@ const int STUN_MAX_RETRANSMISSIONS = 8; // Total sends: 9 // work well. const int STUN_MAX_RTO = 8000; // milliseconds, or 5 doublings +namespace { +const char kRfc5389StunRetransmissions[] = "WebRTC-Rfc5389StunRetransmissions"; +} // namespace + StunRequestManager::StunRequestManager(rtc::Thread* thread) : thread_(thread) {} StunRequestManager::~StunRequestManager() { @@ -169,12 +175,20 @@ StunRequest::StunRequest() timeout_(false), manager_(0), msg_(new StunMessage()), - tstamp_(0) { + tstamp_(0), + in_rfc5389_retransmission_experiment_( + webrtc::field_trial::IsEnabled(kRfc5389StunRetransmissions)) { msg_->SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); } StunRequest::StunRequest(StunMessage* request) - : count_(0), timeout_(false), manager_(0), msg_(request), tstamp_(0) { + : count_(0), + timeout_(false), + manager_(0), + msg_(request), + tstamp_(0), + in_rfc5389_retransmission_experiment_( + webrtc::field_trial::IsEnabled(kRfc5389StunRetransmissions)) { msg_->SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); } @@ -244,7 +258,9 @@ void StunRequest::OnMessage(rtc::Message* pmsg) { void StunRequest::OnSent() { count_ += 1; int retransmissions = (count_ - 1); - if (retransmissions >= STUN_MAX_RETRANSMISSIONS) { + if (retransmissions >= STUN_MAX_RETRANSMISSIONS || + (in_rfc5389_retransmission_experiment_ && + retransmissions >= STUN_MAX_RETRANSMISSIONS_RFC_5389)) { timeout_ = true; } RTC_LOG(LS_VERBOSE) << "Sent STUN request " << count_ diff --git a/p2p/base/stun_request.h b/p2p/base/stun_request.h index 7994fb6709..571abe1826 100644 --- a/p2p/base/stun_request.h +++ b/p2p/base/stun_request.h @@ -148,6 +148,7 @@ class StunRequest : public rtc::MessageHandler { StunRequestManager* manager_; StunMessage* msg_; int64_t tstamp_; + bool in_rfc5389_retransmission_experiment_; friend class StunRequestManager; };