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 |
| 11 #include <algorithm> |
11 #include <memory> | 12 #include <memory> |
12 #include <utility> | 13 #include <utility> |
13 | 14 |
14 #include "webrtc/p2p/base/dtlstransportchannel.h" | 15 #include "webrtc/p2p/base/dtlstransport.h" |
15 | 16 |
16 #include "webrtc/p2p/base/common.h" | 17 #include "webrtc/p2p/base/common.h" |
17 #include "webrtc/p2p/base/packettransportinternal.h" | 18 #include "webrtc/p2p/base/packettransportinternal.h" |
18 #include "webrtc/rtc_base/buffer.h" | 19 #include "webrtc/rtc_base/buffer.h" |
19 #include "webrtc/rtc_base/checks.h" | 20 #include "webrtc/rtc_base/checks.h" |
20 #include "webrtc/rtc_base/dscp.h" | 21 #include "webrtc/rtc_base/dscp.h" |
21 #include "webrtc/rtc_base/messagequeue.h" | 22 #include "webrtc/rtc_base/messagequeue.h" |
22 #include "webrtc/rtc_base/sslstreamadapter.h" | 23 #include "webrtc/rtc_base/sslstreamadapter.h" |
23 #include "webrtc/rtc_base/stream.h" | 24 #include "webrtc/rtc_base/stream.h" |
24 #include "webrtc/rtc_base/thread.h" | 25 #include "webrtc/rtc_base/thread.h" |
(...skipping 30 matching lines...) Expand all Loading... |
55 return (len >= kMinRtpPacketLen && (u[0] & 0xC0) == 0x80); | 56 return (len >= kMinRtpPacketLen && (u[0] & 0xC0) == 0x80); |
56 } | 57 } |
57 | 58 |
58 StreamInterfaceChannel::StreamInterfaceChannel( | 59 StreamInterfaceChannel::StreamInterfaceChannel( |
59 IceTransportInternal* ice_transport) | 60 IceTransportInternal* ice_transport) |
60 : ice_transport_(ice_transport), | 61 : ice_transport_(ice_transport), |
61 state_(rtc::SS_OPEN), | 62 state_(rtc::SS_OPEN), |
62 packets_(kMaxPendingPackets, kMaxDtlsPacketLen) {} | 63 packets_(kMaxPendingPackets, kMaxDtlsPacketLen) {} |
63 | 64 |
64 rtc::StreamResult StreamInterfaceChannel::Read(void* buffer, | 65 rtc::StreamResult StreamInterfaceChannel::Read(void* buffer, |
65 size_t buffer_len, | 66 size_t buffer_len, |
66 size_t* read, | 67 size_t* read, |
67 int* error) { | 68 int* error) { |
68 if (state_ == rtc::SS_CLOSED) | 69 if (state_ == rtc::SS_CLOSED) |
69 return rtc::SR_EOS; | 70 return rtc::SR_EOS; |
70 if (state_ == rtc::SS_OPENING) | 71 if (state_ == rtc::SS_OPENING) |
71 return rtc::SR_BLOCK; | 72 return rtc::SR_BLOCK; |
72 | 73 |
73 if (!packets_.ReadFront(buffer, buffer_len, read)) { | 74 if (!packets_.ReadFront(buffer, buffer_len, read)) { |
74 return rtc::SR_BLOCK; | 75 return rtc::SR_BLOCK; |
75 } | 76 } |
76 | 77 |
77 return rtc::SR_SUCCESS; | 78 return rtc::SR_SUCCESS; |
78 } | 79 } |
79 | 80 |
80 rtc::StreamResult StreamInterfaceChannel::Write(const void* data, | 81 rtc::StreamResult StreamInterfaceChannel::Write(const void* data, |
81 size_t data_len, | 82 size_t data_len, |
82 size_t* written, | 83 size_t* written, |
83 int* error) { | 84 int* error) { |
84 // Always succeeds, since this is an unreliable transport anyway. | 85 // Always succeeds, since this is an unreliable transport anyway. |
85 // TODO(zhihuang): Should this block if ice_transport_'s temporarily | 86 // TODO(zhihuang): Should this block if ice_transport_'s temporarily |
86 // unwritable? | 87 // unwritable? |
87 rtc::PacketOptions packet_options; | 88 rtc::PacketOptions packet_options; |
88 ice_transport_->SendPacket(static_cast<const char*>(data), data_len, | 89 ice_transport_->SendPacket(static_cast<const char*>(data), data_len, |
89 packet_options); | 90 packet_options); |
90 if (written) { | 91 if (written) { |
91 *written = data_len; | 92 *written = data_len; |
92 } | 93 } |
93 return rtc::SR_SUCCESS; | 94 return rtc::SR_SUCCESS; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 323 } |
323 | 324 |
324 bool DtlsTransport::GetSrtpCryptoSuite(int* cipher) { | 325 bool DtlsTransport::GetSrtpCryptoSuite(int* cipher) { |
325 if (dtls_state() != DTLS_TRANSPORT_CONNECTED) { | 326 if (dtls_state() != DTLS_TRANSPORT_CONNECTED) { |
326 return false; | 327 return false; |
327 } | 328 } |
328 | 329 |
329 return dtls_->GetDtlsSrtpCryptoSuite(cipher); | 330 return dtls_->GetDtlsSrtpCryptoSuite(cipher); |
330 } | 331 } |
331 | 332 |
332 | |
333 // Called from upper layers to send a media packet. | 333 // Called from upper layers to send a media packet. |
334 int DtlsTransport::SendPacket(const char* data, | 334 int DtlsTransport::SendPacket(const char* data, |
335 size_t size, | 335 size_t size, |
336 const rtc::PacketOptions& options, | 336 const rtc::PacketOptions& options, |
337 int flags) { | 337 int flags) { |
338 if (!dtls_active_) { | 338 if (!dtls_active_) { |
339 // Not doing DTLS. | 339 // Not doing DTLS. |
340 return ice_transport_->SendPacket(data, size, options); | 340 return ice_transport_->SendPacket(data, size, options); |
341 } | 341 } |
342 | 342 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 SignalDtlsHandshakeError(error); | 664 SignalDtlsHandshakeError(error); |
665 } | 665 } |
666 | 666 |
667 void DtlsTransport::ConfigureHandshakeTimeout() { | 667 void DtlsTransport::ConfigureHandshakeTimeout() { |
668 RTC_DCHECK(dtls_); | 668 RTC_DCHECK(dtls_); |
669 rtc::Optional<int> rtt = ice_transport_->GetRttEstimate(); | 669 rtc::Optional<int> rtt = ice_transport_->GetRttEstimate(); |
670 if (rtt) { | 670 if (rtt) { |
671 // Limit the timeout to a reasonable range in case the ICE RTT takes | 671 // Limit the timeout to a reasonable range in case the ICE RTT takes |
672 // extreme values. | 672 // extreme values. |
673 int initial_timeout = std::max(kMinHandshakeTimeout, | 673 int initial_timeout = std::max(kMinHandshakeTimeout, |
674 std::min(kMaxHandshakeTimeout, | 674 std::min(kMaxHandshakeTimeout, 2 * (*rtt))); |
675 2 * (*rtt))); | |
676 LOG_J(LS_INFO, this) << "configuring DTLS handshake timeout " | 675 LOG_J(LS_INFO, this) << "configuring DTLS handshake timeout " |
677 << initial_timeout << " based on ICE RTT " << *rtt; | 676 << initial_timeout << " based on ICE RTT " << *rtt; |
678 | 677 |
679 dtls_->SetInitialRetransmissionTimeout(initial_timeout); | 678 dtls_->SetInitialRetransmissionTimeout(initial_timeout); |
680 } else { | 679 } else { |
681 LOG_J(LS_INFO, this) | 680 LOG_J(LS_INFO, this) |
682 << "no RTT estimate - using default DTLS handshake timeout"; | 681 << "no RTT estimate - using default DTLS handshake timeout"; |
683 } | 682 } |
684 } | 683 } |
685 | 684 |
686 | |
687 } // namespace cricket | 685 } // namespace cricket |
OLD | NEW |