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