Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "pc/jsep_transport.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 16 | #include <memory> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include <type_traits> |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 18 | #include <utility> // for std::pair |
| 19 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "api/array_view.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 21 | #include "api/candidate.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "p2p/base/p2p_constants.h" |
| 23 | #include "p2p/base/p2p_transport_channel.h" |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 24 | #include "pc/sctp_data_channel_transport.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 25 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "rtc_base/copy_on_write_buffer.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 27 | #include "rtc_base/logging.h" |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 28 | #include "rtc_base/strings/string_builder.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 29 | |
| 30 | using webrtc::SdpType; |
| 31 | |
| 32 | namespace cricket { |
| 33 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 34 | JsepTransportDescription::JsepTransportDescription() {} |
| 35 | |
| 36 | JsepTransportDescription::JsepTransportDescription( |
| 37 | bool rtcp_mux_enabled, |
| 38 | const std::vector<CryptoParams>& cryptos, |
| 39 | const std::vector<int>& encrypted_header_extension_ids, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 40 | int rtp_abs_sendtime_extn_id, |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 41 | const TransportDescription& transport_desc, |
| 42 | absl::optional<std::string> media_alt_protocol, |
| 43 | absl::optional<std::string> data_alt_protocol) |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 44 | : rtcp_mux_enabled(rtcp_mux_enabled), |
| 45 | cryptos(cryptos), |
| 46 | encrypted_header_extension_ids(encrypted_header_extension_ids), |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 47 | rtp_abs_sendtime_extn_id(rtp_abs_sendtime_extn_id), |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 48 | transport_desc(transport_desc), |
| 49 | media_alt_protocol(media_alt_protocol), |
| 50 | data_alt_protocol(data_alt_protocol) {} |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 51 | |
| 52 | JsepTransportDescription::JsepTransportDescription( |
| 53 | const JsepTransportDescription& from) |
| 54 | : rtcp_mux_enabled(from.rtcp_mux_enabled), |
| 55 | cryptos(from.cryptos), |
| 56 | encrypted_header_extension_ids(from.encrypted_header_extension_ids), |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 57 | rtp_abs_sendtime_extn_id(from.rtp_abs_sendtime_extn_id), |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 58 | transport_desc(from.transport_desc), |
| 59 | media_alt_protocol(from.media_alt_protocol), |
| 60 | data_alt_protocol(from.data_alt_protocol) {} |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 61 | |
| 62 | JsepTransportDescription::~JsepTransportDescription() = default; |
| 63 | |
| 64 | JsepTransportDescription& JsepTransportDescription::operator=( |
| 65 | const JsepTransportDescription& from) { |
| 66 | if (this == &from) { |
| 67 | return *this; |
| 68 | } |
| 69 | rtcp_mux_enabled = from.rtcp_mux_enabled; |
| 70 | cryptos = from.cryptos; |
| 71 | encrypted_header_extension_ids = from.encrypted_header_extension_ids; |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 72 | rtp_abs_sendtime_extn_id = from.rtp_abs_sendtime_extn_id; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 73 | transport_desc = from.transport_desc; |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 74 | media_alt_protocol = from.media_alt_protocol; |
| 75 | data_alt_protocol = from.data_alt_protocol; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 76 | |
| 77 | return *this; |
| 78 | } |
| 79 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 80 | JsepTransport::JsepTransport( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 81 | const std::string& mid, |
| 82 | const rtc::scoped_refptr<rtc::RTCCertificate>& local_certificate, |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 83 | rtc::scoped_refptr<webrtc::IceTransportInterface> ice_transport, |
| 84 | rtc::scoped_refptr<webrtc::IceTransportInterface> rtcp_ice_transport, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 85 | std::unique_ptr<webrtc::RtpTransport> unencrypted_rtp_transport, |
| 86 | std::unique_ptr<webrtc::SrtpTransport> sdes_transport, |
| 87 | std::unique_ptr<webrtc::DtlsSrtpTransport> dtls_srtp_transport, |
Bjorn A Mellem | 364b267 | 2019-08-20 16:58:03 -0700 | [diff] [blame] | 88 | std::unique_ptr<webrtc::RtpTransportInternal> datagram_rtp_transport, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 89 | std::unique_ptr<DtlsTransportInternal> rtp_dtls_transport, |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 90 | std::unique_ptr<DtlsTransportInternal> rtcp_dtls_transport, |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 91 | std::unique_ptr<SctpTransportInternal> sctp_transport, |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 92 | std::unique_ptr<webrtc::DatagramTransportInterface> datagram_transport, |
| 93 | webrtc::DataChannelTransportInterface* data_channel_transport) |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 94 | : network_thread_(rtc::Thread::Current()), |
| 95 | mid_(mid), |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 96 | local_certificate_(local_certificate), |
Bjorn A Mellem | 0c1c1b4 | 2019-05-29 17:34:13 -0700 | [diff] [blame] | 97 | ice_transport_(std::move(ice_transport)), |
| 98 | rtcp_ice_transport_(std::move(rtcp_ice_transport)), |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 99 | unencrypted_rtp_transport_(std::move(unencrypted_rtp_transport)), |
| 100 | sdes_transport_(std::move(sdes_transport)), |
| 101 | dtls_srtp_transport_(std::move(dtls_srtp_transport)), |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 102 | rtp_dtls_transport_( |
| 103 | rtp_dtls_transport ? new rtc::RefCountedObject<webrtc::DtlsTransport>( |
| 104 | std::move(rtp_dtls_transport)) |
| 105 | : nullptr), |
| 106 | rtcp_dtls_transport_( |
| 107 | rtcp_dtls_transport |
| 108 | ? new rtc::RefCountedObject<webrtc::DtlsTransport>( |
| 109 | std::move(rtcp_dtls_transport)) |
| 110 | : nullptr), |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 111 | sctp_data_channel_transport_( |
| 112 | sctp_transport ? std::make_unique<webrtc::SctpDataChannelTransport>( |
| 113 | sctp_transport.get()) |
| 114 | : nullptr), |
| 115 | sctp_transport_(sctp_transport |
| 116 | ? new rtc::RefCountedObject<webrtc::SctpTransport>( |
| 117 | std::move(sctp_transport)) |
| 118 | : nullptr), |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 119 | datagram_transport_(std::move(datagram_transport)), |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 120 | datagram_rtp_transport_(std::move(datagram_rtp_transport)), |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 121 | data_channel_transport_(data_channel_transport) { |
Bjorn A Mellem | 0c1c1b4 | 2019-05-29 17:34:13 -0700 | [diff] [blame] | 122 | RTC_DCHECK(ice_transport_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 123 | RTC_DCHECK(rtp_dtls_transport_); |
Bjorn A Mellem | 0c1c1b4 | 2019-05-29 17:34:13 -0700 | [diff] [blame] | 124 | // |rtcp_ice_transport_| must be present iff |rtcp_dtls_transport_| is |
| 125 | // present. |
| 126 | RTC_DCHECK_EQ((rtcp_ice_transport_ != nullptr), |
| 127 | (rtcp_dtls_transport_ != nullptr)); |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 128 | // Verify the "only one out of these three can be set" invariant. |
| 129 | if (unencrypted_rtp_transport_) { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 130 | RTC_DCHECK(!sdes_transport); |
| 131 | RTC_DCHECK(!dtls_srtp_transport); |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 132 | } else if (sdes_transport_) { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 133 | RTC_DCHECK(!unencrypted_rtp_transport); |
| 134 | RTC_DCHECK(!dtls_srtp_transport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 135 | } else { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 136 | RTC_DCHECK(dtls_srtp_transport_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 137 | RTC_DCHECK(!unencrypted_rtp_transport); |
| 138 | RTC_DCHECK(!sdes_transport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 139 | } |
Piotr (Peter) Slatala | 4eb4112 | 2018-11-01 07:26:03 -0700 | [diff] [blame] | 140 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 141 | if (sctp_transport_) { |
| 142 | sctp_transport_->SetDtlsTransport(rtp_dtls_transport_); |
| 143 | } |
| 144 | |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 145 | if (datagram_rtp_transport_ && default_rtp_transport()) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 146 | composite_rtp_transport_ = std::make_unique<webrtc::CompositeRtpTransport>( |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 147 | std::vector<webrtc::RtpTransportInternal*>{ |
| 148 | datagram_rtp_transport_.get(), default_rtp_transport()}); |
| 149 | } |
| 150 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 151 | if (data_channel_transport_ && sctp_data_channel_transport_) { |
| 152 | composite_data_channel_transport_ = |
| 153 | std::make_unique<webrtc::CompositeDataChannelTransport>( |
| 154 | std::vector<webrtc::DataChannelTransportInterface*>{ |
| 155 | data_channel_transport_, sctp_data_channel_transport_.get()}); |
| 156 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Piotr (Peter) Slatala | 4eb4112 | 2018-11-01 07:26:03 -0700 | [diff] [blame] | 159 | JsepTransport::~JsepTransport() { |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 160 | if (sctp_transport_) { |
| 161 | sctp_transport_->Clear(); |
| 162 | } |
| 163 | |
Harald Alvestrand | 628f37a | 2018-12-06 10:55:20 +0100 | [diff] [blame] | 164 | // Clear all DtlsTransports. There may be pointers to these from |
| 165 | // other places, so we can't assume they'll be deleted by the destructor. |
Harald Alvestrand | d02541e | 2019-01-03 12:43:28 +0100 | [diff] [blame] | 166 | rtp_dtls_transport_->Clear(); |
Harald Alvestrand | 628f37a | 2018-12-06 10:55:20 +0100 | [diff] [blame] | 167 | if (rtcp_dtls_transport_) { |
Harald Alvestrand | d02541e | 2019-01-03 12:43:28 +0100 | [diff] [blame] | 168 | rtcp_dtls_transport_->Clear(); |
Harald Alvestrand | 628f37a | 2018-12-06 10:55:20 +0100 | [diff] [blame] | 169 | } |
Anton Sukhanov | 292ce4e | 2019-06-03 13:00:24 -0700 | [diff] [blame] | 170 | |
Anton Sukhanov | 292ce4e | 2019-06-03 13:00:24 -0700 | [diff] [blame] | 171 | // ICE will be the last transport to be deleted. |
Piotr (Peter) Slatala | 4eb4112 | 2018-11-01 07:26:03 -0700 | [diff] [blame] | 172 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 173 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 174 | webrtc::RTCError JsepTransport::SetLocalJsepTransportDescription( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 175 | const JsepTransportDescription& jsep_description, |
| 176 | SdpType type) { |
| 177 | webrtc::RTCError error; |
| 178 | |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 179 | RTC_DCHECK_RUN_ON(network_thread_); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 180 | |
Jonas Oreland | 52aea5d | 2020-03-03 13:21:30 +0100 | [diff] [blame] | 181 | IceParameters ice_parameters = |
| 182 | jsep_description.transport_desc.GetIceParameters(); |
| 183 | webrtc::RTCError ice_parameters_result = ice_parameters.Validate(); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 184 | if (!ice_parameters_result.ok()) { |
| 185 | rtc::StringBuilder sb; |
Jonas Oreland | 52aea5d | 2020-03-03 13:21:30 +0100 | [diff] [blame] | 186 | sb << "Invalid ICE parameters: " << ice_parameters_result.message(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 187 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 188 | sb.Release()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | if (!SetRtcpMux(jsep_description.rtcp_mux_enabled, type, |
| 192 | ContentSource::CS_LOCAL)) { |
| 193 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 194 | "Failed to setup RTCP mux."); |
| 195 | } |
| 196 | |
| 197 | // If doing SDES, setup the SDES crypto parameters. |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 198 | { |
| 199 | rtc::CritScope scope(&accessor_lock_); |
| 200 | if (sdes_transport_) { |
| 201 | RTC_DCHECK(!unencrypted_rtp_transport_); |
| 202 | RTC_DCHECK(!dtls_srtp_transport_); |
| 203 | if (!SetSdes(jsep_description.cryptos, |
| 204 | jsep_description.encrypted_header_extension_ids, type, |
| 205 | ContentSource::CS_LOCAL)) { |
| 206 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 207 | "Failed to setup SDES crypto parameters."); |
| 208 | } |
| 209 | } else if (dtls_srtp_transport_) { |
| 210 | RTC_DCHECK(!unencrypted_rtp_transport_); |
| 211 | RTC_DCHECK(!sdes_transport_); |
| 212 | dtls_srtp_transport_->UpdateRecvEncryptedHeaderExtensionIds( |
| 213 | jsep_description.encrypted_header_extension_ids); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 214 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 215 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 216 | bool ice_restarting = |
| 217 | local_description_ != nullptr && |
| 218 | IceCredentialsChanged(local_description_->transport_desc.ice_ufrag, |
| 219 | local_description_->transport_desc.ice_pwd, |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 220 | ice_parameters.ufrag, ice_parameters.pwd); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 221 | local_description_.reset(new JsepTransportDescription(jsep_description)); |
| 222 | |
| 223 | rtc::SSLFingerprint* local_fp = |
| 224 | local_description_->transport_desc.identity_fingerprint.get(); |
| 225 | |
| 226 | if (!local_fp) { |
| 227 | local_certificate_ = nullptr; |
| 228 | } else { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 229 | error = VerifyCertificateFingerprint(local_certificate_, local_fp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 230 | if (!error.ok()) { |
| 231 | local_description_.reset(); |
| 232 | return error; |
| 233 | } |
| 234 | } |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 235 | { |
| 236 | rtc::CritScope scope(&accessor_lock_); |
| 237 | RTC_DCHECK(rtp_dtls_transport_->internal()); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 238 | rtp_dtls_transport_->internal()->ice_transport()->SetIceParameters( |
| 239 | ice_parameters); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 240 | |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 241 | if (rtcp_dtls_transport_) { |
| 242 | RTC_DCHECK(rtcp_dtls_transport_->internal()); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 243 | rtcp_dtls_transport_->internal()->ice_transport()->SetIceParameters( |
| 244 | ice_parameters); |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 245 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 246 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 247 | // If PRANSWER/ANSWER is set, we should decide transport protocol type. |
| 248 | if (type == SdpType::kPrAnswer || type == SdpType::kAnswer) { |
| 249 | error = NegotiateAndSetDtlsParameters(type); |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 250 | NegotiateDatagramTransport(type); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 251 | } |
| 252 | if (!error.ok()) { |
| 253 | local_description_.reset(); |
| 254 | return error; |
| 255 | } |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 256 | { |
| 257 | rtc::CritScope scope(&accessor_lock_); |
| 258 | if (needs_ice_restart_ && ice_restarting) { |
| 259 | needs_ice_restart_ = false; |
| 260 | RTC_LOG(LS_VERBOSE) << "needs-ice-restart flag cleared for transport " |
| 261 | << mid(); |
| 262 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | return webrtc::RTCError::OK(); |
| 266 | } |
| 267 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 268 | webrtc::RTCError JsepTransport::SetRemoteJsepTransportDescription( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 269 | const JsepTransportDescription& jsep_description, |
| 270 | webrtc::SdpType type) { |
| 271 | webrtc::RTCError error; |
| 272 | |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 273 | RTC_DCHECK_RUN_ON(network_thread_); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 274 | |
Jonas Oreland | 52aea5d | 2020-03-03 13:21:30 +0100 | [diff] [blame] | 275 | IceParameters ice_parameters = |
| 276 | jsep_description.transport_desc.GetIceParameters(); |
| 277 | webrtc::RTCError ice_parameters_result = ice_parameters.Validate(); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 278 | if (!ice_parameters_result.ok()) { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 279 | remote_description_.reset(); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 280 | rtc::StringBuilder sb; |
Jonas Oreland | 52aea5d | 2020-03-03 13:21:30 +0100 | [diff] [blame] | 281 | sb << "Invalid ICE parameters: " << ice_parameters_result.message(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 282 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 283 | sb.Release()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | if (!SetRtcpMux(jsep_description.rtcp_mux_enabled, type, |
| 287 | ContentSource::CS_REMOTE)) { |
| 288 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 289 | "Failed to setup RTCP mux."); |
| 290 | } |
| 291 | |
| 292 | // If doing SDES, setup the SDES crypto parameters. |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 293 | { |
| 294 | rtc::CritScope lock(&accessor_lock_); |
| 295 | if (sdes_transport_) { |
| 296 | RTC_DCHECK(!unencrypted_rtp_transport_); |
| 297 | RTC_DCHECK(!dtls_srtp_transport_); |
| 298 | if (!SetSdes(jsep_description.cryptos, |
| 299 | jsep_description.encrypted_header_extension_ids, type, |
| 300 | ContentSource::CS_REMOTE)) { |
| 301 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 302 | "Failed to setup SDES crypto parameters."); |
| 303 | } |
| 304 | sdes_transport_->CacheRtpAbsSendTimeHeaderExtension( |
| 305 | jsep_description.rtp_abs_sendtime_extn_id); |
| 306 | } else if (dtls_srtp_transport_) { |
| 307 | RTC_DCHECK(!unencrypted_rtp_transport_); |
| 308 | RTC_DCHECK(!sdes_transport_); |
| 309 | dtls_srtp_transport_->UpdateSendEncryptedHeaderExtensionIds( |
| 310 | jsep_description.encrypted_header_extension_ids); |
| 311 | dtls_srtp_transport_->CacheRtpAbsSendTimeHeaderExtension( |
| 312 | jsep_description.rtp_abs_sendtime_extn_id); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 313 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | remote_description_.reset(new JsepTransportDescription(jsep_description)); |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 317 | RTC_DCHECK(rtp_dtls_transport()); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 318 | SetRemoteIceParameters(ice_parameters, rtp_dtls_transport()->ice_transport()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 319 | |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 320 | if (rtcp_dtls_transport()) { |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 321 | SetRemoteIceParameters(ice_parameters, |
| 322 | rtcp_dtls_transport()->ice_transport()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // If PRANSWER/ANSWER is set, we should decide transport protocol type. |
| 326 | if (type == SdpType::kPrAnswer || type == SdpType::kAnswer) { |
| 327 | error = NegotiateAndSetDtlsParameters(SdpType::kOffer); |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 328 | NegotiateDatagramTransport(type); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 329 | } |
| 330 | if (!error.ok()) { |
| 331 | remote_description_.reset(); |
| 332 | return error; |
| 333 | } |
| 334 | return webrtc::RTCError::OK(); |
| 335 | } |
| 336 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 337 | webrtc::RTCError JsepTransport::AddRemoteCandidates( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 338 | const Candidates& candidates) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 339 | RTC_DCHECK_RUN_ON(network_thread_); |
Henrik Boström | 5d8f8fa | 2018-04-13 15:22:50 +0000 | [diff] [blame] | 340 | if (!local_description_ || !remote_description_) { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 341 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_STATE, |
| 342 | mid() + |
| 343 | " is not ready to use the remote candidate " |
Henrik Boström | 5d8f8fa | 2018-04-13 15:22:50 +0000 | [diff] [blame] | 344 | "because the local or remote description is " |
| 345 | "not set."); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | for (const cricket::Candidate& candidate : candidates) { |
| 349 | auto transport = |
| 350 | candidate.component() == cricket::ICE_CANDIDATE_COMPONENT_RTP |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 351 | ? rtp_dtls_transport_ |
| 352 | : rtcp_dtls_transport_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 353 | if (!transport) { |
| 354 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 355 | "Candidate has an unknown component: " + |
Qingsi Wang | 20232a9 | 2019-09-06 12:51:17 -0700 | [diff] [blame] | 356 | candidate.ToSensitiveString() + " for mid " + |
| 357 | mid()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 358 | } |
Harald Alvestrand | 628f37a | 2018-12-06 10:55:20 +0100 | [diff] [blame] | 359 | RTC_DCHECK(transport->internal() && transport->internal()->ice_transport()); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 360 | transport->internal()->ice_transport()->AddRemoteCandidate(candidate); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 361 | } |
| 362 | return webrtc::RTCError::OK(); |
| 363 | } |
| 364 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 365 | void JsepTransport::SetNeedsIceRestartFlag() { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 366 | rtc::CritScope scope(&accessor_lock_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 367 | if (!needs_ice_restart_) { |
| 368 | needs_ice_restart_ = true; |
| 369 | RTC_LOG(LS_VERBOSE) << "needs-ice-restart flag set for transport " << mid(); |
| 370 | } |
| 371 | } |
| 372 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 373 | absl::optional<rtc::SSLRole> JsepTransport::GetDtlsRole() const { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 374 | RTC_DCHECK_RUN_ON(network_thread_); |
| 375 | rtc::CritScope scope(&accessor_lock_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 376 | RTC_DCHECK(rtp_dtls_transport_); |
Harald Alvestrand | 628f37a | 2018-12-06 10:55:20 +0100 | [diff] [blame] | 377 | RTC_DCHECK(rtp_dtls_transport_->internal()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 378 | rtc::SSLRole dtls_role; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 379 | if (!rtp_dtls_transport_->internal()->GetDtlsRole(&dtls_role)) { |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 380 | return absl::optional<rtc::SSLRole>(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 383 | return absl::optional<rtc::SSLRole>(dtls_role); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 386 | absl::optional<OpaqueTransportParameters> |
| 387 | JsepTransport::GetTransportParameters() const { |
| 388 | rtc::CritScope scope(&accessor_lock_); |
| 389 | if (!datagram_transport()) { |
| 390 | return absl::nullopt; |
| 391 | } |
| 392 | |
| 393 | OpaqueTransportParameters params; |
| 394 | params.parameters = datagram_transport()->GetTransportParameters(); |
| 395 | return params; |
| 396 | } |
| 397 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 398 | bool JsepTransport::GetStats(TransportStats* stats) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 399 | RTC_DCHECK_RUN_ON(network_thread_); |
| 400 | rtc::CritScope scope(&accessor_lock_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 401 | stats->transport_name = mid(); |
| 402 | stats->channel_stats.clear(); |
Harald Alvestrand | 628f37a | 2018-12-06 10:55:20 +0100 | [diff] [blame] | 403 | RTC_DCHECK(rtp_dtls_transport_->internal()); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 404 | bool ret = GetTransportStats(rtp_dtls_transport_->internal(), stats); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 405 | if (rtcp_dtls_transport_) { |
Harald Alvestrand | 628f37a | 2018-12-06 10:55:20 +0100 | [diff] [blame] | 406 | RTC_DCHECK(rtcp_dtls_transport_->internal()); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 407 | ret &= GetTransportStats(rtcp_dtls_transport_->internal(), stats); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 408 | } |
| 409 | return ret; |
| 410 | } |
| 411 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 412 | webrtc::RTCError JsepTransport::VerifyCertificateFingerprint( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 413 | const rtc::RTCCertificate* certificate, |
| 414 | const rtc::SSLFingerprint* fingerprint) const { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 415 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 416 | if (!fingerprint) { |
| 417 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 418 | "No fingerprint"); |
| 419 | } |
| 420 | if (!certificate) { |
| 421 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 422 | "Fingerprint provided but no identity available."); |
| 423 | } |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 424 | std::unique_ptr<rtc::SSLFingerprint> fp_tmp = |
| 425 | rtc::SSLFingerprint::CreateUnique(fingerprint->algorithm, |
| 426 | *certificate->identity()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 427 | RTC_DCHECK(fp_tmp.get() != NULL); |
| 428 | if (*fp_tmp == *fingerprint) { |
| 429 | return webrtc::RTCError::OK(); |
| 430 | } |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 431 | char ss_buf[1024]; |
| 432 | rtc::SimpleStringBuilder desc(ss_buf); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 433 | desc << "Local fingerprint does not match identity. Expected: "; |
| 434 | desc << fp_tmp->ToString(); |
| 435 | desc << " Got: " << fingerprint->ToString(); |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 436 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 437 | std::string(desc.str())); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 440 | void JsepTransport::SetActiveResetSrtpParams(bool active_reset_srtp_params) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 441 | RTC_DCHECK_RUN_ON(network_thread_); |
| 442 | rtc::CritScope scope(&accessor_lock_); |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 443 | if (dtls_srtp_transport_) { |
| 444 | RTC_LOG(INFO) |
| 445 | << "Setting active_reset_srtp_params of DtlsSrtpTransport to: " |
| 446 | << active_reset_srtp_params; |
| 447 | dtls_srtp_transport_->SetActiveResetSrtpParams(active_reset_srtp_params); |
| 448 | } |
| 449 | } |
| 450 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 451 | void JsepTransport::SetRemoteIceParameters( |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 452 | const IceParameters& ice_parameters, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 453 | IceTransportInternal* ice_transport) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 454 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 455 | RTC_DCHECK(ice_transport); |
| 456 | RTC_DCHECK(remote_description_); |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 457 | ice_transport->SetRemoteIceParameters(ice_parameters); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 458 | ice_transport->SetRemoteIceMode(remote_description_->transport_desc.ice_mode); |
| 459 | } |
| 460 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 461 | webrtc::RTCError JsepTransport::SetNegotiatedDtlsParameters( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 462 | DtlsTransportInternal* dtls_transport, |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 463 | absl::optional<rtc::SSLRole> dtls_role, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 464 | rtc::SSLFingerprint* remote_fingerprint) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 465 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 466 | RTC_DCHECK(dtls_transport); |
| 467 | // Set SSL role. Role must be set before fingerprint is applied, which |
| 468 | // initiates DTLS setup. |
| 469 | if (dtls_role && !dtls_transport->SetDtlsRole(*dtls_role)) { |
| 470 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 471 | "Failed to set SSL role for the transport."); |
| 472 | } |
| 473 | // Apply remote fingerprint. |
| 474 | if (!remote_fingerprint || |
| 475 | !dtls_transport->SetRemoteFingerprint( |
Amit Hilbuch | e7a5f7b | 2019-03-12 11:10:27 -0700 | [diff] [blame] | 476 | remote_fingerprint->algorithm, remote_fingerprint->digest.cdata(), |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 477 | remote_fingerprint->digest.size())) { |
| 478 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_PARAMETER, |
| 479 | "Failed to apply remote fingerprint."); |
| 480 | } |
| 481 | return webrtc::RTCError::OK(); |
| 482 | } |
| 483 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 484 | bool JsepTransport::SetRtcpMux(bool enable, |
| 485 | webrtc::SdpType type, |
| 486 | ContentSource source) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 487 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 488 | bool ret = false; |
| 489 | switch (type) { |
| 490 | case SdpType::kOffer: |
| 491 | ret = rtcp_mux_negotiator_.SetOffer(enable, source); |
| 492 | break; |
| 493 | case SdpType::kPrAnswer: |
| 494 | // This may activate RTCP muxing, but we don't yet destroy the transport |
| 495 | // because the final answer may deactivate it. |
| 496 | ret = rtcp_mux_negotiator_.SetProvisionalAnswer(enable, source); |
| 497 | break; |
| 498 | case SdpType::kAnswer: |
| 499 | ret = rtcp_mux_negotiator_.SetAnswer(enable, source); |
| 500 | if (ret && rtcp_mux_negotiator_.IsActive()) { |
| 501 | ActivateRtcpMux(); |
| 502 | } |
| 503 | break; |
| 504 | default: |
| 505 | RTC_NOTREACHED(); |
| 506 | } |
| 507 | |
| 508 | if (!ret) { |
| 509 | return false; |
| 510 | } |
| 511 | |
| 512 | auto transport = rtp_transport(); |
| 513 | transport->SetRtcpMuxEnabled(rtcp_mux_negotiator_.IsActive()); |
| 514 | return ret; |
| 515 | } |
| 516 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 517 | void JsepTransport::ActivateRtcpMux() { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 518 | { |
| 519 | // Don't hold the network_thread_ lock while calling other functions, |
| 520 | // since they might call other functions that call RTC_DCHECK_RUN_ON. |
| 521 | // TODO(https://crbug.com/webrtc/10318): Simplify when possible. |
| 522 | RTC_DCHECK_RUN_ON(network_thread_); |
| 523 | } |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 524 | { |
| 525 | rtc::CritScope scope(&accessor_lock_); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 526 | if (unencrypted_rtp_transport_) { |
| 527 | RTC_DCHECK(!sdes_transport_); |
| 528 | RTC_DCHECK(!dtls_srtp_transport_); |
| 529 | unencrypted_rtp_transport_->SetRtcpPacketTransport(nullptr); |
| 530 | } else if (sdes_transport_) { |
| 531 | RTC_DCHECK(!unencrypted_rtp_transport_); |
| 532 | RTC_DCHECK(!dtls_srtp_transport_); |
| 533 | sdes_transport_->SetRtcpPacketTransport(nullptr); |
| 534 | } else if (dtls_srtp_transport_) { |
| 535 | RTC_DCHECK(dtls_srtp_transport_); |
| 536 | RTC_DCHECK(!unencrypted_rtp_transport_); |
| 537 | RTC_DCHECK(!sdes_transport_); |
| 538 | dtls_srtp_transport_->SetDtlsTransports(rtp_dtls_transport(), |
| 539 | /*rtcp_dtls_transport=*/nullptr); |
| 540 | } |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 541 | rtcp_dtls_transport_ = nullptr; // Destroy this reference. |
| 542 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 543 | // Notify the JsepTransportController to update the aggregate states. |
| 544 | SignalRtcpMuxActive(); |
| 545 | } |
| 546 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 547 | bool JsepTransport::SetSdes(const std::vector<CryptoParams>& cryptos, |
| 548 | const std::vector<int>& encrypted_extension_ids, |
| 549 | webrtc::SdpType type, |
| 550 | ContentSource source) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 551 | RTC_DCHECK_RUN_ON(network_thread_); |
| 552 | rtc::CritScope scope(&accessor_lock_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 553 | bool ret = false; |
| 554 | ret = sdes_negotiator_.Process(cryptos, type, source); |
| 555 | if (!ret) { |
| 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | if (source == ContentSource::CS_LOCAL) { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 560 | recv_extension_ids_ = encrypted_extension_ids; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 561 | } else { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 562 | send_extension_ids_ = encrypted_extension_ids; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | // If setting an SDES answer succeeded, apply the negotiated parameters |
| 566 | // to the SRTP transport. |
| 567 | if ((type == SdpType::kPrAnswer || type == SdpType::kAnswer) && ret) { |
| 568 | if (sdes_negotiator_.send_cipher_suite() && |
| 569 | sdes_negotiator_.recv_cipher_suite()) { |
| 570 | RTC_DCHECK(send_extension_ids_); |
| 571 | RTC_DCHECK(recv_extension_ids_); |
| 572 | ret = sdes_transport_->SetRtpParams( |
| 573 | *(sdes_negotiator_.send_cipher_suite()), |
| 574 | sdes_negotiator_.send_key().data(), |
| 575 | static_cast<int>(sdes_negotiator_.send_key().size()), |
| 576 | *(send_extension_ids_), *(sdes_negotiator_.recv_cipher_suite()), |
| 577 | sdes_negotiator_.recv_key().data(), |
| 578 | static_cast<int>(sdes_negotiator_.recv_key().size()), |
| 579 | *(recv_extension_ids_)); |
| 580 | } else { |
| 581 | RTC_LOG(LS_INFO) << "No crypto keys are provided for SDES."; |
| 582 | if (type == SdpType::kAnswer) { |
| 583 | // Explicitly reset the |sdes_transport_| if no crypto param is |
| 584 | // provided in the answer. No need to call |ResetParams()| for |
| 585 | // |sdes_negotiator_| because it resets the params inside |SetAnswer|. |
| 586 | sdes_transport_->ResetParams(); |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | return ret; |
| 591 | } |
| 592 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 593 | webrtc::RTCError JsepTransport::NegotiateAndSetDtlsParameters( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 594 | SdpType local_description_type) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 595 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 596 | if (!local_description_ || !remote_description_) { |
| 597 | return webrtc::RTCError(webrtc::RTCErrorType::INVALID_STATE, |
| 598 | "Applying an answer transport description " |
| 599 | "without applying any offer."); |
| 600 | } |
| 601 | std::unique_ptr<rtc::SSLFingerprint> remote_fingerprint; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 602 | absl::optional<rtc::SSLRole> negotiated_dtls_role; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 603 | |
| 604 | rtc::SSLFingerprint* local_fp = |
| 605 | local_description_->transport_desc.identity_fingerprint.get(); |
| 606 | rtc::SSLFingerprint* remote_fp = |
| 607 | remote_description_->transport_desc.identity_fingerprint.get(); |
| 608 | if (remote_fp && local_fp) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 609 | remote_fingerprint = std::make_unique<rtc::SSLFingerprint>(*remote_fp); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 610 | webrtc::RTCError error = |
| 611 | NegotiateDtlsRole(local_description_type, |
| 612 | local_description_->transport_desc.connection_role, |
| 613 | remote_description_->transport_desc.connection_role, |
| 614 | &negotiated_dtls_role); |
| 615 | if (!error.ok()) { |
| 616 | return error; |
| 617 | } |
| 618 | } else if (local_fp && (local_description_type == SdpType::kAnswer)) { |
| 619 | return webrtc::RTCError( |
| 620 | webrtc::RTCErrorType::INVALID_PARAMETER, |
| 621 | "Local fingerprint supplied when caller didn't offer DTLS."); |
| 622 | } else { |
| 623 | // We are not doing DTLS |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 624 | remote_fingerprint = std::make_unique<rtc::SSLFingerprint>( |
Steve Anton | 4905edb | 2018-10-15 19:27:44 -0700 | [diff] [blame] | 625 | "", rtc::ArrayView<const uint8_t>()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 626 | } |
| 627 | // Now that we have negotiated everything, push it downward. |
| 628 | // Note that we cache the result so that if we have race conditions |
| 629 | // between future SetRemote/SetLocal invocations and new transport |
| 630 | // creation, we have the negotiation state saved until a new |
| 631 | // negotiation happens. |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 632 | RTC_DCHECK(rtp_dtls_transport()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 633 | webrtc::RTCError error = SetNegotiatedDtlsParameters( |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 634 | rtp_dtls_transport(), negotiated_dtls_role, remote_fingerprint.get()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 635 | if (!error.ok()) { |
| 636 | return error; |
| 637 | } |
| 638 | |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 639 | if (rtcp_dtls_transport()) { |
| 640 | error = SetNegotiatedDtlsParameters( |
| 641 | rtcp_dtls_transport(), negotiated_dtls_role, remote_fingerprint.get()); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 642 | } |
| 643 | return error; |
| 644 | } |
| 645 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 646 | webrtc::RTCError JsepTransport::NegotiateDtlsRole( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 647 | SdpType local_description_type, |
| 648 | ConnectionRole local_connection_role, |
| 649 | ConnectionRole remote_connection_role, |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 650 | absl::optional<rtc::SSLRole>* negotiated_dtls_role) { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 651 | // From RFC 4145, section-4.1, The following are the values that the |
| 652 | // 'setup' attribute can take in an offer/answer exchange: |
| 653 | // Offer Answer |
| 654 | // ________________ |
| 655 | // active passive / holdconn |
| 656 | // passive active / holdconn |
| 657 | // actpass active / passive / holdconn |
| 658 | // holdconn holdconn |
| 659 | // |
| 660 | // Set the role that is most conformant with RFC 5763, Section 5, bullet 1 |
| 661 | // The endpoint MUST use the setup attribute defined in [RFC4145]. |
| 662 | // The endpoint that is the offerer MUST use the setup attribute |
| 663 | // value of setup:actpass and be prepared to receive a client_hello |
| 664 | // before it receives the answer. The answerer MUST use either a |
| 665 | // setup attribute value of setup:active or setup:passive. Note that |
| 666 | // if the answerer uses setup:passive, then the DTLS handshake will |
| 667 | // not begin until the answerer is received, which adds additional |
| 668 | // latency. setup:active allows the answer and the DTLS handshake to |
| 669 | // occur in parallel. Thus, setup:active is RECOMMENDED. Whichever |
| 670 | // party is active MUST initiate a DTLS handshake by sending a |
| 671 | // ClientHello over each flow (host/port quartet). |
| 672 | // IOW - actpass and passive modes should be treated as server and |
| 673 | // active as client. |
| 674 | bool is_remote_server = false; |
| 675 | if (local_description_type == SdpType::kOffer) { |
| 676 | if (local_connection_role != CONNECTIONROLE_ACTPASS) { |
| 677 | return webrtc::RTCError( |
| 678 | webrtc::RTCErrorType::INVALID_PARAMETER, |
| 679 | "Offerer must use actpass value for setup attribute."); |
| 680 | } |
| 681 | |
| 682 | if (remote_connection_role == CONNECTIONROLE_ACTIVE || |
| 683 | remote_connection_role == CONNECTIONROLE_PASSIVE || |
| 684 | remote_connection_role == CONNECTIONROLE_NONE) { |
| 685 | is_remote_server = (remote_connection_role == CONNECTIONROLE_PASSIVE); |
| 686 | } else { |
| 687 | return webrtc::RTCError( |
| 688 | webrtc::RTCErrorType::INVALID_PARAMETER, |
| 689 | "Answerer must use either active or passive value " |
| 690 | "for setup attribute."); |
| 691 | } |
| 692 | // If remote is NONE or ACTIVE it will act as client. |
| 693 | } else { |
| 694 | if (remote_connection_role != CONNECTIONROLE_ACTPASS && |
| 695 | remote_connection_role != CONNECTIONROLE_NONE) { |
| 696 | // Accept a remote role attribute that's not "actpass", but matches the |
| 697 | // current negotiated role. This is allowed by dtls-sdp, though our |
| 698 | // implementation will never generate such an offer as it's not |
| 699 | // recommended. |
| 700 | // |
| 701 | // See https://datatracker.ietf.org/doc/html/draft-ietf-mmusic-dtls-sdp, |
| 702 | // section 5.5. |
| 703 | auto current_dtls_role = GetDtlsRole(); |
| 704 | if (!current_dtls_role || |
| 705 | (*current_dtls_role == rtc::SSL_CLIENT && |
| 706 | remote_connection_role == CONNECTIONROLE_ACTIVE) || |
| 707 | (*current_dtls_role == rtc::SSL_SERVER && |
| 708 | remote_connection_role == CONNECTIONROLE_PASSIVE)) { |
| 709 | return webrtc::RTCError( |
| 710 | webrtc::RTCErrorType::INVALID_PARAMETER, |
| 711 | "Offerer must use actpass value or current negotiated role for " |
| 712 | "setup attribute."); |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | if (local_connection_role == CONNECTIONROLE_ACTIVE || |
| 717 | local_connection_role == CONNECTIONROLE_PASSIVE) { |
| 718 | is_remote_server = (local_connection_role == CONNECTIONROLE_ACTIVE); |
| 719 | } else { |
| 720 | return webrtc::RTCError( |
| 721 | webrtc::RTCErrorType::INVALID_PARAMETER, |
| 722 | "Answerer must use either active or passive value " |
| 723 | "for setup attribute."); |
| 724 | } |
| 725 | |
| 726 | // If local is passive, local will act as server. |
| 727 | } |
| 728 | |
Mirko Bonadei | 05cf6be | 2019-01-31 21:38:12 +0100 | [diff] [blame] | 729 | *negotiated_dtls_role = |
| 730 | (is_remote_server ? rtc::SSL_CLIENT : rtc::SSL_SERVER); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 731 | return webrtc::RTCError::OK(); |
| 732 | } |
| 733 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 734 | bool JsepTransport::GetTransportStats(DtlsTransportInternal* dtls_transport, |
| 735 | TransportStats* stats) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 736 | RTC_DCHECK_RUN_ON(network_thread_); |
| 737 | rtc::CritScope scope(&accessor_lock_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 738 | RTC_DCHECK(dtls_transport); |
| 739 | TransportChannelStats substats; |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 740 | if (rtcp_dtls_transport_) { |
| 741 | substats.component = dtls_transport == rtcp_dtls_transport_->internal() |
| 742 | ? ICE_CANDIDATE_COMPONENT_RTCP |
| 743 | : ICE_CANDIDATE_COMPONENT_RTP; |
| 744 | } else { |
| 745 | substats.component = ICE_CANDIDATE_COMPONENT_RTP; |
| 746 | } |
Harald Alvestrand | 5cb7807 | 2019-10-28 09:51:17 +0100 | [diff] [blame] | 747 | dtls_transport->GetSslVersionBytes(&substats.ssl_version_bytes); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 748 | dtls_transport->GetSrtpCryptoSuite(&substats.srtp_crypto_suite); |
| 749 | dtls_transport->GetSslCipherSuite(&substats.ssl_cipher_suite); |
| 750 | substats.dtls_state = dtls_transport->dtls_state(); |
| 751 | if (!dtls_transport->ice_transport()->GetStats( |
Jonas Oreland | 149dc72 | 2019-08-28 08:10:27 +0200 | [diff] [blame] | 752 | &substats.ice_transport_stats)) { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 753 | return false; |
| 754 | } |
| 755 | stats->channel_stats.push_back(substats); |
| 756 | return true; |
| 757 | } |
| 758 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 759 | void JsepTransport::NegotiateDatagramTransport(SdpType type) { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 760 | RTC_DCHECK(type == SdpType::kAnswer || type == SdpType::kPrAnswer); |
| 761 | rtc::CritScope lock(&accessor_lock_); |
Bjorn A Mellem | 703ea95 | 2019-08-23 10:31:11 -0700 | [diff] [blame] | 762 | if (!datagram_transport_) { |
| 763 | return; // No need to negotiate the use of datagram transport. |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Bjorn A Mellem | 0cda7b8 | 2020-01-28 17:06:55 -0800 | [diff] [blame] | 766 | bool compatible_datagram_transport = false; |
| 767 | if (datagram_transport_ && |
| 768 | local_description_->transport_desc.opaque_parameters && |
| 769 | remote_description_->transport_desc.opaque_parameters) { |
| 770 | // If both descriptions have datagram transport parameters, and the remote |
| 771 | // parameters are accepted by the datagram transport, then use the datagram |
| 772 | // transport. Otherwise, fall back to RTP. |
| 773 | compatible_datagram_transport = |
| 774 | datagram_transport_ |
| 775 | ->SetRemoteTransportParameters(remote_description_->transport_desc |
| 776 | .opaque_parameters->parameters) |
| 777 | .ok(); |
| 778 | } |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 779 | |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 780 | bool use_datagram_transport_for_media = |
| 781 | compatible_datagram_transport && |
| 782 | remote_description_->media_alt_protocol == |
| 783 | remote_description_->transport_desc.opaque_parameters->protocol && |
| 784 | remote_description_->media_alt_protocol == |
| 785 | local_description_->media_alt_protocol; |
| 786 | |
| 787 | bool use_datagram_transport_for_data = |
| 788 | compatible_datagram_transport && |
| 789 | remote_description_->data_alt_protocol == |
| 790 | remote_description_->transport_desc.opaque_parameters->protocol && |
| 791 | remote_description_->data_alt_protocol == |
| 792 | local_description_->data_alt_protocol; |
| 793 | |
| 794 | RTC_LOG(LS_INFO) |
| 795 | << "Negotiating datagram transport, use_datagram_transport_for_media=" |
| 796 | << use_datagram_transport_for_media |
| 797 | << ", use_datagram_transport_for_data=" << use_datagram_transport_for_data |
| 798 | << " answer type=" << (type == SdpType::kAnswer ? "answer" : "pr_answer"); |
Bjorn A Mellem | 703ea95 | 2019-08-23 10:31:11 -0700 | [diff] [blame] | 799 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 800 | // A provisional or full or answer lets the peer start sending on one of the |
| 801 | // transports. |
Bjorn A Mellem | 703ea95 | 2019-08-23 10:31:11 -0700 | [diff] [blame] | 802 | if (composite_rtp_transport_) { |
| 803 | composite_rtp_transport_->SetSendTransport( |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 804 | use_datagram_transport_for_media ? datagram_rtp_transport_.get() |
| 805 | : default_rtp_transport()); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 806 | } |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 807 | if (composite_data_channel_transport_) { |
| 808 | composite_data_channel_transport_->SetSendTransport( |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 809 | use_datagram_transport_for_data ? data_channel_transport_ |
| 810 | : sctp_data_channel_transport_.get()); |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 811 | } |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 812 | |
| 813 | if (type != SdpType::kAnswer) { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 814 | return; |
| 815 | } |
| 816 | |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 817 | if (composite_rtp_transport_) { |
| 818 | if (use_datagram_transport_for_media) { |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 819 | // Negotiated use of datagram transport for RTP, so remove the |
| 820 | // non-datagram RTP transport. |
Bjorn A Mellem | 703ea95 | 2019-08-23 10:31:11 -0700 | [diff] [blame] | 821 | composite_rtp_transport_->RemoveTransport(default_rtp_transport()); |
| 822 | if (unencrypted_rtp_transport_) { |
| 823 | unencrypted_rtp_transport_ = nullptr; |
| 824 | } else if (sdes_transport_) { |
| 825 | sdes_transport_ = nullptr; |
| 826 | } else { |
| 827 | dtls_srtp_transport_ = nullptr; |
| 828 | } |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 829 | } else { |
| 830 | composite_rtp_transport_->RemoveTransport(datagram_rtp_transport_.get()); |
| 831 | datagram_rtp_transport_ = nullptr; |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 832 | } |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | if (composite_data_channel_transport_) { |
| 836 | if (use_datagram_transport_for_data) { |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 837 | // Negotiated use of datagram transport for data channels, so remove the |
| 838 | // non-datagram data channel transport. |
| 839 | composite_data_channel_transport_->RemoveTransport( |
| 840 | sctp_data_channel_transport_.get()); |
| 841 | sctp_data_channel_transport_ = nullptr; |
| 842 | sctp_transport_ = nullptr; |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 843 | } else { |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 844 | composite_data_channel_transport_->RemoveTransport( |
| 845 | data_channel_transport_); |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 846 | data_channel_transport_ = nullptr; |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 847 | } |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 848 | } else if (data_channel_transport_ && !use_datagram_transport_for_data) { |
| 849 | // The datagram transport has been rejected without a fallback. We still |
| 850 | // need to inform the application and delete it. |
| 851 | SignalDataChannelTransportNegotiated(this, nullptr); |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 852 | data_channel_transport_ = nullptr; |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | if (!use_datagram_transport_for_media && !use_datagram_transport_for_data) { |
| 856 | // Datagram transport is not being used for anything, so clean it up. |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 857 | datagram_transport_ = nullptr; |
| 858 | } |
| 859 | } |
| 860 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 861 | } // namespace cricket |