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

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

Issue 734063004: Update from https://crrev.com/304418 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/quic/quic_stream_factory.cc ('k') | net/quic/test_tools/quic_config_peer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 a given connection_id should live in the time-wait 30 // Time period for which the connection_id should live in time wait state.
31 // state. 31 const int kTimeWaitSeconds = 5;
32 int64 FLAGS_quic_time_wait_list_seconds = 5;
33 32
34 } // namespace 33 } // namespace
35 34
36 // A very simple alarm that just informs the QuicTimeWaitListManager to clean 35 // A very simple alarm that just informs the QuicTimeWaitListManager to clean
37 // up old connection_ids. This alarm should be unregistered and deleted before 36 // up old connection_ids. This alarm should be unregistered and deleted before
38 // the QuicTimeWaitListManager is deleted. 37 // the QuicTimeWaitListManager is deleted.
39 class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate { 38 class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate {
40 public: 39 public:
41 explicit ConnectionIdCleanUpAlarm( 40 explicit ConnectionIdCleanUpAlarm(
42 QuicTimeWaitListManager* time_wait_list_manager) 41 QuicTimeWaitListManager* time_wait_list_manager)
43 : time_wait_list_manager_(time_wait_list_manager) {} 42 : time_wait_list_manager_(time_wait_list_manager) {
43 }
44 44
45 QuicTime OnAlarm() override { 45 QuicTime OnAlarm() override {
46 time_wait_list_manager_->CleanUpOldConnectionIds(); 46 time_wait_list_manager_->CleanUpOldConnectionIds();
47 // Let the time wait manager register the alarm at appropriate time. 47 // Let the time wait manager register the alarm at appropriate time.
48 return QuicTime::Zero(); 48 return QuicTime::Zero();
49 } 49 }
50 50
51 private: 51 private:
52 // Not owned. 52 // Not owned.
53 QuicTimeWaitListManager* time_wait_list_manager_; 53 QuicTimeWaitListManager* time_wait_list_manager_;
54 }; 54 };
55 55
56 // This class stores pending public reset packets to be sent to clients. 56 // This class stores pending public reset packets to be sent to clients.
57 // server_address - server address on which a packet what was received for 57 // server_address - server address on which a packet what was received for
58 // a connection_id in time wait state. 58 // a connection_id in time wait state.
59 // client_address - address of the client that sent that packet. Needed to send 59 // client_address - address of the client that sent that packet. Needed to send
60 // the public reset packet back to the client. 60 // the public reset packet back to the client.
61 // packet - the pending public reset packet that is to be sent to the client. 61 // packet - the pending public reset packet that is to be sent to the client.
62 // created instance takes the ownership of this packet. 62 // created instance takes the ownership of this packet.
63 class QuicTimeWaitListManager::QueuedPacket { 63 class QuicTimeWaitListManager::QueuedPacket {
64 public: 64 public:
65 QueuedPacket(const IPEndPoint& server_address, 65 QueuedPacket(const IPEndPoint& server_address,
66 const IPEndPoint& client_address, 66 const IPEndPoint& client_address,
67 QuicEncryptedPacket* packet) 67 QuicEncryptedPacket* packet)
68 : server_address_(server_address), 68 : server_address_(server_address),
69 client_address_(client_address), 69 client_address_(client_address),
70 packet_(packet) {} 70 packet_(packet) {
71 }
71 72
72 const IPEndPoint& server_address() const { return server_address_; } 73 const IPEndPoint& server_address() const { return server_address_; }
73 const IPEndPoint& client_address() const { return client_address_; } 74 const IPEndPoint& client_address() const { return client_address_; }
74 QuicEncryptedPacket* packet() { return packet_.get(); } 75 QuicEncryptedPacket* packet() { return packet_.get(); }
75 76
76 private: 77 private:
77 const IPEndPoint server_address_; 78 const IPEndPoint server_address_;
78 const IPEndPoint client_address_; 79 const IPEndPoint client_address_;
79 scoped_ptr<QuicEncryptedPacket> packet_; 80 scoped_ptr<QuicEncryptedPacket> packet_;
80 81
81 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); 82 DISALLOW_COPY_AND_ASSIGN(QueuedPacket);
82 }; 83 };
83 84
84 QuicTimeWaitListManager::QuicTimeWaitListManager( 85 QuicTimeWaitListManager::QuicTimeWaitListManager(
85 QuicPacketWriter* writer, 86 QuicPacketWriter* writer,
86 QuicServerSessionVisitor* visitor, 87 QuicServerSessionVisitor* visitor,
87 QuicConnectionHelperInterface* helper, 88 QuicConnectionHelperInterface* helper,
88 const QuicVersionVector& supported_versions) 89 const QuicVersionVector& supported_versions)
89 : helper_(helper), 90 : helper_(helper),
90 kTimeWaitPeriod_( 91 kTimeWaitPeriod_(QuicTime::Delta::FromSeconds(kTimeWaitSeconds)),
91 QuicTime::Delta::FromSeconds(FLAGS_quic_time_wait_list_seconds)),
92 connection_id_clean_up_alarm_( 92 connection_id_clean_up_alarm_(
93 helper_->CreateAlarm(new ConnectionIdCleanUpAlarm(this))), 93 helper_->CreateAlarm(new ConnectionIdCleanUpAlarm(this))),
94 writer_(writer), 94 writer_(writer),
95 visitor_(visitor) { 95 visitor_(visitor) {
96 SetConnectionIdCleanUpAlarm(); 96 SetConnectionIdCleanUpAlarm();
97 } 97 }
98 98
99 QuicTimeWaitListManager::~QuicTimeWaitListManager() { 99 QuicTimeWaitListManager::~QuicTimeWaitListManager() {
100 connection_id_clean_up_alarm_->Cancel(); 100 connection_id_clean_up_alarm_->Cancel();
101 STLDeleteElements(&pending_packets_queue_); 101 STLDeleteElements(&pending_packets_queue_);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { 270 void QuicTimeWaitListManager::CleanUpOldConnectionIds() {
271 QuicTime now = helper_->GetClock()->ApproximateNow(); 271 QuicTime now = helper_->GetClock()->ApproximateNow();
272 while (!connection_id_map_.empty()) { 272 while (!connection_id_map_.empty()) {
273 ConnectionIdMap::iterator it = connection_id_map_.begin(); 273 ConnectionIdMap::iterator it = connection_id_map_.begin();
274 QuicTime oldest_connection_id = it->second.time_added; 274 QuicTime oldest_connection_id = it->second.time_added;
275 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) { 275 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
276 break; 276 break;
277 } 277 }
278 // 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.";
280 delete it->second.close_packet; 279 delete it->second.close_packet;
281 connection_id_map_.erase(it); 280 connection_id_map_.erase(it);
282 } 281 }
283 SetConnectionIdCleanUpAlarm(); 282 SetConnectionIdCleanUpAlarm();
284 } 283 }
285 284
286 } // namespace net 285 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_stream_factory.cc ('k') | net/quic/test_tools/quic_config_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698