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 server specific QuicSession subclass. |
| 6 | |
| 7 | #ifndef QUICHE_QUIC_CORE_HTTP_QUIC_SERVER_SESSION_BASE_H_ |
| 8 | #define QUICHE_QUIC_CORE_HTTP_QUIC_SERVER_SESSION_BASE_H_ |
| 9 | |
| 10 | #include <cstdint> |
| 11 | #include <memory> |
| 12 | #include <set> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 13 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/quic/core/crypto/quic_compressed_certs_cache.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_session.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/quic_crypto_server_stream.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 20 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 21 | |
| 22 | namespace quic { |
| 23 | |
| 24 | class QuicConfig; |
| 25 | class QuicConnection; |
| 26 | class QuicCryptoServerConfig; |
| 27 | |
| 28 | namespace test { |
| 29 | class QuicServerSessionBasePeer; |
| 30 | class QuicSimpleServerSessionPeer; |
| 31 | } // namespace test |
| 32 | |
| 33 | class QUIC_EXPORT_PRIVATE QuicServerSessionBase : public QuicSpdySession { |
| 34 | public: |
| 35 | // Does not take ownership of |connection|. |crypto_config| must outlive the |
| 36 | // session. |helper| must outlive any created crypto streams. |
| 37 | QuicServerSessionBase(const QuicConfig& config, |
| 38 | const ParsedQuicVersionVector& supported_versions, |
| 39 | QuicConnection* connection, |
| 40 | QuicSession::Visitor* visitor, |
| 41 | QuicCryptoServerStream::Helper* helper, |
| 42 | const QuicCryptoServerConfig* crypto_config, |
| 43 | QuicCompressedCertsCache* compressed_certs_cache); |
| 44 | QuicServerSessionBase(const QuicServerSessionBase&) = delete; |
| 45 | QuicServerSessionBase& operator=(const QuicServerSessionBase&) = delete; |
| 46 | |
| 47 | // Override the base class to cancel any ongoing asychronous crypto. |
fkastenholz | 5d880a9 | 2019-06-21 09:01:56 -0700 | [diff] [blame] | 48 | void OnConnectionClosed(const QuicConnectionCloseFrame& frame, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 49 | ConnectionCloseSource source) override; |
| 50 | |
| 51 | // Sends a server config update to the client, containing new bandwidth |
| 52 | // estimate. |
| 53 | void OnCongestionWindowChange(QuicTime now) override; |
| 54 | |
| 55 | ~QuicServerSessionBase() override; |
| 56 | |
| 57 | void Initialize() override; |
| 58 | |
| 59 | const QuicCryptoServerStreamBase* crypto_stream() const { |
| 60 | return crypto_stream_.get(); |
| 61 | } |
| 62 | |
| 63 | // Override base class to process bandwidth related config received from |
| 64 | // client. |
| 65 | void OnConfigNegotiated() override; |
| 66 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 67 | void set_serving_region(const std::string& serving_region) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 68 | serving_region_ = serving_region; |
| 69 | } |
| 70 | |
| 71 | protected: |
| 72 | // QuicSession methods(override them with return type of QuicSpdyStream*): |
| 73 | QuicCryptoServerStreamBase* GetMutableCryptoStream() override; |
| 74 | |
| 75 | const QuicCryptoServerStreamBase* GetCryptoStream() const override; |
| 76 | |
| 77 | // If an outgoing stream can be created, return true. |
| 78 | // Return false when connection is closed or forward secure encryption hasn't |
| 79 | // established yet or number of server initiated streams already reaches the |
| 80 | // upper limit. |
| 81 | bool ShouldCreateOutgoingBidirectionalStream() override; |
| 82 | bool ShouldCreateOutgoingUnidirectionalStream() override; |
| 83 | |
| 84 | // If we should create an incoming stream, returns true. Otherwise |
| 85 | // does error handling, including communicating the error to the client and |
| 86 | // possibly closing the connection, and returns false. |
| 87 | bool ShouldCreateIncomingStream(QuicStreamId id) override; |
| 88 | |
| 89 | virtual QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( |
| 90 | const QuicCryptoServerConfig* crypto_config, |
| 91 | QuicCompressedCertsCache* compressed_certs_cache) = 0; |
| 92 | |
| 93 | const QuicCryptoServerConfig* crypto_config() { return crypto_config_; } |
| 94 | |
| 95 | QuicCryptoServerStream::Helper* stream_helper() { return helper_; } |
| 96 | |
| 97 | private: |
| 98 | friend class test::QuicServerSessionBasePeer; |
| 99 | friend class test::QuicSimpleServerSessionPeer; |
| 100 | |
| 101 | const QuicCryptoServerConfig* crypto_config_; |
| 102 | |
| 103 | // The cache which contains most recently compressed certs. |
| 104 | // Owned by QuicDispatcher. |
| 105 | QuicCompressedCertsCache* compressed_certs_cache_; |
| 106 | |
| 107 | std::unique_ptr<QuicCryptoServerStreamBase> crypto_stream_; |
| 108 | |
| 109 | // Pointer to the helper used to create crypto server streams. Must outlive |
| 110 | // streams created via CreateQuicCryptoServerStream. |
| 111 | QuicCryptoServerStream::Helper* helper_; |
| 112 | |
| 113 | // Whether bandwidth resumption is enabled for this connection. |
| 114 | bool bandwidth_resumption_enabled_; |
| 115 | |
| 116 | // The most recent bandwidth estimate sent to the client. |
| 117 | QuicBandwidth bandwidth_estimate_sent_to_client_; |
| 118 | |
| 119 | // Text describing server location. Sent to the client as part of the bandwith |
| 120 | // estimate in the source-address token. Optional, can be left empty. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 121 | std::string serving_region_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 122 | |
| 123 | // Time at which we send the last SCUP to the client. |
| 124 | QuicTime last_scup_time_; |
| 125 | |
| 126 | // Number of packets sent to the peer, at the time we last sent a SCUP. |
| 127 | QuicPacketNumber last_scup_packet_number_; |
| 128 | |
| 129 | // Converts QuicBandwidth to an int32 bytes/second that can be |
| 130 | // stored in CachedNetworkParameters. TODO(jokulik): This function |
| 131 | // should go away once we fix http://b//27897982 |
| 132 | int32_t BandwidthToCachedParameterBytesPerSecond( |
| 133 | const QuicBandwidth& bandwidth); |
| 134 | }; |
| 135 | |
| 136 | } // namespace quic |
| 137 | |
| 138 | #endif // QUICHE_QUIC_CORE_HTTP_QUIC_SERVER_SESSION_BASE_H_ |