xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/qbone/qbone_client_session.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2019 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 #ifndef QUICHE_QUIC_QBONE_QBONE_CLIENT_SESSION_H_
6 #define QUICHE_QUIC_QBONE_QBONE_CLIENT_SESSION_H_
7 
8 #include "absl/strings/string_view.h"
9 #include "quiche/quic/core/quic_crypto_client_stream.h"
10 #include "quiche/quic/platform/api/quic_export.h"
11 #include "quiche/quic/qbone/qbone_control.pb.h"
12 #include "quiche/quic/qbone/qbone_control_stream.h"
13 #include "quiche/quic/qbone/qbone_packet_writer.h"
14 #include "quiche/quic/qbone/qbone_session_base.h"
15 
16 namespace quic {
17 
18 class QUIC_EXPORT_PRIVATE QboneClientSession
19     : public QboneSessionBase,
20       public QuicCryptoClientStream::ProofHandler {
21  public:
22   QboneClientSession(QuicConnection* connection,
23                      QuicCryptoClientConfig* quic_crypto_client_config,
24                      QuicSession::Visitor* owner, const QuicConfig& config,
25                      const ParsedQuicVersionVector& supported_versions,
26                      const QuicServerId& server_id, QbonePacketWriter* writer,
27                      QboneClientControlStream::Handler* handler);
28   QboneClientSession(const QboneClientSession&) = delete;
29   QboneClientSession& operator=(const QboneClientSession&) = delete;
30   ~QboneClientSession() override;
31 
32   // QuicSession overrides. This will initiate the crypto stream.
33   void Initialize() override;
34   // Override to create control stream at FORWARD_SECURE encryption level.
35   void SetDefaultEncryptionLevel(quic::EncryptionLevel level) override;
36 
37   // Returns the number of client hello messages that have been sent on the
38   // crypto stream. If the handshake has completed then this is one greater
39   // than the number of round-trips needed for the handshake.
40   int GetNumSentClientHellos() const;
41 
42   // Returns true if early data (0-RTT data) was sent and the server accepted
43   // it.
44   bool EarlyDataAccepted() const;
45 
46   // Returns true if the handshake was delayed one round trip by the server
47   // because the server wanted proof the client controls its source address
48   // before progressing further. In Google QUIC, this would be due to an
49   // inchoate REJ in the QUIC Crypto handshake; in IETF QUIC this would be due
50   // to a Retry packet.
51   // TODO(nharper): Consider a better name for this method.
52   bool ReceivedInchoateReject() const;
53 
54   int GetNumReceivedServerConfigUpdates() const;
55 
56   bool SendServerRequest(const QboneServerRequest& request);
57 
58   void ProcessPacketFromNetwork(absl::string_view packet) override;
59   void ProcessPacketFromPeer(absl::string_view packet) override;
60 
61   // Returns true if there are active requests on this session.
62   bool HasActiveRequests() const;
63 
64  protected:
65   // QboneSessionBase interface implementation.
66   std::unique_ptr<QuicCryptoStream> CreateCryptoStream() override;
67 
68   // Instantiate QboneClientControlStream.
69   void CreateControlStream();
70 
71   // ProofHandler interface implementation.
72   void OnProofValid(const QuicCryptoClientConfig::CachedState& cached) override;
73   void OnProofVerifyDetailsAvailable(
74       const ProofVerifyDetails& verify_details) override;
75 
server_id()76   QuicServerId server_id() { return server_id_; }
crypto_client_config()77   QuicCryptoClientConfig* crypto_client_config() {
78     return quic_crypto_client_config_;
79   }
80 
81  private:
82   QuicServerId server_id_;
83   // Config for QUIC crypto client stream, used by the client.
84   QuicCryptoClientConfig* quic_crypto_client_config_;
85   // Passed to the control stream.
86   QboneClientControlStream::Handler* handler_;
87   // The unowned control stream.
88   QboneClientControlStream* control_stream_ = nullptr;
89 };
90 
91 }  // namespace quic
92 
93 #endif  // QUICHE_QUIC_QBONE_QBONE_CLIENT_SESSION_H_
94