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> |
11 #include <iterator> | 11 #include <iterator> |
12 #include <limits> | 12 #include <limits> |
13 #include <memory> | 13 #include <memory> |
14 #include <set> | 14 #include <set> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "base/debug/stack_trace.h" | 17 #include "base/debug/stack_trace.h" |
18 #include "base/format_macros.h" | 18 #include "base/format_macros.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/quic/crypto/quic_decrypter.h" | 23 #include "net/quic/crypto/quic_decrypter.h" |
24 #include "net/quic/crypto/quic_encrypter.h" | 24 #include "net/quic/crypto/quic_encrypter.h" |
25 #include "net/quic/iovector.h" | 25 #include "net/quic/iovector.h" |
26 #include "net/quic/quic_bandwidth.h" | 26 #include "net/quic/quic_bandwidth.h" |
27 #include "net/quic/quic_config.h" | 27 #include "net/quic/quic_config.h" |
28 #include "net/quic/quic_fec_group.h" | 28 #include "net/quic/quic_fec_group.h" |
29 #include "net/quic/quic_flags.h" | 29 #include "net/quic/quic_flags.h" |
| 30 #include "net/quic/quic_packet_generator.h" |
30 #include "net/quic/quic_utils.h" | 31 #include "net/quic/quic_utils.h" |
31 | 32 |
32 using base::StringPiece; | 33 using base::StringPiece; |
33 using base::StringPrintf; | 34 using base::StringPrintf; |
34 using base::hash_map; | 35 using base::hash_map; |
35 using base::hash_set; | 36 using base::hash_set; |
36 using std::list; | 37 using std::list; |
37 using std::make_pair; | 38 using std::make_pair; |
38 using std::max; | 39 using std::max; |
39 using std::min; | 40 using std::min; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 connection_->SendPing(); | 155 connection_->SendPing(); |
155 return QuicTime::Zero(); | 156 return QuicTime::Zero(); |
156 } | 157 } |
157 | 158 |
158 private: | 159 private: |
159 QuicConnection* connection_; | 160 QuicConnection* connection_; |
160 | 161 |
161 DISALLOW_COPY_AND_ASSIGN(PingAlarm); | 162 DISALLOW_COPY_AND_ASSIGN(PingAlarm); |
162 }; | 163 }; |
163 | 164 |
| 165 // This alarm may be scheduled when an FEC protected packet is sent out. |
| 166 class FecAlarm : public QuicAlarm::Delegate { |
| 167 public: |
| 168 explicit FecAlarm(QuicPacketGenerator* packet_generator) |
| 169 : packet_generator_(packet_generator) {} |
| 170 |
| 171 QuicTime OnAlarm() override { |
| 172 packet_generator_->OnFecTimeout(); |
| 173 return QuicTime::Zero(); |
| 174 } |
| 175 |
| 176 private: |
| 177 QuicPacketGenerator* packet_generator_; |
| 178 |
| 179 DISALLOW_COPY_AND_ASSIGN(FecAlarm); |
| 180 }; |
| 181 |
164 } // namespace | 182 } // namespace |
165 | 183 |
166 QuicConnection::QueuedPacket::QueuedPacket(SerializedPacket packet, | 184 QuicConnection::QueuedPacket::QueuedPacket(SerializedPacket packet, |
167 EncryptionLevel level) | 185 EncryptionLevel level) |
168 : serialized_packet(packet), | 186 : serialized_packet(packet), |
169 encryption_level(level), | 187 encryption_level(level), |
170 transmission_type(NOT_RETRANSMISSION), | 188 transmission_type(NOT_RETRANSMISSION), |
171 original_sequence_number(0) { | 189 original_sequence_number(0) { |
172 } | 190 } |
173 | 191 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 ack_queued_(false), | 237 ack_queued_(false), |
220 num_packets_received_since_last_ack_sent_(0), | 238 num_packets_received_since_last_ack_sent_(0), |
221 stop_waiting_count_(0), | 239 stop_waiting_count_(0), |
222 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), | 240 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), |
223 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), | 241 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), |
224 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 242 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
225 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 243 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
226 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), | 244 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), |
227 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), | 245 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), |
228 packet_generator_(connection_id_, &framer_, random_generator_, this), | 246 packet_generator_(connection_id_, &framer_, random_generator_, this), |
| 247 fec_alarm_(helper->CreateAlarm(new FecAlarm(&packet_generator_))), |
229 idle_network_timeout_(QuicTime::Delta::Infinite()), | 248 idle_network_timeout_(QuicTime::Delta::Infinite()), |
230 overall_connection_timeout_(QuicTime::Delta::Infinite()), | 249 overall_connection_timeout_(QuicTime::Delta::Infinite()), |
231 time_of_last_received_packet_(clock_->ApproximateNow()), | 250 time_of_last_received_packet_(clock_->ApproximateNow()), |
232 time_of_last_sent_new_packet_(clock_->ApproximateNow()), | 251 time_of_last_sent_new_packet_(clock_->ApproximateNow()), |
233 sequence_number_of_last_sent_packet_(0), | 252 sequence_number_of_last_sent_packet_(0), |
234 sent_packet_manager_( | 253 sent_packet_manager_( |
235 is_server, | 254 is_server, |
236 clock_, | 255 clock_, |
237 &stats_, | 256 &stats_, |
238 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, | 257 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 337 |
319 void QuicConnection::OnError(QuicFramer* framer) { | 338 void QuicConnection::OnError(QuicFramer* framer) { |
320 // Packets that we can not or have not decrypted are dropped. | 339 // Packets that we can not or have not decrypted are dropped. |
321 // TODO(rch): add stats to measure this. | 340 // TODO(rch): add stats to measure this. |
322 if (!connected_ || last_packet_decrypted_ == false) { | 341 if (!connected_ || last_packet_decrypted_ == false) { |
323 return; | 342 return; |
324 } | 343 } |
325 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); | 344 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); |
326 } | 345 } |
327 | 346 |
| 347 void QuicConnection::MaybeSetFecAlarm( |
| 348 QuicPacketSequenceNumber sequence_number) { |
| 349 if (fec_alarm_->IsSet()) { |
| 350 return; |
| 351 } |
| 352 QuicTime::Delta timeout = packet_generator_.GetFecTimeout(sequence_number); |
| 353 if (!timeout.IsInfinite()) { |
| 354 fec_alarm_->Set(clock_->ApproximateNow().Add(timeout)); |
| 355 } |
| 356 } |
| 357 |
328 void QuicConnection::OnPacket() { | 358 void QuicConnection::OnPacket() { |
329 DCHECK(last_stream_frames_.empty() && | 359 DCHECK(last_stream_frames_.empty() && |
330 last_ack_frames_.empty() && | 360 last_ack_frames_.empty() && |
331 last_congestion_frames_.empty() && | |
332 last_stop_waiting_frames_.empty() && | 361 last_stop_waiting_frames_.empty() && |
333 last_rst_frames_.empty() && | 362 last_rst_frames_.empty() && |
334 last_goaway_frames_.empty() && | 363 last_goaway_frames_.empty() && |
335 last_window_update_frames_.empty() && | 364 last_window_update_frames_.empty() && |
336 last_blocked_frames_.empty() && | 365 last_blocked_frames_.empty() && |
337 last_ping_frames_.empty() && | 366 last_ping_frames_.empty() && |
338 last_close_frames_.empty()); | 367 last_close_frames_.empty()); |
339 last_packet_decrypted_ = false; | 368 last_packet_decrypted_ = false; |
340 last_packet_revived_ = false; | 369 last_packet_revived_ = false; |
341 } | 370 } |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 } | 649 } |
621 | 650 |
622 void QuicConnection::ProcessStopWaitingFrame( | 651 void QuicConnection::ProcessStopWaitingFrame( |
623 const QuicStopWaitingFrame& stop_waiting) { | 652 const QuicStopWaitingFrame& stop_waiting) { |
624 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; | 653 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; |
625 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); | 654 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); |
626 // Possibly close any FecGroups which are now irrelevant. | 655 // Possibly close any FecGroups which are now irrelevant. |
627 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); | 656 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); |
628 } | 657 } |
629 | 658 |
630 bool QuicConnection::OnCongestionFeedbackFrame( | |
631 const QuicCongestionFeedbackFrame& feedback) { | |
632 DCHECK(connected_); | |
633 if (debug_visitor_.get() != nullptr) { | |
634 debug_visitor_->OnCongestionFeedbackFrame(feedback); | |
635 } | |
636 last_congestion_frames_.push_back(feedback); | |
637 return connected_; | |
638 } | |
639 | |
640 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { | 659 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { |
641 DCHECK(connected_); | 660 DCHECK(connected_); |
642 | 661 |
643 if (last_header_.packet_sequence_number <= | 662 if (last_header_.packet_sequence_number <= |
644 largest_seen_packet_with_stop_waiting_) { | 663 largest_seen_packet_with_stop_waiting_) { |
645 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; | 664 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; |
646 return true; | 665 return true; |
647 } | 666 } |
648 | 667 |
649 if (!ValidateStopWaitingFrame(frame)) { | 668 if (!ValidateStopWaitingFrame(frame)) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 // Don't do anything if this packet closed the connection. | 840 // Don't do anything if this packet closed the connection. |
822 if (!connected_) { | 841 if (!connected_) { |
823 ClearLastFrames(); | 842 ClearLastFrames(); |
824 return; | 843 return; |
825 } | 844 } |
826 | 845 |
827 DVLOG(1) << ENDPOINT << (last_packet_revived_ ? "Revived" : "Got") | 846 DVLOG(1) << ENDPOINT << (last_packet_revived_ ? "Revived" : "Got") |
828 << " packet " << last_header_.packet_sequence_number | 847 << " packet " << last_header_.packet_sequence_number |
829 << " with " << last_stream_frames_.size()<< " stream frames " | 848 << " with " << last_stream_frames_.size()<< " stream frames " |
830 << last_ack_frames_.size() << " acks, " | 849 << last_ack_frames_.size() << " acks, " |
831 << last_congestion_frames_.size() << " congestions, " | |
832 << last_stop_waiting_frames_.size() << " stop_waiting, " | 850 << last_stop_waiting_frames_.size() << " stop_waiting, " |
833 << last_rst_frames_.size() << " rsts, " | 851 << last_rst_frames_.size() << " rsts, " |
834 << last_goaway_frames_.size() << " goaways, " | 852 << last_goaway_frames_.size() << " goaways, " |
835 << last_window_update_frames_.size() << " window updates, " | 853 << last_window_update_frames_.size() << " window updates, " |
836 << last_blocked_frames_.size() << " blocked, " | 854 << last_blocked_frames_.size() << " blocked, " |
837 << last_ping_frames_.size() << " pings, " | 855 << last_ping_frames_.size() << " pings, " |
838 << last_close_frames_.size() << " closes, " | 856 << last_close_frames_.size() << " closes, " |
839 << "for " << last_header_.public_header.connection_id; | 857 << "for " << last_header_.public_header.connection_id; |
840 | 858 |
841 ++num_packets_received_since_last_ack_sent_; | 859 ++num_packets_received_since_last_ack_sent_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 } | 892 } |
875 for (size_t i = 0; i < last_goaway_frames_.size(); ++i) { | 893 for (size_t i = 0; i < last_goaway_frames_.size(); ++i) { |
876 visitor_->OnGoAway(last_goaway_frames_[i]); | 894 visitor_->OnGoAway(last_goaway_frames_[i]); |
877 } | 895 } |
878 for (size_t i = 0; i < last_rst_frames_.size(); ++i) { | 896 for (size_t i = 0; i < last_rst_frames_.size(); ++i) { |
879 visitor_->OnRstStream(last_rst_frames_[i]); | 897 visitor_->OnRstStream(last_rst_frames_[i]); |
880 } | 898 } |
881 for (size_t i = 0; i < last_ack_frames_.size(); ++i) { | 899 for (size_t i = 0; i < last_ack_frames_.size(); ++i) { |
882 ProcessAckFrame(last_ack_frames_[i]); | 900 ProcessAckFrame(last_ack_frames_[i]); |
883 } | 901 } |
884 for (size_t i = 0; i < last_congestion_frames_.size(); ++i) { | |
885 sent_packet_manager_.OnIncomingQuicCongestionFeedbackFrame( | |
886 last_congestion_frames_[i], time_of_last_received_packet_); | |
887 } | |
888 for (size_t i = 0; i < last_stop_waiting_frames_.size(); ++i) { | 902 for (size_t i = 0; i < last_stop_waiting_frames_.size(); ++i) { |
889 ProcessStopWaitingFrame(last_stop_waiting_frames_[i]); | 903 ProcessStopWaitingFrame(last_stop_waiting_frames_[i]); |
890 } | 904 } |
891 if (!last_close_frames_.empty()) { | 905 if (!last_close_frames_.empty()) { |
892 CloseConnection(last_close_frames_[0].error_code, true); | 906 CloseConnection(last_close_frames_[0].error_code, true); |
893 DCHECK(!connected_); | 907 DCHECK(!connected_); |
894 } | 908 } |
895 | 909 |
896 // If there are new missing packets to report, send an ack immediately. | 910 // If there are new missing packets to report, send an ack immediately. |
897 if (received_packet_manager_.HasNewMissingPackets()) { | 911 if (received_packet_manager_.HasNewMissingPackets()) { |
(...skipping 23 matching lines...) Expand all Loading... |
921 } | 935 } |
922 | 936 |
923 if (ack_queued_) { | 937 if (ack_queued_) { |
924 ack_alarm_->Cancel(); | 938 ack_alarm_->Cancel(); |
925 } | 939 } |
926 } | 940 } |
927 | 941 |
928 void QuicConnection::ClearLastFrames() { | 942 void QuicConnection::ClearLastFrames() { |
929 last_stream_frames_.clear(); | 943 last_stream_frames_.clear(); |
930 last_ack_frames_.clear(); | 944 last_ack_frames_.clear(); |
931 last_congestion_frames_.clear(); | |
932 last_stop_waiting_frames_.clear(); | 945 last_stop_waiting_frames_.clear(); |
933 last_rst_frames_.clear(); | 946 last_rst_frames_.clear(); |
934 last_goaway_frames_.clear(); | 947 last_goaway_frames_.clear(); |
935 last_window_update_frames_.clear(); | 948 last_window_update_frames_.clear(); |
936 last_blocked_frames_.clear(); | 949 last_blocked_frames_.clear(); |
937 last_ping_frames_.clear(); | 950 last_ping_frames_.clear(); |
938 last_close_frames_.clear(); | 951 last_close_frames_.clear(); |
939 } | 952 } |
940 | 953 |
941 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() { | 954 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() { |
(...skipping 15 matching lines...) Expand all Loading... |
957 } | 970 } |
958 | 971 |
959 QuicAckFrame* QuicConnection::CreateAckFrame() { | 972 QuicAckFrame* QuicConnection::CreateAckFrame() { |
960 QuicAckFrame* outgoing_ack = new QuicAckFrame(); | 973 QuicAckFrame* outgoing_ack = new QuicAckFrame(); |
961 received_packet_manager_.UpdateReceivedPacketInfo( | 974 received_packet_manager_.UpdateReceivedPacketInfo( |
962 outgoing_ack, clock_->ApproximateNow()); | 975 outgoing_ack, clock_->ApproximateNow()); |
963 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; | 976 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; |
964 return outgoing_ack; | 977 return outgoing_ack; |
965 } | 978 } |
966 | 979 |
967 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() { | |
968 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_); | |
969 } | |
970 | |
971 QuicStopWaitingFrame* QuicConnection::CreateStopWaitingFrame() { | 980 QuicStopWaitingFrame* QuicConnection::CreateStopWaitingFrame() { |
972 QuicStopWaitingFrame stop_waiting; | 981 QuicStopWaitingFrame stop_waiting; |
973 UpdateStopWaiting(&stop_waiting); | 982 UpdateStopWaiting(&stop_waiting); |
974 return new QuicStopWaitingFrame(stop_waiting); | 983 return new QuicStopWaitingFrame(stop_waiting); |
975 } | 984 } |
976 | 985 |
977 bool QuicConnection::ShouldLastPacketInstigateAck() const { | 986 bool QuicConnection::ShouldLastPacketInstigateAck() const { |
978 if (!last_stream_frames_.empty() || | 987 if (!last_stream_frames_.empty() || |
979 !last_goaway_frames_.empty() || | 988 !last_goaway_frames_.empty() || |
980 !last_rst_frames_.empty() || | 989 !last_rst_frames_.empty() || |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 | 1071 |
1063 QuicConsumedData QuicConnection::SendStreamData( | 1072 QuicConsumedData QuicConnection::SendStreamData( |
1064 QuicStreamId id, | 1073 QuicStreamId id, |
1065 const IOVector& data, | 1074 const IOVector& data, |
1066 QuicStreamOffset offset, | 1075 QuicStreamOffset offset, |
1067 bool fin, | 1076 bool fin, |
1068 FecProtection fec_protection, | 1077 FecProtection fec_protection, |
1069 QuicAckNotifier::DelegateInterface* delegate) { | 1078 QuicAckNotifier::DelegateInterface* delegate) { |
1070 if (!fin && data.Empty()) { | 1079 if (!fin && data.Empty()) { |
1071 LOG(DFATAL) << "Attempt to send empty stream frame"; | 1080 LOG(DFATAL) << "Attempt to send empty stream frame"; |
1072 if (FLAGS_quic_empty_data_no_fin_early_return) { | 1081 return QuicConsumedData(0, false); |
1073 return QuicConsumedData(0, false); | |
1074 } | |
1075 } | 1082 } |
1076 | 1083 |
1077 // Opportunistically bundle an ack with every outgoing packet. | 1084 // Opportunistically bundle an ack with every outgoing packet. |
1078 // Particularly, we want to bundle with handshake packets since we don't know | 1085 // Particularly, we want to bundle with handshake packets since we don't know |
1079 // which decrypter will be used on an ack packet following a handshake | 1086 // which decrypter will be used on an ack packet following a handshake |
1080 // packet (a handshake packet from client to server could result in a REJ or a | 1087 // packet (a handshake packet from client to server could result in a REJ or a |
1081 // SHLO from the server, leading to two different decrypters at the server.) | 1088 // SHLO from the server, leading to two different decrypters at the server.) |
1082 // | 1089 // |
1083 // TODO(jri): Note that ConsumeData may cause a response packet to be sent. | 1090 // TODO(jri): Note that ConsumeData may cause a response packet to be sent. |
1084 // We may end up sending stale ack information if there are undecryptable | 1091 // We may end up sending stale ack information if there are undecryptable |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 packet->original_sequence_number, | 1499 packet->original_sequence_number, |
1493 packet->encryption_level, | 1500 packet->encryption_level, |
1494 packet->transmission_type, | 1501 packet->transmission_type, |
1495 *encrypted, | 1502 *encrypted, |
1496 packet_send_time); | 1503 packet_send_time); |
1497 } | 1504 } |
1498 if (packet->transmission_type == NOT_RETRANSMISSION) { | 1505 if (packet->transmission_type == NOT_RETRANSMISSION) { |
1499 time_of_last_sent_new_packet_ = packet_send_time; | 1506 time_of_last_sent_new_packet_ = packet_send_time; |
1500 } | 1507 } |
1501 SetPingAlarm(); | 1508 SetPingAlarm(); |
| 1509 MaybeSetFecAlarm(sequence_number); |
1502 DVLOG(1) << ENDPOINT << "time " | 1510 DVLOG(1) << ENDPOINT << "time " |
1503 << (FLAGS_quic_record_send_time_before_write ? | 1511 << (FLAGS_quic_record_send_time_before_write ? |
1504 "we began writing " : "we finished writing ") | 1512 "we began writing " : "we finished writing ") |
1505 << "last sent packet: " | 1513 << "last sent packet: " |
1506 << packet_send_time.ToDebuggingValue(); | 1514 << packet_send_time.ToDebuggingValue(); |
1507 | 1515 |
1508 // TODO(ianswett): Change the sequence number length and other packet creator | 1516 // TODO(ianswett): Change the sequence number length and other packet creator |
1509 // options by a more explicit API than setting a struct value directly, | 1517 // options by a more explicit API than setting a struct value directly, |
1510 // perhaps via the NetworkChangeVisitor. | 1518 // perhaps via the NetworkChangeVisitor. |
1511 packet_generator_.UpdateSequenceNumberLength( | 1519 packet_generator_.UpdateSequenceNumberLength( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1586 // forward security, start using the forward-secure encrypter. | 1594 // forward security, start using the forward-secure encrypter. |
1587 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && | 1595 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && |
1588 has_forward_secure_encrypter_ && | 1596 has_forward_secure_encrypter_ && |
1589 serialized_packet.sequence_number >= | 1597 serialized_packet.sequence_number >= |
1590 first_required_forward_secure_packet_) { | 1598 first_required_forward_secure_packet_) { |
1591 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | 1599 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); |
1592 } | 1600 } |
1593 if (serialized_packet.retransmittable_frames) { | 1601 if (serialized_packet.retransmittable_frames) { |
1594 serialized_packet.retransmittable_frames-> | 1602 serialized_packet.retransmittable_frames-> |
1595 set_encryption_level(encryption_level_); | 1603 set_encryption_level(encryption_level_); |
| 1604 |
| 1605 if (FLAGS_quic_ack_notifier_informed_on_serialized) { |
| 1606 sent_packet_manager_.OnSerializedPacket(serialized_packet); |
| 1607 } |
| 1608 } |
| 1609 if (serialized_packet.packet->is_fec_packet() && fec_alarm_->IsSet()) { |
| 1610 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. |
| 1611 fec_alarm_->Cancel(); |
1596 } | 1612 } |
1597 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_)); | 1613 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_)); |
1598 } | 1614 } |
1599 | 1615 |
1600 void QuicConnection::OnCongestionWindowChange() { | 1616 void QuicConnection::OnCongestionWindowChange() { |
1601 packet_generator_.OnCongestionWindowChange( | 1617 packet_generator_.OnCongestionWindowChange( |
1602 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); | 1618 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); |
1603 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); | 1619 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); |
1604 } | 1620 } |
1605 | 1621 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 if (retransmission_alarm_->IsSet()) { | 1665 if (retransmission_alarm_->IsSet()) { |
1650 return; | 1666 return; |
1651 } | 1667 } |
1652 packet_generator_.AddControlFrame(QuicFrame(new QuicPingFrame)); | 1668 packet_generator_.AddControlFrame(QuicFrame(new QuicPingFrame)); |
1653 } | 1669 } |
1654 | 1670 |
1655 void QuicConnection::SendAck() { | 1671 void QuicConnection::SendAck() { |
1656 ack_alarm_->Cancel(); | 1672 ack_alarm_->Cancel(); |
1657 stop_waiting_count_ = 0; | 1673 stop_waiting_count_ = 0; |
1658 num_packets_received_since_last_ack_sent_ = 0; | 1674 num_packets_received_since_last_ack_sent_ = 0; |
1659 bool send_feedback = false; | |
1660 | 1675 |
1661 // Deprecating the Congestion Feedback Frame after QUIC_VERSION_22. | 1676 packet_generator_.SetShouldSendAck(true); |
1662 if (version() <= QUIC_VERSION_22) { | |
1663 if (received_packet_manager_.GenerateCongestionFeedback( | |
1664 &outgoing_congestion_feedback_)) { | |
1665 DVLOG(1) << ENDPOINT << "Sending feedback: " | |
1666 << outgoing_congestion_feedback_; | |
1667 send_feedback = true; | |
1668 } | |
1669 } | |
1670 | |
1671 packet_generator_.SetShouldSendAck(send_feedback, true); | |
1672 } | 1677 } |
1673 | 1678 |
1674 void QuicConnection::OnRetransmissionTimeout() { | 1679 void QuicConnection::OnRetransmissionTimeout() { |
1675 if (!sent_packet_manager_.HasUnackedPackets()) { | 1680 if (!sent_packet_manager_.HasUnackedPackets()) { |
1676 return; | 1681 return; |
1677 } | 1682 } |
1678 | 1683 |
1679 sent_packet_manager_.OnRetransmissionTimeout(); | 1684 sent_packet_manager_.OnRetransmissionTimeout(); |
1680 WriteIfNotBlocked(); | 1685 WriteIfNotBlocked(); |
1681 | 1686 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1885 } | 1890 } |
1886 connected_ = false; | 1891 connected_ = false; |
1887 if (debug_visitor_.get() != nullptr) { | 1892 if (debug_visitor_.get() != nullptr) { |
1888 debug_visitor_->OnConnectionClosed(error, from_peer); | 1893 debug_visitor_->OnConnectionClosed(error, from_peer); |
1889 } | 1894 } |
1890 visitor_->OnConnectionClosed(error, from_peer); | 1895 visitor_->OnConnectionClosed(error, from_peer); |
1891 // Cancel the alarms so they don't trigger any action now that the | 1896 // Cancel the alarms so they don't trigger any action now that the |
1892 // connection is closed. | 1897 // connection is closed. |
1893 ack_alarm_->Cancel(); | 1898 ack_alarm_->Cancel(); |
1894 ping_alarm_->Cancel(); | 1899 ping_alarm_->Cancel(); |
| 1900 fec_alarm_->Cancel(); |
1895 resume_writes_alarm_->Cancel(); | 1901 resume_writes_alarm_->Cancel(); |
1896 retransmission_alarm_->Cancel(); | 1902 retransmission_alarm_->Cancel(); |
1897 send_alarm_->Cancel(); | 1903 send_alarm_->Cancel(); |
1898 timeout_alarm_->Cancel(); | 1904 timeout_alarm_->Cancel(); |
1899 } | 1905 } |
1900 | 1906 |
1901 void QuicConnection::SendGoAway(QuicErrorCode error, | 1907 void QuicConnection::SendGoAway(QuicErrorCode error, |
1902 QuicStreamId last_good_stream_id, | 1908 QuicStreamId last_good_stream_id, |
1903 const string& reason) { | 1909 const string& reason) { |
1904 DVLOG(1) << ENDPOINT << "Going away with error " | 1910 DVLOG(1) << ENDPOINT << "Going away with error " |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2107 } | 2113 } |
2108 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2114 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { |
2109 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2115 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { |
2110 return true; | 2116 return true; |
2111 } | 2117 } |
2112 } | 2118 } |
2113 return false; | 2119 return false; |
2114 } | 2120 } |
2115 | 2121 |
2116 } // namespace net | 2122 } // namespace net |
OLD | NEW |