| 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/chromium/quic_chromium_client_session.h" | 5 #include "net/quic/chromium/quic_chromium_client_session.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "net/ssl/channel_id_service.h" | 32 #include "net/ssl/channel_id_service.h" |
| 33 #include "net/ssl/ssl_connection_status_flags.h" | 33 #include "net/ssl/ssl_connection_status_flags.h" |
| 34 #include "net/ssl/ssl_info.h" | 34 #include "net/ssl/ssl_info.h" |
| 35 #include "net/ssl/token_binding.h" | 35 #include "net/ssl/token_binding.h" |
| 36 #include "net/udp/datagram_client_socket.h" | 36 #include "net/udp/datagram_client_socket.h" |
| 37 | 37 |
| 38 namespace net { | 38 namespace net { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // The length of time to wait for a 0-RTT handshake to complete | |
| 43 // before allowing the requests to possibly proceed over TCP. | |
| 44 const int k0RttHandshakeTimeoutMs = 300; | |
| 45 | |
| 46 // IPv6 packets have an additional 20 bytes of overhead than IPv4 packets. | 42 // IPv6 packets have an additional 20 bytes of overhead than IPv4 packets. |
| 47 const size_t kAdditionalOverheadForIPv6 = 20; | 43 const size_t kAdditionalOverheadForIPv6 = 20; |
| 48 | 44 |
| 49 // Maximum number of Readers that are created for any session due to | 45 // Maximum number of Readers that are created for any session due to |
| 50 // connection migration. A new Reader is created every time this endpoint's | 46 // connection migration. A new Reader is created every time this endpoint's |
| 51 // IP address changes. | 47 // IP address changes. |
| 52 const size_t kMaxReadersPerQuicSession = 5; | 48 const size_t kMaxReadersPerQuicSession = 5; |
| 53 | 49 |
| 54 // Size of the MRU cache of Token Binding signatures. Since the material being | 50 // Size of the MRU cache of Token Binding signatures. Since the material being |
| 55 // signed is constant and there aren't many keys being used to sign, a fairly | 51 // signed is constant and there aren't many keys being used to sign, a fairly |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 handshake_start_ = base::TimeTicks::Now(); | 603 handshake_start_ = base::TimeTicks::Now(); |
| 608 RecordHandshakeState(STATE_STARTED); | 604 RecordHandshakeState(STATE_STARTED); |
| 609 DCHECK(flow_controller()); | 605 DCHECK(flow_controller()); |
| 610 crypto_stream_->CryptoConnect(); | 606 crypto_stream_->CryptoConnect(); |
| 611 | 607 |
| 612 if (IsCryptoHandshakeConfirmed()) | 608 if (IsCryptoHandshakeConfirmed()) |
| 613 return OK; | 609 return OK; |
| 614 | 610 |
| 615 // Unless we require handshake confirmation, activate the session if | 611 // Unless we require handshake confirmation, activate the session if |
| 616 // we have established initial encryption. | 612 // we have established initial encryption. |
| 617 if (!require_confirmation_ && IsEncryptionEstablished()) { | 613 if (!require_confirmation_ && IsEncryptionEstablished()) |
| 618 // To mitigate the effects of hanging 0-RTT connections, set up a timer to | |
| 619 // cancel any requests, if the handshake takes too long. | |
| 620 task_runner_->PostDelayedTask( | |
| 621 FROM_HERE, base::Bind(&QuicChromiumClientSession::OnConnectTimeout, | |
| 622 weak_factory_.GetWeakPtr()), | |
| 623 base::TimeDelta::FromMilliseconds(k0RttHandshakeTimeoutMs)); | |
| 624 return OK; | 614 return OK; |
| 625 } | |
| 626 | 615 |
| 627 callback_ = callback; | 616 callback_ = callback; |
| 628 return ERR_IO_PENDING; | 617 return ERR_IO_PENDING; |
| 629 } | 618 } |
| 630 | 619 |
| 631 int QuicChromiumClientSession::ResumeCryptoConnect( | 620 int QuicChromiumClientSession::ResumeCryptoConnect( |
| 632 const CompletionCallback& callback) { | 621 const CompletionCallback& callback) { |
| 633 if (IsCryptoHandshakeConfirmed()) | 622 if (IsCryptoHandshakeConfirmed()) |
| 634 return OK; | 623 return OK; |
| 635 | 624 |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 if (!going_away_) | 1151 if (!going_away_) |
| 1163 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); | 1152 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); |
| 1164 | 1153 |
| 1165 going_away_ = true; | 1154 going_away_ = true; |
| 1166 DCHECK_EQ(0u, GetNumActiveStreams()); | 1155 DCHECK_EQ(0u, GetNumActiveStreams()); |
| 1167 // Will delete |this|. | 1156 // Will delete |this|. |
| 1168 if (stream_factory_) | 1157 if (stream_factory_) |
| 1169 stream_factory_->OnSessionClosed(this); | 1158 stream_factory_->OnSessionClosed(this); |
| 1170 } | 1159 } |
| 1171 | 1160 |
| 1172 void QuicChromiumClientSession::OnConnectTimeout() { | |
| 1173 DCHECK(callback_.is_null()); | |
| 1174 | |
| 1175 if (IsCryptoHandshakeConfirmed()) | |
| 1176 return; | |
| 1177 | |
| 1178 // TODO(rch): re-enable this code once beta is cut. | |
| 1179 // if (stream_factory_) | |
| 1180 // stream_factory_->OnSessionConnectTimeout(this); | |
| 1181 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); | |
| 1182 // DCHECK_EQ(0u, GetNumOpenOutgoingStreams()); | |
| 1183 } | |
| 1184 | |
| 1185 bool QuicChromiumClientSession::MigrateToSocket( | 1161 bool QuicChromiumClientSession::MigrateToSocket( |
| 1186 std::unique_ptr<DatagramClientSocket> socket, | 1162 std::unique_ptr<DatagramClientSocket> socket, |
| 1187 std::unique_ptr<QuicChromiumPacketReader> reader, | 1163 std::unique_ptr<QuicChromiumPacketReader> reader, |
| 1188 std::unique_ptr<QuicChromiumPacketWriter> writer, | 1164 std::unique_ptr<QuicChromiumPacketWriter> writer, |
| 1189 scoped_refptr<StringIOBuffer> packet) { | 1165 scoped_refptr<StringIOBuffer> packet) { |
| 1190 DCHECK_EQ(sockets_.size(), packet_readers_.size()); | 1166 DCHECK_EQ(sockets_.size(), packet_readers_.size()); |
| 1191 if (sockets_.size() >= kMaxReadersPerQuicSession) { | 1167 if (sockets_.size() >= kMaxReadersPerQuicSession) { |
| 1192 return false; | 1168 return false; |
| 1193 } | 1169 } |
| 1194 // TODO(jri): Make SetQuicPacketWriter take a scoped_ptr. | 1170 // TODO(jri): Make SetQuicPacketWriter take a scoped_ptr. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 } | 1220 } |
| 1245 | 1221 |
| 1246 void QuicChromiumClientSession::DeletePromised( | 1222 void QuicChromiumClientSession::DeletePromised( |
| 1247 QuicClientPromisedInfo* promised) { | 1223 QuicClientPromisedInfo* promised) { |
| 1248 if (IsOpenStream(promised->id())) | 1224 if (IsOpenStream(promised->id())) |
| 1249 streams_pushed_and_claimed_count_++; | 1225 streams_pushed_and_claimed_count_++; |
| 1250 QuicClientSessionBase::DeletePromised(promised); | 1226 QuicClientSessionBase::DeletePromised(promised); |
| 1251 } | 1227 } |
| 1252 | 1228 |
| 1253 } // namespace net | 1229 } // namespace net |
| OLD | NEW |