Chromium Code Reviews| 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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 } | 542 } |
| 543 return networks; | 543 return networks; |
| 544 } | 544 } |
| 545 | 545 |
| 546 // For each network, see if we have a sequence that covers it already. If not, | 546 // For each network, see if we have a sequence that covers it already. If not, |
| 547 // create a new sequence to create the appropriate ports. | 547 // create a new sequence to create the appropriate ports. |
| 548 void BasicPortAllocatorSession::DoAllocate() { | 548 void BasicPortAllocatorSession::DoAllocate() { |
| 549 bool done_signal_needed = false; | 549 bool done_signal_needed = false; |
| 550 std::vector<rtc::Network*> networks = GetNetworks(); | 550 std::vector<rtc::Network*> networks = GetNetworks(); |
| 551 | 551 |
| 552 if (IsStopped()) { | |
|
Taylor Brandstetter
2016/08/23 21:50:09
Is this condition only hit when regathering due to
honghaiz3
2016/08/23 22:06:25
yes.
| |
| 553 return; | |
| 554 } | |
| 552 if (networks.empty()) { | 555 if (networks.empty()) { |
| 553 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; | 556 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
| 554 done_signal_needed = true; | 557 done_signal_needed = true; |
| 555 } else { | 558 } else { |
| 559 LOG(LS_INFO) << "Allocate ports on "<< networks.size() << " networks"; | |
| 556 PortConfiguration* config = configs_.empty() ? nullptr : configs_.back(); | 560 PortConfiguration* config = configs_.empty() ? nullptr : configs_.back(); |
| 557 for (uint32_t i = 0; i < networks.size(); ++i) { | 561 for (uint32_t i = 0; i < networks.size(); ++i) { |
| 558 uint32_t sequence_flags = flags(); | 562 uint32_t sequence_flags = flags(); |
| 559 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { | 563 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { |
| 560 // If all the ports are disabled we should just fire the allocation | 564 // If all the ports are disabled we should just fire the allocation |
| 561 // done event and return. | 565 // done event and return. |
| 562 done_signal_needed = true; | 566 done_signal_needed = true; |
| 563 break; | 567 break; |
| 564 } | 568 } |
| 565 | 569 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 578 // ones that we have already made. | 582 // ones that we have already made. |
| 579 DisableEquivalentPhases(networks[i], config, &sequence_flags); | 583 DisableEquivalentPhases(networks[i], config, &sequence_flags); |
| 580 | 584 |
| 581 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { | 585 if ((sequence_flags & DISABLE_ALL_PHASES) == DISABLE_ALL_PHASES) { |
| 582 // New AllocationSequence would have nothing to do, so don't make it. | 586 // New AllocationSequence would have nothing to do, so don't make it. |
| 583 continue; | 587 continue; |
| 584 } | 588 } |
| 585 | 589 |
| 586 AllocationSequence* sequence = | 590 AllocationSequence* sequence = |
| 587 new AllocationSequence(this, networks[i], config, sequence_flags); | 591 new AllocationSequence(this, networks[i], config, sequence_flags); |
| 588 if (!sequence->Init()) { | |
| 589 delete sequence; | |
| 590 continue; | |
| 591 } | |
| 592 done_signal_needed = true; | |
| 593 sequence->SignalPortAllocationComplete.connect( | 592 sequence->SignalPortAllocationComplete.connect( |
| 594 this, &BasicPortAllocatorSession::OnPortAllocationComplete); | 593 this, &BasicPortAllocatorSession::OnPortAllocationComplete); |
| 595 if (!IsStopped()) { | 594 sequence->Init(); |
| 596 sequence->Start(); | 595 sequence->Start(); |
| 597 } | |
| 598 sequences_.push_back(sequence); | 596 sequences_.push_back(sequence); |
| 597 done_signal_needed = true; | |
| 599 } | 598 } |
| 600 } | 599 } |
| 601 if (done_signal_needed) { | 600 if (done_signal_needed) { |
| 602 network_thread_->Post(RTC_FROM_HERE, this, MSG_SEQUENCEOBJECTS_CREATED); | 601 network_thread_->Post(RTC_FROM_HERE, this, MSG_SEQUENCEOBJECTS_CREATED); |
| 603 } | 602 } |
| 604 } | 603 } |
| 605 | 604 |
| 606 void BasicPortAllocatorSession::OnNetworksChanged() { | 605 void BasicPortAllocatorSession::OnNetworksChanged() { |
| 607 std::vector<rtc::Network*> networks = GetNetworks(); | 606 std::vector<rtc::Network*> networks = GetNetworks(); |
| 608 std::vector<rtc::Network*> failed_networks; | 607 std::vector<rtc::Network*> failed_networks; |
| 609 for (AllocationSequence* sequence : sequences_) { | 608 for (AllocationSequence* sequence : sequences_) { |
| 610 // Mark the sequence as "network failed" if its network is not in | 609 // Mark the sequence as "network failed" if its network is not in |
| 611 // |networks|. | 610 // |networks|. |
| 612 if (!sequence->network_failed() && | 611 if (!sequence->network_failed() && |
| 613 std::find(networks.begin(), networks.end(), sequence->network()) == | 612 std::find(networks.begin(), networks.end(), sequence->network()) == |
| 614 networks.end()) { | 613 networks.end()) { |
| 615 sequence->OnNetworkFailed(); | 614 sequence->OnNetworkFailed(); |
| 616 failed_networks.push_back(sequence->network()); | 615 failed_networks.push_back(sequence->network()); |
| 617 } | 616 } |
| 618 } | 617 } |
| 619 RemovePortsAndCandidates(failed_networks); | 618 RemovePortsAndCandidates(failed_networks); |
| 620 | 619 |
| 621 network_manager_started_ = true; | 620 if (!network_manager_started_) { |
| 621 LOG(LS_INFO) << "Network manager is started"; | |
| 622 network_manager_started_ = true; | |
| 623 } | |
| 622 if (allocation_started_) | 624 if (allocation_started_) |
| 623 DoAllocate(); | 625 DoAllocate(); |
| 624 } | 626 } |
| 625 | 627 |
| 626 void BasicPortAllocatorSession::DisableEquivalentPhases( | 628 void BasicPortAllocatorSession::DisableEquivalentPhases( |
| 627 rtc::Network* network, | 629 rtc::Network* network, |
| 628 PortConfiguration* config, | 630 PortConfiguration* config, |
| 629 uint32_t* flags) { | 631 uint32_t* flags) { |
| 630 for (uint32_t i = 0; i < sequences_.size() && | 632 for (uint32_t i = 0; i < sequences_.size() && |
| 631 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; | 633 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 network_(network), | 981 network_(network), |
| 980 ip_(network->GetBestIP()), | 982 ip_(network->GetBestIP()), |
| 981 config_(config), | 983 config_(config), |
| 982 state_(kInit), | 984 state_(kInit), |
| 983 flags_(flags), | 985 flags_(flags), |
| 984 udp_socket_(), | 986 udp_socket_(), |
| 985 udp_port_(NULL), | 987 udp_port_(NULL), |
| 986 phase_(0) { | 988 phase_(0) { |
| 987 } | 989 } |
| 988 | 990 |
| 989 bool AllocationSequence::Init() { | 991 void AllocationSequence::Init() { |
| 990 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { | 992 if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { |
| 991 udp_socket_.reset(session_->socket_factory()->CreateUdpSocket( | 993 udp_socket_.reset(session_->socket_factory()->CreateUdpSocket( |
| 992 rtc::SocketAddress(ip_, 0), session_->allocator()->min_port(), | 994 rtc::SocketAddress(ip_, 0), session_->allocator()->min_port(), |
| 993 session_->allocator()->max_port())); | 995 session_->allocator()->max_port())); |
| 994 if (udp_socket_) { | 996 if (udp_socket_) { |
| 995 udp_socket_->SignalReadPacket.connect( | 997 udp_socket_->SignalReadPacket.connect( |
| 996 this, &AllocationSequence::OnReadPacket); | 998 this, &AllocationSequence::OnReadPacket); |
| 997 } | 999 } |
| 998 // Continuing if |udp_socket_| is NULL, as local TCP and RelayPort using TCP | 1000 // Continuing if |udp_socket_| is NULL, as local TCP and RelayPort using TCP |
| 999 // are next available options to setup a communication channel. | 1001 // are next available options to setup a communication channel. |
| 1000 } | 1002 } |
| 1001 return true; | |
| 1002 } | 1003 } |
| 1003 | 1004 |
| 1004 void AllocationSequence::Clear() { | 1005 void AllocationSequence::Clear() { |
| 1005 udp_port_ = NULL; | 1006 udp_port_ = NULL; |
| 1006 turn_ports_.clear(); | 1007 turn_ports_.clear(); |
| 1007 } | 1008 } |
| 1008 | 1009 |
| 1009 void AllocationSequence::OnNetworkFailed() { | 1010 void AllocationSequence::OnNetworkFailed() { |
| 1010 RTC_DCHECK(!network_failed_); | 1011 RTC_DCHECK(!network_failed_); |
| 1011 network_failed_ = true; | 1012 network_failed_ = true; |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1460 ServerAddresses servers; | 1461 ServerAddresses servers; |
| 1461 for (size_t i = 0; i < relays.size(); ++i) { | 1462 for (size_t i = 0; i < relays.size(); ++i) { |
| 1462 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { | 1463 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { |
| 1463 servers.insert(relays[i].ports.front().address); | 1464 servers.insert(relays[i].ports.front().address); |
| 1464 } | 1465 } |
| 1465 } | 1466 } |
| 1466 return servers; | 1467 return servers; |
| 1467 } | 1468 } |
| 1468 | 1469 |
| 1469 } // namespace cricket | 1470 } // namespace cricket |
| OLD | NEW |