Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [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 20:33:05 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 | [diff] [blame] | 16 | #include "api/async_dns_resolver.h" |
Qingsi Wang | 25ec888 | 2019-11-15 20:33:05 | [diff] [blame] | 17 | #include "api/async_resolver_factory.h" |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 18 | #include "api/rtc_error.h" |
Qingsi Wang | 25ec888 | 2019-11-15 20:33:05 | [diff] [blame] | 19 | #include "api/rtc_event_log/rtc_event_log.h" |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [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 20:33:05 | [diff] [blame] | 25 | class PortAllocator; |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 26 | } // namespace cricket |
| 27 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | // An ICE transport, as represented to the outside world. |
| 31 | // This object is refcounted, and is therefore alive until the |
| 32 | // last holder has released it. |
| 33 | class IceTransportInterface : public rtc::RefCountInterface { |
| 34 | public: |
| 35 | // Accessor for the internal representation of an ICE transport. |
| 36 | // The returned object can only be safely used on the signalling thread. |
| 37 | // TODO(crbug.com/907849): Add API calls for the functions that have to |
| 38 | // be exposed to clients, and stop allowing access to the |
| 39 | // cricket::IceTransportInternal API. |
| 40 | virtual cricket::IceTransportInternal* internal() = 0; |
| 41 | }; |
| 42 | |
Qingsi Wang | 25ec888 | 2019-11-15 20:33:05 | [diff] [blame] | 43 | struct IceTransportInit final { |
| 44 | public: |
| 45 | IceTransportInit() = default; |
| 46 | IceTransportInit(const IceTransportInit&) = delete; |
| 47 | IceTransportInit(IceTransportInit&&) = default; |
| 48 | IceTransportInit& operator=(const IceTransportInit&) = delete; |
| 49 | IceTransportInit& operator=(IceTransportInit&&) = default; |
| 50 | |
| 51 | cricket::PortAllocator* port_allocator() { return port_allocator_; } |
| 52 | void set_port_allocator(cricket::PortAllocator* port_allocator) { |
| 53 | port_allocator_ = port_allocator; |
| 54 | } |
| 55 | |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 | [diff] [blame] | 56 | AsyncDnsResolverFactoryInterface* async_dns_resolver_factory() { |
| 57 | return async_dns_resolver_factory_; |
| 58 | } |
| 59 | void set_async_dns_resolver_factory( |
| 60 | AsyncDnsResolverFactoryInterface* async_dns_resolver_factory) { |
| 61 | RTC_DCHECK(!async_resolver_factory_); |
| 62 | async_dns_resolver_factory_ = async_dns_resolver_factory; |
| 63 | } |
Qingsi Wang | 25ec888 | 2019-11-15 20:33:05 | [diff] [blame] | 64 | AsyncResolverFactory* async_resolver_factory() { |
| 65 | return async_resolver_factory_; |
| 66 | } |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 | [diff] [blame] | 67 | ABSL_DEPRECATED("bugs.webrtc.org/12598") |
Qingsi Wang | 25ec888 | 2019-11-15 20:33:05 | [diff] [blame] | 68 | void set_async_resolver_factory( |
| 69 | AsyncResolverFactory* async_resolver_factory) { |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 | [diff] [blame] | 70 | RTC_DCHECK(!async_dns_resolver_factory_); |
Qingsi Wang | 25ec888 | 2019-11-15 20:33:05 | [diff] [blame] | 71 | async_resolver_factory_ = async_resolver_factory; |
| 72 | } |
| 73 | |
| 74 | RtcEventLog* event_log() { return event_log_; } |
| 75 | void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; } |
| 76 | |
| 77 | private: |
| 78 | cricket::PortAllocator* port_allocator_ = nullptr; |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 | [diff] [blame] | 79 | AsyncDnsResolverFactoryInterface* async_dns_resolver_factory_ = nullptr; |
| 80 | // For backwards compatibility. Only one resolver factory can be set. |
Qingsi Wang | 25ec888 | 2019-11-15 20:33:05 | [diff] [blame] | 81 | AsyncResolverFactory* async_resolver_factory_ = nullptr; |
| 82 | RtcEventLog* event_log_ = nullptr; |
Harald Alvestrand | 0ccfbd2 | 2021-04-08 07:25:04 | [diff] [blame] | 83 | // TODO(https://crbug.com/webrtc/12657): Redesign to have const members. |
Qingsi Wang | 25ec888 | 2019-11-15 20:33:05 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | // TODO(qingsi): The factory interface is defined in this file instead of its |
| 87 | // namesake file ice_transport_factory.h to avoid the extra dependency on p2p/ |
| 88 | // introduced there by the p2p/-dependent factory methods. Move the factory |
| 89 | // methods to a different file or rename it. |
| 90 | class IceTransportFactory { |
| 91 | public: |
| 92 | virtual ~IceTransportFactory() = default; |
| 93 | // As a refcounted object, the returned ICE transport may outlive the host |
| 94 | // construct into which its reference is given, e.g. a peer connection. As a |
| 95 | // result, the returned ICE transport should not hold references to any object |
| 96 | // that the transport does not own and that has a lifetime bound to the host |
| 97 | // construct. Also, assumptions on the thread safety of the returned transport |
| 98 | // should be clarified by implementations. For example, a peer connection |
| 99 | // requires the returned transport to be constructed and destroyed on the |
| 100 | // network thread and an ICE transport factory that intends to work with a |
| 101 | // peer connection should offer transports compatible with these assumptions. |
| 102 | virtual rtc::scoped_refptr<IceTransportInterface> CreateIceTransport( |
| 103 | const std::string& transport_name, |
| 104 | int component, |
| 105 | IceTransportInit init) = 0; |
| 106 | }; |
| 107 | |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 108 | } // namespace webrtc |
| 109 | #endif // API_ICE_TRANSPORT_INTERFACE_H_ |