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

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

Issue 2261523004: Signal to remove remote candidates if ports are pruned. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 3 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // regathers ports and candidates. 307 // regathers ports and candidates.
308 for (AllocationSequence* sequence : sequences_) { 308 for (AllocationSequence* sequence : sequences_) {
309 if (!sequence->network_failed() && 309 if (!sequence->network_failed() &&
310 std::find(failed_networks.begin(), failed_networks.end(), 310 std::find(failed_networks.begin(), failed_networks.end(),
311 sequence->network()) != failed_networks.end()) { 311 sequence->network()) != failed_networks.end()) {
312 sequence->set_network_failed(); 312 sequence->set_network_failed();
313 } 313 }
314 } 314 }
315 // Remove ports from being used locally and send signaling to remove 315 // Remove ports from being used locally and send signaling to remove
316 // the candidates on the remote side. 316 // the candidates on the remote side.
317 RemovePortsAndCandidates(failed_networks); 317 std::vector<PortData*> port_data_list =
318 GetUnprunedPortsOnNetworks(failed_networks);
319 if (!port_data_list.empty()) {
320 LOG(LS_INFO) << "Pruned " << port_data_list.size()
321 << " ports because their networks failed";
322 PrunePortsAndRemoveCandidates(port_data_list);
323 }
318 324
319 if (allocation_started_ && network_manager_started_) { 325 if (allocation_started_ && network_manager_started_) {
320 DoAllocate(); 326 DoAllocate();
321 } 327 }
322 } 328 }
323 329
324 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { 330 std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const {
325 std::vector<PortInterface*> ret; 331 std::vector<PortInterface*> ret;
326 for (const PortData& data : ports_) { 332 for (const PortData& data : ports_) {
327 if (data.ready()) { 333 if (data.ready()) {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 for (AllocationSequence* sequence : sequences_) { 614 for (AllocationSequence* sequence : sequences_) {
609 // Mark the sequence as "network failed" if its network is not in 615 // Mark the sequence as "network failed" if its network is not in
610 // |networks|. 616 // |networks|.
611 if (!sequence->network_failed() && 617 if (!sequence->network_failed() &&
612 std::find(networks.begin(), networks.end(), sequence->network()) == 618 std::find(networks.begin(), networks.end(), sequence->network()) ==
613 networks.end()) { 619 networks.end()) {
614 sequence->OnNetworkFailed(); 620 sequence->OnNetworkFailed();
615 failed_networks.push_back(sequence->network()); 621 failed_networks.push_back(sequence->network());
616 } 622 }
617 } 623 }
618 RemovePortsAndCandidates(failed_networks); 624 std::vector<PortData*> port_data_list =
625 GetUnprunedPortsOnNetworks(failed_networks);
626 if (!port_data_list.empty()) {
627 LOG(LS_INFO) << "Pruned " << port_data_list.size()
628 << " ports because their networks were gone";
629 PrunePortsAndRemoveCandidates(port_data_list);
630 }
619 631
620 if (!network_manager_started_) { 632 if (!network_manager_started_) {
621 LOG(LS_INFO) << "Network manager is started"; 633 LOG(LS_INFO) << "Network manager is started";
622 network_manager_started_ = true; 634 network_manager_started_ = true;
623 } 635 }
624 if (allocation_started_) 636 if (allocation_started_)
625 DoAllocate(); 637 DoAllocate();
626 } 638 }
627 639
628 void BasicPortAllocatorSession::DisableEquivalentPhases( 640 void BasicPortAllocatorSession::DisableEquivalentPhases(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 bool BasicPortAllocatorSession::PruneTurnPorts(Port* newly_pairable_turn_port) { 762 bool BasicPortAllocatorSession::PruneTurnPorts(Port* newly_pairable_turn_port) {
751 // Note: We determine the same network based only on their network names. So 763 // Note: We determine the same network based only on their network names. So
752 // if an IPv4 address and an IPv6 address have the same network name, they 764 // if an IPv4 address and an IPv6 address have the same network name, they
753 // are considered the same network here. 765 // are considered the same network here.
754 const std::string& network_name = newly_pairable_turn_port->Network()->name(); 766 const std::string& network_name = newly_pairable_turn_port->Network()->name();
755 Port* best_turn_port = GetBestTurnPortForNetwork(network_name); 767 Port* best_turn_port = GetBestTurnPortForNetwork(network_name);
756 // |port| is already in the list of ports, so the best port cannot be nullptr. 768 // |port| is already in the list of ports, so the best port cannot be nullptr.
757 RTC_CHECK(best_turn_port != nullptr); 769 RTC_CHECK(best_turn_port != nullptr);
758 770
759 bool pruned = false; 771 bool pruned = false;
760 std::vector<PortInterface*> pruned_ports; 772 std::vector<PortData*> pruned_ports;
761 for (PortData& data : ports_) { 773 for (PortData& data : ports_) {
762 if (data.port()->Network()->name() == network_name && 774 if (data.port()->Network()->name() == network_name &&
763 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() && 775 data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() &&
764 ComparePort(data.port(), best_turn_port) < 0) { 776 ComparePort(data.port(), best_turn_port) < 0) {
765 data.set_pruned();
766 pruned = true; 777 pruned = true;
767 data.port()->Prune();
768 if (data.port() != newly_pairable_turn_port) { 778 if (data.port() != newly_pairable_turn_port) {
769 pruned_ports.push_back(data.port()); 779 // These ports will be pruned in PrunePortsAndRemoveCandidates.
780 pruned_ports.push_back(&data);
781 } else {
782 data.PrunePort();
770 } 783 }
771 } 784 }
772 } 785 }
786
773 if (!pruned_ports.empty()) { 787 if (!pruned_ports.empty()) {
774 LOG(LS_INFO) << "Pruned " << pruned_ports.size() << " ports"; 788 LOG(LS_INFO) << "Pruned " << pruned_ports.size()
775 SignalPortsPruned(this, pruned_ports); 789 << " low-priority Turn ports";
790 PrunePortsAndRemoveCandidates(pruned_ports);
776 } 791 }
777 return pruned; 792 return pruned;
778 } 793 }
779 794
780 void BasicPortAllocatorSession::PruneAllPorts() { 795 void BasicPortAllocatorSession::PruneAllPorts() {
781 for (PortData& data : ports_) { 796 for (PortData& data : ports_) {
782 data.port()->Prune(); 797 data.PrunePort();
783 } 798 }
784 } 799 }
785 800
786 void BasicPortAllocatorSession::OnPortComplete(Port* port) { 801 void BasicPortAllocatorSession::OnPortComplete(Port* port) {
787 ASSERT(rtc::Thread::Current() == network_thread_); 802 ASSERT(rtc::Thread::Current() == network_thread_);
788 LOG_J(LS_INFO, port) << "Port completed gathering candidates."; 803 LOG_J(LS_INFO, port) << "Port completed gathering candidates.";
789 PortData* data = FindPort(port); 804 PortData* data = FindPort(port);
790 ASSERT(data != NULL); 805 ASSERT(data != NULL);
791 806
792 // Ignore any late signals. 807 // Ignore any late signals.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 Port* port) { 950 Port* port) {
936 for (std::vector<PortData>::iterator it = ports_.begin(); 951 for (std::vector<PortData>::iterator it = ports_.begin();
937 it != ports_.end(); ++it) { 952 it != ports_.end(); ++it) {
938 if (it->port() == port) { 953 if (it->port() == port) {
939 return &*it; 954 return &*it;
940 } 955 }
941 } 956 }
942 return NULL; 957 return NULL;
943 } 958 }
944 959
945 // Removes ports and candidates created on a given list of networks. 960 std::vector<BasicPortAllocatorSession::PortData*>
946 void BasicPortAllocatorSession::RemovePortsAndCandidates( 961 BasicPortAllocatorSession::GetUnprunedPortsOnNetworks(
947 const std::vector<rtc::Network*>& networks) { 962 const std::vector<rtc::Network*>& networks) {
963 std::vector<PortData*> port_data_list;
964 for (PortData& data : ports_) {
965 if (!data.pruned() &&
966 std::find(networks.begin(), networks.end(),
967 data.sequence()->network()) != networks.end()) {
968 port_data_list.push_back(&data);
969 }
970 }
971 return port_data_list;
972 }
973
974 void BasicPortAllocatorSession::PrunePortsAndRemoveCandidates(
975 const std::vector<PortData*>& port_data_list) {
948 std::vector<PortInterface*> ports_to_remove; 976 std::vector<PortInterface*> ports_to_remove;
949 std::vector<Candidate> candidates_to_remove; 977 std::vector<Candidate> candidates_to_remove;
950 for (PortData& data : ports_) { 978 for (PortData* data : port_data_list) {
951 if (std::find(networks.begin(), networks.end(),
952 data.sequence()->network()) == networks.end()) {
953 continue;
954 }
955 // Prune the port so that it may be destroyed. 979 // Prune the port so that it may be destroyed.
956 data.port()->Prune(); 980 data->PrunePort();
957 ports_to_remove.push_back(data.port()); 981 ports_to_remove.push_back(data->port());
958 if (data.has_pairable_candidate()) { 982 if (data->has_pairable_candidate()) {
959 GetCandidatesFromPort(data, &candidates_to_remove); 983 GetCandidatesFromPort(*data, &candidates_to_remove);
960 // Mark the port as having no pairable candidates so that its candidates 984 // Mark the port as having no pairable candidates so that its candidates
961 // won't be removed multiple times. 985 // won't be removed multiple times.
962 data.set_has_pairable_candidate(false); 986 data->set_has_pairable_candidate(false);
963 } 987 }
964 } 988 }
965 if (!ports_to_remove.empty()) { 989 if (!ports_to_remove.empty()) {
966 LOG(LS_INFO) << "Removed " << ports_to_remove.size() << " ports";
967 SignalPortsPruned(this, ports_to_remove); 990 SignalPortsPruned(this, ports_to_remove);
968 } 991 }
969 if (!candidates_to_remove.empty()) { 992 if (!candidates_to_remove.empty()) {
993 LOG(LS_INFO) << "Removed " << candidates_to_remove.size() << " candidates";
970 SignalCandidatesRemoved(this, candidates_to_remove); 994 SignalCandidatesRemoved(this, candidates_to_remove);
971 } 995 }
972 } 996 }
973 997
974 // AllocationSequence 998 // AllocationSequence
975 999
976 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session, 1000 AllocationSequence::AllocationSequence(BasicPortAllocatorSession* session,
977 rtc::Network* network, 1001 rtc::Network* network,
978 PortConfiguration* config, 1002 PortConfiguration* config,
979 uint32_t flags) 1003 uint32_t flags)
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 ServerAddresses servers; 1485 ServerAddresses servers;
1462 for (size_t i = 0; i < relays.size(); ++i) { 1486 for (size_t i = 0; i < relays.size(); ++i) {
1463 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1487 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1464 servers.insert(relays[i].ports.front().address); 1488 servers.insert(relays[i].ports.front().address);
1465 } 1489 }
1466 } 1490 }
1467 return servers; 1491 return servers;
1468 } 1492 }
1469 1493
1470 } // namespace cricket 1494 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698