zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 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" |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 19 | #include "webrtc/p2p/base/packettransportinternal.h" |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 20 | #include "webrtc/p2p/base/transportdescription.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 21 | #include "webrtc/rtc_base/stringencode.h" |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | class MetricsObserverInterface; |
| 25 | } |
| 26 | |
| 27 | namespace cricket { |
| 28 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 29 | // TODO(zhihuang): Replace this with |
| 30 | // PeerConnectionInterface::IceConnectionState. |
zhihuang | d06adf6 | 2017-01-12 15:58:31 -0800 | [diff] [blame] | 31 | enum class IceTransportState { |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 32 | STATE_INIT, |
| 33 | STATE_CONNECTING, // Will enter this state once a connection is created |
| 34 | STATE_COMPLETED, |
zhihuang | d06adf6 | 2017-01-12 15:58:31 -0800 | [diff] [blame] | 35 | STATE_FAILED |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | // TODO(zhihuang): Remove this once it's no longer used in |
| 39 | // remoting/protocol/libjingle_transport_factory.cc |
| 40 | enum 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. |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 48 | class IceTransportInternal : public rtc::PacketTransportInternal { |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 49 | public: |
zhihuang | d06adf6 | 2017-01-12 15:58:31 -0800 | [diff] [blame] | 50 | virtual ~IceTransportInternal(){}; |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 51 | |
zhihuang | d06adf6 | 2017-01-12 15:58:31 -0800 | [diff] [blame] | 52 | virtual IceTransportState GetState() const = 0; |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 53 | |
| 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 | |
zhihuang | d06adf6 | 2017-01-12 15:58:31 -0800 | [diff] [blame] | 101 | // Returns the current stats for this connection. |
| 102 | virtual bool GetStats(ConnectionInfos* infos) = 0; |
| 103 | |
skvlad | d030912 | 2017-02-02 17:18:37 -0800 | [diff] [blame] | 104 | // 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 | |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 108 | 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 | |
zhihuang | d06adf6 | 2017-01-12 15:58:31 -0800 | [diff] [blame] | 132 | // 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 | |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 139 | // Invoked when the transport is being destroyed. |
| 140 | sigslot::signal1<IceTransportInternal*> SignalDestroyed; |
| 141 | |
| 142 | // Debugging description of this transport. |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 143 | std::string debug_name() const override { |
deadbeef | dbeeb70 | 2017-02-16 11:10:51 -0800 | [diff] [blame] | 144 | return transport_name() + " " + rtc::ToString(component()); |
zhihuang | d06adf6 | 2017-01-12 15:58:31 -0800 | [diff] [blame] | 145 | } |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace cricket |
zhihuang | d06adf6 | 2017-01-12 15:58:31 -0800 | [diff] [blame] | 149 | |
zhihuang | 86abd6f | 2016-12-19 11:54:05 -0800 | [diff] [blame] | 150 | #endif // WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_ |