Add field trial to reduce max STUN check retransmissions from 8 to 6 in accordance with RFC 5389.

Bug: webrtc:10282
Change-Id: I19ac690e3388e2015792695cf7836cb727a4314b
Reviewed-on: https://webrtc-review.googlesource.com/c/120960
Reviewed-by: Christoffer Rodbro <crodbro@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26524}
This commit is contained in:
Bjorn Terelius
2019-02-01 15:22:20 +01:00
committed by Commit Bot
parent 0237106559
commit 0d28972d8f
2 changed files with 20 additions and 3 deletions

View File

@ -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_

View File

@ -148,6 +148,7 @@ class StunRequest : public rtc::MessageHandler {
StunRequestManager* manager_;
StunMessage* msg_;
int64_t tstamp_;
bool in_rfc5389_retransmission_experiment_;
friend class StunRequestManager;
};