Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: net/quic/quic_connection.cc

Issue 682413002: Close the QUIC connection if too many sent or received packets are (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Remove_QUIC_VERSION_21_78604601
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 18 #include "base/logging.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/stringprintf.h"
20 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
21 #include "net/quic/crypto/quic_decrypter.h" 22 #include "net/quic/crypto/quic_decrypter.h"
22 #include "net/quic/crypto/quic_encrypter.h" 23 #include "net/quic/crypto/quic_encrypter.h"
23 #include "net/quic/iovector.h" 24 #include "net/quic/iovector.h"
24 #include "net/quic/quic_bandwidth.h" 25 #include "net/quic/quic_bandwidth.h"
25 #include "net/quic/quic_config.h" 26 #include "net/quic/quic_config.h"
26 #include "net/quic/quic_fec_group.h" 27 #include "net/quic/quic_fec_group.h"
27 #include "net/quic/quic_flags.h" 28 #include "net/quic/quic_flags.h"
28 #include "net/quic/quic_utils.h" 29 #include "net/quic/quic_utils.h"
29 30
30 using base::StringPiece; 31 using base::StringPiece;
32 using base::StringPrintf;
31 using base::hash_map; 33 using base::hash_map;
32 using base::hash_set; 34 using base::hash_set;
33 using std::list; 35 using std::list;
34 using std::make_pair; 36 using std::make_pair;
35 using std::max; 37 using std::max;
36 using std::min; 38 using std::min;
37 using std::numeric_limits; 39 using std::numeric_limits;
38 using std::set; 40 using std::set;
39 using std::string; 41 using std::string;
40 using std::vector; 42 using std::vector;
41 43
42 namespace net { 44 namespace net {
43 45
44 class QuicDecrypter; 46 class QuicDecrypter;
45 class QuicEncrypter; 47 class QuicEncrypter;
46 48
47 namespace { 49 namespace {
48 50
49 // The largest gap in packets we'll accept without closing the connection. 51 // The largest gap in packets we'll accept without closing the connection.
50 // This will likely have to be tuned. 52 // This will likely have to be tuned.
51 const QuicPacketSequenceNumber kMaxPacketGap = 5000; 53 const QuicPacketSequenceNumber kMaxPacketGap = 5000;
52 54
53 // Limit the number of FEC groups to two. If we get enough out of order packets 55 // Limit the number of FEC groups to two. If we get enough out of order packets
54 // that this becomes limiting, we can revisit. 56 // that this becomes limiting, we can revisit.
55 const size_t kMaxFecGroups = 2; 57 const size_t kMaxFecGroups = 2;
56 58
57 // Maximum number of acks received before sending an ack in response. 59 // Maximum number of acks received before sending an ack in response.
58 const size_t kMaxPacketsReceivedBeforeAckSend = 20; 60 const size_t kMaxPacketsReceivedBeforeAckSend = 20;
59 61
62 // Maximum number of tracked packets.
63 const size_t kMaxTrackedPackets = 5 * kMaxTcpCongestionWindow;;
64
60 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) { 65 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) {
61 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a; 66 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a;
62 return delta <= kMaxPacketGap; 67 return delta <= kMaxPacketGap;
63 } 68 }
64 69
65 // An alarm that is scheduled to send an ack if a timeout occurs. 70 // An alarm that is scheduled to send an ack if a timeout occurs.
66 class AckAlarm : public QuicAlarm::Delegate { 71 class AckAlarm : public QuicAlarm::Delegate {
67 public: 72 public:
68 explicit AckAlarm(QuicConnection* connection) 73 explicit AckAlarm(QuicConnection* connection)
69 : connection_(connection) { 74 : connection_(connection) {
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 DCHECK(!connected_); 880 DCHECK(!connected_);
876 } 881 }
877 882
878 // If there are new missing packets to report, send an ack immediately. 883 // If there are new missing packets to report, send an ack immediately.
879 if (received_packet_manager_.HasNewMissingPackets()) { 884 if (received_packet_manager_.HasNewMissingPackets()) {
880 ack_queued_ = true; 885 ack_queued_ = true;
881 ack_alarm_->Cancel(); 886 ack_alarm_->Cancel();
882 } 887 }
883 888
884 UpdateStopWaitingCount(); 889 UpdateStopWaitingCount();
885
886 ClearLastFrames(); 890 ClearLastFrames();
891 MaybeCloseIfTooManyOutstandingPackets();
887 } 892 }
888 893
889 void QuicConnection::MaybeQueueAck() { 894 void QuicConnection::MaybeQueueAck() {
890 // If the incoming packet was missing, send an ack immediately. 895 // If the incoming packet was missing, send an ack immediately.
891 ack_queued_ = received_packet_manager_.IsMissing( 896 ack_queued_ = received_packet_manager_.IsMissing(
892 last_header_.packet_sequence_number); 897 last_header_.packet_sequence_number);
893 898
894 if (!ack_queued_ && ShouldLastPacketInstigateAck()) { 899 if (!ack_queued_ && ShouldLastPacketInstigateAck()) {
895 if (ack_alarm_->IsSet()) { 900 if (ack_alarm_->IsSet()) {
896 ack_queued_ = true; 901 ack_queued_ = true;
(...skipping 20 matching lines...) Expand all
917 last_congestion_frames_.clear(); 922 last_congestion_frames_.clear();
918 last_stop_waiting_frames_.clear(); 923 last_stop_waiting_frames_.clear();
919 last_rst_frames_.clear(); 924 last_rst_frames_.clear();
920 last_goaway_frames_.clear(); 925 last_goaway_frames_.clear();
921 last_window_update_frames_.clear(); 926 last_window_update_frames_.clear();
922 last_blocked_frames_.clear(); 927 last_blocked_frames_.clear();
923 last_ping_frames_.clear(); 928 last_ping_frames_.clear();
924 last_close_frames_.clear(); 929 last_close_frames_.clear();
925 } 930 }
926 931
932 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() {
933 if (!FLAGS_quic_too_many_outstanding_packets) {
934 return;
935 }
936 // This occurs if we don't discard old packets we've sent fast enough.
937 // It's possible largest observed is less than least unacked.
938 if (sent_packet_manager_.largest_observed() >
939 (sent_packet_manager_.GetLeastUnacked() + kMaxTrackedPackets)) {
940 SendConnectionCloseWithDetails(
941 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS,
942 StringPrintf("More than %zu outstanding.", kMaxTrackedPackets));
943 }
944 // This occurs if there are received packet gaps and the peer does not raise
945 // the least unacked fast enough.
946 if (received_packet_manager_.NumTrackedPackets() > kMaxTrackedPackets) {
947 SendConnectionCloseWithDetails(
948 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS,
949 StringPrintf("More than %zu outstanding.", kMaxTrackedPackets));
950 }
951 }
952
927 QuicAckFrame* QuicConnection::CreateAckFrame() { 953 QuicAckFrame* QuicConnection::CreateAckFrame() {
928 QuicAckFrame* outgoing_ack = new QuicAckFrame(); 954 QuicAckFrame* outgoing_ack = new QuicAckFrame();
929 received_packet_manager_.UpdateReceivedPacketInfo( 955 received_packet_manager_.UpdateReceivedPacketInfo(
930 outgoing_ack, clock_->ApproximateNow()); 956 outgoing_ack, clock_->ApproximateNow());
931 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; 957 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack;
932 return outgoing_ack; 958 return outgoing_ack;
933 } 959 }
934 960
935 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() { 961 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() {
936 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_); 962 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_);
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 } 2073 }
2048 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2074 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2049 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2075 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2050 return true; 2076 return true;
2051 } 2077 }
2052 } 2078 }
2053 return false; 2079 return false;
2054 } 2080 }
2055 2081
2056 } // namespace net 2082 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698