blob: d2f1edc012d6774dc5a801c266eba9a572cad530 [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
16#include "api/async_resolver_factory.h"
Harald Alvestrand98462622019-01-30 14:57:03 +010017#include "api/rtc_error.h"
Qingsi Wang25ec8882019-11-15 12:33:05 -080018#include "api/rtc_event_log/rtc_event_log.h"
Harald Alvestrand98462622019-01-30 14:57:03 +010019#include "api/scoped_refptr.h"
20#include "rtc_base/ref_count.h"
21
22namespace cricket {
23class IceTransportInternal;
Qingsi Wang25ec8882019-11-15 12:33:05 -080024class PortAllocator;
Harald Alvestrand98462622019-01-30 14:57:03 +010025} // namespace cricket
26
27namespace webrtc {
28
29// An ICE transport, as represented to the outside world.
30// This object is refcounted, and is therefore alive until the
31// last holder has released it.
32class IceTransportInterface : public rtc::RefCountInterface {
33 public:
34 // Accessor for the internal representation of an ICE transport.
35 // The returned object can only be safely used on the signalling thread.
36 // TODO(crbug.com/907849): Add API calls for the functions that have to
37 // be exposed to clients, and stop allowing access to the
38 // cricket::IceTransportInternal API.
39 virtual cricket::IceTransportInternal* internal() = 0;
40};
41
Qingsi Wang25ec8882019-11-15 12:33:05 -080042struct IceTransportInit final {
43 public:
44 IceTransportInit() = default;
45 IceTransportInit(const IceTransportInit&) = delete;
46 IceTransportInit(IceTransportInit&&) = default;
47 IceTransportInit& operator=(const IceTransportInit&) = delete;
48 IceTransportInit& operator=(IceTransportInit&&) = default;
49
50 cricket::PortAllocator* port_allocator() { return port_allocator_; }
51 void set_port_allocator(cricket::PortAllocator* port_allocator) {
52 port_allocator_ = port_allocator;
53 }
54
55 AsyncResolverFactory* async_resolver_factory() {
56 return async_resolver_factory_;
57 }
58 void set_async_resolver_factory(
59 AsyncResolverFactory* async_resolver_factory) {
60 async_resolver_factory_ = async_resolver_factory;
61 }
62
63 RtcEventLog* event_log() { return event_log_; }
64 void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; }
65
66 private:
67 cricket::PortAllocator* port_allocator_ = nullptr;
68 AsyncResolverFactory* async_resolver_factory_ = nullptr;
69 RtcEventLog* event_log_ = nullptr;
70};
71
72// TODO(qingsi): The factory interface is defined in this file instead of its
73// namesake file ice_transport_factory.h to avoid the extra dependency on p2p/
74// introduced there by the p2p/-dependent factory methods. Move the factory
75// methods to a different file or rename it.
76class IceTransportFactory {
77 public:
78 virtual ~IceTransportFactory() = default;
79 // As a refcounted object, the returned ICE transport may outlive the host
80 // construct into which its reference is given, e.g. a peer connection. As a
81 // result, the returned ICE transport should not hold references to any object
82 // that the transport does not own and that has a lifetime bound to the host
83 // construct. Also, assumptions on the thread safety of the returned transport
84 // should be clarified by implementations. For example, a peer connection
85 // requires the returned transport to be constructed and destroyed on the
86 // network thread and an ICE transport factory that intends to work with a
87 // peer connection should offer transports compatible with these assumptions.
88 virtual rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
89 const std::string& transport_name,
90 int component,
91 IceTransportInit init) = 0;
92};
93
Harald Alvestrand98462622019-01-30 14:57:03 +010094} // namespace webrtc
95#endif // API_ICE_TRANSPORT_INTERFACE_H_