blob: 3611c69bcf0358b5053cc7a2db2859b32dd73609 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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>
vasilvv872e7a32019-03-12 16:42:44 -070011#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050012
QUICHE teama6ef0a62019-03-07 20:34:33 -050013#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 teama6ef0a62019-03-07 20:34:33 -050017
18namespace quic {
19
20class QuicConnection;
21class QuicServerId;
22
23class 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
vasilvvc48c8712019-03-11 13:38:16 -070045 bool IsAuthorized(const std::string& authority) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050046
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;
renjietangbaea59c2019-05-29 15:08:14 -070069 QuicSpdyStream* CreateIncomingStream(PendingStream* pending) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050070 // 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_