blob: 435a081161026bfe75d88d2b16feed33deebf38d [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"
deadbeef5bd5ca32017-02-10 11:31:50 -080019#include "webrtc/p2p/base/packettransportinternal.h"
zhihuang86abd6f2016-12-19 11:54:05 -080020#include "webrtc/p2p/base/transportdescription.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020021#include "webrtc/rtc_base/stringencode.h"
zhihuang86abd6f2016-12-19 11:54:05 -080022
23namespace webrtc {
24class MetricsObserverInterface;
25}
26
27namespace cricket {
28
zhihuangb2cdd932017-01-19 16:54:25 -080029// TODO(zhihuang): Replace this with
30// PeerConnectionInterface::IceConnectionState.
zhihuangd06adf62017-01-12 15:58:31 -080031enum class IceTransportState {
zhihuang86abd6f2016-12-19 11:54:05 -080032 STATE_INIT,
33 STATE_CONNECTING, // Will enter this state once a connection is created
34 STATE_COMPLETED,
zhihuangd06adf62017-01-12 15:58:31 -080035 STATE_FAILED
zhihuang86abd6f2016-12-19 11:54:05 -080036};
37
38// TODO(zhihuang): Remove this once it's no longer used in
39// remoting/protocol/libjingle_transport_factory.cc
40enum IceProtocolType {
41 ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE.
42};
43
44// IceTransportInternal is an internal abstract class that does ICE.
45// Once the public interface is supported,
46// (https://www.w3.org/TR/webrtc/#rtcicetransport-interface)
47// the IceTransportInterface will be split from this class.
deadbeef5bd5ca32017-02-10 11:31:50 -080048class IceTransportInternal : public rtc::PacketTransportInternal {
zhihuang86abd6f2016-12-19 11:54:05 -080049 public:
zhihuangd06adf62017-01-12 15:58:31 -080050 virtual ~IceTransportInternal(){};
zhihuang86abd6f2016-12-19 11:54:05 -080051
zhihuangd06adf62017-01-12 15:58:31 -080052 virtual IceTransportState GetState() const = 0;
zhihuang86abd6f2016-12-19 11:54:05 -080053
54 virtual const std::string& transport_name() const = 0;
55
56 virtual int component() const = 0;
57
58 virtual IceRole GetIceRole() const = 0;
59
60 virtual void SetIceRole(IceRole role) = 0;
61
62 virtual void SetIceTiebreaker(uint64_t tiebreaker) = 0;
63
64 // TODO(zhihuang): Remove this once it's no longer called in
65 // remoting/protocol/libjingle_transport_factory.cc
66 virtual void SetIceProtocolType(IceProtocolType type) {}
67
68 virtual void SetIceCredentials(const std::string& ice_ufrag,
69 const std::string& ice_pwd) {
70 SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
71 }
72
73 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
74 const std::string& ice_pwd) {
75 SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
76 }
77
78 // The ufrag and pwd in |ice_params| must be set
79 // before candidate gathering can start.
80 virtual void SetIceParameters(const IceParameters& ice_params) = 0;
81
82 virtual void SetRemoteIceParameters(const IceParameters& ice_params) = 0;
83
84 virtual void SetRemoteIceMode(IceMode mode) = 0;
85
86 virtual void SetIceConfig(const IceConfig& config) = 0;
87
88 // Start gathering candidates if not already started, or if an ICE restart
89 // occurred.
90 virtual void MaybeStartGathering() = 0;
91
92 virtual void SetMetricsObserver(
93 webrtc::MetricsObserverInterface* observer) = 0;
94
95 virtual void AddRemoteCandidate(const Candidate& candidate) = 0;
96
97 virtual void RemoveRemoteCandidate(const Candidate& candidate) = 0;
98
99 virtual IceGatheringState gathering_state() const = 0;
100
zhihuangd06adf62017-01-12 15:58:31 -0800101 // Returns the current stats for this connection.
102 virtual bool GetStats(ConnectionInfos* infos) = 0;
103
skvladd0309122017-02-02 17:18:37 -0800104 // Returns RTT estimate over the currently active connection, or an empty
105 // rtc::Optional if there is none.
106 virtual rtc::Optional<int> GetRttEstimate() = 0;
107
zhihuang86abd6f2016-12-19 11:54:05 -0800108 sigslot::signal1<IceTransportInternal*> SignalGatheringState;
109
110 // Handles sending and receiving of candidates.
111 sigslot::signal2<IceTransportInternal*, const Candidate&>
112 SignalCandidateGathered;
113
114 sigslot::signal2<IceTransportInternal*, const Candidates&>
115 SignalCandidatesRemoved;
116
117 // Deprecated by SignalSelectedCandidatePairChanged
118 // This signal occurs when there is a change in the way that packets are
119 // being routed, i.e. to a different remote location. The candidate
120 // indicates where and how we are currently sending media.
121 sigslot::signal2<IceTransportInternal*, const Candidate&> SignalRouteChange;
122
123 // Signalled when the current selected candidate pair has changed.
124 // The first parameter is the transport that signals the event.
125 // The second parameter is the new selected candidate pair. The third
126 // parameter is the last packet id sent on the previous candidate pair.
127 // The fourth parameter is a boolean which is true if the Transport
128 // is ready to send with this candidate pair.
129 sigslot::signal4<IceTransportInternal*, CandidatePairInterface*, int, bool>
130 SignalSelectedCandidatePairChanged;
131
zhihuangd06adf62017-01-12 15:58:31 -0800132 // Invoked when there is conflict in the ICE role between local and remote
133 // agents.
134 sigslot::signal1<IceTransportInternal*> SignalRoleConflict;
135
136 // Emitted whenever the transport state changed.
137 sigslot::signal1<IceTransportInternal*> SignalStateChanged;
138
zhihuang86abd6f2016-12-19 11:54:05 -0800139 // Invoked when the transport is being destroyed.
140 sigslot::signal1<IceTransportInternal*> SignalDestroyed;
141
142 // Debugging description of this transport.
zhihuangb2cdd932017-01-19 16:54:25 -0800143 std::string debug_name() const override {
deadbeefdbeeb702017-02-16 11:10:51 -0800144 return transport_name() + " " + rtc::ToString(component());
zhihuangd06adf62017-01-12 15:58:31 -0800145 }
zhihuang86abd6f2016-12-19 11:54:05 -0800146};
147
148} // namespace cricket
zhihuangd06adf62017-01-12 15:58:31 -0800149
zhihuang86abd6f2016-12-19 11:54:05 -0800150#endif // WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_