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

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
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);
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 // If the network in the sequence has been removed, terminate the
391 // sequence: stop the allocation and clear the ports.
392 if (std::find(networks.begin(), networks.end(), sequence->network()) ==
393 networks.end()) {
394 sequence->Terminate();
395 }
396 }
397
380 network_manager_started_ = true; 398 network_manager_started_ = true;
381 if (allocation_started_) 399 if (allocation_started_)
382 DoAllocate(); 400 DoAllocate();
383 } 401 }
384 402
385 void BasicPortAllocatorSession::DisableEquivalentPhases( 403 void BasicPortAllocatorSession::DisableEquivalentPhases(
386 rtc::Network* network, PortConfiguration* config, uint32* flags) { 404 rtc::Network* network, PortConfiguration* config, uint32* flags) {
387 for (uint32 i = 0; i < sequences_.size() && 405 for (uint32 i = 0; i < sequences_.size() &&
388 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; ++i) { 406 (*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; ++i) {
389 sequences_[i]->DisableEquivalentPhases(network, config, flags); 407 AllocationSequence* sequence = sequences_[i];
408 if (!sequence->IsTerminated()) {
pthatcher1 2015/09/24 17:11:43 Can we just make DisableEquivalentPhases check to
honghaiz3 2015/09/24 19:26:59 Done.
409 sequence->DisableEquivalentPhases(network, config, flags);
410 }
390 } 411 }
391 } 412 }
392 413
393 void BasicPortAllocatorSession::AddAllocatedPort(Port* port, 414 void BasicPortAllocatorSession::AddAllocatedPort(Port* port,
394 AllocationSequence * seq, 415 AllocationSequence * seq,
395 bool prepare_address) { 416 bool prepare_address) {
396 if (!port) 417 if (!port)
397 return; 418 return;
398 419
399 LOG(LS_INFO) << "Adding allocated port for " << content_name(); 420 LOG(LS_INFO) << "Adding allocated port for " << content_name();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 // are next available options to setup a communication channel. 725 // are next available options to setup a communication channel.
705 } 726 }
706 return true; 727 return true;
707 } 728 }
708 729
709 void AllocationSequence::Clear() { 730 void AllocationSequence::Clear() {
710 udp_port_ = NULL; 731 udp_port_ = NULL;
711 turn_ports_.clear(); 732 turn_ports_.clear();
712 } 733 }
713 734
735 void AllocationSequence::Terminate() {
pthatcher1 2015/09/24 17:11:43 How is this much different than calling Clear()?
honghaiz3 2015/09/24 19:26:59 Removed the state.
736 state_ = kTerminated;
737 Clear();
738 session_->network_thread()->Clear(this);
739 }
740
714 AllocationSequence::~AllocationSequence() { 741 AllocationSequence::~AllocationSequence() {
715 session_->network_thread()->Clear(this); 742 session_->network_thread()->Clear(this);
716 } 743 }
717 744
718 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, 745 void AllocationSequence::DisableEquivalentPhases(rtc::Network* network,
719 PortConfiguration* config, uint32* flags) { 746 PortConfiguration* config, uint32* flags) {
720 if (!((network == network_) && (ip_ == network->GetBestIP()))) { 747 if (!((network == network_) && (ip_ == network->GetBestIP()))) {
721 // Different network setup; nothing is equivalent. 748 // Different network setup; nothing is equivalent.
722 return; 749 return;
723 } 750 }
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 ServerAddresses servers; 1167 ServerAddresses servers;
1141 for (size_t i = 0; i < relays.size(); ++i) { 1168 for (size_t i = 0; i < relays.size(); ++i) {
1142 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { 1169 if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) {
1143 servers.insert(relays[i].ports.front().address); 1170 servers.insert(relays[i].ports.front().address);
1144 } 1171 }
1145 } 1172 }
1146 return servers; 1173 return servers;
1147 } 1174 }
1148 1175
1149 } // namespace cricket 1176 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698