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

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

Issue 2639203004: Revert of make the DtlsTransportWrapper inherit form DtlsTransportInternal (Closed)
Patch Set: Created 3 years, 11 months 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/transportcontroller.h ('k') | webrtc/p2p/base/transportcontroller_unittest.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
(...skipping 27 matching lines...) Expand all
38 38
39 } // namespace { 39 } // namespace {
40 40
41 namespace cricket { 41 namespace cricket {
42 42
43 // This class groups the DTLS and ICE channels, and helps keep track of 43 // This class groups the DTLS and ICE channels, and helps keep track of
44 // how many external objects (BaseChannels) reference each channel. 44 // how many external objects (BaseChannels) reference each channel.
45 class TransportController::ChannelPair { 45 class TransportController::ChannelPair {
46 public: 46 public:
47 // TODO(deadbeef): Change the types of |dtls| and |ice| to 47 // TODO(deadbeef): Change the types of |dtls| and |ice| to
48 // DtlsTransport and P2PTransportChannelWrapper, once TransportChannelImpl is 48 // DtlsTransportChannelWrapper and P2PTransportChannelWrapper,
49 // removed. 49 // once TransportChannelImpl is removed.
50 ChannelPair(DtlsTransportInternal* dtls, IceTransportInternal* ice) 50 ChannelPair(TransportChannelImpl* dtls, IceTransportInternal* ice)
51 : ice_(ice), dtls_(dtls) {} 51 : ice_(ice), dtls_(dtls) {}
52 52
53 // Currently, all ICE-related calls still go through this DTLS channel. But 53 // Currently, all ICE-related calls still go through this DTLS channel. But
54 // that will change once we get rid of TransportChannelImpl, and the DTLS 54 // that will change once we get rid of TransportChannelImpl, and the DTLS
55 // channel interface no longer includes ICE-specific methods. 55 // channel interface no longer includes ICE-specific methods.
56 const DtlsTransportInternal* dtls() const { return dtls_.get(); } 56 const TransportChannelImpl* dtls() const { return dtls_.get(); }
57 DtlsTransportInternal* dtls() { return dtls_.get(); } 57 TransportChannelImpl* dtls() { return dtls_.get(); }
58 const IceTransportInternal* ice() const { return ice_.get(); } 58 const IceTransportInternal* ice() const { return ice_.get(); }
59 IceTransportInternal* ice() { return ice_.get(); } 59 IceTransportInternal* ice() { return ice_.get(); }
60 60
61 private: 61 private:
62 std::unique_ptr<IceTransportInternal> ice_; 62 std::unique_ptr<IceTransportInternal> ice_;
63 std::unique_ptr<DtlsTransportInternal> dtls_; 63 std::unique_ptr<TransportChannelImpl> dtls_;
64 64
65 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelPair); 65 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelPair);
66 }; 66 };
67 67
68 TransportController::TransportController(rtc::Thread* signaling_thread, 68 TransportController::TransportController(rtc::Thread* signaling_thread,
69 rtc::Thread* network_thread, 69 rtc::Thread* network_thread,
70 PortAllocator* port_allocator, 70 PortAllocator* port_allocator,
71 bool redetermine_role_on_ice_restart) 71 bool redetermine_role_on_ice_restart)
72 : signaling_thread_(signaling_thread), 72 : signaling_thread_(signaling_thread),
73 network_thread_(network_thread), 73 network_thread_(network_thread),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 rtc::Bind(&TransportController::GetStats_n, this, transport_name, stats)); 220 rtc::Bind(&TransportController::GetStats_n, this, transport_name, stats));
221 } 221 }
222 222
223 void TransportController::SetMetricsObserver( 223 void TransportController::SetMetricsObserver(
224 webrtc::MetricsObserverInterface* metrics_observer) { 224 webrtc::MetricsObserverInterface* metrics_observer) {
225 return network_thread_->Invoke<void>( 225 return network_thread_->Invoke<void>(
226 RTC_FROM_HERE, rtc::Bind(&TransportController::SetMetricsObserver_n, this, 226 RTC_FROM_HERE, rtc::Bind(&TransportController::SetMetricsObserver_n, this,
227 metrics_observer)); 227 metrics_observer));
228 } 228 }
229 229
230 DtlsTransportInternal* TransportController::CreateDtlsTransport( 230 TransportChannel* TransportController::CreateTransportChannel(
231 const std::string& transport_name, 231 const std::string& transport_name,
232 int component) { 232 int component) {
233 return network_thread_->Invoke<DtlsTransportInternal*>( 233 return network_thread_->Invoke<TransportChannel*>(
234 RTC_FROM_HERE, rtc::Bind(&TransportController::CreateDtlsTransport_n, 234 RTC_FROM_HERE, rtc::Bind(&TransportController::CreateTransportChannel_n,
235 this, transport_name, component)); 235 this, transport_name, component));
236 } 236 }
237 237
238 DtlsTransportInternal* TransportController::CreateDtlsTransport_n( 238 TransportChannel* TransportController::CreateTransportChannel_n(
239 const std::string& transport_name, 239 const std::string& transport_name,
240 int component) { 240 int component) {
241 RTC_DCHECK(network_thread_->IsCurrent()); 241 RTC_DCHECK(network_thread_->IsCurrent());
242 242
243 RefCountedChannel* existing_channel = GetChannel_n(transport_name, component); 243 RefCountedChannel* existing_channel = GetChannel_n(transport_name, component);
244 if (existing_channel) { 244 if (existing_channel) {
245 // Channel already exists; increment reference count and return. 245 // Channel already exists; increment reference count and return.
246 existing_channel->AddRef(); 246 existing_channel->AddRef();
247 return existing_channel->dtls(); 247 return existing_channel->dtls();
248 } 248 }
249 249
250 // Need to create a new channel. 250 // Need to create a new channel.
251 JsepTransport* transport = GetOrCreateJsepTransport(transport_name); 251 JsepTransport* transport = GetOrCreateJsepTransport(transport_name);
252 252
253 // Create DTLS channel wrapping ICE channel, and configure it. 253 // Create DTLS channel wrapping ICE channel, and configure it.
254 IceTransportInternal* ice = 254 IceTransportInternal* ice =
255 CreateIceTransportChannel_n(transport_name, component); 255 CreateIceTransportChannel_n(transport_name, component);
256 // TODO(deadbeef): To support QUIC, would need to create a 256 // TODO(deadbeef): To support QUIC, would need to create a
257 // QuicTransportChannel here. What is "dtls" in this file would then become 257 // QuicTransportChannel here. What is "dtls" in this file would then become
258 // "dtls or quic". 258 // "dtls or quic".
259 DtlsTransportInternal* dtls = 259 TransportChannelImpl* dtls =
260 CreateDtlsTransportChannel_n(transport_name, component, ice); 260 CreateDtlsTransportChannel_n(transport_name, component, ice);
261 dtls->ice_transport()->SetMetricsObserver(metrics_observer_); 261 dtls->SetMetricsObserver(metrics_observer_);
262 dtls->ice_transport()->SetIceRole(ice_role_); 262 dtls->SetIceRole(ice_role_);
263 dtls->ice_transport()->SetIceTiebreaker(ice_tiebreaker_); 263 dtls->SetIceTiebreaker(ice_tiebreaker_);
264 dtls->ice_transport()->SetIceConfig(ice_config_); 264 dtls->SetIceConfig(ice_config_);
265 if (certificate_) { 265 if (certificate_) {
266 bool set_cert_success = dtls->SetLocalCertificate(certificate_); 266 bool set_cert_success = dtls->SetLocalCertificate(certificate_);
267 RTC_DCHECK(set_cert_success); 267 RTC_DCHECK(set_cert_success);
268 } 268 }
269 269
270 // Connect to signals offered by the channels. Currently, the DTLS channel 270 // Connect to signals offered by the channels. Currently, the DTLS channel
271 // forwards signals from the ICE channel, so we only need to connect to the 271 // forwards signals from the ICE channel, so we only need to connect to the
272 // DTLS channel. In the future this won't be the case. 272 // DTLS channel. In the future this won't be the case.
273 dtls->SignalWritableState.connect( 273 dtls->SignalWritableState.connect(
274 this, &TransportController::OnChannelWritableState_n); 274 this, &TransportController::OnChannelWritableState_n);
275 dtls->SignalReceivingState.connect( 275 dtls->SignalReceivingState.connect(
276 this, &TransportController::OnChannelReceivingState_n); 276 this, &TransportController::OnChannelReceivingState_n);
277 dtls->SignalGatheringState.connect(
278 this, &TransportController::OnChannelGatheringState_n);
279 dtls->SignalCandidateGathered.connect(
280 this, &TransportController::OnChannelCandidateGathered_n);
281 dtls->SignalCandidatesRemoved.connect(
282 this, &TransportController::OnChannelCandidatesRemoved_n);
283 dtls->SignalRoleConflict.connect(
284 this, &TransportController::OnChannelRoleConflict_n);
285 dtls->SignalStateChanged.connect(
286 this, &TransportController::OnChannelStateChanged_n);
277 dtls->SignalDtlsHandshakeError.connect( 287 dtls->SignalDtlsHandshakeError.connect(
278 this, &TransportController::OnDtlsHandshakeError); 288 this, &TransportController::OnDtlsHandshakeError);
279 dtls->ice_transport()->SignalGatheringState.connect(
280 this, &TransportController::OnChannelGatheringState_n);
281 dtls->ice_transport()->SignalCandidateGathered.connect(
282 this, &TransportController::OnChannelCandidateGathered_n);
283 dtls->ice_transport()->SignalCandidatesRemoved.connect(
284 this, &TransportController::OnChannelCandidatesRemoved_n);
285 dtls->ice_transport()->SignalRoleConflict.connect(
286 this, &TransportController::OnChannelRoleConflict_n);
287 dtls->ice_transport()->SignalStateChanged.connect(
288 this, &TransportController::OnChannelStateChanged_n);
289 RefCountedChannel* new_pair = new RefCountedChannel(dtls, ice); 289 RefCountedChannel* new_pair = new RefCountedChannel(dtls, ice);
290 new_pair->AddRef(); 290 new_pair->AddRef();
291 channels_.insert(channels_.end(), new_pair); 291 channels_.insert(channels_.end(), new_pair);
292 bool channel_added = transport->AddChannel(dtls, component); 292 bool channel_added = transport->AddChannel(dtls, component);
293 RTC_DCHECK(channel_added); 293 RTC_DCHECK(channel_added);
294 // Adding a channel could cause aggregate state to change. 294 // Adding a channel could cause aggregate state to change.
295 UpdateAggregateStates_n(); 295 UpdateAggregateStates_n();
296 return dtls; 296 return dtls;
297 } 297 }
298 298
299 void TransportController::DestroyDtlsTransport( 299 void TransportController::DestroyTransportChannel(
300 const std::string& transport_name, 300 const std::string& transport_name,
301 int component) { 301 int component) {
302 network_thread_->Invoke<void>( 302 network_thread_->Invoke<void>(
303 RTC_FROM_HERE, rtc::Bind(&TransportController::DestroyDtlsTransport_n, 303 RTC_FROM_HERE, rtc::Bind(&TransportController::DestroyTransportChannel_n,
304 this, transport_name, component)); 304 this, transport_name, component));
305 } 305 }
306 306
307 void TransportController::DestroyDtlsTransport_n( 307 void TransportController::DestroyTransportChannel_n(
308 const std::string& transport_name, 308 const std::string& transport_name,
309 int component) { 309 int component) {
310 RTC_DCHECK(network_thread_->IsCurrent()); 310 RTC_DCHECK(network_thread_->IsCurrent());
311 auto it = GetChannelIterator_n(transport_name, component); 311 auto it = GetChannelIterator_n(transport_name, component);
312 if (it == channels_.end()) { 312 if (it == channels_.end()) {
313 LOG(LS_WARNING) << "Attempting to delete " << transport_name 313 LOG(LS_WARNING) << "Attempting to delete " << transport_name
314 << " TransportChannel " << component 314 << " TransportChannel " << component
315 << ", which doesn't exist."; 315 << ", which doesn't exist.";
316 return; 316 return;
317 } 317 }
(...skipping 15 matching lines...) Expand all
333 } 333 }
334 334
335 std::vector<std::string> TransportController::transport_names_for_testing() { 335 std::vector<std::string> TransportController::transport_names_for_testing() {
336 std::vector<std::string> ret; 336 std::vector<std::string> ret;
337 for (const auto& kv : transports_) { 337 for (const auto& kv : transports_) {
338 ret.push_back(kv.first); 338 ret.push_back(kv.first);
339 } 339 }
340 return ret; 340 return ret;
341 } 341 }
342 342
343 std::vector<DtlsTransportInternal*> 343 std::vector<TransportChannelImpl*> TransportController::channels_for_testing() {
344 TransportController::channels_for_testing() { 344 std::vector<TransportChannelImpl*> ret;
345 std::vector<DtlsTransportInternal*> ret;
346 for (RefCountedChannel* channel : channels_) { 345 for (RefCountedChannel* channel : channels_) {
347 ret.push_back(channel->dtls()); 346 ret.push_back(channel->dtls());
348 } 347 }
349 return ret; 348 return ret;
350 } 349 }
351 350
352 DtlsTransportInternal* TransportController::get_channel_for_testing( 351 TransportChannelImpl* TransportController::get_channel_for_testing(
353 const std::string& transport_name, 352 const std::string& transport_name,
354 int component) { 353 int component) {
355 RefCountedChannel* ch = GetChannel_n(transport_name, component); 354 RefCountedChannel* ch = GetChannel_n(transport_name, component);
356 return ch ? ch->dtls() : nullptr; 355 return ch ? ch->dtls() : nullptr;
357 } 356 }
358 357
359 IceTransportInternal* TransportController::CreateIceTransportChannel_n( 358 IceTransportInternal* TransportController::CreateIceTransportChannel_n(
360 const std::string& transport_name, 359 const std::string& transport_name,
361 int component) { 360 int component) {
362 return new P2PTransportChannel(transport_name, component, port_allocator_); 361 return new P2PTransportChannel(transport_name, component, port_allocator_);
363 } 362 }
364 363
365 DtlsTransportInternal* TransportController::CreateDtlsTransportChannel_n( 364 TransportChannelImpl* TransportController::CreateDtlsTransportChannel_n(
366 const std::string&, 365 const std::string&,
367 int, 366 int,
368 IceTransportInternal* ice) { 367 IceTransportInternal* ice) {
369 DtlsTransport* dtls = new DtlsTransport(ice); 368 DtlsTransportChannelWrapper* dtls = new DtlsTransportChannelWrapper(ice);
370 dtls->SetSslMaxProtocolVersion(ssl_max_version_); 369 dtls->SetSslMaxProtocolVersion(ssl_max_version_);
371 return dtls; 370 return dtls;
372 } 371 }
373 372
374 void TransportController::OnMessage(rtc::Message* pmsg) { 373 void TransportController::OnMessage(rtc::Message* pmsg) {
375 RTC_DCHECK(signaling_thread_->IsCurrent()); 374 RTC_DCHECK(signaling_thread_->IsCurrent());
376 375
377 switch (pmsg->message_id) { 376 switch (pmsg->message_id) {
378 case MSG_ICECONNECTIONSTATE: { 377 case MSG_ICECONNECTIONSTATE: {
379 rtc::TypedMessageData<IceConnectionState>* data = 378 rtc::TypedMessageData<IceConnectionState>* data =
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 496
498 ssl_max_version_ = version; 497 ssl_max_version_ = version;
499 return true; 498 return true;
500 } 499 }
501 500
502 void TransportController::SetIceConfig_n(const IceConfig& config) { 501 void TransportController::SetIceConfig_n(const IceConfig& config) {
503 RTC_DCHECK(network_thread_->IsCurrent()); 502 RTC_DCHECK(network_thread_->IsCurrent());
504 503
505 ice_config_ = config; 504 ice_config_ = config;
506 for (auto& channel : channels_) { 505 for (auto& channel : channels_) {
507 channel->dtls()->ice_transport()->SetIceConfig(ice_config_); 506 channel->dtls()->SetIceConfig(ice_config_);
508 } 507 }
509 } 508 }
510 509
511 void TransportController::SetIceRole_n(IceRole ice_role) { 510 void TransportController::SetIceRole_n(IceRole ice_role) {
512 RTC_DCHECK(network_thread_->IsCurrent()); 511 RTC_DCHECK(network_thread_->IsCurrent());
513 512
514 ice_role_ = ice_role; 513 ice_role_ = ice_role;
515 for (auto& channel : channels_) { 514 for (auto& channel : channels_) {
516 channel->dtls()->ice_transport()->SetIceRole(ice_role_); 515 channel->dtls()->SetIceRole(ice_role_);
517 } 516 }
518 } 517 }
519 518
520 bool TransportController::GetSslRole_n(const std::string& transport_name, 519 bool TransportController::GetSslRole_n(const std::string& transport_name,
521 rtc::SSLRole* role) const { 520 rtc::SSLRole* role) const {
522 RTC_DCHECK(network_thread_->IsCurrent()); 521 RTC_DCHECK(network_thread_->IsCurrent());
523 522
524 const JsepTransport* t = GetJsepTransport(transport_name); 523 const JsepTransport* t = GetJsepTransport(transport_name);
525 if (!t) { 524 if (!t) {
526 return false; 525 return false;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // description on a deleted transport. 637 // description on a deleted transport.
639 return true; 638 return true;
640 } 639 }
641 640
642 LOG(LS_INFO) << "Set remote transport description on " << transport_name; 641 LOG(LS_INFO) << "Set remote transport description on " << transport_name;
643 return transport->SetRemoteTransportDescription(tdesc, action, err); 642 return transport->SetRemoteTransportDescription(tdesc, action, err);
644 } 643 }
645 644
646 void TransportController::MaybeStartGathering_n() { 645 void TransportController::MaybeStartGathering_n() {
647 for (auto& channel : channels_) { 646 for (auto& channel : channels_) {
648 channel->dtls()->ice_transport()->MaybeStartGathering(); 647 channel->dtls()->MaybeStartGathering();
649 } 648 }
650 } 649 }
651 650
652 bool TransportController::AddRemoteCandidates_n( 651 bool TransportController::AddRemoteCandidates_n(
653 const std::string& transport_name, 652 const std::string& transport_name,
654 const Candidates& candidates, 653 const Candidates& candidates,
655 std::string* err) { 654 std::string* err) {
656 RTC_DCHECK(network_thread_->IsCurrent()); 655 RTC_DCHECK(network_thread_->IsCurrent());
657 656
658 // Verify each candidate before passing down to the transport layer. 657 // Verify each candidate before passing down to the transport layer.
659 if (!VerifyCandidates(candidates, err)) { 658 if (!VerifyCandidates(candidates, err)) {
660 return false; 659 return false;
661 } 660 }
662 661
663 JsepTransport* transport = GetJsepTransport(transport_name); 662 JsepTransport* transport = GetJsepTransport(transport_name);
664 if (!transport) { 663 if (!transport) {
665 // If we didn't find a transport, that's not an error; 664 // If we didn't find a transport, that's not an error;
666 // it could have been deleted as a result of bundling. 665 // it could have been deleted as a result of bundling.
667 return true; 666 return true;
668 } 667 }
669 668
670 for (const Candidate& candidate : candidates) { 669 for (const Candidate& candidate : candidates) {
671 RefCountedChannel* channel = 670 RefCountedChannel* channel =
672 GetChannel_n(transport_name, candidate.component()); 671 GetChannel_n(transport_name, candidate.component());
673 if (!channel) { 672 if (!channel) {
674 *err = "Candidate has an unknown component: " + candidate.ToString() + 673 *err = "Candidate has an unknown component: " + candidate.ToString() +
675 " for content: " + transport_name; 674 " for content: " + transport_name;
676 return false; 675 return false;
677 } 676 }
678 channel->dtls()->ice_transport()->AddRemoteCandidate(candidate); 677 channel->dtls()->AddRemoteCandidate(candidate);
679 } 678 }
680 return true; 679 return true;
681 } 680 }
682 681
683 bool TransportController::RemoveRemoteCandidates_n(const Candidates& candidates, 682 bool TransportController::RemoveRemoteCandidates_n(const Candidates& candidates,
684 std::string* err) { 683 std::string* err) {
685 RTC_DCHECK(network_thread_->IsCurrent()); 684 RTC_DCHECK(network_thread_->IsCurrent());
686 685
687 // Verify each candidate before passing down to the transport layer. 686 // Verify each candidate before passing down to the transport layer.
688 if (!VerifyCandidates(candidates, err)) { 687 if (!VerifyCandidates(candidates, err)) {
(...skipping 13 matching lines...) Expand all
702 JsepTransport* transport = GetJsepTransport(transport_name); 701 JsepTransport* transport = GetJsepTransport(transport_name);
703 if (!transport) { 702 if (!transport) {
704 // If we didn't find a transport, that's not an error; 703 // If we didn't find a transport, that's not an error;
705 // it could have been deleted as a result of bundling. 704 // it could have been deleted as a result of bundling.
706 continue; 705 continue;
707 } 706 }
708 for (const Candidate& candidate : candidates) { 707 for (const Candidate& candidate : candidates) {
709 RefCountedChannel* channel = 708 RefCountedChannel* channel =
710 GetChannel_n(transport_name, candidate.component()); 709 GetChannel_n(transport_name, candidate.component());
711 if (channel) { 710 if (channel) {
712 channel->dtls()->ice_transport()->RemoveRemoteCandidate(candidate); 711 channel->dtls()->RemoveRemoteCandidate(candidate);
713 } 712 }
714 } 713 }
715 } 714 }
716 return result; 715 return result;
717 } 716 }
718 717
719 bool TransportController::ReadyForRemoteCandidates_n( 718 bool TransportController::ReadyForRemoteCandidates_n(
720 const std::string& transport_name) const { 719 const std::string& transport_name) const {
721 RTC_DCHECK(network_thread_->IsCurrent()); 720 RTC_DCHECK(network_thread_->IsCurrent());
722 721
(...skipping 13 matching lines...) Expand all
736 return false; 735 return false;
737 } 736 }
738 return transport->GetStats(stats); 737 return transport->GetStats(stats);
739 } 738 }
740 739
741 void TransportController::SetMetricsObserver_n( 740 void TransportController::SetMetricsObserver_n(
742 webrtc::MetricsObserverInterface* metrics_observer) { 741 webrtc::MetricsObserverInterface* metrics_observer) {
743 RTC_DCHECK(network_thread_->IsCurrent()); 742 RTC_DCHECK(network_thread_->IsCurrent());
744 metrics_observer_ = metrics_observer; 743 metrics_observer_ = metrics_observer;
745 for (auto& channel : channels_) { 744 for (auto& channel : channels_) {
746 channel->dtls()->ice_transport()->SetMetricsObserver(metrics_observer); 745 channel->dtls()->SetMetricsObserver(metrics_observer);
747 } 746 }
748 } 747 }
749 748
750 void TransportController::OnChannelWritableState_n( 749 void TransportController::OnChannelWritableState_n(
751 rtc::PacketTransportInterface* transport) { 750 rtc::PacketTransportInterface* transport) {
752 RTC_DCHECK(network_thread_->IsCurrent()); 751 RTC_DCHECK(network_thread_->IsCurrent());
753 LOG(LS_INFO) << " TransportChannel " << transport->debug_name() 752 LOG(LS_INFO) << " TransportChannel " << transport->debug_name()
754 << " writability changed to " << transport->writable() << "."; 753 << " writability changed to " << transport->writable() << ".";
755 UpdateAggregateStates_n(); 754 UpdateAggregateStates_n();
756 } 755 }
757 756
758 void TransportController::OnChannelReceivingState_n( 757 void TransportController::OnChannelReceivingState_n(
759 rtc::PacketTransportInterface* transport) { 758 rtc::PacketTransportInterface* transport) {
760 RTC_DCHECK(network_thread_->IsCurrent()); 759 RTC_DCHECK(network_thread_->IsCurrent());
761 UpdateAggregateStates_n(); 760 UpdateAggregateStates_n();
762 } 761 }
763 762
764 void TransportController::OnChannelGatheringState_n( 763 void TransportController::OnChannelGatheringState_n(
765 IceTransportInternal* channel) { 764 TransportChannelImpl* channel) {
766 RTC_DCHECK(network_thread_->IsCurrent()); 765 RTC_DCHECK(network_thread_->IsCurrent());
767 UpdateAggregateStates_n(); 766 UpdateAggregateStates_n();
768 } 767 }
769 768
770 void TransportController::OnChannelCandidateGathered_n( 769 void TransportController::OnChannelCandidateGathered_n(
771 IceTransportInternal* channel, 770 TransportChannelImpl* channel,
772 const Candidate& candidate) { 771 const Candidate& candidate) {
773 RTC_DCHECK(network_thread_->IsCurrent()); 772 RTC_DCHECK(network_thread_->IsCurrent());
774 773
775 // We should never signal peer-reflexive candidates. 774 // We should never signal peer-reflexive candidates.
776 if (candidate.type() == PRFLX_PORT_TYPE) { 775 if (candidate.type() == PRFLX_PORT_TYPE) {
777 RTC_NOTREACHED(); 776 RTC_NOTREACHED();
778 return; 777 return;
779 } 778 }
780 std::vector<Candidate> candidates; 779 std::vector<Candidate> candidates;
781 candidates.push_back(candidate); 780 candidates.push_back(candidate);
782 CandidatesData* data = 781 CandidatesData* data =
783 new CandidatesData(channel->transport_name(), candidates); 782 new CandidatesData(channel->transport_name(), candidates);
784 signaling_thread_->Post(RTC_FROM_HERE, this, MSG_CANDIDATESGATHERED, data); 783 signaling_thread_->Post(RTC_FROM_HERE, this, MSG_CANDIDATESGATHERED, data);
785 } 784 }
786 785
787 void TransportController::OnChannelCandidatesRemoved_n( 786 void TransportController::OnChannelCandidatesRemoved_n(
788 IceTransportInternal* channel, 787 TransportChannelImpl* channel,
789 const Candidates& candidates) { 788 const Candidates& candidates) {
790 invoker_.AsyncInvoke<void>( 789 invoker_.AsyncInvoke<void>(
791 RTC_FROM_HERE, signaling_thread_, 790 RTC_FROM_HERE, signaling_thread_,
792 rtc::Bind(&TransportController::OnChannelCandidatesRemoved, this, 791 rtc::Bind(&TransportController::OnChannelCandidatesRemoved, this,
793 candidates)); 792 candidates));
794 } 793 }
795 794
796 void TransportController::OnChannelCandidatesRemoved( 795 void TransportController::OnChannelCandidatesRemoved(
797 const Candidates& candidates) { 796 const Candidates& candidates) {
798 RTC_DCHECK(signaling_thread_->IsCurrent()); 797 RTC_DCHECK(signaling_thread_->IsCurrent());
799 SignalCandidatesRemoved(candidates); 798 SignalCandidatesRemoved(candidates);
800 } 799 }
801 800
802 void TransportController::OnChannelRoleConflict_n( 801 void TransportController::OnChannelRoleConflict_n(
803 IceTransportInternal* channel) { 802 TransportChannelImpl* channel) {
804 RTC_DCHECK(network_thread_->IsCurrent()); 803 RTC_DCHECK(network_thread_->IsCurrent());
805 // Note: since the role conflict is handled entirely on the network thread, 804 // Note: since the role conflict is handled entirely on the network thread,
806 // we don't need to worry about role conflicts occurring on two ports at once. 805 // we don't need to worry about role conflicts occurring on two ports at once.
807 // The first one encountered should immediately reverse the role. 806 // The first one encountered should immediately reverse the role.
808 IceRole reversed_role = (ice_role_ == ICEROLE_CONTROLLING) 807 IceRole reversed_role = (ice_role_ == ICEROLE_CONTROLLING)
809 ? ICEROLE_CONTROLLED 808 ? ICEROLE_CONTROLLED
810 : ICEROLE_CONTROLLING; 809 : ICEROLE_CONTROLLING;
811 LOG(LS_INFO) << "Got role conflict; switching to " 810 LOG(LS_INFO) << "Got role conflict; switching to "
812 << (reversed_role == ICEROLE_CONTROLLING ? "controlling" 811 << (reversed_role == ICEROLE_CONTROLLING ? "controlling"
813 : "controlled") 812 : "controlled")
814 << " role."; 813 << " role.";
815 SetIceRole_n(reversed_role); 814 SetIceRole_n(reversed_role);
816 } 815 }
817 816
818 void TransportController::OnChannelStateChanged_n( 817 void TransportController::OnChannelStateChanged_n(
819 IceTransportInternal* channel) { 818 TransportChannelImpl* channel) {
820 RTC_DCHECK(network_thread_->IsCurrent()); 819 RTC_DCHECK(network_thread_->IsCurrent());
821 LOG(LS_INFO) << channel->transport_name() << " TransportChannel " 820 LOG(LS_INFO) << channel->transport_name() << " TransportChannel "
822 << channel->component() 821 << channel->component()
823 << " state changed. Check if state is complete."; 822 << " state changed. Check if state is complete.";
824 UpdateAggregateStates_n(); 823 UpdateAggregateStates_n();
825 } 824 }
826 825
827 void TransportController::UpdateAggregateStates_n() { 826 void TransportController::UpdateAggregateStates_n() {
828 RTC_DCHECK(network_thread_->IsCurrent()); 827 RTC_DCHECK(network_thread_->IsCurrent());
829 828
830 IceConnectionState new_connection_state = kIceConnectionConnecting; 829 IceConnectionState new_connection_state = kIceConnectionConnecting;
831 IceGatheringState new_gathering_state = kIceGatheringNew; 830 IceGatheringState new_gathering_state = kIceGatheringNew;
832 bool any_receiving = false; 831 bool any_receiving = false;
833 bool any_failed = false; 832 bool any_failed = false;
834 bool all_connected = !channels_.empty(); 833 bool all_connected = !channels_.empty();
835 bool all_completed = !channels_.empty(); 834 bool all_completed = !channels_.empty();
836 bool any_gathering = false; 835 bool any_gathering = false;
837 bool all_done_gathering = !channels_.empty(); 836 bool all_done_gathering = !channels_.empty();
838 for (const auto& channel : channels_) { 837 for (const auto& channel : channels_) {
839 any_receiving = any_receiving || channel->dtls()->receiving(); 838 any_receiving = any_receiving || channel->dtls()->receiving();
840 any_failed = any_failed || 839 any_failed = any_failed ||
841 channel->dtls()->ice_transport()->GetState() == 840 channel->dtls()->GetState() == IceTransportState::STATE_FAILED;
842 IceTransportState::STATE_FAILED;
843 all_connected = all_connected && channel->dtls()->writable(); 841 all_connected = all_connected && channel->dtls()->writable();
844 all_completed = 842 all_completed =
845 all_completed && channel->dtls()->writable() && 843 all_completed && channel->dtls()->writable() &&
846 channel->dtls()->ice_transport()->GetState() == 844 channel->dtls()->GetState() == IceTransportState::STATE_COMPLETED &&
847 IceTransportState::STATE_COMPLETED && 845 channel->dtls()->GetIceRole() == ICEROLE_CONTROLLING &&
848 channel->dtls()->ice_transport()->GetIceRole() == ICEROLE_CONTROLLING && 846 channel->dtls()->gathering_state() == kIceGatheringComplete;
849 channel->dtls()->ice_transport()->gathering_state() ==
850 kIceGatheringComplete;
851 any_gathering = 847 any_gathering =
852 any_gathering || 848 any_gathering || channel->dtls()->gathering_state() != kIceGatheringNew;
853 channel->dtls()->ice_transport()->gathering_state() != kIceGatheringNew; 849 all_done_gathering =
854 all_done_gathering = all_done_gathering && 850 all_done_gathering &&
855 channel->dtls()->ice_transport()->gathering_state() == 851 channel->dtls()->gathering_state() == kIceGatheringComplete;
856 kIceGatheringComplete;
857 } 852 }
853
858 if (any_failed) { 854 if (any_failed) {
859 new_connection_state = kIceConnectionFailed; 855 new_connection_state = kIceConnectionFailed;
860 } else if (all_completed) { 856 } else if (all_completed) {
861 new_connection_state = kIceConnectionCompleted; 857 new_connection_state = kIceConnectionCompleted;
862 } else if (all_connected) { 858 } else if (all_connected) {
863 new_connection_state = kIceConnectionConnected; 859 new_connection_state = kIceConnectionConnected;
864 } 860 }
865 if (connection_state_ != new_connection_state) { 861 if (connection_state_ != new_connection_state) {
866 connection_state_ = new_connection_state; 862 connection_state_ = new_connection_state;
867 signaling_thread_->Post( 863 signaling_thread_->Post(
(...skipping 18 matching lines...) Expand all
886 RTC_FROM_HERE, this, MSG_ICEGATHERINGSTATE, 882 RTC_FROM_HERE, this, MSG_ICEGATHERINGSTATE,
887 new rtc::TypedMessageData<IceGatheringState>(new_gathering_state)); 883 new rtc::TypedMessageData<IceGatheringState>(new_gathering_state));
888 } 884 }
889 } 885 }
890 886
891 void TransportController::OnDtlsHandshakeError(rtc::SSLHandshakeError error) { 887 void TransportController::OnDtlsHandshakeError(rtc::SSLHandshakeError error) {
892 SignalDtlsHandshakeError(error); 888 SignalDtlsHandshakeError(error);
893 } 889 }
894 890
895 } // namespace cricket 891 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/transportcontroller.h ('k') | webrtc/p2p/base/transportcontroller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698