| Index: net/tools/quic/quic_time_wait_list_manager.cc
|
| diff --git a/net/tools/quic/quic_time_wait_list_manager.cc b/net/tools/quic/quic_time_wait_list_manager.cc
|
| index ed6addc4c8644238b7dbc1b8e5132031b610d3e1..1cb86a584a2db19b64ab1b1873ea47b6f0636b32 100644
|
| --- a/net/tools/quic/quic_time_wait_list_manager.cc
|
| +++ b/net/tools/quic/quic_time_wait_list_manager.cc
|
| @@ -14,6 +14,7 @@
|
| #include "net/quic/crypto/quic_decrypter.h"
|
| #include "net/quic/crypto/quic_encrypter.h"
|
| #include "net/quic/quic_clock.h"
|
| +#include "net/quic/quic_flags.h"
|
| #include "net/quic/quic_framer.h"
|
| #include "net/quic/quic_protocol.h"
|
| #include "net/quic/quic_utils.h"
|
| @@ -26,13 +27,8 @@ using std::make_pair;
|
| namespace net {
|
| namespace tools {
|
|
|
| -namespace {
|
| -
|
| -// Time period for which a given connection_id should live in the time-wait
|
| -// state.
|
| -int64 FLAGS_quic_time_wait_list_seconds = 5;
|
| -
|
| -} // namespace
|
| +// TODO(rtenneti): Remove the duplicated code in this file. Share code with
|
| +// "net/quic/quic_time_wait_list_manager.cc"
|
|
|
| // A very simple alarm that just informs the QuicTimeWaitListManager to clean
|
| // up old connection_ids. This alarm should be unregistered and deleted before
|
| @@ -122,6 +118,11 @@ void QuicTimeWaitListManager::AddConnectionIdToTimeWait(
|
| delete it->second.close_packet;
|
| connection_id_map_.erase(it);
|
| }
|
| + TrimTimeWaitListIfNeeded();
|
| + if (FLAGS_quic_limit_time_wait_list_size) {
|
| + DCHECK_LT(num_connections(),
|
| + static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections));
|
| + }
|
| ConnectionIdData data(num_packets,
|
| version,
|
| clock_.ApproximateNow(),
|
| @@ -278,22 +279,60 @@ void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() {
|
| next_alarm_interval, connection_id_clean_up_alarm_.get());
|
| }
|
|
|
| +bool QuicTimeWaitListManager::MaybeExpireOldestConnection(
|
| + QuicTime expiration_time) {
|
| + if (connection_id_map_.empty()) {
|
| + return false;
|
| + }
|
| + ConnectionIdMap::iterator it = connection_id_map_.begin();
|
| + QuicTime oldest_connection_id_time = it->second.time_added;
|
| + if (oldest_connection_id_time > expiration_time) {
|
| + // Too recent, don't retire.
|
| + return false;
|
| + }
|
| + // This connection_id has lived its age, retire it now.
|
| + const QuicConnectionId connection_id = it->first;
|
| + delete it->second.close_packet;
|
| + connection_id_map_.erase(it);
|
| + visitor_->OnConnectionRemovedFromTimeWaitList(connection_id);
|
| + return true;
|
| +}
|
| +
|
| void QuicTimeWaitListManager::CleanUpOldConnectionIds() {
|
| QuicTime now = clock_.ApproximateNow();
|
| - while (!connection_id_map_.empty()) {
|
| - ConnectionIdMap::iterator it = connection_id_map_.begin();
|
| - QuicTime oldest_connection_id = it->second.time_added;
|
| - if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
|
| - break;
|
| + QuicTime expiration = now.Subtract(kTimeWaitPeriod_);
|
| + if (FLAGS_quic_limit_time_wait_list_size) {
|
| + while (MaybeExpireOldestConnection(expiration)) {
|
| + }
|
| + } else {
|
| + while (!connection_id_map_.empty()) {
|
| + ConnectionIdMap::iterator it = connection_id_map_.begin();
|
| + QuicTime oldest_connection_id = it->second.time_added;
|
| + if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
|
| + break;
|
| + }
|
| + const QuicConnectionId connection_id = it->first;
|
| + // This connection_id has lived its age, retire it now.
|
| + delete it->second.close_packet;
|
| + connection_id_map_.erase(it);
|
| + visitor_->OnConnectionRemovedFromTimeWaitList(connection_id);
|
| }
|
| - const QuicConnectionId connection_id = it->first;
|
| - // This connection_id has lived its age, retire it now.
|
| - delete it->second.close_packet;
|
| - connection_id_map_.erase(it);
|
| - visitor_->OnConnectionRemovedFromTimeWaitList(connection_id);
|
| }
|
| +
|
| SetConnectionIdCleanUpAlarm();
|
| }
|
|
|
| +void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() {
|
| + if (FLAGS_quic_limit_time_wait_list_size) {
|
| + if (FLAGS_quic_time_wait_list_max_connections < 0) {
|
| + return;
|
| + }
|
| + while (num_connections() >=
|
| + static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) {
|
| + MaybeExpireOldestConnection(QuicTime::Infinite());
|
| + }
|
| + }
|
| +}
|
| +
|
| } // namespace tools
|
| } // namespace net
|
|
|