blob: 9d8bd5abe3187dca4c70a84e1c38fdb9db7a6a4e [file] [log] [blame]
Harald Alvestrand98462622019-01-30 14:57:03 +01001/*
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 Wang25ec8882019-11-15 12:33:05 -080014#include <string>
15
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000016#include "api/async_dns_resolver.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080017#include "api/async_resolver_factory.h"
Harald Alvestrand98462622019-01-30 14:57:03 +010018#include "api/rtc_error.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080019#include "api/rtc_event_log/rtc_event_log.h"
Harald Alvestrand98462622019-01-30 14:57:03 +010020#include "api/scoped_refptr.h"
21#include "rtc_base/ref_count.h"
22
23namespace cricket {
24class IceTransportInternal;
Qingsi Wang25ec8882019-11-15 12:33:05 -080025class PortAllocator;
Jonas Oreland7ddc7d52022-03-16 12:21:52 +010026class IceControllerFactoryInterface;
Harald Alvestrand98462622019-01-30 14:57:03 +010027} // namespace cricket
28
29namespace webrtc {
Jonas Orelande62c2f22022-03-29 11:04:48 +020030class FieldTrialsView;
Harald Alvestrand98462622019-01-30 14:57:03 +010031
32// An ICE transport, as represented to the outside world.
33// This object is refcounted, and is therefore alive until the
34// last holder has released it.
35class IceTransportInterface : public rtc::RefCountInterface {
36 public:
37 // Accessor for the internal representation of an ICE transport.
38 // The returned object can only be safely used on the signalling thread.
39 // TODO(crbug.com/907849): Add API calls for the functions that have to
40 // be exposed to clients, and stop allowing access to the
41 // cricket::IceTransportInternal API.
42 virtual cricket::IceTransportInternal* internal() = 0;
43};
44
Qingsi Wang25ec8882019-11-15 12:33:05 -080045struct IceTransportInit final {
46 public:
47 IceTransportInit() = default;
48 IceTransportInit(const IceTransportInit&) = delete;
49 IceTransportInit(IceTransportInit&&) = default;
50 IceTransportInit& operator=(const IceTransportInit&) = delete;
51 IceTransportInit& operator=(IceTransportInit&&) = default;
52
53 cricket::PortAllocator* port_allocator() { return port_allocator_; }
54 void set_port_allocator(cricket::PortAllocator* port_allocator) {
55 port_allocator_ = port_allocator;
56 }
57
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000058 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory() {
59 return async_dns_resolver_factory_;
60 }
61 void set_async_dns_resolver_factory(
62 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory) {
63 RTC_DCHECK(!async_resolver_factory_);
64 async_dns_resolver_factory_ = async_dns_resolver_factory;
65 }
Qingsi Wang25ec8882019-11-15 12:33:05 -080066 AsyncResolverFactory* async_resolver_factory() {
67 return async_resolver_factory_;
68 }
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000069 ABSL_DEPRECATED("bugs.webrtc.org/12598")
Qingsi Wang25ec8882019-11-15 12:33:05 -080070 void set_async_resolver_factory(
71 AsyncResolverFactory* async_resolver_factory) {
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000072 RTC_DCHECK(!async_dns_resolver_factory_);
Qingsi Wang25ec8882019-11-15 12:33:05 -080073 async_resolver_factory_ = async_resolver_factory;
74 }
75
76 RtcEventLog* event_log() { return event_log_; }
77 void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; }
78
Jonas Oreland7ddc7d52022-03-16 12:21:52 +010079 void set_ice_controller_factory(
80 cricket::IceControllerFactoryInterface* ice_controller_factory) {
81 ice_controller_factory_ = ice_controller_factory;
82 }
83 cricket::IceControllerFactoryInterface* ice_controller_factory() {
84 return ice_controller_factory_;
85 }
86
Jonas Orelande62c2f22022-03-29 11:04:48 +020087 const FieldTrialsView* field_trials() { return field_trials_; }
88 void set_field_trials(const FieldTrialsView* field_trials) {
Jonas Oreland340cb5e2022-03-17 09:14:16 +010089 field_trials_ = field_trials;
90 }
91
Qingsi Wang25ec8882019-11-15 12:33:05 -080092 private:
93 cricket::PortAllocator* port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000094 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory_ = nullptr;
95 // For backwards compatibility. Only one resolver factory can be set.
Qingsi Wang25ec8882019-11-15 12:33:05 -080096 AsyncResolverFactory* async_resolver_factory_ = nullptr;
97 RtcEventLog* event_log_ = nullptr;
Jonas Oreland7ddc7d52022-03-16 12:21:52 +010098 cricket::IceControllerFactoryInterface* ice_controller_factory_ = nullptr;
Jonas Orelande62c2f22022-03-29 11:04:48 +020099 const FieldTrialsView* field_trials_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +0000100 // TODO(https://crbug.com/webrtc/12657): Redesign to have const members.
Qingsi Wang25ec8882019-11-15 12:33:05 -0800101};
102
103// TODO(qingsi): The factory interface is defined in this file instead of its
104// namesake file ice_transport_factory.h to avoid the extra dependency on p2p/
105// introduced there by the p2p/-dependent factory methods. Move the factory
106// methods to a different file or rename it.
107class IceTransportFactory {
108 public:
109 virtual ~IceTransportFactory() = default;
110 // As a refcounted object, the returned ICE transport may outlive the host
111 // construct into which its reference is given, e.g. a peer connection. As a
112 // result, the returned ICE transport should not hold references to any object
113 // that the transport does not own and that has a lifetime bound to the host
114 // construct. Also, assumptions on the thread safety of the returned transport
115 // should be clarified by implementations. For example, a peer connection
116 // requires the returned transport to be constructed and destroyed on the
117 // network thread and an ICE transport factory that intends to work with a
118 // peer connection should offer transports compatible with these assumptions.
119 virtual rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
120 const std::string& transport_name,
121 int component,
122 IceTransportInit init) = 0;
123};
124
Harald Alvestrand98462622019-01-30 14:57:03 +0100125} // namespace webrtc
126#endif // API_ICE_TRANSPORT_INTERFACE_H_