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 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const QuicPacketSequenceNumber kMaxPacketGap = 5000; | 49 const QuicPacketSequenceNumber kMaxPacketGap = 5000; |
50 | 50 |
51 // Limit the number of FEC groups to two. If we get enough out of order packets | 51 // Limit the number of FEC groups to two. If we get enough out of order packets |
52 // that this becomes limiting, we can revisit. | 52 // that this becomes limiting, we can revisit. |
53 const size_t kMaxFecGroups = 2; | 53 const size_t kMaxFecGroups = 2; |
54 | 54 |
55 // Limit the number of undecryptable packets we buffer in | 55 // Limit the number of undecryptable packets we buffer in |
56 // expectation of the CHLO/SHLO arriving. | 56 // expectation of the CHLO/SHLO arriving. |
57 const size_t kMaxUndecryptablePackets = 10; | 57 const size_t kMaxUndecryptablePackets = 10; |
58 | 58 |
| 59 // Maximum number of acks received before sending an ack in response. |
| 60 const size_t kMaxPacketsReceivedBeforeAckSend = 20; |
| 61 |
59 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) { | 62 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) { |
60 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a; | 63 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a; |
61 return delta <= kMaxPacketGap; | 64 return delta <= kMaxPacketGap; |
62 } | 65 } |
63 | 66 |
64 // An alarm that is scheduled to send an ack if a timeout occurs. | 67 // An alarm that is scheduled to send an ack if a timeout occurs. |
65 class AckAlarm : public QuicAlarm::Delegate { | 68 class AckAlarm : public QuicAlarm::Delegate { |
66 public: | 69 public: |
67 explicit AckAlarm(QuicConnection* connection) | 70 explicit AckAlarm(QuicConnection* connection) |
68 : connection_(connection) { | 71 : connection_(connection) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 peer_address_(address), | 188 peer_address_(address), |
186 migrating_peer_port_(0), | 189 migrating_peer_port_(0), |
187 last_packet_revived_(false), | 190 last_packet_revived_(false), |
188 last_size_(0), | 191 last_size_(0), |
189 last_decrypted_packet_level_(ENCRYPTION_NONE), | 192 last_decrypted_packet_level_(ENCRYPTION_NONE), |
190 largest_seen_packet_with_ack_(0), | 193 largest_seen_packet_with_ack_(0), |
191 largest_seen_packet_with_stop_waiting_(0), | 194 largest_seen_packet_with_stop_waiting_(0), |
192 pending_version_negotiation_packet_(false), | 195 pending_version_negotiation_packet_(false), |
193 received_packet_manager_(&stats_), | 196 received_packet_manager_(&stats_), |
194 ack_queued_(false), | 197 ack_queued_(false), |
| 198 num_packets_received_since_last_ack_sent_(0), |
195 stop_waiting_count_(0), | 199 stop_waiting_count_(0), |
196 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), | 200 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), |
197 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), | 201 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), |
198 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 202 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
199 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 203 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
200 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), | 204 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), |
201 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), | 205 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), |
202 packet_generator_(connection_id_, &framer_, random_generator_, this), | 206 packet_generator_(connection_id_, &framer_, random_generator_, this), |
203 idle_network_timeout_( | 207 idle_network_timeout_( |
204 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)), | 208 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)), |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 << last_congestion_frames_.size() << " congestions, " | 778 << last_congestion_frames_.size() << " congestions, " |
775 << last_stop_waiting_frames_.size() << " stop_waiting, " | 779 << last_stop_waiting_frames_.size() << " stop_waiting, " |
776 << last_rst_frames_.size() << " rsts, " | 780 << last_rst_frames_.size() << " rsts, " |
777 << last_goaway_frames_.size() << " goaways, " | 781 << last_goaway_frames_.size() << " goaways, " |
778 << last_window_update_frames_.size() << " window updates, " | 782 << last_window_update_frames_.size() << " window updates, " |
779 << last_blocked_frames_.size() << " blocked, " | 783 << last_blocked_frames_.size() << " blocked, " |
780 << last_ping_frames_.size() << " pings, " | 784 << last_ping_frames_.size() << " pings, " |
781 << last_close_frames_.size() << " closes, " | 785 << last_close_frames_.size() << " closes, " |
782 << "for " << last_header_.public_header.connection_id; | 786 << "for " << last_header_.public_header.connection_id; |
783 | 787 |
| 788 ++num_packets_received_since_last_ack_sent_; |
| 789 |
784 // Call MaybeQueueAck() before recording the received packet, since we want | 790 // Call MaybeQueueAck() before recording the received packet, since we want |
785 // to trigger an ack if the newly received packet was previously missing. | 791 // to trigger an ack if the newly received packet was previously missing. |
786 MaybeQueueAck(); | 792 MaybeQueueAck(); |
787 | 793 |
788 // Record received or revived packet to populate ack info correctly before | 794 // Record received or revived packet to populate ack info correctly before |
789 // processing stream frames, since the processing may result in a response | 795 // processing stream frames, since the processing may result in a response |
790 // packet with a bundled ack. | 796 // packet with a bundled ack. |
791 if (last_packet_revived_) { | 797 if (last_packet_revived_) { |
792 received_packet_manager_.RecordPacketRevived( | 798 received_packet_manager_.RecordPacketRevived( |
793 last_header_.packet_sequence_number); | 799 last_header_.packet_sequence_number); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 !last_rst_frames_.empty() || | 913 !last_rst_frames_.empty() || |
908 !last_window_update_frames_.empty() || | 914 !last_window_update_frames_.empty() || |
909 !last_blocked_frames_.empty() || | 915 !last_blocked_frames_.empty() || |
910 !last_ping_frames_.empty()) { | 916 !last_ping_frames_.empty()) { |
911 return true; | 917 return true; |
912 } | 918 } |
913 | 919 |
914 if (!last_ack_frames_.empty() && last_ack_frames_.back().is_truncated) { | 920 if (!last_ack_frames_.empty() && last_ack_frames_.back().is_truncated) { |
915 return true; | 921 return true; |
916 } | 922 } |
| 923 // Always send an ack every 20 packets in order to allow the peer to discard |
| 924 // information from the SentPacketManager and provide an RTT measurement. |
| 925 if (num_packets_received_since_last_ack_sent_ >= |
| 926 kMaxPacketsReceivedBeforeAckSend) { |
| 927 return true; |
| 928 } |
917 return false; | 929 return false; |
918 } | 930 } |
919 | 931 |
920 void QuicConnection::UpdateStopWaitingCount() { | 932 void QuicConnection::UpdateStopWaitingCount() { |
921 if (last_ack_frames_.empty()) { | 933 if (last_ack_frames_.empty()) { |
922 return; | 934 return; |
923 } | 935 } |
924 | 936 |
925 // If the peer is still waiting for a packet that we are no longer planning to | 937 // If the peer is still waiting for a packet that we are no longer planning to |
926 // send, send an ack to raise the high water mark. | 938 // send, send an ack to raise the high water mark. |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 // We should serialize handshake packets immediately to ensure that they | 1283 // We should serialize handshake packets immediately to ensure that they |
1272 // end up sent at the right encryption level. | 1284 // end up sent at the right encryption level. |
1273 if (handshake == IS_HANDSHAKE) { | 1285 if (handshake == IS_HANDSHAKE) { |
1274 return true; | 1286 return true; |
1275 } | 1287 } |
1276 | 1288 |
1277 return CanWrite(retransmittable); | 1289 return CanWrite(retransmittable); |
1278 } | 1290 } |
1279 | 1291 |
1280 bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) { | 1292 bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) { |
| 1293 if (!connected_) { |
| 1294 return false; |
| 1295 } |
| 1296 |
1281 if (writer_->IsWriteBlocked()) { | 1297 if (writer_->IsWriteBlocked()) { |
1282 visitor_->OnWriteBlocked(); | 1298 visitor_->OnWriteBlocked(); |
1283 return false; | 1299 return false; |
1284 } | 1300 } |
1285 | 1301 |
1286 QuicTime now = clock_->Now(); | 1302 QuicTime now = clock_->Now(); |
1287 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend( | 1303 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend( |
1288 now, retransmittable); | 1304 now, retransmittable); |
1289 if (delay.IsInfinite()) { | 1305 if (delay.IsInfinite()) { |
1290 send_alarm_->Cancel(); | 1306 send_alarm_->Cancel(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 DLOG(ERROR) << "Unable to send ping!?"; | 1563 DLOG(ERROR) << "Unable to send ping!?"; |
1548 } | 1564 } |
1549 } else { | 1565 } else { |
1550 packet_generator_.AddControlFrame(QuicFrame(new QuicPingFrame)); | 1566 packet_generator_.AddControlFrame(QuicFrame(new QuicPingFrame)); |
1551 } | 1567 } |
1552 } | 1568 } |
1553 | 1569 |
1554 void QuicConnection::SendAck() { | 1570 void QuicConnection::SendAck() { |
1555 ack_alarm_->Cancel(); | 1571 ack_alarm_->Cancel(); |
1556 stop_waiting_count_ = 0; | 1572 stop_waiting_count_ = 0; |
| 1573 num_packets_received_since_last_ack_sent_ = 0; |
1557 bool send_feedback = false; | 1574 bool send_feedback = false; |
1558 | 1575 |
1559 // Deprecating the Congestion Feedback Frame after QUIC_VERSION_22. | 1576 // Deprecating the Congestion Feedback Frame after QUIC_VERSION_22. |
1560 if (version() <= QUIC_VERSION_22) { | 1577 if (version() <= QUIC_VERSION_22) { |
1561 if (received_packet_manager_.GenerateCongestionFeedback( | 1578 if (received_packet_manager_.GenerateCongestionFeedback( |
1562 &outgoing_congestion_feedback_)) { | 1579 &outgoing_congestion_feedback_)) { |
1563 DVLOG(1) << ENDPOINT << "Sending feedback: " | 1580 DVLOG(1) << ENDPOINT << "Sending feedback: " |
1564 << outgoing_congestion_feedback_; | 1581 << outgoing_congestion_feedback_; |
1565 send_feedback = true; | 1582 send_feedback = true; |
1566 } | 1583 } |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 } | 2010 } |
1994 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2011 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { |
1995 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2012 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { |
1996 return true; | 2013 return true; |
1997 } | 2014 } |
1998 } | 2015 } |
1999 return false; | 2016 return false; |
2000 } | 2017 } |
2001 | 2018 |
2002 } // namespace net | 2019 } // namespace net |
OLD | NEW |