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

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

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

Powered by Google App Engine
This is Rietveld 408576698