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 |
11 #include <memory> | 11 #include <memory> |
12 #include <unordered_map> | 12 #include <unordered_map> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
17 #include "net/base/linked_hash_map.h" | 17 #include "net/base/linked_hash_map.h" |
18 #include "net/quic/core/crypto/quic_compressed_certs_cache.h" | 18 #include "net/quic/core/crypto/quic_compressed_certs_cache.h" |
19 #include "net/quic/core/crypto/quic_random.h" | 19 #include "net/quic/core/crypto/quic_random.h" |
20 #include "net/quic/core/quic_blocked_writer_interface.h" | 20 #include "net/quic/core/quic_blocked_writer_interface.h" |
21 #include "net/quic/core/quic_buffered_packet_store.h" | 21 #include "net/quic/core/quic_buffered_packet_store.h" |
22 #include "net/quic/core/quic_connection.h" | 22 #include "net/quic/core/quic_connection.h" |
| 23 #include "net/quic/core/quic_crypto_server_stream.h" |
23 #include "net/quic/core/quic_protocol.h" | 24 #include "net/quic/core/quic_protocol.h" |
24 #include "net/quic/core/quic_server_session_base.h" | 25 #include "net/quic/core/quic_server_session_base.h" |
| 26 |
25 #include "net/tools/quic/quic_process_packet_interface.h" | 27 #include "net/tools/quic/quic_process_packet_interface.h" |
26 #include "net/tools/quic/quic_time_wait_list_manager.h" | 28 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 29 #include "net/tools/quic/stateless_rejector.h" |
27 | 30 |
28 namespace net { | 31 namespace net { |
29 | 32 |
30 class QuicConfig; | 33 class QuicConfig; |
31 class QuicCryptoServerConfig; | 34 class QuicCryptoServerConfig; |
32 class QuicServerSessionBase; | |
33 | 35 |
34 namespace test { | 36 namespace test { |
35 class QuicDispatcherPeer; | 37 class QuicDispatcherPeer; |
36 } // namespace test | 38 } // namespace test |
37 | 39 |
38 class QuicDispatcher : public QuicServerSessionBase::Visitor, | 40 class QuicDispatcher : public QuicServerSessionBase::Visitor, |
39 public ProcessPacketInterface, | 41 public ProcessPacketInterface, |
40 public QuicBlockedWriterInterface, | 42 public QuicBlockedWriterInterface, |
41 public QuicFramerVisitorInterface, | 43 public QuicFramerVisitorInterface, |
42 public QuicBufferedPacketStore::VisitorInterface { | 44 public QuicBufferedPacketStore::VisitorInterface { |
43 public: | 45 public: |
44 // Ideally we'd have a linked_hash_set: the boolean is unused. | 46 // Ideally we'd have a linked_hash_set: the boolean is unused. |
45 typedef linked_hash_map<QuicBlockedWriterInterface*, | 47 typedef linked_hash_map<QuicBlockedWriterInterface*, |
46 bool, | 48 bool, |
47 QuicBlockedWriterInterfacePtrHash> | 49 QuicBlockedWriterInterfacePtrHash> |
48 WriteBlockedList; | 50 WriteBlockedList; |
49 | 51 |
50 QuicDispatcher(const QuicConfig& config, | 52 QuicDispatcher(const QuicConfig& config, |
51 const QuicCryptoServerConfig* crypto_config, | 53 const QuicCryptoServerConfig* crypto_config, |
52 QuicVersionManager* version_manager, | 54 QuicVersionManager* version_manager, |
53 std::unique_ptr<QuicConnectionHelperInterface> helper, | 55 std::unique_ptr<QuicConnectionHelperInterface> helper, |
54 std::unique_ptr<QuicServerSessionBase::Helper> session_helper, | 56 std::unique_ptr<QuicCryptoServerStream::Helper> session_helper, |
55 std::unique_ptr<QuicAlarmFactory> alarm_factory); | 57 std::unique_ptr<QuicAlarmFactory> alarm_factory); |
56 | 58 |
57 ~QuicDispatcher() override; | 59 ~QuicDispatcher() override; |
58 | 60 |
59 // Takes ownership of |writer|. | 61 // Takes ownership of |writer|. |
60 void InitializeWithWriter(QuicPacketWriter* writer); | 62 void InitializeWithWriter(QuicPacketWriter* writer); |
61 | 63 |
62 // Process the incoming packet by creating a new session, passing it to | 64 // Process the incoming packet by creating a new session, passing it to |
63 // an existing session, or passing it to the time wait list. | 65 // an existing session, or passing it to the time wait list. |
64 void ProcessPacket(const IPEndPoint& server_address, | 66 void ProcessPacket(const IPEndPoint& server_address, |
(...skipping 15 matching lines...) Expand all Loading... |
80 QuicErrorCode error, | 82 QuicErrorCode error, |
81 const std::string& error_details) override; | 83 const std::string& error_details) override; |
82 | 84 |
83 // Queues the blocked writer for later resumption. | 85 // Queues the blocked writer for later resumption. |
84 void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) override; | 86 void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) override; |
85 | 87 |
86 // Called whenever the time wait list manager adds a new connection to the | 88 // Called whenever the time wait list manager adds a new connection to the |
87 // time-wait list. | 89 // time-wait list. |
88 void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override; | 90 void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override; |
89 | 91 |
| 92 void OnPacketBeingDispatchedToSession( |
| 93 QuicServerSessionBase* session) override {} |
| 94 |
90 typedef std::unordered_map<QuicConnectionId, QuicServerSessionBase*> | 95 typedef std::unordered_map<QuicConnectionId, QuicServerSessionBase*> |
91 SessionMap; | 96 SessionMap; |
92 | 97 |
93 const SessionMap& session_map() const { return session_map_; } | 98 const SessionMap& session_map() const { return session_map_; } |
94 | 99 |
95 // Deletes all sessions on the closed session list and clears the list. | 100 // Deletes all sessions on the closed session list and clears the list. |
96 virtual void DeleteSessions(); | 101 virtual void DeleteSessions(); |
97 | 102 |
98 // The largest packet number we expect to receive with a connection | 103 // The largest packet number we expect to receive with a connection |
99 // ID for a connection that is not established yet. The current design will | 104 // ID for a connection that is not established yet. The current design will |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 const QuicCryptoServerConfig* crypto_config() const { return crypto_config_; } | 220 const QuicCryptoServerConfig* crypto_config() const { return crypto_config_; } |
216 | 221 |
217 QuicCompressedCertsCache* compressed_certs_cache() { | 222 QuicCompressedCertsCache* compressed_certs_cache() { |
218 return &compressed_certs_cache_; | 223 return &compressed_certs_cache_; |
219 } | 224 } |
220 | 225 |
221 QuicFramer* framer() { return &framer_; } | 226 QuicFramer* framer() { return &framer_; } |
222 | 227 |
223 QuicConnectionHelperInterface* helper() { return helper_.get(); } | 228 QuicConnectionHelperInterface* helper() { return helper_.get(); } |
224 | 229 |
225 QuicServerSessionBase::Helper* session_helper() { | 230 QuicCryptoServerStream::Helper* session_helper() { |
226 return session_helper_.get(); | 231 return session_helper_.get(); |
227 } | 232 } |
228 | 233 |
229 QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); } | 234 QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); } |
230 | 235 |
231 QuicPacketWriter* writer() { return writer_.get(); } | 236 QuicPacketWriter* writer() { return writer_.get(); } |
232 | 237 |
233 // Creates per-connection packet writers out of the QuicDispatcher's shared | 238 // Creates per-connection packet writers out of the QuicDispatcher's shared |
234 // QuicPacketWriter. The per-connection writers' IsWriteBlocked() state must | 239 // QuicPacketWriter. The per-connection writers' IsWriteBlocked() state must |
235 // always be the same as the shared writer's IsWriteBlocked(), or else the | 240 // always be the same as the shared writer's IsWriteBlocked(), or else the |
(...skipping 20 matching lines...) Expand all Loading... |
256 | 261 |
257 bool HasBufferedPackets(QuicConnectionId connection_id); | 262 bool HasBufferedPackets(QuicConnectionId connection_id); |
258 | 263 |
259 // Called when BufferEarlyPacket() fail to buffer the packet. | 264 // Called when BufferEarlyPacket() fail to buffer the packet. |
260 virtual void OnBufferPacketFailure( | 265 virtual void OnBufferPacketFailure( |
261 QuicBufferedPacketStore::EnqueuePacketResult result, | 266 QuicBufferedPacketStore::EnqueuePacketResult result, |
262 QuicConnectionId connection_id); | 267 QuicConnectionId connection_id); |
263 | 268 |
264 private: | 269 private: |
265 friend class net::test::QuicDispatcherPeer; | 270 friend class net::test::QuicDispatcherPeer; |
| 271 friend class StatelessRejectorProcessDoneCallback; |
266 | 272 |
267 // Removes the session from the session map and write blocked list, and adds | 273 // Removes the session from the session map and write blocked list, and adds |
268 // the ConnectionId to the time-wait list. If |session_closed_statelessly| is | 274 // the ConnectionId to the time-wait list. If |session_closed_statelessly| is |
269 // true, any future packets for the ConnectionId will be black-holed. | 275 // true, any future packets for the ConnectionId will be black-holed. |
270 void CleanUpSession(SessionMap::iterator it, bool session_closed_statelessly); | 276 void CleanUpSession(SessionMap::iterator it, bool session_closed_statelessly); |
271 | 277 |
272 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); | 278 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); |
273 | 279 |
274 // Attempts to reject the connection statelessly, if stateless rejects are | 280 // Attempts to reject the connection statelessly, if stateless rejects are |
275 // possible and if the current packet contains a CHLO message. | 281 // possible and if the current packet contains a CHLO message. Determines a |
276 // Returns a fate which describes what subsequent processing should be | 282 // fate which describes what subsequent processing should be performed on the |
277 // performed on the packets, like ValidityChecks. | 283 // packets, like ValidityChecks, and invokes ProcessUnauthenticatedHeaderFate. |
278 QuicPacketFate MaybeRejectStatelessly(QuicConnectionId connection_id, | 284 void MaybeRejectStatelessly(QuicConnectionId connection_id, |
279 const QuicPacketHeader& header); | 285 const QuicPacketHeader& header); |
280 | 286 |
281 // Deliver |packets| to |session| for further processing. | 287 // Deliver |packets| to |session| for further processing. |
282 void DeliverPacketsToSession( | 288 void DeliverPacketsToSession( |
283 const std::list<QuicBufferedPacketStore::BufferedPacket>& packets, | 289 const std::list<QuicBufferedPacketStore::BufferedPacket>& packets, |
284 QuicServerSessionBase* session); | 290 QuicServerSessionBase* session); |
285 | 291 |
| 292 // Perform the appropriate actions on the current packet based on |fate| - |
| 293 // either process, buffer, or drop it. |
| 294 void ProcessUnauthenticatedHeaderFate(QuicPacketFate fate, |
| 295 QuicConnectionId connection_id, |
| 296 QuicPacketNumber packet_number); |
| 297 |
| 298 // Invoked when StatelessRejector::Process completes. |
| 299 void OnStatelessRejectorProcessDone( |
| 300 std::unique_ptr<StatelessRejector> rejector, |
| 301 QuicPacketNumber packet_number, |
| 302 QuicVersion first_version); |
| 303 |
286 void set_new_sessions_allowed_per_event_loop( | 304 void set_new_sessions_allowed_per_event_loop( |
287 int16_t new_sessions_allowed_per_event_loop) { | 305 int16_t new_sessions_allowed_per_event_loop) { |
288 new_sessions_allowed_per_event_loop_ = new_sessions_allowed_per_event_loop; | 306 new_sessions_allowed_per_event_loop_ = new_sessions_allowed_per_event_loop; |
289 } | 307 } |
290 | 308 |
291 const QuicConfig& config_; | 309 const QuicConfig& config_; |
292 | 310 |
293 const QuicCryptoServerConfig* crypto_config_; | 311 const QuicCryptoServerConfig* crypto_config_; |
294 | 312 |
295 // The cache for most recently compressed certs. | 313 // The cache for most recently compressed certs. |
296 QuicCompressedCertsCache compressed_certs_cache_; | 314 QuicCompressedCertsCache compressed_certs_cache_; |
297 | 315 |
298 // The list of connections waiting to write. | 316 // The list of connections waiting to write. |
299 WriteBlockedList write_blocked_list_; | 317 WriteBlockedList write_blocked_list_; |
300 | 318 |
301 SessionMap session_map_; | 319 SessionMap session_map_; |
302 | 320 |
303 // Entity that manages connection_ids in time wait state. | 321 // Entity that manages connection_ids in time wait state. |
304 std::unique_ptr<QuicTimeWaitListManager> time_wait_list_manager_; | 322 std::unique_ptr<QuicTimeWaitListManager> time_wait_list_manager_; |
305 | 323 |
306 // The list of closed but not-yet-deleted sessions. | 324 // The list of closed but not-yet-deleted sessions. |
307 std::vector<QuicServerSessionBase*> closed_session_list_; | 325 std::vector<QuicServerSessionBase*> closed_session_list_; |
308 | 326 |
309 // The helper used for all connections. | 327 // The helper used for all connections. |
310 std::unique_ptr<QuicConnectionHelperInterface> helper_; | 328 std::unique_ptr<QuicConnectionHelperInterface> helper_; |
311 | 329 |
312 // The helper used for all sessions. | 330 // The helper used for all sessions. |
313 std::unique_ptr<QuicServerSessionBase::Helper> session_helper_; | 331 std::unique_ptr<QuicCryptoServerStream::Helper> session_helper_; |
314 | 332 |
315 // Creates alarms. | 333 // Creates alarms. |
316 std::unique_ptr<QuicAlarmFactory> alarm_factory_; | 334 std::unique_ptr<QuicAlarmFactory> alarm_factory_; |
317 | 335 |
318 // An alarm which deletes closed sessions. | 336 // An alarm which deletes closed sessions. |
319 std::unique_ptr<QuicAlarm> delete_sessions_alarm_; | 337 std::unique_ptr<QuicAlarm> delete_sessions_alarm_; |
320 | 338 |
321 // The writer to write to the socket with. | 339 // The writer to write to the socket with. |
322 std::unique_ptr<QuicPacketWriter> writer_; | 340 std::unique_ptr<QuicPacketWriter> writer_; |
323 | 341 |
(...skipping 19 matching lines...) Expand all Loading... |
343 // A backward counter of how many new sessions can be create within current | 361 // A backward counter of how many new sessions can be create within current |
344 // event loop. When reaches 0, it means can't create sessions for now. | 362 // event loop. When reaches 0, it means can't create sessions for now. |
345 int16_t new_sessions_allowed_per_event_loop_; | 363 int16_t new_sessions_allowed_per_event_loop_; |
346 | 364 |
347 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 365 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
348 }; | 366 }; |
349 | 367 |
350 } // namespace net | 368 } // namespace net |
351 | 369 |
352 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 370 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
OLD | NEW |