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

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

Issue 1498993002: Add ufrag to the ICE candidate signaling. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 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 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 341
342 void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag, 342 void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag,
343 const std::string& ice_pwd) { 343 const std::string& ice_pwd) {
344 ASSERT(worker_thread_ == rtc::Thread::Current()); 344 ASSERT(worker_thread_ == rtc::Thread::Current());
345 bool ice_restart = false; 345 bool ice_restart = false;
346 if (!remote_ice_ufrag_.empty() && !remote_ice_pwd_.empty()) { 346 if (!remote_ice_ufrag_.empty() && !remote_ice_pwd_.empty()) {
347 ice_restart = (remote_ice_ufrag_ != ice_ufrag) || 347 ice_restart = (remote_ice_ufrag_ != ice_ufrag) ||
348 (remote_ice_pwd_!= ice_pwd); 348 (remote_ice_pwd_!= ice_pwd);
349 } 349 }
350 350
351 if (ice_restart) {
352 old_remote_ufrags_.insert(remote_ice_ufrag_);
353 }
351 remote_ice_ufrag_ = ice_ufrag; 354 remote_ice_ufrag_ = ice_ufrag;
352 remote_ice_pwd_ = ice_pwd; 355 remote_ice_pwd_ = ice_pwd;
353 356
354 // We need to update the credentials for any peer reflexive candidates. 357 // We need to update the credentials for any peer reflexive candidates.
355 std::vector<Connection*>::iterator it = connections_.begin(); 358 std::vector<Connection*>::iterator it = connections_.begin();
356 for (; it != connections_.end(); ++it) { 359 for (; it != connections_.end(); ++it) {
357 (*it)->MaybeSetRemoteIceCredentials(ice_ufrag, ice_pwd); 360 (*it)->MaybeSetRemoteIceCredentials(ice_ufrag, ice_pwd);
358 } 361 }
359 362
360 if (ice_restart) { 363 if (ice_restart) {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } else { 638 } else {
636 LOG(LS_INFO) << "Not switching the best connection on controlled side yet," 639 LOG(LS_INFO) << "Not switching the best connection on controlled side yet,"
637 << " because it's not writable: " << conn->ToString(); 640 << " because it's not writable: " << conn->ToString();
638 pending_best_connection_ = conn; 641 pending_best_connection_ = conn;
639 } 642 }
640 } 643 }
641 644
642 void P2PTransportChannel::AddRemoteCandidate(const Candidate& candidate) { 645 void P2PTransportChannel::AddRemoteCandidate(const Candidate& candidate) {
643 ASSERT(worker_thread_ == rtc::Thread::Current()); 646 ASSERT(worker_thread_ == rtc::Thread::Current());
644 647
645 uint32_t generation = candidate.generation();
646 // Network may not guarantee the order of the candidate delivery. If a 648 // Network may not guarantee the order of the candidate delivery. If a
647 // remote candidate with an older generation arrives, drop it. 649 // remote candidate with an older generation arrives, drop it.
648 if (generation != 0 && generation < remote_candidate_generation_) { 650 const std::string& ufrag = candidate.username();
651 uint32_t generation = candidate.generation();
652 if (!ufrag.empty()) {
653 if (old_remote_ufrags_.find(ufrag) != old_remote_ufrags_.end()) {
654 LOG(LS_WARNING) << "Dropping a remote candidate because its ICE ufrag "
655 << ufrag << " is old.";
pthatcher1 2015/12/04 20:43:50 Perhaps say "because its ufrag indicates it was fo
honghaiz3 2015/12/09 23:57:54 Done.
656 return;
657 }
658 // TODO(honghaiz): Get rid of the checking using generation when all clients
659 // include ufrag in the candidate signaling.
660 } else if (generation != 0 && generation < remote_candidate_generation_) {
649 LOG(LS_WARNING) << "Dropping a remote candidate because its generation " 661 LOG(LS_WARNING) << "Dropping a remote candidate because its generation "
650 << generation 662 << generation
651 << " is lower than the current remote generation " 663 << " is lower than the current remote generation "
652 << remote_candidate_generation_; 664 << remote_candidate_generation_;
653 return; 665 return;
654 } 666 }
655 667
656 // Create connections to this remote candidate. 668 // Create connections to this remote candidate.
657 CreateConnections(candidate, NULL); 669 CreateConnections(candidate, NULL);
658 670
659 // Resort the connections list, which may have new elements. 671 // Resort the connections list, which may have new elements.
660 SortConnections(); 672 SortConnections();
661 } 673 }
662 674
663 // Creates connections from all of the ports that we care about to the given 675 // Creates connections from all of the ports that we care about to the given
664 // remote candidate. The return value is true if we created a connection from 676 // remote candidate. The return value is true if we created a connection from
665 // the origin port. 677 // the origin port.
666 bool P2PTransportChannel::CreateConnections(const Candidate& remote_candidate, 678 bool P2PTransportChannel::CreateConnections(const Candidate& remote_candidate,
667 PortInterface* origin_port) { 679 PortInterface* origin_port) {
668 ASSERT(worker_thread_ == rtc::Thread::Current()); 680 ASSERT(worker_thread_ == rtc::Thread::Current());
669 681
670 Candidate new_remote_candidate(remote_candidate); 682 Candidate new_remote_candidate(remote_candidate);
683 // Candidate generation is still used for determining the priority.
pthatcher1 2015/12/04 20:43:50 You can remove the "is still"
honghaiz3 2015/12/09 23:57:54 Moved set_generation to AddRemoteIceCandidate()
671 new_remote_candidate.set_generation( 684 new_remote_candidate.set_generation(
672 GetRemoteCandidateGeneration(remote_candidate)); 685 GetRemoteCandidateGeneration(remote_candidate));
673 // ICE candidates don't need to have username and password set, but 686 // ICE candidates don't need to have username and password set, but
674 // the code below this (specifically, ConnectionRequest::Prepare in 687 // the code below this (specifically, ConnectionRequest::Prepare in
675 // port.cc) uses the remote candidates's username. So, we set it 688 // port.cc) uses the remote candidates's username. So, we set it
676 // here. 689 // here.
677 if (remote_candidate.username().empty()) { 690 if (remote_candidate.username().empty()) {
678 new_remote_candidate.set_username(remote_ice_ufrag_); 691 new_remote_candidate.set_username(remote_ice_ufrag_);
679 } 692 }
680 if (remote_candidate.password().empty()) { 693 if (new_remote_candidate.username() == remote_ice_ufrag_) {
681 new_remote_candidate.set_password(remote_ice_pwd_); 694 if (remote_candidate.password().empty()) {
695 new_remote_candidate.set_password(remote_ice_pwd_);
696 }
697 } else {
698 LOG(LS_WARNING)
699 << "A remote candidate arrives with a ufrag that was not seen before: "
700 << remote_candidate.username();
682 } 701 }
pthatcher1 2015/12/04 20:43:50 When is the pwd on the candidate going to be fille
honghaiz3 2015/12/09 23:57:54 Done.
683 702
684 // If we've already seen the new remote candidate (in the current candidate 703 // If we've already seen the new remote candidate (in the current candidate
685 // generation), then we shouldn't try creating connections for it. 704 // generation), then we shouldn't try creating connections for it.
686 // We either already have a connection for it, or we previously created one 705 // We either already have a connection for it, or we previously created one
687 // and then later pruned it. If we don't return, the channel will again 706 // and then later pruned it. If we don't return, the channel will again
688 // re-create any connections that were previously pruned, which will then 707 // re-create any connections that were previously pruned, which will then
689 // immediately be re-pruned, churning the network for no purpose. 708 // immediately be re-pruned, churning the network for no purpose.
690 // This only applies to candidates received over signaling (i.e. origin_port 709 // This only applies to candidates received over signaling (i.e. origin_port
691 // is NULL). 710 // is NULL).
692 if (!origin_port && IsDuplicateRemoteCandidate(new_remote_candidate)) { 711 if (!origin_port && IsDuplicateRemoteCandidate(new_remote_candidate)) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 cricket::Connection* connection) const { 785 cricket::Connection* connection) const {
767 std::vector<Connection*>::const_iterator citer = 786 std::vector<Connection*>::const_iterator citer =
768 std::find(connections_.begin(), connections_.end(), connection); 787 std::find(connections_.begin(), connections_.end(), connection);
769 return citer != connections_.end(); 788 return citer != connections_.end();
770 } 789 }
771 790
772 uint32_t P2PTransportChannel::GetRemoteCandidateGeneration( 791 uint32_t P2PTransportChannel::GetRemoteCandidateGeneration(
773 const Candidate& candidate) { 792 const Candidate& candidate) {
774 // We need to keep track of the remote ice restart so newer 793 // We need to keep track of the remote ice restart so newer
775 // connections are prioritized over the older. 794 // connections are prioritized over the older.
776 ASSERT(candidate.generation() == 0 || 795 // The candidate generation should be one of 0, remote_candidate_generation_,
777 candidate.generation() == remote_candidate_generation_); 796 // and remote_candidate_generation_ + 1.
778 return remote_candidate_generation_; 797 return std::max(remote_candidate_generation_, candidate.generation());
pthatcher1 2015/12/04 20:43:50 I think this should go lookup the generation by lo
honghaiz3 2015/12/09 23:57:54 Done.
779 } 798 }
780 799
781 // Check if remote candidate is already cached. 800 // Check if remote candidate is already cached.
782 bool P2PTransportChannel::IsDuplicateRemoteCandidate( 801 bool P2PTransportChannel::IsDuplicateRemoteCandidate(
783 const Candidate& candidate) { 802 const Candidate& candidate) {
784 for (size_t i = 0; i < remote_candidates_.size(); ++i) { 803 for (size_t i = 0; i < remote_candidates_.size(); ++i) {
785 if (remote_candidates_[i].IsEquivalent(candidate)) { 804 if (remote_candidates_[i].IsEquivalent(candidate)) {
786 return true; 805 return true;
787 } 806 }
788 } 807 }
789 return false; 808 return false;
790 } 809 }
791 810
792 // Maintain our remote candidate list, adding this new remote one. 811 // Maintain our remote candidate list, adding this new remote one.
793 void P2PTransportChannel::RememberRemoteCandidate( 812 void P2PTransportChannel::RememberRemoteCandidate(
794 const Candidate& remote_candidate, PortInterface* origin_port) { 813 const Candidate& remote_candidate, PortInterface* origin_port) {
795 // Remove any candidates whose generation is older than this one. The 814 // Remove any candidates whose generation is older than this one. The
796 // presence of a new generation indicates that the old ones are not useful. 815 // presence of a new generation indicates that the old ones are not useful.
816 ASSERT(!remote_candidate.username().empty());
797 size_t i = 0; 817 size_t i = 0;
798 while (i < remote_candidates_.size()) { 818 while (i < remote_candidates_.size()) {
799 if (remote_candidates_[i].generation() < remote_candidate.generation()) { 819 if (remote_candidates_[i].username() != remote_candidate.username()) {
800 LOG(INFO) << "Pruning candidate from old generation: " 820 LOG(INFO) << "Pruning candidate from old generation: "
801 << remote_candidates_[i].address().ToSensitiveString(); 821 << remote_candidates_[i].address().ToSensitiveString();
802 remote_candidates_.erase(remote_candidates_.begin() + i); 822 remote_candidates_.erase(remote_candidates_.begin() + i);
803 } else { 823 } else {
804 i += 1; 824 i += 1;
805 } 825 }
806 } 826 }
807 827
808 // Make sure this candidate is not a duplicate. 828 // Make sure this candidate is not a duplicate.
809 if (IsDuplicateRemoteCandidate(remote_candidate)) { 829 if (IsDuplicateRemoteCandidate(remote_candidate)) {
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 SignalSentPacket(this, sent_packet); 1374 SignalSentPacket(this, sent_packet);
1355 } 1375 }
1356 1376
1357 void P2PTransportChannel::OnReadyToSend(Connection* connection) { 1377 void P2PTransportChannel::OnReadyToSend(Connection* connection) {
1358 if (connection == best_connection_ && writable()) { 1378 if (connection == best_connection_ && writable()) {
1359 SignalReadyToSend(this); 1379 SignalReadyToSend(this);
1360 } 1380 }
1361 } 1381 }
1362 1382
1363 } // namespace cricket 1383 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698