Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: webrtc/p2p/base/transportcontroller.h

Issue 2553043004: Revert of Refactoring that removes P2PTransport and DtlsTransport classes. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/transportchannel.h ('k') | webrtc/p2p/base/transportcontroller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ 11 #ifndef WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
12 #define WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ 12 #define WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
13 13
14 #include <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/base/asyncinvoker.h" 19 #include "webrtc/base/asyncinvoker.h"
20 #include "webrtc/base/sigslot.h" 20 #include "webrtc/base/sigslot.h"
21 #include "webrtc/base/sslstreamadapter.h" 21 #include "webrtc/base/sslstreamadapter.h"
22 #include "webrtc/p2p/base/candidate.h" 22 #include "webrtc/p2p/base/candidate.h"
23 #include "webrtc/p2p/base/dtlstransportchannel.h" 23 #include "webrtc/p2p/base/transport.h"
24 #include "webrtc/p2p/base/jseptransport.h"
25 #include "webrtc/p2p/base/p2ptransportchannel.h"
26 24
27 namespace rtc { 25 namespace rtc {
28 class Thread; 26 class Thread;
29 class PacketTransportInterface; 27 class PacketTransportInterface;
30 } 28 }
31 namespace webrtc { 29 namespace webrtc {
32 class MetricsObserverInterface; 30 class MetricsObserverInterface;
33 } 31 }
34 32
35 namespace cricket { 33 namespace cricket {
(...skipping 21 matching lines...) Expand all
57 PortAllocator* port_allocator() const { return port_allocator_; } 55 PortAllocator* port_allocator() const { return port_allocator_; }
58 56
59 // Can only be set before transports are created. 57 // Can only be set before transports are created.
60 // TODO(deadbeef): Make this an argument to the constructor once BaseSession 58 // TODO(deadbeef): Make this an argument to the constructor once BaseSession
61 // and WebRtcSession are combined 59 // and WebRtcSession are combined
62 bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); 60 bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version);
63 61
64 void SetIceConfig(const IceConfig& config); 62 void SetIceConfig(const IceConfig& config);
65 void SetIceRole(IceRole ice_role); 63 void SetIceRole(IceRole ice_role);
66 64
67 bool GetSslRole(const std::string& transport_name, rtc::SSLRole* role) const; 65 bool GetSslRole(const std::string& transport_name, rtc::SSLRole* role);
68 66
69 // Specifies the identity to use in this session. 67 // Specifies the identity to use in this session.
70 // Can only be called once. 68 // Can only be called once.
71 bool SetLocalCertificate( 69 bool SetLocalCertificate(
72 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); 70 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
73 bool GetLocalCertificate( 71 bool GetLocalCertificate(
74 const std::string& transport_name, 72 const std::string& transport_name,
75 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) const; 73 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
76 // Caller owns returned certificate. This method mainly exists for stats 74 // Caller owns returned certificate
77 // reporting.
78 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate( 75 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
79 const std::string& transport_name) const; 76 const std::string& transport_name);
80 bool SetLocalTransportDescription(const std::string& transport_name, 77 bool SetLocalTransportDescription(const std::string& transport_name,
81 const TransportDescription& tdesc, 78 const TransportDescription& tdesc,
82 ContentAction action, 79 ContentAction action,
83 std::string* err); 80 std::string* err);
84 bool SetRemoteTransportDescription(const std::string& transport_name, 81 bool SetRemoteTransportDescription(const std::string& transport_name,
85 const TransportDescription& tdesc, 82 const TransportDescription& tdesc,
86 ContentAction action, 83 ContentAction action,
87 std::string* err); 84 std::string* err);
88 // Start gathering candidates for any new transports, or transports doing an 85 // Start gathering candidates for any new transports, or transports doing an
89 // ICE restart. 86 // ICE restart.
90 void MaybeStartGathering(); 87 void MaybeStartGathering();
91 bool AddRemoteCandidates(const std::string& transport_name, 88 bool AddRemoteCandidates(const std::string& transport_name,
92 const Candidates& candidates, 89 const Candidates& candidates,
93 std::string* err); 90 std::string* err);
94 bool RemoveRemoteCandidates(const Candidates& candidates, std::string* err); 91 bool RemoveRemoteCandidates(const Candidates& candidates, std::string* err);
95 bool ReadyForRemoteCandidates(const std::string& transport_name) const; 92 bool ReadyForRemoteCandidates(const std::string& transport_name);
96 // TODO(deadbeef): GetStats isn't const because all the way down to
97 // OpenSSLStreamAdapter,
98 // GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not const. Fix this.
99 bool GetStats(const std::string& transport_name, TransportStats* stats); 93 bool GetStats(const std::string& transport_name, TransportStats* stats);
100 void SetMetricsObserver(webrtc::MetricsObserverInterface* metrics_observer);
101 94
102 // Creates a channel if it doesn't exist. Otherwise, increments a reference 95 // Creates a channel if it doesn't exist. Otherwise, increments a reference
103 // count and returns an existing channel. 96 // count and returns an existing channel.
104 virtual TransportChannel* CreateTransportChannel_n( 97 virtual TransportChannel* CreateTransportChannel_n(
105 const std::string& transport_name, 98 const std::string& transport_name,
106 int component); 99 int component);
107 100
108 // Decrements a channel's reference count, and destroys the channel if 101 // Decrements a channel's reference count, and destroys the channel if
109 // nothing is referencing it. 102 // nothing is referencing it.
110 virtual void DestroyTransportChannel_n(const std::string& transport_name, 103 virtual void DestroyTransportChannel_n(const std::string& transport_name,
111 int component); 104 int component);
112 105
113 void use_quic() { quic_ = true; } 106 void use_quic() { quic_ = true; }
114 bool quic() const { return quic_; } 107 bool quic() const { return quic_; }
115 108
116 // TODO(deadbeef): Remove all for_testing methods!
117 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing()
118 const {
119 return certificate_;
120 }
121 std::vector<std::string> transport_names_for_testing();
122 std::vector<TransportChannelImpl*> channels_for_testing();
123 TransportChannelImpl* get_channel_for_testing(
124 const std::string& transport_name,
125 int component);
126
127 // All of these signals are fired on the signalling thread. 109 // All of these signals are fired on the signalling thread.
128 110
129 // If any transport failed => failed, 111 // If any transport failed => failed,
130 // Else if all completed => completed, 112 // Else if all completed => completed,
131 // Else if all connected => connected, 113 // Else if all connected => connected,
132 // Else => connecting 114 // Else => connecting
133 sigslot::signal1<IceConnectionState> SignalConnectionState; 115 sigslot::signal1<IceConnectionState> SignalConnectionState;
134 116
135 // Receiving if any transport is receiving 117 // Receiving if any transport is receiving
136 sigslot::signal1<bool> SignalReceiving; 118 sigslot::signal1<bool> SignalReceiving;
137 119
138 // If all transports done gathering => complete, 120 // If all transports done gathering => complete,
139 // Else if any are gathering => gathering, 121 // Else if any are gathering => gathering,
140 // Else => new 122 // Else => new
141 sigslot::signal1<IceGatheringState> SignalGatheringState; 123 sigslot::signal1<IceGatheringState> SignalGatheringState;
142 124
143 // (transport_name, candidates) 125 // (transport_name, candidates)
144 sigslot::signal2<const std::string&, const Candidates&> 126 sigslot::signal2<const std::string&, const Candidates&>
145 SignalCandidatesGathered; 127 SignalCandidatesGathered;
146 128
147 sigslot::signal1<const Candidates&> SignalCandidatesRemoved; 129 sigslot::signal1<const Candidates&> SignalCandidatesRemoved;
148 130
131 // for unit test
132 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing();
133
149 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError; 134 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
150 135
136 void SetMetricsObserver(webrtc::MetricsObserverInterface* metrics_observer);
137
151 protected: 138 protected:
152 // TODO(deadbeef): Get rid of these virtual methods. Used by 139 // Protected and virtual so we can override it in unit tests.
153 // FakeTransportController currently, but FakeTransportController shouldn't 140 virtual Transport* CreateTransport_n(const std::string& transport_name);
154 // even be functioning by subclassing TransportController. 141
155 virtual TransportChannelImpl* CreateIceTransportChannel_n( 142 // For unit tests
156 const std::string& transport_name, 143 const std::map<std::string, Transport*>& transports() { return transports_; }
157 int component); 144 Transport* GetTransport_n(const std::string& transport_name);
158 virtual TransportChannelImpl* CreateDtlsTransportChannel_n(
159 const std::string& transport_name,
160 int component,
161 TransportChannelImpl* ice);
162 145
163 private: 146 private:
164 void OnMessage(rtc::Message* pmsg) override; 147 void OnMessage(rtc::Message* pmsg) override;
165 148
166 // This structure groups the DTLS and ICE channels, and helps keep track of 149 // It's the Transport that's currently responsible for creating/destroying
167 // how many external objects (BaseChannels) reference each channel. 150 // channels, but the TransportController keeps track of how many external
151 // objects (BaseChannels) reference each channel.
168 struct RefCountedChannel { 152 struct RefCountedChannel {
169 RefCountedChannel() = default; 153 RefCountedChannel() : impl_(nullptr), ref_(0) {}
170 // TODO(deadbeef): Change the types of |dtls| and |ice| to 154 explicit RefCountedChannel(TransportChannelImpl* impl)
171 // DtlsTransportChannelWrapper and P2PTransportChannelWrapper, 155 : impl_(impl), ref_(0) {}
172 // once TransportChannelImpl is removed.
173 explicit RefCountedChannel(TransportChannelImpl* dtls,
174 TransportChannelImpl* ice)
175 : ice_(ice), dtls_(dtls), ref_(0) {}
176 156
177 void AddRef() { ++ref_; } 157 void AddRef() { ++ref_; }
178 void DecRef() { 158 void DecRef() {
179 ASSERT(ref_ > 0); 159 ASSERT(ref_ > 0);
180 --ref_; 160 --ref_;
181 } 161 }
182 int ref() const { return ref_; } 162 int ref() const { return ref_; }
183 163
184 // Currently, all ICE-related calls still go through this DTLS channel. But 164 TransportChannelImpl* get() const { return impl_; }
185 // that will change once we get rid of TransportChannelImpl, and the DTLS 165 TransportChannelImpl* operator->() const { return impl_; }
186 // channel interface no longer includes ICE-specific methods.
187 const TransportChannelImpl* dtls() const { return dtls_.get(); }
188 TransportChannelImpl* dtls() { return dtls_.get(); }
189 const TransportChannelImpl* ice() const { return ice_.get(); }
190 TransportChannelImpl* ice() { return ice_.get(); }
191 166
192 private: 167 private:
193 std::unique_ptr<TransportChannelImpl> ice_; 168 TransportChannelImpl* impl_;
194 std::unique_ptr<TransportChannelImpl> dtls_; 169 int ref_;
195 int ref_ = 0;
196 }; 170 };
197 171
198 // Helper functions to get a channel or transport, or iterator to it (in case 172 std::vector<RefCountedChannel>::iterator FindChannel_n(
199 // it needs to be erased).
200 std::vector<RefCountedChannel>::iterator GetChannelIterator_n(
201 const std::string& transport_name, 173 const std::string& transport_name,
202 int component); 174 int component);
203 std::vector<RefCountedChannel>::const_iterator GetChannelIterator_n(
204 const std::string& transport_name,
205 int component) const;
206 const JsepTransport* GetJsepTransport_n(
207 const std::string& transport_name) const;
208 JsepTransport* GetJsepTransport_n(const std::string& transport_name);
209 const RefCountedChannel* GetChannel_n(const std::string& transport_name,
210 int component) const;
211 RefCountedChannel* GetChannel_n(const std::string& transport_name,
212 int component);
213 175
214 JsepTransport* GetOrCreateJsepTransport_n(const std::string& transport_name); 176 Transport* GetOrCreateTransport_n(const std::string& transport_name);
215 void DestroyAllChannels_n(); 177 void DestroyTransport_n(const std::string& transport_name);
178 void DestroyAllTransports_n();
216 179
217 bool SetSslMaxProtocolVersion_n(rtc::SSLProtocolVersion version); 180 bool SetSslMaxProtocolVersion_n(rtc::SSLProtocolVersion version);
218 void SetIceConfig_n(const IceConfig& config); 181 void SetIceConfig_n(const IceConfig& config);
219 void SetIceRole_n(IceRole ice_role); 182 void SetIceRole_n(IceRole ice_role);
220 bool GetSslRole_n(const std::string& transport_name, 183 bool GetSslRole_n(const std::string& transport_name, rtc::SSLRole* role);
221 rtc::SSLRole* role) const;
222 bool SetLocalCertificate_n( 184 bool SetLocalCertificate_n(
223 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); 185 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
224 bool GetLocalCertificate_n( 186 bool GetLocalCertificate_n(
225 const std::string& transport_name, 187 const std::string& transport_name,
226 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) const; 188 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
227 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate_n( 189 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate_n(
228 const std::string& transport_name) const; 190 const std::string& transport_name);
229 bool SetLocalTransportDescription_n(const std::string& transport_name, 191 bool SetLocalTransportDescription_n(const std::string& transport_name,
230 const TransportDescription& tdesc, 192 const TransportDescription& tdesc,
231 ContentAction action, 193 ContentAction action,
232 std::string* err); 194 std::string* err);
233 bool SetRemoteTransportDescription_n(const std::string& transport_name, 195 bool SetRemoteTransportDescription_n(const std::string& transport_name,
234 const TransportDescription& tdesc, 196 const TransportDescription& tdesc,
235 ContentAction action, 197 ContentAction action,
236 std::string* err); 198 std::string* err);
237 void MaybeStartGathering_n(); 199 void MaybeStartGathering_n();
238 bool AddRemoteCandidates_n(const std::string& transport_name, 200 bool AddRemoteCandidates_n(const std::string& transport_name,
239 const Candidates& candidates, 201 const Candidates& candidates,
240 std::string* err); 202 std::string* err);
241 bool RemoveRemoteCandidates_n(const Candidates& candidates, std::string* err); 203 bool RemoveRemoteCandidates_n(const Candidates& candidates, std::string* err);
242 bool ReadyForRemoteCandidates_n(const std::string& transport_name) const; 204 bool ReadyForRemoteCandidates_n(const std::string& transport_name);
243 bool GetStats_n(const std::string& transport_name, TransportStats* stats); 205 bool GetStats_n(const std::string& transport_name, TransportStats* stats);
244 void SetMetricsObserver_n(webrtc::MetricsObserverInterface* metrics_observer);
245 206
246 // Handlers for signals from Transport. 207 // Handlers for signals from Transport.
247 void OnChannelWritableState_n(rtc::PacketTransportInterface* transport); 208 void OnChannelWritableState_n(rtc::PacketTransportInterface* transport);
248 void OnChannelReceivingState_n(rtc::PacketTransportInterface* transport); 209 void OnChannelReceivingState_n(rtc::PacketTransportInterface* transport);
249 void OnChannelGatheringState_n(TransportChannelImpl* channel); 210 void OnChannelGatheringState_n(TransportChannelImpl* channel);
250 void OnChannelCandidateGathered_n(TransportChannelImpl* channel, 211 void OnChannelCandidateGathered_n(TransportChannelImpl* channel,
251 const Candidate& candidate); 212 const Candidate& candidate);
252 void OnChannelCandidatesRemoved(const Candidates& candidates); 213 void OnChannelCandidatesRemoved(const Candidates& candidates);
253 void OnChannelCandidatesRemoved_n(TransportChannelImpl* channel, 214 void OnChannelCandidatesRemoved_n(TransportChannelImpl* channel,
254 const Candidates& candidates); 215 const Candidates& candidates);
255 void OnChannelRoleConflict_n(TransportChannelImpl* channel); 216 void OnChannelRoleConflict_n(TransportChannelImpl* channel);
256 void OnChannelStateChanged_n(TransportChannelImpl* channel); 217 void OnChannelStateChanged_n(TransportChannelImpl* channel);
257 218
258 void UpdateAggregateStates_n(); 219 void UpdateAggregateStates_n();
259 220
260 void OnDtlsHandshakeError(rtc::SSLHandshakeError error); 221 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
261 222
262 rtc::Thread* const signaling_thread_ = nullptr; 223 rtc::Thread* const signaling_thread_ = nullptr;
263 rtc::Thread* const network_thread_ = nullptr; 224 rtc::Thread* const network_thread_ = nullptr;
225 typedef std::map<std::string, Transport*> TransportMap;
226 TransportMap transports_;
227
228 std::vector<RefCountedChannel> channels_;
229
264 PortAllocator* const port_allocator_ = nullptr; 230 PortAllocator* const port_allocator_ = nullptr;
265 231 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
266 std::map<std::string, std::unique_ptr<JsepTransport>> transports_;
267 std::vector<RefCountedChannel> channels_;
268 232
269 // Aggregate state for TransportChannelImpls. 233 // Aggregate state for TransportChannelImpls.
270 IceConnectionState connection_state_ = kIceConnectionConnecting; 234 IceConnectionState connection_state_ = kIceConnectionConnecting;
271 bool receiving_ = false; 235 bool receiving_ = false;
272 IceGatheringState gathering_state_ = kIceGatheringNew; 236 IceGatheringState gathering_state_ = kIceGatheringNew;
273 237
238 // TODO(deadbeef): Move the fields below down to the transports themselves
274 IceConfig ice_config_; 239 IceConfig ice_config_;
275 IceRole ice_role_ = ICEROLE_CONTROLLING; 240 IceRole ice_role_ = ICEROLE_CONTROLLING;
276 bool redetermine_role_on_ice_restart_; 241 bool redetermine_role_on_ice_restart_;
277 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); 242 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
278 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
279 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; 243 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
280 rtc::AsyncInvoker invoker_; 244 rtc::AsyncInvoker invoker_;
281 // True if QUIC is used instead of DTLS. 245 // True if QUIC is used instead of DTLS.
282 bool quic_ = false; 246 bool quic_ = false;
283 247
284 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; 248 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr;
285 }; 249 };
286 250
287 } // namespace cricket 251 } // namespace cricket
288 252
289 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ 253 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/transportchannel.h ('k') | webrtc/p2p/base/transportcontroller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698