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

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

Issue 734063004: Update from https://crrev.com/304418 (Closed) Base URL: https://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_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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 183
184 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") 184 #define ENDPOINT (is_server_ ? "Server: " : " Client: ")
185 185
186 QuicConnection::QuicConnection(QuicConnectionId connection_id, 186 QuicConnection::QuicConnection(QuicConnectionId connection_id,
187 IPEndPoint address, 187 IPEndPoint address,
188 QuicConnectionHelperInterface* helper, 188 QuicConnectionHelperInterface* helper,
189 const PacketWriterFactory& writer_factory, 189 const PacketWriterFactory& writer_factory,
190 bool owns_writer, 190 bool owns_writer,
191 bool is_server, 191 bool is_server,
192 bool is_secure,
192 const QuicVersionVector& supported_versions) 193 const QuicVersionVector& supported_versions)
193 : framer_(supported_versions, helper->GetClock()->ApproximateNow(), 194 : framer_(supported_versions, helper->GetClock()->ApproximateNow(),
194 is_server), 195 is_server),
195 helper_(helper), 196 helper_(helper),
196 writer_(writer_factory.Create(this)), 197 writer_(writer_factory.Create(this)),
197 owns_writer_(owns_writer), 198 owns_writer_(owns_writer),
198 encryption_level_(ENCRYPTION_NONE), 199 encryption_level_(ENCRYPTION_NONE),
199 has_forward_secure_encrypter_(false), 200 has_forward_secure_encrypter_(false),
200 first_required_forward_secure_packet_(0), 201 first_required_forward_secure_packet_(0),
201 clock_(helper->GetClock()), 202 clock_(helper->GetClock()),
(...skipping 13 matching lines...) Expand all
215 ack_queued_(false), 216 ack_queued_(false),
216 num_packets_received_since_last_ack_sent_(0), 217 num_packets_received_since_last_ack_sent_(0),
217 stop_waiting_count_(0), 218 stop_waiting_count_(0),
218 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), 219 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))),
219 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), 220 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))),
220 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), 221 send_alarm_(helper->CreateAlarm(new SendAlarm(this))),
221 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), 222 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))),
222 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), 223 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))),
223 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), 224 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))),
224 packet_generator_(connection_id_, &framer_, random_generator_, this), 225 packet_generator_(connection_id_, &framer_, random_generator_, this),
225 idle_network_timeout_(FLAGS_quic_unified_timeouts ? 226 idle_network_timeout_(QuicTime::Delta::Infinite()),
226 QuicTime::Delta::Infinite() :
227 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs)),
228 overall_connection_timeout_(QuicTime::Delta::Infinite()), 227 overall_connection_timeout_(QuicTime::Delta::Infinite()),
229 time_of_last_received_packet_(clock_->ApproximateNow()), 228 time_of_last_received_packet_(clock_->ApproximateNow()),
230 time_of_last_sent_new_packet_(clock_->ApproximateNow()), 229 time_of_last_sent_new_packet_(clock_->ApproximateNow()),
231 sequence_number_of_last_sent_packet_(0), 230 sequence_number_of_last_sent_packet_(0),
232 sent_packet_manager_( 231 sent_packet_manager_(
233 is_server, clock_, &stats_, 232 is_server, clock_, &stats_,
234 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, 233 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic,
235 FLAGS_quic_use_time_loss_detection ? kTime : kNack), 234 FLAGS_quic_use_time_loss_detection ? kTime : kNack,
235 is_secure),
236 version_negotiation_state_(START_NEGOTIATION), 236 version_negotiation_state_(START_NEGOTIATION),
237 is_server_(is_server), 237 is_server_(is_server),
238 connected_(true), 238 connected_(true),
239 peer_ip_changed_(false), 239 peer_ip_changed_(false),
240 peer_port_changed_(false), 240 peer_port_changed_(false),
241 self_ip_changed_(false), 241 self_ip_changed_(false),
242 self_port_changed_(false), 242 self_port_changed_(false),
243 can_truncate_connection_ids_(true) { 243 can_truncate_connection_ids_(true),
244 is_secure_(is_secure) {
244 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " 245 DVLOG(1) << ENDPOINT << "Created connection with connection_id: "
245 << connection_id; 246 << connection_id;
246 if (!FLAGS_quic_unified_timeouts) {
247 timeout_alarm_->Set(clock_->ApproximateNow().Add(idle_network_timeout_));
248 }
249 framer_.set_visitor(this); 247 framer_.set_visitor(this);
250 framer_.set_received_entropy_calculator(&received_packet_manager_); 248 framer_.set_received_entropy_calculator(&received_packet_manager_);
251 stats_.connection_creation_time = clock_->ApproximateNow(); 249 stats_.connection_creation_time = clock_->ApproximateNow();
252 sent_packet_manager_.set_network_change_visitor(this); 250 sent_packet_manager_.set_network_change_visitor(this);
253 } 251 }
254 252
255 QuicConnection::~QuicConnection() { 253 QuicConnection::~QuicConnection() {
256 if (owns_writer_) { 254 if (owns_writer_) {
257 delete writer_; 255 delete writer_;
258 } 256 }
259 STLDeleteElements(&undecryptable_packets_); 257 STLDeleteElements(&undecryptable_packets_);
260 STLDeleteValues(&group_map_); 258 STLDeleteValues(&group_map_);
261 for (QueuedPacketList::iterator it = queued_packets_.begin(); 259 for (QueuedPacketList::iterator it = queued_packets_.begin();
262 it != queued_packets_.end(); ++it) { 260 it != queued_packets_.end(); ++it) {
263 delete it->serialized_packet.retransmittable_frames; 261 delete it->serialized_packet.retransmittable_frames;
264 delete it->serialized_packet.packet; 262 delete it->serialized_packet.packet;
265 } 263 }
266 } 264 }
267 265
268 void QuicConnection::SetFromConfig(const QuicConfig& config) { 266 void QuicConnection::SetFromConfig(const QuicConfig& config) {
269 if (FLAGS_quic_unified_timeouts) { 267 if (config.negotiated()) {
270 if (config.negotiated()) { 268 SetNetworkTimeouts(QuicTime::Delta::Infinite(),
271 SetNetworkTimeouts(QuicTime::Delta::Infinite(), 269 config.IdleConnectionStateLifetime());
272 config.IdleConnectionStateLifetime());
273 } else {
274 SetNetworkTimeouts(config.max_time_before_crypto_handshake(),
275 config.max_idle_time_before_crypto_handshake());
276 }
277 } else { 270 } else {
278 SetIdleNetworkTimeout(config.IdleConnectionStateLifetime()); 271 SetNetworkTimeouts(config.max_time_before_crypto_handshake(),
272 config.max_idle_time_before_crypto_handshake());
279 } 273 }
274
280 sent_packet_manager_.SetFromConfig(config); 275 sent_packet_manager_.SetFromConfig(config);
281 if (FLAGS_allow_truncated_connection_ids_for_quic && 276 if (FLAGS_allow_truncated_connection_ids_for_quic &&
282 config.HasReceivedBytesForConnectionId() && 277 config.HasReceivedBytesForConnectionId() &&
283 can_truncate_connection_ids_) { 278 can_truncate_connection_ids_) {
284 packet_generator_.SetConnectionIdLength( 279 packet_generator_.SetConnectionIdLength(
285 config.ReceivedBytesForConnectionId()); 280 config.ReceivedBytesForConnectionId());
286 } 281 }
287 max_undecryptable_packets_ = config.max_undecryptable_packets(); 282 max_undecryptable_packets_ = config.max_undecryptable_packets();
288 } 283 }
289 284
(...skipping 1601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 QuicFecGroup* fec_group = it->second; 1886 QuicFecGroup* fec_group = it->second;
1892 DCHECK(!fec_group->CanRevive()); 1887 DCHECK(!fec_group->CanRevive());
1893 FecGroupMap::iterator next = it; 1888 FecGroupMap::iterator next = it;
1894 ++next; 1889 ++next;
1895 group_map_.erase(it); 1890 group_map_.erase(it);
1896 delete fec_group; 1891 delete fec_group;
1897 it = next; 1892 it = next;
1898 } 1893 }
1899 } 1894 }
1900 1895
1901 size_t QuicConnection::max_packet_length() const { 1896 QuicByteCount QuicConnection::max_packet_length() const {
1902 return packet_generator_.max_packet_length(); 1897 return packet_generator_.max_packet_length();
1903 } 1898 }
1904 1899
1905 void QuicConnection::set_max_packet_length(size_t length) { 1900 void QuicConnection::set_max_packet_length(QuicByteCount length) {
1906 return packet_generator_.set_max_packet_length(length); 1901 return packet_generator_.set_max_packet_length(length);
1907 } 1902 }
1908 1903
1909 bool QuicConnection::HasQueuedData() const { 1904 bool QuicConnection::HasQueuedData() const {
1910 return pending_version_negotiation_packet_ || 1905 return pending_version_negotiation_packet_ ||
1911 !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); 1906 !queued_packets_.empty() || packet_generator_.HasQueuedFrames();
1912 } 1907 }
1913 1908
1914 bool QuicConnection::CanWriteStreamData() { 1909 bool QuicConnection::CanWriteStreamData() {
1915 // Don't write stream data if there are negotiation or queued data packets 1910 // Don't write stream data if there are negotiation or queued data packets
1916 // to send. Otherwise, continue and bundle as many frames as possible. 1911 // to send. Otherwise, continue and bundle as many frames as possible.
1917 if (pending_version_negotiation_packet_ || !queued_packets_.empty()) { 1912 if (pending_version_negotiation_packet_ || !queued_packets_.empty()) {
1918 return false; 1913 return false;
1919 } 1914 }
1920 1915
1921 IsHandshake pending_handshake = visitor_->HasPendingHandshake() ? 1916 IsHandshake pending_handshake = visitor_->HasPendingHandshake() ?
1922 IS_HANDSHAKE : NOT_HANDSHAKE; 1917 IS_HANDSHAKE : NOT_HANDSHAKE;
1923 // Sending queued packets may have caused the socket to become write blocked, 1918 // Sending queued packets may have caused the socket to become write blocked,
1924 // or the congestion manager to prohibit sending. If we've sent everything 1919 // or the congestion manager to prohibit sending. If we've sent everything
1925 // we had queued and we're still not blocked, let the visitor know it can 1920 // we had queued and we're still not blocked, let the visitor know it can
1926 // write more. 1921 // write more.
1927 return ShouldGeneratePacket(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, 1922 return ShouldGeneratePacket(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA,
1928 pending_handshake); 1923 pending_handshake);
1929 } 1924 }
1930 1925
1931 void QuicConnection::SetIdleNetworkTimeout(QuicTime::Delta timeout) {
1932 // Adjust the idle timeout on client and server to prevent clients from
1933 // sending requests to servers which have already closed the connection.
1934 if (is_server_) {
1935 timeout = timeout.Add(QuicTime::Delta::FromSeconds(3));
1936 } else if (timeout > QuicTime::Delta::FromSeconds(1)) {
1937 timeout = timeout.Subtract(QuicTime::Delta::FromSeconds(1));
1938 }
1939
1940 if (timeout < idle_network_timeout_) {
1941 idle_network_timeout_ = timeout;
1942 SetTimeoutAlarm();
1943 } else {
1944 idle_network_timeout_ = timeout;
1945 }
1946 }
1947
1948 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) {
1949 if (timeout < overall_connection_timeout_) {
1950 overall_connection_timeout_ = timeout;
1951 SetTimeoutAlarm();
1952 } else {
1953 overall_connection_timeout_ = timeout;
1954 }
1955 }
1956
1957 void QuicConnection::SetNetworkTimeouts(QuicTime::Delta overall_timeout, 1926 void QuicConnection::SetNetworkTimeouts(QuicTime::Delta overall_timeout,
1958 QuicTime::Delta idle_timeout) { 1927 QuicTime::Delta idle_timeout) {
1959 LOG_IF(DFATAL, idle_timeout > overall_timeout) 1928 LOG_IF(DFATAL, idle_timeout > overall_timeout)
1960 << "idle_timeout:" << idle_timeout.ToMilliseconds() 1929 << "idle_timeout:" << idle_timeout.ToMilliseconds()
1961 << " overall_timeout:" << overall_timeout.ToMilliseconds(); 1930 << " overall_timeout:" << overall_timeout.ToMilliseconds();
1962 // Adjust the idle timeout on client and server to prevent clients from 1931 // Adjust the idle timeout on client and server to prevent clients from
1963 // sending requests to servers which have already closed the connection. 1932 // sending requests to servers which have already closed the connection.
1964 if (is_server_) { 1933 if (is_server_) {
1965 idle_timeout = idle_timeout.Add(QuicTime::Delta::FromSeconds(3)); 1934 idle_timeout = idle_timeout.Add(QuicTime::Delta::FromSeconds(3));
1966 } else if (idle_timeout > QuicTime::Delta::FromSeconds(1)) { 1935 } else if (idle_timeout > QuicTime::Delta::FromSeconds(1)) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 } 2068 }
2100 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2069 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2101 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2070 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2102 return true; 2071 return true;
2103 } 2072 }
2104 } 2073 }
2105 return false; 2074 return false;
2106 } 2075 }
2107 2076
2108 } // namespace net 2077 } // 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