| 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 "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 const QuicEncryptedPacket& /*packet*/) { | 159 const QuicEncryptedPacket& /*packet*/) { |
| 160 DCHECK(IsConnectionIdInTimeWait(connection_id)); | 160 DCHECK(IsConnectionIdInTimeWait(connection_id)); |
| 161 DVLOG(1) << "Processing " << connection_id << " in time wait state."; | 161 DVLOG(1) << "Processing " << connection_id << " in time wait state."; |
| 162 // TODO(satyamshekhar): Think about handling packets from different client | 162 // TODO(satyamshekhar): Think about handling packets from different client |
| 163 // addresses. | 163 // addresses. |
| 164 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); | 164 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); |
| 165 DCHECK(it != connection_id_map_.end()); | 165 DCHECK(it != connection_id_map_.end()); |
| 166 // Increment the received packet count. | 166 // Increment the received packet count. |
| 167 ConnectionIdData* connection_data = &it->second; | 167 ConnectionIdData* connection_data = &it->second; |
| 168 ++(connection_data->num_packets); | 168 ++(connection_data->num_packets); |
| 169 |
| 169 if (!ShouldSendResponse(connection_data->num_packets)) { | 170 if (!ShouldSendResponse(connection_data->num_packets)) { |
| 170 return; | 171 return; |
| 171 } | 172 } |
| 173 |
| 172 if (connection_data->close_packet) { | 174 if (connection_data->close_packet) { |
| 173 QueuedPacket* queued_packet = new QueuedPacket( | 175 QueuedPacket* queued_packet = new QueuedPacket( |
| 174 server_address, client_address, connection_data->close_packet->Clone()); | 176 server_address, client_address, connection_data->close_packet->Clone()); |
| 175 // Takes ownership of the packet. | 177 // Takes ownership of the packet. |
| 176 SendOrQueuePacket(queued_packet); | 178 SendOrQueuePacket(queued_packet); |
| 177 } else if (!connection_data->connection_rejected_statelessly) { | 179 return; |
| 178 SendPublicReset(server_address, client_address, connection_id, | 180 } |
| 179 packet_number); | 181 |
| 180 } else { | 182 if (connection_data->connection_rejected_statelessly) { |
| 181 DVLOG(3) << "Time wait list not sending response for connection " | 183 DVLOG(3) << "Time wait list not sending response for connection " |
| 182 << connection_id << " due to previous stateless reject."; | 184 << connection_id << " due to previous stateless reject."; |
| 185 return; |
| 183 } | 186 } |
| 187 |
| 188 SendPublicReset(server_address, client_address, connection_id, packet_number); |
| 184 } | 189 } |
| 185 | 190 |
| 186 // Returns true if the number of packets received for this connection_id is a | 191 // Returns true if the number of packets received for this connection_id is a |
| 187 // power of 2 to throttle the number of public reset packets we send to a | 192 // power of 2 to throttle the number of public reset packets we send to a |
| 188 // client. | 193 // client. |
| 189 bool QuicTimeWaitListManager::ShouldSendResponse(int received_packet_count) { | 194 bool QuicTimeWaitListManager::ShouldSendResponse(int received_packet_count) { |
| 190 return (received_packet_count & (received_packet_count - 1)) == 0; | 195 return (received_packet_count & (received_packet_count - 1)) == 0; |
| 191 } | 196 } |
| 192 | 197 |
| 193 void QuicTimeWaitListManager::SendPublicReset( | 198 void QuicTimeWaitListManager::SendPublicReset( |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 return; | 311 return; |
| 307 } | 312 } |
| 308 while (num_connections() >= | 313 while (num_connections() >= |
| 309 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { | 314 static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections)) { |
| 310 MaybeExpireOldestConnection(QuicTime::Infinite()); | 315 MaybeExpireOldestConnection(QuicTime::Infinite()); |
| 311 } | 316 } |
| 312 } | 317 } |
| 313 | 318 |
| 314 } // namespace tools | 319 } // namespace tools |
| 315 } // namespace net | 320 } // namespace net |
| OLD | NEW |