QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 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> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 11 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | |
| 13 | #include "base/macros.h" |
| 14 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_client_session_base.h" |
| 15 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_client_stream.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/quic_crypto_client_stream.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 18 | |
| 19 | namespace quic { |
| 20 | |
| 21 | class QuicConnection; |
| 22 | class QuicServerId; |
| 23 | |
| 24 | class QuicSpdyClientSession : public QuicSpdyClientSessionBase { |
| 25 | public: |
| 26 | // Takes ownership of |connection|. Caller retains ownership of |
| 27 | // |promised_by_url|. |
| 28 | QuicSpdyClientSession(const QuicConfig& config, |
| 29 | const ParsedQuicVersionVector& supported_versions, |
| 30 | QuicConnection* connection, |
| 31 | const QuicServerId& server_id, |
| 32 | QuicCryptoClientConfig* crypto_config, |
| 33 | QuicClientPushPromiseIndex* push_promise_index); |
| 34 | QuicSpdyClientSession(const QuicSpdyClientSession&) = delete; |
| 35 | QuicSpdyClientSession& operator=(const QuicSpdyClientSession&) = delete; |
| 36 | ~QuicSpdyClientSession() override; |
| 37 | // Set up the QuicSpdyClientSession. Must be called prior to use. |
| 38 | void Initialize() override; |
| 39 | |
| 40 | // QuicSession methods: |
| 41 | QuicSpdyClientStream* CreateOutgoingBidirectionalStream() override; |
| 42 | QuicSpdyClientStream* CreateOutgoingUnidirectionalStream() override; |
| 43 | QuicCryptoClientStreamBase* GetMutableCryptoStream() override; |
| 44 | const QuicCryptoClientStreamBase* GetCryptoStream() const override; |
| 45 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 46 | bool IsAuthorized(const std::string& authority) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 47 | |
| 48 | // QuicSpdyClientSessionBase methods: |
| 49 | void OnProofValid(const QuicCryptoClientConfig::CachedState& cached) override; |
| 50 | void OnProofVerifyDetailsAvailable( |
| 51 | const ProofVerifyDetails& verify_details) override; |
| 52 | |
| 53 | // Performs a crypto handshake with the server. |
| 54 | virtual void CryptoConnect(); |
| 55 | |
| 56 | // Returns the number of client hello messages that have been sent on the |
| 57 | // crypto stream. If the handshake has completed then this is one greater |
| 58 | // than the number of round-trips needed for the handshake. |
| 59 | int GetNumSentClientHellos() const; |
| 60 | |
| 61 | int GetNumReceivedServerConfigUpdates() const; |
| 62 | |
| 63 | void set_respect_goaway(bool respect_goaway) { |
| 64 | respect_goaway_ = respect_goaway; |
| 65 | } |
| 66 | |
| 67 | protected: |
| 68 | // QuicSession methods: |
| 69 | QuicSpdyStream* CreateIncomingStream(QuicStreamId id) override; |
| 70 | QuicSpdyStream* CreateIncomingStream(PendingStream pending) override; |
| 71 | // If an outgoing stream can be created, return true. |
| 72 | bool ShouldCreateOutgoingBidirectionalStream() override; |
| 73 | bool ShouldCreateOutgoingUnidirectionalStream() override; |
| 74 | |
| 75 | // If an incoming stream can be created, return true. |
| 76 | // TODO(fayang): move this up to QuicSpdyClientSessionBase. |
| 77 | bool ShouldCreateIncomingStream(QuicStreamId id) override; |
| 78 | |
| 79 | // Create the crypto stream. Called by Initialize(). |
| 80 | virtual std::unique_ptr<QuicCryptoClientStreamBase> CreateQuicCryptoStream(); |
| 81 | |
| 82 | // Unlike CreateOutgoingBidirectionalStream, which applies a bunch of |
| 83 | // sanity checks, this simply returns a new QuicSpdyClientStream. This may be |
| 84 | // used by subclasses which want to use a subclass of QuicSpdyClientStream for |
| 85 | // streams but wish to use the sanity checks in |
| 86 | // CreateOutgoingBidirectionalStream. |
| 87 | virtual std::unique_ptr<QuicSpdyClientStream> CreateClientStream(); |
| 88 | |
| 89 | const QuicServerId& server_id() { return server_id_; } |
| 90 | QuicCryptoClientConfig* crypto_config() { return crypto_config_; } |
| 91 | |
| 92 | private: |
| 93 | std::unique_ptr<QuicCryptoClientStreamBase> crypto_stream_; |
| 94 | QuicServerId server_id_; |
| 95 | QuicCryptoClientConfig* crypto_config_; |
| 96 | |
| 97 | // If this is set to false, the client will ignore server GOAWAYs and allow |
| 98 | // the creation of streams regardless of the high chance they will fail. |
| 99 | bool respect_goaway_; |
| 100 | }; |
| 101 | |
| 102 | } // namespace quic |
| 103 | |
| 104 | #endif // QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_CLIENT_SESSION_H_ |