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

Side by Side Diff: net/quic/quic_time_wait_list_manager.cc

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months 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
OLDNEW
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"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "net/base/ip_endpoint.h" 12 #include "net/base/ip_endpoint.h"
13 #include "net/quic/crypto/crypto_protocol.h" 13 #include "net/quic/crypto/crypto_protocol.h"
14 #include "net/quic/crypto/quic_decrypter.h" 14 #include "net/quic/crypto/quic_decrypter.h"
15 #include "net/quic/crypto/quic_encrypter.h" 15 #include "net/quic/crypto/quic_encrypter.h"
16 #include "net/quic/quic_clock.h" 16 #include "net/quic/quic_clock.h"
17 #include "net/quic/quic_connection_helper.h" 17 #include "net/quic/quic_connection_helper.h"
18 #include "net/quic/quic_flags.h"
18 #include "net/quic/quic_framer.h" 19 #include "net/quic/quic_framer.h"
19 #include "net/quic/quic_protocol.h" 20 #include "net/quic/quic_protocol.h"
20 #include "net/quic/quic_server_session.h" 21 #include "net/quic/quic_server_session.h"
21 #include "net/quic/quic_utils.h" 22 #include "net/quic/quic_utils.h"
22 23
23 using base::StringPiece; 24 using base::StringPiece;
24 using std::make_pair; 25 using std::make_pair;
25 26
26 namespace net { 27 namespace net {
27 28
28 namespace {
29
30 // Time period for which a given connection_id should live in the time-wait
31 // state.
32 int64 FLAGS_quic_time_wait_list_seconds = 5;
33
34 } // namespace
35
36 // A very simple alarm that just informs the QuicTimeWaitListManager to clean 29 // A very simple alarm that just informs the QuicTimeWaitListManager to clean
37 // up old connection_ids. This alarm should be unregistered and deleted before 30 // up old connection_ids. This alarm should be unregistered and deleted before
38 // the QuicTimeWaitListManager is deleted. 31 // the QuicTimeWaitListManager is deleted.
39 class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate { 32 class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate {
40 public: 33 public:
41 explicit ConnectionIdCleanUpAlarm( 34 explicit ConnectionIdCleanUpAlarm(
42 QuicTimeWaitListManager* time_wait_list_manager) 35 QuicTimeWaitListManager* time_wait_list_manager)
43 : time_wait_list_manager_(time_wait_list_manager) { 36 : time_wait_list_manager_(time_wait_list_manager) {
44 } 37 }
45 38
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 QuicVersion version, 106 QuicVersion version,
114 QuicEncryptedPacket* close_packet) { 107 QuicEncryptedPacket* close_packet) {
115 int num_packets = 0; 108 int num_packets = 0;
116 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); 109 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id);
117 const bool new_connection_id = it == connection_id_map_.end(); 110 const bool new_connection_id = it == connection_id_map_.end();
118 if (!new_connection_id) { // Replace record if it is reinserted. 111 if (!new_connection_id) { // Replace record if it is reinserted.
119 num_packets = it->second.num_packets; 112 num_packets = it->second.num_packets;
120 delete it->second.close_packet; 113 delete it->second.close_packet;
121 connection_id_map_.erase(it); 114 connection_id_map_.erase(it);
122 } 115 }
116 TrimTimeWaitListIfNeeded();
117 if (FLAGS_quic_limit_time_wait_list_size) {
118 DCHECK_LT(num_connections(),
119 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections));
120 }
123 ConnectionIdData data(num_packets, 121 ConnectionIdData data(num_packets,
124 version, 122 version,
125 helper_->GetClock()->ApproximateNow(), 123 helper_->GetClock()->ApproximateNow(),
126 close_packet); 124 close_packet);
127 connection_id_map_.insert(make_pair(connection_id, data)); 125 connection_id_map_.insert(make_pair(connection_id, data));
128 if (new_connection_id) { 126 if (new_connection_id) {
129 visitor_->OnConnectionAddedToTimeWaitList(connection_id); 127 visitor_->OnConnectionAddedToTimeWaitList(connection_id);
130 } 128 }
131 } 129 }
132 130
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 LOG(ERROR) << "ConnectionId lingered for longer than kTimeWaitPeriod"; 263 LOG(ERROR) << "ConnectionId lingered for longer than kTimeWaitPeriod";
266 } 264 }
267 } else { 265 } else {
268 // No connection_ids added so none will expire before kTimeWaitPeriod_. 266 // No connection_ids added so none will expire before kTimeWaitPeriod_.
269 next_alarm_time = now.Add(kTimeWaitPeriod_); 267 next_alarm_time = now.Add(kTimeWaitPeriod_);
270 } 268 }
271 269
272 connection_id_clean_up_alarm_->Set(next_alarm_time); 270 connection_id_clean_up_alarm_->Set(next_alarm_time);
273 } 271 }
274 272
273 bool QuicTimeWaitListManager::MaybeExpireOldestConnection(
274 QuicTime expiration_time) {
275 if (connection_id_map_.empty()) {
276 return false;
277 }
278 ConnectionIdMap::iterator it = connection_id_map_.begin();
279 QuicTime oldest_connection_id_time = it->second.time_added;
280 if (oldest_connection_id_time > expiration_time) {
281 // Too recent, don't retire.
282 return false;
283 }
284 // This connection_id has lived its age, retire it now.
285 const QuicConnectionId connection_id = it->first;
286 delete it->second.close_packet;
287 connection_id_map_.erase(it);
288 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id);
289 return true;
290 }
291
275 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { 292 void QuicTimeWaitListManager::CleanUpOldConnectionIds() {
276 QuicTime now = helper_->GetClock()->ApproximateNow(); 293 QuicTime now = helper_->GetClock()->ApproximateNow();
277 while (!connection_id_map_.empty()) { 294 QuicTime expiration = now.Subtract(kTimeWaitPeriod_);
278 ConnectionIdMap::iterator it = connection_id_map_.begin(); 295 if (FLAGS_quic_limit_time_wait_list_size) {
279 QuicTime oldest_connection_id = it->second.time_added; 296 while (MaybeExpireOldestConnection(expiration)) {
280 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
281 break;
282 } 297 }
283 const QuicConnectionId connection_id = it->first; 298 } else {
284 // This connection_id has lived its age, retire it now. 299 while (!connection_id_map_.empty()) {
285 delete it->second.close_packet; 300 ConnectionIdMap::iterator it = connection_id_map_.begin();
286 connection_id_map_.erase(it); 301 QuicTime oldest_connection_id = it->second.time_added;
287 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id); 302 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
303 break;
304 }
305 const QuicConnectionId connection_id = it->first;
306 // This connection_id has lived its age, retire it now.
307 delete it->second.close_packet;
308 connection_id_map_.erase(it);
309 visitor_->OnConnectionRemovedFromTimeWaitList(connection_id);
310 }
288 } 311 }
312
289 SetConnectionIdCleanUpAlarm(); 313 SetConnectionIdCleanUpAlarm();
290 } 314 }
291 315
316 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() {
317 if (FLAGS_quic_limit_time_wait_list_size) {
318 if (FLAGS_quic_time_wait_list_max_connections < 0) {
319 return;
320 }
321 while (num_connections() >=
322 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) {
323 MaybeExpireOldestConnection(QuicTime::Infinite());
324 }
325 }
326 }
327
292 } // namespace net 328 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_time_wait_list_manager.h ('k') | net/quic/quic_utils.cc » ('j') | shell/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698