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 side dispatcher which dispatches a given client's data to their | 5 // A server side dispatcher which dispatches a given client's data to their |
6 // stream. | 6 // stream. |
7 | 7 |
8 #ifndef NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
9 #define NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 9 #define NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 bool OnPaddingFrame(const QuicPaddingFrame& frame) override; | 134 bool OnPaddingFrame(const QuicPaddingFrame& frame) override; |
135 bool OnPingFrame(const QuicPingFrame& frame) override; | 135 bool OnPingFrame(const QuicPingFrame& frame) override; |
136 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; | 136 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; |
137 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; | 137 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; |
138 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; | 138 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
139 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; | 139 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
140 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; | 140 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
141 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override; | 141 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override; |
142 void OnPacketComplete() override; | 142 void OnPacketComplete() override; |
143 | 143 |
144 // QuicBufferedPacketStore::VisitorInterface | 144 // QuicBufferedPacketStore::VisitorInterface implementation. |
145 void OnExpiredPackets(QuicConnectionId connection_id, | 145 void OnExpiredPackets(QuicConnectionId connection_id, |
146 QuicBufferedPacketStore::BufferedPacketList | 146 QuicBufferedPacketStore::BufferedPacketList |
147 early_arrived_packets) override; | 147 early_arrived_packets) override; |
148 | 148 |
149 protected: | 149 protected: |
150 virtual QuicServerSessionBase* CreateQuicSession( | 150 virtual QuicServerSessionBase* CreateQuicSession( |
151 QuicConnectionId connection_id, | 151 QuicConnectionId connection_id, |
152 const IPEndPoint& client_address) = 0; | 152 const IPEndPoint& client_address) = 0; |
153 | 153 |
154 // Called when a connection is rejected statelessly. | 154 // Called when a connection is rejected statelessly. |
155 virtual void OnConnectionRejectedStatelessly(); | 155 virtual void OnConnectionRejectedStatelessly(); |
156 | 156 |
157 // Called when a connection is closed statelessly. | 157 // Called when a connection is closed statelessly. |
158 virtual void OnConnectionClosedStatelessly(QuicErrorCode error); | 158 virtual void OnConnectionClosedStatelessly(QuicErrorCode error); |
159 | 159 |
160 // Returns true if cheap stateless rejection should be attempted. | 160 // Returns true if cheap stateless rejection should be attempted. |
161 virtual bool ShouldAttemptCheapStatelessRejection(); | 161 virtual bool ShouldAttemptCheapStatelessRejection(); |
162 | 162 |
163 // Values to be returned by ValidityChecks() to indicate what should be done | 163 // Values to be returned by ValidityChecks() to indicate what should be done |
164 // with a packet. Fates with greater values are considered to be higher | 164 // with a packet. Fates with greater values are considered to be higher |
165 // priority, in that if one validity check indicates a lower-valued fate and | 165 // priority, in that if one validity check indicates a lower-valued fate and |
166 // another validity check indicates a higher-valued fate, the higher-valued | 166 // another validity check indicates a higher-valued fate, the higher-valued |
167 // fate should be obeyed. | 167 // fate should be obeyed. |
168 enum QuicPacketFate { | 168 enum QuicPacketFate { |
169 // Process the packet normally, which is usually to establish a connection. | 169 // Process the packet normally, which is usually to establish a connection. |
170 kFateProcess, | 170 kFateProcess, |
171 // Put the connection ID into time-wait state and send a public reset. | 171 // Put the connection ID into time-wait state and send a public reset. |
172 kFateTimeWait, | 172 kFateTimeWait, |
| 173 // Buffer the packet. |
| 174 kFateBuffer, |
173 // Drop the packet (ignore and give no response). | 175 // Drop the packet (ignore and give no response). |
174 kFateDrop, | 176 kFateDrop, |
175 }; | 177 }; |
176 | 178 |
177 // This method is called by OnUnauthenticatedHeader on packets not associated | 179 // This method is called by OnUnauthenticatedHeader on packets not associated |
178 // with a known connection ID. It applies validity checks and returns a | 180 // with a known connection ID. It applies validity checks and returns a |
179 // QuicPacketFate to tell what should be done with the packet. | 181 // QuicPacketFate to tell what should be done with the packet. |
180 virtual QuicPacketFate ValidityChecks(const QuicPacketHeader& header); | 182 virtual QuicPacketFate ValidityChecks(const QuicPacketHeader& header); |
181 | 183 |
182 // Create and return the time wait list manager for this dispatcher, which | 184 // Create and return the time wait list manager for this dispatcher, which |
183 // will be owned by the dispatcher as time_wait_list_manager_ | 185 // will be owned by the dispatcher as time_wait_list_manager_ |
184 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); | 186 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); |
185 | 187 |
| 188 // Called when |current_packet_| is a data packet that has arrived before |
| 189 // the CHLO. Buffers the current packet until the CHLO arrives. |
| 190 void BufferEarlyPacket(QuicConnectionId connection_id); |
| 191 |
| 192 // Called when |current_packet_| is a CHLO packet. Creates a new connection |
| 193 // and delivers any buffered packets for that connection id. |
| 194 void ProcessChlo(); |
| 195 |
186 QuicTimeWaitListManager* time_wait_list_manager() { | 196 QuicTimeWaitListManager* time_wait_list_manager() { |
187 return time_wait_list_manager_.get(); | 197 return time_wait_list_manager_.get(); |
188 } | 198 } |
189 | 199 |
190 const QuicVersionVector& GetSupportedVersions(); | 200 const QuicVersionVector& GetSupportedVersions(); |
191 | 201 |
192 QuicConnectionId current_connection_id() { return current_connection_id_; } | 202 QuicConnectionId current_connection_id() { return current_connection_id_; } |
193 const IPEndPoint& current_server_address() { return current_server_address_; } | 203 const IPEndPoint& current_server_address() { return current_server_address_; } |
194 const IPEndPoint& current_client_address() { return current_client_address_; } | 204 const IPEndPoint& current_client_address() { return current_client_address_; } |
195 const QuicReceivedPacket& current_packet() { return *current_packet_; } | 205 const QuicReceivedPacket& current_packet() { return *current_packet_; } |
(...skipping 30 matching lines...) Expand all Loading... |
226 virtual bool ShouldCreateSessionForUnknownVersion(QuicTag version_tag); | 236 virtual bool ShouldCreateSessionForUnknownVersion(QuicTag version_tag); |
227 | 237 |
228 void SetLastError(QuicErrorCode error); | 238 void SetLastError(QuicErrorCode error); |
229 | 239 |
230 // Called when the public header has been parsed and the session has been | 240 // Called when the public header has been parsed and the session has been |
231 // looked up, and the session was not found in the active list of sessions. | 241 // looked up, and the session was not found in the active list of sessions. |
232 // Returns false if processing should stop after this call. | 242 // Returns false if processing should stop after this call. |
233 virtual bool OnUnauthenticatedUnknownPublicHeader( | 243 virtual bool OnUnauthenticatedUnknownPublicHeader( |
234 const QuicPacketPublicHeader& header); | 244 const QuicPacketPublicHeader& header); |
235 | 245 |
| 246 // Called when a new connection starts to be handled by this dispatcher. |
| 247 // Either this connection is created or its packets is buffered while waiting |
| 248 // for CHLO. |
| 249 virtual void OnNewConnectionAdded(QuicConnectionId connection_id); |
| 250 |
| 251 bool HasBufferedPackets(QuicConnectionId connection_id); |
| 252 |
| 253 // Called when BufferEarlyPacket() fail to buffer the packet. |
| 254 virtual void OnBufferPacketFailure( |
| 255 QuicBufferedPacketStore::EnqueuePacketResult result, |
| 256 QuicConnectionId connection_id); |
| 257 |
236 private: | 258 private: |
237 friend class net::test::QuicDispatcherPeer; | 259 friend class net::test::QuicDispatcherPeer; |
238 | 260 |
239 // Removes the session from the session map and write blocked list, and adds | 261 // Removes the session from the session map and write blocked list, and adds |
240 // the ConnectionId to the time-wait list. If |session_closed_statelessly| is | 262 // the ConnectionId to the time-wait list. If |session_closed_statelessly| is |
241 // true, any future packets for the ConnectionId will be black-holed. | 263 // true, any future packets for the ConnectionId will be black-holed. |
242 void CleanUpSession(SessionMap::iterator it, bool session_closed_statelessly); | 264 void CleanUpSession(SessionMap::iterator it, bool session_closed_statelessly); |
243 | 265 |
244 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); | 266 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); |
245 | 267 |
(...skipping 30 matching lines...) Expand all Loading... |
276 | 298 |
277 // Creates alarms. | 299 // Creates alarms. |
278 std::unique_ptr<QuicAlarmFactory> alarm_factory_; | 300 std::unique_ptr<QuicAlarmFactory> alarm_factory_; |
279 | 301 |
280 // An alarm which deletes closed sessions. | 302 // An alarm which deletes closed sessions. |
281 std::unique_ptr<QuicAlarm> delete_sessions_alarm_; | 303 std::unique_ptr<QuicAlarm> delete_sessions_alarm_; |
282 | 304 |
283 // The writer to write to the socket with. | 305 // The writer to write to the socket with. |
284 std::unique_ptr<QuicPacketWriter> writer_; | 306 std::unique_ptr<QuicPacketWriter> writer_; |
285 | 307 |
286 // Undecryptable packets which are buffered until a connection can be | 308 // Packets which are buffered until a connection can be created to handle |
287 // created to handle them. | 309 // them. |
288 QuicBufferedPacketStore buffered_packets_; | 310 QuicBufferedPacketStore buffered_packets_; |
289 | 311 |
290 // Information about the packet currently being handled. | 312 // Information about the packet currently being handled. |
291 IPEndPoint current_client_address_; | 313 IPEndPoint current_client_address_; |
292 IPEndPoint current_server_address_; | 314 IPEndPoint current_server_address_; |
293 const QuicReceivedPacket* current_packet_; | 315 const QuicReceivedPacket* current_packet_; |
294 QuicConnectionId current_connection_id_; | 316 QuicConnectionId current_connection_id_; |
295 | 317 |
296 // Used to get the supported versions based on flag. Does not own. | 318 // Used to get the supported versions based on flag. Does not own. |
297 QuicVersionManager* version_manager_; | 319 QuicVersionManager* version_manager_; |
298 | 320 |
299 QuicFramer framer_; | 321 QuicFramer framer_; |
300 | 322 |
301 // The last error set by SetLastError(), which is called by | 323 // The last error set by SetLastError(), which is called by |
302 // framer_visitor_->OnError(). | 324 // framer_visitor_->OnError(). |
303 QuicErrorCode last_error_; | 325 QuicErrorCode last_error_; |
304 | 326 |
305 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 327 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
306 }; | 328 }; |
307 | 329 |
308 } // namespace net | 330 } // namespace net |
309 | 331 |
310 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 332 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
OLD | NEW |