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