OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... | |
27 | 27 |
28 // We don't pull the RTP constants from rtputils.h, to avoid a layer violation. | 28 // We don't pull the RTP constants from rtputils.h, to avoid a layer violation. |
29 static const size_t kDtlsRecordHeaderLen = 13; | 29 static const size_t kDtlsRecordHeaderLen = 13; |
30 static const size_t kMaxDtlsPacketLen = 2048; | 30 static const size_t kMaxDtlsPacketLen = 2048; |
31 static const size_t kMinRtpPacketLen = 12; | 31 static const size_t kMinRtpPacketLen = 12; |
32 | 32 |
33 // Maximum number of pending packets in the queue. Packets are read immediately | 33 // Maximum number of pending packets in the queue. Packets are read immediately |
34 // after they have been written, so a capacity of "1" is sufficient. | 34 // after they have been written, so a capacity of "1" is sufficient. |
35 static const size_t kMaxPendingPackets = 1; | 35 static const size_t kMaxPendingPackets = 1; |
36 | 36 |
37 // Minimum and maximum values for the initial DTLS handshake timeout. We'll pick | |
38 // an initial timeout based on ICE RTT estimates, but clamp it to this range. | |
39 static const int kMinHandshakeTimeout = 50; | |
40 static const int kMaxHandshakeTimeout = 3000; | |
41 | |
37 static bool IsDtlsPacket(const char* data, size_t len) { | 42 static bool IsDtlsPacket(const char* data, size_t len) { |
38 const uint8_t* u = reinterpret_cast<const uint8_t*>(data); | 43 const uint8_t* u = reinterpret_cast<const uint8_t*>(data); |
39 return (len >= kDtlsRecordHeaderLen && (u[0] > 19 && u[0] < 64)); | 44 return (len >= kDtlsRecordHeaderLen && (u[0] > 19 && u[0] < 64)); |
40 } | 45 } |
41 static bool IsDtlsClientHelloPacket(const char* data, size_t len) { | 46 static bool IsDtlsClientHelloPacket(const char* data, size_t len) { |
42 if (!IsDtlsPacket(data, len)) { | 47 if (!IsDtlsPacket(data, len)) { |
43 return false; | 48 return false; |
44 } | 49 } |
45 const uint8_t* u = reinterpret_cast<const uint8_t*>(data); | 50 const uint8_t* u = reinterpret_cast<const uint8_t*>(data); |
46 return len > 17 && u[0] == 22 && u[13] == 1; | 51 return len > 17 && u[0] == 22 && u[13] == 1; |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 set_dtls_state(DTLS_TRANSPORT_CLOSED); | 601 set_dtls_state(DTLS_TRANSPORT_CLOSED); |
597 } else { | 602 } else { |
598 LOG_J(LS_INFO, this) << "DTLS transport error, code=" << err; | 603 LOG_J(LS_INFO, this) << "DTLS transport error, code=" << err; |
599 set_dtls_state(DTLS_TRANSPORT_FAILED); | 604 set_dtls_state(DTLS_TRANSPORT_FAILED); |
600 } | 605 } |
601 } | 606 } |
602 } | 607 } |
603 | 608 |
604 void DtlsTransport::MaybeStartDtls() { | 609 void DtlsTransport::MaybeStartDtls() { |
605 if (dtls_ && ice_transport_->writable()) { | 610 if (dtls_ && ice_transport_->writable()) { |
611 ConfigureHandshakeTimeout(); | |
612 | |
606 if (dtls_->StartSSL()) { | 613 if (dtls_->StartSSL()) { |
607 // This should never fail: | 614 // This should never fail: |
608 // Because we are operating in a nonblocking mode and all | 615 // Because we are operating in a nonblocking mode and all |
609 // incoming packets come in via OnReadPacket(), which rejects | 616 // incoming packets come in via OnReadPacket(), which rejects |
610 // packets in this state, the incoming queue must be empty. We | 617 // packets in this state, the incoming queue must be empty. We |
611 // ignore write errors, thus any errors must be because of | 618 // ignore write errors, thus any errors must be because of |
612 // configuration and therefore are our fault. | 619 // configuration and therefore are our fault. |
613 RTC_NOTREACHED() << "StartSSL failed."; | 620 RTC_NOTREACHED() << "StartSSL failed."; |
614 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; | 621 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; |
615 set_dtls_state(DTLS_TRANSPORT_FAILED); | 622 set_dtls_state(DTLS_TRANSPORT_FAILED); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 LOG_J(LS_VERBOSE, this) << "set_dtls_state from:" << dtls_state_ << " to " | 693 LOG_J(LS_VERBOSE, this) << "set_dtls_state from:" << dtls_state_ << " to " |
687 << state; | 694 << state; |
688 dtls_state_ = state; | 695 dtls_state_ = state; |
689 SignalDtlsState(this, state); | 696 SignalDtlsState(this, state); |
690 } | 697 } |
691 | 698 |
692 void DtlsTransport::OnDtlsHandshakeError(rtc::SSLHandshakeError error) { | 699 void DtlsTransport::OnDtlsHandshakeError(rtc::SSLHandshakeError error) { |
693 SignalDtlsHandshakeError(error); | 700 SignalDtlsHandshakeError(error); |
694 } | 701 } |
695 | 702 |
703 void DtlsTransport::ConfigureHandshakeTimeout() { | |
704 RTC_DCHECK(dtls_); | |
705 rtc::Optional<int> rtt = ice_transport_->GetRttEstimate(); | |
Taylor Brandstetter
2017/02/02 18:07:41
If no round trips have occurred yet (which would h
Taylor Brandstetter
2017/02/02 18:13:31
This is probably why the "EndToEndConnectionTimeWi
skvlad
2017/02/02 22:19:33
I've changed P2PTransportChannel->GetRttEstimate()
| |
706 if (rtt) { | |
707 // Limit the timeout to a reasonable range in case the ICE RTT takes | |
708 // extreme values. | |
709 int initial_timeout = std::max(kMinHandshakeTimeout, | |
710 std::min(kMaxHandshakeTimeout, | |
711 2 * (*rtt))); | |
712 LOG_J(LS_INFO, this) << "configuring DTLS handshake timeout " | |
713 << initial_timeout << " based on ICE RTT " << *rtt; | |
714 | |
715 dtls_->SetHandshakeTimeout(initial_timeout); | |
716 } else { | |
717 LOG_J(LS_INFO, this) | |
718 << "no RTT estimate - using default DTLS handshake timeout"; | |
719 } | |
720 } | |
721 | |
722 | |
696 } // namespace cricket | 723 } // namespace cricket |
OLD | NEW |