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

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

Issue 605733006: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert Patch Set 3 Created 6 years, 2 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 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), 212 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))),
213 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), 213 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))),
214 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), 214 send_alarm_(helper->CreateAlarm(new SendAlarm(this))),
215 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), 215 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))),
216 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), 216 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))),
217 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), 217 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))),
218 packet_generator_(connection_id_, &framer_, random_generator_, this), 218 packet_generator_(connection_id_, &framer_, random_generator_, this),
219 idle_network_timeout_( 219 idle_network_timeout_(
220 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)), 220 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)),
221 overall_connection_timeout_(QuicTime::Delta::Infinite()), 221 overall_connection_timeout_(QuicTime::Delta::Infinite()),
222 time_of_last_received_packet_( 222 time_of_last_received_packet_(clock_->ApproximateNow()),
223 FLAGS_quic_timeouts_require_activity 223 time_of_last_sent_new_packet_(clock_->ApproximateNow()),
224 ? QuicTime::Zero() : clock_->ApproximateNow()),
225 time_of_last_sent_new_packet_(
226 FLAGS_quic_timeouts_require_activity
227 ? QuicTime::Zero() : clock_->ApproximateNow()),
228 sequence_number_of_last_sent_packet_(0), 224 sequence_number_of_last_sent_packet_(0),
229 sent_packet_manager_( 225 sent_packet_manager_(
230 is_server, clock_, &stats_, 226 is_server, clock_, &stats_,
231 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, 227 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic,
232 FLAGS_quic_use_time_loss_detection ? kTime : kNack), 228 FLAGS_quic_use_time_loss_detection ? kTime : kNack),
233 version_negotiation_state_(START_NEGOTIATION), 229 version_negotiation_state_(START_NEGOTIATION),
234 is_server_(is_server), 230 is_server_(is_server),
235 connected_(true), 231 connected_(true),
236 peer_ip_changed_(false), 232 peer_ip_changed_(false),
237 peer_port_changed_(false), 233 peer_port_changed_(false),
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 DVLOG(1) << ENDPOINT << "time of last sent packet: " 1431 DVLOG(1) << ENDPOINT << "time of last sent packet: "
1436 << now.ToDebuggingValue(); 1432 << now.ToDebuggingValue();
1437 1433
1438 // TODO(ianswett): Change the sequence number length and other packet creator 1434 // TODO(ianswett): Change the sequence number length and other packet creator
1439 // options by a more explicit API than setting a struct value directly, 1435 // options by a more explicit API than setting a struct value directly,
1440 // perhaps via the NetworkChangeVisitor. 1436 // perhaps via the NetworkChangeVisitor.
1441 packet_generator_.UpdateSequenceNumberLength( 1437 packet_generator_.UpdateSequenceNumberLength(
1442 sent_packet_manager_.least_packet_awaited_by_peer(), 1438 sent_packet_manager_.least_packet_awaited_by_peer(),
1443 sent_packet_manager_.GetCongestionWindow()); 1439 sent_packet_manager_.GetCongestionWindow());
1444 1440
1445 if (packet->original_sequence_number == 0) { 1441 if (packet->original_sequence_number != 0 && debug_visitor_.get() != NULL) {
1446 sent_packet_manager_.OnSerializedPacket(packet->serialized_packet); 1442 debug_visitor_->OnPacketRetransmitted(
1447 } else { 1443 packet->original_sequence_number, sequence_number);
1448 if (debug_visitor_.get() != NULL) {
1449 debug_visitor_->OnPacketRetransmitted(
1450 packet->original_sequence_number, sequence_number);
1451 }
1452 sent_packet_manager_.OnRetransmittedPacket(packet->original_sequence_number,
1453 sequence_number);
1454 } 1444 }
1455 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( 1445 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent(
1456 sequence_number, 1446 &packet->serialized_packet,
1447 packet->original_sequence_number,
1457 now, 1448 now,
1458 encrypted->length(), 1449 encrypted->length(),
1459 packet->transmission_type, 1450 packet->transmission_type,
1460 IsRetransmittable(*packet)); 1451 IsRetransmittable(*packet));
1461 // The SentPacketManager now owns the retransmittable frames.
1462 packet->serialized_packet.retransmittable_frames = NULL;
1463 1452
1464 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { 1453 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
1465 retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(), 1454 retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(),
1466 QuicTime::Delta::FromMilliseconds(1)); 1455 QuicTime::Delta::FromMilliseconds(1));
1467 } 1456 }
1468 1457
1469 stats_.bytes_sent += result.bytes_written; 1458 stats_.bytes_sent += result.bytes_written;
1470 ++stats_.packets_sent; 1459 ++stats_.packets_sent;
1471 if (packet->transmission_type != NOT_RETRANSMISSION) { 1460 if (packet->transmission_type != NOT_RETRANSMISSION) {
1472 stats_.bytes_retransmitted += result.bytes_written; 1461 stats_.bytes_retransmitted += result.bytes_written;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 // Adjust the idle timeout on client and server to prevent clients from 1869 // Adjust the idle timeout on client and server to prevent clients from
1881 // sending requests to servers which have already closed the connection. 1870 // sending requests to servers which have already closed the connection.
1882 if (is_server_) { 1871 if (is_server_) {
1883 timeout = timeout.Add(QuicTime::Delta::FromSeconds(1)); 1872 timeout = timeout.Add(QuicTime::Delta::FromSeconds(1));
1884 } else if (timeout > QuicTime::Delta::FromSeconds(1)) { 1873 } else if (timeout > QuicTime::Delta::FromSeconds(1)) {
1885 timeout = timeout.Subtract(QuicTime::Delta::FromSeconds(1)); 1874 timeout = timeout.Subtract(QuicTime::Delta::FromSeconds(1));
1886 } 1875 }
1887 1876
1888 if (timeout < idle_network_timeout_) { 1877 if (timeout < idle_network_timeout_) {
1889 idle_network_timeout_ = timeout; 1878 idle_network_timeout_ = timeout;
1890 CheckForTimeout(); 1879 if (FLAGS_quic_timeouts_only_from_alarms) {
1880 SetTimeoutAlarm();
1881 } else {
1882 CheckForTimeout();
1883 }
1891 } else { 1884 } else {
1892 idle_network_timeout_ = timeout; 1885 idle_network_timeout_ = timeout;
1893 } 1886 }
1894 } 1887 }
1895 1888
1896 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) { 1889 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) {
1897 if (timeout < overall_connection_timeout_) { 1890 if (timeout < overall_connection_timeout_) {
1898 overall_connection_timeout_ = timeout; 1891 overall_connection_timeout_ = timeout;
1899 CheckForTimeout(); 1892 if (FLAGS_quic_timeouts_only_from_alarms) {
1893 SetTimeoutAlarm();
1894 } else {
1895 CheckForTimeout();
1896 }
1900 } else { 1897 } else {
1901 overall_connection_timeout_ = timeout; 1898 overall_connection_timeout_ = timeout;
1902 } 1899 }
1903 } 1900 }
1904 1901
1905 bool QuicConnection::CheckForTimeout() { 1902 void QuicConnection::CheckForTimeout() {
1906 QuicTime now = clock_->ApproximateNow(); 1903 QuicTime now = clock_->ApproximateNow();
1907 QuicTime time_of_last_packet = max(time_of_last_received_packet_, 1904 QuicTime time_of_last_packet = max(time_of_last_received_packet_,
1908 time_of_last_sent_new_packet_); 1905 time_of_last_sent_new_packet_);
1909 1906
1910 // If no packets have been sent or received, then don't timeout.
1911 if (FLAGS_quic_timeouts_require_activity &&
1912 !time_of_last_packet.IsInitialized()) {
1913 timeout_alarm_->Cancel();
1914 timeout_alarm_->Set(now.Add(idle_network_timeout_));
1915 return false;
1916 }
1917
1918 // |delta| can be < 0 as |now| is approximate time but |time_of_last_packet| 1907 // |delta| can be < 0 as |now| is approximate time but |time_of_last_packet|
1919 // is accurate time. However, this should not change the behavior of 1908 // is accurate time. However, this should not change the behavior of
1920 // timeout handling. 1909 // timeout handling.
1921 QuicTime::Delta delta = now.Subtract(time_of_last_packet); 1910 QuicTime::Delta idle_duration = now.Subtract(time_of_last_packet);
1922 DVLOG(1) << ENDPOINT << "last packet " 1911 DVLOG(1) << ENDPOINT << "last packet "
1923 << time_of_last_packet.ToDebuggingValue() 1912 << time_of_last_packet.ToDebuggingValue()
1924 << " now:" << now.ToDebuggingValue() 1913 << " now:" << now.ToDebuggingValue()
1925 << " delta:" << delta.ToMicroseconds() 1914 << " idle_duration:" << idle_duration.ToMicroseconds()
1926 << " network_timeout: " << idle_network_timeout_.ToMicroseconds(); 1915 << " idle_network_timeout: "
1927 if (delta >= idle_network_timeout_) { 1916 << idle_network_timeout_.ToMicroseconds();
1917 if (idle_duration >= idle_network_timeout_) {
1928 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity."; 1918 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity.";
1929 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT); 1919 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT);
1930 return true; 1920 return;
1931 } 1921 }
1932 1922
1933 // Next timeout delta.
1934 QuicTime::Delta timeout = idle_network_timeout_.Subtract(delta);
1935
1936 if (!overall_connection_timeout_.IsInfinite()) { 1923 if (!overall_connection_timeout_.IsInfinite()) {
1937 QuicTime::Delta connected_time = 1924 QuicTime::Delta connected_duration =
1938 now.Subtract(stats_.connection_creation_time); 1925 now.Subtract(stats_.connection_creation_time);
1939 DVLOG(1) << ENDPOINT << "connection time: " 1926 DVLOG(1) << ENDPOINT << "connection time: "
1940 << connected_time.ToMilliseconds() << " overall timeout: " 1927 << connected_duration.ToMicroseconds() << " overall timeout: "
1941 << overall_connection_timeout_.ToMilliseconds(); 1928 << overall_connection_timeout_.ToMicroseconds();
1942 if (connected_time >= overall_connection_timeout_) { 1929 if (connected_duration >= overall_connection_timeout_) {
1943 DVLOG(1) << ENDPOINT << 1930 DVLOG(1) << ENDPOINT <<
1944 "Connection timedout due to overall connection timeout."; 1931 "Connection timedout due to overall connection timeout.";
1945 SendConnectionClose(QUIC_CONNECTION_OVERALL_TIMED_OUT); 1932 SendConnectionClose(QUIC_CONNECTION_OVERALL_TIMED_OUT);
1946 return true; 1933 return;
1947 }
1948
1949 // Take the min timeout.
1950 QuicTime::Delta connection_timeout =
1951 overall_connection_timeout_.Subtract(connected_time);
1952 if (connection_timeout < timeout) {
1953 timeout = connection_timeout;
1954 } 1934 }
1955 } 1935 }
1956 1936
1937 SetTimeoutAlarm();
1938 }
1939
1940 void QuicConnection::SetTimeoutAlarm() {
1941 QuicTime time_of_last_packet = max(time_of_last_received_packet_,
1942 time_of_last_sent_new_packet_);
1943
1944 QuicTime deadline = time_of_last_packet.Add(idle_network_timeout_);
1945 if (!overall_connection_timeout_.IsInfinite()) {
1946 deadline = min(deadline,
1947 stats_.connection_creation_time.Add(
1948 overall_connection_timeout_));
1949 }
1950
1957 timeout_alarm_->Cancel(); 1951 timeout_alarm_->Cancel();
1958 timeout_alarm_->Set(now.Add(timeout)); 1952 timeout_alarm_->Set(deadline);
1959 return false;
1960 } 1953 }
1961 1954
1962 void QuicConnection::SetPingAlarm() { 1955 void QuicConnection::SetPingAlarm() {
1963 if (is_server_) { 1956 if (is_server_) {
1964 // Only clients send pings. 1957 // Only clients send pings.
1965 return; 1958 return;
1966 } 1959 }
1967 if (!visitor_->HasOpenDataStreams()) { 1960 if (!visitor_->HasOpenDataStreams()) {
1968 ping_alarm_->Cancel(); 1961 ping_alarm_->Cancel();
1969 // Don't send a ping unless there are open streams. 1962 // Don't send a ping unless there are open streams.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 } 2026 }
2034 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2027 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2035 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2028 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2036 return true; 2029 return true;
2037 } 2030 }
2038 } 2031 }
2039 return false; 2032 return false;
2040 } 2033 }
2041 2034
2042 } // namespace net 2035 } // 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