| OLD | NEW |
| (Empty) |
| 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 NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | |
| 8 #define NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | |
| 9 | |
| 10 #include <stdint.h> | |
| 11 | |
| 12 #include <cstdint> | |
| 13 #include <memory> | |
| 14 #include <set> | |
| 15 #include <string> | |
| 16 #include <vector> | |
| 17 | |
| 18 #include "base/macros.h" | |
| 19 #include "net/quic/crypto/quic_compressed_certs_cache.h" | |
| 20 #include "net/quic/quic_crypto_server_stream.h" | |
| 21 #include "net/quic/quic_protocol.h" | |
| 22 #include "net/quic/quic_spdy_session.h" | |
| 23 | |
| 24 namespace net { | |
| 25 | |
| 26 class QuicBlockedWriterInterface; | |
| 27 class QuicConfig; | |
| 28 class QuicConnection; | |
| 29 class QuicCryptoServerConfig; | |
| 30 class ReliableQuicStream; | |
| 31 | |
| 32 namespace test { | |
| 33 class QuicServerSessionBasePeer; | |
| 34 class QuicSimpleServerSessionPeer; | |
| 35 } // namespace test | |
| 36 | |
| 37 class NET_EXPORT_PRIVATE QuicServerSessionBase : public QuicSpdySession { | |
| 38 public: | |
| 39 // An interface from the session to the entity owning the session. | |
| 40 // This lets the session notify its owner (the Dispatcher) when the connection | |
| 41 // is closed, blocked, or added/removed from the time-wait std::list. | |
| 42 class Visitor { | |
| 43 public: | |
| 44 virtual ~Visitor() {} | |
| 45 | |
| 46 // Called when the connection is closed. | |
| 47 virtual void OnConnectionClosed(QuicConnectionId connection_id, | |
| 48 QuicErrorCode error, | |
| 49 const std::string& error_details) = 0; | |
| 50 | |
| 51 // Called when the session has become write blocked. | |
| 52 virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0; | |
| 53 | |
| 54 // Called after the given connection is added to the time-wait std::list. | |
| 55 virtual void OnConnectionAddedToTimeWaitList( | |
| 56 QuicConnectionId connection_id) = 0; | |
| 57 }; | |
| 58 | |
| 59 // Provides helper functions for the session. | |
| 60 class Helper { | |
| 61 public: | |
| 62 virtual ~Helper() {} | |
| 63 | |
| 64 // Given the current connection_id, generates a new ConnectionId to | |
| 65 // be returned with a stateless reject. | |
| 66 virtual QuicConnectionId GenerateConnectionIdForReject( | |
| 67 QuicConnectionId connection_id) const = 0; | |
| 68 | |
| 69 // Returns true if |message|, which was received on |self_address| is | |
| 70 // acceptable according to the visitor's policy. Otherwise, returns false | |
| 71 // and populates |error_details|. | |
| 72 virtual bool CanAcceptClientHello(const CryptoHandshakeMessage& message, | |
| 73 const IPEndPoint& self_address, | |
| 74 std::string* error_details) const = 0; | |
| 75 }; | |
| 76 | |
| 77 // |crypto_config| must outlive the session. | |
| 78 QuicServerSessionBase(const QuicConfig& config, | |
| 79 QuicConnection* connection, | |
| 80 Visitor* visitor, | |
| 81 Helper* helper, | |
| 82 const QuicCryptoServerConfig* crypto_config, | |
| 83 QuicCompressedCertsCache* compressed_certs_cache); | |
| 84 | |
| 85 // Override the base class to notify the owner of the connection close. | |
| 86 void OnConnectionClosed(QuicErrorCode error, | |
| 87 const std::string& error_details, | |
| 88 ConnectionCloseSource source) override; | |
| 89 void OnWriteBlocked() override; | |
| 90 | |
| 91 // Sends a server config update to the client, containing new bandwidth | |
| 92 // estimate. | |
| 93 void OnCongestionWindowChange(QuicTime now) override; | |
| 94 | |
| 95 ~QuicServerSessionBase() override; | |
| 96 | |
| 97 void Initialize() override; | |
| 98 | |
| 99 const QuicCryptoServerStreamBase* crypto_stream() const { | |
| 100 return crypto_stream_.get(); | |
| 101 } | |
| 102 | |
| 103 // Override base class to process bandwidth related config received from | |
| 104 // client. | |
| 105 void OnConfigNegotiated() override; | |
| 106 | |
| 107 void set_serving_region(const std::string& serving_region) { | |
| 108 serving_region_ = serving_region; | |
| 109 } | |
| 110 | |
| 111 bool server_push_enabled() const { return server_push_enabled_; } | |
| 112 | |
| 113 // Delegates to the helper's GenerateConnectionIdForReject method. | |
| 114 QuicConnectionId GenerateConnectionIdForReject( | |
| 115 QuicConnectionId connection_id); | |
| 116 | |
| 117 // Delegates to the helper's CanAcceptClientHello method. | |
| 118 bool CanAcceptClientHello(const CryptoHandshakeMessage& message, | |
| 119 std::string* error_details); | |
| 120 | |
| 121 protected: | |
| 122 // QuicSession methods(override them with return type of QuicSpdyStream*): | |
| 123 QuicCryptoServerStreamBase* GetCryptoStream() override; | |
| 124 | |
| 125 // If an outgoing stream can be created, return true. | |
| 126 // Return false when connection is closed or forward secure encryption hasn't | |
| 127 // established yet or number of server initiated streams already reaches the | |
| 128 // upper limit. | |
| 129 bool ShouldCreateOutgoingDynamicStream() override; | |
| 130 | |
| 131 // If we should create an incoming stream, returns true. Otherwise | |
| 132 // does error handling, including communicating the error to the client and | |
| 133 // possibly closing the connection, and returns false. | |
| 134 bool ShouldCreateIncomingDynamicStream(QuicStreamId id) override; | |
| 135 | |
| 136 virtual QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( | |
| 137 const QuicCryptoServerConfig* crypto_config, | |
| 138 QuicCompressedCertsCache* compressed_certs_cache) = 0; | |
| 139 | |
| 140 const QuicCryptoServerConfig* crypto_config() { return crypto_config_; } | |
| 141 | |
| 142 void set_server_push_enabled(bool enable) { server_push_enabled_ = enable; } | |
| 143 | |
| 144 private: | |
| 145 friend class test::QuicServerSessionBasePeer; | |
| 146 friend class test::QuicSimpleServerSessionPeer; | |
| 147 | |
| 148 const QuicCryptoServerConfig* crypto_config_; | |
| 149 | |
| 150 // The cache which contains most recently compressed certs. | |
| 151 // Owned by QuicDispatcher. | |
| 152 QuicCompressedCertsCache* compressed_certs_cache_; | |
| 153 | |
| 154 std::unique_ptr<QuicCryptoServerStreamBase> crypto_stream_; | |
| 155 Visitor* visitor_; | |
| 156 Helper* helper_; | |
| 157 | |
| 158 // Whether bandwidth resumption is enabled for this connection. | |
| 159 bool bandwidth_resumption_enabled_; | |
| 160 | |
| 161 // The most recent bandwidth estimate sent to the client. | |
| 162 QuicBandwidth bandwidth_estimate_sent_to_client_; | |
| 163 | |
| 164 // Text describing server location. Sent to the client as part of the bandwith | |
| 165 // estimate in the source-address token. Optional, can be left empty. | |
| 166 std::string serving_region_; | |
| 167 | |
| 168 // Time at which we send the last SCUP to the client. | |
| 169 QuicTime last_scup_time_; | |
| 170 | |
| 171 // Number of packets sent to the peer, at the time we last sent a SCUP. | |
| 172 int64_t last_scup_packet_number_; | |
| 173 | |
| 174 // Converts QuicBandwidth to an int32 bytes/second that can be | |
| 175 // stored in CachedNetworkParameters. TODO(jokulik): This function | |
| 176 // should go away once we fix http://b//27897982 | |
| 177 int32_t BandwidthToCachedParameterBytesPerSecond( | |
| 178 const QuicBandwidth& bandwidth); | |
| 179 | |
| 180 // Set during handshake. If true, resources in x-associated-content and link | |
| 181 // headers will be pushed. see: go/gfe_server_push. | |
| 182 bool server_push_enabled_; | |
| 183 | |
| 184 DISALLOW_COPY_AND_ASSIGN(QuicServerSessionBase); | |
| 185 }; | |
| 186 | |
| 187 } // namespace net | |
| 188 | |
| 189 #endif // NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | |
| OLD | NEW |