| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_QUIC_QUIC_DISPATCHER_H_ | 8 #ifndef NET_QUIC_QUIC_DISPATCHER_H_ |
| 9 #define NET_QUIC_QUIC_DISPATCHER_H_ | 9 #define NET_QUIC_QUIC_DISPATCHER_H_ |
| 10 | 10 |
| 11 #include <list> | 11 #include <list> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.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/quic_blocked_writer_interface.h" | 18 #include "net/quic/quic_blocked_writer_interface.h" |
| 19 #include "net/quic/quic_connection_helper.h" | 19 #include "net/quic/quic_connection_helper.h" |
| 20 #include "net/quic/quic_protocol.h" | 20 #include "net/quic/quic_protocol.h" |
| 21 #include "net/quic/quic_server_packet_writer.h" |
| 21 #include "net/quic/quic_server_session.h" | 22 #include "net/quic/quic_server_session.h" |
| 22 #include "net/quic/quic_time_wait_list_manager.h" | 23 #include "net/quic/quic_time_wait_list_manager.h" |
| 23 | 24 |
| 24 #if defined(COMPILER_GCC) | 25 #if defined(COMPILER_GCC) |
| 25 namespace BASE_HASH_NAMESPACE { | 26 namespace BASE_HASH_NAMESPACE { |
| 26 template <> | 27 template <> |
| 27 struct hash<net::QuicBlockedWriterInterface*> { | 28 struct hash<net::QuicBlockedWriterInterface*> { |
| 28 std::size_t operator()(const net::QuicBlockedWriterInterface* ptr) const { | 29 std::size_t operator()(const net::QuicBlockedWriterInterface* ptr) const { |
| 29 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); | 30 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
| 30 } | 31 } |
| 31 }; | 32 }; |
| 32 } | 33 } |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 namespace net { | 36 namespace net { |
| 36 | 37 |
| 37 class QuicConfig; | 38 class QuicConfig; |
| 38 class QuicCryptoServerConfig; | 39 class QuicCryptoServerConfig; |
| 39 class QuicPacketWriterWrapper; | |
| 40 class QuicSession; | 40 class QuicSession; |
| 41 class UDPServerSocket; | |
| 42 | 41 |
| 43 namespace test { | 42 namespace test { |
| 44 class QuicDispatcherPeer; | 43 class QuicDispatcherPeer; |
| 45 } // namespace test | 44 } // namespace test |
| 46 | 45 |
| 47 class DeleteSessionsAlarm; | 46 class DeleteSessionsAlarm; |
| 48 | 47 |
| 49 class QuicDispatcher : public QuicServerSessionVisitor { | 48 class QuicDispatcher : public QuicServerSessionVisitor, |
| 49 public QuicBlockedWriterInterface { |
| 50 public: | 50 public: |
| 51 // Ideally we'd have a linked_hash_set: the boolean is unused. | 51 // Ideally we'd have a linked_hash_set: the boolean is unused. |
| 52 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; | 52 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; |
| 53 | 53 |
| 54 // Due to the way delete_sessions_closure_ is registered, the Dispatcher | 54 // Due to the way delete_sessions_closure_ is registered, the Dispatcher |
| 55 // must live until epoll_server Shutdown. |supported_versions| specifies the | 55 // must live until epoll_server Shutdown. |supported_versions| specifies the |
| 56 // list of supported QUIC versions. | 56 // list of supported QUIC versions. |
| 57 QuicDispatcher(const QuicConfig& config, | 57 QuicDispatcher(const QuicConfig& config, |
| 58 const QuicCryptoServerConfig& crypto_config, | 58 const QuicCryptoServerConfig& crypto_config, |
| 59 const QuicVersionVector& supported_versions, | 59 const QuicVersionVector& supported_versions, |
| 60 QuicConnectionHelperInterface* helper); | 60 QuicConnectionHelperInterface* helper); |
| 61 | 61 |
| 62 virtual ~QuicDispatcher(); | 62 virtual ~QuicDispatcher(); |
| 63 | 63 |
| 64 // Takes ownership of the packet writer | 64 // Takes ownership of the packet writer |
| 65 virtual void Initialize(QuicPacketWriter* writer); | 65 virtual void Initialize(QuicServerPacketWriter* writer); |
| 66 | 66 |
| 67 // Process the incoming packet by creating a new session, passing it to | 67 // Process the incoming packet by creating a new session, passing it to |
| 68 // an existing session, or passing it to the TimeWaitListManager. | 68 // an existing session, or passing it to the TimeWaitListManager. |
| 69 virtual void ProcessPacket(const IPEndPoint& server_address, | 69 virtual void ProcessPacket(const IPEndPoint& server_address, |
| 70 const IPEndPoint& client_address, | 70 const IPEndPoint& client_address, |
| 71 const QuicEncryptedPacket& packet); | 71 const QuicEncryptedPacket& packet); |
| 72 | 72 |
| 73 // Called when the socket becomes writable to allow queued writes to happen. | |
| 74 virtual void OnCanWrite(); | |
| 75 | |
| 76 // Returns true if there's anything in the blocked writer list. | 73 // Returns true if there's anything in the blocked writer list. |
| 77 virtual bool HasPendingWrites() const; | 74 virtual bool HasPendingWrites() const; |
| 78 | 75 |
| 79 // Sends ConnectionClose frames to all connected clients. | 76 // Sends ConnectionClose frames to all connected clients. |
| 80 void Shutdown(); | 77 void Shutdown(); |
| 81 | 78 |
| 79 // QuicBlockedWriterInterface implementation: |
| 80 // Called when the socket becomes writable to allow queued writes to happen. |
| 81 virtual void OnCanWrite() OVERRIDE; |
| 82 |
| 82 // QuicServerSessionVisitor interface implementation: | 83 // QuicServerSessionVisitor interface implementation: |
| 83 // Ensure that the closed connection is cleaned up asynchronously. | 84 // Ensure that the closed connection is cleaned up asynchronously. |
| 84 virtual void OnConnectionClosed(QuicConnectionId connection_id, | 85 virtual void OnConnectionClosed(QuicConnectionId connection_id, |
| 85 QuicErrorCode error) OVERRIDE; | 86 QuicErrorCode error) OVERRIDE; |
| 86 | 87 |
| 87 // Queues the blocked writer for later resumption. | 88 // Queues the blocked writer for later resumption. |
| 88 virtual void OnWriteBlocked(QuicBlockedWriterInterface* writer) OVERRIDE; | 89 virtual void OnWriteBlocked(QuicBlockedWriterInterface* writer) OVERRIDE; |
| 89 | 90 |
| 90 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; | 91 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; |
| 91 | 92 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 108 | 109 |
| 109 // Called by |framer_visitor_| when the public header has been parsed. | 110 // Called by |framer_visitor_| when the public header has been parsed. |
| 110 virtual bool OnUnauthenticatedPublicHeader( | 111 virtual bool OnUnauthenticatedPublicHeader( |
| 111 const QuicPacketPublicHeader& header); | 112 const QuicPacketPublicHeader& header); |
| 112 | 113 |
| 113 // Create and return the time wait list manager for this dispatcher, which | 114 // Create and return the time wait list manager for this dispatcher, which |
| 114 // will be owned by the dispatcher as time_wait_list_manager_ | 115 // will be owned by the dispatcher as time_wait_list_manager_ |
| 115 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); | 116 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); |
| 116 | 117 |
| 117 // Replaces the packet writer with |writer|. Takes ownership of |writer|. | 118 // Replaces the packet writer with |writer|. Takes ownership of |writer|. |
| 118 void set_writer(QuicPacketWriter* writer) { | 119 void set_writer(QuicServerPacketWriter* writer) { |
| 119 writer_.reset(writer); | 120 writer_.reset(writer); |
| 120 } | 121 } |
| 121 | 122 |
| 122 QuicTimeWaitListManager* time_wait_list_manager() { | 123 QuicTimeWaitListManager* time_wait_list_manager() { |
| 123 return time_wait_list_manager_.get(); | 124 return time_wait_list_manager_.get(); |
| 124 } | 125 } |
| 125 | 126 |
| 126 const QuicVersionVector& supported_versions() const { | 127 const QuicVersionVector& supported_versions() const { |
| 127 return supported_versions_; | 128 return supported_versions_; |
| 128 } | 129 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 147 } | 148 } |
| 148 | 149 |
| 149 const QuicConfig& config() const { return config_; } | 150 const QuicConfig& config() const { return config_; } |
| 150 | 151 |
| 151 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } | 152 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } |
| 152 | 153 |
| 153 QuicFramer* framer() { return &framer_; } | 154 QuicFramer* framer() { return &framer_; } |
| 154 | 155 |
| 155 QuicConnectionHelperInterface* helper() { return helper_; } | 156 QuicConnectionHelperInterface* helper() { return helper_; } |
| 156 | 157 |
| 157 QuicPacketWriter* writer() { return writer_.get(); } | 158 QuicServerPacketWriter* writer() { return writer_.get(); } |
| 158 | 159 |
| 159 private: | 160 private: |
| 160 class QuicFramerVisitor; | 161 class QuicFramerVisitor; |
| 161 friend class net::test::QuicDispatcherPeer; | 162 friend class net::test::QuicDispatcherPeer; |
| 162 | 163 |
| 163 // Called by |framer_visitor_| when the private header has been parsed | 164 // Called by |framer_visitor_| when the private header has been parsed |
| 164 // of a data packet that is destined for the time wait manager. | 165 // of a data packet that is destined for the time wait manager. |
| 165 void OnUnauthenticatedHeader(const QuicPacketHeader& header); | 166 void OnUnauthenticatedHeader(const QuicPacketHeader& header); |
| 166 | 167 |
| 167 // Removes the session from the session map and write blocked list, and | 168 // Removes the session from the session map and write blocked list, and |
| (...skipping 17 matching lines...) Expand all Loading... |
| 185 // The helper used for all connections. Owned by the server. | 186 // The helper used for all connections. Owned by the server. |
| 186 QuicConnectionHelperInterface* helper_; | 187 QuicConnectionHelperInterface* helper_; |
| 187 | 188 |
| 188 // An alarm which deletes closed sessions. | 189 // An alarm which deletes closed sessions. |
| 189 scoped_ptr<QuicAlarm> delete_sessions_alarm_; | 190 scoped_ptr<QuicAlarm> delete_sessions_alarm_; |
| 190 | 191 |
| 191 // The list of closed but not-yet-deleted sessions. | 192 // The list of closed but not-yet-deleted sessions. |
| 192 std::list<QuicSession*> closed_session_list_; | 193 std::list<QuicSession*> closed_session_list_; |
| 193 | 194 |
| 194 // The writer to write to the socket with. | 195 // The writer to write to the socket with. |
| 195 scoped_ptr<QuicPacketWriter> writer_; | 196 scoped_ptr<QuicServerPacketWriter> writer_; |
| 196 | 197 |
| 197 // This vector contains QUIC versions which we currently support. | 198 // This vector contains QUIC versions which we currently support. |
| 198 // This should be ordered such that the highest supported version is the first | 199 // This should be ordered such that the highest supported version is the first |
| 199 // element, with subsequent elements in descending order (versions can be | 200 // element, with subsequent elements in descending order (versions can be |
| 200 // skipped as necessary). | 201 // skipped as necessary). |
| 201 const QuicVersionVector supported_versions_; | 202 const QuicVersionVector supported_versions_; |
| 202 | 203 |
| 203 // Versions which do not support flow control (introduced in QUIC_VERSION_17). | 204 // Versions which do not support flow control (introduced in QUIC_VERSION_17). |
| 204 // This is used to construct new QuicConnections when flow control is disabled | 205 // This is used to construct new QuicConnections when flow control is disabled |
| 205 // via flag. | 206 // via flag. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 221 | 222 |
| 222 QuicFramer framer_; | 223 QuicFramer framer_; |
| 223 scoped_ptr<QuicFramerVisitor> framer_visitor_; | 224 scoped_ptr<QuicFramerVisitor> framer_visitor_; |
| 224 | 225 |
| 225 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 226 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
| 226 }; | 227 }; |
| 227 | 228 |
| 228 } // namespace net | 229 } // namespace net |
| 229 | 230 |
| 230 #endif // NET_QUIC_QUIC_DISPATCHER_H_ | 231 #endif // NET_QUIC_QUIC_DISPATCHER_H_ |
| OLD | NEW |