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 13 matching lines...) Expand all Loading... |
24 #include "net/base/address_family.h" | 24 #include "net/base/address_family.h" |
25 #include "net/base/ip_address.h" | 25 #include "net/base/ip_address.h" |
26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
27 #include "net/quic/crypto/crypto_protocol.h" | 27 #include "net/quic/crypto/crypto_protocol.h" |
28 #include "net/quic/crypto/quic_decrypter.h" | 28 #include "net/quic/crypto/quic_decrypter.h" |
29 #include "net/quic/crypto/quic_encrypter.h" | 29 #include "net/quic/crypto/quic_encrypter.h" |
30 #include "net/quic/proto/cached_network_parameters.pb.h" | 30 #include "net/quic/proto/cached_network_parameters.pb.h" |
31 #include "net/quic/quic_bandwidth.h" | 31 #include "net/quic/quic_bandwidth.h" |
32 #include "net/quic/quic_bug_tracker.h" | 32 #include "net/quic/quic_bug_tracker.h" |
33 #include "net/quic/quic_config.h" | 33 #include "net/quic/quic_config.h" |
34 #include "net/quic/quic_fec_group.h" | |
35 #include "net/quic/quic_flags.h" | 34 #include "net/quic/quic_flags.h" |
36 #include "net/quic/quic_packet_generator.h" | 35 #include "net/quic/quic_packet_generator.h" |
37 #include "net/quic/quic_utils.h" | 36 #include "net/quic/quic_utils.h" |
38 | 37 |
39 using base::StringPiece; | 38 using base::StringPiece; |
40 using base::StringPrintf; | 39 using base::StringPrintf; |
41 using base::hash_map; | 40 using base::hash_map; |
42 using base::hash_set; | 41 using base::hash_set; |
43 using std::list; | 42 using std::list; |
44 using std::make_pair; | 43 using std::make_pair; |
45 using std::max; | 44 using std::max; |
46 using std::min; | 45 using std::min; |
47 using std::numeric_limits; | 46 using std::numeric_limits; |
48 using std::set; | 47 using std::set; |
49 using std::string; | 48 using std::string; |
50 using std::vector; | 49 using std::vector; |
51 | 50 |
52 namespace net { | 51 namespace net { |
53 | 52 |
54 class QuicDecrypter; | 53 class QuicDecrypter; |
55 class QuicEncrypter; | 54 class QuicEncrypter; |
56 | 55 |
57 namespace { | 56 namespace { |
58 | 57 |
59 // The largest gap in packets we'll accept without closing the connection. | 58 // The largest gap in packets we'll accept without closing the connection. |
60 // This will likely have to be tuned. | 59 // This will likely have to be tuned. |
61 const QuicPacketNumber kMaxPacketGap = 5000; | 60 const QuicPacketNumber kMaxPacketGap = 5000; |
62 | 61 |
63 // Limit the number of FEC groups to two. If we get enough out of order packets | |
64 // that this becomes limiting, we can revisit. | |
65 const size_t kMaxFecGroups = 2; | |
66 | |
67 // Maximum number of acks received before sending an ack in response. | 62 // Maximum number of acks received before sending an ack in response. |
68 const QuicPacketCount kMaxPacketsReceivedBeforeAckSend = 20; | 63 const QuicPacketCount kMaxPacketsReceivedBeforeAckSend = 20; |
69 | 64 |
70 // Maximum number of retransmittable packets received before sending an ack. | 65 // Maximum number of retransmittable packets received before sending an ack. |
71 const QuicPacketCount kDefaultRetransmittablePacketsBeforeAck = 2; | 66 const QuicPacketCount kDefaultRetransmittablePacketsBeforeAck = 2; |
72 // Minimum number of packets received before ack decimation is enabled. | 67 // Minimum number of packets received before ack decimation is enabled. |
73 // This intends to avoid the beginning of slow start, when CWNDs may be | 68 // This intends to avoid the beginning of slow start, when CWNDs may be |
74 // rapidly increasing. | 69 // rapidly increasing. |
75 const QuicPacketCount kMinReceivedBeforeAckDecimation = 100; | 70 const QuicPacketCount kMinReceivedBeforeAckDecimation = 100; |
76 // Wait for up to 10 retransmittable packets before sending an ack. | 71 // Wait for up to 10 retransmittable packets before sending an ack. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 owns_writer_(owns_writer), | 236 owns_writer_(owns_writer), |
242 encryption_level_(ENCRYPTION_NONE), | 237 encryption_level_(ENCRYPTION_NONE), |
243 has_forward_secure_encrypter_(false), | 238 has_forward_secure_encrypter_(false), |
244 first_required_forward_secure_packet_(0), | 239 first_required_forward_secure_packet_(0), |
245 clock_(helper->GetClock()), | 240 clock_(helper->GetClock()), |
246 random_generator_(helper->GetRandomGenerator()), | 241 random_generator_(helper->GetRandomGenerator()), |
247 connection_id_(connection_id), | 242 connection_id_(connection_id), |
248 peer_address_(address), | 243 peer_address_(address), |
249 migrating_peer_port_(0), | 244 migrating_peer_port_(0), |
250 last_packet_decrypted_(false), | 245 last_packet_decrypted_(false), |
251 last_packet_revived_(false), | |
252 last_size_(0), | 246 last_size_(0), |
253 last_decrypted_packet_level_(ENCRYPTION_NONE), | 247 last_decrypted_packet_level_(ENCRYPTION_NONE), |
254 should_last_packet_instigate_acks_(false), | 248 should_last_packet_instigate_acks_(false), |
255 largest_seen_packet_with_ack_(0), | 249 largest_seen_packet_with_ack_(0), |
256 largest_seen_packet_with_stop_waiting_(0), | 250 largest_seen_packet_with_stop_waiting_(0), |
257 max_undecryptable_packets_(0), | 251 max_undecryptable_packets_(0), |
258 pending_version_negotiation_packet_(false), | 252 pending_version_negotiation_packet_(false), |
259 save_crypto_packets_as_termination_packets_(false), | 253 save_crypto_packets_as_termination_packets_(false), |
260 silent_close_enabled_(false), | 254 silent_close_enabled_(false), |
261 received_packet_manager_(&stats_), | 255 received_packet_manager_(&stats_), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 326 } |
333 | 327 |
334 QuicConnection::~QuicConnection() { | 328 QuicConnection::~QuicConnection() { |
335 if (owns_writer_) { | 329 if (owns_writer_) { |
336 delete writer_; | 330 delete writer_; |
337 } | 331 } |
338 STLDeleteElements(&undecryptable_packets_); | 332 STLDeleteElements(&undecryptable_packets_); |
339 if (termination_packets_.get() != nullptr) { | 333 if (termination_packets_.get() != nullptr) { |
340 STLDeleteElements(termination_packets_.get()); | 334 STLDeleteElements(termination_packets_.get()); |
341 } | 335 } |
342 STLDeleteValues(&group_map_); | |
343 ClearQueuedPackets(); | 336 ClearQueuedPackets(); |
344 } | 337 } |
345 | 338 |
346 void QuicConnection::ClearQueuedPackets() { | 339 void QuicConnection::ClearQueuedPackets() { |
347 for (QueuedPacketList::iterator it = queued_packets_.begin(); | 340 for (QueuedPacketList::iterator it = queued_packets_.begin(); |
348 it != queued_packets_.end(); ++it) { | 341 it != queued_packets_.end(); ++it) { |
349 // Delete the buffer before calling ClearSerializedPacket, which sets | 342 // Delete the buffer before calling ClearSerializedPacket, which sets |
350 // encrypted_buffer to nullptr. | 343 // encrypted_buffer to nullptr. |
351 delete[] it->encrypted_buffer; | 344 delete[] it->encrypted_buffer; |
352 QuicUtils::ClearSerializedPacket(&(*it)); | 345 QuicUtils::ClearSerializedPacket(&(*it)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // Packets that we can not or have not decrypted are dropped. | 435 // Packets that we can not or have not decrypted are dropped. |
443 // TODO(rch): add stats to measure this. | 436 // TODO(rch): add stats to measure this. |
444 if (!connected_ || last_packet_decrypted_ == false) { | 437 if (!connected_ || last_packet_decrypted_ == false) { |
445 return; | 438 return; |
446 } | 439 } |
447 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); | 440 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); |
448 } | 441 } |
449 | 442 |
450 void QuicConnection::OnPacket() { | 443 void QuicConnection::OnPacket() { |
451 last_packet_decrypted_ = false; | 444 last_packet_decrypted_ = false; |
452 last_packet_revived_ = false; | |
453 } | 445 } |
454 | 446 |
455 void QuicConnection::OnPublicResetPacket(const QuicPublicResetPacket& packet) { | 447 void QuicConnection::OnPublicResetPacket(const QuicPublicResetPacket& packet) { |
456 // Check that any public reset packet with a different connection ID that was | 448 // Check that any public reset packet with a different connection ID that was |
457 // routed to this QuicConnection has been redirected before control reaches | 449 // routed to this QuicConnection has been redirected before control reaches |
458 // here. (Check for a bug regression.) | 450 // here. (Check for a bug regression.) |
459 DCHECK_EQ(connection_id_, packet.public_header.connection_id); | 451 DCHECK_EQ(connection_id_, packet.public_header.connection_id); |
460 if (debug_visitor_ != nullptr) { | 452 if (debug_visitor_ != nullptr) { |
461 debug_visitor_->OnPublicResetPacket(packet); | 453 debug_visitor_->OnPublicResetPacket(packet); |
462 } | 454 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 return; | 552 return; |
561 } | 553 } |
562 | 554 |
563 DVLOG(1) << ENDPOINT | 555 DVLOG(1) << ENDPOINT |
564 << "Negotiated version: " << QuicVersionToString(version()); | 556 << "Negotiated version: " << QuicVersionToString(version()); |
565 server_supported_versions_ = packet.versions; | 557 server_supported_versions_ = packet.versions; |
566 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; | 558 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; |
567 RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); | 559 RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); |
568 } | 560 } |
569 | 561 |
570 void QuicConnection::OnRevivedPacket() {} | |
571 | |
572 bool QuicConnection::OnUnauthenticatedPublicHeader( | 562 bool QuicConnection::OnUnauthenticatedPublicHeader( |
573 const QuicPacketPublicHeader& header) { | 563 const QuicPacketPublicHeader& header) { |
574 if (header.connection_id == connection_id_) { | 564 if (header.connection_id == connection_id_) { |
575 return true; | 565 return true; |
576 } | 566 } |
577 | 567 |
578 ++stats_.packets_dropped; | 568 ++stats_.packets_dropped; |
579 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " | 569 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " |
580 << header.connection_id << " instead of " << connection_id_; | 570 << header.connection_id << " instead of " << connection_id_; |
581 if (debug_visitor_ != nullptr) { | 571 if (debug_visitor_ != nullptr) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 | 638 |
649 MaybeMigrateConnectionToNewPeerAddress(); | 639 MaybeMigrateConnectionToNewPeerAddress(); |
650 | 640 |
651 --stats_.packets_dropped; | 641 --stats_.packets_dropped; |
652 DVLOG(1) << ENDPOINT << "Received packet header: " << header; | 642 DVLOG(1) << ENDPOINT << "Received packet header: " << header; |
653 last_header_ = header; | 643 last_header_ = header; |
654 DCHECK(connected_); | 644 DCHECK(connected_); |
655 return true; | 645 return true; |
656 } | 646 } |
657 | 647 |
658 void QuicConnection::OnFecProtectedPayload(StringPiece payload) { | |
659 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); | |
660 DCHECK_NE(0u, last_header_.fec_group); | |
661 QuicFecGroup* group = GetFecGroup(); | |
662 if (group != nullptr) { | |
663 group->Update(last_decrypted_packet_level_, last_header_, payload); | |
664 } | |
665 } | |
666 | |
667 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { | 648 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { |
668 DCHECK(connected_); | 649 DCHECK(connected_); |
669 if (debug_visitor_ != nullptr) { | 650 if (debug_visitor_ != nullptr) { |
670 debug_visitor_->OnStreamFrame(frame); | 651 debug_visitor_->OnStreamFrame(frame); |
671 } | 652 } |
672 if (frame.stream_id != kCryptoStreamId && | 653 if (frame.stream_id != kCryptoStreamId && |
673 last_decrypted_packet_level_ == ENCRYPTION_NONE) { | 654 last_decrypted_packet_level_ == ENCRYPTION_NONE) { |
674 QUIC_BUG << ENDPOINT | 655 QUIC_BUG << ENDPOINT |
675 << "Received an unencrypted data frame: closing connection" | 656 << "Received an unencrypted data frame: closing connection" |
676 << " packet_number:" << last_header_.packet_number | 657 << " packet_number:" << last_header_.packet_number |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 | 713 |
733 // Always reset the retransmission alarm when an ack comes in, since we now | 714 // Always reset the retransmission alarm when an ack comes in, since we now |
734 // have a better estimate of the current rtt than when it was set. | 715 // have a better estimate of the current rtt than when it was set. |
735 SetRetransmissionAlarm(); | 716 SetRetransmissionAlarm(); |
736 } | 717 } |
737 | 718 |
738 void QuicConnection::ProcessStopWaitingFrame( | 719 void QuicConnection::ProcessStopWaitingFrame( |
739 const QuicStopWaitingFrame& stop_waiting) { | 720 const QuicStopWaitingFrame& stop_waiting) { |
740 largest_seen_packet_with_stop_waiting_ = last_header_.packet_number; | 721 largest_seen_packet_with_stop_waiting_ = last_header_.packet_number; |
741 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); | 722 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); |
742 // Possibly close any FecGroups which are now irrelevant. | |
743 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); | |
744 } | 723 } |
745 | 724 |
746 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { | 725 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { |
747 DCHECK(connected_); | 726 DCHECK(connected_); |
748 | 727 |
749 if (last_header_.packet_number <= largest_seen_packet_with_stop_waiting_) { | 728 if (last_header_.packet_number <= largest_seen_packet_with_stop_waiting_) { |
750 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; | 729 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; |
751 return true; | 730 return true; |
752 } | 731 } |
753 | 732 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 | 792 |
814 if (!sent_entropy_manager_.IsValidEntropy(incoming_ack.largest_observed, | 793 if (!sent_entropy_manager_.IsValidEntropy(incoming_ack.largest_observed, |
815 incoming_ack.missing_packets, | 794 incoming_ack.missing_packets, |
816 incoming_ack.entropy_hash)) { | 795 incoming_ack.entropy_hash)) { |
817 LOG(WARNING) << ENDPOINT << "Peer sent invalid entropy." | 796 LOG(WARNING) << ENDPOINT << "Peer sent invalid entropy." |
818 << " largest_observed:" << incoming_ack.largest_observed | 797 << " largest_observed:" << incoming_ack.largest_observed |
819 << " last_received:" << last_header_.packet_number; | 798 << " last_received:" << last_header_.packet_number; |
820 return "Invalid entropy"; | 799 return "Invalid entropy"; |
821 } | 800 } |
822 | 801 |
823 if (incoming_ack.latest_revived_packet != 0 && | |
824 !incoming_ack.missing_packets.Contains( | |
825 incoming_ack.latest_revived_packet)) { | |
826 LOG(WARNING) << ENDPOINT | |
827 << "Peer specified revived packet which was not missing." | |
828 << " revived_packet:" << incoming_ack.latest_revived_packet; | |
829 return "Invalid revived packet"; | |
830 } | |
831 return nullptr; | 802 return nullptr; |
832 } | 803 } |
833 | 804 |
834 const char* QuicConnection::ValidateStopWaitingFrame( | 805 const char* QuicConnection::ValidateStopWaitingFrame( |
835 const QuicStopWaitingFrame& stop_waiting) { | 806 const QuicStopWaitingFrame& stop_waiting) { |
836 if (stop_waiting.least_unacked < | 807 if (stop_waiting.least_unacked < |
837 received_packet_manager_.peer_least_packet_awaiting_ack()) { | 808 received_packet_manager_.peer_least_packet_awaiting_ack()) { |
838 DLOG(ERROR) << ENDPOINT << "Peer's sent low least_unacked: " | 809 DLOG(ERROR) << ENDPOINT << "Peer's sent low least_unacked: " |
839 << stop_waiting.least_unacked << " vs " | 810 << stop_waiting.least_unacked << " vs " |
840 << received_packet_manager_.peer_least_packet_awaiting_ack(); | 811 << received_packet_manager_.peer_least_packet_awaiting_ack(); |
841 // We never process old ack frames, so this number should only increase. | 812 // We never process old ack frames, so this number should only increase. |
842 return "Least unacked too small"; | 813 return "Least unacked too small"; |
843 } | 814 } |
844 | 815 |
845 if (stop_waiting.least_unacked > last_header_.packet_number) { | 816 if (stop_waiting.least_unacked > last_header_.packet_number) { |
846 DLOG(ERROR) << ENDPOINT | 817 DLOG(ERROR) << ENDPOINT |
847 << "Peer sent least_unacked:" << stop_waiting.least_unacked | 818 << "Peer sent least_unacked:" << stop_waiting.least_unacked |
848 << " greater than the enclosing packet number:" | 819 << " greater than the enclosing packet number:" |
849 << last_header_.packet_number; | 820 << last_header_.packet_number; |
850 return "Least unacked too large"; | 821 return "Least unacked too large"; |
851 } | 822 } |
852 | 823 |
853 return nullptr; | 824 return nullptr; |
854 } | 825 } |
855 | 826 |
856 void QuicConnection::OnFecData(StringPiece redundancy) { | |
857 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); | |
858 DCHECK_NE(0u, last_header_.fec_group); | |
859 QuicFecGroup* group = GetFecGroup(); | |
860 if (group != nullptr) { | |
861 group->UpdateFec(last_decrypted_packet_level_, last_header_, redundancy); | |
862 } | |
863 } | |
864 | |
865 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { | 827 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { |
866 DCHECK(connected_); | 828 DCHECK(connected_); |
867 if (debug_visitor_ != nullptr) { | 829 if (debug_visitor_ != nullptr) { |
868 debug_visitor_->OnRstStreamFrame(frame); | 830 debug_visitor_->OnRstStreamFrame(frame); |
869 } | 831 } |
870 DVLOG(1) << ENDPOINT | 832 DVLOG(1) << ENDPOINT |
871 << "RST_STREAM_FRAME received for stream: " << frame.stream_id | 833 << "RST_STREAM_FRAME received for stream: " << frame.stream_id |
872 << " with error: " | 834 << " with error: " |
873 << QuicUtils::StreamErrorToString(frame.error_code); | 835 << QuicUtils::StreamErrorToString(frame.error_code); |
874 visitor_->OnRstStream(frame); | 836 visitor_->OnRstStream(frame); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 return connected_; | 908 return connected_; |
947 } | 909 } |
948 | 910 |
949 void QuicConnection::OnPacketComplete() { | 911 void QuicConnection::OnPacketComplete() { |
950 // Don't do anything if this packet closed the connection. | 912 // Don't do anything if this packet closed the connection. |
951 if (!connected_) { | 913 if (!connected_) { |
952 ClearLastFrames(); | 914 ClearLastFrames(); |
953 return; | 915 return; |
954 } | 916 } |
955 | 917 |
956 DVLOG(1) << ENDPOINT << (last_packet_revived_ ? "Revived" : "Got") | 918 DVLOG(1) << ENDPOINT << "Got packet " << last_header_.packet_number << " for " |
957 << " packet " << last_header_.packet_number << " for " | |
958 << last_header_.public_header.connection_id; | 919 << last_header_.public_header.connection_id; |
959 | 920 |
960 // An ack will be sent if a missing retransmittable packet was received; | 921 // An ack will be sent if a missing retransmittable packet was received; |
961 const bool was_missing = | 922 const bool was_missing = |
962 should_last_packet_instigate_acks_ && | 923 should_last_packet_instigate_acks_ && |
963 received_packet_manager_.IsMissing(last_header_.packet_number); | 924 received_packet_manager_.IsMissing(last_header_.packet_number); |
964 | 925 |
965 // Record received or revived packet to populate ack info correctly before | 926 // Record received to populate ack info correctly before processing stream |
966 // processing stream frames, since the processing may result in a response | 927 // frames, since the processing may result in a response packet with a bundled |
967 // packet with a bundled ack. | 928 // ack. |
968 if (last_packet_revived_) { | 929 received_packet_manager_.RecordPacketReceived(last_size_, last_header_, |
969 received_packet_manager_.RecordPacketRevived(last_header_.packet_number); | 930 time_of_last_received_packet_); |
970 } else { | |
971 received_packet_manager_.RecordPacketReceived( | |
972 last_size_, last_header_, time_of_last_received_packet_); | |
973 } | |
974 | 931 |
975 // Process stop waiting frames here, instead of inline, because the packet | 932 // Process stop waiting frames here, instead of inline, because the packet |
976 // needs to be considered 'received' before the entropy can be updated. | 933 // needs to be considered 'received' before the entropy can be updated. |
977 if (last_stop_waiting_frame_.least_unacked > 0) { | 934 if (last_stop_waiting_frame_.least_unacked > 0) { |
978 ProcessStopWaitingFrame(last_stop_waiting_frame_); | 935 ProcessStopWaitingFrame(last_stop_waiting_frame_); |
979 if (!connected_) { | 936 if (!connected_) { |
980 return; | 937 return; |
981 } | 938 } |
982 } | 939 } |
983 | 940 |
984 MaybeQueueAck(was_missing); | 941 MaybeQueueAck(was_missing); |
985 | 942 |
986 ClearLastFrames(); | 943 ClearLastFrames(); |
987 MaybeCloseIfTooManyOutstandingPackets(); | 944 MaybeCloseIfTooManyOutstandingPackets(); |
988 MaybeProcessRevivedPacket(); | |
989 } | 945 } |
990 | 946 |
991 void QuicConnection::MaybeQueueAck(bool was_missing) { | 947 void QuicConnection::MaybeQueueAck(bool was_missing) { |
992 ++num_packets_received_since_last_ack_sent_; | 948 ++num_packets_received_since_last_ack_sent_; |
993 // Always send an ack every 20 packets in order to allow the peer to discard | 949 // Always send an ack every 20 packets in order to allow the peer to discard |
994 // information from the SentPacketManager and provide an RTT measurement. | 950 // information from the SentPacketManager and provide an RTT measurement. |
995 if (num_packets_received_since_last_ack_sent_ >= | 951 if (num_packets_received_since_last_ack_sent_ >= |
996 kMaxPacketsReceivedBeforeAckSend) { | 952 kMaxPacketsReceivedBeforeAckSend) { |
997 ack_queued_ = true; | 953 ack_queued_ = true; |
998 } | 954 } |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 } | 1319 } |
1364 | 1320 |
1365 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { | 1321 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { |
1366 if (!writer_->IsWriteBlocked()) { | 1322 if (!writer_->IsWriteBlocked()) { |
1367 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK); | 1323 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK); |
1368 OnCanWrite(); | 1324 OnCanWrite(); |
1369 } | 1325 } |
1370 } | 1326 } |
1371 | 1327 |
1372 bool QuicConnection::ProcessValidatedPacket(const QuicPacketHeader& header) { | 1328 bool QuicConnection::ProcessValidatedPacket(const QuicPacketHeader& header) { |
| 1329 if (header.fec_flag) { |
| 1330 // Drop any FEC packet. |
| 1331 return false; |
| 1332 } |
| 1333 |
1373 if (FLAGS_check_peer_address_change_after_decryption) { | 1334 if (FLAGS_check_peer_address_change_after_decryption) { |
1374 if (perspective_ == Perspective::IS_SERVER && | 1335 if (perspective_ == Perspective::IS_SERVER && |
1375 IsInitializedIPEndPoint(self_address_) && | 1336 IsInitializedIPEndPoint(self_address_) && |
1376 IsInitializedIPEndPoint(last_packet_destination_address_) && | 1337 IsInitializedIPEndPoint(last_packet_destination_address_) && |
1377 (!(self_address_ == last_packet_destination_address_))) { | 1338 (!(self_address_ == last_packet_destination_address_))) { |
1378 SendConnectionCloseWithDetails( | 1339 SendConnectionCloseWithDetails( |
1379 QUIC_ERROR_MIGRATING_ADDRESS, | 1340 QUIC_ERROR_MIGRATING_ADDRESS, |
1380 "Self address migration is not supported at the server."); | 1341 "Self address migration is not supported at the server."); |
1381 return false; | 1342 return false; |
1382 } | 1343 } |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 // undecryptable packets as the argument to OnUndecryptablePacket so that | 1893 // undecryptable packets as the argument to OnUndecryptablePacket so that |
1933 // we just need to call OnUndecryptablePacket once? | 1894 // we just need to call OnUndecryptablePacket once? |
1934 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { | 1895 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { |
1935 debug_visitor_->OnUndecryptablePacket(); | 1896 debug_visitor_->OnUndecryptablePacket(); |
1936 } | 1897 } |
1937 } | 1898 } |
1938 STLDeleteElements(&undecryptable_packets_); | 1899 STLDeleteElements(&undecryptable_packets_); |
1939 } | 1900 } |
1940 } | 1901 } |
1941 | 1902 |
1942 void QuicConnection::MaybeProcessRevivedPacket() { | |
1943 QuicFecGroup* group = GetFecGroup(); | |
1944 if (!connected_ || group == nullptr || !group->CanRevive()) { | |
1945 return; | |
1946 } | |
1947 QuicPacketHeader revived_header; | |
1948 char revived_payload[kMaxPacketSize]; | |
1949 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize); | |
1950 if (!received_packet_manager_.IsAwaitingPacket( | |
1951 revived_header.packet_number)) { | |
1952 // Close this FEC group because all packets in the group has been received. | |
1953 group_map_.erase(last_header_.fec_group); | |
1954 delete group; | |
1955 return; | |
1956 } | |
1957 revived_header.public_header.connection_id = connection_id_; | |
1958 revived_header.public_header.connection_id_length = | |
1959 last_header_.public_header.connection_id_length; | |
1960 revived_header.public_header.version_flag = false; | |
1961 revived_header.public_header.reset_flag = false; | |
1962 revived_header.public_header.packet_number_length = | |
1963 last_header_.public_header.packet_number_length; | |
1964 revived_header.fec_flag = false; | |
1965 revived_header.is_in_fec_group = NOT_IN_FEC_GROUP; | |
1966 revived_header.fec_group = 0; | |
1967 group_map_.erase(last_header_.fec_group); | |
1968 last_decrypted_packet_level_ = group->EffectiveEncryptionLevel(); | |
1969 DCHECK_LT(last_decrypted_packet_level_, NUM_ENCRYPTION_LEVELS); | |
1970 delete group; | |
1971 | |
1972 last_packet_revived_ = true; | |
1973 if (debug_visitor_ != nullptr) { | |
1974 debug_visitor_->OnRevivedPacket(revived_header, | |
1975 StringPiece(revived_payload, len)); | |
1976 } | |
1977 | |
1978 ++stats_.packets_revived; | |
1979 framer_.ProcessRevivedPacket(&revived_header, | |
1980 StringPiece(revived_payload, len)); | |
1981 } | |
1982 | |
1983 QuicFecGroup* QuicConnection::GetFecGroup() { | |
1984 QuicFecGroupNumber fec_group_num = last_header_.fec_group; | |
1985 if (fec_group_num == 0 || | |
1986 (fec_group_num < | |
1987 received_packet_manager_.peer_least_packet_awaiting_ack() && | |
1988 !ContainsKey(group_map_, fec_group_num))) { | |
1989 // If the group number is below peer_least_packet_awaiting_ack and this | |
1990 // group does not exist, which means this group has missing packets below | |
1991 // |peer_least_packet_awaiting_ack| which we would never receive, so return | |
1992 // nullptr. | |
1993 return nullptr; | |
1994 } | |
1995 if (!ContainsKey(group_map_, fec_group_num)) { | |
1996 if (group_map_.size() >= kMaxFecGroups) { // Too many groups | |
1997 if (fec_group_num < group_map_.begin()->first) { | |
1998 // The group being requested is a group we've seen before and deleted. | |
1999 // Don't recreate it. | |
2000 return nullptr; | |
2001 } | |
2002 // Clear the lowest group number. | |
2003 delete group_map_.begin()->second; | |
2004 group_map_.erase(group_map_.begin()); | |
2005 } | |
2006 group_map_[fec_group_num] = new QuicFecGroup(fec_group_num); | |
2007 } | |
2008 return group_map_[fec_group_num]; | |
2009 } | |
2010 | |
2011 void QuicConnection::SendConnectionCloseWithDetails(QuicErrorCode error, | 1903 void QuicConnection::SendConnectionCloseWithDetails(QuicErrorCode error, |
2012 const string& details) { | 1904 const string& details) { |
2013 if (!connected_) { | 1905 if (!connected_) { |
2014 DVLOG(1) << "Connection is already closed."; | 1906 DVLOG(1) << "Connection is already closed."; |
2015 return; | 1907 return; |
2016 } | 1908 } |
2017 // If we're write blocked, WritePacket() will not send, but will capture the | 1909 // If we're write blocked, WritePacket() will not send, but will capture the |
2018 // serialized packet. | 1910 // serialized packet. |
2019 SendConnectionClosePacket(error, details); | 1911 SendConnectionClosePacket(error, details); |
2020 CloseConnection(error, ConnectionCloseSource::FROM_SELF); | 1912 CloseConnection(error, ConnectionCloseSource::FROM_SELF); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 | 1966 |
2075 DVLOG(1) << ENDPOINT << "Going away with error " | 1967 DVLOG(1) << ENDPOINT << "Going away with error " |
2076 << QuicUtils::ErrorToString(error) << " (" << error << ")"; | 1968 << QuicUtils::ErrorToString(error) << " (" << error << ")"; |
2077 | 1969 |
2078 // Opportunistically bundle an ack with this outgoing packet. | 1970 // Opportunistically bundle an ack with this outgoing packet. |
2079 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1971 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); |
2080 packet_generator_.AddControlFrame( | 1972 packet_generator_.AddControlFrame( |
2081 QuicFrame(new QuicGoAwayFrame(error, last_good_stream_id, reason))); | 1973 QuicFrame(new QuicGoAwayFrame(error, last_good_stream_id, reason))); |
2082 } | 1974 } |
2083 | 1975 |
2084 void QuicConnection::CloseFecGroupsBefore(QuicPacketNumber packet_number) { | |
2085 FecGroupMap::iterator it = group_map_.begin(); | |
2086 while (it != group_map_.end()) { | |
2087 // If the group doesn't protect this packet we can ignore it. | |
2088 if (!it->second->IsWaitingForPacketBefore(packet_number)) { | |
2089 ++it; | |
2090 continue; | |
2091 } | |
2092 QuicFecGroup* fec_group = it->second; | |
2093 DCHECK(!fec_group->CanRevive()); | |
2094 FecGroupMap::iterator next = it; | |
2095 ++next; | |
2096 group_map_.erase(it); | |
2097 delete fec_group; | |
2098 it = next; | |
2099 } | |
2100 } | |
2101 | |
2102 QuicByteCount QuicConnection::max_packet_length() const { | 1976 QuicByteCount QuicConnection::max_packet_length() const { |
2103 return packet_generator_.GetMaxPacketLength(); | 1977 return packet_generator_.GetMaxPacketLength(); |
2104 } | 1978 } |
2105 | 1979 |
2106 void QuicConnection::SetMaxPacketLength(QuicByteCount length) { | 1980 void QuicConnection::SetMaxPacketLength(QuicByteCount length) { |
2107 return packet_generator_.SetMaxPacketLength(LimitMaxPacketSize(length), | 1981 return packet_generator_.SetMaxPacketLength(LimitMaxPacketSize(length), |
2108 /*force=*/false); | 1982 /*force=*/false); |
2109 } | 1983 } |
2110 | 1984 |
2111 bool QuicConnection::HasQueuedData() const { | 1985 bool QuicConnection::HasQueuedData() const { |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2459 void QuicConnection::OnPathClosed(QuicPathId path_id) { | 2333 void QuicConnection::OnPathClosed(QuicPathId path_id) { |
2460 // Stop receiving packets on this path. | 2334 // Stop receiving packets on this path. |
2461 framer_.OnPathClosed(path_id); | 2335 framer_.OnPathClosed(path_id); |
2462 } | 2336 } |
2463 | 2337 |
2464 bool QuicConnection::ack_frame_updated() const { | 2338 bool QuicConnection::ack_frame_updated() const { |
2465 return received_packet_manager_.ack_frame_updated(); | 2339 return received_packet_manager_.ack_frame_updated(); |
2466 } | 2340 } |
2467 | 2341 |
2468 } // namespace net | 2342 } // namespace net |
OLD | NEW |