blob: fb420090d4d81deb92c61cc25b179d50b57dd191 [file] [log] [blame]
Zhi Huange818b6e2018-02-22 23:26:271/*
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 17:11:0011#ifndef PC_JSEP_TRANSPORT_CONTROLLER_H_
12#define PC_JSEP_TRANSPORT_CONTROLLER_H_
Zhi Huange818b6e2018-02-22 23:26:2713
Harald Alvestrand5761e7b2021-01-29 14:45:0814#include <stdint.h>
15
16#include <functional>
Zhi Huange818b6e2018-02-22 23:26:2717#include <map>
18#include <memory>
19#include <string>
20#include <utility>
21#include <vector>
22
Harald Alvestrand5761e7b2021-01-29 14:45:0823#include "absl/types/optional.h"
Harald Alvestrand0ccfbd22021-04-08 07:25:0424#include "api/async_dns_resolver.h"
Zhi Huange818b6e2018-02-22 23:26:2725#include "api/candidate.h"
Steve Anton10542f22019-01-11 17:11:0026#include "api/crypto/crypto_options.h"
Qingsi Wang25ec8882019-11-15 20:33:0527#include "api/ice_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0828#include "api/ice_transport_interface.h"
29#include "api/jsep.h"
Steve Anton10542f22019-01-11 17:11:0030#include "api/peer_connection_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0831#include "api/rtc_error.h"
Danil Chapovalov83bbe912019-08-07 10:24:5332#include "api/rtc_event_log/rtc_event_log.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0833#include "api/scoped_refptr.h"
Harald Alvestrandde22ab22021-06-17 10:45:3334#include "api/sequence_checker.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0835#include "api/transport/data_channel_transport_interface.h"
36#include "api/transport/sctp_transport_factory_interface.h"
Steve Anton10542f22019-01-11 17:11:0037#include "media/sctp/sctp_transport_internal.h"
38#include "p2p/base/dtls_transport.h"
Qingsi Wang25ec8882019-11-15 20:33:0539#include "p2p/base/dtls_transport_factory.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0840#include "p2p/base/dtls_transport_internal.h"
41#include "p2p/base/ice_transport_internal.h"
Steve Anton10542f22019-01-11 17:11:0042#include "p2p/base/p2p_transport_channel.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0843#include "p2p/base/packet_transport_internal.h"
44#include "p2p/base/port.h"
45#include "p2p/base/port_allocator.h"
46#include "p2p/base/transport_description.h"
47#include "p2p/base/transport_info.h"
Zhi Huange818b6e2018-02-22 23:26:2748#include "pc/channel.h"
Steve Anton10542f22019-01-11 17:11:0049#include "pc/dtls_srtp_transport.h"
50#include "pc/dtls_transport.h"
51#include "pc/jsep_transport.h"
Harald Alvestrand9dea3932021-06-10 06:03:0652#include "pc/jsep_transport_collection.h"
Steve Anton10542f22019-01-11 17:11:0053#include "pc/rtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0854#include "pc/rtp_transport_internal.h"
55#include "pc/sctp_transport.h"
56#include "pc/session_description.h"
Steve Anton10542f22019-01-11 17:11:0057#include "pc/srtp_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0858#include "pc/transport_stats.h"
Mirko Bonadei3d259352020-10-23 10:04:4059#include "rtc_base/callback_list.h"
Harald Alvestrandde22ab22021-06-17 10:45:3360#include "rtc_base/checks.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0861#include "rtc_base/constructor_magic.h"
62#include "rtc_base/copy_on_write_buffer.h"
63#include "rtc_base/helpers.h"
64#include "rtc_base/ref_counted_object.h"
65#include "rtc_base/rtc_certificate.h"
66#include "rtc_base/ssl_certificate.h"
67#include "rtc_base/ssl_stream_adapter.h"
Artem Titove41c4332018-07-25 13:04:2868#include "rtc_base/third_party/sigslot/sigslot.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0869#include "rtc_base/thread.h"
70#include "rtc_base/thread_annotations.h"
Zhi Huange818b6e2018-02-22 23:26:2771
72namespace rtc {
73class Thread;
74class PacketTransportInternal;
75} // namespace rtc
76
77namespace webrtc {
78
Steve Antond25828a2018-08-31 20:06:0579class JsepTransportController : public sigslot::has_slots<> {
Zhi Huange818b6e2018-02-22 23:26:2780 public:
Zhi Huang365381f2018-04-13 23:44:3481 // Used when the RtpTransport/DtlsTransport of the m= section is changed
82 // because the section is rejected or BUNDLE is enabled.
83 class Observer {
84 public:
85 virtual ~Observer() {}
86
Artem Titov880fa812021-07-30 20:30:2387 // Returns true if media associated with `mid` was successfully set up to be
88 // demultiplexed on `rtp_transport`. Could return false if two bundled m=
Zhi Huang365381f2018-04-13 23:44:3489 // sections use the same SSRC, for example.
Bjorn A Mellemb689af42019-08-21 17:44:5990 //
Artem Titov880fa812021-07-30 20:30:2391 // If a data channel transport must be negotiated, `data_channel_transport`
92 // and `negotiation_state` indicate negotiation status. If
93 // `data_channel_transport` is null, the data channel transport should not
Bjorn A Mellemb689af42019-08-21 17:44:5994 // be used. Otherwise, the value is a pointer to the transport to be used
Artem Titov880fa812021-07-30 20:30:2395 // for data channels on `mid`, if any.
Bjorn A Mellemb689af42019-08-21 17:44:5996 //
Artem Titov880fa812021-07-30 20:30:2397 // The observer should not send data on `data_channel_transport` until
98 // `negotiation_state` is provisional or final. It should not delete
99 // `data_channel_transport` or any fallback transport until
100 // `negotiation_state` is final.
Taylor Brandstettercbaa2542018-04-16 23:42:14101 virtual bool OnTransportChanged(
Zhi Huang365381f2018-04-13 23:44:34102 const std::string& mid,
Taylor Brandstettercbaa2542018-04-16 23:42:14103 RtpTransportInternal* rtp_transport,
Harald Alvestrandc85328f2019-02-28 06:51:00104 rtc::scoped_refptr<DtlsTransport> dtls_transport,
Bjorn A Mellembc3eebc2019-09-23 21:53:54105 DataChannelTransportInterface* data_channel_transport) = 0;
Zhi Huang365381f2018-04-13 23:44:34106 };
107
Zhi Huange818b6e2018-02-22 23:26:27108 struct Config {
Artem Titov880fa812021-07-30 20:30:23109 // If `redetermine_role_on_ice_restart` is true, ICE role is redetermined
Zhi Huange818b6e2018-02-22 23:26:27110 // upon setting a local transport description that indicates an ICE
111 // restart.
112 bool redetermine_role_on_ice_restart = true;
113 rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
Artem Titov880fa812021-07-30 20:30:23114 // `crypto_options` is used to determine if created DTLS transports
Zhi Huange818b6e2018-02-22 23:26:27115 // negotiate GCM crypto suites or not.
Benjamin Wrighta54daf12018-10-11 22:33:17116 webrtc::CryptoOptions crypto_options;
Zhi Huange818b6e2018-02-22 23:26:27117 PeerConnectionInterface::BundlePolicy bundle_policy =
118 PeerConnectionInterface::kBundlePolicyBalanced;
119 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy =
120 PeerConnectionInterface::kRtcpMuxPolicyRequire;
121 bool disable_encryption = false;
122 bool enable_external_auth = false;
123 // Used to inject the ICE/DTLS transports created externally.
Qingsi Wang25ec8882019-11-15 20:33:05124 webrtc::IceTransportFactory* ice_transport_factory = nullptr;
125 cricket::DtlsTransportFactory* dtls_transport_factory = nullptr;
Zhi Huang365381f2018-04-13 23:44:34126 Observer* transport_observer = nullptr;
Sebastian Jansson1b83a9e2019-09-18 16:22:12127 // Must be provided and valid for the lifetime of the
128 // JsepTransportController instance.
129 std::function<void(const rtc::CopyOnWriteBuffer& packet,
130 int64_t packet_time_us)>
131 rtcp_handler;
Harald Alvestrand133c0522021-01-29 14:27:12132 // Initial value for whether DtlsTransport reset causes a reset
133 // of SRTP parameters.
Zhi Huangb57e1692018-06-12 18:41:11134 bool active_reset_srtp_params = false;
Qingsi Wang7685e862018-06-12 03:15:46135 RtcEventLog* event_log = nullptr;
Anton Sukhanov7940da02018-10-10 17:34:49136
Bjorn A Mellembc3eebc2019-09-23 21:53:54137 // Factory for SCTP transports.
Per Kjellander2bca0082020-08-28 07:15:15138 SctpTransportFactoryInterface* sctp_factory = nullptr;
Lahiru Ginnaliya Gamathige70f9e242021-01-28 07:32:46139 std::function<void(const rtc::SSLHandshakeError)> on_dtls_handshake_error_;
Zhi Huange818b6e2018-02-22 23:26:27140 };
141
Artem Titov880fa812021-07-30 20:30:23142 // The ICE related events are fired on the `network_thread`.
143 // All the transport related methods are called on the `network_thread`
Tommic3257d02021-02-10 17:40:08144 // and destruction of the JsepTransportController must occur on the
Artem Titov880fa812021-07-30 20:30:23145 // `network_thread`.
Harald Alvestrand0ccfbd22021-04-08 07:25:04146 JsepTransportController(
147 rtc::Thread* network_thread,
148 cricket::PortAllocator* port_allocator,
149 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
150 Config config);
Zhi Huange818b6e2018-02-22 23:26:27151 virtual ~JsepTransportController();
152
153 // The main method to be called; applies a description at the transport
154 // level, creating/destroying transport objects as needed and updating their
155 // properties. This includes RTP, DTLS, and ICE (but not SCTP). At least not
156 // yet? May make sense to in the future.
157 RTCError SetLocalDescription(SdpType type,
158 const cricket::SessionDescription* description);
159
160 RTCError SetRemoteDescription(SdpType type,
161 const cricket::SessionDescription* description);
162
Artem Titov880fa812021-07-30 20:30:23163 // Get transports to be used for the provided `mid`. If bundling is enabled,
Zhi Huange818b6e2018-02-22 23:26:27164 // calling GetRtpTransport for multiple MIDs may yield the same object.
165 RtpTransportInternal* GetRtpTransport(const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 15:47:46166 cricket::DtlsTransportInternal* GetDtlsTransport(const std::string& mid);
167 const cricket::DtlsTransportInternal* GetRtcpDtlsTransport(
Zhi Huange818b6e2018-02-22 23:26:27168 const std::string& mid) const;
Harald Alvestrandad88c882018-11-28 15:47:46169 // Gets the externally sharable version of the DtlsTransport.
Harald Alvestrand4a7b3ac2019-01-17 09:39:40170 rtc::scoped_refptr<webrtc::DtlsTransport> LookupDtlsTransportByMid(
Harald Alvestrandad88c882018-11-28 15:47:46171 const std::string& mid);
Bjorn A Mellembc3eebc2019-09-23 21:53:54172 rtc::scoped_refptr<SctpTransport> GetSctpTransport(
173 const std::string& mid) const;
Zhi Huange818b6e2018-02-22 23:26:27174
Bjorn A Mellemb689af42019-08-21 17:44:59175 DataChannelTransportInterface* GetDataChannelTransport(
Anton Sukhanov316f3ac2019-05-23 22:50:38176 const std::string& mid) const;
177
Zhi Huange818b6e2018-02-22 23:26:27178 /*********************
179 * ICE-related methods
180 ********************/
181 // This method is public to allow PeerConnection to update it from
182 // SetConfiguration.
183 void SetIceConfig(const cricket::IceConfig& config);
184 // Set the "needs-ice-restart" flag as described in JSEP. After the flag is
185 // set, offers should generate new ufrags/passwords until an ICE restart
186 // occurs.
187 void SetNeedsIceRestartFlag();
188 // Returns true if the ICE restart flag above was set, and no ICE restart has
189 // occurred yet for this transport (by applying a local description with
190 // changed ufrag/password). If the transport has been deleted as a result of
191 // bundling, returns false.
192 bool NeedsIceRestart(const std::string& mid) const;
193 // Start gathering candidates for any new transports, or transports doing an
194 // ICE restart.
195 void MaybeStartGathering();
196 RTCError AddRemoteCandidates(
197 const std::string& mid,
198 const std::vector<cricket::Candidate>& candidates);
199 RTCError RemoveRemoteCandidates(
200 const std::vector<cricket::Candidate>& candidates);
201
202 /**********************
203 * DTLS-related methods
204 *********************/
205 // Specifies the identity to use in this session.
206 // Can only be called once.
207 bool SetLocalCertificate(
208 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
209 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate(
210 const std::string& mid) const;
Taylor Brandstetterc3928662018-02-23 21:04:51211 // Caller owns returned certificate chain. This method mainly exists for
212 // stats reporting.
213 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain(
Zhi Huange818b6e2018-02-22 23:26:27214 const std::string& mid) const;
215 // Get negotiated role, if one has been negotiated.
Danil Chapovalov66cadcc2018-06-19 14:47:43216 absl::optional<rtc::SSLRole> GetDtlsRole(const std::string& mid) const;
Zhi Huange818b6e2018-02-22 23:26:27217
218 // TODO(deadbeef): GetStats isn't const because all the way down to
219 // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not
220 // const. Fix this.
221 bool GetStats(const std::string& mid, cricket::TransportStats* stats);
Zhi Huange818b6e2018-02-22 23:26:27222
Zhi Huange830e682018-03-30 17:48:35223 bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
Zhi Huang365381f2018-04-13 23:44:34224
Zhi Huangb57e1692018-06-12 18:41:11225 void SetActiveResetSrtpParams(bool active_reset_srtp_params);
226
Taylor Brandstetter8591eff2021-08-11 21:56:38227 RTCError RollbackTransports();
Eldar Rello5ab79e62019-10-09 15:29:44228
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22229 // F: void(const std::string&, const std::vector<cricket::Candidate>&)
230 template <typename F>
231 void SubscribeIceCandidateGathered(F&& callback) {
Tommic3257d02021-02-10 17:40:08232 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22233 signal_ice_candidates_gathered_.AddReceiver(std::forward<F>(callback));
234 }
235
236 // F: void(cricket::IceConnectionState)
237 template <typename F>
238 void SubscribeIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08239 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22240 signal_ice_connection_state_.AddReceiver(std::forward<F>(callback));
241 }
242
243 // F: void(PeerConnectionInterface::PeerConnectionState)
244 template <typename F>
245 void SubscribeConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08246 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22247 signal_connection_state_.AddReceiver(std::forward<F>(callback));
248 }
249
250 // F: void(PeerConnectionInterface::IceConnectionState)
251 template <typename F>
252 void SubscribeStandardizedIceConnectionState(F&& callback) {
Tommic3257d02021-02-10 17:40:08253 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22254 signal_standardized_ice_connection_state_.AddReceiver(
255 std::forward<F>(callback));
256 }
257
258 // F: void(cricket::IceGatheringState)
259 template <typename F>
260 void SubscribeIceGatheringState(F&& callback) {
Tommic3257d02021-02-10 17:40:08261 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22262 signal_ice_gathering_state_.AddReceiver(std::forward<F>(callback));
263 }
264
265 // F: void(const cricket::IceCandidateErrorEvent&)
266 template <typename F>
267 void SubscribeIceCandidateError(F&& callback) {
Tommic3257d02021-02-10 17:40:08268 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22269 signal_ice_candidate_error_.AddReceiver(std::forward<F>(callback));
270 }
271
272 // F: void(const std::vector<cricket::Candidate>&)
273 template <typename F>
274 void SubscribeIceCandidatesRemoved(F&& callback) {
Tommic3257d02021-02-10 17:40:08275 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22276 signal_ice_candidates_removed_.AddReceiver(std::forward<F>(callback));
277 }
278
279 // F: void(const cricket::CandidatePairChangeEvent&)
280 template <typename F>
281 void SubscribeIceCandidatePairChanged(F&& callback) {
Tommic3257d02021-02-10 17:40:08282 RTC_DCHECK_RUN_ON(network_thread_);
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22283 signal_ice_candidate_pair_changed_.AddReceiver(std::forward<F>(callback));
284 }
285
286 private:
Tommic3257d02021-02-10 17:40:08287 // All of these callbacks are fired on the network thread.
Zhi Huange818b6e2018-02-22 23:26:27288
289 // If any transport failed => failed,
290 // Else if all completed => completed,
291 // Else if all connected => connected,
292 // Else => connecting
Tommic3257d02021-02-10 17:40:08293 CallbackList<cricket::IceConnectionState> signal_ice_connection_state_
294 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27295
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22296 CallbackList<PeerConnectionInterface::PeerConnectionState>
Tommic3257d02021-02-10 17:40:08297 signal_connection_state_ RTC_GUARDED_BY(network_thread_);
Lahiru Ginnaliya Gamathigee99c68d2020-09-30 21:33:45298
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22299 CallbackList<PeerConnectionInterface::IceConnectionState>
Tommic3257d02021-02-10 17:40:08300 signal_standardized_ice_connection_state_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 13:58:17301
Zhi Huange818b6e2018-02-22 23:26:27302 // If all transports done gathering => complete,
303 // Else if any are gathering => gathering,
304 // Else => new
Tommic3257d02021-02-10 17:40:08305 CallbackList<cricket::IceGatheringState> signal_ice_gathering_state_
306 RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27307
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22308 // [mid, candidates]
309 CallbackList<const std::string&, const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08310 signal_ice_candidates_gathered_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27311
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22312 CallbackList<const cricket::IceCandidateErrorEvent&>
Tommic3257d02021-02-10 17:40:08313 signal_ice_candidate_error_ RTC_GUARDED_BY(network_thread_);
Eldar Relloda13ea22019-06-01 09:23:43314
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22315 CallbackList<const std::vector<cricket::Candidate>&>
Tommic3257d02021-02-10 17:40:08316 signal_ice_candidates_removed_ RTC_GUARDED_BY(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27317
Lahiru Ginnaliya Gamathige5eb527c2021-01-19 07:32:22318 CallbackList<const cricket::CandidatePairChangeEvent&>
Tommic3257d02021-02-10 17:40:08319 signal_ice_candidate_pair_changed_ RTC_GUARDED_BY(network_thread_);
Alex Drake00c7ecf2019-08-06 17:54:47320
Zhi Huange818b6e2018-02-22 23:26:27321 RTCError ApplyDescription_n(bool local,
322 SdpType type,
Niels Möller5cf0ef02021-01-18 13:00:36323 const cricket::SessionDescription* description)
324 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 19:04:26325 RTCError ValidateAndMaybeUpdateBundleGroups(
Zhi Huangd2248f82018-04-10 21:41:03326 bool local,
327 SdpType type,
328 const cricket::SessionDescription* description);
Zhi Huange830e682018-03-30 17:48:35329 RTCError ValidateContent(const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 23:26:27330
Harald Alvestrand11b92cf2021-06-17 14:03:09331 void HandleRejectedContent(const cricket::ContentInfo& content_info)
Niels Möller5cf0ef02021-01-18 13:00:36332 RTC_RUN_ON(network_thread_);
Henrik Boströmf8187e02021-04-26 19:04:26333 bool HandleBundledContent(const cricket::ContentInfo& content_info,
334 const cricket::ContentGroup& bundle_group)
Niels Möller5cf0ef02021-01-18 13:00:36335 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27336
337 cricket::JsepTransportDescription CreateJsepTransportDescription(
Harald Alvestrand1716d392019-06-03 18:35:45338 const cricket::ContentInfo& content_info,
339 const cricket::TransportInfo& transport_info,
Zhi Huange830e682018-03-30 17:48:35340 const std::vector<int>& encrypted_extension_ids,
Niels Möllerdc80aaf2020-06-18 08:10:17341 int rtp_abs_sendtime_extn_id);
Zhi Huange818b6e2018-02-22 23:26:27342
Henrik Boströmf8187e02021-04-26 19:04:26343 std::map<const cricket::ContentGroup*, std::vector<int>>
344 MergeEncryptedHeaderExtensionIdsForBundles(
Zhi Huange818b6e2018-02-22 23:26:27345 const cricket::SessionDescription* description);
Zhi Huange818b6e2018-02-22 23:26:27346 std::vector<int> GetEncryptedHeaderExtensionIds(
347 const cricket::ContentInfo& content_info);
348
Zhi Huange830e682018-03-30 17:48:35349 int GetRtpAbsSendTimeHeaderExtensionId(
350 const cricket::ContentInfo& content_info);
Zhi Huange818b6e2018-02-22 23:26:27351
Zhi Huange830e682018-03-30 17:48:35352 // This method takes the BUNDLE group into account. If the JsepTransport is
353 // destroyed because of BUNDLE, it would return the transport which other
354 // transports are bundled on (In current implementation, it is the first
355 // content in the BUNDLE group).
Zhi Huang365381f2018-04-13 23:44:34356 const cricket::JsepTransport* GetJsepTransportForMid(
Tomas Gunnarsson92eebef2021-02-10 12:05:44357 const std::string& mid) const RTC_RUN_ON(network_thread_);
358 cricket::JsepTransport* GetJsepTransportForMid(const std::string& mid)
359 RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 17:48:35360
361 // Get the JsepTransport without considering the BUNDLE group. Return nullptr
362 // if the JsepTransport is destroyed.
Zhi Huang365381f2018-04-13 23:44:34363 const cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 09:22:50364 const std::string& transport_name) const RTC_RUN_ON(network_thread_);
Zhi Huang365381f2018-04-13 23:44:34365 cricket::JsepTransport* GetJsepTransportByName(
Tomas Gunnarsson20f74562021-02-04 09:22:50366 const std::string& transport_name) RTC_RUN_ON(network_thread_);
Zhi Huange830e682018-03-30 17:48:35367
Anton Sukhanov7940da02018-10-10 17:34:49368 // Creates jsep transport. Noop if transport is already created.
Artem Titov880fa812021-07-30 20:30:23369 // Transport is created either during SetLocalDescription (`local` == true) or
370 // during SetRemoteDescription (`local` == false). Passing `local` helps to
Anton Sukhanov7940da02018-10-10 17:34:49371 // differentiate initiator (caller) from answerer (callee).
Piotr (Peter) Slatala105ded32019-02-27 22:26:15372 RTCError MaybeCreateJsepTransport(
373 bool local,
374 const cricket::ContentInfo& content_info,
Niels Möller5cf0ef02021-01-18 13:00:36375 const cricket::SessionDescription& description)
376 RTC_RUN_ON(network_thread_);
Piotr (Peter) Slatala47dfdca2018-11-16 22:13:58377
Niels Möller5cf0ef02021-01-18 13:00:36378 void DestroyAllJsepTransports_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27379
Niels Möller5cf0ef02021-01-18 13:00:36380 void SetIceRole_n(cricket::IceRole ice_role) RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27381
382 cricket::IceRole DetermineIceRole(
Zhi Huang365381f2018-04-13 23:44:34383 cricket::JsepTransport* jsep_transport,
Zhi Huange818b6e2018-02-22 23:26:27384 const cricket::TransportInfo& transport_info,
385 SdpType type,
386 bool local);
387
388 std::unique_ptr<cricket::DtlsTransportInternal> CreateDtlsTransport(
Anton Sukhanovac6c0962019-07-10 22:44:56389 const cricket::ContentInfo& content_info,
Niels Möller2a707032020-06-16 14:39:13390 cricket::IceTransportInternal* ice);
Qingsi Wang25ec8882019-11-15 20:33:05391 rtc::scoped_refptr<webrtc::IceTransportInterface> CreateIceTransport(
392 const std::string& transport_name,
Zhi Huange818b6e2018-02-22 23:26:27393 bool rtcp);
394
395 std::unique_ptr<webrtc::RtpTransport> CreateUnencryptedRtpTransport(
396 const std::string& transport_name,
397 rtc::PacketTransportInternal* rtp_packet_transport,
398 rtc::PacketTransportInternal* rtcp_packet_transport);
399 std::unique_ptr<webrtc::SrtpTransport> CreateSdesTransport(
400 const std::string& transport_name,
Zhi Huange830e682018-03-30 17:48:35401 cricket::DtlsTransportInternal* rtp_dtls_transport,
402 cricket::DtlsTransportInternal* rtcp_dtls_transport);
Zhi Huange818b6e2018-02-22 23:26:27403 std::unique_ptr<webrtc::DtlsSrtpTransport> CreateDtlsSrtpTransport(
404 const std::string& transport_name,
405 cricket::DtlsTransportInternal* rtp_dtls_transport,
406 cricket::DtlsTransportInternal* rtcp_dtls_transport);
407
408 // Collect all the DtlsTransports, including RTP and RTCP, from the
Taylor Brandstetter8591eff2021-08-11 21:56:38409 // JsepTransports, including those not mapped to a MID because they are being
410 // kept alive in case of rollback.
Zhi Huange818b6e2018-02-22 23:26:27411 std::vector<cricket::DtlsTransportInternal*> GetDtlsTransports();
Taylor Brandstetter8591eff2021-08-11 21:56:38412 // Same as the above, but doesn't include rollback transports.
413 // JsepTransportController can iterate all the DtlsTransports and update the
414 // aggregate states.
415 std::vector<cricket::DtlsTransportInternal*> GetActiveDtlsTransports();
Zhi Huange818b6e2018-02-22 23:26:27416
417 // Handlers for signals from Transport.
Niels Möller5cf0ef02021-01-18 13:00:36418 void OnTransportWritableState_n(rtc::PacketTransportInternal* transport)
419 RTC_RUN_ON(network_thread_);
420 void OnTransportReceivingState_n(rtc::PacketTransportInternal* transport)
421 RTC_RUN_ON(network_thread_);
422 void OnTransportGatheringState_n(cricket::IceTransportInternal* transport)
423 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27424 void OnTransportCandidateGathered_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 13:00:36425 const cricket::Candidate& candidate)
426 RTC_RUN_ON(network_thread_);
427 void OnTransportCandidateError_n(cricket::IceTransportInternal* transport,
428 const cricket::IceCandidateErrorEvent& event)
429 RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27430 void OnTransportCandidatesRemoved_n(cricket::IceTransportInternal* transport,
Niels Möller5cf0ef02021-01-18 13:00:36431 const cricket::Candidates& candidates)
432 RTC_RUN_ON(network_thread_);
433 void OnTransportRoleConflict_n(cricket::IceTransportInternal* transport)
434 RTC_RUN_ON(network_thread_);
435 void OnTransportStateChanged_n(cricket::IceTransportInternal* transport)
436 RTC_RUN_ON(network_thread_);
Alex Drake00c7ecf2019-08-06 17:54:47437 void OnTransportCandidatePairChanged_n(
Niels Möller5cf0ef02021-01-18 13:00:36438 const cricket::CandidatePairChangeEvent& event)
439 RTC_RUN_ON(network_thread_);
440 void UpdateAggregateStates_n() RTC_RUN_ON(network_thread_);
Zhi Huange818b6e2018-02-22 23:26:27441
Sebastian Jansson1b83a9e2019-09-18 16:22:12442 void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer* packet,
Niels Möller5cf0ef02021-01-18 13:00:36443 int64_t packet_time_us)
444 RTC_RUN_ON(network_thread_);
Sebastian Jansson1b83a9e2019-09-18 16:22:12445
Zhi Huange818b6e2018-02-22 23:26:27446 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
447
Harald Alvestrand9dea3932021-06-10 06:03:06448 bool OnTransportChanged(const std::string& mid,
449 cricket::JsepTransport* transport);
450
Zhi Huange818b6e2018-02-22 23:26:27451 rtc::Thread* const network_thread_ = nullptr;
452 cricket::PortAllocator* const port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04453 AsyncDnsResolverFactoryInterface* const async_dns_resolver_factory_ = nullptr;
Zhi Huange818b6e2018-02-22 23:26:27454
Harald Alvestrand9dea3932021-06-10 06:03:06455 JsepTransportCollection transports_ RTC_GUARDED_BY(network_thread_);
Jonas Olsson635474e2018-10-18 13:58:17456 // Aggregate states for Transports.
Alex Loiko9289eda2018-11-23 16:18:59457 // standardized_ice_connection_state_ is intended to replace
458 // ice_connection_state, see bugs.webrtc.org/9308
459 cricket::IceConnectionState ice_connection_state_ =
460 cricket::kIceConnectionConnecting;
461 PeerConnectionInterface::IceConnectionState
462 standardized_ice_connection_state_ =
463 PeerConnectionInterface::kIceConnectionNew;
Jonas Olsson635474e2018-10-18 13:58:17464 PeerConnectionInterface::PeerConnectionState combined_connection_state_ =
465 PeerConnectionInterface::PeerConnectionState::kNew;
Zhi Huange818b6e2018-02-22 23:26:27466 cricket::IceGatheringState ice_gathering_state_ = cricket::kIceGatheringNew;
467
Harald Alvestrand133c0522021-01-29 14:27:12468 const Config config_;
469 bool active_reset_srtp_params_ RTC_GUARDED_BY(network_thread_);
Piotr (Peter) Slatalab1ae10b2019-03-01 19:14:05470
Zhi Huange818b6e2018-02-22 23:26:27471 const cricket::SessionDescription* local_desc_ = nullptr;
472 const cricket::SessionDescription* remote_desc_ = nullptr;
Danil Chapovalov66cadcc2018-06-19 14:47:43473 absl::optional<bool> initial_offerer_;
Zhi Huange818b6e2018-02-22 23:26:27474
Zhi Huange818b6e2018-02-22 23:26:27475 cricket::IceConfig ice_config_;
476 cricket::IceRole ice_role_ = cricket::ICEROLE_CONTROLLING;
477 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
478 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
Zhi Huange818b6e2018-02-22 23:26:27479
Harald Alvestrand9f9bf382021-06-08 04:12:37480 BundleManager bundles_;
481
Zhi Huange818b6e2018-02-22 23:26:27482 RTC_DISALLOW_COPY_AND_ASSIGN(JsepTransportController);
483};
484
485} // namespace webrtc
486
Steve Anton10542f22019-01-11 17:11:00487#endif // PC_JSEP_TRANSPORT_CONTROLLER_H_