xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/http/quic_spdy_client_session.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 QuicSession subclass.
6 
7 #ifndef QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_CLIENT_SESSION_H_
8 #define QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_CLIENT_SESSION_H_
9 
10 #include <memory>
11 #include <string>
12 
13 #include "quiche/quic/core/http/quic_spdy_client_session_base.h"
14 #include "quiche/quic/core/http/quic_spdy_client_stream.h"
15 #include "quiche/quic/core/quic_crypto_client_stream.h"
16 #include "quiche/quic/core/quic_packets.h"
17 
18 namespace quic {
19 
20 class QuicConnection;
21 class QuicServerId;
22 
23 class QUICHE_EXPORT QuicSpdyClientSession : public QuicSpdyClientSessionBase {
24  public:
25   // Takes ownership of |connection|.
26   QuicSpdyClientSession(const QuicConfig& config,
27                         const ParsedQuicVersionVector& supported_versions,
28                         QuicConnection* connection,
29                         const QuicServerId& server_id,
30                         QuicCryptoClientConfig* crypto_config);
31 
32   QuicSpdyClientSession(const QuicConfig& config,
33                         const ParsedQuicVersionVector& supported_versions,
34                         QuicConnection* connection,
35                         QuicSession::Visitor* visitor,
36                         const QuicServerId& server_id,
37                         QuicCryptoClientConfig* crypto_config);
38 
39   QuicSpdyClientSession(const QuicSpdyClientSession&) = delete;
40   QuicSpdyClientSession& operator=(const QuicSpdyClientSession&) = delete;
41   ~QuicSpdyClientSession() override;
42   // Set up the QuicSpdyClientSession. Must be called prior to use.
43   void Initialize() override;
44 
45   // QuicSession methods:
46   QuicSpdyClientStream* CreateOutgoingBidirectionalStream() override;
47   QuicSpdyClientStream* CreateOutgoingUnidirectionalStream() override;
48   QuicCryptoClientStreamBase* GetMutableCryptoStream() override;
49   const QuicCryptoClientStreamBase* GetCryptoStream() const override;
50 
51   // QuicSpdyClientSessionBase methods:
52   void OnProofValid(const QuicCryptoClientConfig::CachedState& cached) override;
53   void OnProofVerifyDetailsAvailable(
54       const ProofVerifyDetails& verify_details) override;
55 
56   // Performs a crypto handshake with the server.
57   virtual void CryptoConnect();
58 
59   // Returns the number of client hello messages that have been sent on the
60   // crypto stream. If the handshake has completed then this is one greater
61   // than the number of round-trips needed for the handshake.
62   int GetNumSentClientHellos() const;
63 
64   // Return true if the client attempted a TLS resumption.
65   // Always return false for QUIC Crypto.
66   bool ResumptionAttempted() const;
67 
68   // Return true if the handshake performed is a TLS resumption.
69   // Always return false for QUIC Crypto.
70   bool IsResumption() const;
71 
72   // Returns true if early data (0-RTT data) was sent and the server accepted
73   // it.
74   bool EarlyDataAccepted() const;
75 
76   // Returns true if the handshake was delayed one round trip by the server
77   // because the server wanted proof the client controls its source address
78   // before progressing further. In Google QUIC, this would be due to an
79   // inchoate REJ in the QUIC Crypto handshake; in IETF QUIC this would be due
80   // to a Retry packet.
81   // TODO(nharper): Consider a better name for this method.
82   bool ReceivedInchoateReject() const;
83 
84   int GetNumReceivedServerConfigUpdates() const;
85 
86   using QuicSession::CanOpenNextOutgoingBidirectionalStream;
87 
set_respect_goaway(bool respect_goaway)88   void set_respect_goaway(bool respect_goaway) {
89     respect_goaway_ = respect_goaway;
90   }
91 
92  protected:
93   // QuicSession methods:
94   QuicSpdyStream* CreateIncomingStream(QuicStreamId id) override;
95   QuicSpdyStream* CreateIncomingStream(PendingStream* pending) override;
96   // If an outgoing stream can be created, return true.
97   bool ShouldCreateOutgoingBidirectionalStream() override;
98   bool ShouldCreateOutgoingUnidirectionalStream() override;
99 
100   // If an incoming stream can be created, return true.
101   // TODO(fayang): move this up to QuicSpdyClientSessionBase.
102   bool ShouldCreateIncomingStream(QuicStreamId id) override;
103 
104   // Create the crypto stream. Called by Initialize().
105   virtual std::unique_ptr<QuicCryptoClientStreamBase> CreateQuicCryptoStream();
106 
107   // Unlike CreateOutgoingBidirectionalStream, which applies a bunch of
108   // sanity checks, this simply returns a new QuicSpdyClientStream. This may be
109   // used by subclasses which want to use a subclass of QuicSpdyClientStream for
110   // streams but wish to use the sanity checks in
111   // CreateOutgoingBidirectionalStream.
112   virtual std::unique_ptr<QuicSpdyClientStream> CreateClientStream();
113 
server_id()114   const QuicServerId& server_id() const { return server_id_; }
crypto_config()115   QuicCryptoClientConfig* crypto_config() { return crypto_config_; }
116 
117  private:
118   std::unique_ptr<QuicCryptoClientStreamBase> crypto_stream_;
119   QuicServerId server_id_;
120   QuicCryptoClientConfig* crypto_config_;
121 
122   // If this is set to false, the client will ignore server GOAWAYs and allow
123   // the creation of streams regardless of the high chance they will fail.
124   bool respect_goaway_;
125 };
126 
127 }  // namespace quic
128 
129 #endif  // QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_CLIENT_SESSION_H_
130