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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") | 185 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") |
186 | 186 |
187 QuicConnection::QuicConnection(QuicConnectionId connection_id, | 187 QuicConnection::QuicConnection(QuicConnectionId connection_id, |
188 IPEndPoint address, | 188 IPEndPoint address, |
189 QuicConnectionHelperInterface* helper, | 189 QuicConnectionHelperInterface* helper, |
190 const PacketWriterFactory& writer_factory, | 190 const PacketWriterFactory& writer_factory, |
191 bool owns_writer, | 191 bool owns_writer, |
192 bool is_server, | 192 bool is_server, |
193 bool is_secure, | 193 bool is_secure, |
194 const QuicVersionVector& supported_versions) | 194 const QuicVersionVector& supported_versions) |
195 : framer_(supported_versions, helper->GetClock()->ApproximateNow(), | 195 : framer_(supported_versions, |
| 196 helper->GetClock()->ApproximateNow(), |
196 is_server), | 197 is_server), |
197 helper_(helper), | 198 helper_(helper), |
198 writer_(writer_factory.Create(this)), | 199 writer_(writer_factory.Create(this)), |
199 owns_writer_(owns_writer), | 200 owns_writer_(owns_writer), |
200 encryption_level_(ENCRYPTION_NONE), | 201 encryption_level_(ENCRYPTION_NONE), |
201 has_forward_secure_encrypter_(false), | 202 has_forward_secure_encrypter_(false), |
202 first_required_forward_secure_packet_(0), | 203 first_required_forward_secure_packet_(0), |
203 clock_(helper->GetClock()), | 204 clock_(helper->GetClock()), |
204 random_generator_(helper->GetRandomGenerator()), | 205 random_generator_(helper->GetRandomGenerator()), |
205 connection_id_(connection_id), | 206 connection_id_(connection_id), |
206 peer_address_(address), | 207 peer_address_(address), |
207 migrating_peer_port_(0), | 208 migrating_peer_port_(0), |
208 last_packet_decrypted_(false), | 209 last_packet_decrypted_(false), |
209 last_packet_revived_(false), | 210 last_packet_revived_(false), |
210 last_size_(0), | 211 last_size_(0), |
211 last_decrypted_packet_level_(ENCRYPTION_NONE), | 212 last_decrypted_packet_level_(ENCRYPTION_NONE), |
212 largest_seen_packet_with_ack_(0), | 213 largest_seen_packet_with_ack_(0), |
213 largest_seen_packet_with_stop_waiting_(0), | 214 largest_seen_packet_with_stop_waiting_(0), |
214 max_undecryptable_packets_(0), | 215 max_undecryptable_packets_(0), |
215 pending_version_negotiation_packet_(false), | 216 pending_version_negotiation_packet_(false), |
| 217 silent_close_enabled_(false), |
216 received_packet_manager_(&stats_), | 218 received_packet_manager_(&stats_), |
217 ack_queued_(false), | 219 ack_queued_(false), |
218 num_packets_received_since_last_ack_sent_(0), | 220 num_packets_received_since_last_ack_sent_(0), |
219 stop_waiting_count_(0), | 221 stop_waiting_count_(0), |
220 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), | 222 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), |
221 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), | 223 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), |
222 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 224 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
223 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), | 225 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), |
224 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), | 226 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), |
225 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), | 227 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), |
226 packet_generator_(connection_id_, &framer_, random_generator_, this), | 228 packet_generator_(connection_id_, &framer_, random_generator_, this), |
227 idle_network_timeout_(QuicTime::Delta::Infinite()), | 229 idle_network_timeout_(QuicTime::Delta::Infinite()), |
228 overall_connection_timeout_(QuicTime::Delta::Infinite()), | 230 overall_connection_timeout_(QuicTime::Delta::Infinite()), |
229 time_of_last_received_packet_(clock_->ApproximateNow()), | 231 time_of_last_received_packet_(clock_->ApproximateNow()), |
230 time_of_last_sent_new_packet_(clock_->ApproximateNow()), | 232 time_of_last_sent_new_packet_(clock_->ApproximateNow()), |
231 sequence_number_of_last_sent_packet_(0), | 233 sequence_number_of_last_sent_packet_(0), |
232 sent_packet_manager_( | 234 sent_packet_manager_( |
233 is_server, clock_, &stats_, | 235 is_server, |
| 236 clock_, |
| 237 &stats_, |
234 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, | 238 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, |
235 FLAGS_quic_use_time_loss_detection ? kTime : kNack, | 239 FLAGS_quic_use_time_loss_detection ? kTime : kNack, |
236 is_secure), | 240 is_secure), |
237 version_negotiation_state_(START_NEGOTIATION), | 241 version_negotiation_state_(START_NEGOTIATION), |
238 is_server_(is_server), | 242 is_server_(is_server), |
239 connected_(true), | 243 connected_(true), |
240 peer_ip_changed_(false), | 244 peer_ip_changed_(false), |
241 peer_port_changed_(false), | 245 peer_port_changed_(false), |
242 self_ip_changed_(false), | 246 self_ip_changed_(false), |
243 self_port_changed_(false), | 247 self_port_changed_(false), |
(...skipping 17 matching lines...) Expand all Loading... |
261 it != queued_packets_.end(); ++it) { | 265 it != queued_packets_.end(); ++it) { |
262 delete it->serialized_packet.retransmittable_frames; | 266 delete it->serialized_packet.retransmittable_frames; |
263 delete it->serialized_packet.packet; | 267 delete it->serialized_packet.packet; |
264 } | 268 } |
265 } | 269 } |
266 | 270 |
267 void QuicConnection::SetFromConfig(const QuicConfig& config) { | 271 void QuicConnection::SetFromConfig(const QuicConfig& config) { |
268 if (config.negotiated()) { | 272 if (config.negotiated()) { |
269 SetNetworkTimeouts(QuicTime::Delta::Infinite(), | 273 SetNetworkTimeouts(QuicTime::Delta::Infinite(), |
270 config.IdleConnectionStateLifetime()); | 274 config.IdleConnectionStateLifetime()); |
| 275 if (FLAGS_quic_allow_silent_close && config.SilentClose()) { |
| 276 silent_close_enabled_ = true; |
| 277 } |
271 } else { | 278 } else { |
272 SetNetworkTimeouts(config.max_time_before_crypto_handshake(), | 279 SetNetworkTimeouts(config.max_time_before_crypto_handshake(), |
273 config.max_idle_time_before_crypto_handshake()); | 280 config.max_idle_time_before_crypto_handshake()); |
274 } | 281 } |
275 | 282 |
276 sent_packet_manager_.SetFromConfig(config); | 283 sent_packet_manager_.SetFromConfig(config); |
277 if (FLAGS_allow_truncated_connection_ids_for_quic && | 284 if (FLAGS_allow_truncated_connection_ids_for_quic && |
278 config.HasReceivedBytesForConnectionId() && | 285 config.HasReceivedBytesForConnectionId() && |
279 can_truncate_connection_ids_) { | 286 can_truncate_connection_ids_) { |
280 packet_generator_.SetConnectionIdLength( | 287 packet_generator_.SetConnectionIdLength( |
(...skipping 25 matching lines...) Expand all Loading... |
306 return true; | 313 return true; |
307 } | 314 } |
308 } | 315 } |
309 | 316 |
310 return false; | 317 return false; |
311 } | 318 } |
312 | 319 |
313 void QuicConnection::OnError(QuicFramer* framer) { | 320 void QuicConnection::OnError(QuicFramer* framer) { |
314 // Packets that we can not or have not decrypted are dropped. | 321 // Packets that we can not or have not decrypted are dropped. |
315 // TODO(rch): add stats to measure this. | 322 // TODO(rch): add stats to measure this. |
316 if (FLAGS_quic_drop_junk_packets) { | 323 if (!connected_ || last_packet_decrypted_ == false) { |
317 if (!connected_ || last_packet_decrypted_ == false) { | 324 return; |
318 return; | |
319 } | |
320 } else { | |
321 if (!connected_ || framer->error() == QUIC_DECRYPTION_FAILURE) { | |
322 return; | |
323 } | |
324 } | 325 } |
325 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); | 326 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); |
326 } | 327 } |
327 | 328 |
328 void QuicConnection::OnPacket() { | 329 void QuicConnection::OnPacket() { |
329 DCHECK(last_stream_frames_.empty() && | 330 DCHECK(last_stream_frames_.empty() && |
330 last_ack_frames_.empty() && | 331 last_ack_frames_.empty() && |
331 last_congestion_frames_.empty() && | 332 last_congestion_frames_.empty() && |
332 last_stop_waiting_frames_.empty() && | 333 last_stop_waiting_frames_.empty() && |
333 last_rst_frames_.empty() && | 334 last_rst_frames_.empty() && |
(...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 // disconnect in that case. | 1848 // disconnect in that case. |
1848 CloseConnection(error, false); | 1849 CloseConnection(error, false); |
1849 } | 1850 } |
1850 } | 1851 } |
1851 | 1852 |
1852 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, | 1853 void QuicConnection::SendConnectionClosePacket(QuicErrorCode error, |
1853 const string& details) { | 1854 const string& details) { |
1854 DVLOG(1) << ENDPOINT << "Force closing " << connection_id() | 1855 DVLOG(1) << ENDPOINT << "Force closing " << connection_id() |
1855 << " with error " << QuicUtils::ErrorToString(error) | 1856 << " with error " << QuicUtils::ErrorToString(error) |
1856 << " (" << error << ") " << details; | 1857 << " (" << error << ") " << details; |
| 1858 // Don't send explicit connection close packets for timeouts. |
| 1859 // This is particularly important on mobile, where connections are short. |
| 1860 if (silent_close_enabled_ && |
| 1861 error == QuicErrorCode::QUIC_CONNECTION_TIMED_OUT) { |
| 1862 return; |
| 1863 } |
1857 ScopedPacketBundler ack_bundler(this, SEND_ACK); | 1864 ScopedPacketBundler ack_bundler(this, SEND_ACK); |
1858 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); | 1865 QuicConnectionCloseFrame* frame = new QuicConnectionCloseFrame(); |
1859 frame->error_code = error; | 1866 frame->error_code = error; |
1860 frame->error_details = details; | 1867 frame->error_details = details; |
1861 packet_generator_.AddControlFrame(QuicFrame(frame)); | 1868 packet_generator_.AddControlFrame(QuicFrame(frame)); |
1862 packet_generator_.FlushAllQueuedFrames(); | 1869 packet_generator_.FlushAllQueuedFrames(); |
1863 } | 1870 } |
1864 | 1871 |
1865 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { | 1872 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { |
1866 if (!connected_) { | 1873 if (!connected_) { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 } | 2099 } |
2093 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2100 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { |
2094 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2101 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { |
2095 return true; | 2102 return true; |
2096 } | 2103 } |
2097 } | 2104 } |
2098 return false; | 2105 return false; |
2099 } | 2106 } |
2100 | 2107 |
2101 } // namespace net | 2108 } // namespace net |
OLD | NEW |