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