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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 namespace { | 47 namespace { |
48 | 48 |
49 // The largest gap in packets we'll accept without closing the connection. | 49 // The largest gap in packets we'll accept without closing the connection. |
50 // This will likely have to be tuned. | 50 // This will likely have to be tuned. |
51 const QuicPacketSequenceNumber kMaxPacketGap = 5000; | 51 const QuicPacketSequenceNumber kMaxPacketGap = 5000; |
52 | 52 |
53 // Limit the number of FEC groups to two. If we get enough out of order packets | 53 // Limit the number of FEC groups to two. If we get enough out of order packets |
54 // that this becomes limiting, we can revisit. | 54 // that this becomes limiting, we can revisit. |
55 const size_t kMaxFecGroups = 2; | 55 const size_t kMaxFecGroups = 2; |
56 | 56 |
57 // Limit the number of undecryptable packets we buffer in | |
58 // expectation of the CHLO/SHLO arriving. | |
59 const size_t kMaxUndecryptablePackets = 10; | |
60 | |
61 // Maximum number of acks received before sending an ack in response. | 57 // Maximum number of acks received before sending an ack in response. |
62 const size_t kMaxPacketsReceivedBeforeAckSend = 20; | 58 const size_t kMaxPacketsReceivedBeforeAckSend = 20; |
63 | 59 |
64 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) { | 60 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) { |
65 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a; | 61 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a; |
66 return delta <= kMaxPacketGap; | 62 return delta <= kMaxPacketGap; |
67 } | 63 } |
68 | 64 |
69 // An alarm that is scheduled to send an ack if a timeout occurs. | 65 // An alarm that is scheduled to send an ack if a timeout occurs. |
70 class AckAlarm : public QuicAlarm::Delegate { | 66 class AckAlarm : public QuicAlarm::Delegate { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 clock_(helper->GetClock()), | 194 clock_(helper->GetClock()), |
199 random_generator_(helper->GetRandomGenerator()), | 195 random_generator_(helper->GetRandomGenerator()), |
200 connection_id_(connection_id), | 196 connection_id_(connection_id), |
201 peer_address_(address), | 197 peer_address_(address), |
202 migrating_peer_port_(0), | 198 migrating_peer_port_(0), |
203 last_packet_revived_(false), | 199 last_packet_revived_(false), |
204 last_size_(0), | 200 last_size_(0), |
205 last_decrypted_packet_level_(ENCRYPTION_NONE), | 201 last_decrypted_packet_level_(ENCRYPTION_NONE), |
206 largest_seen_packet_with_ack_(0), | 202 largest_seen_packet_with_ack_(0), |
207 largest_seen_packet_with_stop_waiting_(0), | 203 largest_seen_packet_with_stop_waiting_(0), |
| 204 max_undecryptable_packets_(0), |
208 pending_version_negotiation_packet_(false), | 205 pending_version_negotiation_packet_(false), |
209 received_packet_manager_(&stats_), | 206 received_packet_manager_(&stats_), |
210 ack_queued_(false), | 207 ack_queued_(false), |
211 num_packets_received_since_last_ack_sent_(0), | 208 num_packets_received_since_last_ack_sent_(0), |
212 stop_waiting_count_(0), | 209 stop_waiting_count_(0), |
213 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), | 210 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), |
214 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), | 211 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), |
215 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 212 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
216 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 213 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
217 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), | 214 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 SetNetworkTimeouts(QuicTime::Delta::Infinite(), | 262 SetNetworkTimeouts(QuicTime::Delta::Infinite(), |
266 config.IdleConnectionStateLifetime()); | 263 config.IdleConnectionStateLifetime()); |
267 } else { | 264 } else { |
268 SetNetworkTimeouts(config.max_time_before_crypto_handshake(), | 265 SetNetworkTimeouts(config.max_time_before_crypto_handshake(), |
269 config.max_idle_time_before_crypto_handshake()); | 266 config.max_idle_time_before_crypto_handshake()); |
270 } | 267 } |
271 } else { | 268 } else { |
272 SetIdleNetworkTimeout(config.IdleConnectionStateLifetime()); | 269 SetIdleNetworkTimeout(config.IdleConnectionStateLifetime()); |
273 } | 270 } |
274 sent_packet_manager_.SetFromConfig(config); | 271 sent_packet_manager_.SetFromConfig(config); |
| 272 max_undecryptable_packets_ = config.max_undecryptable_packets(); |
275 } | 273 } |
276 | 274 |
277 bool QuicConnection::SelectMutualVersion( | 275 bool QuicConnection::SelectMutualVersion( |
278 const QuicVersionVector& available_versions) { | 276 const QuicVersionVector& available_versions) { |
279 // Try to find the highest mutual version by iterating over supported | 277 // Try to find the highest mutual version by iterating over supported |
280 // versions, starting with the highest, and breaking out of the loop once we | 278 // versions, starting with the highest, and breaking out of the loop once we |
281 // find a matching version in the provided available_versions vector. | 279 // find a matching version in the provided available_versions vector. |
282 const QuicVersionVector& supported_versions = framer_.supported_versions(); | 280 const QuicVersionVector& supported_versions = framer_.supported_versions(); |
283 for (size_t i = 0; i < supported_versions.size(); ++i) { | 281 for (size_t i = 0; i < supported_versions.size(); ++i) { |
284 const QuicVersion& version = supported_versions[i]; | 282 const QuicVersion& version = supported_versions[i]; |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 CheckForAddressMigration(self_address, peer_address); | 1108 CheckForAddressMigration(self_address, peer_address); |
1111 | 1109 |
1112 stats_.bytes_received += packet.length(); | 1110 stats_.bytes_received += packet.length(); |
1113 ++stats_.packets_received; | 1111 ++stats_.packets_received; |
1114 | 1112 |
1115 if (!framer_.ProcessPacket(packet)) { | 1113 if (!framer_.ProcessPacket(packet)) { |
1116 // If we are unable to decrypt this packet, it might be | 1114 // If we are unable to decrypt this packet, it might be |
1117 // because the CHLO or SHLO packet was lost. | 1115 // because the CHLO or SHLO packet was lost. |
1118 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { | 1116 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { |
1119 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && | 1117 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && |
1120 undecryptable_packets_.size() < kMaxUndecryptablePackets) { | 1118 undecryptable_packets_.size() < max_undecryptable_packets_) { |
1121 QueueUndecryptablePacket(packet); | 1119 QueueUndecryptablePacket(packet); |
1122 } else if (debug_visitor_.get() != nullptr) { | 1120 } else if (debug_visitor_.get() != nullptr) { |
1123 debug_visitor_->OnUndecryptablePacket(); | 1121 debug_visitor_->OnUndecryptablePacket(); |
1124 } | 1122 } |
1125 } | 1123 } |
1126 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " | 1124 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " |
1127 << last_header_.packet_sequence_number; | 1125 << last_header_.packet_sequence_number; |
1128 return; | 1126 return; |
1129 } | 1127 } |
1130 | 1128 |
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 } | 2031 } |
2034 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2032 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { |
2035 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2033 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { |
2036 return true; | 2034 return true; |
2037 } | 2035 } |
2038 } | 2036 } |
2039 return false; | 2037 return false; |
2040 } | 2038 } |
2041 | 2039 |
2042 } // namespace net | 2040 } // namespace net |
OLD | NEW |