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

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: Created 5 years, 2 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_removed() &&
393 std::find(networks.begin(), networks.end(), sequence->network()) ==
394 networks.end()) {
395 sequence->OnNetworkRemoved();
396 }
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::OnNetworkRemoved() {
734 // Stop the allocation sequence if its network is gone.
735 Stop();
736 network_removed_ = true;
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) {
745 if (network_removed_) {
746 // If the network of this allocation sequence has ever gone away,
747 // it won't be equivalent to the new network.
748 return;
749 }
750
720 if (!((network == network_) && (ip_ == network->GetBestIP()))) { 751 if (!((network == network_) && (ip_ == network->GetBestIP()))) {
721 // Different network setup; nothing is equivalent. 752 // Different network setup; nothing is equivalent.
722 return; 753 return;
723 } 754 }
724 755
725 // Else turn off the stuff that we've already got covered. 756 // Else turn off the stuff that we've already got covered.
726 757
727 // Every config implicitly specifies local, so turn that off right away. 758 // Every config implicitly specifies local, so turn that off right away.
728 *flags |= PORTALLOCATOR_DISABLE_UDP; 759 *flags |= PORTALLOCATOR_DISABLE_UDP;
729 *flags |= PORTALLOCATOR_DISABLE_TCP; 760 *flags |= PORTALLOCATOR_DISABLE_TCP;
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 ServerAddresses servers; 1171 ServerAddresses servers;
1141 for (size_t i = 0; i < relays.size(); ++i) { 1172 for (size_t i = 0; i < relays.size(); ++i) {
1142 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1173 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1143 servers.insert(relays[i].ports.front().address); 1174 servers.insert(relays[i].ports.front().address);
1144 } 1175 }
1145 } 1176 }
1146 return servers; 1177 return servers;
1147 } 1178 }
1148 1179
1149 } // namespace cricket 1180 } // 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