Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: net/quic/quic_connection.cc

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1063
1064 QuicConsumedData QuicConnection::SendStreamData( 1064 QuicConsumedData QuicConnection::SendStreamData(
1065 QuicStreamId id, 1065 QuicStreamId id,
1066 const IOVector& data, 1066 const IOVector& data,
1067 QuicStreamOffset offset, 1067 QuicStreamOffset offset,
1068 bool fin, 1068 bool fin,
1069 FecProtection fec_protection, 1069 FecProtection fec_protection,
1070 QuicAckNotifier::DelegateInterface* delegate) { 1070 QuicAckNotifier::DelegateInterface* delegate) {
1071 if (!fin && data.Empty()) { 1071 if (!fin && data.Empty()) {
1072 LOG(DFATAL) << "Attempt to send empty stream frame"; 1072 LOG(DFATAL) << "Attempt to send empty stream frame";
1073 } 1073 if (FLAGS_quic_empty_data_no_fin_early_return) {
1074 1074 return QuicConsumedData(0, false);
1075 // This notifier will be owned by the AckNotifierManager (or deleted below if 1075 }
1076 // no data or FIN was consumed).
1077 QuicAckNotifier* notifier = nullptr;
1078 if (delegate) {
1079 notifier = new QuicAckNotifier(delegate);
1080 } 1076 }
1081 1077
1082 // Opportunistically bundle an ack with every outgoing packet. 1078 // Opportunistically bundle an ack with every outgoing packet.
1083 // Particularly, we want to bundle with handshake packets since we don't know 1079 // Particularly, we want to bundle with handshake packets since we don't know
1084 // which decrypter will be used on an ack packet following a handshake 1080 // which decrypter will be used on an ack packet following a handshake
1085 // packet (a handshake packet from client to server could result in a REJ or a 1081 // packet (a handshake packet from client to server could result in a REJ or a
1086 // SHLO from the server, leading to two different decrypters at the server.) 1082 // SHLO from the server, leading to two different decrypters at the server.)
1087 // 1083 //
1088 // TODO(jri): Note that ConsumeData may cause a response packet to be sent. 1084 // TODO(jri): Note that ConsumeData may cause a response packet to be sent.
1089 // We may end up sending stale ack information if there are undecryptable 1085 // We may end up sending stale ack information if there are undecryptable
1090 // packets hanging around and/or there are revivable packets which may get 1086 // packets hanging around and/or there are revivable packets which may get
1091 // handled after this packet is sent. Change ScopedPacketBundler to do the 1087 // handled after this packet is sent. Change ScopedPacketBundler to do the
1092 // right thing: check ack_queued_, and then check undecryptable packets and 1088 // right thing: check ack_queued_, and then check undecryptable packets and
1093 // also if there is possibility of revival. Only bundle an ack if there's no 1089 // also if there is possibility of revival. Only bundle an ack if there's no
1094 // processing left that may cause received_info_ to change. 1090 // processing left that may cause received_info_ to change.
1095 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); 1091 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK);
1096 QuicConsumedData consumed_data = 1092 return packet_generator_.ConsumeData(id, data, offset, fin, fec_protection,
1097 packet_generator_.ConsumeData(id, data, offset, fin, fec_protection, 1093 delegate);
1098 notifier);
1099
1100 if (notifier &&
1101 (consumed_data.bytes_consumed == 0 && !consumed_data.fin_consumed)) {
1102 // No data was consumed, nor was a fin consumed, so delete the notifier.
1103 delete notifier;
1104 }
1105
1106 return consumed_data;
1107 } 1094 }
1108 1095
1109 void QuicConnection::SendRstStream(QuicStreamId id, 1096 void QuicConnection::SendRstStream(QuicStreamId id,
1110 QuicRstStreamErrorCode error, 1097 QuicRstStreamErrorCode error,
1111 QuicStreamOffset bytes_written) { 1098 QuicStreamOffset bytes_written) {
1112 // Opportunistically bundle an ack with this outgoing packet. 1099 // Opportunistically bundle an ack with this outgoing packet.
1113 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); 1100 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK);
1114 packet_generator_.AddControlFrame(QuicFrame(new QuicRstStreamFrame( 1101 packet_generator_.AddControlFrame(QuicFrame(new QuicRstStreamFrame(
1115 id, AdjustErrorForVersion(error, version()), bytes_written))); 1102 id, AdjustErrorForVersion(error, version()), bytes_written)));
1116 } 1103 }
1117 1104
1118 void QuicConnection::SendWindowUpdate(QuicStreamId id, 1105 void QuicConnection::SendWindowUpdate(QuicStreamId id,
1119 QuicStreamOffset byte_offset) { 1106 QuicStreamOffset byte_offset) {
1120 // Opportunistically bundle an ack with this outgoing packet. 1107 // Opportunistically bundle an ack with this outgoing packet.
1121 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); 1108 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK);
1122 packet_generator_.AddControlFrame( 1109 packet_generator_.AddControlFrame(
1123 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); 1110 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset)));
1124 } 1111 }
1125 1112
1126 void QuicConnection::SendBlocked(QuicStreamId id) { 1113 void QuicConnection::SendBlocked(QuicStreamId id) {
1127 // Opportunistically bundle an ack with this outgoing packet. 1114 // Opportunistically bundle an ack with this outgoing packet.
1128 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); 1115 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK);
1129 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); 1116 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id)));
1130 } 1117 }
1131 1118
1132 const QuicConnectionStats& QuicConnection::GetStats() { 1119 const QuicConnectionStats& QuicConnection::GetStats() {
1133 // Update rtt and estimated bandwidth. 1120 if (!FLAGS_quic_use_initial_rtt_for_stats) {
1134 stats_.min_rtt_us = 1121 stats_.min_rtt_us =
1135 sent_packet_manager_.GetRttStats()->min_rtt().ToMicroseconds(); 1122 sent_packet_manager_.GetRttStats()->min_rtt().ToMicroseconds();
1136 stats_.srtt_us = 1123 stats_.srtt_us =
1137 sent_packet_manager_.GetRttStats()->smoothed_rtt().ToMicroseconds(); 1124 sent_packet_manager_.GetRttStats()->smoothed_rtt().ToMicroseconds();
1125 } else {
1126 const RttStats* rtt_stats = sent_packet_manager_.GetRttStats();
1127
1128 // Update rtt and estimated bandwidth.
1129 QuicTime::Delta min_rtt = rtt_stats->min_rtt();
1130 if (min_rtt.IsZero()) {
1131 // If min RTT has not been set, use initial RTT instead.
1132 min_rtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us());
1133 }
1134 stats_.min_rtt_us = min_rtt.ToMicroseconds();
1135
1136 QuicTime::Delta srtt = rtt_stats->smoothed_rtt();
1137 if (srtt.IsZero()) {
1138 // If SRTT has not been set, use initial RTT instead.
1139 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us());
1140 }
1141 stats_.srtt_us = srtt.ToMicroseconds();
1142 }
1143
1138 stats_.estimated_bandwidth = sent_packet_manager_.BandwidthEstimate(); 1144 stats_.estimated_bandwidth = sent_packet_manager_.BandwidthEstimate();
1139 stats_.max_packet_size = packet_generator_.max_packet_length(); 1145 stats_.max_packet_size = packet_generator_.max_packet_length();
1140 return stats_; 1146 return stats_;
1141 } 1147 }
1142 1148
1143 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, 1149 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address,
1144 const IPEndPoint& peer_address, 1150 const IPEndPoint& peer_address,
1145 const QuicEncryptedPacket& packet) { 1151 const QuicEncryptedPacket& packet) {
1146 if (!connected_) { 1152 if (!connected_) {
1147 return; 1153 return;
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 } 1597 }
1592 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_)); 1598 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_));
1593 } 1599 }
1594 1600
1595 void QuicConnection::OnCongestionWindowChange() { 1601 void QuicConnection::OnCongestionWindowChange() {
1596 packet_generator_.OnCongestionWindowChange( 1602 packet_generator_.OnCongestionWindowChange(
1597 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); 1603 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length()));
1598 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); 1604 visitor_->OnCongestionWindowChange(clock_->ApproximateNow());
1599 } 1605 }
1600 1606
1607 void QuicConnection::OnRttChange() {
1608 // Uses the connection's smoothed RTT. If zero, uses initial_rtt.
1609 QuicTime::Delta rtt = sent_packet_manager_.GetRttStats()->smoothed_rtt();
1610 if (rtt.IsZero()) {
1611 rtt = QuicTime::Delta::FromMicroseconds(
1612 sent_packet_manager_.GetRttStats()->initial_rtt_us());
1613 }
1614 packet_generator_.OnRttChange(rtt);
1615 }
1616
1601 void QuicConnection::OnHandshakeComplete() { 1617 void QuicConnection::OnHandshakeComplete() {
1602 sent_packet_manager_.SetHandshakeConfirmed(); 1618 sent_packet_manager_.SetHandshakeConfirmed();
1603 // The client should immediately ack the SHLO to confirm the handshake is 1619 // The client should immediately ack the SHLO to confirm the handshake is
1604 // complete with the server. 1620 // complete with the server.
1605 if (!is_server_ && !ack_queued_) { 1621 if (!is_server_ && !ack_queued_) {
1606 ack_alarm_->Cancel(); 1622 ack_alarm_->Cancel();
1607 ack_alarm_->Set(clock_->ApproximateNow()); 1623 ack_alarm_->Set(clock_->ApproximateNow());
1608 } 1624 }
1609 } 1625 }
1610 1626
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 } 2108 }
2093 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2109 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2094 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2110 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2095 return true; 2111 return true;
2096 } 2112 }
2097 } 2113 }
2098 return false; 2114 return false;
2099 } 2115 }
2100 2116
2101 } // namespace net 2117 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698