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

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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = 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->KeepAliveUntilPruned();
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;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 RTC_CHECK(best_turn_port != nullptr); 755 RTC_CHECK(best_turn_port != nullptr);
755 756
756 bool pruned = false; 757 bool pruned = false;
757 std::vector<PortInterface*> pruned_ports; 758 std::vector<PortInterface*> pruned_ports;
758 for (PortData& data : ports_) { 759 for (PortData& data : ports_) {
759 if (data.port()->Network()->name() == network_name && 760 if (data.port()->Network()->name() == network_name &&
760 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() && 761 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() &&
761 ComparePort(data.port(), best_turn_port) < 0) { 762 ComparePort(data.port(), best_turn_port) < 0) {
762 data.set_pruned(); 763 data.set_pruned();
763 pruned = true; 764 pruned = true;
765 data.port()->Prune();
764 if (data.port() != newly_pairable_turn_port) { 766 if (data.port() != newly_pairable_turn_port) {
765 pruned_ports.push_back(data.port()); 767 pruned_ports.push_back(data.port());
766 } 768 }
767 } 769 }
768 } 770 }
769 if (!pruned_ports.empty()) { 771 if (!pruned_ports.empty()) {
770 LOG(LS_INFO) << "Pruned " << pruned_ports.size() << " ports"; 772 LOG(LS_INFO) << "Pruned " << pruned_ports.size() << " ports";
771 SignalPortsPruned(this, pruned_ports); 773 SignalPortsPruned(this, pruned_ports);
772 } 774 }
773 return pruned; 775 return pruned;
774 } 776 }
775 777
778 void BasicPortAllocatorSession::PruneAllPorts() {
779 for (PortData& data : ports_) {
780 data.port()->Prune();
781 }
782 }
783
776 void BasicPortAllocatorSession::OnPortComplete(Port* port) { 784 void BasicPortAllocatorSession::OnPortComplete(Port* port) {
777 ASSERT(rtc::Thread::Current() == network_thread_); 785 ASSERT(rtc::Thread::Current() == network_thread_);
778 LOG_J(LS_INFO, port) << "Port completed gathering candidates."; 786 LOG_J(LS_INFO, port) << "Port completed gathering candidates.";
779 PortData* data = FindPort(port); 787 PortData* data = FindPort(port);
780 ASSERT(data != NULL); 788 ASSERT(data != NULL);
781 789
782 // Ignore any late signals. 790 // Ignore any late signals.
783 if (!data->inprogress()) { 791 if (!data->inprogress()) {
784 return; 792 return;
785 } 793 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 // Removes ports and candidates created on a given list of networks. 943 // Removes ports and candidates created on a given list of networks.
936 void BasicPortAllocatorSession::RemovePortsAndCandidates( 944 void BasicPortAllocatorSession::RemovePortsAndCandidates(
937 const std::vector<rtc::Network*>& networks) { 945 const std::vector<rtc::Network*>& networks) {
938 std::vector<PortInterface*> ports_to_remove; 946 std::vector<PortInterface*> ports_to_remove;
939 std::vector<Candidate> candidates_to_remove; 947 std::vector<Candidate> candidates_to_remove;
940 for (PortData& data : ports_) { 948 for (PortData& data : ports_) {
941 if (std::find(networks.begin(), networks.end(), 949 if (std::find(networks.begin(), networks.end(),
942 data.sequence()->network()) == networks.end()) { 950 data.sequence()->network()) == networks.end()) {
943 continue; 951 continue;
944 } 952 }
953 // Prune the port so that it may be destroyed.
954 data.port()->Prune();
945 ports_to_remove.push_back(data.port()); 955 ports_to_remove.push_back(data.port());
946 if (data.has_pairable_candidate()) { 956 if (data.has_pairable_candidate()) {
947 GetCandidatesFromPort(data, &candidates_to_remove); 957 GetCandidatesFromPort(data, &candidates_to_remove);
948 // 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
949 // won't be removed multiple times. 959 // won't be removed multiple times.
950 data.set_has_pairable_candidate(false); 960 data.set_has_pairable_candidate(false);
951 } 961 }
952 } 962 }
953 if (!ports_to_remove.empty()) { 963 if (!ports_to_remove.empty()) {
954 LOG(LS_INFO) << "Removed " << ports_to_remove.size() << " ports"; 964 LOG(LS_INFO) << "Removed " << ports_to_remove.size() << " ports";
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 ServerAddresses servers; 1447 ServerAddresses servers;
1438 for (size_t i = 0; i < relays.size(); ++i) { 1448 for (size_t i = 0; i < relays.size(); ++i) {
1439 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1449 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1440 servers.insert(relays[i].ports.front().address); 1450 servers.insert(relays[i].ports.front().address);
1441 } 1451 }
1442 } 1452 }
1443 return servers; 1453 return servers;
1444 } 1454 }
1445 1455
1446 } // namespace cricket 1456 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.h ('k') | webrtc/p2p/client/basicportallocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698