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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 ping_alarm_( | 249 ping_alarm_( |
250 alarm_factory_->CreateAlarm(arena_.New<PingAlarmDelegate>(this), | 250 alarm_factory_->CreateAlarm(arena_.New<PingAlarmDelegate>(this), |
251 &arena_)), | 251 &arena_)), |
252 mtu_discovery_alarm_(alarm_factory_->CreateAlarm( | 252 mtu_discovery_alarm_(alarm_factory_->CreateAlarm( |
253 arena_.New<MtuDiscoveryAlarmDelegate>(this), | 253 arena_.New<MtuDiscoveryAlarmDelegate>(this), |
254 &arena_)), | 254 &arena_)), |
255 visitor_(nullptr), | 255 visitor_(nullptr), |
256 debug_visitor_(nullptr), | 256 debug_visitor_(nullptr), |
257 packet_generator_(connection_id_, | 257 packet_generator_(connection_id_, |
258 &framer_, | 258 &framer_, |
259 random_generator_, | |
260 helper->GetBufferAllocator(), | 259 helper->GetBufferAllocator(), |
261 this), | 260 this), |
262 idle_network_timeout_(QuicTime::Delta::Infinite()), | 261 idle_network_timeout_(QuicTime::Delta::Infinite()), |
263 handshake_timeout_(QuicTime::Delta::Infinite()), | 262 handshake_timeout_(QuicTime::Delta::Infinite()), |
264 time_of_last_received_packet_(clock_->ApproximateNow()), | 263 time_of_last_received_packet_(clock_->ApproximateNow()), |
265 time_of_last_sent_new_packet_(clock_->ApproximateNow()), | 264 time_of_last_sent_new_packet_(clock_->ApproximateNow()), |
266 last_send_for_timeout_(clock_->ApproximateNow()), | 265 last_send_for_timeout_(clock_->ApproximateNow()), |
267 packet_number_of_last_sent_packet_(0), | 266 packet_number_of_last_sent_packet_(0), |
268 sent_packet_manager_(new QuicSentPacketManager( | 267 sent_packet_manager_(new QuicSentPacketManager( |
269 perspective, | 268 perspective, |
(...skipping 12 matching lines...) Expand all Loading... |
282 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), | 281 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), |
283 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), | 282 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), |
284 largest_received_packet_size_(0), | 283 largest_received_packet_size_(0), |
285 goaway_sent_(false), | 284 goaway_sent_(false), |
286 goaway_received_(false), | 285 goaway_received_(false), |
287 multipath_enabled_(false), | 286 multipath_enabled_(false), |
288 write_error_occured_(false) { | 287 write_error_occured_(false) { |
289 DVLOG(1) << ENDPOINT | 288 DVLOG(1) << ENDPOINT |
290 << "Created connection with connection_id: " << connection_id; | 289 << "Created connection with connection_id: " << connection_id; |
291 framer_.set_visitor(this); | 290 framer_.set_visitor(this); |
292 framer_.set_received_entropy_calculator(&received_packet_manager_); | |
293 if (!FLAGS_quic_receive_packet_once_decrypted) { | 291 if (!FLAGS_quic_receive_packet_once_decrypted) { |
294 last_stop_waiting_frame_.least_unacked = 0; | 292 last_stop_waiting_frame_.least_unacked = 0; |
295 } | 293 } |
296 stats_.connection_creation_time = clock_->ApproximateNow(); | 294 stats_.connection_creation_time = clock_->ApproximateNow(); |
297 if (FLAGS_quic_enable_multipath) { | 295 if (FLAGS_quic_enable_multipath) { |
298 sent_packet_manager_.reset(new QuicMultipathSentPacketManager( | 296 sent_packet_manager_.reset(new QuicMultipathSentPacketManager( |
299 sent_packet_manager_.release(), this)); | 297 sent_packet_manager_.release(), this)); |
300 } | 298 } |
301 // TODO(ianswett): Supply the NetworkChangeVisitor as a constructor argument | 299 // TODO(ianswett): Supply the NetworkChangeVisitor as a constructor argument |
302 // and make it required non-null, because it's always used. | 300 // and make it required non-null, because it's always used. |
303 sent_packet_manager_->SetNetworkChangeVisitor(this); | 301 sent_packet_manager_->SetNetworkChangeVisitor(this); |
304 // Allow the packet writer to potentially reduce the packet size to a value | 302 // Allow the packet writer to potentially reduce the packet size to a value |
305 // even smaller than kDefaultMaxPacketSize. | 303 // even smaller than kDefaultMaxPacketSize. |
306 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER | 304 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER |
307 ? kDefaultServerMaxPacketSize | 305 ? kDefaultServerMaxPacketSize |
308 : kDefaultMaxPacketSize); | 306 : kDefaultMaxPacketSize); |
309 received_packet_manager_.SetVersion(version()); | |
310 } | 307 } |
311 | 308 |
312 QuicConnection::~QuicConnection() { | 309 QuicConnection::~QuicConnection() { |
313 if (owns_writer_) { | 310 if (owns_writer_) { |
314 delete writer_; | 311 delete writer_; |
315 } | 312 } |
316 ClearQueuedPackets(); | 313 ClearQueuedPackets(); |
317 } | 314 } |
318 | 315 |
319 void QuicConnection::ClearQueuedPackets() { | 316 void QuicConnection::ClearQueuedPackets() { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 case NEGOTIATED_VERSION: | 490 case NEGOTIATED_VERSION: |
494 // Might be old packets that were sent by the client before the version | 491 // Might be old packets that were sent by the client before the version |
495 // was negotiated. Drop these. | 492 // was negotiated. Drop these. |
496 return false; | 493 return false; |
497 | 494 |
498 default: | 495 default: |
499 DCHECK(false); | 496 DCHECK(false); |
500 } | 497 } |
501 | 498 |
502 version_negotiation_state_ = NEGOTIATED_VERSION; | 499 version_negotiation_state_ = NEGOTIATED_VERSION; |
503 received_packet_manager_.SetVersion(received_version); | |
504 visitor_->OnSuccessfulVersionNegotiation(received_version); | 500 visitor_->OnSuccessfulVersionNegotiation(received_version); |
505 if (debug_visitor_ != nullptr) { | 501 if (debug_visitor_ != nullptr) { |
506 debug_visitor_->OnSuccessfulVersionNegotiation(received_version); | 502 debug_visitor_->OnSuccessfulVersionNegotiation(received_version); |
507 } | 503 } |
508 DVLOG(1) << ENDPOINT << "version negotiated " << received_version; | 504 DVLOG(1) << ENDPOINT << "version negotiated " << received_version; |
509 | 505 |
510 // Store the new version. | 506 // Store the new version. |
511 framer_.set_version(received_version); | 507 framer_.set_version(received_version); |
512 | 508 |
513 // TODO(satyamshekhar): Store the packet number of this packet and close the | 509 // TODO(satyamshekhar): Store the packet number of this packet and close the |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 "No common version found. Supported versions: {" + | 552 "No common version found. Supported versions: {" + |
557 QuicVersionVectorToString(framer_.supported_versions()) + | 553 QuicVersionVectorToString(framer_.supported_versions()) + |
558 "}, peer supported versions: {" + | 554 "}, peer supported versions: {" + |
559 QuicVersionVectorToString(packet.versions) + "}", | 555 QuicVersionVectorToString(packet.versions) + "}", |
560 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 556 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
561 return; | 557 return; |
562 } | 558 } |
563 | 559 |
564 DVLOG(1) << ENDPOINT | 560 DVLOG(1) << ENDPOINT |
565 << "Negotiated version: " << QuicVersionToString(version()); | 561 << "Negotiated version: " << QuicVersionToString(version()); |
566 received_packet_manager_.SetVersion(version()); | |
567 server_supported_versions_ = packet.versions; | 562 server_supported_versions_ = packet.versions; |
568 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; | 563 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; |
569 RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); | 564 RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); |
570 } | 565 } |
571 | 566 |
572 bool QuicConnection::OnUnauthenticatedPublicHeader( | 567 bool QuicConnection::OnUnauthenticatedPublicHeader( |
573 const QuicPacketPublicHeader& header) { | 568 const QuicPacketPublicHeader& header) { |
574 if (header.connection_id == connection_id_) { | 569 if (header.connection_id == connection_id_) { |
575 return true; | 570 return true; |
576 } | 571 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 if (error != nullptr) { | 720 if (error != nullptr) { |
726 CloseConnection(QUIC_INVALID_ACK_DATA, error, | 721 CloseConnection(QUIC_INVALID_ACK_DATA, error, |
727 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 722 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
728 return false; | 723 return false; |
729 } | 724 } |
730 | 725 |
731 if (send_alarm_->IsSet()) { | 726 if (send_alarm_->IsSet()) { |
732 send_alarm_->Cancel(); | 727 send_alarm_->Cancel(); |
733 } | 728 } |
734 ProcessAckFrame(incoming_ack); | 729 ProcessAckFrame(incoming_ack); |
735 if (incoming_ack.is_truncated) { | |
736 should_last_packet_instigate_acks_ = true; | |
737 } | |
738 // If the incoming ack's packets set expresses missing packets: peer is still | 730 // If the incoming ack's packets set expresses missing packets: peer is still |
739 // waiting for a packet lower than a packet that we are no longer planning to | 731 // waiting for a packet lower than a packet that we are no longer planning to |
740 // send. | 732 // send. |
741 // If the incoming ack's packets set expresses received packets: peer is still | 733 // If the incoming ack's packets set expresses received packets: peer is still |
742 // acking packets which we never care about. | 734 // acking packets which we never care about. |
743 // Send an ack to raise the high water mark. | 735 // Send an ack to raise the high water mark. |
744 if (!incoming_ack.packets.Empty() && | 736 if (!incoming_ack.packets.Empty() && |
745 GetLeastUnacked(incoming_ack.path_id) > incoming_ack.packets.Min()) { | 737 GetLeastUnacked(incoming_ack.path_id) > incoming_ack.packets.Min()) { |
746 ++stop_waiting_count_; | 738 ++stop_waiting_count_; |
747 } else { | 739 } else { |
748 stop_waiting_count_ = 0; | 740 stop_waiting_count_ = 0; |
749 } | 741 } |
750 | 742 |
751 return connected_; | 743 return connected_; |
752 } | 744 } |
753 | 745 |
754 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { | 746 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { |
755 largest_seen_packet_with_ack_ = last_header_.packet_number; | 747 largest_seen_packet_with_ack_ = last_header_.packet_number; |
756 sent_packet_manager_->OnIncomingAck(incoming_ack, | 748 sent_packet_manager_->OnIncomingAck(incoming_ack, |
757 time_of_last_received_packet_); | 749 time_of_last_received_packet_); |
758 if (version() <= QUIC_VERSION_33) { | |
759 sent_entropy_manager_.ClearEntropyBefore( | |
760 sent_packet_manager_->GetLeastPacketAwaitedByPeer( | |
761 incoming_ack.path_id) - | |
762 1); | |
763 } | |
764 // Always reset the retransmission alarm when an ack comes in, since we now | 750 // Always reset the retransmission alarm when an ack comes in, since we now |
765 // have a better estimate of the current rtt than when it was set. | 751 // have a better estimate of the current rtt than when it was set. |
766 SetRetransmissionAlarm(); | 752 SetRetransmissionAlarm(); |
767 } | 753 } |
768 | 754 |
769 void QuicConnection::ProcessStopWaitingFrame( | 755 void QuicConnection::ProcessStopWaitingFrame( |
770 const QuicStopWaitingFrame& stop_waiting) { | 756 const QuicStopWaitingFrame& stop_waiting) { |
771 largest_seen_packet_with_stop_waiting_ = last_header_.packet_number; | 757 largest_seen_packet_with_stop_waiting_ = last_header_.packet_number; |
772 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); | 758 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); |
773 } | 759 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 << incoming_ack.largest_observed << " vs " | 817 << incoming_ack.largest_observed << " vs " |
832 << sent_packet_manager_->GetLargestObserved(incoming_ack.path_id) | 818 << sent_packet_manager_->GetLargestObserved(incoming_ack.path_id) |
833 << " packet_number:" << last_header_.packet_number | 819 << " packet_number:" << last_header_.packet_number |
834 << " largest seen with ack:" << largest_seen_packet_with_ack_ | 820 << " largest seen with ack:" << largest_seen_packet_with_ack_ |
835 << " connection_id: " << connection_id_; | 821 << " connection_id: " << connection_id_; |
836 // A new ack has a diminished largest_observed value. Error out. | 822 // A new ack has a diminished largest_observed value. Error out. |
837 // If this was an old packet, we wouldn't even have checked. | 823 // If this was an old packet, we wouldn't even have checked. |
838 return "Largest observed too low."; | 824 return "Largest observed too low."; |
839 } | 825 } |
840 | 826 |
841 if (version() <= QUIC_VERSION_33) { | 827 if (!incoming_ack.packets.Empty() && |
842 if (!incoming_ack.packets.Empty() && | 828 incoming_ack.packets.Max() != incoming_ack.largest_observed) { |
843 incoming_ack.packets.Max() > incoming_ack.largest_observed) { | 829 QUIC_BUG << ENDPOINT |
844 LOG(WARNING) << ENDPOINT | 830 << "Peer last received packet: " << incoming_ack.packets.Max() |
845 << "Peer sent missing packet: " << incoming_ack.packets.Max() | 831 << " which is not equal to largest observed: " |
846 << " which is greater than largest observed: " | 832 << incoming_ack.largest_observed; |
847 << incoming_ack.largest_observed; | 833 return "Last received packet not equal to largest observed."; |
848 return "Missing packet higher than largest observed."; | |
849 } | |
850 | |
851 if (!incoming_ack.packets.Empty() && | |
852 incoming_ack.packets.Min() < | |
853 sent_packet_manager_->GetLeastPacketAwaitedByPeer( | |
854 incoming_ack.path_id)) { | |
855 LOG(WARNING) << ENDPOINT | |
856 << "Peer sent missing packet: " << incoming_ack.packets.Min() | |
857 << " which is smaller than least_packet_awaited_by_peer_: " | |
858 << sent_packet_manager_->GetLeastPacketAwaitedByPeer( | |
859 incoming_ack.path_id); | |
860 return "Missing packet smaller than least awaited."; | |
861 } | |
862 if (!sent_entropy_manager_.IsValidEntropy(incoming_ack.largest_observed, | |
863 incoming_ack.packets, | |
864 incoming_ack.entropy_hash)) { | |
865 DLOG(WARNING) << ENDPOINT << "Peer sent invalid entropy." | |
866 << " largest_observed:" << incoming_ack.largest_observed | |
867 << " last_received:" << last_header_.packet_number; | |
868 return "Invalid entropy."; | |
869 } | |
870 } else { | |
871 if (!incoming_ack.packets.Empty() && | |
872 incoming_ack.packets.Max() != incoming_ack.largest_observed) { | |
873 QUIC_BUG << ENDPOINT | |
874 << "Peer last received packet: " << incoming_ack.packets.Max() | |
875 << " which is not equal to largest observed: " | |
876 << incoming_ack.largest_observed; | |
877 return "Last received packet not equal to largest observed."; | |
878 } | |
879 } | 834 } |
880 | 835 |
881 return nullptr; | 836 return nullptr; |
882 } | 837 } |
883 | 838 |
884 const char* QuicConnection::ValidateStopWaitingFrame( | 839 const char* QuicConnection::ValidateStopWaitingFrame( |
885 const QuicStopWaitingFrame& stop_waiting) { | 840 const QuicStopWaitingFrame& stop_waiting) { |
886 if (stop_waiting.least_unacked < | 841 if (stop_waiting.least_unacked < |
887 received_packet_manager_.peer_least_packet_awaiting_ack()) { | 842 received_packet_manager_.peer_least_packet_awaiting_ack()) { |
888 DLOG(ERROR) << ENDPOINT << "Peer's sent low least_unacked: " | 843 DLOG(ERROR) << ENDPOINT << "Peer's sent low least_unacked: " |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 ProcessStopWaitingFrame(last_stop_waiting_frame_); | 987 ProcessStopWaitingFrame(last_stop_waiting_frame_); |
1033 if (!connected_) { | 988 if (!connected_) { |
1034 return; | 989 return; |
1035 } | 990 } |
1036 } | 991 } |
1037 | 992 |
1038 MaybeQueueAck(was_missing); | 993 MaybeQueueAck(was_missing); |
1039 } | 994 } |
1040 | 995 |
1041 ClearLastFrames(); | 996 ClearLastFrames(); |
1042 MaybeCloseIfTooManyOutstandingPackets(); | |
1043 } | 997 } |
1044 | 998 |
1045 void QuicConnection::MaybeQueueAck(bool was_missing) { | 999 void QuicConnection::MaybeQueueAck(bool was_missing) { |
1046 ++num_packets_received_since_last_ack_sent_; | 1000 ++num_packets_received_since_last_ack_sent_; |
1047 // Always send an ack every 20 packets in order to allow the peer to discard | 1001 // Always send an ack every 20 packets in order to allow the peer to discard |
1048 // information from the SentPacketManager and provide an RTT measurement. | 1002 // information from the SentPacketManager and provide an RTT measurement. |
1049 if (num_packets_received_since_last_ack_sent_ >= | 1003 if (num_packets_received_since_last_ack_sent_ >= |
1050 kMaxPacketsReceivedBeforeAckSend) { | 1004 kMaxPacketsReceivedBeforeAckSend) { |
1051 ack_queued_ = true; | 1005 ack_queued_ = true; |
1052 } | 1006 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 } | 1060 } |
1107 } | 1061 } |
1108 | 1062 |
1109 void QuicConnection::ClearLastFrames() { | 1063 void QuicConnection::ClearLastFrames() { |
1110 should_last_packet_instigate_acks_ = false; | 1064 should_last_packet_instigate_acks_ = false; |
1111 if (!FLAGS_quic_receive_packet_once_decrypted) { | 1065 if (!FLAGS_quic_receive_packet_once_decrypted) { |
1112 last_stop_waiting_frame_.least_unacked = 0; | 1066 last_stop_waiting_frame_.least_unacked = 0; |
1113 } | 1067 } |
1114 } | 1068 } |
1115 | 1069 |
1116 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() { | |
1117 if (version() > QUIC_VERSION_33) { | |
1118 return; | |
1119 } | |
1120 // This occurs if we don't discard old packets we've sent fast enough. | |
1121 // It's possible largest observed is less than least unacked. | |
1122 if (sent_packet_manager_->GetLargestObserved(last_header_.path_id) > | |
1123 (sent_packet_manager_->GetLeastUnacked(last_header_.path_id) + | |
1124 kMaxTrackedPackets)) { | |
1125 CloseConnection( | |
1126 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS, | |
1127 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets), | |
1128 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | |
1129 } | |
1130 // This occurs if there are received packet gaps and the peer does not raise | |
1131 // the least unacked fast enough. | |
1132 if (received_packet_manager_.NumTrackedPackets() > kMaxTrackedPackets) { | |
1133 CloseConnection( | |
1134 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, | |
1135 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets), | |
1136 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | |
1137 } | |
1138 } | |
1139 | |
1140 const QuicFrame QuicConnection::GetUpdatedAckFrame() { | 1070 const QuicFrame QuicConnection::GetUpdatedAckFrame() { |
1141 return received_packet_manager_.GetUpdatedAckFrame(clock_->ApproximateNow()); | 1071 return received_packet_manager_.GetUpdatedAckFrame(clock_->ApproximateNow()); |
1142 } | 1072 } |
1143 | 1073 |
1144 void QuicConnection::PopulateStopWaitingFrame( | 1074 void QuicConnection::PopulateStopWaitingFrame( |
1145 QuicStopWaitingFrame* stop_waiting) { | 1075 QuicStopWaitingFrame* stop_waiting) { |
1146 stop_waiting->least_unacked = GetLeastUnacked(stop_waiting->path_id); | 1076 stop_waiting->least_unacked = GetLeastUnacked(stop_waiting->path_id); |
1147 if (version() <= QUIC_VERSION_33) { | |
1148 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( | |
1149 stop_waiting->least_unacked - 1); | |
1150 } | |
1151 } | 1077 } |
1152 | 1078 |
1153 QuicPacketNumber QuicConnection::GetLeastUnacked(QuicPathId path_id) const { | 1079 QuicPacketNumber QuicConnection::GetLeastUnacked(QuicPathId path_id) const { |
1154 return sent_packet_manager_->GetLeastUnacked(path_id); | 1080 return sent_packet_manager_->GetLeastUnacked(path_id); |
1155 } | 1081 } |
1156 | 1082 |
1157 void QuicConnection::MaybeSendInResponseToPacket() { | 1083 void QuicConnection::MaybeSendInResponseToPacket() { |
1158 if (!connected_) { | 1084 if (!connected_) { |
1159 return; | 1085 return; |
1160 } | 1086 } |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 " without version flag before version negotiated.", | 1399 " without version flag before version negotiated.", |
1474 ENDPOINT, header.packet_number); | 1400 ENDPOINT, header.packet_number); |
1475 DLOG(WARNING) << error_details; | 1401 DLOG(WARNING) << error_details; |
1476 CloseConnection(QUIC_INVALID_VERSION, error_details, | 1402 CloseConnection(QUIC_INVALID_VERSION, error_details, |
1477 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 1403 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
1478 return false; | 1404 return false; |
1479 } else { | 1405 } else { |
1480 DCHECK_EQ(1u, header.public_header.versions.size()); | 1406 DCHECK_EQ(1u, header.public_header.versions.size()); |
1481 DCHECK_EQ(header.public_header.versions[0], version()); | 1407 DCHECK_EQ(header.public_header.versions[0], version()); |
1482 version_negotiation_state_ = NEGOTIATED_VERSION; | 1408 version_negotiation_state_ = NEGOTIATED_VERSION; |
1483 received_packet_manager_.SetVersion(version()); | |
1484 visitor_->OnSuccessfulVersionNegotiation(version()); | 1409 visitor_->OnSuccessfulVersionNegotiation(version()); |
1485 if (debug_visitor_ != nullptr) { | 1410 if (debug_visitor_ != nullptr) { |
1486 debug_visitor_->OnSuccessfulVersionNegotiation(version()); | 1411 debug_visitor_->OnSuccessfulVersionNegotiation(version()); |
1487 } | 1412 } |
1488 } | 1413 } |
1489 } else { | 1414 } else { |
1490 DCHECK(!header.public_header.version_flag); | 1415 DCHECK(!header.public_header.version_flag); |
1491 // If the client gets a packet without the version flag from the server | 1416 // If the client gets a packet without the version flag from the server |
1492 // it should stop sending version since the version negotiation is done. | 1417 // it should stop sending version since the version negotiation is done. |
1493 packet_generator_.StopSendingVersion(); | 1418 packet_generator_.StopSendingVersion(); |
1494 version_negotiation_state_ = NEGOTIATED_VERSION; | 1419 version_negotiation_state_ = NEGOTIATED_VERSION; |
1495 received_packet_manager_.SetVersion(version()); | |
1496 visitor_->OnSuccessfulVersionNegotiation(version()); | 1420 visitor_->OnSuccessfulVersionNegotiation(version()); |
1497 if (debug_visitor_ != nullptr) { | 1421 if (debug_visitor_ != nullptr) { |
1498 debug_visitor_->OnSuccessfulVersionNegotiation(version()); | 1422 debug_visitor_->OnSuccessfulVersionNegotiation(version()); |
1499 } | 1423 } |
1500 } | 1424 } |
1501 } | 1425 } |
1502 | 1426 |
1503 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); | 1427 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); |
1504 | 1428 |
1505 if (last_size_ > largest_received_packet_size_) { | 1429 if (last_size_ > largest_received_packet_size_) { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 ack_alarm_->Update(clock_->ApproximateNow(), QuicTime::Delta::Zero()); | 1794 ack_alarm_->Update(clock_->ApproximateNow(), QuicTime::Delta::Zero()); |
1871 } | 1795 } |
1872 } | 1796 } |
1873 | 1797 |
1874 void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) { | 1798 void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) { |
1875 // The caller of this function is responsible for checking CanWrite(). | 1799 // The caller of this function is responsible for checking CanWrite(). |
1876 if (packet->encrypted_buffer == nullptr) { | 1800 if (packet->encrypted_buffer == nullptr) { |
1877 QUIC_BUG << "packet.encrypted_buffer == nullptr in to SendOrQueuePacket"; | 1801 QUIC_BUG << "packet.encrypted_buffer == nullptr in to SendOrQueuePacket"; |
1878 return; | 1802 return; |
1879 } | 1803 } |
1880 if (version() <= QUIC_VERSION_33) { | |
1881 sent_entropy_manager_.RecordPacketEntropyHash(packet->packet_number, | |
1882 packet->entropy_hash); | |
1883 } | |
1884 // If there are already queued packets, queue this one immediately to ensure | 1804 // If there are already queued packets, queue this one immediately to ensure |
1885 // it's written in sequence number order. | 1805 // it's written in sequence number order. |
1886 if (!queued_packets_.empty() || !WritePacket(packet)) { | 1806 if (!queued_packets_.empty() || !WritePacket(packet)) { |
1887 // Take ownership of the underlying encrypted packet. | 1807 // Take ownership of the underlying encrypted packet. |
1888 packet->encrypted_buffer = QuicUtils::CopyBuffer(*packet); | 1808 packet->encrypted_buffer = QuicUtils::CopyBuffer(*packet); |
1889 queued_packets_.push_back(*packet); | 1809 queued_packets_.push_back(*packet); |
1890 packet->retransmittable_frames.clear(); | 1810 packet->retransmittable_frames.clear(); |
1891 } | 1811 } |
1892 | 1812 |
1893 QuicUtils::ClearSerializedPacket(packet); | 1813 QuicUtils::ClearSerializedPacket(packet); |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 | 2480 |
2561 void QuicConnection::CheckIfApplicationLimited() { | 2481 void QuicConnection::CheckIfApplicationLimited() { |
2562 if (queued_packets_.empty() && | 2482 if (queued_packets_.empty() && |
2563 !sent_packet_manager_->HasPendingRetransmissions() && | 2483 !sent_packet_manager_->HasPendingRetransmissions() && |
2564 !visitor_->WillingAndAbleToWrite()) { | 2484 !visitor_->WillingAndAbleToWrite()) { |
2565 sent_packet_manager_->OnApplicationLimited(); | 2485 sent_packet_manager_->OnApplicationLimited(); |
2566 } | 2486 } |
2567 } | 2487 } |
2568 | 2488 |
2569 } // namespace net | 2489 } // namespace net |
OLD | NEW |