OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A server specific QuicSession subclass. | 5 // A server specific QuicSession subclass. |
6 | 6 |
7 #ifndef NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | 7 #ifndef NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ |
8 #define NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | 8 #define NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 // Called after the given connection is added to the time-wait std::list. | 54 // Called after the given connection is added to the time-wait std::list. |
55 virtual void OnConnectionAddedToTimeWaitList( | 55 virtual void OnConnectionAddedToTimeWaitList( |
56 QuicConnectionId connection_id) = 0; | 56 QuicConnectionId connection_id) = 0; |
57 | 57 |
58 // Called before a packet is going to be processed by |session|. | 58 // Called before a packet is going to be processed by |session|. |
59 virtual void OnPacketBeingDispatchedToSession( | 59 virtual void OnPacketBeingDispatchedToSession( |
60 QuicServerSessionBase* session) = 0; | 60 QuicServerSessionBase* session) = 0; |
61 }; | 61 }; |
62 | 62 |
63 // Provides helper functions for the session. | |
64 class Helper { | |
65 public: | |
66 virtual ~Helper() {} | |
67 | |
68 // Given the current connection_id, generates a new ConnectionId to | |
69 // be returned with a stateless reject. | |
70 virtual QuicConnectionId GenerateConnectionIdForReject( | |
71 QuicConnectionId connection_id) const = 0; | |
72 | |
73 // Returns true if |message|, which was received on |self_address| is | |
74 // acceptable according to the visitor's policy. Otherwise, returns false | |
75 // and populates |error_details|. | |
76 virtual bool CanAcceptClientHello(const CryptoHandshakeMessage& message, | |
77 const IPEndPoint& self_address, | |
78 std::string* error_details) const = 0; | |
79 }; | |
80 | |
81 // Does not take ownership of |connection|. |crypto_config| must outlive the | 63 // Does not take ownership of |connection|. |crypto_config| must outlive the |
82 // session. | 64 // session. |helper| must outlive any created crypto streams. |
83 QuicServerSessionBase(const QuicConfig& config, | 65 QuicServerSessionBase(const QuicConfig& config, |
84 QuicConnection* connection, | 66 QuicConnection* connection, |
85 Visitor* visitor, | 67 Visitor* visitor, |
86 Helper* helper, | 68 QuicCryptoServerStream::Helper* helper, |
87 const QuicCryptoServerConfig* crypto_config, | 69 const QuicCryptoServerConfig* crypto_config, |
88 QuicCompressedCertsCache* compressed_certs_cache); | 70 QuicCompressedCertsCache* compressed_certs_cache); |
89 | 71 |
90 // Override the base class to notify the owner of the connection close. | 72 // Override the base class to notify the owner of the connection close. |
91 void OnConnectionClosed(QuicErrorCode error, | 73 void OnConnectionClosed(QuicErrorCode error, |
92 const std::string& error_details, | 74 const std::string& error_details, |
93 ConnectionCloseSource source) override; | 75 ConnectionCloseSource source) override; |
94 void OnWriteBlocked() override; | 76 void OnWriteBlocked() override; |
95 | 77 |
96 // Sends a server config update to the client, containing new bandwidth | 78 // Sends a server config update to the client, containing new bandwidth |
(...skipping 11 matching lines...) Expand all Loading... |
108 // Override base class to process bandwidth related config received from | 90 // Override base class to process bandwidth related config received from |
109 // client. | 91 // client. |
110 void OnConfigNegotiated() override; | 92 void OnConfigNegotiated() override; |
111 | 93 |
112 void set_serving_region(const std::string& serving_region) { | 94 void set_serving_region(const std::string& serving_region) { |
113 serving_region_ = serving_region; | 95 serving_region_ = serving_region; |
114 } | 96 } |
115 | 97 |
116 bool server_push_enabled() const { return server_push_enabled_; } | 98 bool server_push_enabled() const { return server_push_enabled_; } |
117 | 99 |
118 // Delegates to the helper's GenerateConnectionIdForReject method. | |
119 QuicConnectionId GenerateConnectionIdForReject( | |
120 QuicConnectionId connection_id); | |
121 | |
122 // Delegates to the helper's CanAcceptClientHello method. | |
123 bool CanAcceptClientHello(const CryptoHandshakeMessage& message, | |
124 std::string* error_details); | |
125 | |
126 protected: | 100 protected: |
127 // QuicSession methods(override them with return type of QuicSpdyStream*): | 101 // QuicSession methods(override them with return type of QuicSpdyStream*): |
128 QuicCryptoServerStreamBase* GetCryptoStream() override; | 102 QuicCryptoServerStreamBase* GetCryptoStream() override; |
129 | 103 |
130 // If an outgoing stream can be created, return true. | 104 // If an outgoing stream can be created, return true. |
131 // Return false when connection is closed or forward secure encryption hasn't | 105 // Return false when connection is closed or forward secure encryption hasn't |
132 // established yet or number of server initiated streams already reaches the | 106 // established yet or number of server initiated streams already reaches the |
133 // upper limit. | 107 // upper limit. |
134 bool ShouldCreateOutgoingDynamicStream() override; | 108 bool ShouldCreateOutgoingDynamicStream() override; |
135 | 109 |
136 // If we should create an incoming stream, returns true. Otherwise | 110 // If we should create an incoming stream, returns true. Otherwise |
137 // does error handling, including communicating the error to the client and | 111 // does error handling, including communicating the error to the client and |
138 // possibly closing the connection, and returns false. | 112 // possibly closing the connection, and returns false. |
139 bool ShouldCreateIncomingDynamicStream(QuicStreamId id) override; | 113 bool ShouldCreateIncomingDynamicStream(QuicStreamId id) override; |
140 | 114 |
141 virtual QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( | 115 virtual QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( |
142 const QuicCryptoServerConfig* crypto_config, | 116 const QuicCryptoServerConfig* crypto_config, |
143 QuicCompressedCertsCache* compressed_certs_cache) = 0; | 117 QuicCompressedCertsCache* compressed_certs_cache) = 0; |
144 | 118 |
145 const QuicCryptoServerConfig* crypto_config() { return crypto_config_; } | 119 const QuicCryptoServerConfig* crypto_config() { return crypto_config_; } |
146 | 120 |
147 void set_server_push_enabled(bool enable) { server_push_enabled_ = enable; } | 121 void set_server_push_enabled(bool enable) { server_push_enabled_ = enable; } |
148 | 122 |
149 Visitor* visitor() { return visitor_; } | 123 Visitor* visitor() { return visitor_; } |
150 | 124 |
| 125 QuicCryptoServerStream::Helper* stream_helper() { return helper_; } |
| 126 |
151 private: | 127 private: |
152 friend class test::QuicServerSessionBasePeer; | 128 friend class test::QuicServerSessionBasePeer; |
153 friend class test::QuicSimpleServerSessionPeer; | 129 friend class test::QuicSimpleServerSessionPeer; |
154 | 130 |
155 const QuicCryptoServerConfig* crypto_config_; | 131 const QuicCryptoServerConfig* crypto_config_; |
156 | 132 |
157 // The cache which contains most recently compressed certs. | 133 // The cache which contains most recently compressed certs. |
158 // Owned by QuicDispatcher. | 134 // Owned by QuicDispatcher. |
159 QuicCompressedCertsCache* compressed_certs_cache_; | 135 QuicCompressedCertsCache* compressed_certs_cache_; |
160 | 136 |
161 std::unique_ptr<QuicCryptoServerStreamBase> crypto_stream_; | 137 std::unique_ptr<QuicCryptoServerStreamBase> crypto_stream_; |
162 Visitor* visitor_; | 138 Visitor* visitor_; |
163 Helper* helper_; | 139 |
| 140 // Pointer to the helper used to create crypto server streams. Must outlive |
| 141 // streams created via CreateQuicCryptoServerStream. |
| 142 QuicCryptoServerStream::Helper* helper_; |
164 | 143 |
165 // Whether bandwidth resumption is enabled for this connection. | 144 // Whether bandwidth resumption is enabled for this connection. |
166 bool bandwidth_resumption_enabled_; | 145 bool bandwidth_resumption_enabled_; |
167 | 146 |
168 // The most recent bandwidth estimate sent to the client. | 147 // The most recent bandwidth estimate sent to the client. |
169 QuicBandwidth bandwidth_estimate_sent_to_client_; | 148 QuicBandwidth bandwidth_estimate_sent_to_client_; |
170 | 149 |
171 // Text describing server location. Sent to the client as part of the bandwith | 150 // Text describing server location. Sent to the client as part of the bandwith |
172 // estimate in the source-address token. Optional, can be left empty. | 151 // estimate in the source-address token. Optional, can be left empty. |
173 std::string serving_region_; | 152 std::string serving_region_; |
(...skipping 13 matching lines...) Expand all Loading... |
187 // Set during handshake. If true, resources in x-associated-content and link | 166 // Set during handshake. If true, resources in x-associated-content and link |
188 // headers will be pushed. see: go/gfe_server_push. | 167 // headers will be pushed. see: go/gfe_server_push. |
189 bool server_push_enabled_; | 168 bool server_push_enabled_; |
190 | 169 |
191 DISALLOW_COPY_AND_ASSIGN(QuicServerSessionBase); | 170 DISALLOW_COPY_AND_ASSIGN(QuicServerSessionBase); |
192 }; | 171 }; |
193 | 172 |
194 } // namespace net | 173 } // namespace net |
195 | 174 |
196 #endif // NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | 175 #endif // NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ |
OLD | NEW |