OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/tools/quic/quic_time_wait_list_manager.h" | 5 #include "net/tools/quic/quic_time_wait_list_manager.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); | 80 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); |
81 }; | 81 }; |
82 | 82 |
83 QuicTimeWaitListManager::QuicTimeWaitListManager( | 83 QuicTimeWaitListManager::QuicTimeWaitListManager( |
84 QuicPacketWriter* writer, | 84 QuicPacketWriter* writer, |
85 QuicServerSessionVisitor* visitor, | 85 QuicServerSessionVisitor* visitor, |
86 EpollServer* epoll_server, | 86 EpollServer* epoll_server, |
87 const QuicVersionVector& supported_versions) | 87 const QuicVersionVector& supported_versions) |
88 : epoll_server_(epoll_server), | 88 : epoll_server_(epoll_server), |
89 kTimeWaitPeriod_( | 89 time_wait_period_( |
90 QuicTime::Delta::FromSeconds(FLAGS_quic_time_wait_list_seconds)), | 90 QuicTime::Delta::FromSeconds(FLAGS_quic_time_wait_list_seconds)), |
91 connection_id_clean_up_alarm_(new ConnectionIdCleanUpAlarm(this)), | 91 connection_id_clean_up_alarm_(new ConnectionIdCleanUpAlarm(this)), |
92 clock_(epoll_server_), | 92 clock_(epoll_server_), |
93 writer_(writer), | 93 writer_(writer), |
94 visitor_(visitor) { | 94 visitor_(visitor) { |
95 SetConnectionIdCleanUpAlarm(); | 95 SetConnectionIdCleanUpAlarm(); |
96 } | 96 } |
97 | 97 |
98 QuicTimeWaitListManager::~QuicTimeWaitListManager() { | 98 QuicTimeWaitListManager::~QuicTimeWaitListManager() { |
99 connection_id_clean_up_alarm_->UnregisterIfRegistered(); | 99 connection_id_clean_up_alarm_->UnregisterIfRegistered(); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 return true; | 252 return true; |
253 } | 253 } |
254 | 254 |
255 void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() { | 255 void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() { |
256 connection_id_clean_up_alarm_->UnregisterIfRegistered(); | 256 connection_id_clean_up_alarm_->UnregisterIfRegistered(); |
257 int64 next_alarm_interval; | 257 int64 next_alarm_interval; |
258 if (!connection_id_map_.empty()) { | 258 if (!connection_id_map_.empty()) { |
259 QuicTime oldest_connection_id = | 259 QuicTime oldest_connection_id = |
260 connection_id_map_.begin()->second.time_added; | 260 connection_id_map_.begin()->second.time_added; |
261 QuicTime now = clock_.ApproximateNow(); | 261 QuicTime now = clock_.ApproximateNow(); |
262 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) { | 262 if (now.Subtract(oldest_connection_id) < time_wait_period_) { |
263 next_alarm_interval = oldest_connection_id.Add(kTimeWaitPeriod_) | 263 next_alarm_interval = oldest_connection_id.Add(time_wait_period_) |
264 .Subtract(now) | 264 .Subtract(now) |
265 .ToMicroseconds(); | 265 .ToMicroseconds(); |
266 } else { | 266 } else { |
267 LOG(ERROR) << "ConnectionId lingered for longer than kTimeWaitPeriod"; | 267 LOG(ERROR) << "ConnectionId lingered for longer than time_wait_period_"; |
268 next_alarm_interval = 0; | 268 next_alarm_interval = 0; |
269 } | 269 } |
270 } else { | 270 } else { |
271 // No connection_ids added so none will expire before kTimeWaitPeriod_. | 271 // No connection_ids added so none will expire before time_wait_period_. |
272 next_alarm_interval = kTimeWaitPeriod_.ToMicroseconds(); | 272 next_alarm_interval = time_wait_period_.ToMicroseconds(); |
273 } | 273 } |
274 | 274 |
275 epoll_server_->RegisterAlarmApproximateDelta( | 275 epoll_server_->RegisterAlarmApproximateDelta( |
276 next_alarm_interval, connection_id_clean_up_alarm_.get()); | 276 next_alarm_interval, connection_id_clean_up_alarm_.get()); |
277 } | 277 } |
278 | 278 |
279 bool QuicTimeWaitListManager::MaybeExpireOldestConnection( | 279 bool QuicTimeWaitListManager::MaybeExpireOldestConnection( |
280 QuicTime expiration_time) { | 280 QuicTime expiration_time) { |
281 if (connection_id_map_.empty()) { | 281 if (connection_id_map_.empty()) { |
282 return false; | 282 return false; |
283 } | 283 } |
284 ConnectionIdMap::iterator it = connection_id_map_.begin(); | 284 ConnectionIdMap::iterator it = connection_id_map_.begin(); |
285 QuicTime oldest_connection_id_time = it->second.time_added; | 285 QuicTime oldest_connection_id_time = it->second.time_added; |
286 if (oldest_connection_id_time > expiration_time) { | 286 if (oldest_connection_id_time > expiration_time) { |
287 // Too recent, don't retire. | 287 // Too recent, don't retire. |
288 return false; | 288 return false; |
289 } | 289 } |
290 // This connection_id has lived its age, retire it now. | 290 // This connection_id has lived its age, retire it now. |
291 const QuicConnectionId connection_id = it->first; | 291 const QuicConnectionId connection_id = it->first; |
292 delete it->second.close_packet; | 292 delete it->second.close_packet; |
293 connection_id_map_.erase(it); | 293 connection_id_map_.erase(it); |
294 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id); | 294 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id); |
295 return true; | 295 return true; |
296 } | 296 } |
297 | 297 |
298 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { | 298 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { |
299 QuicTime now = clock_.ApproximateNow(); | 299 QuicTime now = clock_.ApproximateNow(); |
300 QuicTime expiration = now.Subtract(kTimeWaitPeriod_); | 300 QuicTime expiration = now.Subtract(time_wait_period_); |
301 | 301 |
302 while (MaybeExpireOldestConnection(expiration)) { | 302 while (MaybeExpireOldestConnection(expiration)) { |
303 } | 303 } |
304 | 304 |
305 SetConnectionIdCleanUpAlarm(); | 305 SetConnectionIdCleanUpAlarm(); |
306 } | 306 } |
307 | 307 |
308 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() { | 308 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() { |
309 if (FLAGS_quic_time_wait_list_max_connections < 0) { | 309 if (FLAGS_quic_time_wait_list_max_connections < 0) { |
310 return; | 310 return; |
311 } | 311 } |
312 while (num_connections() >= | 312 while (num_connections() >= |
313 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { | 313 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { |
314 MaybeExpireOldestConnection(QuicTime::Infinite()); | 314 MaybeExpireOldestConnection(QuicTime::Infinite()); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 } // namespace tools | 318 } // namespace tools |
319 } // namespace net | 319 } // namespace net |
OLD | NEW |