Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | |
| 11 | #ifndef API_ICE_TRANSPORT_INTERFACE_H_ |
| 12 | #define API_ICE_TRANSPORT_INTERFACE_H_ |
| 13 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 16 | #include "api/async_dns_resolver.h" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 17 | #include "api/async_resolver_factory.h" |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 18 | #include "api/rtc_error.h" |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 19 | #include "api/rtc_event_log/rtc_event_log.h" |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 20 | #include "api/scoped_refptr.h" |
| 21 | #include "rtc_base/ref_count.h" |
| 22 | |
| 23 | namespace cricket { |
| 24 | class IceTransportInternal; |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 25 | class PortAllocator; |
Jonas Oreland | 7ddc7d5 | 2022-03-16 12:21:52 +0100 | [diff] [blame] | 26 | class IceControllerFactoryInterface; |
Sameer Vijaykar | 6fa8a75 | 2022-09-14 11:48:54 +0200 | [diff] [blame^] | 27 | class ActiveIceControllerFactoryInterface; |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 28 | } // namespace cricket |
| 29 | |
| 30 | namespace webrtc { |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 31 | class FieldTrialsView; |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 32 | |
| 33 | // An ICE transport, as represented to the outside world. |
| 34 | // This object is refcounted, and is therefore alive until the |
| 35 | // last holder has released it. |
| 36 | class IceTransportInterface : public rtc::RefCountInterface { |
| 37 | public: |
| 38 | // Accessor for the internal representation of an ICE transport. |
| 39 | // The returned object can only be safely used on the signalling thread. |
| 40 | // TODO(crbug.com/907849): Add API calls for the functions that have to |
| 41 | // be exposed to clients, and stop allowing access to the |
| 42 | // cricket::IceTransportInternal API. |
| 43 | virtual cricket::IceTransportInternal* internal() = 0; |
| 44 | }; |
| 45 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 46 | struct IceTransportInit final { |
| 47 | public: |
| 48 | IceTransportInit() = default; |
| 49 | IceTransportInit(const IceTransportInit&) = delete; |
| 50 | IceTransportInit(IceTransportInit&&) = default; |
| 51 | IceTransportInit& operator=(const IceTransportInit&) = delete; |
| 52 | IceTransportInit& operator=(IceTransportInit&&) = default; |
| 53 | |
| 54 | cricket::PortAllocator* port_allocator() { return port_allocator_; } |
| 55 | void set_port_allocator(cricket::PortAllocator* port_allocator) { |
| 56 | port_allocator_ = port_allocator; |
| 57 | } |
| 58 | |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 59 | AsyncDnsResolverFactoryInterface* async_dns_resolver_factory() { |
| 60 | return async_dns_resolver_factory_; |
| 61 | } |
| 62 | void set_async_dns_resolver_factory( |
| 63 | AsyncDnsResolverFactoryInterface* async_dns_resolver_factory) { |
| 64 | RTC_DCHECK(!async_resolver_factory_); |
| 65 | async_dns_resolver_factory_ = async_dns_resolver_factory; |
| 66 | } |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 67 | AsyncResolverFactory* async_resolver_factory() { |
| 68 | return async_resolver_factory_; |
| 69 | } |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 70 | ABSL_DEPRECATED("bugs.webrtc.org/12598") |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 71 | void set_async_resolver_factory( |
| 72 | AsyncResolverFactory* async_resolver_factory) { |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 73 | RTC_DCHECK(!async_dns_resolver_factory_); |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 74 | async_resolver_factory_ = async_resolver_factory; |
| 75 | } |
| 76 | |
| 77 | RtcEventLog* event_log() { return event_log_; } |
| 78 | void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; } |
| 79 | |
Jonas Oreland | 7ddc7d5 | 2022-03-16 12:21:52 +0100 | [diff] [blame] | 80 | void set_ice_controller_factory( |
| 81 | cricket::IceControllerFactoryInterface* ice_controller_factory) { |
| 82 | ice_controller_factory_ = ice_controller_factory; |
| 83 | } |
| 84 | cricket::IceControllerFactoryInterface* ice_controller_factory() { |
| 85 | return ice_controller_factory_; |
| 86 | } |
| 87 | |
Sameer Vijaykar | 6fa8a75 | 2022-09-14 11:48:54 +0200 | [diff] [blame^] | 88 | // An active ICE controller actively manages the connection used by an ICE |
| 89 | // transport, in contrast with a legacy ICE controller that only picks the |
| 90 | // best connection to use or ping, and lets the transport decide when and |
| 91 | // whether to switch. |
| 92 | // TODO(bugs.webrtc.org/14367): currently unused, update doc when used. |
| 93 | void set_active_ice_controller_factory( |
| 94 | cricket::ActiveIceControllerFactoryInterface* |
| 95 | active_ice_controller_factory) { |
| 96 | active_ice_controller_factory_ = active_ice_controller_factory; |
| 97 | } |
| 98 | cricket::ActiveIceControllerFactoryInterface* |
| 99 | active_ice_controller_factory() { |
| 100 | return active_ice_controller_factory_; |
| 101 | } |
| 102 | |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 103 | const FieldTrialsView* field_trials() { return field_trials_; } |
| 104 | void set_field_trials(const FieldTrialsView* field_trials) { |
Jonas Oreland | 340cb5e | 2022-03-17 09:14:16 +0100 | [diff] [blame] | 105 | field_trials_ = field_trials; |
| 106 | } |
| 107 | |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 108 | private: |
| 109 | cricket::PortAllocator* port_allocator_ = nullptr; |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 110 | AsyncDnsResolverFactoryInterface* async_dns_resolver_factory_ = nullptr; |
| 111 | // For backwards compatibility. Only one resolver factory can be set. |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 112 | AsyncResolverFactory* async_resolver_factory_ = nullptr; |
| 113 | RtcEventLog* event_log_ = nullptr; |
Jonas Oreland | 7ddc7d5 | 2022-03-16 12:21:52 +0100 | [diff] [blame] | 114 | cricket::IceControllerFactoryInterface* ice_controller_factory_ = nullptr; |
Sameer Vijaykar | 6fa8a75 | 2022-09-14 11:48:54 +0200 | [diff] [blame^] | 115 | cricket::ActiveIceControllerFactoryInterface* active_ice_controller_factory_ = |
| 116 | nullptr; |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame] | 117 | const FieldTrialsView* field_trials_ = nullptr; |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 +0000 | [diff] [blame] | 118 | // TODO(https://crbug.com/webrtc/12657): Redesign to have const members. |
Qingsi Wang | 25ec888 | 2019-11-15 12:33:05 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | // TODO(qingsi): The factory interface is defined in this file instead of its |
| 122 | // namesake file ice_transport_factory.h to avoid the extra dependency on p2p/ |
| 123 | // introduced there by the p2p/-dependent factory methods. Move the factory |
| 124 | // methods to a different file or rename it. |
| 125 | class IceTransportFactory { |
| 126 | public: |
| 127 | virtual ~IceTransportFactory() = default; |
| 128 | // As a refcounted object, the returned ICE transport may outlive the host |
| 129 | // construct into which its reference is given, e.g. a peer connection. As a |
| 130 | // result, the returned ICE transport should not hold references to any object |
| 131 | // that the transport does not own and that has a lifetime bound to the host |
| 132 | // construct. Also, assumptions on the thread safety of the returned transport |
| 133 | // should be clarified by implementations. For example, a peer connection |
| 134 | // requires the returned transport to be constructed and destroyed on the |
| 135 | // network thread and an ICE transport factory that intends to work with a |
| 136 | // peer connection should offer transports compatible with these assumptions. |
| 137 | virtual rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 138 | const std::string& transport_name, |
| 139 | int component, |
| 140 | IceTransportInit init) = 0; |
| 141 | }; |
| 142 | |
Harald Alvestrand | 9846262 | 2019-01-30 14:57:03 +0100 | [diff] [blame] | 143 | } // namespace webrtc |
| 144 | #endif // API_ICE_TRANSPORT_INTERFACE_H_ |