blob: 4779bf922793721f016a807ab162dbeeb0103358 [file] [log] [blame]
Zhi Huange818b6e2018-02-22 15:26:27 -08001/*
2 * Copyright 2017 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 Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_JSEP_TRANSPORT_CONTROLLER_H_
12#define PC_JSEP_TRANSPORT_CONTROLLER_H_
Zhi Huange818b6e2018-02-22 15:26:27 -080013
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000014#include <stdint.h>
15
16#include <functional>
Zhi Huange818b6e2018-02-22 15:26:27 -080017#include <map>
18#include <memory>
19#include <string>
Harald Alvestrandc24a2182022-02-23 13:44:59 +000020#include <type_traits>
Zhi Huange818b6e2018-02-22 15:26:27 -080021#include <utility>
22#include <vector>
23
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000024#include "absl/types/optional.h"
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000025#include "api/async_dns_resolver.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080026#include "api/candidate.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/crypto/crypto_options.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080028#include "api/ice_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000029#include "api/ice_transport_interface.h"
30#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "api/peer_connection_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000032#include "api/rtc_error.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020033#include "api/rtc_event_log/rtc_event_log.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000034#include "api/scoped_refptr.h"
Harald Alvestrandde22ab22021-06-17 10:45:33 +000035#include "api/sequence_checker.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000036#include "api/transport/data_channel_transport_interface.h"
37#include "api/transport/sctp_transport_factory_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080038#include "media/sctp/sctp_transport_internal.h"
39#include "p2p/base/dtls_transport.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080040#include "p2p/base/dtls_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000041#include "p2p/base/dtls_transport_internal.h"
42#include "p2p/base/ice_transport_internal.h"
Steve Anton10542f22019-01-11 09:11:00 -080043#include "p2p/base/p2p_transport_channel.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000044#include "p2p/base/packet_transport_internal.h"
45#include "p2p/base/port.h"
46#include "p2p/base/port_allocator.h"
47#include "p2p/base/transport_description.h"
48#include "p2p/base/transport_info.h"
Steve Anton10542f22019-01-11 09:11:00 -080049#include "pc/dtls_srtp_transport.h"
50#include "pc/dtls_transport.h"
51#include "pc/jsep_transport.h"
Harald Alvestrand9dea3932021-06-10 06:03:06 +000052#include "pc/jsep_transport_collection.h"
Steve Anton10542f22019-01-11 09:11:00 -080053#include "pc/rtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000054#include "pc/rtp_transport_internal.h"
55#include "pc/sctp_transport.h"
56#include "pc/session_description.h"
Steve Anton10542f22019-01-11 09:11:00 -080057#include "pc/srtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000058#include "pc/transport_stats.h"
Mirko Bonadei3d259352020-10-23 12:04:40 +020059#include "rtc_base/callback_list.h"
Harald Alvestrandde22ab22021-06-17 10:45:33 +000060#include "rtc_base/checks.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000061#include "rtc_base/copy_on_write_buffer.h"
62#include "rtc_base/helpers.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000063#include "rtc_base/rtc_certificate.h"
64#include "rtc_base/ssl_certificate.h"
65#include "rtc_base/ssl_stream_adapter.h"
Artem Titove41c4332018-07-25 15:04:28 +020066#include "rtc_base/third_party/sigslot/sigslot.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000067#include "rtc_base/thread.h"
68#include "rtc_base/thread_annotations.h"
Zhi Huange818b6e2018-02-22 15:26:27 -080069
70namespace rtc {
71class Thread;
72class PacketTransportInternal;
73} // namespace rtc
74
75namespace webrtc {
76
Steve Antond25828a2018-08-31 13:06:05 -070077class JsepTransportController : public sigslot::has_slots<> {
Zhi Huange818b6e2018-02-22 15:26:27 -080078 public:
Zhi Huang365381f2018-04-13 16:44:34 -070079 // Used when the RtpTransport/DtlsTransport of the m= section is changed
80 // because the section is rejected or BUNDLE is enabled.
81 class Observer {
82 public:
83 virtual ~Observer() {}
84
Artem Titov880fa812021-07-30 22:30:23 +020085 // Returns true if media associated with `mid` was successfully set up to be
86 // demultiplexed on `rtp_transport`. Could return false if two bundled m=
Zhi Huang365381f2018-04-13 16:44:34 -070087 // sections use the same SSRC, for example.
Bjorn A Mellemb689af42019-08-21 10:44:59 -070088 //
Artem Titov880fa812021-07-30 22:30:23 +020089 // If a data channel transport must be negotiated, `data_channel_transport`
90 // and `negotiation_state` indicate negotiation status. If
91 // `data_channel_transport` is null, the data channel transport should not
Bjorn A Mellemb689af42019-08-21 10:44:59 -070092 // be used. Otherwise, the value is a pointer to the transport to be used
Artem Titov880fa812021-07-30 22:30:23 +020093 // for data channels on `mid`, if any.
Bjorn A Mellemb689af42019-08-21 10:44:59 -070094 //
Artem Titov880fa812021-07-30 22:30:23 +020095 // The observer should not send data on `data_channel_transport` until
96 // `negotiation_state` is provisional or final. It should not delete
97 // `data_channel_transport` or any fallback transport until
98 // `negotiation_state` is final.
Taylor Brandstettercbaa2542018-04-16 16:42:14 -070099 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 16:44:34 -0700100 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 16:42:14 -0700101 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 07:51:00 +0100102 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700103 DataChannelTransportInterface* data_channel_transport) = 0;
Zhi Huang365381f2018-04-13 16:44:34 -0700104 };
105
Zhi Huange818b6e2018-02-22 15:26:27 -0800106 struct Config {
Artem Titov880fa812021-07-30 22:30:23 +0200107 // If `redetermine_role_on_ice_restart` is true, ICE role is redetermined
Zhi Huange818b6e2018-02-22 15:26:27 -0800108 // upon setting a local transport description that indicates an ICE
109 // restart.
110 bool redetermine_role_on_ice_restart = true;
111 rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
Artem Titov880fa812021-07-30 22:30:23 +0200112 // `crypto_options` is used to determine if created DTLS transports
Zhi Huange818b6e2018-02-22 15:26:27 -0800113 // negotiate GCM crypto suites or not.
Benjamin Wrighta54daf12018-10-11 15:33:17 -0700114 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 15:26:27 -0800115 PeerConnectionInterface::BundlePolicy bundle_policy =
116 PeerConnectionInterface::kBundlePolicyBalanced;
117 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
118 PeerConnectionInterface::kRtcpMuxPolicyRequire;
119 bool disable_encryption = false;
120 bool enable_external_auth = false;
121 // Used to inject the ICE/DTLS transports created externally.
Qingsi Wang25ec8882019-11-15 12:33:05 -0800122 webrtc::IceTransportFactory* ice_transport_factory = nullptr;
123 cricket::DtlsTransportFactory* dtls_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 16:44:34 -0700124 Observer* transport_observer = nullptr;
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200125 // Must be provided and valid for the lifetime of the
126 // JsepTransportController instance.
127 std::function<void(const rtc::CopyOnWriteBuffer& packet,
128 int64_t packet_time_us)>
129 rtcp_handler;
Harald Alvestrand133c0522021-01-29 14:27:12 +0000130 // Initial value for whether DtlsTransport reset causes a reset
131 // of SRTP parameters.
Zhi Huangb57e1692018-06-12 11:41:11 -0700132 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-11 20:15:46 -0700133 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 10:34:49 -0700134
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700135 // Factory for SCTP transports.
Per Kjellander2bca0082020-08-28 09:15:15 +0200136 SctpTransportFactoryInterface* sctp_factory = nullptr;
Ali Tofigh62238092022-01-25 13:27:19 +0100137 std::function<void(rtc::SSLHandshakeError)> on_dtls_handshake_error_;
Jonas Orelanded99dae2022-03-09 09:28:10 +0100138
139 // Field trials.
Jonas Orelande62c2f22022-03-29 11:04:48 +0200140 const webrtc::FieldTrialsView* field_trials;
Zhi Huange818b6e2018-02-22 15:26:27 -0800141 };
142
Artem Titov880fa812021-07-30 22:30:23 +0200143 // The ICE related events are fired on the `network_thread`.
144 // All the transport related methods are called on the `network_thread`
Tommic3257d02021-02-10 17:40:08 +0000145 // and destruction of the JsepTransportController must occur on the
Artem Titov880fa812021-07-30 22:30:23 +0200146 // `network_thread`.
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000147 JsepTransportController(
148 rtc::Thread* network_thread,
149 cricket::PortAllocator* port_allocator,
150 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
151 Config config);
Zhi Huange818b6e2018-02-22 15:26:27 -0800152 virtual ~JsepTransportController();
153
Byoungchan Leec065e732022-01-18 09:35:48 +0900154 JsepTransportController(const JsepTransportController&) = delete;
155 JsepTransportController& operator=(const JsepTransportController&) = delete;
156
Zhi Huange818b6e2018-02-22 15:26:27 -0800157 // The main method to be called; applies a description at the transport
158 // level, creating/destroying transport objects as needed and updating their
159 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
160 // yet? May make sense to in the future.
161 RTCError SetLocalDescription(SdpType type,
162 const cricket::SessionDescription* description);
163
164 RTCError SetRemoteDescription(SdpType type,
165 const cricket::SessionDescription* description);
166
Artem Titov880fa812021-07-30 22:30:23 +0200167 // Get transports to be used for the provided `mid`. If bundling is enabled,
Zhi Huange818b6e2018-02-22 15:26:27 -0800168 // calling GetRtpTransport for multiple MIDs may yield the same object.
Harald Alvestrand8f429922022-05-04 10:32:30 +0000169 RtpTransportInternal* GetRtpTransport(absl::string_view mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100170 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
171 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 15:26:27 -0800172 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 16:47:46 +0100173 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100174 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 16:47:46 +0100175 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700176 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
177 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800178
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700179 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 15:50:38 -0700180 const std::string& mid) const;
181
Zhi Huange818b6e2018-02-22 15:26:27 -0800182 /*********************
183 * ICE-related methods
184 ********************/
185 // This method is public to allow PeerConnection to update it from
186 // SetConfiguration.
187 void SetIceConfig(const cricket::IceConfig& config);
188 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
189 // set, offers should generate new ufrags/passwords until an ICE restart
190 // occurs.
191 void SetNeedsIceRestartFlag();
192 // Returns true if the ICE restart flag above was set, and no ICE restart has
193 // occurred yet for this transport (by applying a local description with
194 // changed ufrag/password). If the transport has been deleted as a result of
195 // bundling, returns false.
196 bool NeedsIceRestart(const std::string& mid) const;
197 // Start gathering candidates for any new transports, or transports doing an
198 // ICE restart.
199 void MaybeStartGathering();
200 RTCError AddRemoteCandidates(
201 const std::string& mid,
202 const std::vector<cricket::Candidate>& candidates);
203 RTCError RemoveRemoteCandidates(
204 const std::vector<cricket::Candidate>& candidates);
205
206 /**********************
207 * DTLS-related methods
208 *********************/
209 // Specifies the identity to use in this session.
210 // Can only be called once.
211 bool SetLocalCertificate(
212 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
213 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
214 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 13:04:51 -0800215 // Caller owns returned certificate chain. This method mainly exists for
216 // stats reporting.
217 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 15:26:27 -0800218 const std::string& mid) const;
219 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200220 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 15:26:27 -0800221
222 // TODO(deadbeef): GetStats isn't const because all the way down to
223 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
224 // const. Fix this.
225 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 15:26:27 -0800226
Zhi Huange830e682018-03-30 10:48:35 -0700227 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 16:44:34 -0700228
Zhi Huangb57e1692018-06-12 11:41:11 -0700229 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
230
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700231 RTCError RollbackTransports();
Eldar Rello5ab79e62019-10-09 18:29:44 +0300232
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800233 // F: void(const std::string&, const std::vector<cricket::Candidate>&)
234 template <typename F>
235 void SubscribeIceCandidateGathered(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000236 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800237 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
238 }
239
240 // F: void(cricket::IceConnectionState)
241 template <typename F>
242 void SubscribeIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000243 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800244 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
245 }
246
247 // F: void(PeerConnectionInterface::PeerConnectionState)
248 template <typename F>
249 void SubscribeConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000250 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800251 signal_connection_state_.AddReceiver(std::forward<F>(callback));
252 }
253
254 // F: void(PeerConnectionInterface::IceConnectionState)
255 template <typename F>
256 void SubscribeStandardizedIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000257 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800258 signal_standardized_ice_connection_state_.AddReceiver(
259 std::forward<F>(callback));
260 }
261
262 // F: void(cricket::IceGatheringState)
263 template <typename F>
264 void SubscribeIceGatheringState(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000265 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800266 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
267 }
268
269 // F: void(const cricket::IceCandidateErrorEvent&)
270 template <typename F>
271 void SubscribeIceCandidateError(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000272 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800273 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
274 }
275
276 // F: void(const std::vector<cricket::Candidate>&)
277 template <typename F>
278 void SubscribeIceCandidatesRemoved(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000279 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800280 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
281 }
282
283 // F: void(const cricket::CandidatePairChangeEvent&)
284 template <typename F>
285 void SubscribeIceCandidatePairChanged(F&& callback) {
Tommic3257d02021-02-10 17:40:08 +0000286 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800287 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
288 }
289
290 private:
Tommic3257d02021-02-10 17:40:08 +0000291 // All of these callbacks are fired on the network thread.
Zhi Huange818b6e2018-02-22 15:26:27 -0800292
293 // If any transport failed => failed,
294 // Else if all completed => completed,
295 // Else if all connected => connected,
296 // Else => connecting
Tommic3257d02021-02-10 17:40:08 +0000297 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_
298 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800299
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800300 CallbackList<PeerConnectionInterface::PeerConnectionState>
Tommic3257d02021-02-10 17:40:08 +0000301 signal_connection_state_ RTC_GUARDED_BY(network_thread_);
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 14:33:45 -0700302
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800303 CallbackList<PeerConnectionInterface::IceConnectionState>
Tommic3257d02021-02-10 17:40:08 +0000304 signal_standardized_ice_connection_state_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200305
Zhi Huange818b6e2018-02-22 15:26:27 -0800306 // If all transports done gathering => complete,
307 // Else if any are gathering => gathering,
308 // Else => new
Tommic3257d02021-02-10 17:40:08 +0000309 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_
310 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800311
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800312 // [mid, candidates]
313 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08 +0000314 signal_ice_candidates_gathered_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800315
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800316 CallbackList<const cricket::IceCandidateErrorEvent&>
Tommic3257d02021-02-10 17:40:08 +0000317 signal_ice_candidate_error_ RTC_GUARDED_BY(network_thread_);
Eldar Relloda13ea22019-06-01 12:23:43 +0300318
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800319 CallbackList<const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08 +0000320 signal_ice_candidates_removed_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800321
Lahiru Ginnaliya Gamathige5eb527c2021-01-18 23:32:22 -0800322 CallbackList<const cricket::CandidatePairChangeEvent&>
Tommic3257d02021-02-10 17:40:08 +0000323 signal_ice_candidate_pair_changed_ RTC_GUARDED_BY(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700324
Zhi Huange818b6e2018-02-22 15:26:27 -0800325 RTCError ApplyDescription_n(bool local,
326 SdpType type,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100327 const cricket::SessionDescription* description)
328 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 21:04:26 +0200329 RTCError ValidateAndMaybeUpdateBundleGroups(
Zhi Huangd2248f82018-04-10 14:41:03 -0700330 bool local,
331 SdpType type,
332 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 10:48:35 -0700333 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800334
Harald Alvestrand11b92cf2021-06-17 14:03:09 +0000335 void HandleRejectedContent(const cricket::ContentInfo& content_info)
Niels Möller5cf0ef02021-01-18 14:00:36 +0100336 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 21:04:26 +0200337 bool HandleBundledContent(const cricket::ContentInfo& content_info,
338 const cricket::ContentGroup& bundle_group)
Niels Möller5cf0ef02021-01-18 14:00:36 +0100339 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800340
341 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 20:35:45 +0200342 const cricket::ContentInfo& content_info,
343 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 10:48:35 -0700344 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 10:10:17 +0200345 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 15:26:27 -0800346
Henrik Boströmf8187e02021-04-26 21:04:26 +0200347 std::map<const cricket::ContentGroup*, std::vector<int>>
348 MergeEncryptedHeaderExtensionIdsForBundles(
Zhi Huange818b6e2018-02-22 15:26:27 -0800349 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 15:26:27 -0800350 std::vector<int> GetEncryptedHeaderExtensionIds(
351 const cricket::ContentInfo& content_info);
352
Zhi Huange830e682018-03-30 10:48:35 -0700353 int GetRtpAbsSendTimeHeaderExtensionId(
354 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 15:26:27 -0800355
Zhi Huange830e682018-03-30 10:48:35 -0700356 // This method takes the BUNDLE group into account. If the JsepTransport is
357 // destroyed because of BUNDLE, it would return the transport which other
358 // transports are bundled on (In current implementation, it is the first
359 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 16:44:34 -0700360 const cricket::JsepTransport* GetJsepTransportForMid(
Tomas Gunnarsson92eebef2021-02-10 13:05:44 +0100361 const std::string& mid) const RTC_RUN_ON(network_thread_);
362 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid)
363 RTC_RUN_ON(network_thread_);
Harald Alvestrand8f429922022-05-04 10:32:30 +0000364 const cricket::JsepTransport* GetJsepTransportForMid(
365 absl::string_view mid) const RTC_RUN_ON(network_thread_);
366 cricket::JsepTransport* GetJsepTransportForMid(absl::string_view mid)
367 RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 10:48:35 -0700368
369 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
370 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 16:44:34 -0700371 const cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 10:22:50 +0100372 const std::string& transport_name) const RTC_RUN_ON(network_thread_);
Zhi Huang365381f2018-04-13 16:44:34 -0700373 cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 10:22:50 +0100374 const std::string& transport_name) RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 10:48:35 -0700375
Anton Sukhanov7940da02018-10-10 10:34:49 -0700376 // Creates jsep transport. Noop if transport is already created.
Artem Titov880fa812021-07-30 22:30:23 +0200377 // Transport is created either during SetLocalDescription (`local` == true) or
378 // during SetRemoteDescription (`local` == false). Passing `local` helps to
Anton Sukhanov7940da02018-10-10 10:34:49 -0700379 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 14:26:15 -0800380 RTCError MaybeCreateJsepTransport(
381 bool local,
382 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100383 const cricket::SessionDescription& description)
384 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 14:13:58 -0800385
Niels Möller5cf0ef02021-01-18 14:00:36 +0100386 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800387
Niels Möller5cf0ef02021-01-18 14:00:36 +0100388 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800389
390 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 16:44:34 -0700391 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 15:26:27 -0800392 const cricket::TransportInfo& transport_info,
393 SdpType type,
394 bool local);
395
396 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 15:44:56 -0700397 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 16:39:13 +0200398 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 12:33:05 -0800399 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
400 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 15:26:27 -0800401 bool rtcp);
402
403 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
404 const std::string& transport_name,
405 rtc::PacketTransportInternal* rtp_packet_transport,
406 rtc::PacketTransportInternal* rtcp_packet_transport);
407 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
408 const std::string& transport_name,
Zhi Huange830e682018-03-30 10:48:35 -0700409 cricket::DtlsTransportInternal* rtp_dtls_transport,
410 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 15:26:27 -0800411 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
412 const std::string& transport_name,
413 cricket::DtlsTransportInternal* rtp_dtls_transport,
414 cricket::DtlsTransportInternal* rtcp_dtls_transport);
415
416 // Collect all the DtlsTransports, including RTP and RTCP, from the
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700417 // JsepTransports, including those not mapped to a MID because they are being
418 // kept alive in case of rollback.
Zhi Huange818b6e2018-02-22 15:26:27 -0800419 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
Taylor Brandstetter8591eff2021-08-11 14:56:38 -0700420 // Same as the above, but doesn't include rollback transports.
421 // JsepTransportController can iterate all the DtlsTransports and update the
422 // aggregate states.
423 std::vector<cricket::DtlsTransportInternal*> GetActiveDtlsTransports();
Zhi Huange818b6e2018-02-22 15:26:27 -0800424
425 // Handlers for signals from Transport.
Niels Möller5cf0ef02021-01-18 14:00:36 +0100426 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport)
427 RTC_RUN_ON(network_thread_);
428 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport)
429 RTC_RUN_ON(network_thread_);
430 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport)
431 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800432 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100433 const cricket::Candidate& candidate)
434 RTC_RUN_ON(network_thread_);
435 void OnTransportCandidateError_n(cricket::IceTransportInternal* transport,
436 const cricket::IceCandidateErrorEvent& event)
437 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800438 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100439 const cricket::Candidates& candidates)
440 RTC_RUN_ON(network_thread_);
441 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport)
442 RTC_RUN_ON(network_thread_);
443 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport)
444 RTC_RUN_ON(network_thread_);
Alex Drake00c7ecf2019-08-06 10:54:47 -0700445 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 14:00:36 +0100446 const cricket::CandidatePairChangeEvent& event)
447 RTC_RUN_ON(network_thread_);
448 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 15:26:27 -0800449
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200450 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 14:00:36 +0100451 int64_t packet_time_us)
452 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 18:22:12 +0200453
Zhi Huange818b6e2018-02-22 15:26:27 -0800454 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
455
Harald Alvestrand9dea3932021-06-10 06:03:06 +0000456 bool OnTransportChanged(const std::string& mid,
457 cricket::JsepTransport* transport);
458
Zhi Huange818b6e2018-02-22 15:26:27 -0800459 rtc::Thread* const network_thread_ = nullptr;
460 cricket::PortAllocator* const port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000461 AsyncDnsResolverFactoryInterface* const async_dns_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 15:26:27 -0800462
Harald Alvestrand9dea3932021-06-10 06:03:06 +0000463 JsepTransportCollection transports_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 15:58:17 +0200464 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59 +0000465 // standardized_ice_connection_state_ is intended to replace
466 // ice_connection_state, see bugs.webrtc.org/9308
467 cricket::IceConnectionState ice_connection_state_ =
468 cricket::kIceConnectionConnecting;
469 PeerConnectionInterface::IceConnectionState
470 standardized_ice_connection_state_ =
471 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 15:58:17 +0200472 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
473 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 15:26:27 -0800474 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
475
Harald Alvestrand133c0522021-01-29 14:27:12 +0000476 const Config config_;
477 bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_);
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800478
Zhi Huange818b6e2018-02-22 15:26:27 -0800479 const cricket::SessionDescription* local_desc_ = nullptr;
480 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200481 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800482
Zhi Huange818b6e2018-02-22 15:26:27 -0800483 cricket::IceConfig ice_config_;
484 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
485 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
486 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800487
Harald Alvestrand9f9bf382021-06-08 04:12:37 +0000488 BundleManager bundles_;
Zhi Huange818b6e2018-02-22 15:26:27 -0800489};
490
491} // namespace webrtc
492
Steve Anton10542f22019-01-11 09:11:00 -0800493#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_