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> |
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/format_macros.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
22 #include "net/quic/crypto/quic_decrypter.h" | 23 #include "net/quic/crypto/quic_decrypter.h" |
23 #include "net/quic/crypto/quic_encrypter.h" | 24 #include "net/quic/crypto/quic_encrypter.h" |
24 #include "net/quic/iovector.h" | 25 #include "net/quic/iovector.h" |
25 #include "net/quic/quic_bandwidth.h" | 26 #include "net/quic/quic_bandwidth.h" |
26 #include "net/quic/quic_config.h" | 27 #include "net/quic/quic_config.h" |
27 #include "net/quic/quic_fec_group.h" | 28 #include "net/quic/quic_fec_group.h" |
(...skipping 22 matching lines...) Expand all Loading... |
50 | 51 |
51 // The largest gap in packets we'll accept without closing the connection. | 52 // The largest gap in packets we'll accept without closing the connection. |
52 // This will likely have to be tuned. | 53 // This will likely have to be tuned. |
53 const QuicPacketSequenceNumber kMaxPacketGap = 5000; | 54 const QuicPacketSequenceNumber kMaxPacketGap = 5000; |
54 | 55 |
55 // Limit the number of FEC groups to two. If we get enough out of order packets | 56 // Limit the number of FEC groups to two. If we get enough out of order packets |
56 // that this becomes limiting, we can revisit. | 57 // that this becomes limiting, we can revisit. |
57 const size_t kMaxFecGroups = 2; | 58 const size_t kMaxFecGroups = 2; |
58 | 59 |
59 // Maximum number of acks received before sending an ack in response. | 60 // Maximum number of acks received before sending an ack in response. |
60 const size_t kMaxPacketsReceivedBeforeAckSend = 20; | 61 const QuicPacketCount kMaxPacketsReceivedBeforeAckSend = 20; |
61 | 62 |
62 // Maximum number of tracked packets. | 63 // Maximum number of tracked packets. |
63 const size_t kMaxTrackedPackets = 5 * kMaxTcpCongestionWindow;; | 64 const QuicPacketCount kMaxTrackedPackets = 5 * kMaxTcpCongestionWindow; |
64 | 65 |
65 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) { | 66 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) { |
66 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a; | 67 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a; |
67 return delta <= kMaxPacketGap; | 68 return delta <= kMaxPacketGap; |
68 } | 69 } |
69 | 70 |
70 // An alarm that is scheduled to send an ack if a timeout occurs. | 71 // An alarm that is scheduled to send an ack if a timeout occurs. |
71 class AckAlarm : public QuicAlarm::Delegate { | 72 class AckAlarm : public QuicAlarm::Delegate { |
72 public: | 73 public: |
73 explicit AckAlarm(QuicConnection* connection) | 74 explicit AckAlarm(QuicConnection* connection) |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 sent_packet_manager_.SetFromConfig(config); | 276 sent_packet_manager_.SetFromConfig(config); |
276 if (FLAGS_allow_truncated_connection_ids_for_quic && | 277 if (FLAGS_allow_truncated_connection_ids_for_quic && |
277 config.HasReceivedBytesForConnectionId() && | 278 config.HasReceivedBytesForConnectionId() && |
278 can_truncate_connection_ids_) { | 279 can_truncate_connection_ids_) { |
279 packet_generator_.SetConnectionIdLength( | 280 packet_generator_.SetConnectionIdLength( |
280 config.ReceivedBytesForConnectionId()); | 281 config.ReceivedBytesForConnectionId()); |
281 } | 282 } |
282 max_undecryptable_packets_ = config.max_undecryptable_packets(); | 283 max_undecryptable_packets_ = config.max_undecryptable_packets(); |
283 } | 284 } |
284 | 285 |
285 void QuicConnection::ResumeConnectionState( | 286 bool QuicConnection::ResumeConnectionState( |
286 const CachedNetworkParameters& cached_network_params) { | 287 const CachedNetworkParameters& cached_network_params) { |
287 sent_packet_manager_.ResumeConnectionState(cached_network_params); | 288 return sent_packet_manager_.ResumeConnectionState(cached_network_params); |
288 } | 289 } |
289 | 290 |
290 void QuicConnection::SetNumOpenStreams(size_t num_streams) { | 291 void QuicConnection::SetNumOpenStreams(size_t num_streams) { |
291 sent_packet_manager_.SetNumOpenStreams(num_streams); | 292 sent_packet_manager_.SetNumOpenStreams(num_streams); |
292 } | 293 } |
293 | 294 |
294 bool QuicConnection::SelectMutualVersion( | 295 bool QuicConnection::SelectMutualVersion( |
295 const QuicVersionVector& available_versions) { | 296 const QuicVersionVector& available_versions) { |
296 // Try to find the highest mutual version by iterating over supported | 297 // Try to find the highest mutual version by iterating over supported |
297 // versions, starting with the highest, and breaking out of the loop once we | 298 // versions, starting with the highest, and breaking out of the loop once we |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() { | 943 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() { |
943 if (!FLAGS_quic_too_many_outstanding_packets) { | 944 if (!FLAGS_quic_too_many_outstanding_packets) { |
944 return; | 945 return; |
945 } | 946 } |
946 // This occurs if we don't discard old packets we've sent fast enough. | 947 // This occurs if we don't discard old packets we've sent fast enough. |
947 // It's possible largest observed is less than least unacked. | 948 // It's possible largest observed is less than least unacked. |
948 if (sent_packet_manager_.largest_observed() > | 949 if (sent_packet_manager_.largest_observed() > |
949 (sent_packet_manager_.GetLeastUnacked() + kMaxTrackedPackets)) { | 950 (sent_packet_manager_.GetLeastUnacked() + kMaxTrackedPackets)) { |
950 SendConnectionCloseWithDetails( | 951 SendConnectionCloseWithDetails( |
951 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS, | 952 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS, |
952 StringPrintf("More than %zu outstanding.", kMaxTrackedPackets)); | 953 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets)); |
953 } | 954 } |
954 // This occurs if there are received packet gaps and the peer does not raise | 955 // This occurs if there are received packet gaps and the peer does not raise |
955 // the least unacked fast enough. | 956 // the least unacked fast enough. |
956 if (received_packet_manager_.NumTrackedPackets() > kMaxTrackedPackets) { | 957 if (received_packet_manager_.NumTrackedPackets() > kMaxTrackedPackets) { |
957 SendConnectionCloseWithDetails( | 958 SendConnectionCloseWithDetails( |
958 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, | 959 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, |
959 StringPrintf("More than %zu outstanding.", kMaxTrackedPackets)); | 960 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets)); |
960 } | 961 } |
961 } | 962 } |
962 | 963 |
963 QuicAckFrame* QuicConnection::CreateAckFrame() { | 964 QuicAckFrame* QuicConnection::CreateAckFrame() { |
964 QuicAckFrame* outgoing_ack = new QuicAckFrame(); | 965 QuicAckFrame* outgoing_ack = new QuicAckFrame(); |
965 received_packet_manager_.UpdateReceivedPacketInfo( | 966 received_packet_manager_.UpdateReceivedPacketInfo( |
966 outgoing_ack, clock_->ApproximateNow()); | 967 outgoing_ack, clock_->ApproximateNow()); |
967 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; | 968 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; |
968 return outgoing_ack; | 969 return outgoing_ack; |
969 } | 970 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1132 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); |
1132 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); | 1133 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); |
1133 } | 1134 } |
1134 | 1135 |
1135 const QuicConnectionStats& QuicConnection::GetStats() { | 1136 const QuicConnectionStats& QuicConnection::GetStats() { |
1136 // Update rtt and estimated bandwidth. | 1137 // Update rtt and estimated bandwidth. |
1137 stats_.min_rtt_us = | 1138 stats_.min_rtt_us = |
1138 sent_packet_manager_.GetRttStats()->min_rtt().ToMicroseconds(); | 1139 sent_packet_manager_.GetRttStats()->min_rtt().ToMicroseconds(); |
1139 stats_.srtt_us = | 1140 stats_.srtt_us = |
1140 sent_packet_manager_.GetRttStats()->smoothed_rtt().ToMicroseconds(); | 1141 sent_packet_manager_.GetRttStats()->smoothed_rtt().ToMicroseconds(); |
1141 stats_.estimated_bandwidth = | 1142 stats_.estimated_bandwidth = sent_packet_manager_.BandwidthEstimate(); |
1142 sent_packet_manager_.BandwidthEstimate().ToBytesPerSecond(); | |
1143 stats_.max_packet_size = packet_generator_.max_packet_length(); | 1143 stats_.max_packet_size = packet_generator_.max_packet_length(); |
1144 return stats_; | 1144 return stats_; |
1145 } | 1145 } |
1146 | 1146 |
1147 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, | 1147 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, |
1148 const IPEndPoint& peer_address, | 1148 const IPEndPoint& peer_address, |
1149 const QuicEncryptedPacket& packet) { | 1149 const QuicEncryptedPacket& packet) { |
1150 if (!connected_) { | 1150 if (!connected_) { |
1151 return; | 1151 return; |
1152 } | 1152 } |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 } | 2092 } |
2093 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2093 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { |
2094 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2094 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { |
2095 return true; | 2095 return true; |
2096 } | 2096 } |
2097 } | 2097 } |
2098 return false; | 2098 return false; |
2099 } | 2099 } |
2100 | 2100 |
2101 } // namespace net | 2101 } // namespace net |
OLD | NEW |