| 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_crypto_server_stream.h" |
| 24 #include "net/quic/core/quic_protocol.h" | 24 #include "net/quic/core/quic_protocol.h" |
| 25 #include "net/quic/core/quic_server_session_base.h" | 25 #include "net/quic/core/quic_session.h" |
| 26 | 26 |
| 27 #include "net/tools/quic/quic_process_packet_interface.h" | 27 #include "net/tools/quic/quic_process_packet_interface.h" |
| 28 #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" | 29 #include "net/tools/quic/stateless_rejector.h" |
| 30 | 30 |
| 31 namespace net { | 31 namespace net { |
| 32 | 32 |
| 33 class QuicConfig; | 33 class QuicConfig; |
| 34 class QuicCryptoServerConfig; | 34 class QuicCryptoServerConfig; |
| 35 | 35 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 QuicErrorCode error, | 82 QuicErrorCode error, |
| 83 const std::string& error_details) override; | 83 const std::string& error_details) override; |
| 84 | 84 |
| 85 // Queues the blocked writer for later resumption. | 85 // Queues the blocked writer for later resumption. |
| 86 void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) override; | 86 void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) override; |
| 87 | 87 |
| 88 // 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 |
| 89 // time-wait list. | 89 // time-wait list. |
| 90 void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override; | 90 void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override; |
| 91 | 91 |
| 92 void OnPacketBeingDispatchedToSession( | 92 void OnPacketBeingDispatchedToSession(QuicSession* session) override {} |
| 93 QuicServerSessionBase* session) override {} | |
| 94 | 93 |
| 95 using SessionMap = std::unordered_map<QuicConnectionId, | 94 using SessionMap = |
| 96 std::unique_ptr<QuicServerSessionBase>>; | 95 std::unordered_map<QuicConnectionId, std::unique_ptr<QuicSession>>; |
| 97 | 96 |
| 98 const SessionMap& session_map() const { return session_map_; } | 97 const SessionMap& session_map() const { return session_map_; } |
| 99 | 98 |
| 100 // Deletes all sessions on the closed session list and clears the list. | 99 // Deletes all sessions on the closed session list and clears the list. |
| 101 virtual void DeleteSessions(); | 100 virtual void DeleteSessions(); |
| 102 | 101 |
| 103 // The largest packet number we expect to receive with a connection | 102 // The largest packet number we expect to receive with a connection |
| 104 // ID for a connection that is not established yet. The current design will | 103 // ID for a connection that is not established yet. The current design will |
| 105 // send a handshake and then up to 50 or so data packets, and then it may | 104 // send a handshake and then up to 50 or so data packets, and then it may |
| 106 // resend the handshake packet up to 10 times. (Retransmitted packets are | 105 // resend the handshake packet up to 10 times. (Retransmitted packets are |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 QuicBufferedPacketStore::BufferedPacketList | 150 QuicBufferedPacketStore::BufferedPacketList |
| 152 early_arrived_packets) override; | 151 early_arrived_packets) override; |
| 153 | 152 |
| 154 // Create connections for previously buffered CHLOs as many as allowed. | 153 // Create connections for previously buffered CHLOs as many as allowed. |
| 155 virtual void ProcessBufferedChlos(size_t max_connections_to_create); | 154 virtual void ProcessBufferedChlos(size_t max_connections_to_create); |
| 156 | 155 |
| 157 // Return true if there is CHLO buffered. | 156 // Return true if there is CHLO buffered. |
| 158 virtual bool HasChlosBuffered() const; | 157 virtual bool HasChlosBuffered() const; |
| 159 | 158 |
| 160 protected: | 159 protected: |
| 161 virtual QuicServerSessionBase* CreateQuicSession( | 160 virtual QuicSession* CreateQuicSession(QuicConnectionId connection_id, |
| 162 QuicConnectionId connection_id, | 161 const IPEndPoint& client_address) = 0; |
| 163 const IPEndPoint& client_address) = 0; | |
| 164 | 162 |
| 165 // Called when a connection is rejected statelessly. | 163 // Called when a connection is rejected statelessly. |
| 166 virtual void OnConnectionRejectedStatelessly(); | 164 virtual void OnConnectionRejectedStatelessly(); |
| 167 | 165 |
| 168 // Called when a connection is closed statelessly. | 166 // Called when a connection is closed statelessly. |
| 169 virtual void OnConnectionClosedStatelessly(QuicErrorCode error); | 167 virtual void OnConnectionClosedStatelessly(QuicErrorCode error); |
| 170 | 168 |
| 171 // Returns true if cheap stateless rejection should be attempted. | 169 // Returns true if cheap stateless rejection should be attempted. |
| 172 virtual bool ShouldAttemptCheapStatelessRejection(); | 170 virtual bool ShouldAttemptCheapStatelessRejection(); |
| 173 | 171 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // Attempts to reject the connection statelessly, if stateless rejects are | 284 // Attempts to reject the connection statelessly, if stateless rejects are |
| 287 // possible and if the current packet contains a CHLO message. Determines a | 285 // possible and if the current packet contains a CHLO message. Determines a |
| 288 // fate which describes what subsequent processing should be performed on the | 286 // fate which describes what subsequent processing should be performed on the |
| 289 // packets, like ValidityChecks, and invokes ProcessUnauthenticatedHeaderFate. | 287 // packets, like ValidityChecks, and invokes ProcessUnauthenticatedHeaderFate. |
| 290 void MaybeRejectStatelessly(QuicConnectionId connection_id, | 288 void MaybeRejectStatelessly(QuicConnectionId connection_id, |
| 291 const QuicPacketHeader& header); | 289 const QuicPacketHeader& header); |
| 292 | 290 |
| 293 // Deliver |packets| to |session| for further processing. | 291 // Deliver |packets| to |session| for further processing. |
| 294 void DeliverPacketsToSession( | 292 void DeliverPacketsToSession( |
| 295 const std::list<QuicBufferedPacketStore::BufferedPacket>& packets, | 293 const std::list<QuicBufferedPacketStore::BufferedPacket>& packets, |
| 296 QuicServerSessionBase* session); | 294 QuicSession* session); |
| 297 | 295 |
| 298 // Perform the appropriate actions on the current packet based on |fate| - | 296 // Perform the appropriate actions on the current packet based on |fate| - |
| 299 // either process, buffer, or drop it. | 297 // either process, buffer, or drop it. |
| 300 void ProcessUnauthenticatedHeaderFate(QuicPacketFate fate, | 298 void ProcessUnauthenticatedHeaderFate(QuicPacketFate fate, |
| 301 QuicConnectionId connection_id, | 299 QuicConnectionId connection_id, |
| 302 QuicPacketNumber packet_number); | 300 QuicPacketNumber packet_number); |
| 303 | 301 |
| 304 // Invoked when StatelessRejector::Process completes. | 302 // Invoked when StatelessRejector::Process completes. |
| 305 void OnStatelessRejectorProcessDone( | 303 void OnStatelessRejectorProcessDone( |
| 306 std::unique_ptr<StatelessRejector> rejector, | 304 std::unique_ptr<StatelessRejector> rejector, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 330 QuicCompressedCertsCache compressed_certs_cache_; | 328 QuicCompressedCertsCache compressed_certs_cache_; |
| 331 | 329 |
| 332 // The list of connections waiting to write. | 330 // The list of connections waiting to write. |
| 333 WriteBlockedList write_blocked_list_; | 331 WriteBlockedList write_blocked_list_; |
| 334 | 332 |
| 335 SessionMap session_map_; | 333 SessionMap session_map_; |
| 336 | 334 |
| 337 // Entity that manages connection_ids in time wait state. | 335 // Entity that manages connection_ids in time wait state. |
| 338 std::unique_ptr<QuicTimeWaitListManager> time_wait_list_manager_; | 336 std::unique_ptr<QuicTimeWaitListManager> time_wait_list_manager_; |
| 339 | 337 |
| 340 // The list of closed but not-yet-deleted sessions. | 338 // The std::list of closed but not-yet-deleted sessions. |
| 341 std::vector<std::unique_ptr<QuicServerSessionBase>> closed_session_list_; | 339 std::vector<std::unique_ptr<QuicSession>> closed_session_list_; |
| 342 | 340 |
| 343 // The helper used for all connections. | 341 // The helper used for all connections. |
| 344 std::unique_ptr<QuicConnectionHelperInterface> helper_; | 342 std::unique_ptr<QuicConnectionHelperInterface> helper_; |
| 345 | 343 |
| 346 // The helper used for all sessions. | 344 // The helper used for all sessions. |
| 347 std::unique_ptr<QuicCryptoServerStream::Helper> session_helper_; | 345 std::unique_ptr<QuicCryptoServerStream::Helper> session_helper_; |
| 348 | 346 |
| 349 // Creates alarms. | 347 // Creates alarms. |
| 350 std::unique_ptr<QuicAlarmFactory> alarm_factory_; | 348 std::unique_ptr<QuicAlarmFactory> alarm_factory_; |
| 351 | 349 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 382 // A backward counter of how many new sessions can be create within current | 380 // A backward counter of how many new sessions can be create within current |
| 383 // event loop. When reaches 0, it means can't create sessions for now. | 381 // event loop. When reaches 0, it means can't create sessions for now. |
| 384 int16_t new_sessions_allowed_per_event_loop_; | 382 int16_t new_sessions_allowed_per_event_loop_; |
| 385 | 383 |
| 386 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 384 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
| 387 }; | 385 }; |
| 388 | 386 |
| 389 } // namespace net | 387 } // namespace net |
| 390 | 388 |
| 391 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 389 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
| OLD | NEW |