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/core/quic_connection.h" | 5 #include "net/quic/core/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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 random_generator_(helper->GetRandomGenerator()), | 203 random_generator_(helper->GetRandomGenerator()), |
204 connection_id_(connection_id), | 204 connection_id_(connection_id), |
205 peer_address_(address), | 205 peer_address_(address), |
206 active_peer_migration_type_(NO_CHANGE), | 206 active_peer_migration_type_(NO_CHANGE), |
207 highest_packet_sent_before_peer_migration_(0), | 207 highest_packet_sent_before_peer_migration_(0), |
208 last_packet_decrypted_(false), | 208 last_packet_decrypted_(false), |
209 last_size_(0), | 209 last_size_(0), |
210 current_packet_data_(nullptr), | 210 current_packet_data_(nullptr), |
211 last_decrypted_packet_level_(ENCRYPTION_NONE), | 211 last_decrypted_packet_level_(ENCRYPTION_NONE), |
212 should_last_packet_instigate_acks_(false), | 212 should_last_packet_instigate_acks_(false), |
| 213 was_last_packet_missing_(false), |
213 largest_seen_packet_with_ack_(0), | 214 largest_seen_packet_with_ack_(0), |
214 largest_seen_packet_with_stop_waiting_(0), | 215 largest_seen_packet_with_stop_waiting_(0), |
215 max_undecryptable_packets_(0), | 216 max_undecryptable_packets_(0), |
216 pending_version_negotiation_packet_(false), | 217 pending_version_negotiation_packet_(false), |
217 save_crypto_packets_as_termination_packets_(false), | 218 save_crypto_packets_as_termination_packets_(false), |
218 idle_timeout_connection_close_behavior_( | 219 idle_timeout_connection_close_behavior_( |
219 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET), | 220 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET), |
220 close_connection_after_five_rtos_(false), | 221 close_connection_after_five_rtos_(false), |
221 received_packet_manager_(&stats_), | 222 received_packet_manager_(&stats_), |
222 ack_queued_(false), | 223 ack_queued_(false), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 largest_received_packet_size_(0), | 283 largest_received_packet_size_(0), |
283 largest_packet_size_supported_(std::numeric_limits<QuicByteCount>::max()), | 284 largest_packet_size_supported_(std::numeric_limits<QuicByteCount>::max()), |
284 goaway_sent_(false), | 285 goaway_sent_(false), |
285 goaway_received_(false), | 286 goaway_received_(false), |
286 multipath_enabled_(false), | 287 multipath_enabled_(false), |
287 write_error_occured_(false) { | 288 write_error_occured_(false) { |
288 DVLOG(1) << ENDPOINT | 289 DVLOG(1) << ENDPOINT |
289 << "Created connection with connection_id: " << connection_id; | 290 << "Created connection with connection_id: " << connection_id; |
290 framer_.set_visitor(this); | 291 framer_.set_visitor(this); |
291 framer_.set_received_entropy_calculator(&received_packet_manager_); | 292 framer_.set_received_entropy_calculator(&received_packet_manager_); |
292 last_stop_waiting_frame_.least_unacked = 0; | 293 if (!FLAGS_quic_receive_packet_once_decrypted) { |
| 294 last_stop_waiting_frame_.least_unacked = 0; |
| 295 } |
293 stats_.connection_creation_time = clock_->ApproximateNow(); | 296 stats_.connection_creation_time = clock_->ApproximateNow(); |
294 if (FLAGS_quic_enable_multipath) { | 297 if (FLAGS_quic_enable_multipath) { |
295 sent_packet_manager_.reset(new QuicMultipathSentPacketManager( | 298 sent_packet_manager_.reset(new QuicMultipathSentPacketManager( |
296 sent_packet_manager_.release(), this)); | 299 sent_packet_manager_.release(), this)); |
297 } | 300 } |
298 // TODO(ianswett): Supply the NetworkChangeVisitor as a constructor argument | 301 // TODO(ianswett): Supply the NetworkChangeVisitor as a constructor argument |
299 // and make it required non-null, because it's always used. | 302 // and make it required non-null, because it's always used. |
300 sent_packet_manager_->SetNetworkChangeVisitor(this); | 303 sent_packet_manager_->SetNetworkChangeVisitor(this); |
301 // Allow the packet writer to potentially reduce the packet size to a value | 304 // Allow the packet writer to potentially reduce the packet size to a value |
302 // even smaller than kDefaultMaxPacketSize. | 305 // even smaller than kDefaultMaxPacketSize. |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 // packet. | 657 // packet. |
655 if (active_peer_migration_type_ == NO_CHANGE && | 658 if (active_peer_migration_type_ == NO_CHANGE && |
656 peer_migration_type != NO_CHANGE && | 659 peer_migration_type != NO_CHANGE && |
657 header.packet_number > received_packet_manager_.GetLargestObserved()) { | 660 header.packet_number > received_packet_manager_.GetLargestObserved()) { |
658 StartPeerMigration(header.path_id, peer_migration_type); | 661 StartPeerMigration(header.path_id, peer_migration_type); |
659 } | 662 } |
660 | 663 |
661 --stats_.packets_dropped; | 664 --stats_.packets_dropped; |
662 DVLOG(1) << ENDPOINT << "Received packet header: " << header; | 665 DVLOG(1) << ENDPOINT << "Received packet header: " << header; |
663 last_header_ = header; | 666 last_header_ = header; |
| 667 if (FLAGS_quic_receive_packet_once_decrypted) { |
| 668 // An ack will be sent if a missing retransmittable packet was received; |
| 669 was_last_packet_missing_ = |
| 670 received_packet_manager_.IsMissing(last_header_.packet_number); |
| 671 |
| 672 // Record received to populate ack info correctly before processing stream |
| 673 // frames, since the processing may result in a response packet with a |
| 674 // bundled ack. |
| 675 received_packet_manager_.RecordPacketReceived( |
| 676 last_header_, time_of_last_received_packet_); |
| 677 } |
664 DCHECK(connected_); | 678 DCHECK(connected_); |
665 return true; | 679 return true; |
666 } | 680 } |
667 | 681 |
668 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { | 682 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { |
669 DCHECK(connected_); | 683 DCHECK(connected_); |
670 if (debug_visitor_ != nullptr) { | 684 if (debug_visitor_ != nullptr) { |
671 debug_visitor_->OnStreamFrame(frame); | 685 debug_visitor_->OnStreamFrame(frame); |
672 } | 686 } |
673 if (frame.stream_id != kCryptoStreamId && | 687 if (frame.stream_id != kCryptoStreamId && |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 if (error != nullptr) { | 785 if (error != nullptr) { |
772 CloseConnection(QUIC_INVALID_STOP_WAITING_DATA, error, | 786 CloseConnection(QUIC_INVALID_STOP_WAITING_DATA, error, |
773 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 787 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
774 return false; | 788 return false; |
775 } | 789 } |
776 | 790 |
777 if (debug_visitor_ != nullptr) { | 791 if (debug_visitor_ != nullptr) { |
778 debug_visitor_->OnStopWaitingFrame(frame); | 792 debug_visitor_->OnStopWaitingFrame(frame); |
779 } | 793 } |
780 | 794 |
781 last_stop_waiting_frame_ = frame; | 795 if (FLAGS_quic_receive_packet_once_decrypted) { |
| 796 ProcessStopWaitingFrame(frame); |
| 797 } else { |
| 798 last_stop_waiting_frame_ = frame; |
| 799 } |
782 return connected_; | 800 return connected_; |
783 } | 801 } |
784 | 802 |
785 bool QuicConnection::OnPaddingFrame(const QuicPaddingFrame& frame) { | 803 bool QuicConnection::OnPaddingFrame(const QuicPaddingFrame& frame) { |
786 DCHECK(connected_); | 804 DCHECK(connected_); |
787 if (debug_visitor_ != nullptr) { | 805 if (debug_visitor_ != nullptr) { |
788 debug_visitor_->OnPaddingFrame(frame); | 806 debug_visitor_->OnPaddingFrame(frame); |
789 } | 807 } |
790 return true; | 808 return true; |
791 } | 809 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 void QuicConnection::OnPacketComplete() { | 997 void QuicConnection::OnPacketComplete() { |
980 // Don't do anything if this packet closed the connection. | 998 // Don't do anything if this packet closed the connection. |
981 if (!connected_) { | 999 if (!connected_) { |
982 ClearLastFrames(); | 1000 ClearLastFrames(); |
983 return; | 1001 return; |
984 } | 1002 } |
985 | 1003 |
986 DVLOG(1) << ENDPOINT << "Got packet " << last_header_.packet_number << " for " | 1004 DVLOG(1) << ENDPOINT << "Got packet " << last_header_.packet_number << " for " |
987 << last_header_.public_header.connection_id; | 1005 << last_header_.public_header.connection_id; |
988 | 1006 |
989 // An ack will be sent if a missing retransmittable packet was received; | 1007 if (FLAGS_quic_receive_packet_once_decrypted) { |
990 const bool was_missing = | 1008 // An ack will be sent if a missing retransmittable packet was received; |
991 should_last_packet_instigate_acks_ && | 1009 const bool was_missing = |
992 received_packet_manager_.IsMissing(last_header_.packet_number); | 1010 should_last_packet_instigate_acks_ && was_last_packet_missing_; |
993 | 1011 |
994 // Record received to populate ack info correctly before processing stream | 1012 // It's possible the ack frame was sent along with response data, so it |
995 // frames, since the processing may result in a response packet with a bundled | 1013 // no longer needs to be sent. |
996 // ack. | 1014 if (ack_frame_updated()) { |
997 received_packet_manager_.RecordPacketReceived(last_size_, last_header_, | 1015 MaybeQueueAck(was_missing); |
998 time_of_last_received_packet_); | 1016 } |
| 1017 } else { |
| 1018 // An ack will be sent if a missing retransmittable packet was received; |
| 1019 const bool was_missing = |
| 1020 should_last_packet_instigate_acks_ && |
| 1021 received_packet_manager_.IsMissing(last_header_.packet_number); |
999 | 1022 |
1000 // Process stop waiting frames here, instead of inline, because the packet | 1023 // Record received to populate ack info correctly before processing stream |
1001 // needs to be considered 'received' before the entropy can be updated. | 1024 // frames, since the processing may result in a response packet with a |
1002 if (last_stop_waiting_frame_.least_unacked > 0) { | 1025 // bundled ack. |
1003 ProcessStopWaitingFrame(last_stop_waiting_frame_); | 1026 received_packet_manager_.RecordPacketReceived( |
1004 if (!connected_) { | 1027 last_header_, time_of_last_received_packet_); |
1005 return; | 1028 |
| 1029 // Process stop waiting frames here, instead of inline, because the packet |
| 1030 // needs to be considered 'received' before the entropy can be updated. |
| 1031 if (last_stop_waiting_frame_.least_unacked > 0) { |
| 1032 ProcessStopWaitingFrame(last_stop_waiting_frame_); |
| 1033 if (!connected_) { |
| 1034 return; |
| 1035 } |
1006 } | 1036 } |
| 1037 |
| 1038 MaybeQueueAck(was_missing); |
1007 } | 1039 } |
1008 | 1040 |
1009 MaybeQueueAck(was_missing); | |
1010 | |
1011 ClearLastFrames(); | 1041 ClearLastFrames(); |
1012 MaybeCloseIfTooManyOutstandingPackets(); | 1042 MaybeCloseIfTooManyOutstandingPackets(); |
1013 } | 1043 } |
1014 | 1044 |
1015 void QuicConnection::MaybeQueueAck(bool was_missing) { | 1045 void QuicConnection::MaybeQueueAck(bool was_missing) { |
1016 ++num_packets_received_since_last_ack_sent_; | 1046 ++num_packets_received_since_last_ack_sent_; |
1017 // Always send an ack every 20 packets in order to allow the peer to discard | 1047 // Always send an ack every 20 packets in order to allow the peer to discard |
1018 // information from the SentPacketManager and provide an RTT measurement. | 1048 // information from the SentPacketManager and provide an RTT measurement. |
1019 if (num_packets_received_since_last_ack_sent_ >= | 1049 if (num_packets_received_since_last_ack_sent_ >= |
1020 kMaxPacketsReceivedBeforeAckSend) { | 1050 kMaxPacketsReceivedBeforeAckSend) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 } | 1101 } |
1072 } | 1102 } |
1073 | 1103 |
1074 if (ack_queued_) { | 1104 if (ack_queued_) { |
1075 ack_alarm_->Cancel(); | 1105 ack_alarm_->Cancel(); |
1076 } | 1106 } |
1077 } | 1107 } |
1078 | 1108 |
1079 void QuicConnection::ClearLastFrames() { | 1109 void QuicConnection::ClearLastFrames() { |
1080 should_last_packet_instigate_acks_ = false; | 1110 should_last_packet_instigate_acks_ = false; |
1081 last_stop_waiting_frame_.least_unacked = 0; | 1111 if (!FLAGS_quic_receive_packet_once_decrypted) { |
| 1112 last_stop_waiting_frame_.least_unacked = 0; |
| 1113 } |
1082 } | 1114 } |
1083 | 1115 |
1084 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() { | 1116 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() { |
1085 if (version() > QUIC_VERSION_33) { | 1117 if (version() > QUIC_VERSION_33) { |
1086 return; | 1118 return; |
1087 } | 1119 } |
1088 // This occurs if we don't discard old packets we've sent fast enough. | 1120 // This occurs if we don't discard old packets we've sent fast enough. |
1089 // It's possible largest observed is less than least unacked. | 1121 // It's possible largest observed is less than least unacked. |
1090 if (sent_packet_manager_->GetLargestObserved(last_header_.path_id) > | 1122 if (sent_packet_manager_->GetLargestObserved(last_header_.path_id) > |
1091 (sent_packet_manager_->GetLeastUnacked(last_header_.path_id) + | 1123 (sent_packet_manager_->GetLeastUnacked(last_header_.path_id) + |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 } | 1737 } |
1706 | 1738 |
1707 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { | 1739 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { |
1708 // Pass the write result to the visitor. | 1740 // Pass the write result to the visitor. |
1709 debug_visitor_->OnPacketSent(*packet, packet->original_path_id, | 1741 debug_visitor_->OnPacketSent(*packet, packet->original_path_id, |
1710 packet->original_packet_number, | 1742 packet->original_packet_number, |
1711 packet->transmission_type, packet_send_time); | 1743 packet->transmission_type, packet_send_time); |
1712 } | 1744 } |
1713 if (packet->transmission_type == NOT_RETRANSMISSION) { | 1745 if (packet->transmission_type == NOT_RETRANSMISSION) { |
1714 time_of_last_sent_new_packet_ = packet_send_time; | 1746 time_of_last_sent_new_packet_ = packet_send_time; |
1715 if (!FLAGS_quic_better_last_send_for_timeout) { | |
1716 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && | |
1717 last_send_for_timeout_ <= time_of_last_received_packet_) { | |
1718 last_send_for_timeout_ = packet_send_time; | |
1719 } | |
1720 } | |
1721 } | 1747 } |
1722 if (FLAGS_quic_better_last_send_for_timeout) { | 1748 // Only adjust the last sent time (for the purpose of tracking the idle |
1723 // Only adjust the last sent time (for the purpose of tracking the idle | 1749 // timeout) if this is the first retransmittable packet sent after a |
1724 // timeout) if this is the first retransmittable packet sent after a | 1750 // packet is received. If it were updated on every sent packet, then |
1725 // packet is received. If it were updated on every sent packet, then | 1751 // sending into a black hole might never timeout. |
1726 // sending into a black hole might never timeout. | 1752 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && |
1727 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && | 1753 last_send_for_timeout_ <= time_of_last_received_packet_) { |
1728 last_send_for_timeout_ <= time_of_last_received_packet_) { | 1754 last_send_for_timeout_ = packet_send_time; |
1729 last_send_for_timeout_ = packet_send_time; | |
1730 } | |
1731 } | 1755 } |
1732 SetPingAlarm(); | 1756 SetPingAlarm(); |
1733 MaybeSetMtuAlarm(); | 1757 MaybeSetMtuAlarm(); |
1734 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " | 1758 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " |
1735 << packet_send_time.ToDebuggingValue(); | 1759 << packet_send_time.ToDebuggingValue(); |
1736 | 1760 |
1737 bool reset_retransmission_alarm = sent_packet_manager_->OnPacketSent( | 1761 bool reset_retransmission_alarm = sent_packet_manager_->OnPacketSent( |
1738 packet, packet->original_path_id, packet->original_packet_number, | 1762 packet, packet->original_path_id, packet->original_packet_number, |
1739 packet_send_time, packet->transmission_type, IsRetransmittable(*packet)); | 1763 packet_send_time, packet->transmission_type, IsRetransmittable(*packet)); |
1740 | 1764 |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 return; | 2253 return; |
2230 } | 2254 } |
2231 } | 2255 } |
2232 | 2256 |
2233 SetTimeoutAlarm(); | 2257 SetTimeoutAlarm(); |
2234 } | 2258 } |
2235 | 2259 |
2236 void QuicConnection::SetTimeoutAlarm() { | 2260 void QuicConnection::SetTimeoutAlarm() { |
2237 QuicTime time_of_last_packet = | 2261 QuicTime time_of_last_packet = |
2238 max(time_of_last_received_packet_, time_of_last_sent_new_packet_); | 2262 max(time_of_last_received_packet_, time_of_last_sent_new_packet_); |
2239 if (FLAGS_quic_better_last_send_for_timeout) { | 2263 time_of_last_packet = |
2240 time_of_last_packet = | 2264 max(time_of_last_received_packet_, last_send_for_timeout_); |
2241 max(time_of_last_received_packet_, last_send_for_timeout_); | |
2242 } | |
2243 | 2265 |
2244 QuicTime deadline = time_of_last_packet + idle_network_timeout_; | 2266 QuicTime deadline = time_of_last_packet + idle_network_timeout_; |
2245 if (!handshake_timeout_.IsInfinite()) { | 2267 if (!handshake_timeout_.IsInfinite()) { |
2246 deadline = | 2268 deadline = |
2247 min(deadline, stats_.connection_creation_time + handshake_timeout_); | 2269 min(deadline, stats_.connection_creation_time + handshake_timeout_); |
2248 } | 2270 } |
2249 | 2271 |
2250 timeout_alarm_->Update(deadline, QuicTime::Delta::Zero()); | 2272 timeout_alarm_->Update(deadline, QuicTime::Delta::Zero()); |
2251 } | 2273 } |
2252 | 2274 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2568 | 2590 |
2569 void QuicConnection::CheckIfApplicationLimited() { | 2591 void QuicConnection::CheckIfApplicationLimited() { |
2570 if (queued_packets_.empty() && | 2592 if (queued_packets_.empty() && |
2571 !sent_packet_manager_->HasPendingRetransmissions() && | 2593 !sent_packet_manager_->HasPendingRetransmissions() && |
2572 !visitor_->WillingAndAbleToWrite()) { | 2594 !visitor_->WillingAndAbleToWrite()) { |
2573 sent_packet_manager_->OnApplicationLimited(); | 2595 sent_packet_manager_->OnApplicationLimited(); |
2574 } | 2596 } |
2575 } | 2597 } |
2576 | 2598 |
2577 } // namespace net | 2599 } // namespace net |
OLD | NEW |