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 <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_protocol.h" | 19 #include "net/quic/quic_protocol.h" |
20 #include "net/tools/quic/quic_server_session.h" | 20 #include "net/tools/quic/quic_server_session.h" |
21 #include "net/tools/quic/quic_time_wait_list_manager.h" | 21 #include "net/tools/quic/quic_time_wait_list_manager.h" |
22 | 22 |
23 #if defined(COMPILER_GCC) | 23 #if defined(COMPILER_GCC) && !defined(QUIC_BLOCKED_WRITER_INTERFACE_HASH) |
| 24 #define QUIC_BLOCKED_WRITER_INTERFACE_HASH |
24 namespace BASE_HASH_NAMESPACE { | 25 namespace BASE_HASH_NAMESPACE { |
25 template<> | 26 template<> |
26 struct hash<net::QuicBlockedWriterInterface*> { | 27 struct hash<net::QuicBlockedWriterInterface*> { |
27 std::size_t operator()( | 28 std::size_t operator()( |
28 const net::QuicBlockedWriterInterface* ptr) const { | 29 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 |
(...skipping 20 matching lines...) Expand all Loading... |
54 public: | 55 public: |
55 virtual ~ProcessPacketInterface() {} | 56 virtual ~ProcessPacketInterface() {} |
56 virtual void ProcessPacket(const IPEndPoint& server_address, | 57 virtual void ProcessPacket(const IPEndPoint& server_address, |
57 const IPEndPoint& client_address, | 58 const IPEndPoint& client_address, |
58 const QuicEncryptedPacket& packet) = 0; | 59 const QuicEncryptedPacket& packet) = 0; |
59 }; | 60 }; |
60 | 61 |
61 class QuicDispatcher : public QuicServerSessionVisitor, | 62 class QuicDispatcher : public QuicServerSessionVisitor, |
62 public ProcessPacketInterface { | 63 public ProcessPacketInterface { |
63 public: | 64 public: |
| 65 // Creates per-connection packet writers out of the QuicDispatcher's shared |
| 66 // QuicPacketWriter. The per-connection writers' IsWriteBlocked() state must |
| 67 // always be the same as the shared writer's IsWriteBlocked(), or else the |
| 68 // QuicDispatcher::OnCanWrite logic will not work. (This will hopefully be |
| 69 // cleaned up for bug 16950226.) |
| 70 class PacketWriterFactory { |
| 71 public: |
| 72 virtual ~PacketWriterFactory() {} |
| 73 |
| 74 virtual QuicPacketWriter* Create(QuicPacketWriter* writer, |
| 75 QuicConnection* connection) = 0; |
| 76 }; |
| 77 |
| 78 // Creates ordinary QuicPerConnectionPacketWriter instances. |
| 79 class DefaultPacketWriterFactory : public PacketWriterFactory { |
| 80 public: |
| 81 virtual ~DefaultPacketWriterFactory() {} |
| 82 |
| 83 virtual QuicPacketWriter* Create( |
| 84 QuicPacketWriter* writer, |
| 85 QuicConnection* connection) OVERRIDE; |
| 86 }; |
| 87 |
64 // Ideally we'd have a linked_hash_set: the boolean is unused. | 88 // Ideally we'd have a linked_hash_set: the boolean is unused. |
65 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; | 89 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; |
66 | 90 |
67 // Due to the way delete_sessions_closure_ is registered, the Dispatcher | 91 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must |
68 // must live until epoll_server Shutdown. |supported_versions| specifies the | 92 // live until epoll_server Shutdown. |supported_versions| specifies the list |
69 // list of supported QUIC versions. | 93 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, |
| 94 // which is used to create per-connection writers. |
70 QuicDispatcher(const QuicConfig& config, | 95 QuicDispatcher(const QuicConfig& config, |
71 const QuicCryptoServerConfig& crypto_config, | 96 const QuicCryptoServerConfig& crypto_config, |
72 const QuicVersionVector& supported_versions, | 97 const QuicVersionVector& supported_versions, |
| 98 PacketWriterFactory* packet_writer_factory, |
73 EpollServer* epoll_server); | 99 EpollServer* epoll_server); |
74 | 100 |
75 virtual ~QuicDispatcher(); | 101 virtual ~QuicDispatcher(); |
76 | 102 |
77 virtual void Initialize(int fd); | 103 virtual void Initialize(int fd); |
78 | 104 |
79 // Process the incoming packet by creating a new session, passing it to | 105 // Process the incoming packet by creating a new session, passing it to |
80 // an existing session, or passing it to the TimeWaitListManager. | 106 // an existing session, or passing it to the TimeWaitListManager. |
81 virtual void ProcessPacket(const IPEndPoint& server_address, | 107 virtual void ProcessPacket(const IPEndPoint& server_address, |
82 const IPEndPoint& client_address, | 108 const IPEndPoint& client_address, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 const QuicConfig& config() const { return config_; } | 183 const QuicConfig& config() const { return config_; } |
158 | 184 |
159 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } | 185 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } |
160 | 186 |
161 QuicFramer* framer() { return &framer_; } | 187 QuicFramer* framer() { return &framer_; } |
162 | 188 |
163 QuicEpollConnectionHelper* helper() { return helper_.get(); } | 189 QuicEpollConnectionHelper* helper() { return helper_.get(); } |
164 | 190 |
165 QuicPacketWriter* writer() { return writer_.get(); } | 191 QuicPacketWriter* writer() { return writer_.get(); } |
166 | 192 |
| 193 const QuicConnection::PacketWriterFactory& connection_writer_factory() { |
| 194 return connection_writer_factory_; |
| 195 } |
| 196 |
167 private: | 197 private: |
168 class QuicFramerVisitor; | 198 class QuicFramerVisitor; |
169 friend class net::tools::test::QuicDispatcherPeer; | 199 friend class net::tools::test::QuicDispatcherPeer; |
170 | 200 |
| 201 // An adapter that creates packet writers using the dispatcher's |
| 202 // PacketWriterFactory and shared writer. Essentially, it just curries the |
| 203 // writer argument away from QuicDispatcher::PacketWriterFactory. |
| 204 class PacketWriterFactoryAdapter : |
| 205 public QuicConnection::PacketWriterFactory { |
| 206 public: |
| 207 PacketWriterFactoryAdapter(QuicDispatcher* dispatcher); |
| 208 virtual ~PacketWriterFactoryAdapter (); |
| 209 |
| 210 virtual QuicPacketWriter* Create(QuicConnection* connection) const OVERRIDE; |
| 211 |
| 212 private: |
| 213 QuicDispatcher* dispatcher_; |
| 214 }; |
| 215 |
171 // Called by |framer_visitor_| when the private header has been parsed | 216 // Called by |framer_visitor_| when the private header has been parsed |
172 // of a data packet that is destined for the time wait manager. | 217 // of a data packet that is destined for the time wait manager. |
173 void OnUnauthenticatedHeader(const QuicPacketHeader& header); | 218 void OnUnauthenticatedHeader(const QuicPacketHeader& header); |
174 | 219 |
175 // Removes the session from the session map and write blocked list, and | 220 // Removes the session from the session map and write blocked list, and |
176 // adds the ConnectionId to the time-wait list. | 221 // adds the ConnectionId to the time-wait list. |
177 void CleanUpSession(SessionMap::iterator it); | 222 void CleanUpSession(SessionMap::iterator it); |
178 | 223 |
179 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); | 224 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); |
180 | 225 |
(...skipping 16 matching lines...) Expand all Loading... |
197 std::list<QuicSession*> closed_session_list_; | 242 std::list<QuicSession*> closed_session_list_; |
198 | 243 |
199 EpollServer* epoll_server_; // Owned by the server. | 244 EpollServer* epoll_server_; // Owned by the server. |
200 | 245 |
201 // The helper used for all connections. | 246 // The helper used for all connections. |
202 scoped_ptr<QuicEpollConnectionHelper> helper_; | 247 scoped_ptr<QuicEpollConnectionHelper> helper_; |
203 | 248 |
204 // The writer to write to the socket with. | 249 // The writer to write to the socket with. |
205 scoped_ptr<QuicPacketWriter> writer_; | 250 scoped_ptr<QuicPacketWriter> writer_; |
206 | 251 |
| 252 // Used to create per-connection packet writers, not |writer_| itself. |
| 253 scoped_ptr<PacketWriterFactory> packet_writer_factory_; |
| 254 |
| 255 // Passed in to QuicConnection for it to create the per-connection writers |
| 256 PacketWriterFactoryAdapter connection_writer_factory_; |
| 257 |
207 // This vector contains QUIC versions which we currently support. | 258 // This vector contains QUIC versions which we currently support. |
208 // This should be ordered such that the highest supported version is the first | 259 // This should be ordered such that the highest supported version is the first |
209 // element, with subsequent elements in descending order (versions can be | 260 // element, with subsequent elements in descending order (versions can be |
210 // skipped as necessary). | 261 // skipped as necessary). |
211 const QuicVersionVector supported_versions_; | 262 const QuicVersionVector supported_versions_; |
212 | 263 |
213 // Information about the packet currently being handled. | 264 // Information about the packet currently being handled. |
214 IPEndPoint current_client_address_; | 265 IPEndPoint current_client_address_; |
215 IPEndPoint current_server_address_; | 266 IPEndPoint current_server_address_; |
216 const QuicEncryptedPacket* current_packet_; | 267 const QuicEncryptedPacket* current_packet_; |
217 | 268 |
218 QuicFramer framer_; | 269 QuicFramer framer_; |
219 scoped_ptr<QuicFramerVisitor> framer_visitor_; | 270 scoped_ptr<QuicFramerVisitor> framer_visitor_; |
220 | 271 |
221 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 272 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
222 }; | 273 }; |
223 | 274 |
224 } // namespace tools | 275 } // namespace tools |
225 } // namespace net | 276 } // namespace net |
226 | 277 |
227 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 278 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
OLD | NEW |