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

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

Issue 2571683004: Fixing possible crash due to RefCountedChannel assignment operator. (Closed)
Patch Set: Merge with master 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/constructormagic.h"
21 #include "webrtc/base/refcountedobject.h"
20 #include "webrtc/base/sigslot.h" 22 #include "webrtc/base/sigslot.h"
21 #include "webrtc/base/sslstreamadapter.h" 23 #include "webrtc/base/sslstreamadapter.h"
22 #include "webrtc/p2p/base/candidate.h" 24 #include "webrtc/p2p/base/candidate.h"
23 #include "webrtc/p2p/base/dtlstransportchannel.h" 25 #include "webrtc/p2p/base/dtlstransportchannel.h"
24 #include "webrtc/p2p/base/jseptransport.h" 26 #include "webrtc/p2p/base/jseptransport.h"
25 #include "webrtc/p2p/base/p2ptransportchannel.h" 27 #include "webrtc/p2p/base/p2ptransportchannel.h"
26 28
27 namespace rtc { 29 namespace rtc {
28 class Thread; 30 class Thread;
29 class PacketTransportInterface; 31 class PacketTransportInterface;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 const std::string& transport_name, 168 const std::string& transport_name,
167 int component); 169 int component);
168 virtual TransportChannelImpl* CreateDtlsTransportChannel_n( 170 virtual TransportChannelImpl* CreateDtlsTransportChannel_n(
169 const std::string& transport_name, 171 const std::string& transport_name,
170 int component, 172 int component,
171 TransportChannelImpl* ice); 173 TransportChannelImpl* ice);
172 174
173 private: 175 private:
174 void OnMessage(rtc::Message* pmsg) override; 176 void OnMessage(rtc::Message* pmsg) override;
175 177
176 // This structure groups the DTLS and ICE channels, and helps keep track of 178 class ChannelPair;
177 // how many external objects (BaseChannels) reference each channel. 179 typedef rtc::RefCountedObject<ChannelPair> RefCountedChannel;
178 struct RefCountedChannel {
179 RefCountedChannel() = default;
180 // TODO(deadbeef): Change the types of |dtls| and |ice| to
181 // DtlsTransportChannelWrapper and P2PTransportChannelWrapper,
182 // once TransportChannelImpl is removed.
183 explicit RefCountedChannel(TransportChannelImpl* dtls,
184 TransportChannelImpl* ice)
185 : ice_(ice), dtls_(dtls), ref_(0) {}
186
187 void AddRef() { ++ref_; }
188 void DecRef() {
189 ASSERT(ref_ > 0);
190 --ref_;
191 }
192 int ref() const { return ref_; }
193
194 // Currently, all ICE-related calls still go through this DTLS channel. But
195 // that will change once we get rid of TransportChannelImpl, and the DTLS
196 // channel interface no longer includes ICE-specific methods.
197 const TransportChannelImpl* dtls() const { return dtls_.get(); }
198 TransportChannelImpl* dtls() { return dtls_.get(); }
199 const TransportChannelImpl* ice() const { return ice_.get(); }
200 TransportChannelImpl* ice() { return ice_.get(); }
201
202 private:
203 std::unique_ptr<TransportChannelImpl> ice_;
204 std::unique_ptr<TransportChannelImpl> dtls_;
205 int ref_ = 0;
206 };
207 180
208 // Helper functions to get a channel or transport, or iterator to it (in case 181 // Helper functions to get a channel or transport, or iterator to it (in case
209 // it needs to be erased). 182 // it needs to be erased).
210 std::vector<RefCountedChannel>::iterator GetChannelIterator_n( 183 std::vector<RefCountedChannel*>::iterator GetChannelIterator_n(
211 const std::string& transport_name, 184 const std::string& transport_name,
212 int component); 185 int component);
213 std::vector<RefCountedChannel>::const_iterator GetChannelIterator_n( 186 std::vector<RefCountedChannel*>::const_iterator GetChannelIterator_n(
214 const std::string& transport_name, 187 const std::string& transport_name,
215 int component) const; 188 int component) const;
216 const JsepTransport* GetJsepTransport( 189 const JsepTransport* GetJsepTransport(
217 const std::string& transport_name) const; 190 const std::string& transport_name) const;
218 JsepTransport* GetJsepTransport(const std::string& transport_name); 191 JsepTransport* GetJsepTransport(const std::string& transport_name);
219 const RefCountedChannel* GetChannel_n(const std::string& transport_name, 192 const RefCountedChannel* GetChannel_n(const std::string& transport_name,
220 int component) const; 193 int component) const;
221 RefCountedChannel* GetChannel_n(const std::string& transport_name, 194 RefCountedChannel* GetChannel_n(const std::string& transport_name,
222 int component); 195 int component);
223 196
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 240
268 void UpdateAggregateStates_n(); 241 void UpdateAggregateStates_n();
269 242
270 void OnDtlsHandshakeError(rtc::SSLHandshakeError error); 243 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
271 244
272 rtc::Thread* const signaling_thread_ = nullptr; 245 rtc::Thread* const signaling_thread_ = nullptr;
273 rtc::Thread* const network_thread_ = nullptr; 246 rtc::Thread* const network_thread_ = nullptr;
274 PortAllocator* const port_allocator_ = nullptr; 247 PortAllocator* const port_allocator_ = nullptr;
275 248
276 std::map<std::string, std::unique_ptr<JsepTransport>> transports_; 249 std::map<std::string, std::unique_ptr<JsepTransport>> transports_;
277 std::vector<RefCountedChannel> channels_; 250 std::vector<RefCountedChannel*> channels_;
278 251
279 // Aggregate state for TransportChannelImpls. 252 // Aggregate state for TransportChannelImpls.
280 IceConnectionState connection_state_ = kIceConnectionConnecting; 253 IceConnectionState connection_state_ = kIceConnectionConnecting;
281 bool receiving_ = false; 254 bool receiving_ = false;
282 IceGatheringState gathering_state_ = kIceGatheringNew; 255 IceGatheringState gathering_state_ = kIceGatheringNew;
283 256
284 IceConfig ice_config_; 257 IceConfig ice_config_;
285 IceRole ice_role_ = ICEROLE_CONTROLLING; 258 IceRole ice_role_ = ICEROLE_CONTROLLING;
286 bool redetermine_role_on_ice_restart_; 259 bool redetermine_role_on_ice_restart_;
287 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); 260 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
288 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; 261 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
289 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; 262 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
290 rtc::AsyncInvoker invoker_; 263 rtc::AsyncInvoker invoker_;
291 // True if QUIC is used instead of DTLS. 264 // True if QUIC is used instead of DTLS.
292 bool quic_ = false; 265 bool quic_ = false;
293 266
294 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; 267 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr;
268
269 RTC_DISALLOW_COPY_AND_ASSIGN(TransportController);
295 }; 270 };
296 271
297 } // namespace cricket 272 } // namespace cricket
298 273
299 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ 274 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/transportcontroller.cc » ('j') | webrtc/p2p/base/transportcontroller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698