blob: 4c47a140a5145103bf1d259ccecdf5368d4fd7ea [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
28enum class TransportState {
29 STATE_INIT,
30 STATE_CONNECTING, // Will enter this state once a connection is created
31 STATE_COMPLETED,
32 STATE_FAILEDs
33};
34
35// TODO(zhihuang): Remove this once it's no longer used in
36// remoting/protocol/libjingle_transport_factory.cc
37enum IceProtocolType {
38 ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE.
39};
40
41// IceTransportInternal is an internal abstract class that does ICE.
42// Once the public interface is supported,
43// (https://www.w3.org/TR/webrtc/#rtcicetransport-interface)
44// the IceTransportInterface will be split from this class.
45class IceTransportInternal : public rtc::PacketTransportInterface {
46 public:
47 virtual ~IceTransportInternal();
48
49 virtual TransportState GetState() const = 0;
50
51 virtual const std::string& transport_name() const = 0;
52
53 virtual int component() const = 0;
54
55 virtual IceRole GetIceRole() const = 0;
56
57 virtual void SetIceRole(IceRole role) = 0;
58
59 virtual void SetIceTiebreaker(uint64_t tiebreaker) = 0;
60
61 // TODO(zhihuang): Remove this once it's no longer called in
62 // remoting/protocol/libjingle_transport_factory.cc
63 virtual void SetIceProtocolType(IceProtocolType type) {}
64
65 virtual void SetIceCredentials(const std::string& ice_ufrag,
66 const std::string& ice_pwd) {
67 SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
68 }
69
70 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
71 const std::string& ice_pwd) {
72 SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
73 }
74
75 // The ufrag and pwd in |ice_params| must be set
76 // before candidate gathering can start.
77 virtual void SetIceParameters(const IceParameters& ice_params) = 0;
78
79 virtual void SetRemoteIceParameters(const IceParameters& ice_params) = 0;
80
81 virtual void SetRemoteIceMode(IceMode mode) = 0;
82
83 virtual void SetIceConfig(const IceConfig& config) = 0;
84
85 // Start gathering candidates if not already started, or if an ICE restart
86 // occurred.
87 virtual void MaybeStartGathering() = 0;
88
89 virtual void SetMetricsObserver(
90 webrtc::MetricsObserverInterface* observer) = 0;
91
92 virtual void AddRemoteCandidate(const Candidate& candidate) = 0;
93
94 virtual void RemoveRemoteCandidate(const Candidate& candidate) = 0;
95
96 virtual IceGatheringState gathering_state() const = 0;
97
98 sigslot::signal1<IceTransportInternal*> SignalGatheringState;
99
100 // Handles sending and receiving of candidates.
101 sigslot::signal2<IceTransportInternal*, const Candidate&>
102 SignalCandidateGathered;
103
104 sigslot::signal2<IceTransportInternal*, const Candidates&>
105 SignalCandidatesRemoved;
106
107 // Deprecated by SignalSelectedCandidatePairChanged
108 // This signal occurs when there is a change in the way that packets are
109 // being routed, i.e. to a different remote location. The candidate
110 // indicates where and how we are currently sending media.
111 sigslot::signal2<IceTransportInternal*, const Candidate&> SignalRouteChange;
112
113 // Signalled when the current selected candidate pair has changed.
114 // The first parameter is the transport that signals the event.
115 // The second parameter is the new selected candidate pair. The third
116 // parameter is the last packet id sent on the previous candidate pair.
117 // The fourth parameter is a boolean which is true if the Transport
118 // is ready to send with this candidate pair.
119 sigslot::signal4<IceTransportInternal*, CandidatePairInterface*, int, bool>
120 SignalSelectedCandidatePairChanged;
121
122 // Invoked when the transport is being destroyed.
123 sigslot::signal1<IceTransportInternal*> SignalDestroyed;
124
125 // Debugging description of this transport.
126 std::string ToString() const;
127};
128
129} // namespace cricket
130
131#endif // WEBRTC_P2P_BASE_ICETRANSPORTINTERNAL_H_