| 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" |
| 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_framer.h" | 18 #include "net/quic/quic_framer.h" |
| 19 #include "net/quic/quic_protocol.h" | 19 #include "net/quic/quic_protocol.h" |
| 20 #include "net/quic/quic_server_session.h" | 20 #include "net/quic/quic_server_session.h" |
| 21 #include "net/quic/quic_utils.h" | 21 #include "net/quic/quic_utils.h" |
| 22 | 22 |
| 23 using base::StringPiece; | 23 using base::StringPiece; |
| 24 using std::make_pair; | 24 using std::make_pair; |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Time period for which the connection_id should live in time wait state.. | 30 // Time period for which a given connection_id should live in the time-wait |
| 31 const int kTimeWaitSeconds = 5; | 31 // state. |
| 32 int64 FLAGS_quic_time_wait_list_seconds = 5; |
| 32 | 33 |
| 33 } // namespace | 34 } // namespace |
| 34 | 35 |
| 35 // A very simple alarm that just informs the QuicTimeWaitListManager to clean | 36 // A very simple alarm that just informs the QuicTimeWaitListManager to clean |
| 36 // up old connection_ids. This alarm should be unregistered and deleted before | 37 // up old connection_ids. This alarm should be unregistered and deleted before |
| 37 // the QuicTimeWaitListManager is deleted. | 38 // the QuicTimeWaitListManager is deleted. |
| 38 class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate { | 39 class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate { |
| 39 public: | 40 public: |
| 40 explicit ConnectionIdCleanUpAlarm( | 41 explicit ConnectionIdCleanUpAlarm( |
| 41 QuicTimeWaitListManager* time_wait_list_manager) | 42 QuicTimeWaitListManager* time_wait_list_manager) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 80 |
| 80 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); | 81 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 QuicTimeWaitListManager::QuicTimeWaitListManager( | 84 QuicTimeWaitListManager::QuicTimeWaitListManager( |
| 84 QuicPacketWriter* writer, | 85 QuicPacketWriter* writer, |
| 85 QuicServerSessionVisitor* visitor, | 86 QuicServerSessionVisitor* visitor, |
| 86 QuicConnectionHelperInterface* helper, | 87 QuicConnectionHelperInterface* helper, |
| 87 const QuicVersionVector& supported_versions) | 88 const QuicVersionVector& supported_versions) |
| 88 : helper_(helper), | 89 : helper_(helper), |
| 89 kTimeWaitPeriod_(QuicTime::Delta::FromSeconds(kTimeWaitSeconds)), | 90 kTimeWaitPeriod_( |
| 91 QuicTime::Delta::FromSeconds(FLAGS_quic_time_wait_list_seconds)), |
| 90 connection_id_clean_up_alarm_( | 92 connection_id_clean_up_alarm_( |
| 91 helper_->CreateAlarm(new ConnectionIdCleanUpAlarm(this))), | 93 helper_->CreateAlarm(new ConnectionIdCleanUpAlarm(this))), |
| 92 writer_(writer), | 94 writer_(writer), |
| 93 visitor_(visitor) { | 95 visitor_(visitor) { |
| 94 SetConnectionIdCleanUpAlarm(); | 96 SetConnectionIdCleanUpAlarm(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 QuicTimeWaitListManager::~QuicTimeWaitListManager() { | 99 QuicTimeWaitListManager::~QuicTimeWaitListManager() { |
| 98 connection_id_clean_up_alarm_->Cancel(); | 100 connection_id_clean_up_alarm_->Cancel(); |
| 99 STLDeleteElements(&pending_packets_queue_); | 101 STLDeleteElements(&pending_packets_queue_); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 269 |
| 268 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { | 270 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { |
| 269 QuicTime now = helper_->GetClock()->ApproximateNow(); | 271 QuicTime now = helper_->GetClock()->ApproximateNow(); |
| 270 while (!connection_id_map_.empty()) { | 272 while (!connection_id_map_.empty()) { |
| 271 ConnectionIdMap::iterator it = connection_id_map_.begin(); | 273 ConnectionIdMap::iterator it = connection_id_map_.begin(); |
| 272 QuicTime oldest_connection_id = it->second.time_added; | 274 QuicTime oldest_connection_id = it->second.time_added; |
| 273 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) { | 275 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) { |
| 274 break; | 276 break; |
| 275 } | 277 } |
| 276 // This connection_id has lived its age, retire it now. | 278 // This connection_id has lived its age, retire it now. |
| 279 DVLOG(1) << "Retiring " << it->first << " from the time-wait state."; |
| 277 delete it->second.close_packet; | 280 delete it->second.close_packet; |
| 278 connection_id_map_.erase(it); | 281 connection_id_map_.erase(it); |
| 279 } | 282 } |
| 280 SetConnectionIdCleanUpAlarm(); | 283 SetConnectionIdCleanUpAlarm(); |
| 281 } | 284 } |
| 282 | 285 |
| 283 } // namespace net | 286 } // namespace net |
| OLD | NEW |