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 <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return true; | 260 return true; |
261 } | 261 } |
262 | 262 |
263 void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() { | 263 void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() { |
264 connection_id_clean_up_alarm_->Cancel(); | 264 connection_id_clean_up_alarm_->Cancel(); |
265 QuicTime::Delta next_alarm_interval = QuicTime::Delta::Zero(); | 265 QuicTime::Delta next_alarm_interval = QuicTime::Delta::Zero(); |
266 if (!connection_id_map_.empty()) { | 266 if (!connection_id_map_.empty()) { |
267 QuicTime oldest_connection_id = | 267 QuicTime oldest_connection_id = |
268 connection_id_map_.begin()->second.time_added; | 268 connection_id_map_.begin()->second.time_added; |
269 QuicTime now = clock_->ApproximateNow(); | 269 QuicTime now = clock_->ApproximateNow(); |
270 if (now.Subtract(oldest_connection_id) < time_wait_period_) { | 270 if (now - oldest_connection_id < time_wait_period_) { |
271 next_alarm_interval = | 271 next_alarm_interval = oldest_connection_id + time_wait_period_ - now; |
272 oldest_connection_id.Add(time_wait_period_).Subtract(now); | |
273 } else { | 272 } else { |
274 LOG(ERROR) << "ConnectionId lingered for longer than time_wait_period_"; | 273 LOG(ERROR) << "ConnectionId lingered for longer than time_wait_period_"; |
275 } | 274 } |
276 } else { | 275 } else { |
277 // No connection_ids added so none will expire before time_wait_period_. | 276 // No connection_ids added so none will expire before time_wait_period_. |
278 next_alarm_interval = time_wait_period_; | 277 next_alarm_interval = time_wait_period_; |
279 } | 278 } |
280 | 279 |
281 connection_id_clean_up_alarm_->Set( | 280 connection_id_clean_up_alarm_->Set(clock_->ApproximateNow() + |
282 clock_->ApproximateNow().Add(next_alarm_interval)); | 281 next_alarm_interval); |
283 } | 282 } |
284 | 283 |
285 bool QuicTimeWaitListManager::MaybeExpireOldestConnection( | 284 bool QuicTimeWaitListManager::MaybeExpireOldestConnection( |
286 QuicTime expiration_time) { | 285 QuicTime expiration_time) { |
287 if (connection_id_map_.empty()) { | 286 if (connection_id_map_.empty()) { |
288 return false; | 287 return false; |
289 } | 288 } |
290 ConnectionIdMap::iterator it = connection_id_map_.begin(); | 289 ConnectionIdMap::iterator it = connection_id_map_.begin(); |
291 QuicTime oldest_connection_id_time = it->second.time_added; | 290 QuicTime oldest_connection_id_time = it->second.time_added; |
292 if (oldest_connection_id_time > expiration_time) { | 291 if (oldest_connection_id_time > expiration_time) { |
293 // Too recent, don't retire. | 292 // Too recent, don't retire. |
294 return false; | 293 return false; |
295 } | 294 } |
296 // This connection_id has lived its age, retire it now. | 295 // This connection_id has lived its age, retire it now. |
297 connection_id_map_.erase(it); | 296 connection_id_map_.erase(it); |
298 return true; | 297 return true; |
299 } | 298 } |
300 | 299 |
301 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { | 300 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { |
302 QuicTime now = clock_->ApproximateNow(); | 301 QuicTime now = clock_->ApproximateNow(); |
303 QuicTime expiration = now.Subtract(time_wait_period_); | 302 QuicTime expiration = now - time_wait_period_; |
304 | 303 |
305 while (MaybeExpireOldestConnection(expiration)) { | 304 while (MaybeExpireOldestConnection(expiration)) { |
306 } | 305 } |
307 | 306 |
308 SetConnectionIdCleanUpAlarm(); | 307 SetConnectionIdCleanUpAlarm(); |
309 } | 308 } |
310 | 309 |
311 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() { | 310 void QuicTimeWaitListManager::TrimTimeWaitListIfNeeded() { |
312 if (FLAGS_quic_time_wait_list_max_connections < 0) { | 311 if (FLAGS_quic_time_wait_list_max_connections < 0) { |
313 return; | 312 return; |
(...skipping 13 matching lines...) Expand all Loading... |
327 version(version_), | 326 version(version_), |
328 time_added(time_added_), | 327 time_added(time_added_), |
329 connection_rejected_statelessly(connection_rejected_statelessly) {} | 328 connection_rejected_statelessly(connection_rejected_statelessly) {} |
330 | 329 |
331 QuicTimeWaitListManager::ConnectionIdData::ConnectionIdData( | 330 QuicTimeWaitListManager::ConnectionIdData::ConnectionIdData( |
332 ConnectionIdData&& other) = default; | 331 ConnectionIdData&& other) = default; |
333 | 332 |
334 QuicTimeWaitListManager::ConnectionIdData::~ConnectionIdData() {} | 333 QuicTimeWaitListManager::ConnectionIdData::~ConnectionIdData() {} |
335 | 334 |
336 } // namespace net | 335 } // namespace net |
OLD | NEW |