blob: bd3c78a770556aa443a3d58823a87672a21c6f5b [file] [log] [blame]
zhihuang86abd6f2016-12-19 11:54:05 -08001/*
2 * Copyright 2016 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 WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_
12#define WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_
13
14#include <string>
15
16#include "webrtc/p2p/base/candidate.h"
17#include "webrtc/p2p/base/candidatepairinterface.h"
18#include "webrtc/p2p/base/jseptransport.h"
19#include "webrtc/p2p/base/packettransportinterface.h"
20#include "webrtc/p2p/base/transportdescription.h"
21
22namespace webrtc {
23class MetricsObserverInterface;
24}
25
26namespace cricket {
27
zhihuangd06adf62017-01-12 15:58:31 -080028class IceTransportInternal;
29typedef IceTransportInternal IceTransportInternal2;
30
31// TODO(zhihuang): replace it with PeerConnectionInterface::IceConnectionState.
32enum class IceTransportState {
zhihuang86abd6f2016-12-19 11:54:05 -080033 STATE_INIT,
34 STATE_CONNECTING, // Will enter this state once a connection is created
35 STATE_COMPLETED,
zhihuangd06adf62017-01-12 15:58:31 -080036 STATE_FAILED
zhihuang86abd6f2016-12-19 11:54:05 -080037};
38
39// TODO(zhihuang): Remove this once it's no longer used in
40// remoting/protocol/libjingle_transport_factory.cc
41enum IceProtocolType {
42 ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE.
43};
44
45// IceTransportInternal is an internal abstract class that does ICE.
46// Once the public interface is supported,
47// (https://www.w3.org/TR/webrtc/#rtcicetransport-interface)
48// the IceTransportInterface will be split from this class.
49class IceTransportInternal : public rtc::PacketTransportInterface {
50 public:
zhihuangd06adf62017-01-12 15:58:31 -080051 virtual ~IceTransportInternal(){};
zhihuang86abd6f2016-12-19 11:54:05 -080052
zhihuangd06adf62017-01-12 15:58:31 -080053 virtual IceTransportState GetState() const = 0;
zhihuang86abd6f2016-12-19 11:54:05 -080054
55 virtual const std::string& transport_name() const = 0;
56
57 virtual int component() const = 0;
58
59 virtual IceRole GetIceRole() const = 0;
60
61 virtual void SetIceRole(IceRole role) = 0;
62
63 virtual void SetIceTiebreaker(uint64_t tiebreaker) = 0;
64
65 // TODO(zhihuang): Remove this once it's no longer called in
66 // remoting/protocol/libjingle_transport_factory.cc
67 virtual void SetIceProtocolType(IceProtocolType type) {}
68
69 virtual void SetIceCredentials(const std::string& ice_ufrag,
70 const std::string& ice_pwd) {
71 SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
72 }
73
74 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
75 const std::string& ice_pwd) {
76 SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
77 }
78
79 // The ufrag and pwd in |ice_params| must be set
80 // before candidate gathering can start.
81 virtual void SetIceParameters(const IceParameters& ice_params) = 0;
82
83 virtual void SetRemoteIceParameters(const IceParameters& ice_params) = 0;
84
85 virtual void SetRemoteIceMode(IceMode mode) = 0;
86
87 virtual void SetIceConfig(const IceConfig& config) = 0;
88
89 // Start gathering candidates if not already started, or if an ICE restart
90 // occurred.
91 virtual void MaybeStartGathering() = 0;
92
93 virtual void SetMetricsObserver(
94 webrtc::MetricsObserverInterface* observer) = 0;
95
96 virtual void AddRemoteCandidate(const Candidate& candidate) = 0;
97
98 virtual void RemoveRemoteCandidate(const Candidate& candidate) = 0;
99
100 virtual IceGatheringState gathering_state() const = 0;
101
zhihuangd06adf62017-01-12 15:58:31 -0800102 // Returns the current stats for this connection.
103 virtual bool GetStats(ConnectionInfos* infos) = 0;
104
zhihuang86abd6f2016-12-19 11:54:05 -0800105 sigslot::signal1<IceTransportInternal*> SignalGatheringState;
106
107 // Handles sending and receiving of candidates.
108 sigslot::signal2<IceTransportInternal*, const Candidate&>
109 SignalCandidateGathered;
110
111 sigslot::signal2<IceTransportInternal*, const Candidates&>
112 SignalCandidatesRemoved;
113
114 // Deprecated by SignalSelectedCandidatePairChanged
115 // This signal occurs when there is a change in the way that packets are
116 // being routed, i.e. to a different remote location. The candidate
117 // indicates where and how we are currently sending media.
118 sigslot::signal2<IceTransportInternal*, const Candidate&> SignalRouteChange;
119
120 // Signalled when the current selected candidate pair has changed.
121 // The first parameter is the transport that signals the event.
122 // The second parameter is the new selected candidate pair. The third
123 // parameter is the last packet id sent on the previous candidate pair.
124 // The fourth parameter is a boolean which is true if the Transport
125 // is ready to send with this candidate pair.
126 sigslot::signal4<IceTransportInternal*, CandidatePairInterface*, int, bool>
127 SignalSelectedCandidatePairChanged;
128
zhihuangd06adf62017-01-12 15:58:31 -0800129 // Invoked when there is conflict in the ICE role between local and remote
130 // agents.
131 sigslot::signal1<IceTransportInternal*> SignalRoleConflict;
132
133 // Emitted whenever the transport state changed.
134 sigslot::signal1<IceTransportInternal*> SignalStateChanged;
135
zhihuang86abd6f2016-12-19 11:54:05 -0800136 // Invoked when the transport is being destroyed.
137 sigslot::signal1<IceTransportInternal*> SignalDestroyed;
138
139 // Debugging description of this transport.
zhihuangd06adf62017-01-12 15:58:31 -0800140 const std::string debug_name() const override {
141 return transport_name() + " " + std::to_string(component());
142 }
zhihuang86abd6f2016-12-19 11:54:05 -0800143};
144
145} // namespace cricket
zhihuangd06adf62017-01-12 15:58:31 -0800146
zhihuang86abd6f2016-12-19 11:54:05 -0800147#endif // WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_