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

Side by Side 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 unified diff | 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 »
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 11 matching lines...) Expand all
22 generation_(0), 22 generation_(0),
23 content_name_(content_name), 23 content_name_(content_name),
24 component_(component), 24 component_(component),
25 ice_ufrag_(ice_ufrag), 25 ice_ufrag_(ice_ufrag),
26 ice_pwd_(ice_pwd) { 26 ice_pwd_(ice_pwd) {
27 // Pooled sessions are allowed to be created with empty content name, 27 // Pooled sessions are allowed to be created with empty content name,
28 // component, ufrag and password. 28 // component, ufrag and password.
29 RTC_DCHECK(ice_ufrag.empty() == ice_pwd.empty()); 29 RTC_DCHECK(ice_ufrag.empty() == ice_pwd.empty());
30 } 30 }
31 31
32 void PortAllocator::SetConfiguration( 32 bool PortAllocator::SetConfiguration(
33 const ServerAddresses& stun_servers, 33 const ServerAddresses& stun_servers,
34 const std::vector<RelayServerConfig>& turn_servers, 34 const std::vector<RelayServerConfig>& turn_servers,
35 int candidate_pool_size, 35 int candidate_pool_size,
36 bool prune_turn_ports) { 36 bool prune_turn_ports) {
37 bool ice_servers_changed = 37 bool ice_servers_changed =
38 (stun_servers != stun_servers_ || turn_servers != turn_servers_); 38 (stun_servers != stun_servers_ || turn_servers != turn_servers_);
39 stun_servers_ = stun_servers; 39 stun_servers_ = stun_servers;
40 turn_servers_ = turn_servers; 40 turn_servers_ = turn_servers;
41 prune_turn_ports_ = prune_turn_ports; 41 prune_turn_ports_ = prune_turn_ports;
42 42
43 bool candidate_pool_drain_began =
44 static_cast<int>(pooled_sessions_.size()) != candidate_pool_size_;
45 if (candidate_pool_drain_began &&
46 candidate_pool_size != candidate_pool_size_) {
47 LOG(LS_ERROR) << "Trying to change candidate pool size after pool started "
48 "to be drained.";
49 return false;
50 }
51 if (candidate_pool_size < 0) {
52 LOG(LS_ERROR) << "Can't set negative pool size.";
53 return false;
54 }
55 candidate_pool_size_ = candidate_pool_size;
56
57 // If sessions need to be recreated, only recreate as many as the current
58 // pool size if the pool has begun to be drained.
59 int sessions_needed = candidate_pool_drain_began
60 ? static_cast<int>(pooled_sessions_.size())
61 : candidate_pool_size_;
62
43 // If ICE servers changed, throw away any existing pooled sessions and create 63 // If ICE servers changed, throw away any existing pooled sessions and create
44 // new ones. 64 // new ones.
45 if (ice_servers_changed) { 65 if (ice_servers_changed) {
46 pooled_sessions_.clear(); 66 pooled_sessions_.clear();
47 allocated_pooled_session_count_ = 0;
48 } 67 }
49 68
50 // If |size| is less than the number of allocated sessions, get rid of the 69 // If |sessions_needed| is less than the number of pooled sessions, get rid
51 // extras. 70 // of the extras.
52 while (allocated_pooled_session_count_ > candidate_pool_size && 71 while (sessions_needed < static_cast<int>(pooled_sessions_.size())) {
53 !pooled_sessions_.empty()) {
54 pooled_sessions_.front().reset(nullptr); 72 pooled_sessions_.front().reset(nullptr);
55 pooled_sessions_.pop_front(); 73 pooled_sessions_.pop_front();
56 --allocated_pooled_session_count_;
57 } 74 }
58 // If |size| is greater than the number of allocated sessions, create new 75
59 // sessions. 76 // If |sessions_needed| is greater than the number of pooled sessions,
60 while (allocated_pooled_session_count_ < candidate_pool_size) { 77 // create new sessions.
78 while (static_cast<int>(pooled_sessions_.size()) < sessions_needed) {
61 PortAllocatorSession* pooled_session = CreateSessionInternal("", 0, "", ""); 79 PortAllocatorSession* pooled_session = CreateSessionInternal("", 0, "", "");
62 pooled_session->StartGettingPorts(); 80 pooled_session->StartGettingPorts();
63 pooled_sessions_.push_back( 81 pooled_sessions_.push_back(
64 std::unique_ptr<PortAllocatorSession>(pooled_session)); 82 std::unique_ptr<PortAllocatorSession>(pooled_session));
65 ++allocated_pooled_session_count_;
66 } 83 }
67 target_pooled_session_count_ = candidate_pool_size; 84 return true;
68 } 85 }
69 86
70 std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession( 87 std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession(
71 const std::string& content_name, 88 const std::string& content_name,
72 int component, 89 int component,
73 const std::string& ice_ufrag, 90 const std::string& ice_ufrag,
74 const std::string& ice_pwd) { 91 const std::string& ice_pwd) {
75 auto session = std::unique_ptr<PortAllocatorSession>( 92 auto session = std::unique_ptr<PortAllocatorSession>(
76 CreateSessionInternal(content_name, component, ice_ufrag, ice_pwd)); 93 CreateSessionInternal(content_name, component, ice_ufrag, ice_pwd));
77 session->SetCandidateFilter(candidate_filter()); 94 session->SetCandidateFilter(candidate_filter());
(...skipping 21 matching lines...) Expand all
99 } 116 }
100 117
101 const PortAllocatorSession* PortAllocator::GetPooledSession() const { 118 const PortAllocatorSession* PortAllocator::GetPooledSession() const {
102 if (pooled_sessions_.empty()) { 119 if (pooled_sessions_.empty()) {
103 return nullptr; 120 return nullptr;
104 } 121 }
105 return pooled_sessions_.front().get(); 122 return pooled_sessions_.front().get();
106 } 123 }
107 124
108 } // namespace cricket 125 } // namespace cricket
OLDNEW
« 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