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

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

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 sent_packet_manager_( 230 sent_packet_manager_(
226 is_server, clock_, &stats_, 231 is_server, clock_, &stats_,
227 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, 232 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic,
228 FLAGS_quic_use_time_loss_detection ? kTime : kNack), 233 FLAGS_quic_use_time_loss_detection ? kTime : kNack),
229 version_negotiation_state_(START_NEGOTIATION), 234 version_negotiation_state_(START_NEGOTIATION),
230 is_server_(is_server), 235 is_server_(is_server),
231 connected_(true), 236 connected_(true),
232 peer_ip_changed_(false), 237 peer_ip_changed_(false),
233 peer_port_changed_(false), 238 peer_port_changed_(false),
234 self_ip_changed_(false), 239 self_ip_changed_(false),
235 self_port_changed_(false) { 240 self_port_changed_(false),
241 can_truncate_connection_ids_(true) {
236 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " 242 DVLOG(1) << ENDPOINT << "Created connection with connection_id: "
237 << connection_id; 243 << connection_id;
238 if (!FLAGS_quic_unified_timeouts) { 244 if (!FLAGS_quic_unified_timeouts) {
239 timeout_alarm_->Set(clock_->ApproximateNow().Add(idle_network_timeout_)); 245 timeout_alarm_->Set(clock_->ApproximateNow().Add(idle_network_timeout_));
240 } 246 }
241 framer_.set_visitor(this); 247 framer_.set_visitor(this);
242 framer_.set_received_entropy_calculator(&received_packet_manager_); 248 framer_.set_received_entropy_calculator(&received_packet_manager_);
243 stats_.connection_creation_time = clock_->ApproximateNow(); 249 stats_.connection_creation_time = clock_->ApproximateNow();
244 sent_packet_manager_.set_network_change_visitor(this); 250 sent_packet_manager_.set_network_change_visitor(this);
245 } 251 }
(...skipping 17 matching lines...) Expand all
263 SetNetworkTimeouts(QuicTime::Delta::Infinite(), 269 SetNetworkTimeouts(QuicTime::Delta::Infinite(),
264 config.IdleConnectionStateLifetime()); 270 config.IdleConnectionStateLifetime());
265 } else { 271 } else {
266 SetNetworkTimeouts(config.max_time_before_crypto_handshake(), 272 SetNetworkTimeouts(config.max_time_before_crypto_handshake(),
267 config.max_idle_time_before_crypto_handshake()); 273 config.max_idle_time_before_crypto_handshake());
268 } 274 }
269 } else { 275 } else {
270 SetIdleNetworkTimeout(config.IdleConnectionStateLifetime()); 276 SetIdleNetworkTimeout(config.IdleConnectionStateLifetime());
271 } 277 }
272 sent_packet_manager_.SetFromConfig(config); 278 sent_packet_manager_.SetFromConfig(config);
279 if (FLAGS_allow_truncated_connection_ids_for_quic &&
280 config.HasReceivedBytesForConnectionId() &&
281 can_truncate_connection_ids_) {
282 packet_generator_.SetConnectionIdLength(
283 config.ReceivedBytesForConnectionId());
284 }
273 max_undecryptable_packets_ = config.max_undecryptable_packets(); 285 max_undecryptable_packets_ = config.max_undecryptable_packets();
274 } 286 }
275 287
276 bool QuicConnection::SelectMutualVersion( 288 bool QuicConnection::SelectMutualVersion(
277 const QuicVersionVector& available_versions) { 289 const QuicVersionVector& available_versions) {
278 // Try to find the highest mutual version by iterating over supported 290 // Try to find the highest mutual version by iterating over supported
279 // versions, starting with the highest, and breaking out of the loop once we 291 // versions, starting with the highest, and breaking out of the loop once we
280 // find a matching version in the provided available_versions vector. 292 // find a matching version in the provided available_versions vector.
281 const QuicVersionVector& supported_versions = framer_.supported_versions(); 293 const QuicVersionVector& supported_versions = framer_.supported_versions();
282 for (size_t i = 0; i < supported_versions.size(); ++i) { 294 for (size_t i = 0; i < supported_versions.size(); ++i) {
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 DCHECK(!connected_); 880 DCHECK(!connected_);
869 } 881 }
870 882
871 // 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.
872 if (received_packet_manager_.HasNewMissingPackets()) { 884 if (received_packet_manager_.HasNewMissingPackets()) {
873 ack_queued_ = true; 885 ack_queued_ = true;
874 ack_alarm_->Cancel(); 886 ack_alarm_->Cancel();
875 } 887 }
876 888
877 UpdateStopWaitingCount(); 889 UpdateStopWaitingCount();
878
879 ClearLastFrames(); 890 ClearLastFrames();
891 MaybeCloseIfTooManyOutstandingPackets();
880 } 892 }
881 893
882 void QuicConnection::MaybeQueueAck() { 894 void QuicConnection::MaybeQueueAck() {
883 // If the incoming packet was missing, send an ack immediately. 895 // If the incoming packet was missing, send an ack immediately.
884 ack_queued_ = received_packet_manager_.IsMissing( 896 ack_queued_ = received_packet_manager_.IsMissing(
885 last_header_.packet_sequence_number); 897 last_header_.packet_sequence_number);
886 898
887 if (!ack_queued_ && ShouldLastPacketInstigateAck()) { 899 if (!ack_queued_ && ShouldLastPacketInstigateAck()) {
888 if (ack_alarm_->IsSet()) { 900 if (ack_alarm_->IsSet()) {
889 ack_queued_ = true; 901 ack_queued_ = true;
(...skipping 20 matching lines...) Expand all
910 last_congestion_frames_.clear(); 922 last_congestion_frames_.clear();
911 last_stop_waiting_frames_.clear(); 923 last_stop_waiting_frames_.clear();
912 last_rst_frames_.clear(); 924 last_rst_frames_.clear();
913 last_goaway_frames_.clear(); 925 last_goaway_frames_.clear();
914 last_window_update_frames_.clear(); 926 last_window_update_frames_.clear();
915 last_blocked_frames_.clear(); 927 last_blocked_frames_.clear();
916 last_ping_frames_.clear(); 928 last_ping_frames_.clear();
917 last_close_frames_.clear(); 929 last_close_frames_.clear();
918 } 930 }
919 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
920 QuicAckFrame* QuicConnection::CreateAckFrame() { 953 QuicAckFrame* QuicConnection::CreateAckFrame() {
921 QuicAckFrame* outgoing_ack = new QuicAckFrame(); 954 QuicAckFrame* outgoing_ack = new QuicAckFrame();
922 received_packet_manager_.UpdateReceivedPacketInfo( 955 received_packet_manager_.UpdateReceivedPacketInfo(
923 outgoing_ack, clock_->ApproximateNow()); 956 outgoing_ack, clock_->ApproximateNow());
924 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; 957 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack;
925 return outgoing_ack; 958 return outgoing_ack;
926 } 959 }
927 960
928 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() { 961 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() {
929 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
2040 } 2073 }
2041 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2074 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2042 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2075 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2043 return true; 2076 return true;
2044 } 2077 }
2045 } 2078 }
2046 return false; 2079 return false;
2047 } 2080 }
2048 2081
2049 } // 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