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