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

Side by Side Diff: webrtc/p2p/client/basicportallocator.cc

Issue 2176743003: Merge SignalPortPruned with SignalPortsRemoved in PortAllocatorSession (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 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/portallocator.h ('k') | webrtc/p2p/client/basicportallocator_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 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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 688
689 // Mark that the port has a pairable candidate, either because we have a 689 // Mark that the port has a pairable candidate, either because we have a
690 // usable candidate from the port, or simply because the port is bound to the 690 // usable candidate from the port, or simply because the port is bound to the
691 // any address and therefore has no host candidate. This will trigger the port 691 // any address and therefore has no host candidate. This will trigger the port
692 // to start creating candidate pairs (connections) and issue connectivity 692 // to start creating candidate pairs (connections) and issue connectivity
693 // checks. If port has already been marked as having a pairable candidate, 693 // checks. If port has already been marked as having a pairable candidate,
694 // do nothing here. 694 // do nothing here.
695 // Note: We should check whether any candidates may become ready after this 695 // Note: We should check whether any candidates may become ready after this
696 // because there we will check whether the candidate is generated by the ready 696 // because there we will check whether the candidate is generated by the ready
697 // ports, which may include this port. 697 // ports, which may include this port.
698 bool pruned_port = false; 698 bool pruned = false;
699 if (CandidatePairable(c, port) && !data->has_pairable_candidate()) { 699 if (CandidatePairable(c, port) && !data->has_pairable_candidate()) {
700 data->set_has_pairable_candidate(true); 700 data->set_has_pairable_candidate(true);
701 701
702 if (prune_turn_ports_ && port->Type() == RELAY_PORT_TYPE) { 702 if (prune_turn_ports_ && port->Type() == RELAY_PORT_TYPE) {
703 pruned_port = PruneTurnPorts(port); 703 pruned = PruneTurnPorts(port);
704 } 704 }
705 // If the current port is not pruned yet, SignalPortReady. 705 // If the current port is not pruned yet, SignalPortReady.
706 if (!data->pruned()) { 706 if (!data->pruned()) {
707 LOG_J(LS_INFO, port) << "Port ready."; 707 LOG_J(LS_INFO, port) << "Port ready.";
708 SignalPortReady(this, port); 708 SignalPortReady(this, port);
709 } 709 }
710 } 710 }
711 711
712 ProtocolType pvalue; 712 ProtocolType pvalue;
713 bool candidate_protocol_enabled = 713 bool candidate_protocol_enabled =
714 StringToProto(c.protocol().c_str(), &pvalue) && 714 StringToProto(c.protocol().c_str(), &pvalue) &&
715 data->sequence()->ProtocolEnabled(pvalue); 715 data->sequence()->ProtocolEnabled(pvalue);
716 716
717 if (data->ready() && CheckCandidateFilter(c) && candidate_protocol_enabled) { 717 if (data->ready() && CheckCandidateFilter(c) && candidate_protocol_enabled) {
718 std::vector<Candidate> candidates; 718 std::vector<Candidate> candidates;
719 candidates.push_back(SanitizeRelatedAddress(c)); 719 candidates.push_back(SanitizeRelatedAddress(c));
720 SignalCandidatesReady(this, candidates); 720 SignalCandidatesReady(this, candidates);
721 } else if (!candidate_protocol_enabled) { 721 } else if (!candidate_protocol_enabled) {
722 LOG(LS_INFO) 722 LOG(LS_INFO)
723 << "Not yet signaling candidate because protocol is not yet enabled."; 723 << "Not yet signaling candidate because protocol is not yet enabled.";
724 } else { 724 } else {
725 LOG(LS_INFO) << "Discarding candidate because it doesn't match filter."; 725 LOG(LS_INFO) << "Discarding candidate because it doesn't match filter.";
726 } 726 }
727 727
728 // If we have pruned any port, maybe need to signal port allocation done. 728 // If we have pruned any port, maybe need to signal port allocation done.
729 if (pruned_port) { 729 if (pruned) {
730 MaybeSignalCandidatesAllocationDone(); 730 MaybeSignalCandidatesAllocationDone();
731 } 731 }
732 } 732 }
733 733
734 Port* BasicPortAllocatorSession::GetBestTurnPortForNetwork( 734 Port* BasicPortAllocatorSession::GetBestTurnPortForNetwork(
735 const std::string& network_name) const { 735 const std::string& network_name) const {
736 Port* best_turn_port = nullptr; 736 Port* best_turn_port = nullptr;
737 for (const PortData& data : ports_) { 737 for (const PortData& data : ports_) {
738 if (data.port()->Network()->name() == network_name && 738 if (data.port()->Network()->name() == network_name &&
739 data.port()->Type() == RELAY_PORT_TYPE && data.ready() && 739 data.port()->Type() == RELAY_PORT_TYPE && data.ready() &&
740 (!best_turn_port || ComparePort(data.port(), best_turn_port) > 0)) { 740 (!best_turn_port || ComparePort(data.port(), best_turn_port) > 0)) {
741 best_turn_port = data.port(); 741 best_turn_port = data.port();
742 } 742 }
743 } 743 }
744 return best_turn_port; 744 return best_turn_port;
745 } 745 }
746 746
747 bool BasicPortAllocatorSession::PruneTurnPorts(Port* newly_pairable_turn_port) { 747 bool BasicPortAllocatorSession::PruneTurnPorts(Port* newly_pairable_turn_port) {
748 bool pruned_port = false;
749 // Note: We determine the same network based only on their network names. So 748 // Note: We determine the same network based only on their network names. So
750 // if an IPv4 address and an IPv6 address have the same network name, they 749 // if an IPv4 address and an IPv6 address have the same network name, they
751 // are considered the same network here. 750 // are considered the same network here.
752 const std::string& network_name = newly_pairable_turn_port->Network()->name(); 751 const std::string& network_name = newly_pairable_turn_port->Network()->name();
753 Port* best_turn_port = GetBestTurnPortForNetwork(network_name); 752 Port* best_turn_port = GetBestTurnPortForNetwork(network_name);
754 // |port| is already in the list of ports, so the best port cannot be nullptr. 753 // |port| is already in the list of ports, so the best port cannot be nullptr.
755 RTC_CHECK(best_turn_port != nullptr); 754 RTC_CHECK(best_turn_port != nullptr);
756 755
756 bool pruned = false;
757 std::vector<PortInterface*> pruned_ports;
757 for (PortData& data : ports_) { 758 for (PortData& data : ports_) {
758 if (data.port()->Network()->name() == network_name && 759 if (data.port()->Network()->name() == network_name &&
759 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() && 760 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() &&
760 ComparePort(data.port(), best_turn_port) < 0) { 761 ComparePort(data.port(), best_turn_port) < 0) {
761 data.set_pruned(); 762 data.set_pruned();
762 pruned_port = true; 763 pruned = true;
763 if (data.port() != newly_pairable_turn_port) { 764 if (data.port() != newly_pairable_turn_port) {
764 SignalPortPruned(this, data.port()); 765 pruned_ports.push_back(data.port());
765 } 766 }
766 } 767 }
767 } 768 }
768 return pruned_port; 769 if (!pruned_ports.empty()) {
770 LOG(LS_INFO) << "Pruned " << pruned_ports.size() << " ports";
771 SignalPortsPruned(this, pruned_ports);
772 }
773 return pruned;
769 } 774 }
770 775
771 void BasicPortAllocatorSession::OnPortComplete(Port* port) { 776 void BasicPortAllocatorSession::OnPortComplete(Port* port) {
772 ASSERT(rtc::Thread::Current() == network_thread_); 777 ASSERT(rtc::Thread::Current() == network_thread_);
773 LOG_J(LS_INFO, port) << "Port completed gathering candidates."; 778 LOG_J(LS_INFO, port) << "Port completed gathering candidates.";
774 PortData* data = FindPort(port); 779 PortData* data = FindPort(port);
775 ASSERT(data != NULL); 780 ASSERT(data != NULL);
776 781
777 // Ignore any late signals. 782 // Ignore any late signals.
778 if (!data->inprogress()) { 783 if (!data->inprogress()) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 } 944 }
940 ports_to_remove.push_back(data.port()); 945 ports_to_remove.push_back(data.port());
941 if (data.has_pairable_candidate()) { 946 if (data.has_pairable_candidate()) {
942 GetCandidatesFromPort(data, &candidates_to_remove); 947 GetCandidatesFromPort(data, &candidates_to_remove);
943 // Mark the port as having no pairable candidates so that its candidates 948 // Mark the port as having no pairable candidates so that its candidates
944 // won't be removed multiple times. 949 // won't be removed multiple times.
945 data.set_has_pairable_candidate(false); 950 data.set_has_pairable_candidate(false);
946 } 951 }
947 } 952 }
948 if (!ports_to_remove.empty()) { 953 if (!ports_to_remove.empty()) {
949 SignalPortsRemoved(this, ports_to_remove); 954 LOG(LS_INFO) << "Removed " << ports_to_remove.size() << " ports";
955 SignalPortsPruned(this, ports_to_remove);
950 } 956 }
951 if (!candidates_to_remove.empty()) { 957 if (!candidates_to_remove.empty()) {
952 SignalCandidatesRemoved(this, candidates_to_remove); 958 SignalCandidatesRemoved(this, candidates_to_remove);
953 } 959 }
954 } 960 }
955 961
956 // AllocationSequence 962 // AllocationSequence
957 963
958 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session, 964 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session,
959 rtc::Network* network, 965 rtc::Network* network,
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 ServerAddresses servers; 1437 ServerAddresses servers;
1432 for (size_t i = 0; i < relays.size(); ++i) { 1438 for (size_t i = 0; i < relays.size(); ++i) {
1433 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1439 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1434 servers.insert(relays[i].ports.front().address); 1440 servers.insert(relays[i].ports.front().address);
1435 } 1441 }
1436 } 1442 }
1437 return servers; 1443 return servers;
1438 } 1444 }
1439 1445
1440 } // namespace cricket 1446 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/portallocator.h ('k') | webrtc/p2p/client/basicportallocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698