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

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

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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_stats.h » ('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 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 1132
1133 void QuicConnection::SendBlocked(QuicStreamId id) { 1133 void QuicConnection::SendBlocked(QuicStreamId id) {
1134 // Opportunistically bundle an ack with this outgoing packet. 1134 // Opportunistically bundle an ack with this outgoing packet.
1135 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); 1135 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK);
1136 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); 1136 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id)));
1137 } 1137 }
1138 1138
1139 const QuicConnectionStats& QuicConnection::GetStats() { 1139 const QuicConnectionStats& QuicConnection::GetStats() {
1140 // Update rtt and estimated bandwidth. 1140 // Update rtt and estimated bandwidth.
1141 stats_.min_rtt_us = 1141 stats_.min_rtt_us =
1142 sent_packet_manager_.GetRttStats()->MinRtt().ToMicroseconds(); 1142 sent_packet_manager_.GetRttStats()->min_rtt().ToMicroseconds();
1143 stats_.srtt_us = 1143 stats_.srtt_us =
1144 sent_packet_manager_.GetRttStats()->SmoothedRtt().ToMicroseconds(); 1144 sent_packet_manager_.GetRttStats()->smoothed_rtt().ToMicroseconds();
1145 stats_.estimated_bandwidth = 1145 stats_.estimated_bandwidth =
1146 sent_packet_manager_.BandwidthEstimate().ToBytesPerSecond(); 1146 sent_packet_manager_.BandwidthEstimate().ToBytesPerSecond();
1147 stats_.congestion_window = sent_packet_manager_.GetCongestionWindow();
1148 stats_.slow_start_threshold = sent_packet_manager_.GetSlowStartThreshold();
1149 stats_.max_packet_size = packet_generator_.max_packet_length(); 1147 stats_.max_packet_size = packet_generator_.max_packet_length();
1150 return stats_; 1148 return stats_;
1151 } 1149 }
1152 1150
1153 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, 1151 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address,
1154 const IPEndPoint& peer_address, 1152 const IPEndPoint& peer_address,
1155 const QuicEncryptedPacket& packet) { 1153 const QuicEncryptedPacket& packet) {
1156 if (!connected_) { 1154 if (!connected_) {
1157 return; 1155 return;
1158 } 1156 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 << ", migrating connection."; 1267 << ", migrating connection.";
1270 peer_address_ = IPEndPoint(peer_address_.address(), migrating_peer_port_); 1268 peer_address_ = IPEndPoint(peer_address_.address(), migrating_peer_port_);
1271 } 1269 }
1272 1270
1273 time_of_last_received_packet_ = clock_->Now(); 1271 time_of_last_received_packet_ = clock_->Now();
1274 DVLOG(1) << ENDPOINT << "time of last received packet: " 1272 DVLOG(1) << ENDPOINT << "time of last received packet: "
1275 << time_of_last_received_packet_.ToDebuggingValue(); 1273 << time_of_last_received_packet_.ToDebuggingValue();
1276 1274
1277 if (is_server_ && encryption_level_ == ENCRYPTION_NONE && 1275 if (is_server_ && encryption_level_ == ENCRYPTION_NONE &&
1278 last_size_ > packet_generator_.max_packet_length()) { 1276 last_size_ > packet_generator_.max_packet_length()) {
1279 packet_generator_.set_max_packet_length(last_size_); 1277 set_max_packet_length(last_size_);
1280 } 1278 }
1281 return true; 1279 return true;
1282 } 1280 }
1283 1281
1284 void QuicConnection::WriteQueuedPackets() { 1282 void QuicConnection::WriteQueuedPackets() {
1285 DCHECK(!writer_->IsWriteBlocked()); 1283 DCHECK(!writer_->IsWriteBlocked());
1286 1284
1287 if (pending_version_negotiation_packet_) { 1285 if (pending_version_negotiation_packet_) {
1288 SendVersionNegotiationPacket(); 1286 SendVersionNegotiationPacket();
1289 } 1287 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 } 1487 }
1490 SetPingAlarm(); 1488 SetPingAlarm();
1491 DVLOG(1) << ENDPOINT << "time of last sent packet: " 1489 DVLOG(1) << ENDPOINT << "time of last sent packet: "
1492 << now.ToDebuggingValue(); 1490 << now.ToDebuggingValue();
1493 1491
1494 // TODO(ianswett): Change the sequence number length and other packet creator 1492 // TODO(ianswett): Change the sequence number length and other packet creator
1495 // options by a more explicit API than setting a struct value directly, 1493 // options by a more explicit API than setting a struct value directly,
1496 // perhaps via the NetworkChangeVisitor. 1494 // perhaps via the NetworkChangeVisitor.
1497 packet_generator_.UpdateSequenceNumberLength( 1495 packet_generator_.UpdateSequenceNumberLength(
1498 sent_packet_manager_.least_packet_awaited_by_peer(), 1496 sent_packet_manager_.least_packet_awaited_by_peer(),
1499 sent_packet_manager_.GetCongestionWindow()); 1497 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length()));
1500 1498
1501 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( 1499 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent(
1502 &packet->serialized_packet, 1500 &packet->serialized_packet,
1503 packet->original_sequence_number, 1501 packet->original_sequence_number,
1504 now, 1502 now,
1505 encrypted->length(), 1503 encrypted->length(),
1506 packet->transmission_type, 1504 packet->transmission_type,
1507 IsRetransmittable(*packet)); 1505 IsRetransmittable(*packet));
1508 1506
1509 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { 1507 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 } 1577 }
1580 if (serialized_packet.retransmittable_frames) { 1578 if (serialized_packet.retransmittable_frames) {
1581 serialized_packet.retransmittable_frames-> 1579 serialized_packet.retransmittable_frames->
1582 set_encryption_level(encryption_level_); 1580 set_encryption_level(encryption_level_);
1583 } 1581 }
1584 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_)); 1582 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_));
1585 } 1583 }
1586 1584
1587 void QuicConnection::OnCongestionWindowChange() { 1585 void QuicConnection::OnCongestionWindowChange() {
1588 packet_generator_.OnCongestionWindowChange( 1586 packet_generator_.OnCongestionWindowChange(
1589 sent_packet_manager_.GetCongestionWindow()); 1587 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length()));
1590 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); 1588 visitor_->OnCongestionWindowChange(clock_->ApproximateNow());
1591 } 1589 }
1592 1590
1593 void QuicConnection::OnHandshakeComplete() { 1591 void QuicConnection::OnHandshakeComplete() {
1594 sent_packet_manager_.SetHandshakeConfirmed(); 1592 sent_packet_manager_.SetHandshakeConfirmed();
1595 } 1593 }
1596 1594
1597 void QuicConnection::SendOrQueuePacket(QueuedPacket packet) { 1595 void QuicConnection::SendOrQueuePacket(QueuedPacket packet) {
1598 // The caller of this function is responsible for checking CanWrite(). 1596 // The caller of this function is responsible for checking CanWrite().
1599 if (packet.serialized_packet.packet == nullptr) { 1597 if (packet.serialized_packet.packet == nullptr) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 QuicEncrypter* encrypter) { 1677 QuicEncrypter* encrypter) {
1680 framer_.SetEncrypter(level, encrypter); 1678 framer_.SetEncrypter(level, encrypter);
1681 if (FLAGS_enable_quic_delay_forward_security && 1679 if (FLAGS_enable_quic_delay_forward_security &&
1682 level == ENCRYPTION_FORWARD_SECURE) { 1680 level == ENCRYPTION_FORWARD_SECURE) {
1683 has_forward_secure_encrypter_ = true; 1681 has_forward_secure_encrypter_ = true;
1684 first_required_forward_secure_packet_ = 1682 first_required_forward_secure_packet_ =
1685 sequence_number_of_last_sent_packet_ + 1683 sequence_number_of_last_sent_packet_ +
1686 // 3 times the current congestion window (in slow start) should cover 1684 // 3 times the current congestion window (in slow start) should cover
1687 // about two full round trips worth of packets, which should be 1685 // about two full round trips worth of packets, which should be
1688 // sufficient. 1686 // sufficient.
1689 3 * sent_packet_manager_.GetCongestionWindow() / max_packet_length(); 1687 3 * sent_packet_manager_.EstimateMaxPacketsInFlight(
1688 max_packet_length());
1690 } 1689 }
1691 } 1690 }
1692 1691
1693 const QuicEncrypter* QuicConnection::encrypter(EncryptionLevel level) const { 1692 const QuicEncrypter* QuicConnection::encrypter(EncryptionLevel level) const {
1694 return framer_.encrypter(level); 1693 return framer_.encrypter(level);
1695 } 1694 }
1696 1695
1697 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) { 1696 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) {
1698 encryption_level_ = level; 1697 encryption_level_ = level;
1699 packet_generator_.set_encryption_level(level); 1698 packet_generator_.set_encryption_level(level);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 // Adjust the idle timeout on client and server to prevent clients from 1932 // Adjust the idle timeout on client and server to prevent clients from
1934 // sending requests to servers which have already closed the connection. 1933 // sending requests to servers which have already closed the connection.
1935 if (is_server_) { 1934 if (is_server_) {
1936 timeout = timeout.Add(QuicTime::Delta::FromSeconds(3)); 1935 timeout = timeout.Add(QuicTime::Delta::FromSeconds(3));
1937 } else if (timeout > QuicTime::Delta::FromSeconds(1)) { 1936 } else if (timeout > QuicTime::Delta::FromSeconds(1)) {
1938 timeout = timeout.Subtract(QuicTime::Delta::FromSeconds(1)); 1937 timeout = timeout.Subtract(QuicTime::Delta::FromSeconds(1));
1939 } 1938 }
1940 1939
1941 if (timeout < idle_network_timeout_) { 1940 if (timeout < idle_network_timeout_) {
1942 idle_network_timeout_ = timeout; 1941 idle_network_timeout_ = timeout;
1943 if (FLAGS_quic_timeouts_only_from_alarms) { 1942 SetTimeoutAlarm();
1944 SetTimeoutAlarm();
1945 } else {
1946 CheckForTimeout();
1947 }
1948 } else { 1943 } else {
1949 idle_network_timeout_ = timeout; 1944 idle_network_timeout_ = timeout;
1950 } 1945 }
1951 } 1946 }
1952 1947
1953 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) { 1948 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) {
1954 if (timeout < overall_connection_timeout_) { 1949 if (timeout < overall_connection_timeout_) {
1955 overall_connection_timeout_ = timeout; 1950 overall_connection_timeout_ = timeout;
1956 if (FLAGS_quic_timeouts_only_from_alarms) { 1951 SetTimeoutAlarm();
1957 SetTimeoutAlarm();
1958 } else {
1959 CheckForTimeout();
1960 }
1961 } else { 1952 } else {
1962 overall_connection_timeout_ = timeout; 1953 overall_connection_timeout_ = timeout;
1963 } 1954 }
1964 } 1955 }
1965 1956
1966 void QuicConnection::SetNetworkTimeouts(QuicTime::Delta overall_timeout, 1957 void QuicConnection::SetNetworkTimeouts(QuicTime::Delta overall_timeout,
1967 QuicTime::Delta idle_timeout) { 1958 QuicTime::Delta idle_timeout) {
1968 LOG_IF(DFATAL, idle_timeout > overall_timeout) 1959 LOG_IF(DFATAL, idle_timeout > overall_timeout)
1969 << "idle_timeout:" << idle_timeout.ToMilliseconds() 1960 << "idle_timeout:" << idle_timeout.ToMilliseconds()
1970 << " overall_timeout:" << overall_timeout.ToMilliseconds(); 1961 << " overall_timeout:" << overall_timeout.ToMilliseconds();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 } 2099 }
2109 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2100 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2110 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2101 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2111 return true; 2102 return true;
2112 } 2103 }
2113 } 2104 }
2114 return false; 2105 return false;
2115 } 2106 }
2116 2107
2117 } // namespace net 2108 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698