Index: webrtc/p2p/client/basicportallocator.cc |
diff --git a/webrtc/p2p/client/basicportallocator.cc b/webrtc/p2p/client/basicportallocator.cc |
index 982025279d7322102add345e7c897145599233bb..4012f052d21421bdae102af5cfac908294cff2f2 100644 |
--- a/webrtc/p2p/client/basicportallocator.cc |
+++ b/webrtc/p2p/client/basicportallocator.cc |
@@ -298,28 +298,35 @@ void BasicPortAllocatorSession::OnAllocate() { |
allocation_started_ = true; |
} |
-// For each network, see if we have a sequence that covers it already. If not, |
-// create a new sequence to create the appropriate ports. |
-void BasicPortAllocatorSession::DoAllocate() { |
- bool done_signal_needed = false; |
- std::vector<rtc::Network*> networks; |
- |
+void BasicPortAllocatorSession::GetNetworks( |
+ std::vector<rtc::Network*>* networks) { |
+ networks->clear(); |
+ rtc::NetworkManager* network_manager = allocator_->network_manager(); |
+ ASSERT(network_manager); |
// If the network permission state is BLOCKED, we just act as if the flag has |
// been passed in. |
- if (allocator_->network_manager()->enumeration_permission() == |
+ if (network_manager->enumeration_permission() == |
rtc::NetworkManager::ENUMERATION_BLOCKED) { |
set_flags(flags() | PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
} |
- |
// If the adapter enumeration is disabled, we'll just bind to any address |
// instead of specific NIC. This is to ensure the same routing for http |
// traffic by OS is also used here to avoid any local or public IP leakage |
// during stun process. |
if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { |
- allocator_->network_manager()->GetAnyAddressNetworks(&networks); |
+ network_manager->GetAnyAddressNetworks(networks); |
} else { |
- allocator_->network_manager()->GetNetworks(&networks); |
+ network_manager->GetNetworks(networks); |
} |
+} |
+ |
+// For each network, see if we have a sequence that covers it already. If not, |
+// create a new sequence to create the appropriate ports. |
+void BasicPortAllocatorSession::DoAllocate() { |
+ bool done_signal_needed = false; |
+ std::vector<rtc::Network*> networks; |
+ GetNetworks(&networks); |
+ |
if (networks.empty()) { |
LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
done_signal_needed = true; |
@@ -377,6 +384,17 @@ void BasicPortAllocatorSession::DoAllocate() { |
} |
void BasicPortAllocatorSession::OnNetworksChanged() { |
+ std::vector<rtc::Network*> networks; |
+ GetNetworks(&networks); |
+ for (AllocationSequence* sequence : sequences_) { |
+ // If the network in the sequence has been removed, terminate the |
+ // sequence: stop the allocation and clear the ports. |
+ if (std::find(networks.begin(), networks.end(), sequence->network()) == |
+ networks.end()) { |
+ sequence->Terminate(); |
+ } |
+ } |
+ |
network_manager_started_ = true; |
if (allocation_started_) |
DoAllocate(); |
@@ -386,7 +404,10 @@ void BasicPortAllocatorSession::DisableEquivalentPhases( |
rtc::Network* network, PortConfiguration* config, uint32* flags) { |
for (uint32 i = 0; i < sequences_.size() && |
(*flags & DISABLE_ALL_PHASES) != DISABLE_ALL_PHASES; ++i) { |
- sequences_[i]->DisableEquivalentPhases(network, config, flags); |
+ AllocationSequence* sequence = sequences_[i]; |
+ 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.
|
+ sequence->DisableEquivalentPhases(network, config, flags); |
+ } |
} |
} |
@@ -711,6 +732,12 @@ void AllocationSequence::Clear() { |
turn_ports_.clear(); |
} |
+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.
|
+ state_ = kTerminated; |
+ Clear(); |
+ session_->network_thread()->Clear(this); |
+} |
+ |
AllocationSequence::~AllocationSequence() { |
session_->network_thread()->Clear(this); |
} |