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

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

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Fix the format. 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
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 // DtlsTransportChannelWrapper and P2PTransportChannelWrapper, 48 // DtlsTransport and P2PTransportChannelWrapper, once TransportChannelImpl is
49 // once TransportChannelImpl is removed. 49 // removed.
50 ChannelPair(TransportChannelImpl* dtls, IceTransportInternal* ice) 50 ChannelPair(DtlsTransportInternal* 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 TransportChannelImpl* dtls() const { return dtls_.get(); } 56 const DtlsTransportInternal* dtls() const { return dtls_.get(); }
57 TransportChannelImpl* dtls() { return dtls_.get(); } 57 DtlsTransportInternal* 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<TransportChannelImpl> dtls_; 63 std::unique_ptr<DtlsTransportInternal> 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 TransportChannel* TransportController::CreateTransportChannel( 230 DtlsTransportInternal* TransportController::CreateDtlsTransport(
231 const std::string& transport_name, 231 const std::string& transport_name,
232 int component) { 232 int component) {
233 return network_thread_->Invoke<TransportChannel*>( 233 return network_thread_->Invoke<DtlsTransportInternal*>(
234 RTC_FROM_HERE, rtc::Bind(&TransportController::CreateTransportChannel_n, 234 RTC_FROM_HERE, rtc::Bind(&TransportController::CreateDtlsTransport_n,
235 this, transport_name, component)); 235 this, transport_name, component));
236 } 236 }
237 237
238 TransportChannel* TransportController::CreateTransportChannel_n( 238 DtlsTransportInternal* TransportController::CreateDtlsTransport_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 TransportChannelImpl* dtls = 259 DtlsTransportInternal* dtls =
260 CreateDtlsTransportChannel_n(transport_name, component, ice); 260 CreateDtlsTransportChannel_n(transport_name, component, ice);
261 dtls->SetMetricsObserver(metrics_observer_); 261 dtls->ice_transport()->SetMetricsObserver(metrics_observer_);
262 dtls->SetIceRole(ice_role_); 262 dtls->ice_transport()->SetIceRole(ice_role_);
263 dtls->SetIceTiebreaker(ice_tiebreaker_); 263 dtls->ice_transport()->SetIceTiebreaker(ice_tiebreaker_);
264 dtls->SetIceConfig(ice_config_); 264 dtls->ice_transport()->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);
287 dtls->SignalDtlsHandshakeError.connect( 277 dtls->SignalDtlsHandshakeError.connect(
288 this, &TransportController::OnDtlsHandshakeError); 278 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::DestroyTransportChannel_n( 299 void TransportController::DestroyDtlsTransport_n(
300 const std::string& transport_name, 300 const std::string& transport_name,
301 int component) { 301 int component) {
302 RTC_DCHECK(network_thread_->IsCurrent()); 302 RTC_DCHECK(network_thread_->IsCurrent());
303 auto it = GetChannelIterator_n(transport_name, component); 303 auto it = GetChannelIterator_n(transport_name, component);
304 if (it == channels_.end()) { 304 if (it == channels_.end()) {
305 LOG(LS_WARNING) << "Attempting to delete " << transport_name 305 LOG(LS_WARNING) << "Attempting to delete " << transport_name
306 << " TransportChannel " << component 306 << " TransportChannel " << component
307 << ", which doesn't exist."; 307 << ", which doesn't exist.";
308 return; 308 return;
309 } 309 }
(...skipping 15 matching lines...) Expand all
325 } 325 }
326 326
327 std::vector<std::string> TransportController::transport_names_for_testing() { 327 std::vector<std::string> TransportController::transport_names_for_testing() {
328 std::vector<std::string> ret; 328 std::vector<std::string> ret;
329 for (const auto& kv : transports_) { 329 for (const auto& kv : transports_) {
330 ret.push_back(kv.first); 330 ret.push_back(kv.first);
331 } 331 }
332 return ret; 332 return ret;
333 } 333 }
334 334
335 std::vector<TransportChannelImpl*> TransportController::channels_for_testing() { 335 std::vector<DtlsTransportInternal*>
336 std::vector<TransportChannelImpl*> ret; 336 TransportController::channels_for_testing() {
337 std::vector<DtlsTransportInternal*> ret;
337 for (RefCountedChannel* channel : channels_) { 338 for (RefCountedChannel* channel : channels_) {
338 ret.push_back(channel->dtls()); 339 ret.push_back(channel->dtls());
339 } 340 }
340 return ret; 341 return ret;
341 } 342 }
342 343
343 TransportChannelImpl* TransportController::get_channel_for_testing( 344 DtlsTransportInternal* TransportController::get_channel_for_testing(
344 const std::string& transport_name, 345 const std::string& transport_name,
345 int component) { 346 int component) {
346 RefCountedChannel* ch = GetChannel_n(transport_name, component); 347 RefCountedChannel* ch = GetChannel_n(transport_name, component);
347 return ch ? ch->dtls() : nullptr; 348 return ch ? ch->dtls() : nullptr;
348 } 349 }
349 350
350 IceTransportInternal* TransportController::CreateIceTransportChannel_n( 351 IceTransportInternal* TransportController::CreateIceTransportChannel_n(
351 const std::string& transport_name, 352 const std::string& transport_name,
352 int component) { 353 int component) {
353 return new P2PTransportChannel(transport_name, component, port_allocator_); 354 return new P2PTransportChannel(transport_name, component, port_allocator_);
354 } 355 }
355 356
356 TransportChannelImpl* TransportController::CreateDtlsTransportChannel_n( 357 DtlsTransportInternal* TransportController::CreateDtlsTransportChannel_n(
357 const std::string&, 358 const std::string&,
358 int, 359 int,
359 IceTransportInternal* ice) { 360 IceTransportInternal* ice) {
360 DtlsTransportChannelWrapper* dtls = new DtlsTransportChannelWrapper(ice); 361 DtlsTransport* dtls = new DtlsTransport(ice);
361 dtls->SetSslMaxProtocolVersion(ssl_max_version_); 362 dtls->SetSslMaxProtocolVersion(ssl_max_version_);
362 return dtls; 363 return dtls;
363 } 364 }
364 365
365 void TransportController::OnMessage(rtc::Message* pmsg) { 366 void TransportController::OnMessage(rtc::Message* pmsg) {
366 RTC_DCHECK(signaling_thread_->IsCurrent()); 367 RTC_DCHECK(signaling_thread_->IsCurrent());
367 368
368 switch (pmsg->message_id) { 369 switch (pmsg->message_id) {
369 case MSG_ICECONNECTIONSTATE: { 370 case MSG_ICECONNECTIONSTATE: {
370 rtc::TypedMessageData<IceConnectionState>* data = 371 rtc::TypedMessageData<IceConnectionState>* data =
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 489
489 ssl_max_version_ = version; 490 ssl_max_version_ = version;
490 return true; 491 return true;
491 } 492 }
492 493
493 void TransportController::SetIceConfig_n(const IceConfig& config) { 494 void TransportController::SetIceConfig_n(const IceConfig& config) {
494 RTC_DCHECK(network_thread_->IsCurrent()); 495 RTC_DCHECK(network_thread_->IsCurrent());
495 496
496 ice_config_ = config; 497 ice_config_ = config;
497 for (auto& channel : channels_) { 498 for (auto& channel : channels_) {
498 channel->dtls()->SetIceConfig(ice_config_); 499 channel->dtls()->ice_transport()->SetIceConfig(ice_config_);
499 } 500 }
500 } 501 }
501 502
502 void TransportController::SetIceRole_n(IceRole ice_role) { 503 void TransportController::SetIceRole_n(IceRole ice_role) {
503 RTC_DCHECK(network_thread_->IsCurrent()); 504 RTC_DCHECK(network_thread_->IsCurrent());
504 505
505 ice_role_ = ice_role; 506 ice_role_ = ice_role;
506 for (auto& channel : channels_) { 507 for (auto& channel : channels_) {
507 channel->dtls()->SetIceRole(ice_role_); 508 channel->dtls()->ice_transport()->SetIceRole(ice_role_);
508 } 509 }
509 } 510 }
510 511
511 bool TransportController::GetSslRole_n(const std::string& transport_name, 512 bool TransportController::GetSslRole_n(const std::string& transport_name,
512 rtc::SSLRole* role) const { 513 rtc::SSLRole* role) const {
513 RTC_DCHECK(network_thread_->IsCurrent()); 514 RTC_DCHECK(network_thread_->IsCurrent());
514 515
515 const JsepTransport* t = GetJsepTransport(transport_name); 516 const JsepTransport* t = GetJsepTransport(transport_name);
516 if (!t) { 517 if (!t) {
517 return false; 518 return false;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 // description on a deleted transport. 630 // description on a deleted transport.
630 return true; 631 return true;
631 } 632 }
632 633
633 LOG(LS_INFO) << "Set remote transport description on " << transport_name; 634 LOG(LS_INFO) << "Set remote transport description on " << transport_name;
634 return transport->SetRemoteTransportDescription(tdesc, action, err); 635 return transport->SetRemoteTransportDescription(tdesc, action, err);
635 } 636 }
636 637
637 void TransportController::MaybeStartGathering_n() { 638 void TransportController::MaybeStartGathering_n() {
638 for (auto& channel : channels_) { 639 for (auto& channel : channels_) {
639 channel->dtls()->MaybeStartGathering(); 640 channel->dtls()->ice_transport()->MaybeStartGathering();
640 } 641 }
641 } 642 }
642 643
643 bool TransportController::AddRemoteCandidates_n( 644 bool TransportController::AddRemoteCandidates_n(
644 const std::string& transport_name, 645 const std::string& transport_name,
645 const Candidates& candidates, 646 const Candidates& candidates,
646 std::string* err) { 647 std::string* err) {
647 RTC_DCHECK(network_thread_->IsCurrent()); 648 RTC_DCHECK(network_thread_->IsCurrent());
648 649
649 // Verify each candidate before passing down to the transport layer. 650 // Verify each candidate before passing down to the transport layer.
650 if (!VerifyCandidates(candidates, err)) { 651 if (!VerifyCandidates(candidates, err)) {
651 return false; 652 return false;
652 } 653 }
653 654
654 JsepTransport* transport = GetJsepTransport(transport_name); 655 JsepTransport* transport = GetJsepTransport(transport_name);
655 if (!transport) { 656 if (!transport) {
656 // If we didn't find a transport, that's not an error; 657 // If we didn't find a transport, that's not an error;
657 // it could have been deleted as a result of bundling. 658 // it could have been deleted as a result of bundling.
658 return true; 659 return true;
659 } 660 }
660 661
661 for (const Candidate& candidate : candidates) { 662 for (const Candidate& candidate : candidates) {
662 RefCountedChannel* channel = 663 RefCountedChannel* channel =
663 GetChannel_n(transport_name, candidate.component()); 664 GetChannel_n(transport_name, candidate.component());
664 if (!channel) { 665 if (!channel) {
665 *err = "Candidate has an unknown component: " + candidate.ToString() + 666 *err = "Candidate has an unknown component: " + candidate.ToString() +
666 " for content: " + transport_name; 667 " for content: " + transport_name;
667 return false; 668 return false;
668 } 669 }
669 channel->dtls()->AddRemoteCandidate(candidate); 670 channel->dtls()->ice_transport()->AddRemoteCandidate(candidate);
670 } 671 }
671 return true; 672 return true;
672 } 673 }
673 674
674 bool TransportController::RemoveRemoteCandidates_n(const Candidates& candidates, 675 bool TransportController::RemoveRemoteCandidates_n(const Candidates& candidates,
675 std::string* err) { 676 std::string* err) {
676 RTC_DCHECK(network_thread_->IsCurrent()); 677 RTC_DCHECK(network_thread_->IsCurrent());
677 678
678 // Verify each candidate before passing down to the transport layer. 679 // Verify each candidate before passing down to the transport layer.
679 if (!VerifyCandidates(candidates, err)) { 680 if (!VerifyCandidates(candidates, err)) {
(...skipping 13 matching lines...) Expand all
693 JsepTransport* transport = GetJsepTransport(transport_name); 694 JsepTransport* transport = GetJsepTransport(transport_name);
694 if (!transport) { 695 if (!transport) {
695 // If we didn't find a transport, that's not an error; 696 // If we didn't find a transport, that's not an error;
696 // it could have been deleted as a result of bundling. 697 // it could have been deleted as a result of bundling.
697 continue; 698 continue;
698 } 699 }
699 for (const Candidate& candidate : candidates) { 700 for (const Candidate& candidate : candidates) {
700 RefCountedChannel* channel = 701 RefCountedChannel* channel =
701 GetChannel_n(transport_name, candidate.component()); 702 GetChannel_n(transport_name, candidate.component());
702 if (channel) { 703 if (channel) {
703 channel->dtls()->RemoveRemoteCandidate(candidate); 704 channel->dtls()->ice_transport()->RemoveRemoteCandidate(candidate);
704 } 705 }
705 } 706 }
706 } 707 }
707 return result; 708 return result;
708 } 709 }
709 710
710 bool TransportController::ReadyForRemoteCandidates_n( 711 bool TransportController::ReadyForRemoteCandidates_n(
711 const std::string& transport_name) const { 712 const std::string& transport_name) const {
712 RTC_DCHECK(network_thread_->IsCurrent()); 713 RTC_DCHECK(network_thread_->IsCurrent());
713 714
(...skipping 13 matching lines...) Expand all
727 return false; 728 return false;
728 } 729 }
729 return transport->GetStats(stats); 730 return transport->GetStats(stats);
730 } 731 }
731 732
732 void TransportController::SetMetricsObserver_n( 733 void TransportController::SetMetricsObserver_n(
733 webrtc::MetricsObserverInterface* metrics_observer) { 734 webrtc::MetricsObserverInterface* metrics_observer) {
734 RTC_DCHECK(network_thread_->IsCurrent()); 735 RTC_DCHECK(network_thread_->IsCurrent());
735 metrics_observer_ = metrics_observer; 736 metrics_observer_ = metrics_observer;
736 for (auto& channel : channels_) { 737 for (auto& channel : channels_) {
737 channel->dtls()->SetMetricsObserver(metrics_observer); 738 channel->dtls()->ice_transport()->SetMetricsObserver(metrics_observer);
738 } 739 }
739 } 740 }
740 741
741 void TransportController::OnChannelWritableState_n( 742 void TransportController::OnChannelWritableState_n(
742 rtc::PacketTransportInterface* transport) { 743 rtc::PacketTransportInterface* transport) {
743 RTC_DCHECK(network_thread_->IsCurrent()); 744 RTC_DCHECK(network_thread_->IsCurrent());
744 LOG(LS_INFO) << " TransportChannel " << transport->debug_name() 745 LOG(LS_INFO) << " TransportChannel " << transport->debug_name()
745 << " writability changed to " << transport->writable() << "."; 746 << " writability changed to " << transport->writable() << ".";
746 UpdateAggregateStates_n(); 747 UpdateAggregateStates_n();
747 } 748 }
748 749
749 void TransportController::OnChannelReceivingState_n( 750 void TransportController::OnChannelReceivingState_n(
750 rtc::PacketTransportInterface* transport) { 751 rtc::PacketTransportInterface* transport) {
751 RTC_DCHECK(network_thread_->IsCurrent()); 752 RTC_DCHECK(network_thread_->IsCurrent());
752 UpdateAggregateStates_n(); 753 UpdateAggregateStates_n();
753 } 754 }
754 755
755 void TransportController::OnChannelGatheringState_n( 756 void TransportController::OnChannelGatheringState_n(
756 TransportChannelImpl* channel) { 757 IceTransportInternal* channel) {
757 RTC_DCHECK(network_thread_->IsCurrent()); 758 RTC_DCHECK(network_thread_->IsCurrent());
758 UpdateAggregateStates_n(); 759 UpdateAggregateStates_n();
759 } 760 }
760 761
761 void TransportController::OnChannelCandidateGathered_n( 762 void TransportController::OnChannelCandidateGathered_n(
762 TransportChannelImpl* channel, 763 IceTransportInternal* channel,
763 const Candidate& candidate) { 764 const Candidate& candidate) {
764 RTC_DCHECK(network_thread_->IsCurrent()); 765 RTC_DCHECK(network_thread_->IsCurrent());
765 766
766 // We should never signal peer-reflexive candidates. 767 // We should never signal peer-reflexive candidates.
767 if (candidate.type() == PRFLX_PORT_TYPE) { 768 if (candidate.type() == PRFLX_PORT_TYPE) {
768 RTC_NOTREACHED(); 769 RTC_NOTREACHED();
769 return; 770 return;
770 } 771 }
771 std::vector<Candidate> candidates; 772 std::vector<Candidate> candidates;
772 candidates.push_back(candidate); 773 candidates.push_back(candidate);
773 CandidatesData* data = 774 CandidatesData* data =
774 new CandidatesData(channel->transport_name(), candidates); 775 new CandidatesData(channel->transport_name(), candidates);
775 signaling_thread_->Post(RTC_FROM_HERE, this, MSG_CANDIDATESGATHERED, data); 776 signaling_thread_->Post(RTC_FROM_HERE, this, MSG_CANDIDATESGATHERED, data);
776 } 777 }
777 778
778 void TransportController::OnChannelCandidatesRemoved_n( 779 void TransportController::OnChannelCandidatesRemoved_n(
779 TransportChannelImpl* channel, 780 IceTransportInternal* channel,
780 const Candidates& candidates) { 781 const Candidates& candidates) {
781 invoker_.AsyncInvoke<void>( 782 invoker_.AsyncInvoke<void>(
782 RTC_FROM_HERE, signaling_thread_, 783 RTC_FROM_HERE, signaling_thread_,
783 rtc::Bind(&TransportController::OnChannelCandidatesRemoved, this, 784 rtc::Bind(&TransportController::OnChannelCandidatesRemoved, this,
784 candidates)); 785 candidates));
785 } 786 }
786 787
787 void TransportController::OnChannelCandidatesRemoved( 788 void TransportController::OnChannelCandidatesRemoved(
788 const Candidates& candidates) { 789 const Candidates& candidates) {
789 RTC_DCHECK(signaling_thread_->IsCurrent()); 790 RTC_DCHECK(signaling_thread_->IsCurrent());
790 SignalCandidatesRemoved(candidates); 791 SignalCandidatesRemoved(candidates);
791 } 792 }
792 793
793 void TransportController::OnChannelRoleConflict_n( 794 void TransportController::OnChannelRoleConflict_n(
794 TransportChannelImpl* channel) { 795 IceTransportInternal* channel) {
795 RTC_DCHECK(network_thread_->IsCurrent()); 796 RTC_DCHECK(network_thread_->IsCurrent());
796 // Note: since the role conflict is handled entirely on the network thread, 797 // Note: since the role conflict is handled entirely on the network thread,
797 // we don't need to worry about role conflicts occurring on two ports at once. 798 // we don't need to worry about role conflicts occurring on two ports at once.
798 // The first one encountered should immediately reverse the role. 799 // The first one encountered should immediately reverse the role.
799 IceRole reversed_role = (ice_role_ == ICEROLE_CONTROLLING) 800 IceRole reversed_role = (ice_role_ == ICEROLE_CONTROLLING)
800 ? ICEROLE_CONTROLLED 801 ? ICEROLE_CONTROLLED
801 : ICEROLE_CONTROLLING; 802 : ICEROLE_CONTROLLING;
802 LOG(LS_INFO) << "Got role conflict; switching to " 803 LOG(LS_INFO) << "Got role conflict; switching to "
803 << (reversed_role == ICEROLE_CONTROLLING ? "controlling" 804 << (reversed_role == ICEROLE_CONTROLLING ? "controlling"
804 : "controlled") 805 : "controlled")
805 << " role."; 806 << " role.";
806 SetIceRole_n(reversed_role); 807 SetIceRole_n(reversed_role);
807 } 808 }
808 809
809 void TransportController::OnChannelStateChanged_n( 810 void TransportController::OnChannelStateChanged_n(
810 TransportChannelImpl* channel) { 811 IceTransportInternal* channel) {
811 RTC_DCHECK(network_thread_->IsCurrent()); 812 RTC_DCHECK(network_thread_->IsCurrent());
812 LOG(LS_INFO) << channel->transport_name() << " TransportChannel " 813 LOG(LS_INFO) << channel->transport_name() << " TransportChannel "
813 << channel->component() 814 << channel->component()
814 << " state changed. Check if state is complete."; 815 << " state changed. Check if state is complete.";
815 UpdateAggregateStates_n(); 816 UpdateAggregateStates_n();
816 } 817 }
817 818
818 void TransportController::UpdateAggregateStates_n() { 819 void TransportController::UpdateAggregateStates_n() {
819 RTC_DCHECK(network_thread_->IsCurrent()); 820 RTC_DCHECK(network_thread_->IsCurrent());
820 821
821 IceConnectionState new_connection_state = kIceConnectionConnecting; 822 IceConnectionState new_connection_state = kIceConnectionConnecting;
822 IceGatheringState new_gathering_state = kIceGatheringNew; 823 IceGatheringState new_gathering_state = kIceGatheringNew;
823 bool any_receiving = false; 824 bool any_receiving = false;
824 bool any_failed = false; 825 bool any_failed = false;
825 bool all_connected = !channels_.empty(); 826 bool all_connected = !channels_.empty();
826 bool all_completed = !channels_.empty(); 827 bool all_completed = !channels_.empty();
827 bool any_gathering = false; 828 bool any_gathering = false;
828 bool all_done_gathering = !channels_.empty(); 829 bool all_done_gathering = !channels_.empty();
829 for (const auto& channel : channels_) { 830 for (const auto& channel : channels_) {
830 any_receiving = any_receiving || channel->dtls()->receiving(); 831 any_receiving = any_receiving || channel->dtls()->receiving();
831 any_failed = any_failed || 832 any_failed = any_failed ||
832 channel->dtls()->GetState() == IceTransportState::STATE_FAILED; 833 channel->dtls()->ice_transport()->GetState() ==
834 IceTransportState::STATE_FAILED;
833 all_connected = all_connected && channel->dtls()->writable(); 835 all_connected = all_connected && channel->dtls()->writable();
834 all_completed = 836 all_completed =
835 all_completed && channel->dtls()->writable() && 837 all_completed && channel->dtls()->writable() &&
836 channel->dtls()->GetState() == IceTransportState::STATE_COMPLETED && 838 channel->dtls()->ice_transport()->GetState() ==
837 channel->dtls()->GetIceRole() == ICEROLE_CONTROLLING && 839 IceTransportState::STATE_COMPLETED &&
838 channel->dtls()->gathering_state() == kIceGatheringComplete; 840 channel->dtls()->ice_transport()->GetIceRole() == ICEROLE_CONTROLLING &&
841 channel->dtls()->ice_transport()->gathering_state() ==
842 kIceGatheringComplete;
839 any_gathering = 843 any_gathering =
840 any_gathering || channel->dtls()->gathering_state() != kIceGatheringNew; 844 any_gathering ||
841 all_done_gathering = 845 channel->dtls()->ice_transport()->gathering_state() != kIceGatheringNew;
842 all_done_gathering && 846 all_done_gathering = all_done_gathering &&
843 channel->dtls()->gathering_state() == kIceGatheringComplete; 847 channel->dtls()->ice_transport()->gathering_state() ==
848 kIceGatheringComplete;
844 } 849 }
845
846 if (any_failed) { 850 if (any_failed) {
847 new_connection_state = kIceConnectionFailed; 851 new_connection_state = kIceConnectionFailed;
848 } else if (all_completed) { 852 } else if (all_completed) {
849 new_connection_state = kIceConnectionCompleted; 853 new_connection_state = kIceConnectionCompleted;
850 } else if (all_connected) { 854 } else if (all_connected) {
851 new_connection_state = kIceConnectionConnected; 855 new_connection_state = kIceConnectionConnected;
852 } 856 }
853 if (connection_state_ != new_connection_state) { 857 if (connection_state_ != new_connection_state) {
854 connection_state_ = new_connection_state; 858 connection_state_ = new_connection_state;
855 signaling_thread_->Post( 859 signaling_thread_->Post(
(...skipping 18 matching lines...) Expand all
874 RTC_FROM_HERE, this, MSG_ICEGATHERINGSTATE, 878 RTC_FROM_HERE, this, MSG_ICEGATHERINGSTATE,
875 new rtc::TypedMessageData<IceGatheringState>(new_gathering_state)); 879 new rtc::TypedMessageData<IceGatheringState>(new_gathering_state));
876 } 880 }
877 } 881 }
878 882
879 void TransportController::OnDtlsHandshakeError(rtc::SSLHandshakeError error) { 883 void TransportController::OnDtlsHandshakeError(rtc::SSLHandshakeError error) {
880 SignalDtlsHandshakeError(error); 884 SignalDtlsHandshakeError(error);
881 } 885 }
882 886
883 } // namespace cricket 887 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698