ice_transport_interface.h (5663B)
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 14 #include <string> 15 16 #include "api/async_dns_resolver.h" 17 #include "api/environment/environment.h" 18 #include "api/local_network_access_permission.h" 19 #include "api/ref_count.h" 20 #include "api/rtc_event_log/rtc_event_log.h" 21 #include "api/scoped_refptr.h" 22 23 namespace webrtc { 24 25 class ActiveIceControllerFactoryInterface; 26 class FieldTrialsView; 27 class IceControllerFactoryInterface; 28 class IceTransportInternal; 29 class PortAllocator; 30 31 // An ICE transport, as represented to the outside world. 32 // This object is refcounted, and is therefore alive until the 33 // last holder has released it. 34 class IceTransportInterface : public RefCountInterface { 35 public: 36 // Accessor for the internal representation of an ICE transport. 37 // The returned object can only be safely used on the signalling thread. 38 // TODO(crbug.com/907849): Add API calls for the functions that have to 39 // be exposed to clients, and stop allowing access to the 40 // IceTransportInternal API. 41 virtual IceTransportInternal* internal() = 0; 42 }; 43 44 class IceTransportInit final { 45 public: 46 explicit IceTransportInit(const Environment& env) : env_(env) {} 47 IceTransportInit(const IceTransportInit&) = delete; 48 IceTransportInit(IceTransportInit&&) = default; 49 IceTransportInit& operator=(const IceTransportInit&) = delete; 50 IceTransportInit& operator=(IceTransportInit&&) = default; 51 52 PortAllocator* port_allocator() { return port_allocator_; } 53 void set_port_allocator(PortAllocator* port_allocator) { 54 port_allocator_ = port_allocator; 55 } 56 57 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory() { 58 return async_dns_resolver_factory_; 59 } 60 void set_async_dns_resolver_factory( 61 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory) { 62 async_dns_resolver_factory_ = async_dns_resolver_factory; 63 } 64 65 LocalNetworkAccessPermissionFactoryInterface* lna_permission_factory() { 66 return lna_permission_factory_; 67 } 68 69 void set_lna_permission_factory( 70 LocalNetworkAccessPermissionFactoryInterface* lna_permission_factory) { 71 lna_permission_factory_ = lna_permission_factory; 72 } 73 74 RtcEventLog* event_log() { return &env_.event_log(); } 75 76 void set_ice_controller_factory( 77 IceControllerFactoryInterface* ice_controller_factory) { 78 ice_controller_factory_ = ice_controller_factory; 79 } 80 IceControllerFactoryInterface* ice_controller_factory() { 81 return ice_controller_factory_; 82 } 83 84 // An active ICE controller actively manages the connection used by an ICE 85 // transport, in contrast with a legacy ICE controller that only picks the 86 // best connection to use or ping, and lets the transport decide when and 87 // whether to switch. 88 // 89 // Which ICE controller is used is determined as follows: 90 // 91 // 1. If an active ICE controller factory is supplied, it is used and 92 // the legacy ICE controller factory is not used. 93 // 2. If not, a default active ICE controller is used, wrapping over the 94 // supplied or the default legacy ICE controller. 95 void set_active_ice_controller_factory( 96 ActiveIceControllerFactoryInterface* active_ice_controller_factory) { 97 active_ice_controller_factory_ = active_ice_controller_factory; 98 } 99 ActiveIceControllerFactoryInterface* active_ice_controller_factory() { 100 return active_ice_controller_factory_; 101 } 102 103 const FieldTrialsView* field_trials() { return &env_.field_trials(); } 104 105 const Environment& env() { return env_; } 106 107 private: 108 Environment env_; 109 PortAllocator* port_allocator_ = nullptr; 110 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory_ = nullptr; 111 LocalNetworkAccessPermissionFactoryInterface* lna_permission_factory_ = 112 nullptr; 113 IceControllerFactoryInterface* ice_controller_factory_ = nullptr; 114 ActiveIceControllerFactoryInterface* active_ice_controller_factory_ = nullptr; 115 // TODO(https://crbug.com/webrtc/12657): Redesign to have const members. 116 }; 117 118 // TODO(qingsi): The factory interface is defined in this file instead of its 119 // namesake file ice_transport_factory.h to avoid the extra dependency on p2p/ 120 // introduced there by the p2p/-dependent factory methods. Move the factory 121 // methods to a different file or rename it. 122 class IceTransportFactory { 123 public: 124 virtual ~IceTransportFactory() = default; 125 // As a refcounted object, the returned ICE transport may outlive the host 126 // construct into which its reference is given, e.g. a peer connection. As a 127 // result, the returned ICE transport should not hold references to any object 128 // that the transport does not own and that has a lifetime bound to the host 129 // construct. Also, assumptions on the thread safety of the returned transport 130 // should be clarified by implementations. For example, a peer connection 131 // requires the returned transport to be constructed and destroyed on the 132 // network thread and an ICE transport factory that intends to work with a 133 // peer connection should offer transports compatible with these assumptions. 134 virtual scoped_refptr<IceTransportInterface> CreateIceTransport( 135 const std::string& transport_name, 136 int component, 137 IceTransportInit init) = 0; 138 }; 139 140 } // namespace webrtc 141 #endif // API_ICE_TRANSPORT_INTERFACE_H_