blob: 941215a388f4a9b0477640ca235790f595f188cc [file] [log] [blame]
[email protected]dd3fd0e2012-11-04 05:14:401// 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 Hamilton8d9ee76e2018-05-29 23:52:525// A client specific quic::QuicSession subclass. This class owns the underlying
6// quic::QuicConnection and QuicConnectionHelper objects. The connection stores
[email protected]e13201d82012-12-12 05:00:327// a non-owning pointer to the helper so this session needs to ensure that
8// the helper outlives the connection.
[email protected]dd3fd0e2012-11-04 05:14:409
Ryan Hamiltona3ee93a72018-08-01 22:03:0810#ifndef NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_
11#define NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_
[email protected]dd3fd0e2012-11-04 05:14:4012
Avi Drissman13fc8932015-12-20 04:40:4613#include <stddef.h>
14
bnc5fdc07162016-05-23 17:36:0315#include <list>
danakjad1777e2016-04-16 00:56:4216#include <memory>
bnc5fdc07162016-05-23 17:36:0317#include <set>
[email protected]41d6b172013-01-29 16:10:5718#include <string>
bnc5fdc07162016-05-23 17:36:0319#include <vector>
[email protected]41d6b172013-01-29 16:10:5720
nharperd5cddca2016-02-27 03:37:5221#include "base/containers/mru_cache.h"
Avi Drissman13fc8932015-12-20 04:40:4622#include "base/macros.h"
[email protected]c4338da2014-06-07 08:47:0723#include "base/time/time.h"
Sebastien Marchandefda77e532019-01-25 22:53:5224#include "base/timer/timer.h"
Bence Békyd8a21fc32018-06-27 18:29:5825#include "net/base/completion_once_callback.h"
xunjieli100937eb52016-09-15 20:09:3726#include "net/base/load_timing_info.h"
zhongyi6b5a3892016-03-12 04:46:2027#include "net/base/net_error_details.h"
bnc81c46c1f2016-10-04 16:25:5928#include "net/base/net_export.h"
Lily Houghton582d4622018-01-22 22:43:4029#include "net/base/proxy_server.h"
rtenneti052774e2015-11-24 21:00:1230#include "net/cert/ct_verify_result.h"
mikecironef22f9812016-10-04 03:40:1931#include "net/log/net_log_with_source.h"
Ryan Hamiltona3ee93a72018-08-01 22:03:0832#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"
tbansalca83c002016-04-28 20:56:2838#include "net/socket/socket_performance_watcher.h"
Bence Béky94658bf2018-05-11 19:22:5839#include "net/spdy/http2_priority_dependencies.h"
40#include "net/spdy/multiplexed_session.h"
41#include "net/spdy/server_push_delegate.h"
Victor Vasiliev6bb59d22019-03-08 21:34:5142#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 Halavati683bcaa92018-02-14 08:42:3948#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]dd3fd0e2012-11-04 05:14:4049
50namespace net {
51
[email protected]b694e48c2014-03-18 17:10:1352class CertVerifyResult;
[email protected]6dcd1d5c2013-03-15 07:28:3753class DatagramClientSocket;
mikecironef22f9812016-10-04 03:40:1954class NetLog;
Matt Menke26e41542019-06-05 01:09:5155class NetworkIsolationKey;
[email protected]e8ff26842013-03-22 21:02:0556class QuicCryptoClientStreamFactory;
[email protected]b694e48c2014-03-18 17:10:1357class QuicServerInfo;
[email protected]e13201d82012-12-12 05:00:3258class QuicStreamFactory;
Nick Harper89bc7212018-07-31 19:07:5759class SSLConfigService;
[email protected]a69af0522013-07-12 19:23:4760class SSLInfo;
[email protected]5db452202014-08-19 05:22:1561class TransportSecurityState;
[email protected]e13201d82012-12-12 05:00:3262
[email protected]899951652013-05-16 12:52:3963namespace test {
ckrasic4f9d88d2015-07-22 22:23:1664class QuicChromiumClientSessionPeer;
[email protected]899951652013-05-16 12:52:3965} // namespace test
66
Bence Béky3a76c142019-07-16 23:53:1667// SETTINGS_MAX_HEADERS_LIST_SIZE, the maximum size of uncompressed QUIC headers
68// that the server is allowed to send.
69const size_t kQuicMaxHeaderListSize = 256 * 1024;
70
Zhongyi Shi673f22ef2017-10-18 00:00:4771// Result of a session migration attempt.
72enum 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 Shief52e20ab2017-12-02 10:41:4378// Mode of connection migration.
79enum 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 Shi95f086902018-03-02 20:09:4587// Cause of connection migration.
88enum ConnectionMigrationCause {
Daniel Bratellde285c3d2018-11-08 17:22:5489 UNKNOWN_CAUSE,
Cherie Shi95f086902018-03-02 20:09:4590 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 Yang8bfc0e22018-03-27 05:53:4096 MIGRATION_CAUSE_MAX
Cherie Shi95f086902018-03-02 20:09:4597};
98
99// Result of connection migration.
100enum 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 Shi7f738652018-03-02 21:53:48111 MIGRATION_STATUS_PATH_DEGRADING_NOT_ENABLED,
112 MIGRATION_STATUS_TIMEOUT,
Zhongyi Shiee760762018-08-01 00:54:29113 MIGRATION_STATUS_ON_WRITE_ERROR_DISABLED,
Zhongyi Shic1449372018-08-09 09:58:58114 MIGRATION_STATUS_PATH_DEGRADING_BEFORE_HANDSHAKE_CONFIRMED,
Zhongyi Shic16b4102019-02-12 00:37:40115 MIGRATION_STATUS_IDLE_MIGRATION_TIMEOUT,
Cherie Shi95f086902018-03-02 20:09:45116 MIGRATION_STATUS_MAX
117};
118
Zhongyi Shi8fff75b2017-11-19 21:36:36119// Result of a connectivity probing attempt.
120enum 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
ckrasic4f9d88d2015-07-22 22:23:16129class NET_EXPORT_PRIVATE QuicChromiumClientSession
Ryan Hamilton8d9ee76e2018-05-29 23:52:52130 : public quic::QuicSpdyClientSessionBase,
rcha378f65da2016-12-08 22:58:15131 public MultiplexedSession,
Zhongyi Shi8fff75b2017-11-19 21:36:36132 public QuicConnectivityProbingManager::Delegate,
jried79618b2016-07-02 03:18:52133 public QuicChromiumPacketReader::Visitor,
jribce3eec2016-09-09 05:41:08134 public QuicChromiumPacketWriter::Delegate {
[email protected]dd3fd0e2012-11-04 05:14:40135 public:
rchf0b18c8a2017-05-05 19:31:57136 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.
rch56ec40a2017-06-23 14:48:44141 class NET_EXPORT_PRIVATE Handle
142 : public MultiplexedSessionHandle,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52143 public quic::QuicClientPushPromiseIndex::Delegate {
[email protected]4d283b32013-10-17 12:57:27144 public:
Ryan Hamilton6c2a2a82017-12-15 02:06:28145 // 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);
rchf0b18c8a2017-05-05 19:31:57149 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
rch56ec40a2017-06-23 14:48:44158 // 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 Hamilton0239aac2018-05-19 00:03:13162 int RendezvousWithPromised(const spdy::SpdyHeaderBlock& headers,
Bence Békyd8a21fc32018-06-27 18:29:58163 CompletionOnceCallback callback);
rch56ec40a2017-06-23 14:48:44164
rchf0b18c8a2017-05-05 19:31:57165 // 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ékyd8a21fc32018-06-27 18:29:58170 CompletionOnceCallback callback,
Ramin Halavati683bcaa92018-02-14 08:42:39171 const NetworkTrafficAnnotationTag& traffic_annotation);
rchf0b18c8a2017-05-05 19:31:57172
Helen Liaeed1e82017-08-14 23:52:30173 // Releases |stream_| to the caller. Returns nullptr if the underlying
174 // QuicChromiumClientSession is closed.
rch1bcfddf22017-06-03 00:26:29175 std::unique_ptr<QuicChromiumClientStream::Handle> ReleaseStream();
rchf0b18c8a2017-05-05 19:31:57176
rch56ec40a2017-06-23 14:48:44177 // Releases |push_stream_| to the caller.
178 std::unique_ptr<QuicChromiumClientStream::Handle> ReleasePromisedStream();
179
rchf0b18c8a2017-05-05 19:31:57180 // 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 Hamilton8d9ee76e2018-05-29 23:52:52184 void ResetPromised(quic::QuicStreamId id,
185 quic::QuicRstStreamErrorCode error_code);
rchf0b18c8a2017-05-05 19:31:57186
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 Hamilton8d9ee76e2018-05-29 23:52:52189 std::unique_ptr<quic::QuicConnection::ScopedPacketFlusher>
Bin Wuae74d8b2019-06-19 23:55:07190 CreatePacketBundler();
rchf0b18c8a2017-05-05 19:31:57191
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
rchf0b18c8a2017-05-05 19:31:57198 // 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 Hamilton8d9ee76e2018-05-29 23:52:52202 quic::QuicTransportVersion GetQuicVersion() const;
rchf0b18c8a2017-05-05 19:31:57203
204 // Copies the remote udp address into |address| and returns a net error
205 // code.
206 int GetPeerAddress(IPEndPoint* address) const;
207
Yixin Wang0d2c6b7e12017-08-16 21:12:55208 // Copies the local udp address into |address| and returns a net error
209 // code.
210 int GetSelfAddress(IPEndPoint* address) const;
211
rchf0b18c8a2017-05-05 19:31:57212 // Returns the push promise index associated with the session.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52213 quic::QuicClientPushPromiseIndex* GetPushPromiseIndex();
rchf0b18c8a2017-05-05 19:31:57214
215 // Returns the session's server ID.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52216 quic::QuicServerId server_id() const { return server_id_; }
rchf0b18c8a2017-05-05 19:31:57217
Ryan Hamilton6c2a2a82017-12-15 02:06:28218 // Returns the alternative server used for this session.
219 HostPortPair destination() const { return destination_; }
220
rchf0b18c8a2017-05-05 19:31:57221 // Returns the session's net log.
222 const NetLogWithSource& net_log() const { return net_log_; }
223
Zhongyi Shief52e20ab2017-12-02 10:41:43224 // Returns the session's connection migration mode.
225 ConnectionMigrationMode connection_migration_mode() const {
226 return session_->connection_migration_mode();
227 }
228
Ryan Hamilton8d9ee76e2018-05-29 23:52:52229 // quic::QuicClientPushPromiseIndex::Delegate implementation
Ryan Hamilton0239aac2018-05-19 00:03:13230 bool CheckVary(const spdy::SpdyHeaderBlock& client_request,
231 const spdy::SpdyHeaderBlock& promise_request,
232 const spdy::SpdyHeaderBlock& promise_response) override;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52233 void OnRendezvousResult(quic::QuicSpdyStream* stream) override;
rch56ec40a2017-06-23 14:48:44234
Yixin Wang0d2c6b7e12017-08-16 21:12:55235 // Returns true if the session's connection has sent or received any bytes.
236 bool WasEverUsed() const;
237
rchf0b18c8a2017-05-05 19:31:57238 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ékyd8a21fc32018-06-27 18:29:58247 int WaitForHandshakeConfirmation(CompletionOnceCallback callback);
rchf0b18c8a2017-05-05 19:31:57248
249 // Called when the handshake is confirmed.
250 void OnCryptoHandshakeConfirmed();
251
252 // Called when the session is closed with a net error.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52253 void OnSessionClosed(quic::QuicTransportVersion quic_version,
Ryan Hamiltone316e482017-08-17 02:48:53254 int net_error,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52255 quic::QuicErrorCode quic_error,
rchf0b18c8a2017-05-05 19:31:57256 bool port_migration_detected,
Yixin Wang0d2c6b7e12017-08-16 21:12:55257 LoadTimingInfo::ConnectTiming connect_timing,
258 bool was_ever_used);
rchf0b18c8a2017-05-05 19:31:57259
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 Hamilton6c2a2a82017-12-15 02:06:28269 HostPortPair destination_;
270
rchf0b18c8a2017-05-05 19:31:57271 // 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 Hamiltone316e482017-08-17 02:48:53278 int net_error_;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52279 quic::QuicErrorCode quic_error_;
rchf0b18c8a2017-05-05 19:31:57280 bool port_migration_detected_;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52281 quic::QuicServerId server_id_;
282 quic::QuicTransportVersion quic_version_;
rchf0b18c8a2017-05-05 19:31:57283 LoadTimingInfo::ConnectTiming connect_timing_;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52284 quic::QuicClientPushPromiseIndex* push_promise_index_;
rch56ec40a2017-06-23 14:48:44285
Ryan Hamilton8d9ee76e2018-05-29 23:52:52286 // |quic::QuicClientPromisedInfo| owns this. It will be set when |Try()|
287 // is asynchronous, i.e. it returned quic::QUIC_PENDING, and remains valid
rch56ec40a2017-06-23 14:48:44288 // until |OnRendezvouResult()| fires or |push_handle_->Cancel()| is
289 // invoked.
Ryan Hamilton8d9ee76e2018-05-29 23:52:52290 quic::QuicClientPushPromiseIndex::TryHandle* push_handle_;
Bence Békyd8a21fc32018-06-27 18:29:58291 CompletionOnceCallback push_callback_;
rch56ec40a2017-06-23 14:48:44292 std::unique_ptr<QuicChromiumClientStream::Handle> push_stream_;
Yixin Wang0d2c6b7e12017-08-16 21:12:55293
294 bool was_ever_used_;
[email protected]4d283b32013-10-17 12:57:27295 };
296
[email protected]0b2294d32013-08-02 00:46:36297 // A helper class used to manage a request to create a stream.
298 class NET_EXPORT_PRIVATE StreamRequest {
299 public:
rch1baa7472017-04-26 05:43:58300 // Cancels any pending stream creation request and resets |stream_| if
301 // it has not yet been released.
[email protected]0b2294d32013-08-02 00:46:36302 ~StreamRequest();
303
304 // Starts a request to create a stream. If OK is returned, then
rch1baa7472017-04-26 05:43:58305 // |stream_| will be updated with the newly created stream. If
[email protected]0b2294d32013-08-02 00:46:36306 // ERR_IO_PENDING is returned, then when the request is eventuallly
307 // complete |callback| will be called.
Bence Békyd8a21fc32018-06-27 18:29:58308 int StartRequest(CompletionOnceCallback callback);
[email protected]0b2294d32013-08-02 00:46:36309
rch1bcfddf22017-06-03 00:26:29310 // Releases |stream_| to the caller.
311 std::unique_ptr<QuicChromiumClientStream::Handle> ReleaseStream();
[email protected]0b2294d32013-08-02 00:46:36312
Ramin Halavati683bcaa92018-02-14 08:42:39313 const NetworkTrafficAnnotationTag traffic_annotation() {
314 return traffic_annotation_;
315 }
316
[email protected]0b2294d32013-08-02 00:46:36317 private:
ckrasic4f9d88d2015-07-22 22:23:16318 friend class QuicChromiumClientSession;
[email protected]0b2294d32013-08-02 00:46:36319
rchd606b6c32017-05-02 17:32:57320 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
rch9ddcded2017-05-06 18:55:57328 // |session| must outlive this request.
329 StreamRequest(QuicChromiumClientSession::Handle* session,
Ramin Halavati683bcaa92018-02-14 08:42:39330 bool requires_confirmation,
331 const NetworkTrafficAnnotationTag& traffic_annotation);
rchd606b6c32017-05-02 17:32:57332
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);
rch1baa7472017-04-26 05:43:58341
[email protected]0b2294d32013-08-02 00:46:36342 // Called by |session_| for an asynchronous request when the stream
343 // request has finished successfully.
Ryan Hamiltonc682cae2017-08-21 18:07:17344 void OnRequestCompleteSuccess(
345 std::unique_ptr<QuicChromiumClientStream::Handle> stream);
[email protected]0b2294d32013-08-02 00:46:36346
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
rch9ddcded2017-05-06 18:55:57352 QuicChromiumClientSession::Handle* session_;
rchd606b6c32017-05-02 17:32:57353 const bool requires_confirmation_;
Bence Békyd8a21fc32018-06-27 18:29:58354 CompletionOnceCallback callback_;
Ryan Hamiltonc682cae2017-08-21 18:07:17355 std::unique_ptr<QuicChromiumClientStream::Handle> stream_;
ckrasicc9c7b832016-11-30 22:33:21356 // For tracking how much time pending stream requests wait.
357 base::TimeTicks pending_start_time_;
rchd606b6c32017-05-02 17:32:57358 State next_state_;
359
Ramin Halavati683bcaa92018-02-14 08:42:39360 const NetworkTrafficAnnotationTag traffic_annotation_;
361
Jeremy Romand54000b22019-07-08 18:40:16362 base::WeakPtrFactory<StreamRequest> weak_factory_{this};
[email protected]0b2294d32013-08-02 00:46:36363
364 DISALLOW_COPY_AND_ASSIGN(StreamRequest);
365 };
366
rtennetib998b322014-08-26 00:36:33367 // Constructs a new session which will own |connection|, but not
368 // |stream_factory|, which must outlive this session.
[email protected]e13201d82012-12-12 05:00:32369 // TODO(rch): decouple the factory from the session via a Delegate interface.
ckrasic4f9d88d2015-07-22 22:23:16370 QuicChromiumClientSession(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52371 quic::QuicConnection* connection,
danakjad1777e2016-04-16 00:56:42372 std::unique_ptr<DatagramClientSocket> socket,
ckrasic4f9d88d2015-07-22 22:23:16373 QuicStreamFactory* stream_factory,
374 QuicCryptoClientStreamFactory* crypto_client_stream_factory,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52375 quic::QuicClock* clock,
ckrasic4f9d88d2015-07-22 22:23:16376 TransportSecurityState* transport_security_state,
Nick Harper89bc7212018-07-31 19:07:57377 SSLConfigService* ssl_config_service,
danakjad1777e2016-04-16 00:56:42378 std::unique_ptr<QuicServerInfo> server_info,
Paul Jensen8e3c5d32018-02-19 17:06:33379 const QuicSessionKey& session_key,
rch433bf5f2017-02-14 04:10:47380 bool require_confirmation,
Zhongyi Shif4683a32017-12-01 00:03:28381 bool migrate_sesion_early_v2,
Zhongyi Shi5f587cc2017-11-21 23:24:17382 bool migrate_session_on_network_change_v2,
Zhongyi Shid672f7542018-06-08 01:03:26383 NetworkChangeNotifier::NetworkHandle default_network,
Zhongyi Shie01f2db2019-02-22 19:53:23384 quic::QuicTime::Delta retransmittable_on_wire_timeout,
Zhongyi Shi32fe14d42019-02-28 00:25:36385 bool migrate_idle_session,
Zhongyi Shic16b4102019-02-12 00:37:40386 base::TimeDelta idle_migration_period,
Zhongyi Shi73f23ca872017-12-13 18:37:13387 base::TimeDelta max_time_on_non_default_network,
Zhongyi Shiee760762018-08-01 00:54:29388 int max_migrations_to_non_default_network_on_write_error,
Zhongyi Shi8b1e43f2017-12-13 20:46:30389 int max_migrations_to_non_default_network_on_path_degrading,
rtenneti1cd3b162015-09-29 02:58:28390 int yield_after_packets,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52391 quic::QuicTime::Delta yield_after_duration,
Zhongyi Shidbce7f412019-02-01 23:16:29392 bool go_away_on_path_degrading,
Yixin Wang079ad542018-01-11 04:06:05393 bool headers_include_h2_stream_dependency,
ckrasic4f9d88d2015-07-22 22:23:16394 int cert_verify_flags,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52395 const quic::QuicConfig& config,
396 quic::QuicCryptoClientConfig* crypto_config,
ckrasic4f9d88d2015-07-22 22:23:16397 const char* const connection_description,
xunjieli100937eb52016-09-15 20:09:37398 base::TimeTicks dns_resolution_start_time,
ckrasic4f9d88d2015-07-22 22:23:16399 base::TimeTicks dns_resolution_end_time,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52400 quic::QuicClientPushPromiseIndex* push_promise_index,
zhongyiaf257542016-12-19 03:36:01401 ServerPushDelegate* push_delegate,
Zhongyi Shic16b4102019-02-12 00:37:40402 const base::TickClock* tick_clock,
Zhongyi Shi8fff75b2017-11-19 21:36:36403 base::SequencedTaskRunner* task_runner,
danakjad1777e2016-04-16 00:56:42404 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
ckrasic4f9d88d2015-07-22 22:23:16405 NetLog* net_log);
406 ~QuicChromiumClientSession() override;
[email protected]dd3fd0e2012-11-04 05:14:40407
ckrasic52b1db11b2016-05-24 19:29:16408 void Initialize() override;
409
rchf0b18c8a2017-05-05 19:31:57410 void AddHandle(Handle* handle);
411 void RemoveHandle(Handle* handle);
[email protected]4d283b32013-10-17 12:57:27412
Zhongyi Shief52e20ab2017-12-02 10:41:43413 // Returns the session's connection migration mode.
414 ConnectionMigrationMode connection_migration_mode() const;
415
rchd606b6c32017-05-02 17:32:57416 // 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ékyd8a21fc32018-06-27 18:29:58421 int WaitForHandshakeConfirmation(CompletionOnceCallback callback);
rchd606b6c32017-05-02 17:32:57422
[email protected]0b2294d32013-08-02 00:46:36423 // 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.
rch1baa7472017-04-26 05:43:58430 int TryCreateStream(StreamRequest* request);
[email protected]0b2294d32013-08-02 00:46:36431
432 // Cancels the pending stream creation request.
433 void CancelRequest(StreamRequest* request);
434
jribce3eec2016-09-09 05:41:08435 // QuicChromiumPacketWriter::Delegate override.
436 int HandleWriteError(int error_code,
Charles 'Buck' Krasic3a35aa52017-08-10 22:20:06437 scoped_refptr<QuicChromiumPacketWriter::ReusableIOBuffer>
438 last_packet) override;
jribce3eec2016-09-09 05:41:08439 void OnWriteError(int error_code) override;
Zhongyi Shib3bc982c2018-07-10 19:59:24440 // 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.
jribce3eec2016-09-09 05:41:08444 void OnWriteUnblocked() override;
jried79618b2016-07-02 03:18:52445
Zhongyi Shi8fff75b2017-11-19 21:36:36446 // QuicConnectivityProbingManager::Delegate override.
Zhongyi Shifdacb822018-12-11 22:49:15447 void OnProbeSucceeded(
Zhongyi Shi8fff75b2017-11-19 21:36:36448 NetworkChangeNotifier::NetworkHandle network,
Zhongyi Shifdacb822018-12-11 22:49:15449 const quic::QuicSocketAddress& peer_address,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52450 const quic::QuicSocketAddress& self_address,
Zhongyi Shi8fff75b2017-11-19 21:36:36451 std::unique_ptr<DatagramClientSocket> socket,
452 std::unique_ptr<QuicChromiumPacketWriter> writer,
453 std::unique_ptr<QuicChromiumPacketReader> reader) override;
454
Zhongyi Shifdacb822018-12-11 22:49:15455 void OnProbeFailed(NetworkChangeNotifier::NetworkHandle network,
456 const quic::QuicSocketAddress& peer_address) override;
Zhongyi Shi8fff75b2017-11-19 21:36:36457
Zhongyi Shi5f587cc2017-11-21 23:24:17458 bool OnSendConnectivityProbingPacket(
Zhongyi Shi8fff75b2017-11-19 21:36:36459 QuicChromiumPacketWriter* writer,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52460 const quic::QuicSocketAddress& peer_address) override;
Zhongyi Shi8fff75b2017-11-19 21:36:36461
Ryan Hamilton8d9ee76e2018-05-29 23:52:52462 // quic::QuicSpdySession methods:
Bence Béky984c8262019-02-15 01:08:36463 size_t WriteHeadersOnHeadersStream(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52464 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 Hamilton0239aac2018-05-19 00:03:13472 spdy::SpdyPriority new_priority) override;
rch99b644c2015-11-04 05:25:28473
Ryan Hamilton8d9ee76e2018-05-29 23:52:52474 // quic::QuicSession methods:
475 void OnStreamFrame(const quic::QuicStreamFrame& frame) override;
Fan Yange44bd4722018-10-11 01:11:32476 QuicChromiumClientStream* CreateOutgoingBidirectionalStream() override;
477 QuicChromiumClientStream* CreateOutgoingUnidirectionalStream() override;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52478 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;
dchengb03027d2014-10-21 12:00:20484 void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override;
485 void OnCryptoHandshakeMessageSent(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52486 const quic::CryptoHandshakeMessage& message) override;
dchengb03027d2014-10-21 12:00:20487 void OnCryptoHandshakeMessageReceived(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52488 const quic::CryptoHandshakeMessage& message) override;
489 void OnGoAway(const quic::QuicGoAwayFrame& frame) override;
490 void OnRstStream(const quic::QuicRstStreamFrame& frame) override;
Zhongyi Shi64c06852018-11-09 23:43:11491 void OnCanCreateNewOutgoingStream() override;
[email protected]b694e48c2014-03-18 17:10:13492
[email protected]90f62f092014-03-24 02:41:23493 // QuicClientSessionBase methods:
jri217455a12016-07-13 20:15:09494 void OnConfigNegotiated() override;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52495 void OnProofValid(
496 const quic::QuicCryptoClientConfig::CachedState& cached) override;
dchengb03027d2014-10-21 12:00:20497 void OnProofVerifyDetailsAvailable(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52498 const quic::ProofVerifyDetails& verify_details) override;
[email protected]8ba81212013-05-03 13:11:48499
Ryan Hamilton8d9ee76e2018-05-29 23:52:52500 // quic::QuicConnectionVisitorInterface methods:
Bin Wu9c4f0f72019-06-24 15:34:00501 void OnConnectionClosed(const quic::QuicConnectionCloseFrame& frame,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52502 quic::ConnectionCloseSource source) override;
Michael Warres74ee3ce2017-10-09 15:26:37503 void OnSuccessfulVersionNegotiation(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52504 const quic::ParsedQuicVersion& version) override;
Zhongyi Shi8fff75b2017-11-19 21:36:36505 void OnConnectivityProbeReceived(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52506 const quic::QuicSocketAddress& self_address,
507 const quic::QuicSocketAddress& peer_address) override;
jrid36ada62016-02-06 02:42:08508 void OnPathDegrading() override;
Victor Vasiliev3ef45552019-03-04 22:06:12509 bool ShouldKeepConnectionAlive() const override;
[email protected]dd3fd0e2012-11-04 05:14:40510
rcha02807b42016-01-29 21:56:15511 // QuicChromiumPacketReader::Visitor methods:
jrid140c472015-12-22 23:28:11512 void OnReadError(int result, const DatagramClientSocket* socket) override;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52513 bool OnPacket(const quic::QuicReceivedPacket& packet,
514 const quic::QuicSocketAddress& local_address,
515 const quic::QuicSocketAddress& peer_address) override;
rch31ca50f2015-03-20 05:51:00516
rcha378f65da2016-12-08 22:58:15517 // MultiplexedSession methods:
518 bool GetRemoteEndpoint(IPEndPoint* endpoint) override;
519 bool GetSSLInfo(SSLInfo* ssl_info) const override;
nharperd5cddca2016-02-27 03:37:52520
[email protected]872edd9e2013-01-16 08:51:15521 // Performs a crypto handshake with the server.
Bence Békyd8a21fc32018-06-27 18:29:58522 int CryptoConnect(CompletionOnceCallback callback);
[email protected]dd3fd0e2012-11-04 05:14:40523
jri7e636642016-01-14 06:57:08524 // Causes the QuicConnectionHelper to start reading from all sockets
Ryan Hamilton8d9ee76e2018-05-29 23:52:52525 // and passing the data along to the quic::QuicConnection.
[email protected]e13201d82012-12-12 05:00:32526 void StartReading();
527
rch90f64eb2017-05-01 03:07:12528 // Close the session because of |net_error| and notifies the factory
[email protected]35103d32013-06-26 04:00:20529 // that this session has been closed, which will delete the session.
Renjieba55fae2018-09-20 03:05:16530 // |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]56dfb902013-01-03 23:17:55535
Zhongyi Shi5f587cc2017-11-21 23:24:17536 // Close the session because of |net_error| and notifies the factory
537 // that this session has been closed later, which will delete the session.
Renjieba55fae2018-09-20 03:05:16538 // |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 Shi5f587cc2017-11-21 23:24:17543
Eric Romanb0436912019-04-30 23:38:42544 base::Value GetInfoAsValue(const std::set<HostPortPair>& aliases);
[email protected]c5b061b2013-01-05 00:31:34545
tfarina428341112016-09-22 13:38:20546 const NetLogWithSource& net_log() const { return net_log_; }
[email protected]0d10b592013-02-14 16:09:26547
rchf0b18c8a2017-05-05 19:31:57548 // Returns a Handle to this session.
Ryan Hamilton6c2a2a82017-12-15 02:06:28549 std::unique_ptr<QuicChromiumClientSession::Handle> CreateHandle(
550 const HostPortPair& destination);
[email protected]0b2294d32013-08-02 00:46:36551
[email protected]97cf3022013-09-05 14:30:16552 // 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]eed749f92013-12-23 18:57:38557 // 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 Jensen8e3c5d32018-02-19 17:06:33560 bool CanPool(const std::string& hostname,
561 PrivacyMode privacy_mode,
Matt Menke26e41542019-06-05 01:09:51562 const SocketTag& socket_tag,
563 const NetworkIsolationKey& network_isolation_key) const;
rch09a730f2015-01-23 00:30:41564
Ryan Hamilton8d9ee76e2018-05-29 23:52:52565 const quic::QuicServerId& server_id() const {
566 return session_key_.server_id();
567 }
[email protected]eed749f92013-12-23 18:57:38568
Renjiec5e9a8a32019-07-04 01:17:09569 const QuicSessionKey& quic_session_key() const { return session_key_; }
570
Zhongyi Shif3d6cddb2018-07-11 03:30:02571 // 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);
jri9f303712016-09-13 01:10:22575
Zhongyi Shib3bc982c2018-07-10 19:59:24576 // 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.
jri9f303712016-09-13 01:10:22579 void WriteToNewSocket();
580
Zhongyi Shi673f22ef2017-10-18 00:00:47581 // 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 Shi87ef15c2018-06-27 22:00:43587 bool close_session_on_error,
Zhongyi Shi673f22ef2017-10-18 00:00:47588 const NetLogWithSource& migration_net_log);
589
Zhongyi Shid3d5f502018-08-10 00:22:22590 // 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
jri9f303712016-09-13 01:10:22594 // 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|.
danakjad1777e2016-04-16 00:56:42598 bool MigrateToSocket(std::unique_ptr<DatagramClientSocket> socket,
599 std::unique_ptr<QuicChromiumPacketReader> reader,
jri9f303712016-09-13 01:10:22600 std::unique_ptr<QuicChromiumPacketWriter> writer);
jri7e636642016-01-14 06:57:08601
jri5b785512016-09-13 04:29:11602 // 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,
tfarina428341112016-09-22 13:38:20606 const NetLogWithSource& net_log);
jri5b785512016-09-13 04:29:11607
Zhongyi Shi5f587cc2017-11-21 23:24:17608 // 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 Shif124a582017-11-02 00:15:04614 // 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
jri5b785512016-09-13 04:29:11619 // 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
zhongyi6b5a3892016-03-12 04:46:20626 // Populates network error details for this session.
rchf0b18c8a2017-05-05 19:31:57627 void PopulateNetErrorDetails(NetErrorDetails* details) const;
zhongyi6b5a3892016-03-12 04:46:20628
jri7e636642016-01-14 06:57:08629 // 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
ckrasic244375a32016-02-04 21:21:22634 bool IsAuthorized(const std::string& hostname) override;
635
Ryan Hamilton8d9ee76e2018-05-29 23:52:52636 bool HandlePromised(quic::QuicStreamId associated_id,
637 quic::QuicStreamId promised_id,
Ryan Hamilton0239aac2018-05-19 00:03:13638 const spdy::SpdyHeaderBlock& headers) override;
ckrasic92757722016-03-22 00:45:36639
Ryan Hamilton8d9ee76e2018-05-29 23:52:52640 void DeletePromised(quic::QuicClientPromisedInfo* promised) override;
ckrasic4be6c6b2016-03-24 20:53:22641
Ryan Hamilton8d9ee76e2018-05-29 23:52:52642 void OnPushStreamTimedOut(quic::QuicStreamId stream_id) override;
zhongyi92bd5b42016-10-14 21:18:41643
zhongyi18bb2d92016-10-27 19:38:50644 // 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
xunjieli100937eb52016-09-15 20:09:37648 const LoadTimingInfo::ConnectTiming& GetConnectTiming();
649
Ryan Hamilton8d9ee76e2018-05-29 23:52:52650 quic::QuicTransportVersion GetQuicVersion() const;
bnc90be5dd782016-11-09 16:28:44651
xunjieli69720dd2017-01-30 15:36:29652 // 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 Hamiltona12722b2017-08-12 02:23:20657 bool require_confirmation() const { return require_confirmation_; }
658
[email protected]dd3fd0e2012-11-04 05:14:40659 protected:
Ryan Hamilton8d9ee76e2018-05-29 23:52:52660 // quic::QuicSession methods:
Fan Yang5a3bddf2018-10-12 10:05:50661 bool ShouldCreateIncomingStream(quic::QuicStreamId id) override;
Fan Yang32c5a112018-12-10 20:06:33662 bool ShouldCreateOutgoingBidirectionalStream() override;
663 bool ShouldCreateOutgoingUnidirectionalStream() override;
jokulikf2bd55c52016-03-24 22:35:30664
Fan Yang5a3bddf2018-10-12 10:05:50665 QuicChromiumClientStream* CreateIncomingStream(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52666 quic::QuicStreamId id) override;
Fan Yang32c5a112018-12-10 20:06:33667 QuicChromiumClientStream* CreateIncomingStream(
Ryan Hamilton8380c652019-06-04 02:25:06668 quic::PendingStream* pending) override;
[email protected]dd3fd0e2012-11-04 05:14:40669
670 private:
ckrasic4f9d88d2015-07-22 22:23:16671 friend class test::QuicChromiumClientSessionPeer;
[email protected]0b2294d32013-08-02 00:46:36672
rchf0b18c8a2017-05-05 19:31:57673 typedef std::set<Handle*> HandleSet;
[email protected]0b2294d32013-08-02 00:46:36674 typedef std::list<StreamRequest*> StreamRequestQueue;
675
Yixin Wang0d2c6b7e12017-08-16 21:12:55676 bool WasConnectionEverUsed();
677
Ramin Halavati683bcaa92018-02-14 08:42:39678 QuicChromiumClientStream* CreateOutgoingReliableStreamImpl(
679 const NetworkTrafficAnnotationTag& traffic_annotation);
680 QuicChromiumClientStream* CreateIncomingReliableStreamImpl(
Ryan Hamilton8d9ee76e2018-05-29 23:52:52681 quic::QuicStreamId id,
Ramin Halavati683bcaa92018-02-14 08:42:39682 const NetworkTrafficAnnotationTag& traffic_annotation);
Fan Yang32c5a112018-12-10 20:06:33683 QuicChromiumClientStream* CreateIncomingReliableStreamImpl(
Ryan Hamilton8380c652019-06-04 02:25:06684 quic::PendingStream* pending,
Fan Yang32c5a112018-12-10 20:06:33685 const NetworkTrafficAnnotationTag& traffic_annotation);
[email protected]e13201d82012-12-12 05:00:32686 // A completion callback invoked when a read completes.
687 void OnReadComplete(int result);
688
[email protected]4d283b32013-10-17 12:57:27689 void CloseAllStreams(int net_error);
rchf0b18c8a2017-05-05 19:31:57690 void CloseAllHandles(int net_error);
rch94c26d682017-04-29 02:49:27691 void CancelAllRequests(int net_error);
rchd606b6c32017-05-02 17:32:57692 void NotifyRequestsOfConfirmation(int net_error);
[email protected]4d283b32013-10-17 12:57:27693
Zhongyi Shi8fff75b2017-11-19 21:36:36694 ProbingResult StartProbeNetwork(NetworkChangeNotifier::NetworkHandle network,
Zhongyi Shi7b280d02018-12-13 02:54:41695 const quic::QuicSocketAddress& peer_address,
Zhongyi Shi8fff75b2017-11-19 21:36:36696 const NetLogWithSource& migration_net_log);
697
Zhongyi Shi5f587cc2017-11-21 23:24:17698 // Called when there is only one possible working network: |network|, If any
Zhongyi Shi7b280d02018-12-13 02:54:41699 // 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 Shi5f587cc2017-11-21 23:24:17706
Zhongyi Shif4747b32018-12-14 01:19:06707 // 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 Shi5f587cc2017-11-21 23:24:17719 void StartMigrateBackToDefaultNetworkTimer(base::TimeDelta delay);
720 void CancelMigrateBackToDefaultNetworkTimer();
721 void TryMigrateBackToDefaultNetwork(base::TimeDelta timeout);
722 void MaybeRetryMigrateBackToDefaultNetwork();
723
Zhongyi Shi32fe14d42019-02-28 00:25:36724 // 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 Shic16b4102019-02-12 00:37:40728 bool CheckIdleTimeExceedsIdleMigrationPeriod();
729
Zhongyi Shi0439ecc72018-07-11 04:41:26730 // 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 Shi5f587cc2017-11-21 23:24:17734 void LogMetricsOnNetworkDisconnected();
735 void LogMetricsOnNetworkMadeDefault();
Cherie Shi95f086902018-03-02 20:09:45736 void LogConnectionMigrationResultToHistogram(
737 QuicConnectionMigrationStatus status);
Zhongyi Shi996e31d2018-05-08 07:06:45738 void LogHandshakeStatusOnConnectionMigrationSignal() const;
Cherie Shi95f086902018-03-02 20:09:45739 void HistogramAndLogMigrationFailure(const NetLogWithSource& net_log,
740 QuicConnectionMigrationStatus status,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52741 quic::QuicConnectionId connection_id,
Cherie Shi95f086902018-03-02 20:09:45742 const std::string& reason);
743 void HistogramAndLogMigrationSuccess(const NetLogWithSource& net_log,
Ryan Hamilton8d9ee76e2018-05-29 23:52:52744 quic::QuicConnectionId connection_id);
Zhongyi Shi5f587cc2017-11-21 23:24:17745
[email protected]4d283b32013-10-17 12:57:27746 // 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]35103d32013-06-26 04:00:20751 // Posts a task to notify the factory that this session has been closed.
[email protected]4d283b32013-10-17 12:57:27752 void NotifyFactoryOfSessionClosedLater();
[email protected]35103d32013-06-26 04:00:20753
754 // Notifies the factory that this session has been closed which will
755 // delete |this|.
[email protected]4d283b32013-10-17 12:57:27756 void NotifyFactoryOfSessionClosed();
[email protected]35103d32013-06-26 04:00:20757
Paul Jensen8e3c5d32018-02-19 17:06:33758 QuicSessionKey session_key_;
[email protected]11c05872013-08-20 02:04:12759 bool require_confirmation_;
Zhongyi Shif4683a32017-12-01 00:03:28760 bool migrate_session_early_v2_;
Zhongyi Shi5f587cc2017-11-21 23:24:17761 bool migrate_session_on_network_change_v2_;
Zhongyi Shi32fe14d42019-02-28 00:25:36762 bool migrate_idle_session_;
Zhongyi Shic16b4102019-02-12 00:37:40763 // Session can be migrated if its idle time is within this period.
764 base::TimeDelta idle_migration_period_;
Zhongyi Shi73f23ca872017-12-13 18:37:13765 base::TimeDelta max_time_on_non_default_network_;
Zhongyi Shi8b1e43f2017-12-13 20:46:30766 // Maximum allowed number of migrations to non-default network triggered by
Zhongyi Shiee760762018-08-01 00:54:29767 // 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 Shi8b1e43f2017-12-13 20:46:30771 // 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 Hamilton8d9ee76e2018-05-29 23:52:52774 quic::QuicClock* clock_; // Unowned.
Zhongyi Shi673f22ef2017-10-18 00:00:47775 int yield_after_packets_;
Ryan Hamilton8d9ee76e2018-05-29 23:52:52776 quic::QuicTime::Delta yield_after_duration_;
Zhongyi Shidbce7f412019-02-01 23:16:29777 bool go_away_on_path_degrading_;
Zhongyi Shi673f22ef2017-10-18 00:00:47778
Zhongyi Shi066985fd2017-11-02 09:11:34779 base::TimeTicks most_recent_path_degrading_timestamp_;
780 base::TimeTicks most_recent_network_disconnected_timestamp_;
Zhongyi Shic16b4102019-02-12 00:37:40781 const base::TickClock* tick_clock_;
782 base::TimeTicks most_recent_stream_close_time_;
Zhongyi Shi066985fd2017-11-02 09:11:34783
784 int most_recent_write_error_;
785 base::TimeTicks most_recent_write_error_timestamp_;
786
Ryan Hamilton8d9ee76e2018-05-29 23:52:52787 std::unique_ptr<quic::QuicCryptoClientStream> crypto_stream_;
[email protected]e13201d82012-12-12 05:00:32788 QuicStreamFactory* stream_factory_;
danakjad1777e2016-04-16 00:56:42789 std::vector<std::unique_ptr<DatagramClientSocket>> sockets_;
[email protected]5db452202014-08-19 05:22:15790 TransportSecurityState* transport_security_state_;
Nick Harper89bc7212018-07-31 19:07:57791 SSLConfigService* ssl_config_service_;
danakjad1777e2016-04-16 00:56:42792 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]080b77932014-08-04 01:22:46795 std::string pinning_failure_log_;
dadriandf302c42016-06-10 18:48:59796 bool pkp_bypassed_;
Carlos IL81133382017-12-06 17:18:45797 bool is_fatal_cert_error_;
rchf0b18c8a2017-05-05 19:31:57798 HandleSet handles_;
[email protected]0b2294d32013-08-02 00:46:36799 StreamRequestQueue stream_requests_;
Bence Békyd8a21fc32018-06-27 18:29:58800 std::vector<CompletionOnceCallback> waiting_for_confirmation_callbacks_;
801 CompletionOnceCallback callback_;
[email protected]0d10b592013-02-14 16:09:26802 size_t num_total_streams_;
Zhongyi Shi8fff75b2017-11-19 21:36:36803 base::SequencedTaskRunner* task_runner_;
tfarina428341112016-09-22 13:38:20804 NetLogWithSource net_log_;
danakjad1777e2016-04-16 00:56:42805 std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_;
xunjieli100937eb52016-09-15 20:09:37806 LoadTimingInfo::ConnectTiming connect_timing_;
danakjad1777e2016-04-16 00:56:42807 std::unique_ptr<QuicConnectionLogger> logger_;
[email protected]775381a2014-03-27 15:37:39808 // 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_;
zhongyi6b5a3892016-03-12 04:46:20811 // True when the session receives a go away from server due to port migration.
812 bool port_migration_detected_;
zhongyi7465c1b2016-11-11 01:38:05813 // Not owned. |push_delegate_| outlives the session and handles server pushes
814 // received by session.
815 ServerPushDelegate* push_delegate_;
ckrasic4be6c6b2016-03-24 20:53:22816 // UMA histogram counters for streams pushed to this session.
817 int streams_pushed_count_;
818 int streams_pushed_and_claimed_count_;
zhongyi92bd5b42016-10-14 21:18:41819 uint64_t bytes_pushed_count_;
820 uint64_t bytes_pushed_and_unclaimed_count_;
Zhongyi Shib3bc982c2018-07-10 19:59:24821 // 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' Krasic3a35aa52017-08-10 22:20:06824 scoped_refptr<QuicChromiumPacketWriter::ReusableIOBuffer> packet_;
Zhongyi Shi5f587cc2017-11-21 23:24:17825 // Stores the latest default network platform marks.
826 NetworkChangeNotifier::NetworkHandle default_network_;
Zhongyi Shi8fff75b2017-11-19 21:36:36827 QuicConnectivityProbingManager probing_manager_;
Zhongyi Shi5f587cc2017-11-21 23:24:17828 int retry_migrate_back_count_;
829 base::OneShotTimer migrate_back_to_default_timer_;
Cherie Shi95f086902018-03-02 20:09:45830 ConnectionMigrationCause current_connection_migration_cause_;
Zhongyi Shib3bc982c2018-07-10 19:59:24831 // 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 Shif3d6cddb2018-07-11 03:30:02835 // 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 Wang079ad542018-01-11 04:06:05841
842 // If true, client headers will include HTTP/2 stream dependency info derived
Ryan Hamilton0239aac2018-05-19 00:03:13843 // from spdy::SpdyPriority.
Yixin Wang079ad542018-01-11 04:06:05844 bool headers_include_h2_stream_dependency_;
845 Http2PriorityDependencies priority_dependency_state_;
846
Jeremy Romand54000b22019-07-08 18:40:16847 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_{this};
[email protected]8ee611b2012-11-20 01:48:12848
ckrasic4f9d88d2015-07-22 22:23:16849 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession);
[email protected]dd3fd0e2012-11-04 05:14:40850};
851
852} // namespace net
853
Ryan Hamiltona3ee93a72018-08-01 22:03:08854#endif // NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_