quic_chromium_client_session.h 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  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. //
  5. // A client specific quic::QuicSession subclass. This class owns the underlying
  6. // quic::QuicConnection and QuicConnectionHelper objects. The connection stores
  7. // a non-owning pointer to the helper so this session needs to ensure that
  8. // the helper outlives the connection.
  9. #ifndef NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_
  10. #define NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_
  11. #include <stddef.h>
  12. #include <list>
  13. #include <memory>
  14. #include <set>
  15. #include <string>
  16. #include <vector>
  17. #include "base/containers/flat_map.h"
  18. #include "base/containers/lru_cache.h"
  19. #include "base/memory/raw_ptr.h"
  20. #include "base/observer_list.h"
  21. #include "base/observer_list_types.h"
  22. #include "base/strings/string_piece.h"
  23. #include "base/time/time.h"
  24. #include "base/timer/timer.h"
  25. #include "net/base/completion_once_callback.h"
  26. #include "net/base/load_timing_info.h"
  27. #include "net/base/net_error_details.h"
  28. #include "net/base/net_export.h"
  29. #include "net/base/network_handle.h"
  30. #include "net/base/proxy_server.h"
  31. #include "net/log/net_log_with_source.h"
  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_crypto_client_config_handle.h"
  37. #include "net/quic/quic_http3_logger.h"
  38. #include "net/quic/quic_session_key.h"
  39. #include "net/socket/socket_performance_watcher.h"
  40. #include "net/spdy/http2_priority_dependencies.h"
  41. #include "net/spdy/multiplexed_session.h"
  42. #include "net/spdy/server_push_delegate.h"
  43. #include "net/third_party/quiche/src/quiche/quic/core/http/quic_client_push_promise_index.h"
  44. #include "net/third_party/quiche/src/quiche/quic/core/http/quic_spdy_client_session_base.h"
  45. #include "net/third_party/quiche/src/quiche/quic/core/quic_crypto_client_stream.h"
  46. #include "net/third_party/quiche/src/quiche/quic/core/quic_packet_writer.h"
  47. #include "net/third_party/quiche/src/quiche/quic/core/quic_packets.h"
  48. #include "net/third_party/quiche/src/quiche/quic/core/quic_path_validator.h"
  49. #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h"
  50. #include "net/third_party/quiche/src/quiche/quic/core/quic_time.h"
  51. #include "net/traffic_annotation/network_traffic_annotation.h"
  52. #include "url/origin.h"
  53. #include "url/scheme_host_port.h"
  54. namespace net {
  55. class CertVerifyResult;
  56. class DatagramClientSocket;
  57. class NetLog;
  58. class QuicCryptoClientStreamFactory;
  59. class QuicServerInfo;
  60. class QuicStreamFactory;
  61. class SSLConfigService;
  62. class SSLInfo;
  63. class TransportSecurityState;
  64. namespace test {
  65. class QuicChromiumClientSessionPeer;
  66. } // namespace test
  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. // Result of a session migration attempt.
  71. enum class MigrationResult {
  72. SUCCESS, // Migration succeeded.
  73. NO_NEW_NETWORK, // Migration failed since no new network was found.
  74. FAILURE // Migration failed for other reasons.
  75. };
  76. // Mode of connection migration.
  77. enum class ConnectionMigrationMode {
  78. NO_MIGRATION,
  79. NO_MIGRATION_ON_PATH_DEGRADING_V1,
  80. FULL_MIGRATION_V1,
  81. NO_MIGRATION_ON_PATH_DEGRADING_V2,
  82. FULL_MIGRATION_V2
  83. };
  84. // Cause of a migration.
  85. enum MigrationCause {
  86. UNKNOWN_CAUSE,
  87. ON_NETWORK_CONNECTED, // No probing.
  88. ON_NETWORK_DISCONNECTED, // No probing.
  89. ON_WRITE_ERROR, // No probing.
  90. ON_NETWORK_MADE_DEFAULT, // With probing.
  91. ON_MIGRATE_BACK_TO_DEFAULT_NETWORK, // With probing.
  92. CHANGE_NETWORK_ON_PATH_DEGRADING, // With probing.
  93. CHANGE_PORT_ON_PATH_DEGRADING, // With probing.
  94. NEW_NETWORK_CONNECTED_POST_PATH_DEGRADING, // With probing.
  95. MIGRATION_CAUSE_MAX
  96. };
  97. // Result of connection migration.
  98. enum QuicConnectionMigrationStatus {
  99. MIGRATION_STATUS_NO_MIGRATABLE_STREAMS,
  100. MIGRATION_STATUS_ALREADY_MIGRATED,
  101. MIGRATION_STATUS_INTERNAL_ERROR,
  102. MIGRATION_STATUS_TOO_MANY_CHANGES,
  103. MIGRATION_STATUS_SUCCESS,
  104. MIGRATION_STATUS_NON_MIGRATABLE_STREAM,
  105. MIGRATION_STATUS_NOT_ENABLED,
  106. MIGRATION_STATUS_NO_ALTERNATE_NETWORK,
  107. MIGRATION_STATUS_ON_PATH_DEGRADING_DISABLED,
  108. MIGRATION_STATUS_DISABLED_BY_CONFIG,
  109. MIGRATION_STATUS_PATH_DEGRADING_NOT_ENABLED,
  110. MIGRATION_STATUS_TIMEOUT,
  111. MIGRATION_STATUS_ON_WRITE_ERROR_DISABLED,
  112. MIGRATION_STATUS_PATH_DEGRADING_BEFORE_HANDSHAKE_CONFIRMED,
  113. MIGRATION_STATUS_IDLE_MIGRATION_TIMEOUT,
  114. MIGRATION_STATUS_NO_UNUSED_CONNECTION_ID,
  115. MIGRATION_STATUS_MAX
  116. };
  117. // Result of a connectivity probing attempt.
  118. enum class ProbingResult {
  119. PENDING, // Probing started, pending result.
  120. DISABLED_WITH_IDLE_SESSION, // Probing disabled with idle session.
  121. DISABLED_BY_CONFIG, // Probing disabled by config.
  122. DISABLED_BY_NON_MIGRABLE_STREAM, // Probing disabled by special stream.
  123. INTERNAL_ERROR, // Probing failed for internal reason.
  124. FAILURE, // Probing failed for other reason.
  125. };
  126. class NET_EXPORT_PRIVATE QuicChromiumClientSession
  127. : public quic::QuicSpdyClientSessionBase,
  128. public MultiplexedSession,
  129. public QuicChromiumPacketReader::Visitor,
  130. public QuicChromiumPacketWriter::Delegate {
  131. public:
  132. class StreamRequest;
  133. // An interface that when implemented and added via
  134. // AddConnectivityObserver(), provides notifications when connectivity
  135. // quality changes.
  136. class NET_EXPORT_PRIVATE ConnectivityObserver : public base::CheckedObserver {
  137. public:
  138. // Called when path degrading is detected on |network|.
  139. virtual void OnSessionPathDegrading(QuicChromiumClientSession* session,
  140. handles::NetworkHandle network) = 0;
  141. // Called when forward progress is made after path degrading on |network|.
  142. virtual void OnSessionResumedPostPathDegrading(
  143. QuicChromiumClientSession* session,
  144. handles::NetworkHandle network) = 0;
  145. // Called when |session| encounters write error on |network|.
  146. // A write error may be caused by the change in the underlying network
  147. // interface, and can be pre-emptive hints of connectivity quality changes
  148. // based on the |error_code|.
  149. virtual void OnSessionEncounteringWriteError(
  150. QuicChromiumClientSession* session,
  151. handles::NetworkHandle network,
  152. int error_code) = 0;
  153. // Called when |session| is closed by |source| with |error_code|
  154. // and handshake has been confirmed.
  155. virtual void OnSessionClosedAfterHandshake(
  156. QuicChromiumClientSession* session,
  157. handles::NetworkHandle network,
  158. quic::ConnectionCloseSource source,
  159. quic::QuicErrorCode error_code) = 0;
  160. // Called when |this| is registered to monitor the connectivity of the
  161. // |session|.
  162. virtual void OnSessionRegistered(QuicChromiumClientSession* session,
  163. handles::NetworkHandle network) = 0;
  164. // Called when |session| is removed.
  165. virtual void OnSessionRemoved(QuicChromiumClientSession* session) = 0;
  166. };
  167. // Wrapper for interacting with the session in a restricted fashion which
  168. // hides the details of the underlying session's lifetime. All methods of
  169. // the Handle are safe to use even after the underlying session is destroyed.
  170. class NET_EXPORT_PRIVATE Handle
  171. : public MultiplexedSessionHandle,
  172. public quic::QuicClientPushPromiseIndex::Delegate {
  173. public:
  174. // Constructs a handle to |session| which was created via the alternative
  175. // server |destination|.
  176. Handle(const base::WeakPtr<QuicChromiumClientSession>& session,
  177. url::SchemeHostPort destination);
  178. Handle(const Handle& other) = delete;
  179. ~Handle() override;
  180. // Returns true if the session is still connected.
  181. bool IsConnected() const;
  182. // Returns true if the handshake has been confirmed.
  183. bool OneRttKeysAvailable() const;
  184. // Starts a request to rendezvous with a promised a stream. If OK is
  185. // returned, then |push_stream_| will be updated with the promised
  186. // stream. If ERR_IO_PENDING is returned, then when the rendezvous is
  187. // eventually completed |callback| will be called.
  188. int RendezvousWithPromised(const spdy::Http2HeaderBlock& headers,
  189. CompletionOnceCallback callback);
  190. // Starts a request to create a stream. If OK is returned, then
  191. // |stream_| will be updated with the newly created stream. If
  192. // ERR_IO_PENDING is returned, then when the request is eventuallly
  193. // complete |callback| will be called.
  194. int RequestStream(bool requires_confirmation,
  195. CompletionOnceCallback callback,
  196. const NetworkTrafficAnnotationTag& traffic_annotation);
  197. // Releases |stream_| to the caller. Returns nullptr if the underlying
  198. // QuicChromiumClientSession is closed.
  199. std::unique_ptr<QuicChromiumClientStream::Handle> ReleaseStream();
  200. // Releases |push_stream_| to the caller.
  201. std::unique_ptr<QuicChromiumClientStream::Handle> ReleasePromisedStream();
  202. // Sends Rst for the stream, and makes sure that future calls to
  203. // IsClosedStream(id) return true, which ensures that any subsequent
  204. // frames related to this stream will be ignored (modulo flow
  205. // control accounting).
  206. void ResetPromised(quic::QuicStreamId id,
  207. quic::QuicRstStreamErrorCode error_code);
  208. // Returns a new packet bundler while will cause writes to be batched up
  209. // until a packet is full, or the last bundler is destroyed.
  210. std::unique_ptr<quic::QuicConnection::ScopedPacketFlusher>
  211. CreatePacketBundler();
  212. // Populates network error details for this session.
  213. void PopulateNetErrorDetails(NetErrorDetails* details) const;
  214. // Returns the connection timing for the handshake of this session.
  215. const LoadTimingInfo::ConnectTiming& GetConnectTiming();
  216. // Returns true if |other| is a handle to the same session as this handle.
  217. bool SharesSameSession(const Handle& other) const;
  218. // Returns the QUIC version used by the session.
  219. quic::ParsedQuicVersion GetQuicVersion() const;
  220. // Copies the remote udp address into |address| and returns a net error
  221. // code.
  222. int GetPeerAddress(IPEndPoint* address) const;
  223. // Copies the local udp address into |address| and returns a net error
  224. // code.
  225. int GetSelfAddress(IPEndPoint* address) const;
  226. // Returns the push promise index associated with the session.
  227. quic::QuicClientPushPromiseIndex* GetPushPromiseIndex();
  228. // Returns the session's server ID.
  229. quic::QuicServerId server_id() const { return server_id_; }
  230. // Returns the alternative server used for this session.
  231. const url::SchemeHostPort& destination() const { return destination_; }
  232. // Returns the session's net log.
  233. const NetLogWithSource& net_log() const { return net_log_; }
  234. // Returns the session's connection migration mode.
  235. ConnectionMigrationMode connection_migration_mode() const {
  236. return session_->connection_migration_mode();
  237. }
  238. // quic::QuicClientPushPromiseIndex::Delegate implementation
  239. bool CheckVary(const spdy::Http2HeaderBlock& client_request,
  240. const spdy::Http2HeaderBlock& promise_request,
  241. const spdy::Http2HeaderBlock& promise_response) override;
  242. void OnRendezvousResult(quic::QuicSpdyStream* stream) override;
  243. // Returns true if the session's connection has sent or received any bytes.
  244. bool WasEverUsed() const;
  245. // Retrieves any DNS aliases for the given session key from the map stored
  246. // in `stream_factory_`. Includes all known aliases, e.g. from A, AAAA, or
  247. // HTTPS, not just from the address used for the connection, in no
  248. // particular order.
  249. const std::set<std::string>& GetDnsAliasesForSessionKey(
  250. const QuicSessionKey& key) const;
  251. private:
  252. friend class QuicChromiumClientSession;
  253. friend class QuicChromiumClientSession::StreamRequest;
  254. // Waits for the handshake to be confirmed and invokes |callback| when
  255. // that happens. If the handshake has already been confirmed, returns OK.
  256. // If the connection has already been closed, returns a net error. If the
  257. // connection closes before the handshake is confirmed, |callback| will
  258. // be invoked with an error.
  259. int WaitForHandshakeConfirmation(CompletionOnceCallback callback);
  260. // Called when the handshake is confirmed.
  261. void OnCryptoHandshakeConfirmed();
  262. // Called when the session is closed with a net error.
  263. void OnSessionClosed(quic::ParsedQuicVersion quic_version,
  264. int net_error,
  265. quic::QuicErrorCode quic_error,
  266. bool port_migration_detected,
  267. bool quic_connection_migration_attempted,
  268. bool quic_connection_migration_successful,
  269. LoadTimingInfo::ConnectTiming connect_timing,
  270. bool was_ever_used);
  271. // Called by |request| to create a stream.
  272. int TryCreateStream(StreamRequest* request);
  273. // Called by |request| to cancel stream request.
  274. void CancelRequest(StreamRequest* request);
  275. // Underlying session which may be destroyed before this handle.
  276. base::WeakPtr<QuicChromiumClientSession> session_;
  277. url::SchemeHostPort destination_;
  278. // Stream request created by |RequestStream()|.
  279. std::unique_ptr<StreamRequest> stream_request_;
  280. // Information saved from the session which can be used even after the
  281. // session is destroyed.
  282. NetLogWithSource net_log_;
  283. bool was_handshake_confirmed_;
  284. int net_error_ = OK;
  285. quic::QuicErrorCode quic_error_ = quic::QUIC_NO_ERROR;
  286. bool port_migration_detected_ = false;
  287. bool quic_connection_migration_attempted_ = false;
  288. bool quic_connection_migration_successful_ = false;
  289. quic::QuicServerId server_id_;
  290. quic::ParsedQuicVersion quic_version_;
  291. LoadTimingInfo::ConnectTiming connect_timing_;
  292. raw_ptr<quic::QuicClientPushPromiseIndex> push_promise_index_;
  293. // |quic::QuicClientPromisedInfo| owns this. It will be set when |Try()|
  294. // is asynchronous, i.e. it returned quic::QUIC_PENDING, and remains valid
  295. // until |OnRendezvouResult()| fires or |push_handle_->Cancel()| is
  296. // invoked.
  297. quic::QuicClientPushPromiseIndex::TryHandle* push_handle_ = nullptr;
  298. CompletionOnceCallback push_callback_;
  299. std::unique_ptr<QuicChromiumClientStream::Handle> push_stream_;
  300. bool was_ever_used_ = false;
  301. };
  302. // A helper class used to manage a request to create a stream.
  303. class NET_EXPORT_PRIVATE StreamRequest {
  304. public:
  305. StreamRequest(const StreamRequest&) = delete;
  306. StreamRequest& operator=(const StreamRequest&) = delete;
  307. // Cancels any pending stream creation request and resets |stream_| if
  308. // it has not yet been released.
  309. ~StreamRequest();
  310. // Starts a request to create a stream. If OK is returned, then
  311. // |stream_| will be updated with the newly created stream. If
  312. // ERR_IO_PENDING is returned, then when the request is eventuallly
  313. // complete |callback| will be called.
  314. int StartRequest(CompletionOnceCallback callback);
  315. // Releases |stream_| to the caller.
  316. std::unique_ptr<QuicChromiumClientStream::Handle> ReleaseStream();
  317. const NetworkTrafficAnnotationTag traffic_annotation() {
  318. return traffic_annotation_;
  319. }
  320. private:
  321. friend class QuicChromiumClientSession;
  322. enum State {
  323. STATE_NONE,
  324. STATE_WAIT_FOR_CONFIRMATION,
  325. STATE_WAIT_FOR_CONFIRMATION_COMPLETE,
  326. STATE_REQUEST_STREAM,
  327. STATE_REQUEST_STREAM_COMPLETE,
  328. };
  329. // |session| must outlive this request.
  330. StreamRequest(QuicChromiumClientSession::Handle* session,
  331. bool requires_confirmation,
  332. const NetworkTrafficAnnotationTag& traffic_annotation);
  333. void OnIOComplete(int rv);
  334. void DoCallback(int rv);
  335. int DoLoop(int rv);
  336. int DoWaitForConfirmation();
  337. int DoWaitForConfirmationComplete(int rv);
  338. int DoRequestStream();
  339. int DoRequestStreamComplete(int rv);
  340. // Called by |session_| for an asynchronous request when the stream
  341. // request has finished successfully.
  342. void OnRequestCompleteSuccess(
  343. std::unique_ptr<QuicChromiumClientStream::Handle> stream);
  344. // Called by |session_| for an asynchronous request when the stream
  345. // request has finished with an error. Also called with ERR_ABORTED
  346. // if |session_| is destroyed while the stream request is still pending.
  347. void OnRequestCompleteFailure(int rv);
  348. raw_ptr<QuicChromiumClientSession::Handle> session_;
  349. const bool requires_confirmation_;
  350. CompletionOnceCallback callback_;
  351. std::unique_ptr<QuicChromiumClientStream::Handle> stream_;
  352. // For tracking how much time pending stream requests wait.
  353. base::TimeTicks pending_start_time_;
  354. State next_state_;
  355. const NetworkTrafficAnnotationTag traffic_annotation_;
  356. base::WeakPtrFactory<StreamRequest> weak_factory_{this};
  357. };
  358. // This class contains all the context needed for path validation and
  359. // migration.
  360. class NET_EXPORT_PRIVATE QuicChromiumPathValidationContext
  361. : public quic::QuicPathValidationContext {
  362. public:
  363. QuicChromiumPathValidationContext(
  364. const quic::QuicSocketAddress& self_address,
  365. const quic::QuicSocketAddress& peer_address,
  366. handles::NetworkHandle network,
  367. std::unique_ptr<DatagramClientSocket> socket,
  368. std::unique_ptr<QuicChromiumPacketWriter> writer,
  369. std::unique_ptr<QuicChromiumPacketReader> reader);
  370. ~QuicChromiumPathValidationContext() override;
  371. handles::NetworkHandle network();
  372. quic::QuicPacketWriter* WriterToUse() override;
  373. // Transfer the ownership from |this| to the caller.
  374. std::unique_ptr<QuicChromiumPacketWriter> ReleaseWriter();
  375. std::unique_ptr<DatagramClientSocket> ReleaseSocket();
  376. std::unique_ptr<QuicChromiumPacketReader> ReleaseReader();
  377. private:
  378. handles::NetworkHandle network_handle_;
  379. std::unique_ptr<DatagramClientSocket> socket_;
  380. std::unique_ptr<QuicChromiumPacketWriter> writer_;
  381. std::unique_ptr<QuicChromiumPacketReader> reader_;
  382. };
  383. // This class implements Chrome logic for path validation events associated
  384. // with connection migration.
  385. class NET_EXPORT_PRIVATE ConnectionMigrationValidationResultDelegate
  386. : public quic::QuicPathValidator::ResultDelegate {
  387. public:
  388. explicit ConnectionMigrationValidationResultDelegate(
  389. QuicChromiumClientSession* session);
  390. void OnPathValidationSuccess(
  391. std::unique_ptr<quic::QuicPathValidationContext> context,
  392. quic::QuicTime start_time) override;
  393. void OnPathValidationFailure(
  394. std::unique_ptr<quic::QuicPathValidationContext> context) override;
  395. private:
  396. // |session_| owns |this| and should out live |this|.
  397. raw_ptr<QuicChromiumClientSession> session_;
  398. };
  399. // This class implements Chrome logic for path validation events associated
  400. // with port migration.
  401. class NET_EXPORT_PRIVATE PortMigrationValidationResultDelegate
  402. : public quic::QuicPathValidator::ResultDelegate {
  403. public:
  404. explicit PortMigrationValidationResultDelegate(
  405. QuicChromiumClientSession* session);
  406. void OnPathValidationSuccess(
  407. std::unique_ptr<quic::QuicPathValidationContext> context,
  408. quic::QuicTime start_time) override;
  409. void OnPathValidationFailure(
  410. std::unique_ptr<quic::QuicPathValidationContext> context) override;
  411. private:
  412. // |session_| owns |this| and should out live |this|.
  413. raw_ptr<QuicChromiumClientSession> session_;
  414. };
  415. // This class is used to handle writer events that occur on the probing path.
  416. class NET_EXPORT_PRIVATE QuicChromiumPathValidationWriterDelegate
  417. : public QuicChromiumPacketWriter::Delegate {
  418. public:
  419. QuicChromiumPathValidationWriterDelegate(
  420. QuicChromiumClientSession* session,
  421. base::SequencedTaskRunner* task_runner);
  422. QuicChromiumPathValidationWriterDelegate(
  423. const QuicChromiumPathValidationWriterDelegate&) = delete;
  424. QuicChromiumPathValidationWriterDelegate& operator=(
  425. const QuicChromiumPathValidationWriterDelegate&) = delete;
  426. ~QuicChromiumPathValidationWriterDelegate();
  427. // QuicChromiumPacketWriter::Delegate interface.
  428. int HandleWriteError(
  429. int error_code,
  430. scoped_refptr<QuicChromiumPacketWriter::ReusableIOBuffer> last_packet)
  431. override;
  432. void OnWriteError(int error_code) override;
  433. void OnWriteUnblocked() override;
  434. void set_peer_address(const quic::QuicSocketAddress& peer_address);
  435. void set_network(handles::NetworkHandle network);
  436. private:
  437. void NotifySessionProbeFailed(handles::NetworkHandle network);
  438. // |session_| owns |this| and should out live |this|.
  439. raw_ptr<QuicChromiumClientSession> session_;
  440. // |task_owner_| should out live |this|.
  441. raw_ptr<base::SequencedTaskRunner> task_runner_;
  442. // The path validation context of the most recent probing.
  443. handles::NetworkHandle network_;
  444. quic::QuicSocketAddress peer_address_;
  445. base::WeakPtrFactory<QuicChromiumPathValidationWriterDelegate>
  446. weak_factory_{this};
  447. };
  448. // Constructs a new session which will own |connection|, but not
  449. // |stream_factory|, which must outlive this session.
  450. // TODO(rch): decouple the factory from the session via a Delegate interface.
  451. //
  452. // If |require_confirmation| is true, the returned session will wait for a
  453. // successful QUIC handshake before vending any streams, to ensure that both
  454. // the server and the current network support QUIC, as HTTP fallback can't
  455. // trigger (or at least will take longer) after a QUIC stream has successfully
  456. // been created.
  457. QuicChromiumClientSession(
  458. quic::QuicConnection* connection,
  459. std::unique_ptr<DatagramClientSocket> socket,
  460. QuicStreamFactory* stream_factory,
  461. QuicCryptoClientStreamFactory* crypto_client_stream_factory,
  462. const quic::QuicClock* clock,
  463. TransportSecurityState* transport_security_state,
  464. SSLConfigService* ssl_config_service,
  465. std::unique_ptr<QuicServerInfo> server_info,
  466. const QuicSessionKey& session_key,
  467. bool require_confirmation,
  468. bool migrate_sesion_early_v2,
  469. bool migrate_session_on_network_change_v2,
  470. handles::NetworkHandle default_network,
  471. quic::QuicTime::Delta retransmittable_on_wire_timeout,
  472. bool migrate_idle_session,
  473. bool allow_port_migration,
  474. base::TimeDelta idle_migration_period,
  475. base::TimeDelta max_time_on_non_default_network,
  476. int max_migrations_to_non_default_network_on_write_error,
  477. int max_migrations_to_non_default_network_on_path_degrading,
  478. int yield_after_packets,
  479. quic::QuicTime::Delta yield_after_duration,
  480. bool headers_include_h2_stream_dependency,
  481. int cert_verify_flags,
  482. const quic::QuicConfig& config,
  483. std::unique_ptr<QuicCryptoClientConfigHandle> crypto_config,
  484. const char* const connection_description,
  485. base::TimeTicks dns_resolution_start_time,
  486. base::TimeTicks dns_resolution_end_time,
  487. std::unique_ptr<quic::QuicClientPushPromiseIndex> push_promise_index,
  488. ServerPushDelegate* push_delegate,
  489. const base::TickClock* tick_clock,
  490. base::SequencedTaskRunner* task_runner,
  491. std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
  492. NetLog* net_log);
  493. QuicChromiumClientSession(const QuicChromiumClientSession&) = delete;
  494. QuicChromiumClientSession& operator=(const QuicChromiumClientSession&) =
  495. delete;
  496. ~QuicChromiumClientSession() override;
  497. void Initialize() override;
  498. void AddHandle(Handle* handle);
  499. void RemoveHandle(Handle* handle);
  500. void AddConnectivityObserver(ConnectivityObserver* observer);
  501. void RemoveConnectivityObserver(ConnectivityObserver* observer);
  502. // Returns the session's connection migration mode.
  503. ConnectionMigrationMode connection_migration_mode() const;
  504. // Waits for the handshake to be confirmed and invokes |callback| when
  505. // that happens. If the handshake has already been confirmed, returns OK.
  506. // If the connection has already been closed, returns a net error. If the
  507. // connection closes before the handshake is confirmed, |callback| will
  508. // be invoked with an error.
  509. int WaitForHandshakeConfirmation(CompletionOnceCallback callback);
  510. // Attempts to create a new stream. If the stream can be
  511. // created immediately, returns OK. If the open stream limit
  512. // has been reached, returns ERR_IO_PENDING, and |request|
  513. // will be added to the stream requets queue and will
  514. // be completed asynchronously.
  515. // TODO(rch): remove |stream| from this and use setter on |request|
  516. // and fix in spdy too.
  517. int TryCreateStream(StreamRequest* request);
  518. // Cancels the pending stream creation request.
  519. void CancelRequest(StreamRequest* request);
  520. // QuicChromiumPacketWriter::Delegate override.
  521. int HandleWriteError(int error_code,
  522. scoped_refptr<QuicChromiumPacketWriter::ReusableIOBuffer>
  523. last_packet) override;
  524. void OnWriteError(int error_code) override;
  525. // Called when the associated writer is unblocked. Write the cached |packet_|
  526. // if |packet_| is set. May send a PING packet if
  527. // |send_packet_after_migration_| is set and writer is not blocked after
  528. // writing queued packets.
  529. void OnWriteUnblocked() override;
  530. void OnConnectionMigrationProbeSucceeded(
  531. handles::NetworkHandle network,
  532. const quic::QuicSocketAddress& peer_address,
  533. const quic::QuicSocketAddress& self_address,
  534. std::unique_ptr<DatagramClientSocket> socket,
  535. std::unique_ptr<QuicChromiumPacketWriter> writer,
  536. std::unique_ptr<QuicChromiumPacketReader> reader);
  537. void OnPortMigrationProbeSucceeded(
  538. handles::NetworkHandle network,
  539. const quic::QuicSocketAddress& peer_address,
  540. const quic::QuicSocketAddress& self_address,
  541. std::unique_ptr<DatagramClientSocket> socket,
  542. std::unique_ptr<QuicChromiumPacketWriter> writer,
  543. std::unique_ptr<QuicChromiumPacketReader> reader);
  544. void OnProbeFailed(handles::NetworkHandle network,
  545. const quic::QuicSocketAddress& peer_address);
  546. // quic::QuicSpdySession methods:
  547. size_t WriteHeadersOnHeadersStream(
  548. quic::QuicStreamId id,
  549. spdy::Http2HeaderBlock headers,
  550. bool fin,
  551. const spdy::SpdyStreamPrecedence& precedence,
  552. quiche::QuicheReferenceCountedPointer<quic::QuicAckListenerInterface>
  553. ack_listener) override;
  554. void UnregisterStreamPriority(quic::QuicStreamId id, bool is_static) override;
  555. void UpdateStreamPriority(
  556. quic::QuicStreamId id,
  557. const spdy::SpdyStreamPrecedence& new_precedence) override;
  558. void OnHttp3GoAway(uint64_t id) override;
  559. void OnAcceptChFrameReceivedViaAlps(
  560. const quic::AcceptChFrame& frame) override;
  561. // quic::QuicSession methods:
  562. QuicChromiumClientStream* CreateOutgoingBidirectionalStream() override;
  563. QuicChromiumClientStream* CreateOutgoingUnidirectionalStream() override;
  564. const quic::QuicCryptoClientStream* GetCryptoStream() const override;
  565. quic::QuicCryptoClientStream* GetMutableCryptoStream() override;
  566. void SetDefaultEncryptionLevel(quic::EncryptionLevel level) override;
  567. void OnTlsHandshakeComplete() override;
  568. void OnNewEncryptionKeyAvailable(
  569. quic::EncryptionLevel level,
  570. std::unique_ptr<quic::QuicEncrypter> encrypter) override;
  571. void OnCryptoHandshakeMessageSent(
  572. const quic::CryptoHandshakeMessage& message) override;
  573. void OnCryptoHandshakeMessageReceived(
  574. const quic::CryptoHandshakeMessage& message) override;
  575. void OnGoAway(const quic::QuicGoAwayFrame& frame) override;
  576. void OnCanCreateNewOutgoingStream(bool unidirectional) override;
  577. // QuicSpdyClientSessionBase methods:
  578. void OnConfigNegotiated() override;
  579. void OnProofValid(
  580. const quic::QuicCryptoClientConfig::CachedState& cached) override;
  581. void OnProofVerifyDetailsAvailable(
  582. const quic::ProofVerifyDetails& verify_details) override;
  583. // quic::QuicConnectionVisitorInterface methods:
  584. void OnConnectionClosed(const quic::QuicConnectionCloseFrame& frame,
  585. quic::ConnectionCloseSource source) override;
  586. void OnSuccessfulVersionNegotiation(
  587. const quic::ParsedQuicVersion& version) override;
  588. void OnPathDegrading() override;
  589. void OnForwardProgressMadeAfterPathDegrading() override;
  590. void OnKeyUpdate(quic::KeyUpdateReason reason) override;
  591. // QuicChromiumPacketReader::Visitor methods:
  592. bool OnReadError(int result, const DatagramClientSocket* socket) override;
  593. bool OnPacket(const quic::QuicReceivedPacket& packet,
  594. const quic::QuicSocketAddress& local_address,
  595. const quic::QuicSocketAddress& peer_address) override;
  596. void OnStreamClosed(quic::QuicStreamId stream_id) override;
  597. // MultiplexedSession methods:
  598. int GetRemoteEndpoint(IPEndPoint* endpoint) override;
  599. bool GetSSLInfo(SSLInfo* ssl_info) const override;
  600. base::StringPiece GetAcceptChViaAlps(
  601. const url::SchemeHostPort& scheme_host_port) const override;
  602. // Performs a crypto handshake with the server.
  603. int CryptoConnect(CompletionOnceCallback callback);
  604. // Causes the QuicConnectionHelper to start reading from all sockets
  605. // and passing the data along to the quic::QuicConnection.
  606. void StartReading();
  607. // Close the session because of |net_error| and notifies the factory
  608. // that this session has been closed, which will delete the session.
  609. // |behavior| will suggest whether we should send connection close packets
  610. // when closing the connection.
  611. void CloseSessionOnError(int net_error,
  612. quic::QuicErrorCode quic_error,
  613. quic::ConnectionCloseBehavior behavior);
  614. // Close the session because of |net_error| and notifies the factory
  615. // that this session has been closed later, which will delete the session.
  616. // |behavior| will suggest whether we should send connection close packets
  617. // when closing the connection.
  618. void CloseSessionOnErrorLater(int net_error,
  619. quic::QuicErrorCode quic_error,
  620. quic::ConnectionCloseBehavior behavior);
  621. base::Value GetInfoAsValue(const std::set<HostPortPair>& aliases);
  622. const NetLogWithSource& net_log() const { return net_log_; }
  623. // Returns true if the stream factory disables gQUIC 0-RTT.
  624. bool gquic_zero_rtt_disabled() const;
  625. // Returns a Handle to this session.
  626. std::unique_ptr<QuicChromiumClientSession::Handle> CreateHandle(
  627. url::SchemeHostPort destination);
  628. // Returns the number of client hello messages that have been sent on the
  629. // crypto stream. If the handshake has completed then this is one greater
  630. // than the number of round-trips needed for the handshake.
  631. int GetNumSentClientHellos() const;
  632. // Returns true if |hostname| may be pooled onto this session.
  633. // |other_session_key| specifies the seession key associated with |hostname|
  634. // (its own hostname and port fields are ignored). If this is a secure QUIC
  635. // session, then |hostname| must match the certificate presented during the
  636. // handshake.
  637. bool CanPool(const std::string& hostname,
  638. const QuicSessionKey& other_session_key) const;
  639. const quic::QuicServerId& server_id() const {
  640. return session_key_.server_id();
  641. }
  642. const QuicSessionKey& quic_session_key() const { return session_key_; }
  643. // Attempts to migrate session when |writer| encounters a write error.
  644. // If |writer| is no longer actively used, abort migration.
  645. void MigrateSessionOnWriteError(int error_code,
  646. quic::QuicPacketWriter* writer);
  647. // Helper method that completes connection/server migration.
  648. // Unblocks packet writer on network level. If the writer becomes unblocked
  649. // then, OnWriteUnblocked() will be invoked to send packet after migration.
  650. void WriteToNewSocket();
  651. // Migrates session over to use |peer_address| and |network|.
  652. // If |network| is handles::kInvalidNetworkHandle, default network is used. If
  653. // the migration fails and |close_session_on_error| is true, session will be
  654. // closed.
  655. MigrationResult Migrate(handles::NetworkHandle network,
  656. IPEndPoint peer_address,
  657. bool close_session_on_error);
  658. // Migrates session onto new socket, i.e., sets |writer| to be the new
  659. // default writer and post a task to write to |socket|. |reader| *must*
  660. // has been started reading from the socket. Returns true if
  661. // socket was successfully added to the session and the session was
  662. // successfully migrated to using the new socket. Returns true on
  663. // successful migration, or false if number of migrations exceeds
  664. // kMaxReadersPerQuicSession. Takes ownership of |socket|, |reader|,
  665. // and |writer|.
  666. bool MigrateToSocket(const quic::QuicSocketAddress& self_address,
  667. const quic::QuicSocketAddress& peer_address,
  668. std::unique_ptr<DatagramClientSocket> socket,
  669. std::unique_ptr<QuicChromiumPacketReader> reader,
  670. std::unique_ptr<QuicChromiumPacketWriter> writer);
  671. // Called when NetworkChangeNotifier notifies observers of a newly
  672. // connected network. Migrates this session to the newly connected
  673. // network if the session has a pending migration.
  674. void OnNetworkConnected(handles::NetworkHandle network);
  675. // Called when NetworkChangeNotifier broadcasts to observers of
  676. // |disconnected_network|.
  677. void OnNetworkDisconnectedV2(handles::NetworkHandle disconnected_network);
  678. // Called when NetworkChangeNotifier broadcats to observers of a new default
  679. // network. Migrates this session to |new_network| if appropriate.
  680. void OnNetworkMadeDefault(handles::NetworkHandle new_network);
  681. // Schedules a migration alarm to wait for a new network.
  682. void OnNoNewNetwork();
  683. // Called when migration alarm fires. If migration has not occurred
  684. // since alarm was set, closes session with error.
  685. void OnMigrationTimeout(size_t num_sockets);
  686. // Populates network error details for this session.
  687. void PopulateNetErrorDetails(NetErrorDetails* details) const;
  688. // Returns current default socket. This is the socket over which all
  689. // QUIC packets are sent. This default socket can change, so do not store the
  690. // returned socket.
  691. const DatagramClientSocket* GetDefaultSocket() const;
  692. // Returns the network interface that is currently used to send packets.
  693. // If handles::NetworkHandle is not supported, always return
  694. // handles::kInvalidNetworkHandle.
  695. handles::NetworkHandle GetCurrentNetwork() const;
  696. bool IsAuthorized(const std::string& hostname) override;
  697. bool HandlePromised(quic::QuicStreamId associated_id,
  698. quic::QuicStreamId promised_id,
  699. const spdy::Http2HeaderBlock& headers) override;
  700. void DeletePromised(quic::QuicClientPromisedInfo* promised) override;
  701. void OnPushStreamTimedOut(quic::QuicStreamId stream_id) override;
  702. // Cancels the push if the push stream for |url| has not been claimed and is
  703. // still active. Otherwise, no-op.
  704. void CancelPush(const GURL& url);
  705. const LoadTimingInfo::ConnectTiming& GetConnectTiming();
  706. quic::ParsedQuicVersion GetQuicVersion() const;
  707. // Looks for a push that matches the provided parameters.
  708. quic::QuicClientPromisedInfo* GetPromised(const GURL& url,
  709. const QuicSessionKey& session_key);
  710. bool require_confirmation() const { return require_confirmation_; }
  711. // Retrieves any DNS aliases for the given session key from the map stored
  712. // in `stream_factory_`. Includes all known aliases, e.g. from A, AAAA, or
  713. // HTTPS, not just from the address used for the connection, in no particular
  714. // order.
  715. const std::set<std::string>& GetDnsAliasesForSessionKey(
  716. const QuicSessionKey& key) const;
  717. protected:
  718. // quic::QuicSession methods:
  719. bool ShouldCreateIncomingStream(quic::QuicStreamId id) override;
  720. bool ShouldCreateOutgoingBidirectionalStream() override;
  721. bool ShouldCreateOutgoingUnidirectionalStream() override;
  722. QuicChromiumClientStream* CreateIncomingStream(
  723. quic::QuicStreamId id) override;
  724. QuicChromiumClientStream* CreateIncomingStream(
  725. quic::PendingStream* pending) override;
  726. private:
  727. friend class test::QuicChromiumClientSessionPeer;
  728. typedef std::set<Handle*> HandleSet;
  729. typedef std::list<StreamRequest*> StreamRequestQueue;
  730. bool WasConnectionEverUsed();
  731. QuicChromiumClientStream* CreateOutgoingReliableStreamImpl(
  732. const NetworkTrafficAnnotationTag& traffic_annotation);
  733. QuicChromiumClientStream* CreateIncomingReliableStreamImpl(
  734. quic::QuicStreamId id,
  735. const NetworkTrafficAnnotationTag& traffic_annotation);
  736. QuicChromiumClientStream* CreateIncomingReliableStreamImpl(
  737. quic::PendingStream* pending,
  738. const NetworkTrafficAnnotationTag& traffic_annotation);
  739. // A completion callback invoked when a read completes.
  740. void OnReadComplete(int result);
  741. void NotifyAllStreamsOfError(int net_error);
  742. void CloseAllHandles(int net_error);
  743. void CancelAllRequests(int net_error);
  744. void NotifyRequestsOfConfirmation(int net_error);
  745. // Probe on <network, peer_address>.
  746. // If <network, peer_addres> is identical to the current path, the probe
  747. // is sent on a different port.
  748. ProbingResult StartProbing(handles::NetworkHandle network,
  749. const quic::QuicSocketAddress& peer_address);
  750. // Perform a few checks before StartProbing. If any of those checks fails,
  751. // StartProbing will be skipped.
  752. ProbingResult MaybeStartProbing(handles::NetworkHandle network,
  753. const quic::QuicSocketAddress& peer_address);
  754. // Helper method to perform a few checks and initiate connection migration
  755. // attempt when path degrading is detected.
  756. // Called when path is degrading and there is an alternate network or a new
  757. // network is connected after path degrading.
  758. void MaybeMigrateToAlternateNetworkOnPathDegrading();
  759. // Helper method to initiate a port migration on path degrading is detected.
  760. void MaybeMigrateToDifferentPortOnPathDegrading();
  761. // Called when there is only one possible working network: |network|, If any
  762. // error encountered, this session will be closed.
  763. // When the migration succeeds:
  764. // - If no longer on the default network, set timer to migrate back to the
  765. // default network;
  766. // - If now on the default network, cancel timer to migrate back to default
  767. // network.
  768. void MigrateNetworkImmediately(handles::NetworkHandle network);
  769. void StartMigrateBackToDefaultNetworkTimer(base::TimeDelta delay);
  770. void CancelMigrateBackToDefaultNetworkTimer();
  771. void TryMigrateBackToDefaultNetwork(base::TimeDelta timeout);
  772. void MaybeRetryMigrateBackToDefaultNetwork();
  773. // If migrate idle session is enabled, returns true and post a task to close
  774. // the connection if session's idle time exceeds the |idle_migration_period_|.
  775. // If migrate idle session is not enabled, returns true and posts a task to
  776. // close the connection if session doesn't have outstanding streams.
  777. bool CheckIdleTimeExceedsIdleMigrationPeriod();
  778. // Close non-migratable streams in both directions by sending reset stream to
  779. // peer when connection migration attempts to migrate to the alternate
  780. // network.
  781. void ResetNonMigratableStreams();
  782. void LogMetricsOnNetworkDisconnected();
  783. void LogMetricsOnNetworkMadeDefault();
  784. void LogMigrationResultToHistogram(QuicConnectionMigrationStatus status);
  785. void LogHandshakeStatusOnMigrationSignal() const;
  786. void HistogramAndLogMigrationFailure(QuicConnectionMigrationStatus status,
  787. quic::QuicConnectionId connection_id,
  788. const char* reason);
  789. void HistogramAndLogMigrationSuccess(quic::QuicConnectionId connection_id);
  790. // Notifies the factory that this session is going away and no more streams
  791. // should be created from it. This needs to be called before closing any
  792. // streams, because closing a stream may cause a new stream to be created.
  793. void NotifyFactoryOfSessionGoingAway();
  794. // Posts a task to notify the factory that this session has been closed.
  795. void NotifyFactoryOfSessionClosedLater();
  796. // Notifies the factory that this session has been closed which will
  797. // delete |this|.
  798. void NotifyFactoryOfSessionClosed();
  799. // Called when default encryption level switches to forward secure.
  800. void OnCryptoHandshakeComplete();
  801. void LogZeroRttStats();
  802. QuicSessionKey session_key_;
  803. bool require_confirmation_;
  804. bool migrate_session_early_v2_;
  805. bool migrate_session_on_network_change_v2_;
  806. bool migrate_idle_session_;
  807. bool allow_port_migration_;
  808. // Session can be migrated if its idle time is within this period.
  809. base::TimeDelta idle_migration_period_;
  810. base::TimeDelta max_time_on_non_default_network_;
  811. // Maximum allowed number of migrations to non-default network triggered by
  812. // packet write error per default network.
  813. int max_migrations_to_non_default_network_on_write_error_;
  814. int current_migrations_to_non_default_network_on_write_error_ = 0;
  815. // Maximum allowed number of migrations to non-default network triggered by
  816. // path degrading per default network.
  817. int max_migrations_to_non_default_network_on_path_degrading_;
  818. int current_migrations_to_non_default_network_on_path_degrading_ = 0;
  819. raw_ptr<const quic::QuicClock> clock_; // Unowned.
  820. int yield_after_packets_;
  821. quic::QuicTime::Delta yield_after_duration_;
  822. base::TimeTicks most_recent_path_degrading_timestamp_;
  823. base::TimeTicks most_recent_network_disconnected_timestamp_;
  824. raw_ptr<const base::TickClock> tick_clock_;
  825. base::TimeTicks most_recent_stream_close_time_;
  826. int most_recent_write_error_ = 0;
  827. base::TimeTicks most_recent_write_error_timestamp_;
  828. std::unique_ptr<QuicCryptoClientConfigHandle> crypto_config_;
  829. std::unique_ptr<quic::QuicCryptoClientStream> crypto_stream_;
  830. raw_ptr<QuicStreamFactory> stream_factory_;
  831. base::ObserverList<ConnectivityObserver> connectivity_observer_list_;
  832. std::vector<std::unique_ptr<DatagramClientSocket>> sockets_;
  833. raw_ptr<TransportSecurityState> transport_security_state_;
  834. raw_ptr<SSLConfigService> ssl_config_service_;
  835. std::unique_ptr<QuicServerInfo> server_info_;
  836. std::unique_ptr<CertVerifyResult> cert_verify_result_;
  837. std::string pinning_failure_log_;
  838. bool pkp_bypassed_ = false;
  839. bool is_fatal_cert_error_ = false;
  840. HandleSet handles_;
  841. StreamRequestQueue stream_requests_;
  842. std::vector<CompletionOnceCallback> waiting_for_confirmation_callbacks_;
  843. CompletionOnceCallback callback_;
  844. size_t num_total_streams_ = 0;
  845. raw_ptr<base::SequencedTaskRunner> task_runner_;
  846. NetLogWithSource net_log_;
  847. std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_;
  848. LoadTimingInfo::ConnectTiming connect_timing_;
  849. std::unique_ptr<QuicConnectionLogger> logger_;
  850. std::unique_ptr<QuicHttp3Logger> http3_logger_;
  851. // True when the session is going away, and streams may no longer be created
  852. // on this session. Existing stream will continue to be processed.
  853. bool going_away_ = false;
  854. // True when the session receives a go away from server due to port migration.
  855. bool port_migration_detected_ = false;
  856. bool quic_connection_migration_attempted_ = false;
  857. bool quic_connection_migration_successful_ = false;
  858. // Not owned. |push_delegate_| outlives the session and handles server pushes
  859. // received by session.
  860. raw_ptr<ServerPushDelegate> push_delegate_;
  861. // UMA histogram counters for streams pushed to this session.
  862. int streams_pushed_count_ = 0;
  863. int streams_pushed_and_claimed_count_ = 0;
  864. uint64_t bytes_pushed_count_ = 0;
  865. uint64_t bytes_pushed_and_unclaimed_count_ = 0;
  866. // Stores the packet that witnesses socket write error. This packet will be
  867. // written to an alternate socket when the migration completes and the
  868. // alternate socket is unblocked.
  869. scoped_refptr<QuicChromiumPacketWriter::ReusableIOBuffer> packet_;
  870. // Stores the latest default network platform marks if migration is enabled.
  871. // Otherwise, stores the network interface that is used by the connection.
  872. handles::NetworkHandle default_network_;
  873. int retry_migrate_back_count_ = 0;
  874. base::OneShotTimer migrate_back_to_default_timer_;
  875. MigrationCause current_migration_cause_ = UNKNOWN_CAUSE;
  876. // True if a packet needs to be sent when packet writer is unblocked to
  877. // complete connection migration. The packet can be a cached packet if
  878. // |packet_| is set, a queued packet, or a PING packet.
  879. bool send_packet_after_migration_ = false;
  880. // True if migration is triggered, and there is no alternate network to
  881. // migrate to.
  882. bool wait_for_new_network_ = false;
  883. // True if read errors should be ignored. Set when migration on write error is
  884. // posted and unset until the first packet is written after migration.
  885. bool ignore_read_error_ = false;
  886. // If true, client headers will include HTTP/2 stream dependency info derived
  887. // from spdy::SpdyStreamPrecedence.
  888. bool headers_include_h2_stream_dependency_;
  889. Http2PriorityDependencies priority_dependency_state_;
  890. bool attempted_zero_rtt_ = false;
  891. size_t num_migrations_ = 0;
  892. // The reason for the last 1-RTT key update on the connection. Will be
  893. // kInvalid if no key updates have occurred.
  894. quic::KeyUpdateReason last_key_update_reason_ =
  895. quic::KeyUpdateReason::kInvalid;
  896. std::unique_ptr<quic::QuicClientPushPromiseIndex> push_promise_index_;
  897. QuicChromiumPathValidationWriterDelegate path_validation_writer_delegate_;
  898. // Map of origin to Accept-CH header field values received via ALPS.
  899. base::flat_map<url::SchemeHostPort, std::string>
  900. accept_ch_entries_received_via_alps_;
  901. base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_{this};
  902. };
  903. } // namespace net
  904. #endif // NET_QUIC_QUIC_CHROMIUM_CLIENT_SESSION_H_