| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 QuicEncryptedPacket* close_packet) { | 111 QuicEncryptedPacket* close_packet) { |
| 112 int num_packets = 0; | 112 int num_packets = 0; |
| 113 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); | 113 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); |
| 114 const bool new_connection_id = it == connection_id_map_.end(); | 114 const bool new_connection_id = it == connection_id_map_.end(); |
| 115 if (!new_connection_id) { // Replace record if it is reinserted. | 115 if (!new_connection_id) { // Replace record if it is reinserted. |
| 116 num_packets = it->second.num_packets; | 116 num_packets = it->second.num_packets; |
| 117 delete it->second.close_packet; | 117 delete it->second.close_packet; |
| 118 connection_id_map_.erase(it); | 118 connection_id_map_.erase(it); |
| 119 } | 119 } |
| 120 TrimTimeWaitListIfNeeded(); | 120 TrimTimeWaitListIfNeeded(); |
| 121 if (FLAGS_quic_limit_time_wait_list_size) { | 121 DCHECK_LT(num_connections(), |
| 122 DCHECK_LT(num_connections(), | 122 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)); |
| 123 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)); | |
| 124 } | |
| 125 ConnectionIdData data(num_packets, | 123 ConnectionIdData data(num_packets, |
| 126 version, | 124 version, |
| 127 clock_.ApproximateNow(), | 125 clock_.ApproximateNow(), |
| 128 close_packet); | 126 close_packet); |
| 129 connection_id_map_.insert(std::make_pair(connection_id, data)); | 127 connection_id_map_.insert(std::make_pair(connection_id, data)); |
| 130 if (new_connection_id) { | 128 if (new_connection_id) { |
| 131 visitor_->OnConnectionAddedToTimeWaitList(connection_id); | 129 visitor_->OnConnectionAddedToTimeWaitList(connection_id); |
| 132 } | 130 } |
| 133 } | 131 } |
| 134 | 132 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 const QuicConnectionId connection_id = it->first; | 291 const QuicConnectionId connection_id = it->first; |
| 294 delete it->second.close_packet; | 292 delete it->second.close_packet; |
| 295 connection_id_map_.erase(it); | 293 connection_id_map_.erase(it); |
| 296 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id); | 294 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id); |
| 297 return true; | 295 return true; |
| 298 } | 296 } |
| 299 | 297 |
| 300 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { | 298 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { |
| 301 QuicTime now = clock_.ApproximateNow(); | 299 QuicTime now = clock_.ApproximateNow(); |
| 302 QuicTime expiration = now.Subtract(kTimeWaitPeriod_); | 300 QuicTime expiration = now.Subtract(kTimeWaitPeriod_); |
| 303 if (FLAGS_quic_limit_time_wait_list_size) { | 301 |
| 304 while (MaybeExpireOldestConnection(expiration)) { | 302 while (MaybeExpireOldestConnection(expiration)) { |
| 305 } | |
| 306 } else { | |
| 307 while (!connection_id_map_.empty()) { | |
| 308 ConnectionIdMap::iterator it = connection_id_map_.begin(); | |
| 309 QuicTime oldest_connection_id = it->second.time_added; | |
| 310 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) { | |
| 311 break; | |
| 312 } | |
| 313 const QuicConnectionId connection_id = it->first; | |
| 314 // This connection_id has lived its age, retire it now. | |
| 315 delete it->second.close_packet; | |
| 316 connection_id_map_.erase(it); | |
| 317 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id); | |
| 318 } | |
| 319 } | 303 } |
| 320 | 304 |
| 321 SetConnectionIdCleanUpAlarm(); | 305 SetConnectionIdCleanUpAlarm(); |
| 322 } | 306 } |
| 323 | 307 |
| 324 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() { | 308 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() { |
| 325 if (FLAGS_quic_limit_time_wait_list_size) { | 309 if (FLAGS_quic_time_wait_list_max_connections < 0) { |
| 326 if (FLAGS_quic_time_wait_list_max_connections < 0) { | 310 return; |
| 327 return; | 311 } |
| 328 } | 312 while (num_connections() >= |
| 329 while (num_connections() >= | 313 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { |
| 330 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { | 314 MaybeExpireOldestConnection(QuicTime::Infinite()); |
| 331 MaybeExpireOldestConnection(QuicTime::Infinite()); | |
| 332 } | |
| 333 } | 315 } |
| 334 } | 316 } |
| 335 | 317 |
| 336 } // namespace tools | 318 } // namespace tools |
| 337 } // namespace net | 319 } // namespace net |
| OLD | NEW |