| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 public: | 57 public: |
| 58 virtual ~PacketWriterFactory() {} | 58 virtual ~PacketWriterFactory() {} |
| 59 | 59 |
| 60 virtual QuicPacketWriter* Create(QuicPacketWriter* writer, | 60 virtual QuicPacketWriter* Create(QuicPacketWriter* writer, |
| 61 QuicConnection* connection) = 0; | 61 QuicConnection* connection) = 0; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 // Creates ordinary QuicPerConnectionPacketWriter instances. | 64 // Creates ordinary QuicPerConnectionPacketWriter instances. |
| 65 class DefaultPacketWriterFactory : public PacketWriterFactory { | 65 class DefaultPacketWriterFactory : public PacketWriterFactory { |
| 66 public: | 66 public: |
| 67 virtual ~DefaultPacketWriterFactory() {} | 67 ~DefaultPacketWriterFactory() override {} |
| 68 | 68 |
| 69 virtual QuicPacketWriter* Create( | 69 QuicPacketWriter* Create(QuicPacketWriter* writer, |
| 70 QuicPacketWriter* writer, | 70 QuicConnection* connection) override; |
| 71 QuicConnection* connection) override; | |
| 72 }; | 71 }; |
| 73 | 72 |
| 74 // Ideally we'd have a linked_hash_set: the boolean is unused. | 73 // Ideally we'd have a linked_hash_set: the boolean is unused. |
| 75 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; | 74 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; |
| 76 | 75 |
| 77 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must | 76 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must |
| 78 // live until epoll_server Shutdown. |supported_versions| specifies the list | 77 // live until epoll_server Shutdown. |supported_versions| specifies the list |
| 79 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, | 78 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, |
| 80 // which is used to create per-connection writers. | 79 // which is used to create per-connection writers. |
| 81 QuicDispatcher(const QuicConfig& config, | 80 QuicDispatcher(const QuicConfig& config, |
| 82 const QuicCryptoServerConfig& crypto_config, | 81 const QuicCryptoServerConfig& crypto_config, |
| 83 const QuicVersionVector& supported_versions, | 82 const QuicVersionVector& supported_versions, |
| 84 PacketWriterFactory* packet_writer_factory, | 83 PacketWriterFactory* packet_writer_factory, |
| 85 EpollServer* epoll_server); | 84 EpollServer* epoll_server); |
| 86 | 85 |
| 87 virtual ~QuicDispatcher(); | 86 ~QuicDispatcher() override; |
| 88 | 87 |
| 89 virtual void Initialize(int fd); | 88 virtual void Initialize(int fd); |
| 90 | 89 |
| 91 // Process the incoming packet by creating a new session, passing it to | 90 // Process the incoming packet by creating a new session, passing it to |
| 92 // an existing session, or passing it to the TimeWaitListManager. | 91 // an existing session, or passing it to the TimeWaitListManager. |
| 93 virtual void ProcessPacket(const IPEndPoint& server_address, | 92 void ProcessPacket(const IPEndPoint& server_address, |
| 94 const IPEndPoint& client_address, | 93 const IPEndPoint& client_address, |
| 95 const QuicEncryptedPacket& packet) override; | 94 const QuicEncryptedPacket& packet) override; |
| 96 | 95 |
| 97 // Called when the socket becomes writable to allow queued writes to happen. | 96 // Called when the socket becomes writable to allow queued writes to happen. |
| 98 virtual void OnCanWrite(); | 97 virtual void OnCanWrite(); |
| 99 | 98 |
| 100 // Returns true if there's anything in the blocked writer list. | 99 // Returns true if there's anything in the blocked writer list. |
| 101 virtual bool HasPendingWrites() const; | 100 virtual bool HasPendingWrites() const; |
| 102 | 101 |
| 103 // Sends ConnectionClose frames to all connected clients. | 102 // Sends ConnectionClose frames to all connected clients. |
| 104 void Shutdown(); | 103 void Shutdown(); |
| 105 | 104 |
| 106 // QuicServerSessionVisitor interface implementation: | 105 // QuicServerSessionVisitor interface implementation: |
| 107 // Ensure that the closed connection is cleaned up asynchronously. | 106 // Ensure that the closed connection is cleaned up asynchronously. |
| 108 virtual void OnConnectionClosed(QuicConnectionId connection_id, | 107 void OnConnectionClosed(QuicConnectionId connection_id, |
| 109 QuicErrorCode error) override; | 108 QuicErrorCode error) override; |
| 110 | 109 |
| 111 // Queues the blocked writer for later resumption. | 110 // Queues the blocked writer for later resumption. |
| 112 virtual void OnWriteBlocked( | 111 void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) override; |
| 113 QuicBlockedWriterInterface* blocked_writer) override; | |
| 114 | 112 |
| 115 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; | 113 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; |
| 116 | 114 |
| 117 // Deletes all sessions on the closed session list and clears the list. | 115 // Deletes all sessions on the closed session list and clears the list. |
| 118 void DeleteSessions(); | 116 void DeleteSessions(); |
| 119 | 117 |
| 120 const SessionMap& session_map() const { return session_map_; } | 118 const SessionMap& session_map() const { return session_map_; } |
| 121 | 119 |
| 122 protected: | 120 protected: |
| 123 // Instantiates a new low-level packet writer. Caller takes ownership of the | 121 // Instantiates a new low-level packet writer. Caller takes ownership of the |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 class QuicFramerVisitor; | 182 class QuicFramerVisitor; |
| 185 friend class net::tools::test::QuicDispatcherPeer; | 183 friend class net::tools::test::QuicDispatcherPeer; |
| 186 | 184 |
| 187 // An adapter that creates packet writers using the dispatcher's | 185 // An adapter that creates packet writers using the dispatcher's |
| 188 // PacketWriterFactory and shared writer. Essentially, it just curries the | 186 // PacketWriterFactory and shared writer. Essentially, it just curries the |
| 189 // writer argument away from QuicDispatcher::PacketWriterFactory. | 187 // writer argument away from QuicDispatcher::PacketWriterFactory. |
| 190 class PacketWriterFactoryAdapter : | 188 class PacketWriterFactoryAdapter : |
| 191 public QuicConnection::PacketWriterFactory { | 189 public QuicConnection::PacketWriterFactory { |
| 192 public: | 190 public: |
| 193 PacketWriterFactoryAdapter(QuicDispatcher* dispatcher); | 191 PacketWriterFactoryAdapter(QuicDispatcher* dispatcher); |
| 194 virtual ~PacketWriterFactoryAdapter (); | 192 ~PacketWriterFactoryAdapter() override; |
| 195 | 193 |
| 196 virtual QuicPacketWriter* Create(QuicConnection* connection) const override; | 194 QuicPacketWriter* Create(QuicConnection* connection) const override; |
| 197 | 195 |
| 198 private: | 196 private: |
| 199 QuicDispatcher* dispatcher_; | 197 QuicDispatcher* dispatcher_; |
| 200 }; | 198 }; |
| 201 | 199 |
| 202 // Called by |framer_visitor_| when the private header has been parsed | 200 // Called by |framer_visitor_| when the private header has been parsed |
| 203 // of a data packet that is destined for the time wait manager. | 201 // of a data packet that is destined for the time wait manager. |
| 204 void OnUnauthenticatedHeader(const QuicPacketHeader& header); | 202 void OnUnauthenticatedHeader(const QuicPacketHeader& header); |
| 205 | 203 |
| 206 // Removes the session from the session map and write blocked list, and | 204 // Removes the session from the session map and write blocked list, and |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 QuicFramer framer_; | 253 QuicFramer framer_; |
| 256 scoped_ptr<QuicFramerVisitor> framer_visitor_; | 254 scoped_ptr<QuicFramerVisitor> framer_visitor_; |
| 257 | 255 |
| 258 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 256 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
| 259 }; | 257 }; |
| 260 | 258 |
| 261 } // namespace tools | 259 } // namespace tools |
| 262 } // namespace net | 260 } // namespace net |
| 263 | 261 |
| 264 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 262 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
| OLD | NEW |