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/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 migrating_peer_port_(0), | 271 migrating_peer_port_(0), |
272 last_packet_decrypted_(false), | 272 last_packet_decrypted_(false), |
273 last_packet_revived_(false), | 273 last_packet_revived_(false), |
274 last_size_(0), | 274 last_size_(0), |
275 last_decrypted_packet_level_(ENCRYPTION_NONE), | 275 last_decrypted_packet_level_(ENCRYPTION_NONE), |
276 should_last_packet_instigate_acks_(false), | 276 should_last_packet_instigate_acks_(false), |
277 largest_seen_packet_with_ack_(0), | 277 largest_seen_packet_with_ack_(0), |
278 largest_seen_packet_with_stop_waiting_(0), | 278 largest_seen_packet_with_stop_waiting_(0), |
279 max_undecryptable_packets_(0), | 279 max_undecryptable_packets_(0), |
280 pending_version_negotiation_packet_(false), | 280 pending_version_negotiation_packet_(false), |
| 281 save_crypto_packets_as_termination_packets_(false), |
281 silent_close_enabled_(false), | 282 silent_close_enabled_(false), |
282 received_packet_manager_(&stats_), | 283 received_packet_manager_(&stats_), |
283 ack_queued_(false), | 284 ack_queued_(false), |
284 num_packets_received_since_last_ack_sent_(0), | 285 num_packets_received_since_last_ack_sent_(0), |
285 stop_waiting_count_(0), | 286 stop_waiting_count_(0), |
286 delay_setting_retransmission_alarm_(false), | 287 delay_setting_retransmission_alarm_(false), |
287 pending_retransmission_alarm_(false), | 288 pending_retransmission_alarm_(false), |
288 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), | 289 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), |
289 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), | 290 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), |
290 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 291 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER | 335 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER |
335 ? kDefaultServerMaxPacketSize | 336 ? kDefaultServerMaxPacketSize |
336 : kDefaultMaxPacketSize); | 337 : kDefaultMaxPacketSize); |
337 } | 338 } |
338 | 339 |
339 QuicConnection::~QuicConnection() { | 340 QuicConnection::~QuicConnection() { |
340 if (owns_writer_) { | 341 if (owns_writer_) { |
341 delete writer_; | 342 delete writer_; |
342 } | 343 } |
343 STLDeleteElements(&undecryptable_packets_); | 344 STLDeleteElements(&undecryptable_packets_); |
| 345 if (termination_packets_.get() != nullptr) { |
| 346 STLDeleteElements(termination_packets_.get()); |
| 347 } |
344 STLDeleteValues(&group_map_); | 348 STLDeleteValues(&group_map_); |
345 ClearQueuedPackets(); | 349 ClearQueuedPackets(); |
346 } | 350 } |
347 | 351 |
348 void QuicConnection::ClearQueuedPackets() { | 352 void QuicConnection::ClearQueuedPackets() { |
349 for (QueuedPacketList::iterator it = queued_packets_.begin(); | 353 for (QueuedPacketList::iterator it = queued_packets_.begin(); |
350 it != queued_packets_.end(); ++it) { | 354 it != queued_packets_.end(); ++it) { |
351 delete it->serialized_packet.retransmittable_frames; | 355 delete it->serialized_packet.retransmittable_frames; |
352 delete it->serialized_packet.packet; | 356 delete it->serialized_packet.packet; |
353 } | 357 } |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 << packet->serialized_packet.packet_number | 1494 << packet->serialized_packet.packet_number |
1491 << " after:" << sent_packet_manager_.largest_sent_packet(); | 1495 << " after:" << sent_packet_manager_.largest_sent_packet(); |
1492 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR, | 1496 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR, |
1493 "Packet written out of order."); | 1497 "Packet written out of order."); |
1494 return true; | 1498 return true; |
1495 } | 1499 } |
1496 if (ShouldDiscardPacket(*packet)) { | 1500 if (ShouldDiscardPacket(*packet)) { |
1497 ++stats_.packets_discarded; | 1501 ++stats_.packets_discarded; |
1498 return true; | 1502 return true; |
1499 } | 1503 } |
1500 // Connection close packets are encrypted and saved, so don't exit early. | 1504 // Termination packets are encrypted and saved, so don't exit early. |
1501 const bool is_connection_close = IsConnectionClose(*packet); | 1505 const bool is_termination_packet = IsTerminationPacket(*packet); |
1502 if (writer_->IsWriteBlocked() && !is_connection_close) { | 1506 if (writer_->IsWriteBlocked() && !is_termination_packet) { |
1503 return false; | 1507 return false; |
1504 } | 1508 } |
1505 | 1509 |
1506 QuicPacketNumber packet_number = packet->serialized_packet.packet_number; | 1510 QuicPacketNumber packet_number = packet->serialized_packet.packet_number; |
1507 DCHECK_LE(packet_number_of_last_sent_packet_, packet_number); | 1511 DCHECK_LE(packet_number_of_last_sent_packet_, packet_number); |
1508 packet_number_of_last_sent_packet_ = packet_number; | 1512 packet_number_of_last_sent_packet_ = packet_number; |
1509 | 1513 |
1510 QuicEncryptedPacket* encrypted = packet->serialized_packet.packet; | 1514 QuicEncryptedPacket* encrypted = packet->serialized_packet.packet; |
1511 // Connection close packets are eventually owned by TimeWaitListManager. | 1515 // Termination packets are eventually owned by TimeWaitListManager. |
1512 // Others are deleted at the end of this call. | 1516 // Others are deleted at the end of this call. |
1513 if (is_connection_close) { | 1517 if (is_termination_packet) { |
1514 DCHECK(connection_close_packet_.get() == nullptr); | 1518 if (termination_packets_.get() == nullptr) { |
| 1519 termination_packets_.reset(new std::vector<QuicEncryptedPacket*>); |
| 1520 } |
1515 // Clone the packet so it's owned in the future. | 1521 // Clone the packet so it's owned in the future. |
1516 connection_close_packet_.reset(encrypted->Clone()); | 1522 termination_packets_->push_back(encrypted->Clone()); |
1517 // This assures we won't try to write *forced* packets when blocked. | 1523 // This assures we won't try to write *forced* packets when blocked. |
1518 // Return true to stop processing. | 1524 // Return true to stop processing. |
1519 if (writer_->IsWriteBlocked()) { | 1525 if (writer_->IsWriteBlocked()) { |
1520 visitor_->OnWriteBlocked(); | 1526 visitor_->OnWriteBlocked(); |
1521 return true; | 1527 return true; |
1522 } | 1528 } |
1523 } | 1529 } |
1524 | 1530 |
1525 DCHECK_LE(encrypted->length(), kMaxPacketSize); | 1531 DCHECK_LE(encrypted->length(), kMaxPacketSize); |
1526 DCHECK_LE(encrypted->length(), packet_generator_.GetMaxPacketLength()); | 1532 DCHECK_LE(encrypted->length(), packet_generator_.GetMaxPacketLength()); |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 void QuicConnection::SetMaxPacketLength(QuicByteCount length) { | 2023 void QuicConnection::SetMaxPacketLength(QuicByteCount length) { |
2018 return packet_generator_.SetMaxPacketLength(LimitMaxPacketSize(length), | 2024 return packet_generator_.SetMaxPacketLength(LimitMaxPacketSize(length), |
2019 /*force=*/false); | 2025 /*force=*/false); |
2020 } | 2026 } |
2021 | 2027 |
2022 bool QuicConnection::HasQueuedData() const { | 2028 bool QuicConnection::HasQueuedData() const { |
2023 return pending_version_negotiation_packet_ || | 2029 return pending_version_negotiation_packet_ || |
2024 !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); | 2030 !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); |
2025 } | 2031 } |
2026 | 2032 |
| 2033 void QuicConnection::EnableSavingCryptoPackets() { |
| 2034 save_crypto_packets_as_termination_packets_ = true; |
| 2035 } |
| 2036 |
2027 bool QuicConnection::CanWriteStreamData() { | 2037 bool QuicConnection::CanWriteStreamData() { |
2028 // Don't write stream data if there are negotiation or queued data packets | 2038 // Don't write stream data if there are negotiation or queued data packets |
2029 // to send. Otherwise, continue and bundle as many frames as possible. | 2039 // to send. Otherwise, continue and bundle as many frames as possible. |
2030 if (pending_version_negotiation_packet_ || !queued_packets_.empty()) { | 2040 if (pending_version_negotiation_packet_ || !queued_packets_.empty()) { |
2031 return false; | 2041 return false; |
2032 } | 2042 } |
2033 | 2043 |
2034 IsHandshake pending_handshake = visitor_->HasPendingHandshake() ? | 2044 IsHandshake pending_handshake = visitor_->HasPendingHandshake() ? |
2035 IS_HANDSHAKE : NOT_HANDSHAKE; | 2045 IS_HANDSHAKE : NOT_HANDSHAKE; |
2036 // Sending queued packets may have caused the socket to become write blocked, | 2046 // Sending queued packets may have caused the socket to become write blocked, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2221 // Retransmitted packets retransmittable frames are owned by the unacked | 2231 // Retransmitted packets retransmittable frames are owned by the unacked |
2222 // packet map, but are not present in the serialized packet. | 2232 // packet map, but are not present in the serialized packet. |
2223 if (packet.transmission_type != NOT_RETRANSMISSION || | 2233 if (packet.transmission_type != NOT_RETRANSMISSION || |
2224 packet.serialized_packet.retransmittable_frames != nullptr) { | 2234 packet.serialized_packet.retransmittable_frames != nullptr) { |
2225 return HAS_RETRANSMITTABLE_DATA; | 2235 return HAS_RETRANSMITTABLE_DATA; |
2226 } else { | 2236 } else { |
2227 return NO_RETRANSMITTABLE_DATA; | 2237 return NO_RETRANSMITTABLE_DATA; |
2228 } | 2238 } |
2229 } | 2239 } |
2230 | 2240 |
2231 bool QuicConnection::IsConnectionClose(const QueuedPacket& packet) { | 2241 bool QuicConnection::IsTerminationPacket(const QueuedPacket& packet) { |
2232 const RetransmittableFrames* retransmittable_frames = | 2242 const RetransmittableFrames* retransmittable_frames = |
2233 packet.serialized_packet.retransmittable_frames; | 2243 packet.serialized_packet.retransmittable_frames; |
2234 if (retransmittable_frames == nullptr) { | 2244 if (retransmittable_frames == nullptr) { |
2235 return false; | 2245 return false; |
2236 } | 2246 } |
2237 for (const QuicFrame& frame : retransmittable_frames->frames()) { | 2247 for (const QuicFrame& frame : retransmittable_frames->frames()) { |
2238 if (frame.type == CONNECTION_CLOSE_FRAME) { | 2248 if (frame.type == CONNECTION_CLOSE_FRAME) { |
2239 return true; | 2249 return true; |
2240 } | 2250 } |
| 2251 if (save_crypto_packets_as_termination_packets_ && |
| 2252 frame.type == STREAM_FRAME && |
| 2253 frame.stream_frame->stream_id == kCryptoStreamId) { |
| 2254 return true; |
| 2255 } |
2241 } | 2256 } |
2242 return false; | 2257 return false; |
2243 } | 2258 } |
2244 | 2259 |
2245 void QuicConnection::SetMtuDiscoveryTarget(QuicByteCount target) { | 2260 void QuicConnection::SetMtuDiscoveryTarget(QuicByteCount target) { |
2246 mtu_discovery_target_ = LimitMaxPacketSize(target); | 2261 mtu_discovery_target_ = LimitMaxPacketSize(target); |
2247 } | 2262 } |
2248 | 2263 |
2249 QuicByteCount QuicConnection::LimitMaxPacketSize( | 2264 QuicByteCount QuicConnection::LimitMaxPacketSize( |
2250 QuicByteCount suggested_max_packet_size) { | 2265 QuicByteCount suggested_max_packet_size) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; | 2313 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; |
2299 ++mtu_probe_count_; | 2314 ++mtu_probe_count_; |
2300 | 2315 |
2301 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; | 2316 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; |
2302 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2317 SendMtuDiscoveryPacket(mtu_discovery_target_); |
2303 | 2318 |
2304 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2319 DCHECK(!mtu_discovery_alarm_->IsSet()); |
2305 } | 2320 } |
2306 | 2321 |
2307 } // namespace net | 2322 } // namespace net |
OLD | NEW |