1 /* 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 22 namespace webrtc { 23 class MetricsObserverInterface; 24 } 25 26 namespace cricket { 27 28 class IceTransportInternal; 29 typedef IceTransportInternal IceTransportInternal2; 30 31 // TODO(zhihuang): replace it with PeerConnectionInterface::IceConnectionState. 32 enum class IceTransportState { 33 STATE_INIT, 34 STATE_CONNECTING, // Will enter this state once a connection is created 35 STATE_COMPLETED, 36 STATE_FAILED 37 }; 38 39 // TODO(zhihuang): Remove this once it's no longer used in 40 // remoting/protocol/libjingle_transport_factory.cc 41 enum 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. 49 class IceTransportInternal : public rtc::PacketTransportInterface { 50 public: ~IceTransportInternal()51 virtual ~IceTransportInternal(){}; 52 53 virtual IceTransportState GetState() const = 0; 54 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 SetIceProtocolType(IceProtocolType type)67 virtual void SetIceProtocolType(IceProtocolType type) {} 68 SetIceCredentials(const std::string & ice_ufrag,const std::string & ice_pwd)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 SetRemoteIceCredentials(const std::string & ice_ufrag,const std::string & ice_pwd)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 102 // Returns the current stats for this connection. 103 virtual bool GetStats(ConnectionInfos* infos) = 0; 104 105 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 129 // 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 136 // Invoked when the transport is being destroyed. 137 sigslot::signal1<IceTransportInternal*> SignalDestroyed; 138 139 // Debugging description of this transport. debug_name()140 const std::string debug_name() const override { 141 return transport_name() + " " + std::to_string(component()); 142 } 143 }; 144 145 } // namespace cricket 146 147 #endif // WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_ 148