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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 packet_generator_(connection_id_, &framer_, random_generator_, this), | 298 packet_generator_(connection_id_, &framer_, random_generator_, this), |
299 fec_alarm_(helper->CreateAlarm(new FecAlarm(&packet_generator_))), | 299 fec_alarm_(helper->CreateAlarm(new FecAlarm(&packet_generator_))), |
300 idle_network_timeout_(QuicTime::Delta::Infinite()), | 300 idle_network_timeout_(QuicTime::Delta::Infinite()), |
301 overall_connection_timeout_(QuicTime::Delta::Infinite()), | 301 overall_connection_timeout_(QuicTime::Delta::Infinite()), |
302 time_of_last_received_packet_(clock_->ApproximateNow()), | 302 time_of_last_received_packet_(clock_->ApproximateNow()), |
303 time_of_last_sent_new_packet_(clock_->ApproximateNow()), | 303 time_of_last_sent_new_packet_(clock_->ApproximateNow()), |
304 last_send_for_timeout_(clock_->ApproximateNow()), | 304 last_send_for_timeout_(clock_->ApproximateNow()), |
305 packet_number_of_last_sent_packet_(0), | 305 packet_number_of_last_sent_packet_(0), |
306 sent_packet_manager_( | 306 sent_packet_manager_( |
307 perspective, | 307 perspective, |
| 308 kDefaultPathId, |
308 clock_, | 309 clock_, |
309 &stats_, | 310 &stats_, |
310 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, | 311 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, |
311 FLAGS_quic_use_time_loss_detection ? kTime : kNack), | 312 FLAGS_quic_use_time_loss_detection ? kTime : kNack), |
312 version_negotiation_state_(START_NEGOTIATION), | 313 version_negotiation_state_(START_NEGOTIATION), |
313 perspective_(perspective), | 314 perspective_(perspective), |
314 connected_(true), | 315 connected_(true), |
315 peer_ip_changed_(false), | 316 peer_ip_changed_(false), |
316 peer_port_changed_(false), | 317 peer_port_changed_(false), |
317 self_ip_changed_(false), | 318 self_ip_changed_(false), |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 debug_visitor_->OnUnauthenticatedHeader(header); | 608 debug_visitor_->OnUnauthenticatedHeader(header); |
608 } | 609 } |
609 | 610 |
610 // Check that any public reset packet with a different connection ID that was | 611 // Check that any public reset packet with a different connection ID that was |
611 // routed to this QuicConnection has been redirected before control reaches | 612 // routed to this QuicConnection has been redirected before control reaches |
612 // here. | 613 // here. |
613 DCHECK_EQ(connection_id_, header.public_header.connection_id); | 614 DCHECK_EQ(connection_id_, header.public_header.connection_id); |
614 | 615 |
615 // If this packet has already been seen, or the sender has told us that it | 616 // If this packet has already been seen, or the sender has told us that it |
616 // will not be retransmitted, then stop processing the packet. | 617 // will not be retransmitted, then stop processing the packet. |
617 if (!received_packet_manager_.IsAwaitingPacket(header.packet_number)) { | 618 if (FLAGS_quic_drop_non_awaited_packets && |
| 619 !received_packet_manager_.IsAwaitingPacket(header.packet_number)) { |
618 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number | 620 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number |
619 << " no longer being waited for. Discarding."; | 621 << " no longer being waited for. Discarding."; |
620 if (debug_visitor_ != nullptr) { | 622 if (debug_visitor_ != nullptr) { |
621 debug_visitor_->OnDuplicatePacket(header.packet_number); | 623 debug_visitor_->OnDuplicatePacket(header.packet_number); |
622 } | 624 } |
623 ++stats_.packets_dropped; | 625 ++stats_.packets_dropped; |
624 return false; | 626 return false; |
625 } | 627 } |
626 | 628 |
627 return true; | 629 return true; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 670 |
669 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { | 671 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { |
670 DCHECK(connected_); | 672 DCHECK(connected_); |
671 if (debug_visitor_ != nullptr) { | 673 if (debug_visitor_ != nullptr) { |
672 debug_visitor_->OnStreamFrame(frame); | 674 debug_visitor_->OnStreamFrame(frame); |
673 } | 675 } |
674 if (frame.stream_id != kCryptoStreamId && | 676 if (frame.stream_id != kCryptoStreamId && |
675 last_decrypted_packet_level_ == ENCRYPTION_NONE) { | 677 last_decrypted_packet_level_ == ENCRYPTION_NONE) { |
676 DLOG(WARNING) << ENDPOINT | 678 DLOG(WARNING) << ENDPOINT |
677 << "Received an unencrypted data frame: closing connection"; | 679 << "Received an unencrypted data frame: closing connection"; |
678 SendConnectionClose(QUIC_UNENCRYPTED_STREAM_DATA); | 680 SendConnectionCloseWithDetails(QUIC_UNENCRYPTED_STREAM_DATA, |
| 681 "Unencrypted stream data seen"); |
679 return false; | 682 return false; |
680 } | 683 } |
681 visitor_->OnStreamFrame(frame); | 684 visitor_->OnStreamFrame(frame); |
682 stats_.stream_bytes_received += frame.frame_length; | 685 stats_.stream_bytes_received += frame.frame_length; |
683 should_last_packet_instigate_acks_ = true; | 686 should_last_packet_instigate_acks_ = true; |
684 return connected_; | 687 return connected_; |
685 } | 688 } |
686 | 689 |
687 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { | 690 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { |
688 DCHECK(connected_); | 691 DCHECK(connected_); |
689 if (debug_visitor_ != nullptr) { | 692 if (debug_visitor_ != nullptr) { |
690 debug_visitor_->OnAckFrame(incoming_ack); | 693 debug_visitor_->OnAckFrame(incoming_ack); |
691 } | 694 } |
692 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack; | 695 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack; |
693 | 696 |
694 if (last_header_.packet_number <= largest_seen_packet_with_ack_) { | 697 if (last_header_.packet_number <= largest_seen_packet_with_ack_) { |
695 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring"; | 698 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring"; |
696 return true; | 699 return true; |
697 } | 700 } |
698 | 701 |
699 if (!ValidateAckFrame(incoming_ack)) { | 702 const char* error = ValidateAckFrame(incoming_ack); |
700 SendConnectionClose(QUIC_INVALID_ACK_DATA); | 703 if (error != nullptr) { |
| 704 SendConnectionCloseWithDetails(QUIC_INVALID_ACK_DATA, error); |
701 return false; | 705 return false; |
702 } | 706 } |
703 | 707 |
704 if (FLAGS_quic_respect_send_alarm2 && send_alarm_->IsSet()) { | 708 if (FLAGS_quic_respect_send_alarm2 && send_alarm_->IsSet()) { |
705 send_alarm_->Cancel(); | 709 send_alarm_->Cancel(); |
706 } | 710 } |
707 ProcessAckFrame(incoming_ack); | 711 ProcessAckFrame(incoming_ack); |
708 if (incoming_ack.is_truncated) { | 712 if (incoming_ack.is_truncated) { |
709 should_last_packet_instigate_acks_ = true; | 713 should_last_packet_instigate_acks_ = true; |
710 } | 714 } |
(...skipping 30 matching lines...) Expand all Loading... |
741 } | 745 } |
742 | 746 |
743 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { | 747 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { |
744 DCHECK(connected_); | 748 DCHECK(connected_); |
745 | 749 |
746 if (last_header_.packet_number <= largest_seen_packet_with_stop_waiting_) { | 750 if (last_header_.packet_number <= largest_seen_packet_with_stop_waiting_) { |
747 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; | 751 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; |
748 return true; | 752 return true; |
749 } | 753 } |
750 | 754 |
751 if (!ValidateStopWaitingFrame(frame)) { | 755 const char* error = ValidateStopWaitingFrame(frame); |
752 SendConnectionClose(QUIC_INVALID_STOP_WAITING_DATA); | 756 if (error != nullptr) { |
| 757 SendConnectionCloseWithDetails(QUIC_INVALID_STOP_WAITING_DATA, error); |
753 return false; | 758 return false; |
754 } | 759 } |
755 | 760 |
756 if (debug_visitor_ != nullptr) { | 761 if (debug_visitor_ != nullptr) { |
757 debug_visitor_->OnStopWaitingFrame(frame); | 762 debug_visitor_->OnStopWaitingFrame(frame); |
758 } | 763 } |
759 | 764 |
760 last_stop_waiting_frame_ = frame; | 765 last_stop_waiting_frame_ = frame; |
761 return connected_; | 766 return connected_; |
762 } | 767 } |
763 | 768 |
764 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) { | 769 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) { |
765 DCHECK(connected_); | 770 DCHECK(connected_); |
766 if (debug_visitor_ != nullptr) { | 771 if (debug_visitor_ != nullptr) { |
767 debug_visitor_->OnPingFrame(frame); | 772 debug_visitor_->OnPingFrame(frame); |
768 } | 773 } |
769 should_last_packet_instigate_acks_ = true; | 774 should_last_packet_instigate_acks_ = true; |
770 return true; | 775 return true; |
771 } | 776 } |
772 | 777 |
773 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { | 778 const char* QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { |
774 if (incoming_ack.largest_observed > packet_generator_.packet_number()) { | 779 if (incoming_ack.largest_observed > packet_generator_.packet_number()) { |
775 LOG(WARNING) << ENDPOINT << "Peer's observed unsent packet:" | 780 LOG(WARNING) << ENDPOINT << "Peer's observed unsent packet:" |
776 << incoming_ack.largest_observed << " vs " | 781 << incoming_ack.largest_observed << " vs " |
777 << packet_generator_.packet_number(); | 782 << packet_generator_.packet_number(); |
778 // We got an error for data we have not sent. Error out. | 783 // We got an error for data we have not sent. Error out. |
779 return false; | 784 return "Largest observed too high"; |
780 } | 785 } |
781 | 786 |
782 if (incoming_ack.largest_observed < sent_packet_manager_.largest_observed()) { | 787 if (incoming_ack.largest_observed < sent_packet_manager_.largest_observed()) { |
783 LOG(WARNING) << ENDPOINT << "Peer's largest_observed packet decreased:" | 788 LOG(WARNING) << ENDPOINT << "Peer's largest_observed packet decreased:" |
784 << incoming_ack.largest_observed << " vs " | 789 << incoming_ack.largest_observed << " vs " |
785 << sent_packet_manager_.largest_observed(); | 790 << sent_packet_manager_.largest_observed(); |
786 // A new ack has a diminished largest_observed value. Error out. | 791 // A new ack has a diminished largest_observed value. Error out. |
787 // If this was an old packet, we wouldn't even have checked. | 792 // If this was an old packet, we wouldn't even have checked. |
788 return false; | 793 return "Largest observed too low"; |
789 } | 794 } |
790 | 795 |
791 if (!incoming_ack.missing_packets.Empty() && | 796 if (!incoming_ack.missing_packets.Empty() && |
792 incoming_ack.missing_packets.Max() > incoming_ack.largest_observed) { | 797 incoming_ack.missing_packets.Max() > incoming_ack.largest_observed) { |
793 LOG(WARNING) << ENDPOINT << "Peer sent missing packet: " | 798 LOG(WARNING) << ENDPOINT << "Peer sent missing packet: " |
794 << incoming_ack.missing_packets.Max() | 799 << incoming_ack.missing_packets.Max() |
795 << " which is greater than largest observed: " | 800 << " which is greater than largest observed: " |
796 << incoming_ack.largest_observed; | 801 << incoming_ack.largest_observed; |
797 return false; | 802 return "Missing packet higher than largest observed"; |
798 } | 803 } |
799 | 804 |
800 if (!incoming_ack.missing_packets.Empty() && | 805 if (!incoming_ack.missing_packets.Empty() && |
801 incoming_ack.missing_packets.Min() < | 806 incoming_ack.missing_packets.Min() < |
802 sent_packet_manager_.least_packet_awaited_by_peer()) { | 807 sent_packet_manager_.least_packet_awaited_by_peer()) { |
803 LOG(WARNING) << ENDPOINT << "Peer sent missing packet: " | 808 LOG(WARNING) << ENDPOINT << "Peer sent missing packet: " |
804 << incoming_ack.missing_packets.Min() | 809 << incoming_ack.missing_packets.Min() |
805 << " which is smaller than least_packet_awaited_by_peer_: " | 810 << " which is smaller than least_packet_awaited_by_peer_: " |
806 << sent_packet_manager_.least_packet_awaited_by_peer(); | 811 << sent_packet_manager_.least_packet_awaited_by_peer(); |
807 return false; | 812 return "Missing packet smaller than least awaited"; |
808 } | 813 } |
809 | 814 |
810 if (!sent_entropy_manager_.IsValidEntropy(incoming_ack.largest_observed, | 815 if (!sent_entropy_manager_.IsValidEntropy(incoming_ack.largest_observed, |
811 incoming_ack.missing_packets, | 816 incoming_ack.missing_packets, |
812 incoming_ack.entropy_hash)) { | 817 incoming_ack.entropy_hash)) { |
813 LOG(WARNING) << ENDPOINT << "Peer sent invalid entropy."; | 818 LOG(WARNING) << ENDPOINT << "Peer sent invalid entropy."; |
814 return false; | 819 return "Invalid entropy"; |
815 } | 820 } |
816 | 821 |
817 if (incoming_ack.latest_revived_packet != 0 && | 822 if (incoming_ack.latest_revived_packet != 0 && |
818 !incoming_ack.missing_packets.Contains( | 823 !incoming_ack.missing_packets.Contains( |
819 incoming_ack.latest_revived_packet)) { | 824 incoming_ack.latest_revived_packet)) { |
820 LOG(WARNING) << ENDPOINT | 825 LOG(WARNING) << ENDPOINT |
821 << "Peer specified revived packet which was not missing."; | 826 << "Peer specified revived packet which was not missing."; |
822 return false; | 827 return "Invalid revived packet"; |
823 } | 828 } |
824 return true; | 829 return nullptr; |
825 } | 830 } |
826 | 831 |
827 bool QuicConnection::ValidateStopWaitingFrame( | 832 const char* QuicConnection::ValidateStopWaitingFrame( |
828 const QuicStopWaitingFrame& stop_waiting) { | 833 const QuicStopWaitingFrame& stop_waiting) { |
829 if (stop_waiting.least_unacked < | 834 if (stop_waiting.least_unacked < |
830 received_packet_manager_.peer_least_packet_awaiting_ack()) { | 835 received_packet_manager_.peer_least_packet_awaiting_ack()) { |
831 DLOG(ERROR) << ENDPOINT << "Peer's sent low least_unacked: " | 836 DLOG(ERROR) << ENDPOINT << "Peer's sent low least_unacked: " |
832 << stop_waiting.least_unacked << " vs " | 837 << stop_waiting.least_unacked << " vs " |
833 << received_packet_manager_.peer_least_packet_awaiting_ack(); | 838 << received_packet_manager_.peer_least_packet_awaiting_ack(); |
834 // We never process old ack frames, so this number should only increase. | 839 // We never process old ack frames, so this number should only increase. |
835 return false; | 840 return "Least unacked too small"; |
836 } | 841 } |
837 | 842 |
838 if (stop_waiting.least_unacked > last_header_.packet_number) { | 843 if (stop_waiting.least_unacked > last_header_.packet_number) { |
839 DLOG(ERROR) << ENDPOINT | 844 DLOG(ERROR) << ENDPOINT |
840 << "Peer sent least_unacked:" << stop_waiting.least_unacked | 845 << "Peer sent least_unacked:" << stop_waiting.least_unacked |
841 << " greater than the enclosing packet number:" | 846 << " greater than the enclosing packet number:" |
842 << last_header_.packet_number; | 847 << last_header_.packet_number; |
843 return false; | 848 return "Least unacked too large"; |
844 } | 849 } |
845 | 850 |
846 return true; | 851 return nullptr; |
847 } | 852 } |
848 | 853 |
849 void QuicConnection::OnFecData(StringPiece redundancy) { | 854 void QuicConnection::OnFecData(StringPiece redundancy) { |
850 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); | 855 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); |
851 DCHECK_NE(0u, last_header_.fec_group); | 856 DCHECK_NE(0u, last_header_.fec_group); |
852 QuicFecGroup* group = GetFecGroup(); | 857 QuicFecGroup* group = GetFecGroup(); |
853 if (group != nullptr) { | 858 if (group != nullptr) { |
854 group->UpdateFec(last_decrypted_packet_level_, last_header_, redundancy); | 859 group->UpdateFec(last_decrypted_packet_level_, last_header_, redundancy); |
855 } | 860 } |
856 } | 861 } |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 } | 1350 } |
1346 | 1351 |
1347 if (!Near(header.packet_number, last_header_.packet_number)) { | 1352 if (!Near(header.packet_number, last_header_.packet_number)) { |
1348 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number | 1353 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number |
1349 << " out of bounds. Discarding"; | 1354 << " out of bounds. Discarding"; |
1350 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, | 1355 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, |
1351 "packet number out of bounds"); | 1356 "packet number out of bounds"); |
1352 return false; | 1357 return false; |
1353 } | 1358 } |
1354 | 1359 |
| 1360 // If this packet has already been seen, or the sender has told us that it |
| 1361 // will not be retransmitted, then stop processing the packet. |
| 1362 if (!FLAGS_quic_drop_non_awaited_packets && |
| 1363 !received_packet_manager_.IsAwaitingPacket(header.packet_number)) { |
| 1364 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number |
| 1365 << " no longer being waited for. Discarding."; |
| 1366 if (debug_visitor_ != nullptr) { |
| 1367 debug_visitor_->OnDuplicatePacket(header.packet_number); |
| 1368 } |
| 1369 return false; |
| 1370 } |
| 1371 |
1355 if (version_negotiation_state_ != NEGOTIATED_VERSION) { | 1372 if (version_negotiation_state_ != NEGOTIATED_VERSION) { |
1356 if (perspective_ == Perspective::IS_SERVER) { | 1373 if (perspective_ == Perspective::IS_SERVER) { |
1357 if (!header.public_header.version_flag) { | 1374 if (!header.public_header.version_flag) { |
1358 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_number | 1375 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_number |
1359 << " without version flag before version negotiated."; | 1376 << " without version flag before version negotiated."; |
1360 // Packets should have the version flag till version negotiation is | 1377 // Packets should have the version flag till version negotiation is |
1361 // done. | 1378 // done. |
1362 CloseConnection(QUIC_INVALID_VERSION, false); | 1379 CloseConnection(QUIC_INVALID_VERSION, false); |
1363 return false; | 1380 return false; |
1364 } else { | 1381 } else { |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 } | 1727 } |
1711 | 1728 |
1712 void QuicConnection::OnWriteError(int error_code) { | 1729 void QuicConnection::OnWriteError(int error_code) { |
1713 DVLOG(1) << ENDPOINT << "Write failed with error: " << error_code << " (" | 1730 DVLOG(1) << ENDPOINT << "Write failed with error: " << error_code << " (" |
1714 << ErrorToString(error_code) << ")"; | 1731 << ErrorToString(error_code) << ")"; |
1715 // We can't send an error as the socket is presumably borked. | 1732 // We can't send an error as the socket is presumably borked. |
1716 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); | 1733 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); |
1717 } | 1734 } |
1718 | 1735 |
1719 void QuicConnection::OnSerializedPacket(SerializedPacket* serialized_packet) { | 1736 void QuicConnection::OnSerializedPacket(SerializedPacket* serialized_packet) { |
| 1737 DCHECK_NE(kInvalidPathId, serialized_packet->path_id); |
1720 if (serialized_packet->packet == nullptr) { | 1738 if (serialized_packet->packet == nullptr) { |
1721 // We failed to serialize the packet, so close the connection. | 1739 // We failed to serialize the packet, so close the connection. |
1722 // CloseConnection does not send close packet, so no infinite loop here. | 1740 // CloseConnection does not send close packet, so no infinite loop here. |
1723 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | 1741 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
1724 return; | 1742 return; |
1725 } | 1743 } |
1726 if (serialized_packet->is_fec_packet && fec_alarm_->IsSet()) { | 1744 if (serialized_packet->is_fec_packet && fec_alarm_->IsSet()) { |
1727 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. | 1745 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. |
1728 fec_alarm_->Cancel(); | 1746 fec_alarm_->Cancel(); |
1729 } | 1747 } |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1963 StringPiece(revived_payload, len)); | 1981 StringPiece(revived_payload, len)); |
1964 } | 1982 } |
1965 | 1983 |
1966 ++stats_.packets_revived; | 1984 ++stats_.packets_revived; |
1967 framer_.ProcessRevivedPacket(&revived_header, | 1985 framer_.ProcessRevivedPacket(&revived_header, |
1968 StringPiece(revived_payload, len)); | 1986 StringPiece(revived_payload, len)); |
1969 } | 1987 } |
1970 | 1988 |
1971 QuicFecGroup* QuicConnection::GetFecGroup() { | 1989 QuicFecGroup* QuicConnection::GetFecGroup() { |
1972 QuicFecGroupNumber fec_group_num = last_header_.fec_group; | 1990 QuicFecGroupNumber fec_group_num = last_header_.fec_group; |
1973 if (fec_group_num == 0) { | 1991 if (fec_group_num == 0 || |
| 1992 (FLAGS_quic_drop_non_awaited_packets && |
| 1993 fec_group_num < |
| 1994 received_packet_manager_.peer_least_packet_awaiting_ack() && |
| 1995 !ContainsKey(group_map_, fec_group_num))) { |
| 1996 // If the group number is below peer_least_packet_awaiting_ack and this |
| 1997 // group does not exist, which means this group has missing packets below |
| 1998 // |peer_least_packet_awaiting_ack| which we would never receive, so return |
| 1999 // nullptr. |
1974 return nullptr; | 2000 return nullptr; |
1975 } | 2001 } |
1976 if (!ContainsKey(group_map_, fec_group_num)) { | 2002 if (!ContainsKey(group_map_, fec_group_num)) { |
1977 if (group_map_.size() >= kMaxFecGroups) { // Too many groups | 2003 if (group_map_.size() >= kMaxFecGroups) { // Too many groups |
1978 if (fec_group_num < group_map_.begin()->first) { | 2004 if (fec_group_num < group_map_.begin()->first) { |
1979 // The group being requested is a group we've seen before and deleted. | 2005 // The group being requested is a group we've seen before and deleted. |
1980 // Don't recreate it. | 2006 // Don't recreate it. |
1981 return nullptr; | 2007 return nullptr; |
1982 } | 2008 } |
1983 // Clear the lowest group number. | 2009 // Clear the lowest group number. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2057 | 2083 |
2058 // Opportunistically bundle an ack with this outgoing packet. | 2084 // Opportunistically bundle an ack with this outgoing packet. |
2059 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 2085 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); |
2060 packet_generator_.AddControlFrame( | 2086 packet_generator_.AddControlFrame( |
2061 QuicFrame(new QuicGoAwayFrame(error, last_good_stream_id, reason))); | 2087 QuicFrame(new QuicGoAwayFrame(error, last_good_stream_id, reason))); |
2062 } | 2088 } |
2063 | 2089 |
2064 void QuicConnection::CloseFecGroupsBefore(QuicPacketNumber packet_number) { | 2090 void QuicConnection::CloseFecGroupsBefore(QuicPacketNumber packet_number) { |
2065 FecGroupMap::iterator it = group_map_.begin(); | 2091 FecGroupMap::iterator it = group_map_.begin(); |
2066 while (it != group_map_.end()) { | 2092 while (it != group_map_.end()) { |
2067 // If this is the current group or the group doesn't protect this packet | 2093 // If the group doesn't protect this packet we can ignore it. |
2068 // we can ignore it. | 2094 if ((!FLAGS_quic_drop_non_awaited_packets && |
2069 if (last_header_.fec_group == it->first || | 2095 last_header_.fec_group == it->first) || |
2070 !it->second->IsWaitingForPacketBefore(packet_number)) { | 2096 !it->second->IsWaitingForPacketBefore(packet_number)) { |
2071 ++it; | 2097 ++it; |
2072 continue; | 2098 continue; |
2073 } | 2099 } |
2074 QuicFecGroup* fec_group = it->second; | 2100 QuicFecGroup* fec_group = it->second; |
2075 DCHECK(!fec_group->CanRevive()); | 2101 DCHECK(!fec_group->CanRevive()); |
2076 FecGroupMap::iterator next = it; | 2102 FecGroupMap::iterator next = it; |
2077 ++next; | 2103 ++next; |
2078 group_map_.erase(it); | 2104 group_map_.erase(it); |
2079 delete fec_group; | 2105 delete fec_group; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2149 // timeout handling. | 2175 // timeout handling. |
2150 QuicTime::Delta idle_duration = now.Subtract(time_of_last_packet); | 2176 QuicTime::Delta idle_duration = now.Subtract(time_of_last_packet); |
2151 DVLOG(1) << ENDPOINT << "last packet " | 2177 DVLOG(1) << ENDPOINT << "last packet " |
2152 << time_of_last_packet.ToDebuggingValue() | 2178 << time_of_last_packet.ToDebuggingValue() |
2153 << " now:" << now.ToDebuggingValue() | 2179 << " now:" << now.ToDebuggingValue() |
2154 << " idle_duration:" << idle_duration.ToMicroseconds() | 2180 << " idle_duration:" << idle_duration.ToMicroseconds() |
2155 << " idle_network_timeout: " | 2181 << " idle_network_timeout: " |
2156 << idle_network_timeout_.ToMicroseconds(); | 2182 << idle_network_timeout_.ToMicroseconds(); |
2157 if (idle_duration >= idle_network_timeout_) { | 2183 if (idle_duration >= idle_network_timeout_) { |
2158 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity."; | 2184 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity."; |
2159 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT); | 2185 SendConnectionCloseWithDetails(QUIC_CONNECTION_TIMED_OUT, |
| 2186 "No recent network activity"); |
2160 return; | 2187 return; |
2161 } | 2188 } |
2162 | 2189 |
2163 if (!overall_connection_timeout_.IsInfinite()) { | 2190 if (!overall_connection_timeout_.IsInfinite()) { |
2164 QuicTime::Delta connected_duration = | 2191 QuicTime::Delta connected_duration = |
2165 now.Subtract(stats_.connection_creation_time); | 2192 now.Subtract(stats_.connection_creation_time); |
2166 DVLOG(1) << ENDPOINT | 2193 DVLOG(1) << ENDPOINT |
2167 << "connection time: " << connected_duration.ToMicroseconds() | 2194 << "connection time: " << connected_duration.ToMicroseconds() |
2168 << " overall timeout: " | 2195 << " overall timeout: " |
2169 << overall_connection_timeout_.ToMicroseconds(); | 2196 << overall_connection_timeout_.ToMicroseconds(); |
2170 if (connected_duration >= overall_connection_timeout_) { | 2197 if (connected_duration >= overall_connection_timeout_) { |
2171 DVLOG(1) << ENDPOINT | 2198 DVLOG(1) << ENDPOINT |
2172 << "Connection timedout due to overall connection timeout."; | 2199 << "Connection timedout due to overall connection timeout."; |
2173 SendConnectionClose(QUIC_CONNECTION_OVERALL_TIMED_OUT); | 2200 SendConnectionCloseWithDetails(QUIC_CONNECTION_OVERALL_TIMED_OUT, |
| 2201 "Overall timeout expired"); |
2174 return; | 2202 return; |
2175 } | 2203 } |
2176 } | 2204 } |
2177 | 2205 |
2178 SetTimeoutAlarm(); | 2206 SetTimeoutAlarm(); |
2179 } | 2207 } |
2180 | 2208 |
2181 void QuicConnection::SetTimeoutAlarm() { | 2209 void QuicConnection::SetTimeoutAlarm() { |
2182 QuicTime time_of_last_packet = | 2210 QuicTime time_of_last_packet = |
2183 max(time_of_last_received_packet_, time_of_last_sent_new_packet_); | 2211 max(time_of_last_received_packet_, time_of_last_sent_new_packet_); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2391 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2419 SendMtuDiscoveryPacket(mtu_discovery_target_); |
2392 | 2420 |
2393 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2421 DCHECK(!mtu_discovery_alarm_->IsSet()); |
2394 } | 2422 } |
2395 | 2423 |
2396 bool QuicConnection::ack_frame_updated() const { | 2424 bool QuicConnection::ack_frame_updated() const { |
2397 return received_packet_manager_.ack_frame_updated(); | 2425 return received_packet_manager_.ack_frame_updated(); |
2398 } | 2426 } |
2399 | 2427 |
2400 } // namespace net | 2428 } // namespace net |
OLD | NEW |