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

Unified Diff: webrtc/p2p/base/portallocator.cc

Issue 2566833002: Don't allow changing ICE pool size after SetLocalDescription. (Closed)
Patch Set: Fixing signed/unsigned compare warning. Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/portallocator.h ('k') | webrtc/p2p/base/portallocator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/portallocator.cc
diff --git a/webrtc/p2p/base/portallocator.cc b/webrtc/p2p/base/portallocator.cc
index e71582ade8db72ae084deb113286db6927313b09..dc4166a03d14c6e59faf430b405abd6eefe2a4de 100644
--- a/webrtc/p2p/base/portallocator.cc
+++ b/webrtc/p2p/base/portallocator.cc
@@ -29,7 +29,7 @@ PortAllocatorSession::PortAllocatorSession(const std::string& content_name,
RTC_DCHECK(ice_ufrag.empty() == ice_pwd.empty());
}
-void PortAllocator::SetConfiguration(
+bool PortAllocator::SetConfiguration(
const ServerAddresses& stun_servers,
const std::vector<RelayServerConfig>& turn_servers,
int candidate_pool_size,
@@ -40,31 +40,48 @@ void PortAllocator::SetConfiguration(
turn_servers_ = turn_servers;
prune_turn_ports_ = prune_turn_ports;
+ bool candidate_pool_drain_began =
+ static_cast<int>(pooled_sessions_.size()) != candidate_pool_size_;
+ if (candidate_pool_drain_began &&
+ candidate_pool_size != candidate_pool_size_) {
+ LOG(LS_ERROR) << "Trying to change candidate pool size after pool started "
+ "to be drained.";
+ return false;
+ }
+ if (candidate_pool_size < 0) {
+ LOG(LS_ERROR) << "Can't set negative pool size.";
+ return false;
+ }
+ candidate_pool_size_ = candidate_pool_size;
+
+ // If sessions need to be recreated, only recreate as many as the current
+ // pool size if the pool has begun to be drained.
+ int sessions_needed = candidate_pool_drain_began
+ ? static_cast<int>(pooled_sessions_.size())
+ : candidate_pool_size_;
+
// If ICE servers changed, throw away any existing pooled sessions and create
// new ones.
if (ice_servers_changed) {
pooled_sessions_.clear();
- allocated_pooled_session_count_ = 0;
}
- // If |size| is less than the number of allocated sessions, get rid of the
- // extras.
- while (allocated_pooled_session_count_ > candidate_pool_size &&
- !pooled_sessions_.empty()) {
+ // If |sessions_needed| is less than the number of pooled sessions, get rid
+ // of the extras.
+ while (sessions_needed < static_cast<int>(pooled_sessions_.size())) {
pooled_sessions_.front().reset(nullptr);
pooled_sessions_.pop_front();
- --allocated_pooled_session_count_;
}
- // If |size| is greater than the number of allocated sessions, create new
- // sessions.
- while (allocated_pooled_session_count_ < candidate_pool_size) {
+
+ // If |sessions_needed| is greater than the number of pooled sessions,
+ // create new sessions.
+ while (static_cast<int>(pooled_sessions_.size()) < sessions_needed) {
PortAllocatorSession* pooled_session = CreateSessionInternal("", 0, "", "");
pooled_session->StartGettingPorts();
pooled_sessions_.push_back(
std::unique_ptr<PortAllocatorSession>(pooled_session));
- ++allocated_pooled_session_count_;
}
- target_pooled_session_count_ = candidate_pool_size;
+ return true;
}
std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession(
« no previous file with comments | « webrtc/p2p/base/portallocator.h ('k') | webrtc/p2p/base/portallocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698