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

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

Issue 2171183002: Remove ports that are not used by any channel after timeout (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
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 port->BecomeReady();
709 } 710 }
710 } 711 }
711 712
712 ProtocolType pvalue; 713 ProtocolType pvalue;
713 bool candidate_protocol_enabled = 714 bool candidate_protocol_enabled =
714 StringToProto(c.protocol().c_str(), &pvalue) && 715 StringToProto(c.protocol().c_str(), &pvalue) &&
715 data->sequence()->ProtocolEnabled(pvalue); 716 data->sequence()->ProtocolEnabled(pvalue);
716 717
717 if (data->ready() && CheckCandidateFilter(c) && candidate_protocol_enabled) { 718 if (data->ready() && CheckCandidateFilter(c) && candidate_protocol_enabled) {
718 std::vector<Candidate> candidates; 719 std::vector<Candidate> candidates;
719 candidates.push_back(SanitizeRelatedAddress(c)); 720 candidates.push_back(SanitizeRelatedAddress(c));
720 SignalCandidatesReady(this, candidates); 721 SignalCandidatesReady(this, candidates);
721 } else if (!candidate_protocol_enabled) { 722 } else if (!candidate_protocol_enabled) {
722 LOG(LS_INFO) 723 LOG(LS_INFO)
723 << "Not yet signaling candidate because protocol is not yet enabled."; 724 << "Not yet signaling candidate because protocol is not yet enabled.";
724 } else { 725 } else {
725 LOG(LS_INFO) << "Discarding candidate because it doesn't match filter."; 726 LOG(LS_INFO) << "Discarding candidate because it doesn't match filter.";
726 } 727 }
727 728
728 // If we have pruned any port, maybe need to signal port allocation done. 729 // If we have pruned any port, maybe need to signal port allocation done.
729 if (pruned_port) { 730 if (pruned) {
730 MaybeSignalCandidatesAllocationDone(); 731 MaybeSignalCandidatesAllocationDone();
731 } 732 }
732 } 733 }
733 734
734 Port* BasicPortAllocatorSession::GetBestTurnPortForNetwork( 735 Port* BasicPortAllocatorSession::GetBestTurnPortForNetwork(
735 const std::string& network_name) const { 736 const std::string& network_name) const {
736 Port* best_turn_port = nullptr; 737 Port* best_turn_port = nullptr;
737 for (const PortData& data : ports_) { 738 for (const PortData& data : ports_) {
738 if (data.port()->Network()->name() == network_name && 739 if (data.port()->Network()->name() == network_name &&
739 data.port()->Type() == RELAY_PORT_TYPE && data.ready() && 740 data.port()->Type() == RELAY_PORT_TYPE && data.ready() &&
740 (!best_turn_port || ComparePort(data.port(), best_turn_port) > 0)) { 741 (!best_turn_port || ComparePort(data.port(), best_turn_port) > 0)) {
741 best_turn_port = data.port(); 742 best_turn_port = data.port();
742 } 743 }
743 } 744 }
744 return best_turn_port; 745 return best_turn_port;
745 } 746 }
746 747
747 bool BasicPortAllocatorSession::PruneTurnPorts(Port* newly_pairable_turn_port) { 748 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 749 // 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 750 // if an IPv4 address and an IPv6 address have the same network name, they
751 // are considered the same network here. 751 // are considered the same network here.
752 const std::string& network_name = newly_pairable_turn_port->Network()->name(); 752 const std::string& network_name = newly_pairable_turn_port->Network()->name();
753 Port* best_turn_port = GetBestTurnPortForNetwork(network_name); 753 Port* best_turn_port = GetBestTurnPortForNetwork(network_name);
754 // |port| is already in the list of ports, so the best port cannot be nullptr. 754 // |port| is already in the list of ports, so the best port cannot be nullptr.
755 RTC_CHECK(best_turn_port != nullptr); 755 RTC_CHECK(best_turn_port != nullptr);
756 756
757 bool pruned = false;
758 std::vector<PortInterface*> pruned_ports;
757 for (PortData& data : ports_) { 759 for (PortData& data : ports_) {
758 if (data.port()->Network()->name() == network_name && 760 if (data.port()->Network()->name() == network_name &&
759 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() && 761 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() &&
760 ComparePort(data.port(), best_turn_port) < 0) { 762 ComparePort(data.port(), best_turn_port) < 0) {
761 data.set_pruned(); 763 data.set_pruned();
762 pruned_port = true; 764 pruned = true;
765 data.port()->Prune();
763 if (data.port() != newly_pairable_turn_port) { 766 if (data.port() != newly_pairable_turn_port) {
764 SignalPortPruned(this, data.port()); 767 pruned_ports.push_back(data.port());
765 } 768 }
766 } 769 }
767 } 770 }
768 return pruned_port; 771 if (!pruned_ports.empty()) {
772 LOG(LS_INFO) << "Pruned " << pruned_ports.size() << " ports";
773 SignalPortsPruned(this, pruned_ports);
774 }
775 return pruned;
776 }
777
778 void BasicPortAllocatorSession::PruneAllPorts() {
779 for (PortData& data : ports_) {
780 data.port()->Prune();
781 }
769 } 782 }
770 783
771 void BasicPortAllocatorSession::OnPortComplete(Port* port) { 784 void BasicPortAllocatorSession::OnPortComplete(Port* port) {
772 ASSERT(rtc::Thread::Current() == network_thread_); 785 ASSERT(rtc::Thread::Current() == network_thread_);
773 LOG_J(LS_INFO, port) << "Port completed gathering candidates."; 786 LOG_J(LS_INFO, port) << "Port completed gathering candidates.";
774 PortData* data = FindPort(port); 787 PortData* data = FindPort(port);
775 ASSERT(data != NULL); 788 ASSERT(data != NULL);
776 789
777 // Ignore any late signals. 790 // Ignore any late signals.
778 if (!data->inprogress()) { 791 if (!data->inprogress()) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 // Removes ports and candidates created on a given list of networks. 943 // Removes ports and candidates created on a given list of networks.
931 void BasicPortAllocatorSession::RemovePortsAndCandidates( 944 void BasicPortAllocatorSession::RemovePortsAndCandidates(
932 const std::vector<rtc::Network*>& networks) { 945 const std::vector<rtc::Network*>& networks) {
933 std::vector<PortInterface*> ports_to_remove; 946 std::vector<PortInterface*> ports_to_remove;
934 std::vector<Candidate> candidates_to_remove; 947 std::vector<Candidate> candidates_to_remove;
935 for (PortData& data : ports_) { 948 for (PortData& data : ports_) {
936 if (std::find(networks.begin(), networks.end(), 949 if (std::find(networks.begin(), networks.end(),
937 data.sequence()->network()) == networks.end()) { 950 data.sequence()->network()) == networks.end()) {
938 continue; 951 continue;
939 } 952 }
953 // Prune the port so that it may be destroyed.
954 data.port()->Prune();
940 ports_to_remove.push_back(data.port()); 955 ports_to_remove.push_back(data.port());
941 if (data.has_pairable_candidate()) { 956 if (data.has_pairable_candidate()) {
942 GetCandidatesFromPort(data, &candidates_to_remove); 957 GetCandidatesFromPort(data, &candidates_to_remove);
943 // Mark the port as having no pairable candidates so that its candidates 958 // Mark the port as having no pairable candidates so that its candidates
944 // won't be removed multiple times. 959 // won't be removed multiple times.
945 data.set_has_pairable_candidate(false); 960 data.set_has_pairable_candidate(false);
946 } 961 }
947 } 962 }
948 if (!ports_to_remove.empty()) { 963 if (!ports_to_remove.empty()) {
949 SignalPortsRemoved(this, ports_to_remove); 964 LOG(LS_INFO) << "Removed " << ports_to_remove.size() << " ports";
965 SignalPortsPruned(this, ports_to_remove);
950 } 966 }
951 if (!candidates_to_remove.empty()) { 967 if (!candidates_to_remove.empty()) {
952 SignalCandidatesRemoved(this, candidates_to_remove); 968 SignalCandidatesRemoved(this, candidates_to_remove);
953 } 969 }
954 } 970 }
955 971
956 // AllocationSequence 972 // AllocationSequence
957 973
958 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session, 974 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session,
959 rtc::Network* network, 975 rtc::Network* network,
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 ServerAddresses servers; 1447 ServerAddresses servers;
1432 for (size_t i = 0; i < relays.size(); ++i) { 1448 for (size_t i = 0; i < relays.size(); ++i) {
1433 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1449 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1434 servers.insert(relays[i].ports.front().address); 1450 servers.insert(relays[i].ports.front().address);
1435 } 1451 }
1436 } 1452 }
1437 return servers; 1453 return servers;
1438 } 1454 }
1439 1455
1440 } // namespace cricket 1456 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698