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

Side by Side Diff: net/tools/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
OLDNEW
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 "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"
(...skipping 10 matching lines...) Expand all
21 #include "net/tools/quic/quic_server_session.h" 21 #include "net/tools/quic/quic_server_session.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 namespace tools { 27 namespace tools {
28 28
29 namespace { 29 namespace {
30 30
31 // Time period for which a given connection_id should live in the time-wait 31 // Time period for which the connection_id should live in time wait state.
32 // state. 32 const int kTimeWaitSeconds = 5;
33 int64 FLAGS_quic_time_wait_list_seconds = 5;
34 33
35 } // namespace 34 } // namespace
36 35
37 // A very simple alarm that just informs the QuicTimeWaitListManager to clean 36 // A very simple alarm that just informs the QuicTimeWaitListManager to clean
38 // 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
39 // the QuicTimeWaitListManager is deleted. 38 // the QuicTimeWaitListManager is deleted.
40 class ConnectionIdCleanUpAlarm : public EpollAlarm { 39 class ConnectionIdCleanUpAlarm : public EpollAlarm {
41 public: 40 public:
42 explicit ConnectionIdCleanUpAlarm( 41 explicit ConnectionIdCleanUpAlarm(
43 QuicTimeWaitListManager* time_wait_list_manager) 42 QuicTimeWaitListManager* time_wait_list_manager)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 83
85 DISALLOW_COPY_AND_ASSIGN(QueuedPacket); 84 DISALLOW_COPY_AND_ASSIGN(QueuedPacket);
86 }; 85 };
87 86
88 QuicTimeWaitListManager::QuicTimeWaitListManager( 87 QuicTimeWaitListManager::QuicTimeWaitListManager(
89 QuicPacketWriter* writer, 88 QuicPacketWriter* writer,
90 QuicServerSessionVisitor* visitor, 89 QuicServerSessionVisitor* visitor,
91 EpollServer* epoll_server, 90 EpollServer* epoll_server,
92 const QuicVersionVector& supported_versions) 91 const QuicVersionVector& supported_versions)
93 : epoll_server_(epoll_server), 92 : epoll_server_(epoll_server),
94 kTimeWaitPeriod_( 93 kTimeWaitPeriod_(QuicTime::Delta::FromSeconds(kTimeWaitSeconds)),
95 QuicTime::Delta::FromSeconds(FLAGS_quic_time_wait_list_seconds)),
96 connection_id_clean_up_alarm_(new ConnectionIdCleanUpAlarm(this)), 94 connection_id_clean_up_alarm_(new ConnectionIdCleanUpAlarm(this)),
97 clock_(epoll_server_), 95 clock_(epoll_server_),
98 writer_(writer), 96 writer_(writer),
99 visitor_(visitor) { 97 visitor_(visitor) {
100 SetConnectionIdCleanUpAlarm(); 98 SetConnectionIdCleanUpAlarm();
101 } 99 }
102 100
103 QuicTimeWaitListManager::~QuicTimeWaitListManager() { 101 QuicTimeWaitListManager::~QuicTimeWaitListManager() {
104 connection_id_clean_up_alarm_->UnregisterIfRegistered(); 102 connection_id_clean_up_alarm_->UnregisterIfRegistered();
105 STLDeleteElements(&pending_packets_queue_); 103 STLDeleteElements(&pending_packets_queue_);
106 for (ConnectionIdMap::iterator it = connection_id_map_.begin(); 104 for (ConnectionIdMap::iterator it = connection_id_map_.begin();
107 it != connection_id_map_.end(); 105 it != connection_id_map_.end();
108 ++it) { 106 ++it) {
109 delete it->second.close_packet; 107 delete it->second.close_packet;
110 } 108 }
111 } 109 }
112 110
113 void QuicTimeWaitListManager::AddConnectionIdToTimeWait( 111 void QuicTimeWaitListManager::AddConnectionIdToTimeWait(
114 QuicConnectionId connection_id, 112 QuicConnectionId connection_id,
115 QuicVersion version, 113 QuicVersion version,
116 QuicEncryptedPacket* close_packet) { 114 QuicEncryptedPacket* close_packet) {
117 DVLOG(1) << "Adding " << connection_id << " to the time wait list."; 115 DVLOG(1) << "Adding " << connection_id << " to the time wait list.";
118 int num_packets = 0; 116 int num_packets = 0;
119 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); 117 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id);
120 if (it != connection_id_map_.end()) { // Replace record if it is reinserted. 118 if (it != connection_id_map_.end()) { // Replace record if it is reinserted.
121 num_packets = it->second.num_packets; 119 num_packets = it->second.num_packets;
122 delete it->second.close_packet; 120 delete it->second.close_packet;
123 connection_id_map_.erase(it); 121 connection_id_map_.erase(it);
124 } 122 }
125 ConnectionIdData data(num_packets, version, clock_.ApproximateNow(), 123 ConnectionIdData data(num_packets,
124 version,
125 clock_.ApproximateNow(),
126 close_packet); 126 close_packet);
127 connection_id_map_.insert(make_pair(connection_id, data)); 127 connection_id_map_.insert(make_pair(connection_id, data));
128 } 128 }
129 129
130 bool QuicTimeWaitListManager::IsConnectionIdInTimeWait( 130 bool QuicTimeWaitListManager::IsConnectionIdInTimeWait(
131 QuicConnectionId connection_id) const { 131 QuicConnectionId connection_id) const {
132 return ContainsKey(connection_id_map_, connection_id); 132 return ContainsKey(connection_id_map_, connection_id);
133 } 133 }
134 134
135 QuicVersion QuicTimeWaitListManager::GetQuicVersionFromConnectionId( 135 QuicVersion QuicTimeWaitListManager::GetQuicVersionFromConnectionId(
(...skipping 25 matching lines...) Expand all
161 // TODO(satyamshekhar): Think about handling packets from different client 161 // TODO(satyamshekhar): Think about handling packets from different client
162 // addresses. 162 // addresses.
163 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); 163 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id);
164 DCHECK(it != connection_id_map_.end()); 164 DCHECK(it != connection_id_map_.end());
165 // Increment the received packet count. 165 // Increment the received packet count.
166 ++((it->second).num_packets); 166 ++((it->second).num_packets);
167 if (!ShouldSendResponse((it->second).num_packets)) { 167 if (!ShouldSendResponse((it->second).num_packets)) {
168 return; 168 return;
169 } 169 }
170 if (it->second.close_packet) { 170 if (it->second.close_packet) {
171 QueuedPacket* queued_packet = 171 QueuedPacket* queued_packet =
172 new QueuedPacket(server_address, 172 new QueuedPacket(server_address,
173 client_address, 173 client_address,
174 it->second.close_packet->Clone()); 174 it->second.close_packet->Clone());
175 // Takes ownership of the packet. 175 // Takes ownership of the packet.
176 SendOrQueuePacket(queued_packet); 176 SendOrQueuePacket(queued_packet);
177 } else { 177 } else {
178 SendPublicReset(server_address, 178 SendPublicReset(server_address,
179 client_address, 179 client_address,
180 connection_id, 180 connection_id,
181 sequence_number); 181 sequence_number);
182 } 182 }
183 } 183 }
184 184
185 // Returns true if the number of packets received for this connection_id is a 185 // Returns true if the number of packets received for this connection_id is a
186 // power of 2 to throttle the number of public reset packets we send to a 186 // power of 2 to throttle the number of public reset packets we send to a
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 275
276 void QuicTimeWaitListManager::CleanUpOldConnectionIds() { 276 void QuicTimeWaitListManager::CleanUpOldConnectionIds() {
277 QuicTime now = clock_.ApproximateNow(); 277 QuicTime now = clock_.ApproximateNow();
278 while (!connection_id_map_.empty()) { 278 while (!connection_id_map_.empty()) {
279 ConnectionIdMap::iterator it = connection_id_map_.begin(); 279 ConnectionIdMap::iterator it = connection_id_map_.begin();
280 QuicTime oldest_connection_id = it->second.time_added; 280 QuicTime oldest_connection_id = it->second.time_added;
281 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) { 281 if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
282 break; 282 break;
283 } 283 }
284 // This connection_id has lived its age, retire it now. 284 // This connection_id has lived its age, retire it now.
285 DVLOG(1) << "Retiring " << it->first << " from the time-wait state.";
286 delete it->second.close_packet; 285 delete it->second.close_packet;
287 connection_id_map_.erase(it); 286 connection_id_map_.erase(it);
288 } 287 }
289 SetConnectionIdCleanUpAlarm(); 288 SetConnectionIdCleanUpAlarm();
290 } 289 }
291 290
292 } // namespace tools 291 } // namespace tools
293 } // namespace net 292 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_spdy_client_stream_test.cc ('k') | net/tools/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698