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

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

Issue 1361183004: When doing DisableEquivalentPhases, exclude those AllocationSequences (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Removed the new state kTerminated Created 5 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
« no previous file with comments | « webrtc/p2p/client/basicportallocator.h ('k') | webrtc/p2p/client/portallocator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 network_thread_->Post(this, MSG_ALLOCATE); 291 network_thread_->Post(this, MSG_ALLOCATE);
292 } 292 }
293 293
294 void BasicPortAllocatorSession::OnAllocate() { 294 void BasicPortAllocatorSession::OnAllocate() {
295 if (network_manager_started_) 295 if (network_manager_started_)
296 DoAllocate(); 296 DoAllocate();
297 297
298 allocation_started_ = true; 298 allocation_started_ = true;
299 } 299 }
300 300
301 void BasicPortAllocatorSession::GetNetworks(
302 std::vector<rtc::Network*>* networks) {
303 networks->clear();
304 rtc::NetworkManager* network_manager = allocator_->network_manager();
305 ASSERT(network_manager != nullptr);
306 // If the network permission state is BLOCKED, we just act as if the flag has
307 // been passed in.
308 if (network_manager->enumeration_permission() ==
309 rtc::NetworkManager::ENUMERATION_BLOCKED) {
310 set_flags(flags() | PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
311 }
312 // If the adapter enumeration is disabled, we'll just bind to any address
313 // instead of specific NIC. This is to ensure the same routing for http
314 // traffic by OS is also used here to avoid any local or public IP leakage
315 // during stun process.
316 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) {
317 network_manager->GetAnyAddressNetworks(networks);
318 } else {
319 network_manager->GetNetworks(networks);
320 }
321 }
322
301 // For each network, see if we have a sequence that covers it already. If not, 323 // For each network, see if we have a sequence that covers it already. If not,
302 // create a new sequence to create the appropriate ports. 324 // create a new sequence to create the appropriate ports.
303 void BasicPortAllocatorSession::DoAllocate() { 325 void BasicPortAllocatorSession::DoAllocate() {
304 bool done_signal_needed = false; 326 bool done_signal_needed = false;
305 std::vector<rtc::Network*> networks; 327 std::vector<rtc::Network*> networks;
328 GetNetworks(&networks);
306 329
307 // If the network permission state is BLOCKED, we just act as if the flag has
308 // been passed in.
309 if (allocator_->network_manager()->enumeration_permission() ==
310 rtc::NetworkManager::ENUMERATION_BLOCKED) {
311 set_flags(flags() | PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
312 }
313
314 // If the adapter enumeration is disabled, we'll just bind to any address
315 // instead of specific NIC. This is to ensure the same routing for http
316 // traffic by OS is also used here to avoid any local or public IP leakage
317 // during stun process.
318 if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) {
319 allocator_->network_manager()->GetAnyAddressNetworks(&networks);
320 } else {
321 allocator_->network_manager()->GetNetworks(&networks);
322 }
323 if (networks.empty()) { 330 if (networks.empty()) {
324 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; 331 LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated";
325 done_signal_needed = true; 332 done_signal_needed = true;
326 } else { 333 } else {
327 for (uint32 i = 0; i < networks.size(); ++i) { 334 for (uint32 i = 0; i < networks.size(); ++i) {
328 PortConfiguration* config = NULL; 335 PortConfiguration* config = NULL;
329 if (configs_.size() > 0) 336 if (configs_.size() > 0)
330 config = configs_.back(); 337 config = configs_.back();
331 338
332 uint32 sequence_flags = flags(); 339 uint32 sequence_flags = flags();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 sequence->Start(); 377 sequence->Start();
371 sequences_.push_back(sequence); 378 sequences_.push_back(sequence);
372 } 379 }
373 } 380 }
374 if (done_signal_needed) { 381 if (done_signal_needed) {
375 network_thread_->Post(this, MSG_SEQUENCEOBJECTS_CREATED); 382 network_thread_->Post(this, MSG_SEQUENCEOBJECTS_CREATED);
376 } 383 }
377 } 384 }
378 385
379 void BasicPortAllocatorSession::OnNetworksChanged() { 386 void BasicPortAllocatorSession::OnNetworksChanged() {
387 std::vector<rtc::Network*> networks;
388 GetNetworks(&networks);
389 for (AllocationSequence* sequence : sequences_) {
390 // Remove the network from the allocation sequence if it is not in
391 // |networks|.
392 if (sequence->network() != nullptr &&
393 std::find(networks.begin(), networks.end(), sequence->network()) ==
394 networks.end()) {
395 sequence->RemoveNetwork();
396 }
pthatcher1 2015/09/24 21:41:43 Wouldn't this be the same as: if (sequence->state
honghaiz3 2015/09/24 22:41:28 Not exactly as we discussed.
397 }
398
380 network_manager_started_ = true; 399 network_manager_started_ = true;
381 if (allocation_started_) 400 if (allocation_started_)
382 DoAllocate(); 401 DoAllocate();
383 } 402 }
384 403
385 void BasicPortAllocatorSession::DisableEquivalentPhases( 404 void BasicPortAllocatorSession::DisableEquivalentPhases(
386 rtc::Network* network, PortConfiguration* config, uint32* flags) { 405 rtc::Network* network, PortConfiguration* config, uint32* flags) {
387 for (uint32 i = 0; i < sequences_.size() && 406 for (uint32 i = 0; i < sequences_.size() &&
388 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; ++i) { 407 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; ++i) {
389 sequences_[i]->DisableEquivalentPhases(network, config, flags); 408 sequences_[i]->DisableEquivalentPhases(network, config, flags);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 // are next available options to setup a communication channel. 723 // are next available options to setup a communication channel.
705 } 724 }
706 return true; 725 return true;
707 } 726 }
708 727
709 void AllocationSequence::Clear() { 728 void AllocationSequence::Clear() {
710 udp_port_ = NULL; 729 udp_port_ = NULL;
711 turn_ports_.clear(); 730 turn_ports_.clear();
712 } 731 }
713 732
733 void AllocationSequence::RemoveNetwork() {
734 // Stop the allocation sequence if its network is gone.
735 Stop();
736 network_ = nullptr;
pthatcher1 2015/09/24 21:41:43 There's lot of code in this file that expects netw
honghaiz3 2015/09/24 22:41:28 Changed to use a binary variable.
737 }
738
714 AllocationSequence::~AllocationSequence() { 739 AllocationSequence::~AllocationSequence() {
715 session_->network_thread()->Clear(this); 740 session_->network_thread()->Clear(this);
716 } 741 }
717 742
718 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, 743 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network,
719 PortConfiguration* config, uint32* flags) { 744 PortConfiguration* config, uint32* flags) {
720 if (!((network == network_) && (ip_ == network->GetBestIP()))) { 745 if (!((network == network_) && (ip_ == network->GetBestIP()))) {
721 // Different network setup; nothing is equivalent. 746 // Different network setup; nothing is equivalent.
722 return; 747 return;
723 } 748 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 784
760 void AllocationSequence::OnMessage(rtc::Message* msg) { 785 void AllocationSequence::OnMessage(rtc::Message* msg) {
761 ASSERT(rtc::Thread::Current() == session_->network_thread()); 786 ASSERT(rtc::Thread::Current() == session_->network_thread());
762 ASSERT(msg->message_id == MSG_ALLOCATION_PHASE); 787 ASSERT(msg->message_id == MSG_ALLOCATION_PHASE);
763 788
764 const char* const PHASE_NAMES[kNumPhases] = { 789 const char* const PHASE_NAMES[kNumPhases] = {
765 "Udp", "Relay", "Tcp", "SslTcp" 790 "Udp", "Relay", "Tcp", "SslTcp"
766 }; 791 };
767 792
768 // Perform all of the phases in the current step. 793 // Perform all of the phases in the current step.
794 ASSERT(network_ != nullptr);
769 LOG_J(LS_INFO, network_) << "Allocation Phase=" 795 LOG_J(LS_INFO, network_) << "Allocation Phase="
770 << PHASE_NAMES[phase_]; 796 << PHASE_NAMES[phase_];
771 797
772 switch (phase_) { 798 switch (phase_) {
773 case PHASE_UDP: 799 case PHASE_UDP:
774 CreateUDPPorts(); 800 CreateUDPPorts();
775 CreateStunPorts(); 801 CreateStunPorts();
776 EnableProtocol(PROTO_UDP); 802 EnableProtocol(PROTO_UDP);
777 break; 803 break;
778 804
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 ServerAddresses servers; 1166 ServerAddresses servers;
1141 for (size_t i = 0; i < relays.size(); ++i) { 1167 for (size_t i = 0; i < relays.size(); ++i) {
1142 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1168 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1143 servers.insert(relays[i].ports.front().address); 1169 servers.insert(relays[i].ports.front().address);
1144 } 1170 }
1145 } 1171 }
1146 return servers; 1172 return servers;
1147 } 1173 }
1148 1174
1149 } // namespace cricket 1175 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.h ('k') | webrtc/p2p/client/portallocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698