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/core/quic_connection.h" | 5 #include "net/quic/core/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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 class QuicDecrypter; | 42 class QuicDecrypter; |
43 class QuicEncrypter; | 43 class QuicEncrypter; |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 // The largest gap in packets we'll accept without closing the connection. | 47 // The largest gap in packets we'll accept without closing the connection. |
48 // This will likely have to be tuned. | 48 // This will likely have to be tuned. |
49 const QuicPacketNumber kMaxPacketGap = 5000; | 49 const QuicPacketNumber kMaxPacketGap = 5000; |
50 | 50 |
51 // Maximum number of acks received before sending an ack in response. | 51 // Maximum number of acks received before sending an ack in response. |
| 52 // TODO(fayang): Remove this constant when deprecating QUIC_VERSION_38. |
52 const QuicPacketCount kMaxPacketsReceivedBeforeAckSend = 20; | 53 const QuicPacketCount kMaxPacketsReceivedBeforeAckSend = 20; |
53 | 54 |
| 55 // Maximum number of consecutive sent nonretransmittable packets. |
| 56 const QuicPacketCount kMaxConsecutiveNonRetransmittablePackets = 19; |
| 57 |
54 // Maximum number of retransmittable packets received before sending an ack. | 58 // Maximum number of retransmittable packets received before sending an ack. |
55 const QuicPacketCount kDefaultRetransmittablePacketsBeforeAck = 2; | 59 const QuicPacketCount kDefaultRetransmittablePacketsBeforeAck = 2; |
56 // Minimum number of packets received before ack decimation is enabled. | 60 // Minimum number of packets received before ack decimation is enabled. |
57 // This intends to avoid the beginning of slow start, when CWNDs may be | 61 // This intends to avoid the beginning of slow start, when CWNDs may be |
58 // rapidly increasing. | 62 // rapidly increasing. |
59 const QuicPacketCount kMinReceivedBeforeAckDecimation = 100; | 63 const QuicPacketCount kMinReceivedBeforeAckDecimation = 100; |
60 // Wait for up to 10 retransmittable packets before sending an ack. | 64 // Wait for up to 10 retransmittable packets before sending an ack. |
61 const QuicPacketCount kMaxRetransmittablePacketsBeforeAck = 10; | 65 const QuicPacketCount kMaxRetransmittablePacketsBeforeAck = 10; |
62 // One quarter RTT delay when doing ack decimation. | 66 // One quarter RTT delay when doing ack decimation. |
63 const float kAckDecimationDelay = 0.25; | 67 const float kAckDecimationDelay = 0.25; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 connected_(true), | 258 connected_(true), |
255 can_truncate_connection_ids_(true), | 259 can_truncate_connection_ids_(true), |
256 mtu_discovery_target_(0), | 260 mtu_discovery_target_(0), |
257 mtu_probe_count_(0), | 261 mtu_probe_count_(0), |
258 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), | 262 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), |
259 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), | 263 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), |
260 largest_received_packet_size_(0), | 264 largest_received_packet_size_(0), |
261 goaway_sent_(false), | 265 goaway_sent_(false), |
262 goaway_received_(false), | 266 goaway_received_(false), |
263 write_error_occured_(false), | 267 write_error_occured_(false), |
264 no_stop_waiting_frames_(false) { | 268 no_stop_waiting_frames_(false), |
| 269 consecutive_num_packets_with_no_retransmittable_frames_(0) { |
265 QUIC_DLOG(INFO) << ENDPOINT | 270 QUIC_DLOG(INFO) << ENDPOINT |
266 << "Created connection with connection_id: " << connection_id; | 271 << "Created connection with connection_id: " << connection_id; |
267 framer_.set_visitor(this); | 272 framer_.set_visitor(this); |
268 stats_.connection_creation_time = clock_->ApproximateNow(); | 273 stats_.connection_creation_time = clock_->ApproximateNow(); |
269 // TODO(ianswett): Supply the NetworkChangeVisitor as a constructor argument | 274 // TODO(ianswett): Supply the NetworkChangeVisitor as a constructor argument |
270 // and make it required non-null, because it's always used. | 275 // and make it required non-null, because it's always used. |
271 sent_packet_manager_.SetNetworkChangeVisitor(this); | 276 sent_packet_manager_.SetNetworkChangeVisitor(this); |
272 // Allow the packet writer to potentially reduce the packet size to a value | 277 // Allow the packet writer to potentially reduce the packet size to a value |
273 // even smaller than kDefaultMaxPacketSize. | 278 // even smaller than kDefaultMaxPacketSize. |
274 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER | 279 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 MaybeQueueAck(was_missing); | 931 MaybeQueueAck(was_missing); |
927 } | 932 } |
928 | 933 |
929 ClearLastFrames(); | 934 ClearLastFrames(); |
930 } | 935 } |
931 | 936 |
932 void QuicConnection::MaybeQueueAck(bool was_missing) { | 937 void QuicConnection::MaybeQueueAck(bool was_missing) { |
933 ++num_packets_received_since_last_ack_sent_; | 938 ++num_packets_received_since_last_ack_sent_; |
934 // Always send an ack every 20 packets in order to allow the peer to discard | 939 // Always send an ack every 20 packets in order to allow the peer to discard |
935 // information from the SentPacketManager and provide an RTT measurement. | 940 // information from the SentPacketManager and provide an RTT measurement. |
936 if (num_packets_received_since_last_ack_sent_ >= | 941 if (version() <= QUIC_VERSION_38 && |
937 kMaxPacketsReceivedBeforeAckSend) { | 942 num_packets_received_since_last_ack_sent_ >= |
| 943 kMaxPacketsReceivedBeforeAckSend) { |
938 ack_queued_ = true; | 944 ack_queued_ = true; |
939 } | 945 } |
940 | 946 |
941 // Determine whether the newly received packet was missing before recording | 947 // Determine whether the newly received packet was missing before recording |
942 // the received packet. | 948 // the received packet. |
943 // Ack decimation with reordering relies on the timer to send an ack, but if | 949 // Ack decimation with reordering relies on the timer to send an ack, but if |
944 // missing packets we reported in the previous ack, send an ack immediately. | 950 // missing packets we reported in the previous ack, send an ack immediately. |
945 if (was_missing && (ack_mode_ != ACK_DECIMATION_WITH_REORDERING || | 951 if (was_missing && (ack_mode_ != ACK_DECIMATION_WITH_REORDERING || |
946 last_ack_had_missing_packets_)) { | 952 last_ack_had_missing_packets_)) { |
947 ack_queued_ = true; | 953 ack_queued_ = true; |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 // TearDownLocalConnectionState does not send close packet, so no infinite | 1659 // TearDownLocalConnectionState does not send close packet, so no infinite |
1654 // loop here. | 1660 // loop here. |
1655 // TODO(ianswett): This is actually an internal error, not an | 1661 // TODO(ianswett): This is actually an internal error, not an |
1656 // encryption failure. | 1662 // encryption failure. |
1657 TearDownLocalConnectionState( | 1663 TearDownLocalConnectionState( |
1658 QUIC_ENCRYPTION_FAILURE, | 1664 QUIC_ENCRYPTION_FAILURE, |
1659 "Serialized packet does not have an encrypted buffer.", | 1665 "Serialized packet does not have an encrypted buffer.", |
1660 ConnectionCloseSource::FROM_SELF); | 1666 ConnectionCloseSource::FROM_SELF); |
1661 return; | 1667 return; |
1662 } | 1668 } |
| 1669 |
| 1670 if (version() > QUIC_VERSION_38) { |
| 1671 if (serialized_packet->retransmittable_frames.empty() && |
| 1672 serialized_packet->original_packet_number == 0) { |
| 1673 // Increment consecutive_num_packets_with_no_retransmittable_frames_ if |
| 1674 // this packet is a new transmission with no retransmittable frames. |
| 1675 ++consecutive_num_packets_with_no_retransmittable_frames_; |
| 1676 } else { |
| 1677 consecutive_num_packets_with_no_retransmittable_frames_ = 0; |
| 1678 } |
| 1679 } |
1663 SendOrQueuePacket(serialized_packet); | 1680 SendOrQueuePacket(serialized_packet); |
1664 } | 1681 } |
1665 | 1682 |
1666 void QuicConnection::OnUnrecoverableError(QuicErrorCode error, | 1683 void QuicConnection::OnUnrecoverableError(QuicErrorCode error, |
1667 const string& error_details, | 1684 const string& error_details, |
1668 ConnectionCloseSource source) { | 1685 ConnectionCloseSource source) { |
1669 // The packet creator or generator encountered an unrecoverable error: tear | 1686 // The packet creator or generator encountered an unrecoverable error: tear |
1670 // down local connection state immediately. | 1687 // down local connection state immediately. |
1671 TearDownLocalConnectionState(error, error_details, source); | 1688 TearDownLocalConnectionState(error, error_details, source); |
1672 } | 1689 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1742 | 1759 |
1743 void QuicConnection::SendAck() { | 1760 void QuicConnection::SendAck() { |
1744 ack_alarm_->Cancel(); | 1761 ack_alarm_->Cancel(); |
1745 ack_queued_ = false; | 1762 ack_queued_ = false; |
1746 stop_waiting_count_ = 0; | 1763 stop_waiting_count_ = 0; |
1747 num_retransmittable_packets_received_since_last_ack_sent_ = 0; | 1764 num_retransmittable_packets_received_since_last_ack_sent_ = 0; |
1748 last_ack_had_missing_packets_ = received_packet_manager_.HasMissingPackets(); | 1765 last_ack_had_missing_packets_ = received_packet_manager_.HasMissingPackets(); |
1749 num_packets_received_since_last_ack_sent_ = 0; | 1766 num_packets_received_since_last_ack_sent_ = 0; |
1750 | 1767 |
1751 packet_generator_.SetShouldSendAck(!no_stop_waiting_frames_); | 1768 packet_generator_.SetShouldSendAck(!no_stop_waiting_frames_); |
| 1769 if (consecutive_num_packets_with_no_retransmittable_frames_ < |
| 1770 kMaxConsecutiveNonRetransmittablePackets) { |
| 1771 return; |
| 1772 } |
| 1773 consecutive_num_packets_with_no_retransmittable_frames_ = 0; |
| 1774 if (packet_generator_.HasRetransmittableFrames()) { |
| 1775 // There is pending retransmittable frames. |
| 1776 return; |
| 1777 } |
| 1778 |
| 1779 visitor_->OnAckNeedsRetransmittableFrame(); |
| 1780 if (!packet_generator_.HasRetransmittableFrames()) { |
| 1781 // Visitor did not add a retransmittable frame, add a ping frame. |
| 1782 packet_generator_.AddControlFrame(QuicFrame(QuicPingFrame())); |
| 1783 } |
1752 } | 1784 } |
1753 | 1785 |
1754 void QuicConnection::OnRetransmissionTimeout() { | 1786 void QuicConnection::OnRetransmissionTimeout() { |
1755 DCHECK(sent_packet_manager_.HasUnackedPackets()); | 1787 DCHECK(sent_packet_manager_.HasUnackedPackets()); |
1756 | 1788 |
1757 if (close_connection_after_five_rtos_ && | 1789 if (close_connection_after_five_rtos_ && |
1758 sent_packet_manager_.GetConsecutiveRtoCount() >= 4) { | 1790 sent_packet_manager_.GetConsecutiveRtoCount() >= 4) { |
1759 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. | 1791 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. |
1760 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", | 1792 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", |
1761 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 1793 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2388 | 2420 |
2389 void QuicConnection::CheckIfApplicationLimited() { | 2421 void QuicConnection::CheckIfApplicationLimited() { |
2390 if (queued_packets_.empty() && | 2422 if (queued_packets_.empty() && |
2391 !sent_packet_manager_.HasPendingRetransmissions() && | 2423 !sent_packet_manager_.HasPendingRetransmissions() && |
2392 !visitor_->WillingAndAbleToWrite()) { | 2424 !visitor_->WillingAndAbleToWrite()) { |
2393 sent_packet_manager_.OnApplicationLimited(); | 2425 sent_packet_manager_.OnApplicationLimited(); |
2394 } | 2426 } |
2395 } | 2427 } |
2396 | 2428 |
2397 } // namespace net | 2429 } // namespace net |
OLD | NEW |