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 | #ifndef PC_JSEP_TRANSPORT_H_ |
| 12 | #define PC_JSEP_TRANSPORT_H_ |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 13 | |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 20 | #include "api/candidate.h" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 21 | #include "api/ice_transport_interface.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 22 | #include "api/jsep.h" |
Niels Möller | 65f17ca | 2019-09-12 13:59:36 +0200 | [diff] [blame] | 23 | #include "api/transport/datagram_transport_interface.h" |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 24 | #include "media/sctp/sctp_transport_internal.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "p2p/base/dtls_transport.h" |
| 26 | #include "p2p/base/p2p_constants.h" |
| 27 | #include "p2p/base/transport_info.h" |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 28 | #include "pc/composite_data_channel_transport.h" |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 29 | #include "pc/composite_rtp_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "pc/dtls_srtp_transport.h" |
| 31 | #include "pc/dtls_transport.h" |
| 32 | #include "pc/rtcp_mux_filter.h" |
| 33 | #include "pc/rtp_transport.h" |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 34 | #include "pc/sctp_transport.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 35 | #include "pc/session_description.h" |
| 36 | #include "pc/srtp_filter.h" |
| 37 | #include "pc/srtp_transport.h" |
| 38 | #include "pc/transport_stats.h" |
| 39 | #include "rtc_base/constructor_magic.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 40 | #include "rtc_base/rtc_certificate.h" |
| 41 | #include "rtc_base/ssl_stream_adapter.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 42 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 43 | #include "rtc_base/thread_checker.h" |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 44 | |
| 45 | namespace cricket { |
| 46 | |
| 47 | class DtlsTransportInternal; |
| 48 | |
| 49 | struct JsepTransportDescription { |
| 50 | public: |
| 51 | JsepTransportDescription(); |
| 52 | JsepTransportDescription( |
| 53 | bool rtcp_mux_enabled, |
| 54 | const std::vector<CryptoParams>& cryptos, |
| 55 | const std::vector<int>& encrypted_header_extension_ids, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 56 | int rtp_abs_sendtime_extn_id, |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 57 | const TransportDescription& transport_description, |
| 58 | absl::optional<std::string> media_alt_protocol, |
| 59 | absl::optional<std::string> data_alt_protocol); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 60 | JsepTransportDescription(const JsepTransportDescription& from); |
| 61 | ~JsepTransportDescription(); |
| 62 | |
| 63 | JsepTransportDescription& operator=(const JsepTransportDescription& from); |
| 64 | |
| 65 | bool rtcp_mux_enabled = true; |
| 66 | std::vector<CryptoParams> cryptos; |
| 67 | std::vector<int> encrypted_header_extension_ids; |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 68 | int rtp_abs_sendtime_extn_id = -1; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 69 | // TODO(zhihuang): Add the ICE and DTLS related variables and methods from |
| 70 | // TransportDescription and remove this extra layer of abstraction. |
| 71 | TransportDescription transport_desc; |
Bjorn A Mellem | 8e1343a | 2019-09-30 15:12:47 -0700 | [diff] [blame] | 72 | |
| 73 | // Alt-protocols that apply to this JsepTransport. Presence indicates a |
| 74 | // request to use an alternative protocol for media and/or data. The |
| 75 | // alt-protocol is handled by a datagram transport. If one or both of these |
| 76 | // values are present, JsepTransport will attempt to negotiate use of the |
| 77 | // datagram transport for media and/or data. |
| 78 | absl::optional<std::string> media_alt_protocol; |
| 79 | absl::optional<std::string> data_alt_protocol; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | // Helper class used by JsepTransportController that processes |
| 83 | // TransportDescriptions. A TransportDescription represents the |
| 84 | // transport-specific properties of an SDP m= section, processed according to |
| 85 | // JSEP. Each transport consists of DTLS and ICE transport channels for RTP |
| 86 | // (and possibly RTCP, if rtcp-mux isn't used). |
| 87 | // |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 88 | // On Threading: JsepTransport performs work solely on the network thread, and |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 89 | // so its methods should only be called on the network thread. |
Bjorn A Mellem | 7a9a092 | 2019-11-26 09:19:40 -0800 | [diff] [blame] | 90 | class JsepTransport : public sigslot::has_slots<> { |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 91 | public: |
| 92 | // |mid| is just used for log statements in order to identify the Transport. |
| 93 | // Note that |local_certificate| is allowed to be null since a remote |
| 94 | // description may be set before a local certificate is generated. |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 95 | JsepTransport( |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 96 | const std::string& mid, |
| 97 | const rtc::scoped_refptr<rtc::RTCCertificate>& local_certificate, |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 98 | rtc::scoped_refptr<webrtc::IceTransportInterface> ice_transport, |
| 99 | rtc::scoped_refptr<webrtc::IceTransportInterface> rtcp_ice_transport, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 100 | std::unique_ptr<webrtc::RtpTransport> unencrypted_rtp_transport, |
| 101 | std::unique_ptr<webrtc::SrtpTransport> sdes_transport, |
| 102 | std::unique_ptr<webrtc::DtlsSrtpTransport> dtls_srtp_transport, |
Bjorn A Mellem | 364b267 | 2019-08-20 16:58:03 -0700 | [diff] [blame] | 103 | std::unique_ptr<webrtc::RtpTransportInternal> datagram_rtp_transport, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 104 | std::unique_ptr<DtlsTransportInternal> rtp_dtls_transport, |
Anton Sukhanov | 7940da0 | 2018-10-10 10:34:49 -0700 | [diff] [blame] | 105 | std::unique_ptr<DtlsTransportInternal> rtcp_dtls_transport, |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 106 | std::unique_ptr<SctpTransportInternal> sctp_transport, |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 107 | std::unique_ptr<webrtc::DatagramTransportInterface> datagram_transport, |
| 108 | webrtc::DataChannelTransportInterface* data_channel_transport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 109 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 110 | ~JsepTransport() override; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 111 | |
| 112 | // Returns the MID of this transport. This is only used for logging. |
| 113 | const std::string& mid() const { return mid_; } |
| 114 | |
| 115 | // Must be called before applying local session description. |
| 116 | // Needed in order to verify the local fingerprint. |
| 117 | void SetLocalCertificate( |
| 118 | const rtc::scoped_refptr<rtc::RTCCertificate>& local_certificate) { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 119 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 120 | local_certificate_ = local_certificate; |
| 121 | } |
| 122 | |
| 123 | // Return the local certificate provided by SetLocalCertificate. |
| 124 | rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 125 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 126 | return local_certificate_; |
| 127 | } |
| 128 | |
| 129 | webrtc::RTCError SetLocalJsepTransportDescription( |
| 130 | const JsepTransportDescription& jsep_description, |
| 131 | webrtc::SdpType type); |
| 132 | |
| 133 | // Set the remote TransportDescription to be used by DTLS and ICE channels |
| 134 | // that are part of this Transport. |
| 135 | webrtc::RTCError SetRemoteJsepTransportDescription( |
| 136 | const JsepTransportDescription& jsep_description, |
| 137 | webrtc::SdpType type); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 138 | webrtc::RTCError AddRemoteCandidates(const Candidates& candidates); |
| 139 | |
| 140 | // Set the "needs-ice-restart" flag as described in JSEP. After the flag is |
| 141 | // set, offers should generate new ufrags/passwords until an ICE restart |
| 142 | // occurs. |
| 143 | // |
| 144 | // This and the below method can be called safely from any thread as long as |
| 145 | // SetXTransportDescription is not in progress. |
| 146 | void SetNeedsIceRestartFlag(); |
| 147 | // Returns true if the ICE restart flag above was set, and no ICE restart has |
| 148 | // occurred yet for this transport (by applying a local description with |
| 149 | // changed ufrag/password). |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 150 | bool needs_ice_restart() const { |
| 151 | rtc::CritScope scope(&accessor_lock_); |
| 152 | return needs_ice_restart_; |
| 153 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 154 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 155 | // Returns role if negotiated, or empty absl::optional if it hasn't been |
| 156 | // negotiated yet. |
| 157 | absl::optional<rtc::SSLRole> GetDtlsRole() const; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 158 | |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 159 | absl::optional<OpaqueTransportParameters> GetTransportParameters() const; |
| 160 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 161 | // TODO(deadbeef): Make this const. See comment in transportcontroller.h. |
| 162 | bool GetStats(TransportStats* stats); |
| 163 | |
| 164 | const JsepTransportDescription* local_description() const { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 165 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 166 | return local_description_.get(); |
| 167 | } |
| 168 | |
| 169 | const JsepTransportDescription* remote_description() const { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 170 | RTC_DCHECK_RUN_ON(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 171 | return remote_description_.get(); |
| 172 | } |
| 173 | |
| 174 | webrtc::RtpTransportInternal* rtp_transport() const { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 175 | rtc::CritScope scope(&accessor_lock_); |
| 176 | if (composite_rtp_transport_) { |
| 177 | return composite_rtp_transport_.get(); |
| 178 | } else if (datagram_rtp_transport_) { |
| 179 | return datagram_rtp_transport_.get(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 180 | } else { |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 181 | return default_rtp_transport(); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 185 | const DtlsTransportInternal* rtp_dtls_transport() const { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 186 | rtc::CritScope scope(&accessor_lock_); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 187 | if (rtp_dtls_transport_) { |
| 188 | return rtp_dtls_transport_->internal(); |
| 189 | } else { |
| 190 | return nullptr; |
| 191 | } |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 194 | DtlsTransportInternal* rtp_dtls_transport() { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 195 | rtc::CritScope scope(&accessor_lock_); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 196 | if (rtp_dtls_transport_) { |
| 197 | return rtp_dtls_transport_->internal(); |
| 198 | } else { |
| 199 | return nullptr; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | const DtlsTransportInternal* rtcp_dtls_transport() const { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 204 | rtc::CritScope scope(&accessor_lock_); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 205 | if (rtcp_dtls_transport_) { |
| 206 | return rtcp_dtls_transport_->internal(); |
| 207 | } else { |
| 208 | return nullptr; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | DtlsTransportInternal* rtcp_dtls_transport() { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 213 | rtc::CritScope scope(&accessor_lock_); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 214 | if (rtcp_dtls_transport_) { |
| 215 | return rtcp_dtls_transport_->internal(); |
| 216 | } else { |
| 217 | return nullptr; |
| 218 | } |
| 219 | } |
| 220 | |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 221 | rtc::scoped_refptr<webrtc::DtlsTransport> RtpDtlsTransport() { |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 222 | rtc::CritScope scope(&accessor_lock_); |
Harald Alvestrand | ad88c88 | 2018-11-28 16:47:46 +0100 | [diff] [blame] | 223 | return rtp_dtls_transport_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 226 | rtc::scoped_refptr<webrtc::SctpTransport> SctpTransport() const { |
| 227 | rtc::CritScope scope(&accessor_lock_); |
| 228 | return sctp_transport_; |
| 229 | } |
| 230 | |
| 231 | webrtc::DataChannelTransportInterface* data_channel_transport() const { |
| 232 | rtc::CritScope scope(&accessor_lock_); |
| 233 | if (composite_data_channel_transport_) { |
| 234 | return composite_data_channel_transport_.get(); |
| 235 | } else if (sctp_data_channel_transport_) { |
| 236 | return sctp_data_channel_transport_.get(); |
| 237 | } |
| 238 | return data_channel_transport_; |
| 239 | } |
| 240 | |
Anton Sukhanov | 316f3ac | 2019-05-23 15:50:38 -0700 | [diff] [blame] | 241 | // Returns datagram transport, if available. |
| 242 | webrtc::DatagramTransportInterface* datagram_transport() const { |
| 243 | rtc::CritScope scope(&accessor_lock_); |
Anton Sukhanov | 292ce4e | 2019-06-03 13:00:24 -0700 | [diff] [blame] | 244 | return datagram_transport_.get(); |
Anton Sukhanov | 316f3ac | 2019-05-23 15:50:38 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 247 | // This is signaled when RTCP-mux becomes active and |
| 248 | // |rtcp_dtls_transport_| is destroyed. The JsepTransportController will |
| 249 | // handle the signal and update the aggregate transport states. |
| 250 | sigslot::signal<> SignalRtcpMuxActive; |
| 251 | |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 252 | // Signals that a data channel transport was negotiated and may be used to |
| 253 | // send data. The first parameter is |this|. The second parameter is the |
| 254 | // transport that was negotiated, or null if negotiation rejected the data |
| 255 | // channel transport. The third parameter (bool) indicates whether the |
| 256 | // negotiation was provisional or final. If true, it is provisional, if |
| 257 | // false, it is final. |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 258 | sigslot::signal2<JsepTransport*, webrtc::DataChannelTransportInterface*> |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 259 | SignalDataChannelTransportNegotiated; |
| 260 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 261 | // TODO(deadbeef): The methods below are only public for testing. Should make |
| 262 | // them utility functions or objects so they can be tested independently from |
| 263 | // this class. |
| 264 | |
| 265 | // Returns an error if the certificate's identity does not match the |
| 266 | // fingerprint, or either is NULL. |
| 267 | webrtc::RTCError VerifyCertificateFingerprint( |
| 268 | const rtc::RTCCertificate* certificate, |
| 269 | const rtc::SSLFingerprint* fingerprint) const; |
| 270 | |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 271 | void SetActiveResetSrtpParams(bool active_reset_srtp_params); |
| 272 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 273 | private: |
| 274 | bool SetRtcpMux(bool enable, webrtc::SdpType type, ContentSource source); |
| 275 | |
| 276 | void ActivateRtcpMux(); |
| 277 | |
| 278 | bool SetSdes(const std::vector<CryptoParams>& cryptos, |
| 279 | const std::vector<int>& encrypted_extension_ids, |
| 280 | webrtc::SdpType type, |
| 281 | ContentSource source); |
| 282 | |
| 283 | // Negotiates and sets the DTLS parameters based on the current local and |
| 284 | // remote transport description, such as the DTLS role to use, and whether |
| 285 | // DTLS should be activated. |
| 286 | // |
| 287 | // Called when an answer TransportDescription is applied. |
| 288 | webrtc::RTCError NegotiateAndSetDtlsParameters( |
| 289 | webrtc::SdpType local_description_type); |
| 290 | |
| 291 | // Negotiates the DTLS role based off the offer and answer as specified by |
| 292 | // RFC 4145, section-4.1. Returns an RTCError if role cannot be determined |
| 293 | // from the local description and remote description. |
| 294 | webrtc::RTCError NegotiateDtlsRole( |
| 295 | webrtc::SdpType local_description_type, |
| 296 | ConnectionRole local_connection_role, |
| 297 | ConnectionRole remote_connection_role, |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 298 | absl::optional<rtc::SSLRole>* negotiated_dtls_role); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 299 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 300 | // Pushes down the ICE parameters from the remote description. |
Steve Anton | 71ff073 | 2020-01-24 16:28:15 -0800 | [diff] [blame] | 301 | void SetRemoteIceParameters(const IceParameters& ice_parameters, |
| 302 | IceTransportInternal* ice); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 303 | |
| 304 | // Pushes down the DTLS parameters obtained via negotiation. |
| 305 | webrtc::RTCError SetNegotiatedDtlsParameters( |
| 306 | DtlsTransportInternal* dtls_transport, |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 307 | absl::optional<rtc::SSLRole> dtls_role, |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 308 | rtc::SSLFingerprint* remote_fingerprint); |
| 309 | |
| 310 | bool GetTransportStats(DtlsTransportInternal* dtls_transport, |
| 311 | TransportStats* stats); |
| 312 | |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 313 | // Deactivates, signals removal, and deletes |composite_rtp_transport_| if the |
| 314 | // current state of negotiation is sufficient to determine which rtp_transport |
Bjorn A Mellem | b689af4 | 2019-08-21 10:44:59 -0700 | [diff] [blame] | 315 | // and data channel transport to use. |
| 316 | void NegotiateDatagramTransport(webrtc::SdpType type) |
| 317 | RTC_RUN_ON(network_thread_); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 318 | |
| 319 | // Returns the default (non-datagram) rtp transport, if any. |
| 320 | webrtc::RtpTransportInternal* default_rtp_transport() const |
| 321 | RTC_EXCLUSIVE_LOCKS_REQUIRED(accessor_lock_) { |
| 322 | if (dtls_srtp_transport_) { |
| 323 | return dtls_srtp_transport_.get(); |
| 324 | } else if (sdes_transport_) { |
| 325 | return sdes_transport_.get(); |
| 326 | } else if (unencrypted_rtp_transport_) { |
| 327 | return unencrypted_rtp_transport_.get(); |
| 328 | } else { |
| 329 | return nullptr; |
| 330 | } |
| 331 | } |
| 332 | |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 333 | // Owning thread, for safety checks |
| 334 | const rtc::Thread* const network_thread_; |
| 335 | // Critical scope for fields accessed off-thread |
| 336 | // TODO(https://bugs.webrtc.org/10300): Stop doing this. |
| 337 | rtc::CriticalSection accessor_lock_; |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 338 | const std::string mid_; |
| 339 | // needs-ice-restart bit as described in JSEP. |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 340 | bool needs_ice_restart_ RTC_GUARDED_BY(accessor_lock_) = false; |
| 341 | rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_ |
| 342 | RTC_GUARDED_BY(network_thread_); |
| 343 | std::unique_ptr<JsepTransportDescription> local_description_ |
| 344 | RTC_GUARDED_BY(network_thread_); |
| 345 | std::unique_ptr<JsepTransportDescription> remote_description_ |
| 346 | RTC_GUARDED_BY(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 347 | |
Bjorn A Mellem | 0c1c1b4 | 2019-05-29 17:34:13 -0700 | [diff] [blame] | 348 | // Ice transport which may be used by any of upper-layer transports (below). |
| 349 | // Owned by JsepTransport and guaranteed to outlive the transports below. |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 350 | const rtc::scoped_refptr<webrtc::IceTransportInterface> ice_transport_; |
| 351 | const rtc::scoped_refptr<webrtc::IceTransportInterface> rtcp_ice_transport_; |
Bjorn A Mellem | 0c1c1b4 | 2019-05-29 17:34:13 -0700 | [diff] [blame] | 352 | |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 353 | // To avoid downcasting and make it type safe, keep three unique pointers for |
| 354 | // different SRTP mode and only one of these is non-nullptr. |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 355 | std::unique_ptr<webrtc::RtpTransport> unencrypted_rtp_transport_ |
| 356 | RTC_GUARDED_BY(accessor_lock_); |
| 357 | std::unique_ptr<webrtc::SrtpTransport> sdes_transport_ |
| 358 | RTC_GUARDED_BY(accessor_lock_); |
| 359 | std::unique_ptr<webrtc::DtlsSrtpTransport> dtls_srtp_transport_ |
| 360 | RTC_GUARDED_BY(accessor_lock_); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 361 | |
| 362 | // If multiple RTP transports are in use, |composite_rtp_transport_| will be |
| 363 | // passed to callers. This is only valid for offer-only, receive-only |
| 364 | // scenarios, as it is not possible for the composite to correctly choose |
| 365 | // which transport to use for sending. |
| 366 | std::unique_ptr<webrtc::CompositeRtpTransport> composite_rtp_transport_ |
| 367 | RTC_GUARDED_BY(accessor_lock_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 368 | |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 369 | rtc::scoped_refptr<webrtc::DtlsTransport> rtp_dtls_transport_ |
| 370 | RTC_GUARDED_BY(accessor_lock_); |
| 371 | rtc::scoped_refptr<webrtc::DtlsTransport> rtcp_dtls_transport_ |
| 372 | RTC_GUARDED_BY(accessor_lock_); |
Bjorn A Mellem | c85ebbe | 2019-06-07 10:28:06 -0700 | [diff] [blame] | 373 | rtc::scoped_refptr<webrtc::DtlsTransport> datagram_dtls_transport_ |
| 374 | RTC_GUARDED_BY(accessor_lock_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 375 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 376 | std::unique_ptr<webrtc::DataChannelTransportInterface> |
| 377 | sctp_data_channel_transport_ RTC_GUARDED_BY(accessor_lock_); |
| 378 | rtc::scoped_refptr<webrtc::SctpTransport> sctp_transport_ |
| 379 | RTC_GUARDED_BY(accessor_lock_); |
| 380 | |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 381 | SrtpFilter sdes_negotiator_ RTC_GUARDED_BY(network_thread_); |
| 382 | RtcpMuxFilter rtcp_mux_negotiator_ RTC_GUARDED_BY(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 383 | |
| 384 | // Cache the encrypted header extension IDs for SDES negoitation. |
Harald Alvestrand | 78a5e96 | 2019-04-03 10:42:39 +0200 | [diff] [blame] | 385 | absl::optional<std::vector<int>> send_extension_ids_ |
| 386 | RTC_GUARDED_BY(network_thread_); |
| 387 | absl::optional<std::vector<int>> recv_extension_ids_ |
| 388 | RTC_GUARDED_BY(network_thread_); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 389 | |
Anton Sukhanov | 292ce4e | 2019-06-03 13:00:24 -0700 | [diff] [blame] | 390 | // Optional datagram transport (experimental). |
| 391 | std::unique_ptr<webrtc::DatagramTransportInterface> datagram_transport_ |
| 392 | RTC_GUARDED_BY(accessor_lock_); |
| 393 | |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 394 | std::unique_ptr<webrtc::RtpTransportInternal> datagram_rtp_transport_ |
| 395 | RTC_GUARDED_BY(accessor_lock_); |
| 396 | |
Bjorn A Mellem | 7a9a092 | 2019-11-26 09:19:40 -0800 | [diff] [blame] | 397 | // Non-SCTP data channel transport. Set to |datagram_transport_| if that |
| 398 | // transport should be used for data chanels. Unset otherwise. |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 399 | webrtc::DataChannelTransportInterface* data_channel_transport_ |
| 400 | RTC_GUARDED_BY(accessor_lock_) = nullptr; |
| 401 | |
| 402 | // Composite data channel transport, used during negotiation. |
| 403 | std::unique_ptr<webrtc::CompositeDataChannelTransport> |
| 404 | composite_data_channel_transport_ RTC_GUARDED_BY(accessor_lock_); |
| 405 | |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 406 | RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransport); |
Zhi Huang | e818b6e | 2018-02-22 15:26:27 -0800 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | } // namespace cricket |
| 410 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 411 | #endif // PC_JSEP_TRANSPORT_H_ |