| 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 |
| 11 #include "base/logging.h" | |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 14 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 15 #include "net/quic/core/crypto/crypto_protocol.h" | 14 #include "net/quic/core/crypto/crypto_protocol.h" |
| 16 #include "net/quic/core/crypto/quic_decrypter.h" | 15 #include "net/quic/core/crypto/quic_decrypter.h" |
| 17 #include "net/quic/core/crypto/quic_encrypter.h" | 16 #include "net/quic/core/crypto/quic_encrypter.h" |
| 18 #include "net/quic/core/quic_flags.h" | 17 #include "net/quic/core/quic_flags.h" |
| 19 #include "net/quic/core/quic_framer.h" | 18 #include "net/quic/core/quic_framer.h" |
| 20 #include "net/quic/core/quic_packets.h" | 19 #include "net/quic/core/quic_packets.h" |
| 21 #include "net/quic/core/quic_server_session_base.h" | 20 #include "net/quic/core/quic_server_session_base.h" |
| 22 #include "net/quic/core/quic_utils.h" | 21 #include "net/quic/core/quic_utils.h" |
| 23 #include "net/quic/platform/api/quic_clock.h" | 22 #include "net/quic/platform/api/quic_clock.h" |
| 23 #include "net/quic/platform/api/quic_logging.h" |
| 24 #include "net/quic/platform/api/quic_socket_address.h" | 24 #include "net/quic/platform/api/quic_socket_address.h" |
| 25 | 25 |
| 26 using base::StringPiece; | 26 using base::StringPiece; |
| 27 | 27 |
| 28 namespace net { | 28 namespace net { |
| 29 | 29 |
| 30 // A very simple alarm that just informs the QuicTimeWaitListManager to clean | 30 // A very simple alarm that just informs the QuicTimeWaitListManager to clean |
| 31 // up old connection_ids. This alarm should be cancelled and deleted before | 31 // up old connection_ids. This alarm should be cancelled and deleted before |
| 32 // the QuicTimeWaitListManager is deleted. | 32 // the QuicTimeWaitListManager is deleted. |
| 33 class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate { | 33 class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 void QuicTimeWaitListManager::ProcessPacket( | 150 void QuicTimeWaitListManager::ProcessPacket( |
| 151 const QuicSocketAddress& server_address, | 151 const QuicSocketAddress& server_address, |
| 152 const QuicSocketAddress& client_address, | 152 const QuicSocketAddress& client_address, |
| 153 QuicConnectionId connection_id, | 153 QuicConnectionId connection_id, |
| 154 QuicPacketNumber packet_number, | 154 QuicPacketNumber packet_number, |
| 155 const QuicEncryptedPacket& /*packet*/) { | 155 const QuicEncryptedPacket& /*packet*/) { |
| 156 DCHECK(IsConnectionIdInTimeWait(connection_id)); | 156 DCHECK(IsConnectionIdInTimeWait(connection_id)); |
| 157 DVLOG(1) << "Processing " << connection_id << " in time wait state."; | 157 QUIC_DLOG(INFO) << "Processing " << connection_id << " in time wait state."; |
| 158 // TODO(satyamshekhar): Think about handling packets from different client | 158 // TODO(satyamshekhar): Think about handling packets from different client |
| 159 // addresses. | 159 // addresses. |
| 160 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); | 160 ConnectionIdMap::iterator it = connection_id_map_.find(connection_id); |
| 161 DCHECK(it != connection_id_map_.end()); | 161 DCHECK(it != connection_id_map_.end()); |
| 162 // Increment the received packet count. | 162 // Increment the received packet count. |
| 163 ConnectionIdData* connection_data = &it->second; | 163 ConnectionIdData* connection_data = &it->second; |
| 164 ++(connection_data->num_packets); | 164 ++(connection_data->num_packets); |
| 165 | 165 |
| 166 if (!ShouldSendResponse(connection_data->num_packets)) { | 166 if (!ShouldSendResponse(connection_data->num_packets)) { |
| 167 return; | 167 return; |
| 168 } | 168 } |
| 169 | 169 |
| 170 if (!connection_data->termination_packets.empty()) { | 170 if (!connection_data->termination_packets.empty()) { |
| 171 if (connection_data->connection_rejected_statelessly) { | 171 if (connection_data->connection_rejected_statelessly) { |
| 172 DVLOG(3) << "Time wait list sending previous stateless reject response " | 172 QUIC_DVLOG(3) |
| 173 << "for connection " << connection_id; | 173 << "Time wait list sending previous stateless reject response " |
| 174 << "for connection " << connection_id; |
| 174 } | 175 } |
| 175 for (const auto& packet : connection_data->termination_packets) { | 176 for (const auto& packet : connection_data->termination_packets) { |
| 176 SendOrQueuePacket(base::MakeUnique<QueuedPacket>( | 177 SendOrQueuePacket(base::MakeUnique<QueuedPacket>( |
| 177 server_address, client_address, packet->Clone())); | 178 server_address, client_address, packet->Clone())); |
| 178 } | 179 } |
| 179 return; | 180 return; |
| 180 } | 181 } |
| 181 | 182 |
| 182 SendPublicReset(server_address, client_address, connection_id, packet_number); | 183 SendPublicReset(server_address, client_address, connection_id, packet_number); |
| 183 } | 184 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 WriteResult result = writer_->WritePacket( | 242 WriteResult result = writer_->WritePacket( |
| 242 queued_packet->packet()->data(), queued_packet->packet()->length(), | 243 queued_packet->packet()->data(), queued_packet->packet()->length(), |
| 243 queued_packet->server_address().host(), queued_packet->client_address(), | 244 queued_packet->server_address().host(), queued_packet->client_address(), |
| 244 nullptr); | 245 nullptr); |
| 245 if (result.status == WRITE_STATUS_BLOCKED) { | 246 if (result.status == WRITE_STATUS_BLOCKED) { |
| 246 // If blocked and unbuffered, return false to retry sending. | 247 // If blocked and unbuffered, return false to retry sending. |
| 247 DCHECK(writer_->IsWriteBlocked()); | 248 DCHECK(writer_->IsWriteBlocked()); |
| 248 visitor_->OnWriteBlocked(this); | 249 visitor_->OnWriteBlocked(this); |
| 249 return writer_->IsWriteBlockedDataBuffered(); | 250 return writer_->IsWriteBlockedDataBuffered(); |
| 250 } else if (result.status == WRITE_STATUS_ERROR) { | 251 } else if (result.status == WRITE_STATUS_ERROR) { |
| 251 LOG(WARNING) << "Received unknown error while sending reset packet to " | 252 QUIC_LOG_FIRST_N(WARNING, 1) |
| 252 << queued_packet->client_address().ToString() << ": " | 253 << "Received unknown error while sending reset packet to " |
| 253 << strerror(result.error_code); | 254 << queued_packet->client_address().ToString() << ": " |
| 255 << strerror(result.error_code); |
| 254 } | 256 } |
| 255 return true; | 257 return true; |
| 256 } | 258 } |
| 257 | 259 |
| 258 void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() { | 260 void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() { |
| 259 QuicTime::Delta next_alarm_interval = QuicTime::Delta::Zero(); | 261 QuicTime::Delta next_alarm_interval = QuicTime::Delta::Zero(); |
| 260 if (!connection_id_map_.empty()) { | 262 if (!connection_id_map_.empty()) { |
| 261 QuicTime oldest_connection_id = | 263 QuicTime oldest_connection_id = |
| 262 connection_id_map_.begin()->second.time_added; | 264 connection_id_map_.begin()->second.time_added; |
| 263 QuicTime now = clock_->ApproximateNow(); | 265 QuicTime now = clock_->ApproximateNow(); |
| 264 if (now - oldest_connection_id < time_wait_period_) { | 266 if (now - oldest_connection_id < time_wait_period_) { |
| 265 next_alarm_interval = oldest_connection_id + time_wait_period_ - now; | 267 next_alarm_interval = oldest_connection_id + time_wait_period_ - now; |
| 266 } else { | 268 } else { |
| 267 LOG(ERROR) << "ConnectionId lingered for longer than time_wait_period_"; | 269 QUIC_LOG(ERROR) |
| 270 << "ConnectionId lingered for longer than time_wait_period_"; |
| 268 } | 271 } |
| 269 } else { | 272 } else { |
| 270 // No connection_ids added so none will expire before time_wait_period_. | 273 // No connection_ids added so none will expire before time_wait_period_. |
| 271 next_alarm_interval = time_wait_period_; | 274 next_alarm_interval = time_wait_period_; |
| 272 } | 275 } |
| 273 | 276 |
| 274 connection_id_clean_up_alarm_->Update( | 277 connection_id_clean_up_alarm_->Update( |
| 275 clock_->ApproximateNow() + next_alarm_interval, QuicTime::Delta::Zero()); | 278 clock_->ApproximateNow() + next_alarm_interval, QuicTime::Delta::Zero()); |
| 276 } | 279 } |
| 277 | 280 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 version(version_), | 323 version(version_), |
| 321 time_added(time_added_), | 324 time_added(time_added_), |
| 322 connection_rejected_statelessly(connection_rejected_statelessly) {} | 325 connection_rejected_statelessly(connection_rejected_statelessly) {} |
| 323 | 326 |
| 324 QuicTimeWaitListManager::ConnectionIdData::ConnectionIdData( | 327 QuicTimeWaitListManager::ConnectionIdData::ConnectionIdData( |
| 325 ConnectionIdData&& other) = default; | 328 ConnectionIdData&& other) = default; |
| 326 | 329 |
| 327 QuicTimeWaitListManager::ConnectionIdData::~ConnectionIdData() {} | 330 QuicTimeWaitListManager::ConnectionIdData::~ConnectionIdData() {} |
| 328 | 331 |
| 329 } // namespace net | 332 } // namespace net |
| OLD | NEW |