| 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 largest_received_packet_size_(0), | 311 largest_received_packet_size_(0), |
| 312 goaway_sent_(false), | 312 goaway_sent_(false), |
| 313 goaway_received_(false), | 313 goaway_received_(false), |
| 314 multipath_enabled_(false) { | 314 multipath_enabled_(false) { |
| 315 DVLOG(1) << ENDPOINT | 315 DVLOG(1) << ENDPOINT |
| 316 << "Created connection with connection_id: " << connection_id; | 316 << "Created connection with connection_id: " << connection_id; |
| 317 framer_.set_visitor(this); | 317 framer_.set_visitor(this); |
| 318 framer_.set_received_entropy_calculator(&received_packet_manager_); | 318 framer_.set_received_entropy_calculator(&received_packet_manager_); |
| 319 last_stop_waiting_frame_.least_unacked = 0; | 319 last_stop_waiting_frame_.least_unacked = 0; |
| 320 stats_.connection_creation_time = clock_->ApproximateNow(); | 320 stats_.connection_creation_time = clock_->ApproximateNow(); |
| 321 // TODO(ianswett): Supply the NetworkChangeVisitor as a constructor argument |
| 322 // and make it required non-null, because it's always used. |
| 321 sent_packet_manager_->SetNetworkChangeVisitor(this); | 323 sent_packet_manager_->SetNetworkChangeVisitor(this); |
| 322 // Allow the packet writer to potentially reduce the packet size to a value | 324 // Allow the packet writer to potentially reduce the packet size to a value |
| 323 // even smaller than kDefaultMaxPacketSize. | 325 // even smaller than kDefaultMaxPacketSize. |
| 324 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER | 326 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER |
| 325 ? kDefaultServerMaxPacketSize | 327 ? kDefaultServerMaxPacketSize |
| 326 : kDefaultMaxPacketSize); | 328 : kDefaultMaxPacketSize); |
| 327 received_packet_manager_.SetVersion(version()); | 329 received_packet_manager_.SetVersion(version()); |
| 328 } | 330 } |
| 329 | 331 |
| 330 QuicConnection::~QuicConnection() { | 332 QuicConnection::~QuicConnection() { |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 return true; | 693 return true; |
| 692 } | 694 } |
| 693 | 695 |
| 694 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { | 696 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { |
| 695 DCHECK(connected_); | 697 DCHECK(connected_); |
| 696 if (debug_visitor_ != nullptr) { | 698 if (debug_visitor_ != nullptr) { |
| 697 debug_visitor_->OnStreamFrame(frame); | 699 debug_visitor_->OnStreamFrame(frame); |
| 698 } | 700 } |
| 699 if (frame.stream_id != kCryptoStreamId && | 701 if (frame.stream_id != kCryptoStreamId && |
| 700 last_decrypted_packet_level_ == ENCRYPTION_NONE) { | 702 last_decrypted_packet_level_ == ENCRYPTION_NONE) { |
| 701 if (FLAGS_quic_detect_memory_corrpution && | 703 if (MaybeConsiderAsMemoryCorruption(frame)) { |
| 702 MaybeConsiderAsMemoryCorruption(frame)) { | |
| 703 CloseConnection(QUIC_MAYBE_CORRUPTED_MEMORY, | 704 CloseConnection(QUIC_MAYBE_CORRUPTED_MEMORY, |
| 704 "Received crypto frame on non crypto stream.", | 705 "Received crypto frame on non crypto stream.", |
| 705 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 706 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 706 return false; | 707 return false; |
| 707 } | 708 } |
| 708 | 709 |
| 709 QUIC_BUG << ENDPOINT | 710 QUIC_BUG << ENDPOINT |
| 710 << "Received an unencrypted data frame: closing connection" | 711 << "Received an unencrypted data frame: closing connection" |
| 711 << " packet_number:" << last_header_.packet_number | 712 << " packet_number:" << last_header_.packet_number |
| 712 << " stream_id:" << frame.stream_id | 713 << " stream_id:" << frame.stream_id |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && | 1674 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && |
| 1674 last_send_for_timeout_ <= time_of_last_received_packet_) { | 1675 last_send_for_timeout_ <= time_of_last_received_packet_) { |
| 1675 last_send_for_timeout_ = packet_send_time; | 1676 last_send_for_timeout_ = packet_send_time; |
| 1676 } | 1677 } |
| 1677 } | 1678 } |
| 1678 SetPingAlarm(); | 1679 SetPingAlarm(); |
| 1679 MaybeSetMtuAlarm(); | 1680 MaybeSetMtuAlarm(); |
| 1680 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " | 1681 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " |
| 1681 << packet_send_time.ToDebuggingValue(); | 1682 << packet_send_time.ToDebuggingValue(); |
| 1682 | 1683 |
| 1683 // TODO(ianswett): Change the packet number length and other packet creator | 1684 if (!FLAGS_quic_simple_packet_number_length) { |
| 1684 // options by a more explicit API than setting a struct value directly, | 1685 // TODO(ianswett): Change the packet number length and other packet creator |
| 1685 // perhaps via the NetworkChangeVisitor. | 1686 // options by a more explicit API than setting a struct value directly, |
| 1686 packet_generator_.UpdateSequenceNumberLength( | 1687 // perhaps via the NetworkChangeVisitor. |
| 1687 sent_packet_manager_->GetLeastPacketAwaitedByPeer(packet->path_id), | 1688 packet_generator_.UpdateSequenceNumberLength( |
| 1688 sent_packet_manager_->EstimateMaxPacketsInFlight(max_packet_length())); | 1689 sent_packet_manager_->GetLeastPacketAwaitedByPeer(packet->path_id), |
| 1690 sent_packet_manager_->EstimateMaxPacketsInFlight(max_packet_length())); |
| 1691 } |
| 1689 | 1692 |
| 1690 bool reset_retransmission_alarm = sent_packet_manager_->OnPacketSent( | 1693 bool reset_retransmission_alarm = sent_packet_manager_->OnPacketSent( |
| 1691 packet, packet->original_path_id, packet->original_packet_number, | 1694 packet, packet->original_path_id, packet->original_packet_number, |
| 1692 packet_send_time, packet->transmission_type, IsRetransmittable(*packet)); | 1695 packet_send_time, packet->transmission_type, IsRetransmittable(*packet)); |
| 1693 | 1696 |
| 1694 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { | 1697 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { |
| 1695 SetRetransmissionAlarm(); | 1698 SetRetransmissionAlarm(); |
| 1696 } | 1699 } |
| 1697 | 1700 |
| 1701 if (FLAGS_quic_simple_packet_number_length) { |
| 1702 // The packet number length must be updated after OnPacketSent, because it |
| 1703 // may change the packet number length in packet. |
| 1704 packet_generator_.UpdateSequenceNumberLength( |
| 1705 sent_packet_manager_->GetLeastPacketAwaitedByPeer(packet->path_id), |
| 1706 sent_packet_manager_->EstimateMaxPacketsInFlight(max_packet_length())); |
| 1707 } |
| 1708 |
| 1698 stats_.bytes_sent += result.bytes_written; | 1709 stats_.bytes_sent += result.bytes_written; |
| 1699 ++stats_.packets_sent; | 1710 ++stats_.packets_sent; |
| 1700 if (packet->transmission_type != NOT_RETRANSMISSION) { | 1711 if (packet->transmission_type != NOT_RETRANSMISSION) { |
| 1701 stats_.bytes_retransmitted += result.bytes_written; | 1712 stats_.bytes_retransmitted += result.bytes_written; |
| 1702 ++stats_.packets_retransmitted; | 1713 ++stats_.packets_retransmitted; |
| 1703 } | 1714 } |
| 1704 | 1715 |
| 1705 if (result.status == WRITE_STATUS_ERROR) { | 1716 if (result.status == WRITE_STATUS_ERROR) { |
| 1706 OnWriteError(result.error_code); | 1717 OnWriteError(result.error_code); |
| 1707 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted_length | 1718 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted_length |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 } | 1811 } |
| 1801 | 1812 |
| 1802 if (debug_visitor_) | 1813 if (debug_visitor_) |
| 1803 debug_visitor_->OnRttChanged(rtt); | 1814 debug_visitor_->OnRttChanged(rtt); |
| 1804 } | 1815 } |
| 1805 | 1816 |
| 1806 void QuicConnection::OnPathDegrading() { | 1817 void QuicConnection::OnPathDegrading() { |
| 1807 visitor_->OnPathDegrading(); | 1818 visitor_->OnPathDegrading(); |
| 1808 } | 1819 } |
| 1809 | 1820 |
| 1821 void QuicConnection::OnPathMtuIncreased(QuicPacketLength packet_size) { |
| 1822 DCHECK(FLAGS_quic_no_mtu_discovery_ack_listener); |
| 1823 if (packet_size > max_packet_length()) { |
| 1824 SetMaxPacketLength(packet_size); |
| 1825 } |
| 1826 } |
| 1827 |
| 1810 void QuicConnection::OnHandshakeComplete() { | 1828 void QuicConnection::OnHandshakeComplete() { |
| 1811 sent_packet_manager_->SetHandshakeConfirmed(); | 1829 sent_packet_manager_->SetHandshakeConfirmed(); |
| 1812 // The client should immediately ack the SHLO to confirm the handshake is | 1830 // The client should immediately ack the SHLO to confirm the handshake is |
| 1813 // complete with the server. | 1831 // complete with the server. |
| 1814 if (perspective_ == Perspective::IS_CLIENT && !ack_queued_ && | 1832 if (perspective_ == Perspective::IS_CLIENT && !ack_queued_ && |
| 1815 ack_frame_updated()) { | 1833 ack_frame_updated()) { |
| 1816 ack_alarm_->Cancel(); | 1834 ack_alarm_->Cancel(); |
| 1817 ack_alarm_->Set(clock_->ApproximateNow()); | 1835 ack_alarm_->Set(clock_->ApproximateNow()); |
| 1818 } | 1836 } |
| 1819 } | 1837 } |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2365 | 2383 |
| 2366 // Create a listener for the new probe. The ownership of the listener is | 2384 // Create a listener for the new probe. The ownership of the listener is |
| 2367 // transferred to the AckNotifierManager. The notifier will get destroyed | 2385 // transferred to the AckNotifierManager. The notifier will get destroyed |
| 2368 // before the connection (because it's stored in one of the connection's | 2386 // before the connection (because it's stored in one of the connection's |
| 2369 // subfields), hence |this| pointer is guaranteed to stay valid at all times. | 2387 // subfields), hence |this| pointer is guaranteed to stay valid at all times. |
| 2370 scoped_refptr<MtuDiscoveryAckListener> last_mtu_discovery_ack_listener( | 2388 scoped_refptr<MtuDiscoveryAckListener> last_mtu_discovery_ack_listener( |
| 2371 new MtuDiscoveryAckListener(this, target_mtu)); | 2389 new MtuDiscoveryAckListener(this, target_mtu)); |
| 2372 | 2390 |
| 2373 // Send the probe. | 2391 // Send the probe. |
| 2374 packet_generator_.GenerateMtuDiscoveryPacket( | 2392 packet_generator_.GenerateMtuDiscoveryPacket( |
| 2375 target_mtu, last_mtu_discovery_ack_listener.get()); | 2393 target_mtu, FLAGS_quic_no_mtu_discovery_ack_listener |
| 2394 ? nullptr |
| 2395 : last_mtu_discovery_ack_listener.get()); |
| 2376 } | 2396 } |
| 2377 | 2397 |
| 2378 void QuicConnection::DiscoverMtu() { | 2398 void QuicConnection::DiscoverMtu() { |
| 2379 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2399 DCHECK(!mtu_discovery_alarm_->IsSet()); |
| 2380 | 2400 |
| 2381 // Chcek if the MTU has been already increased. | 2401 // Check if the MTU has been already increased. |
| 2382 if (mtu_discovery_target_ <= max_packet_length()) { | 2402 if (mtu_discovery_target_ <= max_packet_length()) { |
| 2383 return; | 2403 return; |
| 2384 } | 2404 } |
| 2385 | 2405 |
| 2386 // Schedule the next probe *before* sending the current one. This is | 2406 // Calculate the packet number of the next probe *before* sending the current |
| 2387 // important, otherwise, when SendMtuDiscoveryPacket() is called, | 2407 // one. Otherwise, when SendMtuDiscoveryPacket() is called, |
| 2388 // MaybeSetMtuAlarm() will not realize that the probe has been just sent, and | 2408 // MaybeSetMtuAlarm() will not realize that the probe has been just sent, and |
| 2389 // will reschedule this probe again. | 2409 // will reschedule this probe again. |
| 2390 packets_between_mtu_probes_ *= 2; | 2410 packets_between_mtu_probes_ *= 2; |
| 2391 next_mtu_probe_at_ = | 2411 next_mtu_probe_at_ = |
| 2392 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; | 2412 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; |
| 2393 ++mtu_probe_count_; | 2413 ++mtu_probe_count_; |
| 2394 | 2414 |
| 2395 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; | 2415 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; |
| 2396 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2416 SendMtuDiscoveryPacket(mtu_discovery_target_); |
| 2397 | 2417 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2491 // the sender and a signaling mechanism -- if the sender uses a | 2511 // the sender and a signaling mechanism -- if the sender uses a |
| 2492 // different MinRTO, we may get spurious retransmissions. May not have | 2512 // different MinRTO, we may get spurious retransmissions. May not have |
| 2493 // any benefits, but if the delayed ack becomes a significant source | 2513 // any benefits, but if the delayed ack becomes a significant source |
| 2494 // of (likely, tail) latency, then consider such a mechanism. | 2514 // of (likely, tail) latency, then consider such a mechanism. |
| 2495 const QuicTime::Delta QuicConnection::DelayedAckTime() { | 2515 const QuicTime::Delta QuicConnection::DelayedAckTime() { |
| 2496 return QuicTime::Delta::FromMilliseconds( | 2516 return QuicTime::Delta::FromMilliseconds( |
| 2497 min(kMaxDelayedAckTimeMs, kMinRetransmissionTimeMs / 2)); | 2517 min(kMaxDelayedAckTimeMs, kMinRetransmissionTimeMs / 2)); |
| 2498 } | 2518 } |
| 2499 | 2519 |
| 2500 } // namespace net | 2520 } // namespace net |
| OLD | NEW |