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

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

Issue 2670113002: Pick the DTLS handshake timeout based on the ICE RTT estimate (Closed)
Patch Set: Rename InitialHandshakeRetransmissionTimeout -> InitialRetransmissionTimeout. Created 3 years, 11 months 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/dtlstransportchannel.h ('k') | webrtc/p2p/base/fakeicetransport.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/dtlstransportchannel.cc
diff --git a/webrtc/p2p/base/dtlstransportchannel.cc b/webrtc/p2p/base/dtlstransportchannel.cc
index 476005fd54e17feb0bb77b96a3eaa2175c2aa8b0..575ec327b982dbe3c61e3f7a6e98e35a4f6e9a00 100644
--- a/webrtc/p2p/base/dtlstransportchannel.cc
+++ b/webrtc/p2p/base/dtlstransportchannel.cc
@@ -34,6 +34,11 @@ static const size_t kMinRtpPacketLen = 12;
// after they have been written, so a capacity of "1" is sufficient.
static const size_t kMaxPendingPackets = 1;
+// Minimum and maximum values for the initial DTLS handshake timeout. We'll pick
+// an initial timeout based on ICE RTT estimates, but clamp it to this range.
+static const int kMinHandshakeTimeout = 50;
+static const int kMaxHandshakeTimeout = 3000;
+
static bool IsDtlsPacket(const char* data, size_t len) {
const uint8_t* u = reinterpret_cast<const uint8_t*>(data);
return (len >= kDtlsRecordHeaderLen && (u[0] > 19 && u[0] < 64));
@@ -603,6 +608,8 @@ void DtlsTransport::OnDtlsEvent(rtc::StreamInterface* dtls, int sig, int err) {
void DtlsTransport::MaybeStartDtls() {
if (dtls_ && ice_transport_->writable()) {
+ ConfigureHandshakeTimeout();
+
if (dtls_->StartSSL()) {
// This should never fail:
// Because we are operating in a nonblocking mode and all
@@ -693,4 +700,24 @@ void DtlsTransport::OnDtlsHandshakeError(rtc::SSLHandshakeError error) {
SignalDtlsHandshakeError(error);
}
+void DtlsTransport::ConfigureHandshakeTimeout() {
+ RTC_DCHECK(dtls_);
+ rtc::Optional<int> rtt = ice_transport_->GetRttEstimate();
+ if (rtt) {
+ // Limit the timeout to a reasonable range in case the ICE RTT takes
+ // extreme values.
+ int initial_timeout = std::max(kMinHandshakeTimeout,
+ std::min(kMaxHandshakeTimeout,
+ 2 * (*rtt)));
+ LOG_J(LS_INFO, this) << "configuring DTLS handshake timeout "
+ << initial_timeout << " based on ICE RTT " << *rtt;
+
+ dtls_->SetInitialRetransmissionTimeout(initial_timeout);
+ } else {
+ LOG_J(LS_INFO, this)
+ << "no RTT estimate - using default DTLS handshake timeout";
+ }
+}
+
+
} // namespace cricket
« no previous file with comments | « webrtc/p2p/base/dtlstransportchannel.h ('k') | webrtc/p2p/base/fakeicetransport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698