| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic/quic_time_wait_list_manager.h" | 5 #include "net/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); | 75 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 QuicTimeWaitListManager::QuicTimeWaitListManager( | 78 QuicTimeWaitListManager::QuicTimeWaitListManager( |
| 79 QuicPacketWriter* writer, | 79 QuicPacketWriter* writer, |
| 80 QuicServerSessionVisitor* visitor, | 80 QuicServerSessionVisitor* visitor, |
| 81 QuicConnectionHelperInterface* helper, | 81 QuicConnectionHelperInterface* helper, |
| 82 const QuicVersionVector& supported_versions) | 82 const QuicVersionVector& supported_versions) |
| 83 : helper_(helper), | 83 : helper_(helper), |
| 84 kTimeWaitPeriod_( | 84 time_wait_period_( |
| 85 QuicTime::Delta::FromSeconds(FLAGS_quic_time_wait_list_seconds)), | 85 QuicTime::Delta::FromSeconds(FLAGS_quic_time_wait_list_seconds)), |
| 86 connection_id_clean_up_alarm_( | 86 connection_id_clean_up_alarm_( |
| 87 helper_->CreateAlarm(new ConnectionIdCleanUpAlarm(this))), | 87 helper_->CreateAlarm(new ConnectionIdCleanUpAlarm(this))), |
| 88 writer_(writer), | 88 writer_(writer), |
| 89 visitor_(visitor) { | 89 visitor_(visitor) { |
| 90 SetConnectionIdCleanUpAlarm(); | 90 SetConnectionIdCleanUpAlarm(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 QuicTimeWaitListManager::~QuicTimeWaitListManager() { | 93 QuicTimeWaitListManager::~QuicTimeWaitListManager() { |
| 94 connection_id_clean_up_alarm_->Cancel(); | 94 connection_id_clean_up_alarm_->Cancel(); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 return true; | 247 return true; |
| 248 } | 248 } |
| 249 | 249 |
| 250 void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() { | 250 void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() { |
| 251 connection_id_clean_up_alarm_->Cancel(); | 251 connection_id_clean_up_alarm_->Cancel(); |
| 252 QuicTime now = helper_->GetClock()->ApproximateNow(); | 252 QuicTime now = helper_->GetClock()->ApproximateNow(); |
| 253 QuicTime next_alarm_time = now; | 253 QuicTime next_alarm_time = now; |
| 254 if (!connection_id_map_.empty()) { | 254 if (!connection_id_map_.empty()) { |
| 255 QuicTime oldest_connection_id = | 255 QuicTime oldest_connection_id = |
| 256 connection_id_map_.begin()->second.time_added; | 256 connection_id_map_.begin()->second.time_added; |
| 257 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) { | 257 if (now.Subtract(oldest_connection_id) < time_wait_period_) { |
| 258 next_alarm_time = oldest_connection_id.Add(kTimeWaitPeriod_); | 258 next_alarm_time = oldest_connection_id.Add(time_wait_period_); |
| 259 } else { | 259 } else { |
| 260 LOG(ERROR) << "ConnectionId lingered for longer than kTimeWaitPeriod"; | 260 LOG(ERROR) << "ConnectionId lingered for longer than kTimeWaitPeriod"; |
| 261 } | 261 } |
| 262 } else { | 262 } else { |
| 263 // No connection_ids added so none will expire before kTimeWaitPeriod_. | 263 // No connection_ids added so none will expire before time_wait_period_. |
| 264 next_alarm_time = now.Add(kTimeWaitPeriod_); | 264 next_alarm_time = now.Add(time_wait_period_); |
| 265 } | 265 } |
| 266 | 266 |
| 267 connection_id_clean_up_alarm_->Set(next_alarm_time); | 267 connection_id_clean_up_alarm_->Set(next_alarm_time); |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool QuicTimeWaitListManager::MaybeExpireOldestConnection( | 270 bool QuicTimeWaitListManager::MaybeExpireOldestConnection( |
| 271 QuicTime expiration_time) { | 271 QuicTime expiration_time) { |
| 272 if (connection_id_map_.empty()) { | 272 if (connection_id_map_.empty()) { |
| 273 return false; | 273 return false; |
| 274 } | 274 } |
| 275 ConnectionIdMap::iterator it = connection_id_map_.begin(); | 275 ConnectionIdMap::iterator it = connection_id_map_.begin(); |
| 276 QuicTime oldest_connection_id_time = it->second.time_added; | 276 QuicTime oldest_connection_id_time = it->second.time_added; |
| 277 if (oldest_connection_id_time > expiration_time) { | 277 if (oldest_connection_id_time > expiration_time) { |
| 278 // Too recent, don't retire. | 278 // Too recent, don't retire. |
| 279 return false; | 279 return false; |
| 280 } | 280 } |
| 281 // This connection_id has lived its age, retire it now. | 281 // This connection_id has lived its age, retire it now. |
| 282 const QuicConnectionId connection_id = it->first; | 282 const QuicConnectionId connection_id = it->first; |
| 283 delete it->second.close_packet; | 283 delete it->second.close_packet; |
| 284 connection_id_map_.erase(it); | 284 connection_id_map_.erase(it); |
| 285 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id); | 285 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id); |
| 286 return true; | 286 return true; |
| 287 } | 287 } |
| 288 | 288 |
| 289 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { | 289 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { |
| 290 QuicTime now = helper_->GetClock()->ApproximateNow(); | 290 QuicTime now = helper_->GetClock()->ApproximateNow(); |
| 291 QuicTime expiration = now.Subtract(kTimeWaitPeriod_); | 291 QuicTime expiration = now.Subtract(time_wait_period_); |
| 292 | 292 |
| 293 while (MaybeExpireOldestConnection(expiration)) { | 293 while (MaybeExpireOldestConnection(expiration)) { |
| 294 } | 294 } |
| 295 | 295 |
| 296 SetConnectionIdCleanUpAlarm(); | 296 SetConnectionIdCleanUpAlarm(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() { | 299 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() { |
| 300 if (FLAGS_quic_time_wait_list_max_connections < 0) { | 300 if (FLAGS_quic_time_wait_list_max_connections < 0) { |
| 301 return; | 301 return; |
| 302 } | 302 } |
| 303 while (num_connections() >= | 303 while (num_connections() >= |
| 304 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { | 304 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { |
| 305 MaybeExpireOldestConnection(QuicTime::Infinite()); | 305 MaybeExpireOldestConnection(QuicTime::Infinite()); |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 } // namespace net | 309 } // namespace net |
| OLD | NEW |