blob: f202658acf1b9c7580ca83baffb846df7e9e63ba [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 {
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.
34class IceTransportInterface : public rtc::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 // cricket::IceTransportInternal API.
41 virtual cricket::IceTransportInternal* internal() = 0;
42};
43
Qingsi Wang25ec8882019-11-15 12:33:05 -080044struct IceTransportInit final {
45 public:
46 IceTransportInit() = default;
47 IceTransportInit(const IceTransportInit&) = delete;
48 IceTransportInit(IceTransportInit&&) = default;
49 IceTransportInit& operator=(const IceTransportInit&) = delete;
50 IceTransportInit& operator=(IceTransportInit&&) = default;
51
52 cricket::PortAllocator* port_allocator() { return port_allocator_; }
53 void set_port_allocator(cricket::PortAllocator* port_allocator) {
54 port_allocator_ = port_allocator;
55 }
56
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000057 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 RTC_DCHECK(!async_resolver_factory_);
63 async_dns_resolver_factory_ = async_dns_resolver_factory;
64 }
Qingsi Wang25ec8882019-11-15 12:33:05 -080065 AsyncResolverFactory* async_resolver_factory() {
66 return async_resolver_factory_;
67 }
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000068 ABSL_DEPRECATED("bugs.webrtc.org/12598")
Qingsi Wang25ec8882019-11-15 12:33:05 -080069 void set_async_resolver_factory(
70 AsyncResolverFactory* async_resolver_factory) {
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000071 RTC_DCHECK(!async_dns_resolver_factory_);
Qingsi Wang25ec8882019-11-15 12:33:05 -080072 async_resolver_factory_ = async_resolver_factory;
73 }
74
75 RtcEventLog* event_log() { return event_log_; }
76 void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; }
77
Jonas Oreland7ddc7d52022-03-16 12:21:52 +010078 void set_ice_controller_factory(
79 cricket::IceControllerFactoryInterface* ice_controller_factory) {
80 ice_controller_factory_ = ice_controller_factory;
81 }
82 cricket::IceControllerFactoryInterface* ice_controller_factory() {
83 return ice_controller_factory_;
84 }
85
Qingsi Wang25ec8882019-11-15 12:33:05 -080086 private:
87 cricket::PortAllocator* port_allocator_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000088 AsyncDnsResolverFactoryInterface* async_dns_resolver_factory_ = nullptr;
89 // For backwards compatibility. Only one resolver factory can be set.
Qingsi Wang25ec8882019-11-15 12:33:05 -080090 AsyncResolverFactory* async_resolver_factory_ = nullptr;
91 RtcEventLog* event_log_ = nullptr;
Jonas Oreland7ddc7d52022-03-16 12:21:52 +010092 cricket::IceControllerFactoryInterface* ice_controller_factory_ = nullptr;
Harald Alvestrand0ccfbd22021-04-08 07:25:04 +000093 // TODO(https://crbug.com/webrtc/12657): Redesign to have const members.
Qingsi Wang25ec8882019-11-15 12:33:05 -080094};
95
96// TODO(qingsi): The factory interface is defined in this file instead of its
97// namesake file ice_transport_factory.h to avoid the extra dependency on p2p/
98// introduced there by the p2p/-dependent factory methods. Move the factory
99// methods to a different file or rename it.
100class IceTransportFactory {
101 public:
102 virtual ~IceTransportFactory() = default;
103 // As a refcounted object, the returned ICE transport may outlive the host
104 // construct into which its reference is given, e.g. a peer connection. As a
105 // result, the returned ICE transport should not hold references to any object
106 // that the transport does not own and that has a lifetime bound to the host
107 // construct. Also, assumptions on the thread safety of the returned transport
108 // should be clarified by implementations. For example, a peer connection
109 // requires the returned transport to be constructed and destroyed on the
110 // network thread and an ICE transport factory that intends to work with a
111 // peer connection should offer transports compatible with these assumptions.
112 virtual rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
113 const std::string& transport_name,
114 int component,
115 IceTransportInit init) = 0;
116};
117
Harald Alvestrand98462622019-01-30 14:57:03 +0100118} // namespace webrtc
119#endif // API_ICE_TRANSPORT_INTERFACE_H_