[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | // |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5 | // A client specific quic::QuicSession subclass. This class owns the underlying |
| 6 | // quic::QuicConnection and QuicConnectionHelper objects. The connection stores |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 7 | // a non-owning pointer to the helper so this session needs to ensure that |
| 8 | // the helper outlives the connection. |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 9 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 10 | #ifndef NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_ |
| 11 | #define NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_ |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 12 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 15 | #include <list> |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 16 | #include <memory> |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 17 | #include <set> |
[email protected] | 41d6b17 | 2013-01-29 16:10:57 | [diff] [blame] | 18 | #include <string> |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 19 | #include <vector> |
[email protected] | 41d6b17 | 2013-01-29 16:10:57 | [diff] [blame] | 20 | |
nharper | d5cddca | 2016-02-27 03:37:52 | [diff] [blame] | 21 | #include "base/containers/mru_cache.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 22 | #include "base/macros.h" |
[email protected] | c4338da | 2014-06-07 08:47:07 | [diff] [blame] | 23 | #include "base/time/time.h" |
Sebastien Marchand | efda77e53 | 2019-01-25 22:53:52 | [diff] [blame] | 24 | #include "base/timer/timer.h" |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 25 | #include "net/base/completion_once_callback.h" |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 26 | #include "net/base/load_timing_info.h" |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 27 | #include "net/base/net_error_details.h" |
bnc | 81c46c1f | 2016-10-04 16:25:59 | [diff] [blame] | 28 | #include "net/base/net_export.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 29 | #include "net/base/proxy_server.h" |
rtenneti | 052774e | 2015-11-24 21:00:12 | [diff] [blame] | 30 | #include "net/cert/ct_verify_result.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 31 | #include "net/log/net_log_with_source.h" |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 32 | #include "net/quic/quic_chromium_client_stream.h" |
| 33 | #include "net/quic/quic_chromium_packet_reader.h" |
| 34 | #include "net/quic/quic_chromium_packet_writer.h" |
| 35 | #include "net/quic/quic_connection_logger.h" |
| 36 | #include "net/quic/quic_connectivity_probing_manager.h" |
| 37 | #include "net/quic/quic_session_key.h" |
tbansal | ca83c00 | 2016-04-28 20:56:28 | [diff] [blame] | 38 | #include "net/socket/socket_performance_watcher.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 39 | #include "net/spdy/http2_priority_dependencies.h" |
| 40 | #include "net/spdy/multiplexed_session.h" |
| 41 | #include "net/spdy/server_push_delegate.h" |
Victor Vasiliev | 6bb59d2 | 2019-03-08 21:34:51 | [diff] [blame] | 42 | #include "net/third_party/quiche/src/quic/core/http/quic_client_push_promise_index.h" |
| 43 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_client_session_base.h" |
| 44 | #include "net/third_party/quiche/src/quic/core/quic_crypto_client_stream.h" |
| 45 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 46 | #include "net/third_party/quiche/src/quic/core/quic_server_id.h" |
| 47 | #include "net/third_party/quiche/src/quic/core/quic_time.h" |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 48 | #include "net/traffic_annotation/network_traffic_annotation.h" |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 49 | |
| 50 | namespace net { |
| 51 | |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 52 | class CertVerifyResult; |
[email protected] | 6dcd1d5c | 2013-03-15 07:28:37 | [diff] [blame] | 53 | class DatagramClientSocket; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 54 | class NetLog; |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 55 | class NetworkIsolationKey; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 56 | class QuicCryptoClientStreamFactory; |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 57 | class QuicServerInfo; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 58 | class QuicStreamFactory; |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 59 | class SSLConfigService; |
[email protected] | a69af052 | 2013-07-12 19:23:47 | [diff] [blame] | 60 | class SSLInfo; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 61 | class TransportSecurityState; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 62 | |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 63 | namespace test { |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 64 | class QuicChromiumClientSessionPeer; |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 65 | } // namespace test |
| 66 | |
Bence Béky | 3a76c14 | 2019-07-16 23:53:16 | [diff] [blame] | 67 | // SETTINGS_MAX_HEADERS_LIST_SIZE, the maximum size of uncompressed QUIC headers |
| 68 | // that the server is allowed to send. |
| 69 | const size_t kQuicMaxHeaderListSize = 256 * 1024; |
| 70 | |
Zhongyi Shi | 673f22ef | 2017-10-18 00:00:47 | [diff] [blame] | 71 | // Result of a session migration attempt. |
| 72 | enum class MigrationResult { |
| 73 | SUCCESS, // Migration succeeded. |
| 74 | NO_NEW_NETWORK, // Migration failed since no new network was found. |
| 75 | FAILURE // Migration failed for other reasons. |
| 76 | }; |
| 77 | |
Zhongyi Shi | ef52e20ab | 2017-12-02 10:41:43 | [diff] [blame] | 78 | // Mode of connection migration. |
| 79 | enum class ConnectionMigrationMode { |
| 80 | NO_MIGRATION, |
| 81 | NO_MIGRATION_ON_PATH_DEGRADING_V1, |
| 82 | FULL_MIGRATION_V1, |
| 83 | NO_MIGRATION_ON_PATH_DEGRADING_V2, |
| 84 | FULL_MIGRATION_V2 |
| 85 | }; |
| 86 | |
Cherie Shi | 95f08690 | 2018-03-02 20:09:45 | [diff] [blame] | 87 | // Cause of connection migration. |
| 88 | enum ConnectionMigrationCause { |
Daniel Bratell | de285c3d | 2018-11-08 17:22:54 | [diff] [blame] | 89 | UNKNOWN_CAUSE, |
Cherie Shi | 95f08690 | 2018-03-02 20:09:45 | [diff] [blame] | 90 | ON_NETWORK_CONNECTED, // No probing. |
| 91 | ON_NETWORK_DISCONNECTED, // No probing. |
| 92 | ON_WRITE_ERROR, // No probing. |
| 93 | ON_NETWORK_MADE_DEFAULT, // With probing. |
| 94 | ON_MIGRATE_BACK_TO_DEFAULT_NETWORK, // With probing. |
| 95 | ON_PATH_DEGRADING, // With probing. |
Fan Yang | 8bfc0e2 | 2018-03-27 05:53:40 | [diff] [blame] | 96 | MIGRATION_CAUSE_MAX |
Cherie Shi | 95f08690 | 2018-03-02 20:09:45 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | // Result of connection migration. |
| 100 | enum QuicConnectionMigrationStatus { |
| 101 | MIGRATION_STATUS_NO_MIGRATABLE_STREAMS, |
| 102 | MIGRATION_STATUS_ALREADY_MIGRATED, |
| 103 | MIGRATION_STATUS_INTERNAL_ERROR, |
| 104 | MIGRATION_STATUS_TOO_MANY_CHANGES, |
| 105 | MIGRATION_STATUS_SUCCESS, |
| 106 | MIGRATION_STATUS_NON_MIGRATABLE_STREAM, |
| 107 | MIGRATION_STATUS_NOT_ENABLED, |
| 108 | MIGRATION_STATUS_NO_ALTERNATE_NETWORK, |
| 109 | MIGRATION_STATUS_ON_PATH_DEGRADING_DISABLED, |
| 110 | MIGRATION_STATUS_DISABLED_BY_CONFIG, |
Zhongyi Shi | 7f73865 | 2018-03-02 21:53:48 | [diff] [blame] | 111 | MIGRATION_STATUS_PATH_DEGRADING_NOT_ENABLED, |
| 112 | MIGRATION_STATUS_TIMEOUT, |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 113 | MIGRATION_STATUS_ON_WRITE_ERROR_DISABLED, |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 114 | MIGRATION_STATUS_PATH_DEGRADING_BEFORE_HANDSHAKE_CONFIRMED, |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 115 | MIGRATION_STATUS_IDLE_MIGRATION_TIMEOUT, |
Cherie Shi | 95f08690 | 2018-03-02 20:09:45 | [diff] [blame] | 116 | MIGRATION_STATUS_MAX |
| 117 | }; |
| 118 | |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 119 | // Result of a connectivity probing attempt. |
| 120 | enum class ProbingResult { |
| 121 | PENDING, // Probing started, pending result. |
| 122 | DISABLED_WITH_IDLE_SESSION, // Probing disabled with idle session. |
| 123 | DISABLED_BY_CONFIG, // Probing disabled by config. |
| 124 | DISABLED_BY_NON_MIGRABLE_STREAM, // Probing disabled by special stream. |
| 125 | INTERNAL_ERROR, // Probing failed for internal reason. |
| 126 | FAILURE, // Probing failed for other reason. |
| 127 | }; |
| 128 | |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 129 | class NET_EXPORT_PRIVATE QuicChromiumClientSession |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 130 | : public quic::QuicSpdyClientSessionBase, |
rch | a378f65da | 2016-12-08 22:58:15 | [diff] [blame] | 131 | public MultiplexedSession, |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 132 | public QuicConnectivityProbingManager::Delegate, |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 133 | public QuicChromiumPacketReader::Visitor, |
jri | bce3eec | 2016-09-09 05:41:08 | [diff] [blame] | 134 | public QuicChromiumPacketWriter::Delegate { |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 135 | public: |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 136 | class StreamRequest; |
| 137 | |
| 138 | // Wrapper for interacting with the session in a restricted fashion which |
| 139 | // hides the details of the underlying session's lifetime. All methods of |
| 140 | // the Handle are safe to use even after the underlying session is destroyed. |
rch | 56ec40a | 2017-06-23 14:48:44 | [diff] [blame] | 141 | class NET_EXPORT_PRIVATE Handle |
| 142 | : public MultiplexedSessionHandle, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 143 | public quic::QuicClientPushPromiseIndex::Delegate { |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 144 | public: |
Ryan Hamilton | 6c2a2a8 | 2017-12-15 02:06:28 | [diff] [blame] | 145 | // Constructs a handle to |session| which was created via the alternative |
| 146 | // server |destination|. |
| 147 | Handle(const base::WeakPtr<QuicChromiumClientSession>& session, |
| 148 | const HostPortPair& destination); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 149 | Handle(const Handle& other) = delete; |
| 150 | ~Handle() override; |
| 151 | |
| 152 | // Returns true if the session is still connected. |
| 153 | bool IsConnected() const; |
| 154 | |
| 155 | // Returns true if the handshake has been confirmed. |
| 156 | bool IsCryptoHandshakeConfirmed() const; |
| 157 | |
rch | 56ec40a | 2017-06-23 14:48:44 | [diff] [blame] | 158 | // Starts a request to rendezvous with a promised a stream. If OK is |
| 159 | // returned, then |push_stream_| will be updated with the promised |
| 160 | // stream. If ERR_IO_PENDING is returned, then when the rendezvous is |
| 161 | // eventually completed |callback| will be called. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 162 | int RendezvousWithPromised(const spdy::SpdyHeaderBlock& headers, |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 163 | CompletionOnceCallback callback); |
rch | 56ec40a | 2017-06-23 14:48:44 | [diff] [blame] | 164 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 165 | // Starts a request to create a stream. If OK is returned, then |
| 166 | // |stream_| will be updated with the newly created stream. If |
| 167 | // ERR_IO_PENDING is returned, then when the request is eventuallly |
| 168 | // complete |callback| will be called. |
| 169 | int RequestStream(bool requires_confirmation, |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 170 | CompletionOnceCallback callback, |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 171 | const NetworkTrafficAnnotationTag& traffic_annotation); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 172 | |
Helen Li | aeed1e8 | 2017-08-14 23:52:30 | [diff] [blame] | 173 | // Releases |stream_| to the caller. Returns nullptr if the underlying |
| 174 | // QuicChromiumClientSession is closed. |
rch | 1bcfddf2 | 2017-06-03 00:26:29 | [diff] [blame] | 175 | std::unique_ptr<QuicChromiumClientStream::Handle> ReleaseStream(); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 176 | |
rch | 56ec40a | 2017-06-23 14:48:44 | [diff] [blame] | 177 | // Releases |push_stream_| to the caller. |
| 178 | std::unique_ptr<QuicChromiumClientStream::Handle> ReleasePromisedStream(); |
| 179 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 180 | // Sends Rst for the stream, and makes sure that future calls to |
| 181 | // IsClosedStream(id) return true, which ensures that any subsequent |
| 182 | // frames related to this stream will be ignored (modulo flow |
| 183 | // control accounting). |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 184 | void ResetPromised(quic::QuicStreamId id, |
| 185 | quic::QuicRstStreamErrorCode error_code); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 186 | |
| 187 | // Returns a new packet bundler while will cause writes to be batched up |
| 188 | // until a packet is full, or the last bundler is destroyed. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 189 | std::unique_ptr<quic::QuicConnection::ScopedPacketFlusher> |
Bin Wu | ae74d8b | 2019-06-19 23:55:07 | [diff] [blame] | 190 | CreatePacketBundler(); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 191 | |
| 192 | // Populates network error details for this session. |
| 193 | void PopulateNetErrorDetails(NetErrorDetails* details) const; |
| 194 | |
| 195 | // Returns the connection timing for the handshake of this session. |
| 196 | const LoadTimingInfo::ConnectTiming& GetConnectTiming(); |
| 197 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 198 | // Returns true if |other| is a handle to the same session as this handle. |
| 199 | bool SharesSameSession(const Handle& other) const; |
| 200 | |
| 201 | // Returns the QUIC version used by the session. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 202 | quic::QuicTransportVersion GetQuicVersion() const; |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 203 | |
| 204 | // Copies the remote udp address into |address| and returns a net error |
| 205 | // code. |
| 206 | int GetPeerAddress(IPEndPoint* address) const; |
| 207 | |
Yixin Wang | 0d2c6b7e1 | 2017-08-16 21:12:55 | [diff] [blame] | 208 | // Copies the local udp address into |address| and returns a net error |
| 209 | // code. |
| 210 | int GetSelfAddress(IPEndPoint* address) const; |
| 211 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 212 | // Returns the push promise index associated with the session. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 213 | quic::QuicClientPushPromiseIndex* GetPushPromiseIndex(); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 214 | |
| 215 | // Returns the session's server ID. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 216 | quic::QuicServerId server_id() const { return server_id_; } |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 217 | |
Ryan Hamilton | 6c2a2a8 | 2017-12-15 02:06:28 | [diff] [blame] | 218 | // Returns the alternative server used for this session. |
| 219 | HostPortPair destination() const { return destination_; } |
| 220 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 221 | // Returns the session's net log. |
| 222 | const NetLogWithSource& net_log() const { return net_log_; } |
| 223 | |
Zhongyi Shi | ef52e20ab | 2017-12-02 10:41:43 | [diff] [blame] | 224 | // Returns the session's connection migration mode. |
| 225 | ConnectionMigrationMode connection_migration_mode() const { |
| 226 | return session_->connection_migration_mode(); |
| 227 | } |
| 228 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 229 | // quic::QuicClientPushPromiseIndex::Delegate implementation |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 230 | bool CheckVary(const spdy::SpdyHeaderBlock& client_request, |
| 231 | const spdy::SpdyHeaderBlock& promise_request, |
| 232 | const spdy::SpdyHeaderBlock& promise_response) override; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 233 | void OnRendezvousResult(quic::QuicSpdyStream* stream) override; |
rch | 56ec40a | 2017-06-23 14:48:44 | [diff] [blame] | 234 | |
Yixin Wang | 0d2c6b7e1 | 2017-08-16 21:12:55 | [diff] [blame] | 235 | // Returns true if the session's connection has sent or received any bytes. |
| 236 | bool WasEverUsed() const; |
| 237 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 238 | private: |
| 239 | friend class QuicChromiumClientSession; |
| 240 | friend class QuicChromiumClientSession::StreamRequest; |
| 241 | |
| 242 | // Waits for the handshake to be confirmed and invokes |callback| when |
| 243 | // that happens. If the handshake has already been confirmed, returns OK. |
| 244 | // If the connection has already been closed, returns a net error. If the |
| 245 | // connection closes before the handshake is confirmed, |callback| will |
| 246 | // be invoked with an error. |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 247 | int WaitForHandshakeConfirmation(CompletionOnceCallback callback); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 248 | |
| 249 | // Called when the handshake is confirmed. |
| 250 | void OnCryptoHandshakeConfirmed(); |
| 251 | |
| 252 | // Called when the session is closed with a net error. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 253 | void OnSessionClosed(quic::QuicTransportVersion quic_version, |
Ryan Hamilton | e316e48 | 2017-08-17 02:48:53 | [diff] [blame] | 254 | int net_error, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 255 | quic::QuicErrorCode quic_error, |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 256 | bool port_migration_detected, |
Yixin Wang | 0d2c6b7e1 | 2017-08-16 21:12:55 | [diff] [blame] | 257 | LoadTimingInfo::ConnectTiming connect_timing, |
| 258 | bool was_ever_used); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 259 | |
| 260 | // Called by |request| to create a stream. |
| 261 | int TryCreateStream(StreamRequest* request); |
| 262 | |
| 263 | // Called by |request| to cancel stream request. |
| 264 | void CancelRequest(StreamRequest* request); |
| 265 | |
| 266 | // Underlying session which may be destroyed before this handle. |
| 267 | base::WeakPtr<QuicChromiumClientSession> session_; |
| 268 | |
Ryan Hamilton | 6c2a2a8 | 2017-12-15 02:06:28 | [diff] [blame] | 269 | HostPortPair destination_; |
| 270 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 271 | // Stream request created by |RequestStream()|. |
| 272 | std::unique_ptr<StreamRequest> stream_request_; |
| 273 | |
| 274 | // Information saved from the session which can be used even after the |
| 275 | // session is destroyed. |
| 276 | NetLogWithSource net_log_; |
| 277 | bool was_handshake_confirmed_; |
Ryan Hamilton | e316e48 | 2017-08-17 02:48:53 | [diff] [blame] | 278 | int net_error_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 279 | quic::QuicErrorCode quic_error_; |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 280 | bool port_migration_detected_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 281 | quic::QuicServerId server_id_; |
| 282 | quic::QuicTransportVersion quic_version_; |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 283 | LoadTimingInfo::ConnectTiming connect_timing_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 284 | quic::QuicClientPushPromiseIndex* push_promise_index_; |
rch | 56ec40a | 2017-06-23 14:48:44 | [diff] [blame] | 285 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 286 | // |quic::QuicClientPromisedInfo| owns this. It will be set when |Try()| |
| 287 | // is asynchronous, i.e. it returned quic::QUIC_PENDING, and remains valid |
rch | 56ec40a | 2017-06-23 14:48:44 | [diff] [blame] | 288 | // until |OnRendezvouResult()| fires or |push_handle_->Cancel()| is |
| 289 | // invoked. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 290 | quic::QuicClientPushPromiseIndex::TryHandle* push_handle_; |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 291 | CompletionOnceCallback push_callback_; |
rch | 56ec40a | 2017-06-23 14:48:44 | [diff] [blame] | 292 | std::unique_ptr<QuicChromiumClientStream::Handle> push_stream_; |
Yixin Wang | 0d2c6b7e1 | 2017-08-16 21:12:55 | [diff] [blame] | 293 | |
| 294 | bool was_ever_used_; |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 295 | }; |
| 296 | |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 297 | // A helper class used to manage a request to create a stream. |
| 298 | class NET_EXPORT_PRIVATE StreamRequest { |
| 299 | public: |
rch | 1baa747 | 2017-04-26 05:43:58 | [diff] [blame] | 300 | // Cancels any pending stream creation request and resets |stream_| if |
| 301 | // it has not yet been released. |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 302 | ~StreamRequest(); |
| 303 | |
| 304 | // Starts a request to create a stream. If OK is returned, then |
rch | 1baa747 | 2017-04-26 05:43:58 | [diff] [blame] | 305 | // |stream_| will be updated with the newly created stream. If |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 306 | // ERR_IO_PENDING is returned, then when the request is eventuallly |
| 307 | // complete |callback| will be called. |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 308 | int StartRequest(CompletionOnceCallback callback); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 309 | |
rch | 1bcfddf2 | 2017-06-03 00:26:29 | [diff] [blame] | 310 | // Releases |stream_| to the caller. |
| 311 | std::unique_ptr<QuicChromiumClientStream::Handle> ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 312 | |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 313 | const NetworkTrafficAnnotationTag traffic_annotation() { |
| 314 | return traffic_annotation_; |
| 315 | } |
| 316 | |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 317 | private: |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 318 | friend class QuicChromiumClientSession; |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 319 | |
rch | d606b6c3 | 2017-05-02 17:32:57 | [diff] [blame] | 320 | enum State { |
| 321 | STATE_NONE, |
| 322 | STATE_WAIT_FOR_CONFIRMATION, |
| 323 | STATE_WAIT_FOR_CONFIRMATION_COMPLETE, |
| 324 | STATE_REQUEST_STREAM, |
| 325 | STATE_REQUEST_STREAM_COMPLETE, |
| 326 | }; |
| 327 | |
rch | 9ddcded | 2017-05-06 18:55:57 | [diff] [blame] | 328 | // |session| must outlive this request. |
| 329 | StreamRequest(QuicChromiumClientSession::Handle* session, |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 330 | bool requires_confirmation, |
| 331 | const NetworkTrafficAnnotationTag& traffic_annotation); |
rch | d606b6c3 | 2017-05-02 17:32:57 | [diff] [blame] | 332 | |
| 333 | void OnIOComplete(int rv); |
| 334 | void DoCallback(int rv); |
| 335 | |
| 336 | int DoLoop(int rv); |
| 337 | int DoWaitForConfirmation(); |
| 338 | int DoWaitForConfirmationComplete(int rv); |
| 339 | int DoRequestStream(); |
| 340 | int DoRequestStreamComplete(int rv); |
rch | 1baa747 | 2017-04-26 05:43:58 | [diff] [blame] | 341 | |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 342 | // Called by |session_| for an asynchronous request when the stream |
| 343 | // request has finished successfully. |
Ryan Hamilton | c682cae | 2017-08-21 18:07:17 | [diff] [blame] | 344 | void OnRequestCompleteSuccess( |
| 345 | std::unique_ptr<QuicChromiumClientStream::Handle> stream); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 346 | |
| 347 | // Called by |session_| for an asynchronous request when the stream |
| 348 | // request has finished with an error. Also called with ERR_ABORTED |
| 349 | // if |session_| is destroyed while the stream request is still pending. |
| 350 | void OnRequestCompleteFailure(int rv); |
| 351 | |
rch | 9ddcded | 2017-05-06 18:55:57 | [diff] [blame] | 352 | QuicChromiumClientSession::Handle* session_; |
rch | d606b6c3 | 2017-05-02 17:32:57 | [diff] [blame] | 353 | const bool requires_confirmation_; |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 354 | CompletionOnceCallback callback_; |
Ryan Hamilton | c682cae | 2017-08-21 18:07:17 | [diff] [blame] | 355 | std::unique_ptr<QuicChromiumClientStream::Handle> stream_; |
ckrasic | c9c7b83 | 2016-11-30 22:33:21 | [diff] [blame] | 356 | // For tracking how much time pending stream requests wait. |
| 357 | base::TimeTicks pending_start_time_; |
rch | d606b6c3 | 2017-05-02 17:32:57 | [diff] [blame] | 358 | State next_state_; |
| 359 | |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 360 | const NetworkTrafficAnnotationTag traffic_annotation_; |
| 361 | |
Jeremy Roman | d54000b2 | 2019-07-08 18:40:16 | [diff] [blame] | 362 | base::WeakPtrFactory<StreamRequest> weak_factory_{this}; |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 363 | |
| 364 | DISALLOW_COPY_AND_ASSIGN(StreamRequest); |
| 365 | }; |
| 366 | |
rtenneti | b998b32 | 2014-08-26 00:36:33 | [diff] [blame] | 367 | // Constructs a new session which will own |connection|, but not |
| 368 | // |stream_factory|, which must outlive this session. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 369 | // TODO(rch): decouple the factory from the session via a Delegate interface. |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 370 | QuicChromiumClientSession( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 371 | quic::QuicConnection* connection, |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 372 | std::unique_ptr<DatagramClientSocket> socket, |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 373 | QuicStreamFactory* stream_factory, |
| 374 | QuicCryptoClientStreamFactory* crypto_client_stream_factory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 375 | quic::QuicClock* clock, |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 376 | TransportSecurityState* transport_security_state, |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 377 | SSLConfigService* ssl_config_service, |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 378 | std::unique_ptr<QuicServerInfo> server_info, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 379 | const QuicSessionKey& session_key, |
rch | 433bf5f | 2017-02-14 04:10:47 | [diff] [blame] | 380 | bool require_confirmation, |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 381 | bool migrate_sesion_early_v2, |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 382 | bool migrate_session_on_network_change_v2, |
Zhongyi Shi | d672f754 | 2018-06-08 01:03:26 | [diff] [blame] | 383 | NetworkChangeNotifier::NetworkHandle default_network, |
Zhongyi Shi | e01f2db | 2019-02-22 19:53:23 | [diff] [blame] | 384 | quic::QuicTime::Delta retransmittable_on_wire_timeout, |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame] | 385 | bool migrate_idle_session, |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 386 | base::TimeDelta idle_migration_period, |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 387 | base::TimeDelta max_time_on_non_default_network, |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 388 | int max_migrations_to_non_default_network_on_write_error, |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 389 | int max_migrations_to_non_default_network_on_path_degrading, |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 390 | int yield_after_packets, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 391 | quic::QuicTime::Delta yield_after_duration, |
Zhongyi Shi | dbce7f41 | 2019-02-01 23:16:29 | [diff] [blame] | 392 | bool go_away_on_path_degrading, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 393 | bool headers_include_h2_stream_dependency, |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 394 | int cert_verify_flags, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 395 | const quic::QuicConfig& config, |
| 396 | quic::QuicCryptoClientConfig* crypto_config, |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 397 | const char* const connection_description, |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 398 | base::TimeTicks dns_resolution_start_time, |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 399 | base::TimeTicks dns_resolution_end_time, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 400 | quic::QuicClientPushPromiseIndex* push_promise_index, |
zhongyi | af25754 | 2016-12-19 03:36:01 | [diff] [blame] | 401 | ServerPushDelegate* push_delegate, |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 402 | const base::TickClock* tick_clock, |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 403 | base::SequencedTaskRunner* task_runner, |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 404 | std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 405 | NetLog* net_log); |
| 406 | ~QuicChromiumClientSession() override; |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 407 | |
ckrasic | 52b1db11b | 2016-05-24 19:29:16 | [diff] [blame] | 408 | void Initialize() override; |
| 409 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 410 | void AddHandle(Handle* handle); |
| 411 | void RemoveHandle(Handle* handle); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 412 | |
Zhongyi Shi | ef52e20ab | 2017-12-02 10:41:43 | [diff] [blame] | 413 | // Returns the session's connection migration mode. |
| 414 | ConnectionMigrationMode connection_migration_mode() const; |
| 415 | |
rch | d606b6c3 | 2017-05-02 17:32:57 | [diff] [blame] | 416 | // Waits for the handshake to be confirmed and invokes |callback| when |
| 417 | // that happens. If the handshake has already been confirmed, returns OK. |
| 418 | // If the connection has already been closed, returns a net error. If the |
| 419 | // connection closes before the handshake is confirmed, |callback| will |
| 420 | // be invoked with an error. |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 421 | int WaitForHandshakeConfirmation(CompletionOnceCallback callback); |
rch | d606b6c3 | 2017-05-02 17:32:57 | [diff] [blame] | 422 | |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 423 | // Attempts to create a new stream. If the stream can be |
| 424 | // created immediately, returns OK. If the open stream limit |
| 425 | // has been reached, returns ERR_IO_PENDING, and |request| |
| 426 | // will be added to the stream requets queue and will |
| 427 | // be completed asynchronously. |
| 428 | // TODO(rch): remove |stream| from this and use setter on |request| |
| 429 | // and fix in spdy too. |
rch | 1baa747 | 2017-04-26 05:43:58 | [diff] [blame] | 430 | int TryCreateStream(StreamRequest* request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 431 | |
| 432 | // Cancels the pending stream creation request. |
| 433 | void CancelRequest(StreamRequest* request); |
| 434 | |
jri | bce3eec | 2016-09-09 05:41:08 | [diff] [blame] | 435 | // QuicChromiumPacketWriter::Delegate override. |
| 436 | int HandleWriteError(int error_code, |
Charles 'Buck' Krasic | 3a35aa5 | 2017-08-10 22:20:06 | [diff] [blame] | 437 | scoped_refptr<QuicChromiumPacketWriter::ReusableIOBuffer> |
| 438 | last_packet) override; |
jri | bce3eec | 2016-09-09 05:41:08 | [diff] [blame] | 439 | void OnWriteError(int error_code) override; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 440 | // Called when the associated writer is unblocked. Write the cached |packet_| |
| 441 | // if |packet_| is set. May send a PING packet if |
| 442 | // |send_packet_after_migration_| is set and writer is not blocked after |
| 443 | // writing queued packets. |
jri | bce3eec | 2016-09-09 05:41:08 | [diff] [blame] | 444 | void OnWriteUnblocked() override; |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 445 | |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 446 | // QuicConnectivityProbingManager::Delegate override. |
Zhongyi Shi | fdacb82 | 2018-12-11 22:49:15 | [diff] [blame] | 447 | void OnProbeSucceeded( |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 448 | NetworkChangeNotifier::NetworkHandle network, |
Zhongyi Shi | fdacb82 | 2018-12-11 22:49:15 | [diff] [blame] | 449 | const quic::QuicSocketAddress& peer_address, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 450 | const quic::QuicSocketAddress& self_address, |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 451 | std::unique_ptr<DatagramClientSocket> socket, |
| 452 | std::unique_ptr<QuicChromiumPacketWriter> writer, |
| 453 | std::unique_ptr<QuicChromiumPacketReader> reader) override; |
| 454 | |
Zhongyi Shi | fdacb82 | 2018-12-11 22:49:15 | [diff] [blame] | 455 | void OnProbeFailed(NetworkChangeNotifier::NetworkHandle network, |
| 456 | const quic::QuicSocketAddress& peer_address) override; |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 457 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 458 | bool OnSendConnectivityProbingPacket( |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 459 | QuicChromiumPacketWriter* writer, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 460 | const quic::QuicSocketAddress& peer_address) override; |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 461 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 462 | // quic::QuicSpdySession methods: |
Bence Béky | 984c826 | 2019-02-15 01:08:36 | [diff] [blame] | 463 | size_t WriteHeadersOnHeadersStream( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 464 | quic::QuicStreamId id, |
| 465 | spdy::SpdyHeaderBlock headers, |
| 466 | bool fin, |
| 467 | spdy::SpdyPriority priority, |
| 468 | quic::QuicReferenceCountedPointer<quic::QuicAckListenerInterface> |
| 469 | ack_listener) override; |
| 470 | void UnregisterStreamPriority(quic::QuicStreamId id, bool is_static) override; |
| 471 | void UpdateStreamPriority(quic::QuicStreamId id, |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 472 | spdy::SpdyPriority new_priority) override; |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 473 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 474 | // quic::QuicSession methods: |
| 475 | void OnStreamFrame(const quic::QuicStreamFrame& frame) override; |
Fan Yang | e44bd472 | 2018-10-11 01:11:32 | [diff] [blame] | 476 | QuicChromiumClientStream* CreateOutgoingBidirectionalStream() override; |
| 477 | QuicChromiumClientStream* CreateOutgoingUnidirectionalStream() override; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 478 | const quic::QuicCryptoClientStream* GetCryptoStream() const override; |
| 479 | quic::QuicCryptoClientStream* GetMutableCryptoStream() override; |
| 480 | void CloseStream(quic::QuicStreamId stream_id) override; |
| 481 | void SendRstStream(quic::QuicStreamId id, |
| 482 | quic::QuicRstStreamErrorCode error, |
| 483 | quic::QuicStreamOffset bytes_written) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 484 | void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override; |
| 485 | void OnCryptoHandshakeMessageSent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 486 | const quic::CryptoHandshakeMessage& message) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 487 | void OnCryptoHandshakeMessageReceived( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 488 | const quic::CryptoHandshakeMessage& message) override; |
| 489 | void OnGoAway(const quic::QuicGoAwayFrame& frame) override; |
| 490 | void OnRstStream(const quic::QuicRstStreamFrame& frame) override; |
Zhongyi Shi | 64c0685 | 2018-11-09 23:43:11 | [diff] [blame] | 491 | void OnCanCreateNewOutgoingStream() override; |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 492 | |
[email protected] | 90f62f09 | 2014-03-24 02:41:23 | [diff] [blame] | 493 | // QuicClientSessionBase methods: |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 494 | void OnConfigNegotiated() override; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 495 | void OnProofValid( |
| 496 | const quic::QuicCryptoClientConfig::CachedState& cached) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 497 | void OnProofVerifyDetailsAvailable( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 498 | const quic::ProofVerifyDetails& verify_details) override; |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 499 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 500 | // quic::QuicConnectionVisitorInterface methods: |
Bin Wu | 9c4f0f7 | 2019-06-24 15:34:00 | [diff] [blame] | 501 | void OnConnectionClosed(const quic::QuicConnectionCloseFrame& frame, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 502 | quic::ConnectionCloseSource source) override; |
Michael Warres | 74ee3ce | 2017-10-09 15:26:37 | [diff] [blame] | 503 | void OnSuccessfulVersionNegotiation( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 504 | const quic::ParsedQuicVersion& version) override; |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 505 | void OnConnectivityProbeReceived( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 506 | const quic::QuicSocketAddress& self_address, |
| 507 | const quic::QuicSocketAddress& peer_address) override; |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 508 | void OnPathDegrading() override; |
Victor Vasiliev | 3ef4555 | 2019-03-04 22:06:12 | [diff] [blame] | 509 | bool ShouldKeepConnectionAlive() const override; |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 510 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 511 | // QuicChromiumPacketReader::Visitor methods: |
jri | d140c47 | 2015-12-22 23:28:11 | [diff] [blame] | 512 | void OnReadError(int result, const DatagramClientSocket* socket) override; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 513 | bool OnPacket(const quic::QuicReceivedPacket& packet, |
| 514 | const quic::QuicSocketAddress& local_address, |
| 515 | const quic::QuicSocketAddress& peer_address) override; |
rch | 31ca50f | 2015-03-20 05:51:00 | [diff] [blame] | 516 | |
rch | a378f65da | 2016-12-08 22:58:15 | [diff] [blame] | 517 | // MultiplexedSession methods: |
| 518 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override; |
| 519 | bool GetSSLInfo(SSLInfo* ssl_info) const override; |
nharper | d5cddca | 2016-02-27 03:37:52 | [diff] [blame] | 520 | |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 521 | // Performs a crypto handshake with the server. |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 522 | int CryptoConnect(CompletionOnceCallback callback); |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 523 | |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 524 | // Causes the QuicConnectionHelper to start reading from all sockets |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 525 | // and passing the data along to the quic::QuicConnection. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 526 | void StartReading(); |
| 527 | |
rch | 90f64eb | 2017-05-01 03:07:12 | [diff] [blame] | 528 | // Close the session because of |net_error| and notifies the factory |
[email protected] | 35103d3 | 2013-06-26 04:00:20 | [diff] [blame] | 529 | // that this session has been closed, which will delete the session. |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 530 | // |behavior| will suggest whether we should send connection close packets |
| 531 | // when closing the connection. |
| 532 | void CloseSessionOnError(int net_error, |
| 533 | quic::QuicErrorCode quic_error, |
| 534 | quic::ConnectionCloseBehavior behavior); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 535 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 536 | // Close the session because of |net_error| and notifies the factory |
| 537 | // that this session has been closed later, which will delete the session. |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 538 | // |behavior| will suggest whether we should send connection close packets |
| 539 | // when closing the connection. |
| 540 | void CloseSessionOnErrorLater(int net_error, |
| 541 | quic::QuicErrorCode quic_error, |
| 542 | quic::ConnectionCloseBehavior behavior); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 543 | |
Eric Roman | b043691 | 2019-04-30 23:38:42 | [diff] [blame] | 544 | base::Value GetInfoAsValue(const std::set<HostPortPair>& aliases); |
[email protected] | c5b061b | 2013-01-05 00:31:34 | [diff] [blame] | 545 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 546 | const NetLogWithSource& net_log() const { return net_log_; } |
[email protected] | 0d10b59 | 2013-02-14 16:09:26 | [diff] [blame] | 547 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 548 | // Returns a Handle to this session. |
Ryan Hamilton | 6c2a2a8 | 2017-12-15 02:06:28 | [diff] [blame] | 549 | std::unique_ptr<QuicChromiumClientSession::Handle> CreateHandle( |
| 550 | const HostPortPair& destination); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 551 | |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 552 | // Returns the number of client hello messages that have been sent on the |
| 553 | // crypto stream. If the handshake has completed then this is one greater |
| 554 | // than the number of round-trips needed for the handshake. |
| 555 | int GetNumSentClientHellos() const; |
| 556 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 557 | // Returns true if |hostname| may be pooled onto this session. If this |
| 558 | // is a secure QUIC session, then |hostname| must match the certificate |
| 559 | // presented during the handshake. |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 560 | bool CanPool(const std::string& hostname, |
| 561 | PrivacyMode privacy_mode, |
Matt Menke | 26e4154 | 2019-06-05 01:09:51 | [diff] [blame] | 562 | const SocketTag& socket_tag, |
| 563 | const NetworkIsolationKey& network_isolation_key) const; |
rch | 09a730f | 2015-01-23 00:30:41 | [diff] [blame] | 564 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 565 | const quic::QuicServerId& server_id() const { |
| 566 | return session_key_.server_id(); |
| 567 | } |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 568 | |
Renjie | c5e9a8a3 | 2019-07-04 01:17:09 | [diff] [blame] | 569 | const QuicSessionKey& quic_session_key() const { return session_key_; } |
| 570 | |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 571 | // Attempts to migrate session when |writer| encounters a write error. |
| 572 | // If |writer| is no longer actively used, abort migration. |
| 573 | void MigrateSessionOnWriteError(int error_code, |
| 574 | quic::QuicPacketWriter* writer); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 575 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 576 | // Helper method that completes connection/server migration. |
| 577 | // Unblocks packet writer on network level. If the writer becomes unblocked |
| 578 | // then, OnWriteUnblocked() will be invoked to send packet after migration. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 579 | void WriteToNewSocket(); |
| 580 | |
Zhongyi Shi | 673f22ef | 2017-10-18 00:00:47 | [diff] [blame] | 581 | // Migrates session over to use |peer_address| and |network|. |
| 582 | // If |network| is kInvalidNetworkHandle, default network is used. If the |
| 583 | // migration fails and |close_session_on_error| is true, session will be |
| 584 | // closed. |
| 585 | MigrationResult Migrate(NetworkChangeNotifier::NetworkHandle network, |
| 586 | IPEndPoint peer_address, |
Zhongyi Shi | 87ef15c | 2018-06-27 22:00:43 | [diff] [blame] | 587 | bool close_session_on_error, |
Zhongyi Shi | 673f22ef | 2017-10-18 00:00:47 | [diff] [blame] | 588 | const NetLogWithSource& migration_net_log); |
| 589 | |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 590 | // Migrates session onto new socket, i.e., sets |writer| to be the new |
| 591 | // default writer and post a task to write to |socket|. |reader| *must* |
| 592 | // has been started reading from the socket. Returns true if |
| 593 | // socket was successfully added to the session and the session was |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 594 | // successfully migrated to using the new socket. Returns true on |
| 595 | // successful migration, or false if number of migrations exceeds |
| 596 | // kMaxReadersPerQuicSession. Takes ownership of |socket|, |reader|, |
| 597 | // and |writer|. |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 598 | bool MigrateToSocket(std::unique_ptr<DatagramClientSocket> socket, |
| 599 | std::unique_ptr<QuicChromiumPacketReader> reader, |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 600 | std::unique_ptr<QuicChromiumPacketWriter> writer); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 601 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 602 | // Called when NetworkChangeNotifier notifies observers of a newly |
| 603 | // connected network. Migrates this session to the newly connected |
| 604 | // network if the session has a pending migration. |
| 605 | void OnNetworkConnected(NetworkChangeNotifier::NetworkHandle network, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 606 | const NetLogWithSource& net_log); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 607 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 608 | // Called when NetworkChangeNotifier broadcasts to observers of |
| 609 | // |disconnected_network|. |
| 610 | void OnNetworkDisconnectedV2( |
| 611 | NetworkChangeNotifier::NetworkHandle disconnected_network, |
| 612 | const NetLogWithSource& migration_net_log); |
| 613 | |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 614 | // Called when NetworkChangeNotifier broadcats to observers of a new default |
| 615 | // network. Migrates this session to |new_network| if appropriate. |
| 616 | void OnNetworkMadeDefault(NetworkChangeNotifier::NetworkHandle new_network, |
| 617 | const NetLogWithSource& migration_net_log); |
| 618 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 619 | // Schedules a migration alarm to wait for a new network. |
| 620 | void OnNoNewNetwork(); |
| 621 | |
| 622 | // Called when migration alarm fires. If migration has not occurred |
| 623 | // since alarm was set, closes session with error. |
| 624 | void OnMigrationTimeout(size_t num_sockets); |
| 625 | |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 626 | // Populates network error details for this session. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 627 | void PopulateNetErrorDetails(NetErrorDetails* details) const; |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 628 | |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 629 | // Returns current default socket. This is the socket over which all |
| 630 | // QUIC packets are sent. This default socket can change, so do not store the |
| 631 | // returned socket. |
| 632 | const DatagramClientSocket* GetDefaultSocket() const; |
| 633 | |
ckrasic | 244375a3 | 2016-02-04 21:21:22 | [diff] [blame] | 634 | bool IsAuthorized(const std::string& hostname) override; |
| 635 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 636 | bool HandlePromised(quic::QuicStreamId associated_id, |
| 637 | quic::QuicStreamId promised_id, |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 638 | const spdy::SpdyHeaderBlock& headers) override; |
ckrasic | 9275772 | 2016-03-22 00:45:36 | [diff] [blame] | 639 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 640 | void DeletePromised(quic::QuicClientPromisedInfo* promised) override; |
ckrasic | 4be6c6b | 2016-03-24 20:53:22 | [diff] [blame] | 641 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 642 | void OnPushStreamTimedOut(quic::QuicStreamId stream_id) override; |
zhongyi | 92bd5b4 | 2016-10-14 21:18:41 | [diff] [blame] | 643 | |
zhongyi | 18bb2d9 | 2016-10-27 19:38:50 | [diff] [blame] | 644 | // Cancels the push if the push stream for |url| has not been claimed and is |
| 645 | // still active. Otherwise, no-op. |
| 646 | void CancelPush(const GURL& url); |
| 647 | |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 648 | const LoadTimingInfo::ConnectTiming& GetConnectTiming(); |
| 649 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 650 | quic::QuicTransportVersion GetQuicVersion() const; |
bnc | 90be5dd78 | 2016-11-09 16:28:44 | [diff] [blame] | 651 | |
xunjieli | 69720dd | 2017-01-30 15:36:29 | [diff] [blame] | 652 | // Returns the estimate of dynamically allocated memory in bytes. |
| 653 | // See base/trace_event/memory_usage_estimator.h. |
| 654 | // TODO(xunjieli): It only tracks |packet_readers_|. Write a better estimate. |
| 655 | size_t EstimateMemoryUsage() const; |
| 656 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 657 | bool require_confirmation() const { return require_confirmation_; } |
| 658 | |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 659 | protected: |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 660 | // quic::QuicSession methods: |
Fan Yang | 5a3bddf | 2018-10-12 10:05:50 | [diff] [blame] | 661 | bool ShouldCreateIncomingStream(quic::QuicStreamId id) override; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 662 | bool ShouldCreateOutgoingBidirectionalStream() override; |
| 663 | bool ShouldCreateOutgoingUnidirectionalStream() override; |
jokulik | f2bd55c5 | 2016-03-24 22:35:30 | [diff] [blame] | 664 | |
Fan Yang | 5a3bddf | 2018-10-12 10:05:50 | [diff] [blame] | 665 | QuicChromiumClientStream* CreateIncomingStream( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 666 | quic::QuicStreamId id) override; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 667 | QuicChromiumClientStream* CreateIncomingStream( |
Ryan Hamilton | 8380c65 | 2019-06-04 02:25:06 | [diff] [blame] | 668 | quic::PendingStream* pending) override; |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 669 | |
| 670 | private: |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 671 | friend class test::QuicChromiumClientSessionPeer; |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 672 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 673 | typedef std::set<Handle*> HandleSet; |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 674 | typedef std::list<StreamRequest*> StreamRequestQueue; |
| 675 | |
Yixin Wang | 0d2c6b7e1 | 2017-08-16 21:12:55 | [diff] [blame] | 676 | bool WasConnectionEverUsed(); |
| 677 | |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 678 | QuicChromiumClientStream* CreateOutgoingReliableStreamImpl( |
| 679 | const NetworkTrafficAnnotationTag& traffic_annotation); |
| 680 | QuicChromiumClientStream* CreateIncomingReliableStreamImpl( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 681 | quic::QuicStreamId id, |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 682 | const NetworkTrafficAnnotationTag& traffic_annotation); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 683 | QuicChromiumClientStream* CreateIncomingReliableStreamImpl( |
Ryan Hamilton | 8380c65 | 2019-06-04 02:25:06 | [diff] [blame] | 684 | quic::PendingStream* pending, |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 685 | const NetworkTrafficAnnotationTag& traffic_annotation); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 686 | // A completion callback invoked when a read completes. |
| 687 | void OnReadComplete(int result); |
| 688 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 689 | void CloseAllStreams(int net_error); |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 690 | void CloseAllHandles(int net_error); |
rch | 94c26d68 | 2017-04-29 02:49:27 | [diff] [blame] | 691 | void CancelAllRequests(int net_error); |
rch | d606b6c3 | 2017-05-02 17:32:57 | [diff] [blame] | 692 | void NotifyRequestsOfConfirmation(int net_error); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 693 | |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 694 | ProbingResult StartProbeNetwork(NetworkChangeNotifier::NetworkHandle network, |
Zhongyi Shi | 7b280d0 | 2018-12-13 02:54:41 | [diff] [blame] | 695 | const quic::QuicSocketAddress& peer_address, |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 696 | const NetLogWithSource& migration_net_log); |
| 697 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 698 | // Called when there is only one possible working network: |network|, If any |
Zhongyi Shi | 7b280d0 | 2018-12-13 02:54:41 | [diff] [blame] | 699 | // error encountered, this session will be closed. |
| 700 | // When the migration succeeds: |
| 701 | // - If no longer on the default network, set timer to migrate back to the |
| 702 | // default network; |
| 703 | // - If now on the default network, cancel timer to migrate back to default |
| 704 | // network. |
| 705 | void MigrateNetworkImmediately(NetworkChangeNotifier::NetworkHandle network); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 706 | |
Zhongyi Shi | f4747b3 | 2018-12-14 01:19:06 | [diff] [blame] | 707 | // Called when probe |network| succeeded. |
| 708 | void OnProbeNetworkSucceeded( |
| 709 | NetworkChangeNotifier::NetworkHandle network, |
| 710 | const quic::QuicSocketAddress& peer_address, |
| 711 | const quic::QuicSocketAddress& self_address, |
| 712 | std::unique_ptr<DatagramClientSocket> socket, |
| 713 | std::unique_ptr<QuicChromiumPacketWriter> writer, |
| 714 | std::unique_ptr<QuicChromiumPacketReader> reader); |
| 715 | // Called when probe |network| failed. |
| 716 | void OnProbeNetworkFailed(NetworkChangeNotifier::NetworkHandle network, |
| 717 | const quic::QuicSocketAddress& peer_address); |
| 718 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 719 | void StartMigrateBackToDefaultNetworkTimer(base::TimeDelta delay); |
| 720 | void CancelMigrateBackToDefaultNetworkTimer(); |
| 721 | void TryMigrateBackToDefaultNetwork(base::TimeDelta timeout); |
| 722 | void MaybeRetryMigrateBackToDefaultNetwork(); |
| 723 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame] | 724 | // If migrate idle session is enabled, returns true and post a task to close |
| 725 | // the connection if session's idle time exceeds the |idle_migration_period_|. |
| 726 | // If migrate idle session is not enabled, returns true and posts a task to |
| 727 | // close the connection if session doesn't have outstanding streams. |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 728 | bool CheckIdleTimeExceedsIdleMigrationPeriod(); |
| 729 | |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 730 | // Close non-migratable streams in both directions by sending reset stream to |
| 731 | // peer when connection migration attempts to migrate to the alternate |
| 732 | // network. |
| 733 | void ResetNonMigratableStreams(); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 734 | void LogMetricsOnNetworkDisconnected(); |
| 735 | void LogMetricsOnNetworkMadeDefault(); |
Cherie Shi | 95f08690 | 2018-03-02 20:09:45 | [diff] [blame] | 736 | void LogConnectionMigrationResultToHistogram( |
| 737 | QuicConnectionMigrationStatus status); |
Zhongyi Shi | 996e31d | 2018-05-08 07:06:45 | [diff] [blame] | 738 | void LogHandshakeStatusOnConnectionMigrationSignal() const; |
Cherie Shi | 95f08690 | 2018-03-02 20:09:45 | [diff] [blame] | 739 | void HistogramAndLogMigrationFailure(const NetLogWithSource& net_log, |
| 740 | QuicConnectionMigrationStatus status, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 741 | quic::QuicConnectionId connection_id, |
Cherie Shi | 95f08690 | 2018-03-02 20:09:45 | [diff] [blame] | 742 | const std::string& reason); |
| 743 | void HistogramAndLogMigrationSuccess(const NetLogWithSource& net_log, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 744 | quic::QuicConnectionId connection_id); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 745 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 746 | // Notifies the factory that this session is going away and no more streams |
| 747 | // should be created from it. This needs to be called before closing any |
| 748 | // streams, because closing a stream may cause a new stream to be created. |
| 749 | void NotifyFactoryOfSessionGoingAway(); |
| 750 | |
[email protected] | 35103d3 | 2013-06-26 04:00:20 | [diff] [blame] | 751 | // Posts a task to notify the factory that this session has been closed. |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 752 | void NotifyFactoryOfSessionClosedLater(); |
[email protected] | 35103d3 | 2013-06-26 04:00:20 | [diff] [blame] | 753 | |
| 754 | // Notifies the factory that this session has been closed which will |
| 755 | // delete |this|. |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 756 | void NotifyFactoryOfSessionClosed(); |
[email protected] | 35103d3 | 2013-06-26 04:00:20 | [diff] [blame] | 757 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 758 | QuicSessionKey session_key_; |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 759 | bool require_confirmation_; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 760 | bool migrate_session_early_v2_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 761 | bool migrate_session_on_network_change_v2_; |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame] | 762 | bool migrate_idle_session_; |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 763 | // Session can be migrated if its idle time is within this period. |
| 764 | base::TimeDelta idle_migration_period_; |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 765 | base::TimeDelta max_time_on_non_default_network_; |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 766 | // Maximum allowed number of migrations to non-default network triggered by |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 767 | // packet write error per default network. |
| 768 | int max_migrations_to_non_default_network_on_write_error_; |
| 769 | int current_migrations_to_non_default_network_on_write_error_; |
| 770 | // Maximum allowed number of migrations to non-default network triggered by |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 771 | // path degrading per default network. |
| 772 | int max_migrations_to_non_default_network_on_path_degrading_; |
| 773 | int current_migrations_to_non_default_network_on_path_degrading_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 774 | quic::QuicClock* clock_; // Unowned. |
Zhongyi Shi | 673f22ef | 2017-10-18 00:00:47 | [diff] [blame] | 775 | int yield_after_packets_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 776 | quic::QuicTime::Delta yield_after_duration_; |
Zhongyi Shi | dbce7f41 | 2019-02-01 23:16:29 | [diff] [blame] | 777 | bool go_away_on_path_degrading_; |
Zhongyi Shi | 673f22ef | 2017-10-18 00:00:47 | [diff] [blame] | 778 | |
Zhongyi Shi | 066985fd | 2017-11-02 09:11:34 | [diff] [blame] | 779 | base::TimeTicks most_recent_path_degrading_timestamp_; |
| 780 | base::TimeTicks most_recent_network_disconnected_timestamp_; |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 781 | const base::TickClock* tick_clock_; |
| 782 | base::TimeTicks most_recent_stream_close_time_; |
Zhongyi Shi | 066985fd | 2017-11-02 09:11:34 | [diff] [blame] | 783 | |
| 784 | int most_recent_write_error_; |
| 785 | base::TimeTicks most_recent_write_error_timestamp_; |
| 786 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 787 | std::unique_ptr<quic::QuicCryptoClientStream> crypto_stream_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 788 | QuicStreamFactory* stream_factory_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 789 | std::vector<std::unique_ptr<DatagramClientSocket>> sockets_; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 790 | TransportSecurityState* transport_security_state_; |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 791 | SSLConfigService* ssl_config_service_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 792 | std::unique_ptr<QuicServerInfo> server_info_; |
| 793 | std::unique_ptr<CertVerifyResult> cert_verify_result_; |
| 794 | std::unique_ptr<ct::CTVerifyResult> ct_verify_result_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 795 | std::string pinning_failure_log_; |
dadrian | df302c4 | 2016-06-10 18:48:59 | [diff] [blame] | 796 | bool pkp_bypassed_; |
Carlos IL | 8113338 | 2017-12-06 17:18:45 | [diff] [blame] | 797 | bool is_fatal_cert_error_; |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 798 | HandleSet handles_; |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 799 | StreamRequestQueue stream_requests_; |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 800 | std::vector<CompletionOnceCallback> waiting_for_confirmation_callbacks_; |
| 801 | CompletionOnceCallback callback_; |
[email protected] | 0d10b59 | 2013-02-14 16:09:26 | [diff] [blame] | 802 | size_t num_total_streams_; |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 803 | base::SequencedTaskRunner* task_runner_; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 804 | NetLogWithSource net_log_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 805 | std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_; |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 806 | LoadTimingInfo::ConnectTiming connect_timing_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 807 | std::unique_ptr<QuicConnectionLogger> logger_; |
[email protected] | 775381a | 2014-03-27 15:37:39 | [diff] [blame] | 808 | // True when the session is going away, and streams may no longer be created |
| 809 | // on this session. Existing stream will continue to be processed. |
| 810 | bool going_away_; |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 811 | // True when the session receives a go away from server due to port migration. |
| 812 | bool port_migration_detected_; |
zhongyi | 7465c1b | 2016-11-11 01:38:05 | [diff] [blame] | 813 | // Not owned. |push_delegate_| outlives the session and handles server pushes |
| 814 | // received by session. |
| 815 | ServerPushDelegate* push_delegate_; |
ckrasic | 4be6c6b | 2016-03-24 20:53:22 | [diff] [blame] | 816 | // UMA histogram counters for streams pushed to this session. |
| 817 | int streams_pushed_count_; |
| 818 | int streams_pushed_and_claimed_count_; |
zhongyi | 92bd5b4 | 2016-10-14 21:18:41 | [diff] [blame] | 819 | uint64_t bytes_pushed_count_; |
| 820 | uint64_t bytes_pushed_and_unclaimed_count_; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 821 | // Stores the packet that witnesses socket write error. This packet will be |
| 822 | // written to an alternate socket when the migration completes and the |
| 823 | // alternate socket is unblocked. |
Charles 'Buck' Krasic | 3a35aa5 | 2017-08-10 22:20:06 | [diff] [blame] | 824 | scoped_refptr<QuicChromiumPacketWriter::ReusableIOBuffer> packet_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 825 | // Stores the latest default network platform marks. |
| 826 | NetworkChangeNotifier::NetworkHandle default_network_; |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 827 | QuicConnectivityProbingManager probing_manager_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 828 | int retry_migrate_back_count_; |
| 829 | base::OneShotTimer migrate_back_to_default_timer_; |
Cherie Shi | 95f08690 | 2018-03-02 20:09:45 | [diff] [blame] | 830 | ConnectionMigrationCause current_connection_migration_cause_; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 831 | // True if a packet needs to be sent when packet writer is unblocked to |
| 832 | // complete connection migration. The packet can be a cached packet if |
| 833 | // |packet_| is set, a queued packet, or a PING packet. |
| 834 | bool send_packet_after_migration_; |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 835 | // True if migration is triggered, and there is no alternate network to |
| 836 | // migrate to. |
| 837 | bool wait_for_new_network_; |
| 838 | // True if read errors should be ignored. Set when migration on write error is |
| 839 | // posted and unset until the first packet is written after migration. |
| 840 | bool ignore_read_error_; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 841 | |
| 842 | // If true, client headers will include HTTP/2 stream dependency info derived |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 843 | // from spdy::SpdyPriority. |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 844 | bool headers_include_h2_stream_dependency_; |
| 845 | Http2PriorityDependencies priority_dependency_state_; |
| 846 | |
Jeremy Roman | d54000b2 | 2019-07-08 18:40:16 | [diff] [blame] | 847 | base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_{this}; |
[email protected] | 8ee611b | 2012-11-20 01:48:12 | [diff] [blame] | 848 | |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 849 | DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession); |
[email protected] | dd3fd0e | 2012-11-04 05:14:40 | [diff] [blame] | 850 | }; |
| 851 | |
| 852 | } // namespace net |
| 853 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 854 | #endif // NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_ |