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 namespace net { | 23 namespace net { |
24 | 24 |
25 class EpollServer; | |
26 class QuicConfig; | 25 class QuicConfig; |
27 class QuicCryptoServerConfig; | 26 class QuicCryptoServerConfig; |
28 class QuicSession; | 27 class QuicSession; |
29 | 28 |
30 namespace tools { | 29 namespace tools { |
31 | 30 |
32 class DeleteSessionsAlarm; | |
33 class QuicEpollConnectionHelper; | |
34 class QuicPacketWriterWrapper; | |
35 | |
36 namespace test { | 31 namespace test { |
37 class QuicDispatcherPeer; | 32 class QuicDispatcherPeer; |
38 } // namespace test | 33 } // namespace test |
39 | 34 |
40 class ProcessPacketInterface { | 35 class ProcessPacketInterface { |
41 public: | 36 public: |
42 virtual ~ProcessPacketInterface() {} | 37 virtual ~ProcessPacketInterface() {} |
43 virtual void ProcessPacket(const IPEndPoint& server_address, | 38 virtual void ProcessPacket(const IPEndPoint& server_address, |
44 const IPEndPoint& client_address, | 39 const IPEndPoint& client_address, |
45 const QuicEncryptedPacket& packet) = 0; | 40 const QuicEncryptedPacket& packet) = 0; |
(...skipping 28 matching lines...) Expand all Loading... |
74 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; | 69 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; |
75 | 70 |
76 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must | 71 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must |
77 // live until epoll_server Shutdown. |supported_versions| specifies the list | 72 // live until epoll_server Shutdown. |supported_versions| specifies the list |
78 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, | 73 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, |
79 // which is used to create per-connection writers. | 74 // which is used to create per-connection writers. |
80 QuicDispatcher(const QuicConfig& config, | 75 QuicDispatcher(const QuicConfig& config, |
81 const QuicCryptoServerConfig& crypto_config, | 76 const QuicCryptoServerConfig& crypto_config, |
82 const QuicVersionVector& supported_versions, | 77 const QuicVersionVector& supported_versions, |
83 PacketWriterFactory* packet_writer_factory, | 78 PacketWriterFactory* packet_writer_factory, |
84 EpollServer* epoll_server); | 79 QuicConnectionHelperInterface* helper); |
85 | 80 |
86 ~QuicDispatcher() override; | 81 ~QuicDispatcher() override; |
87 | 82 |
88 virtual void Initialize(int fd); | 83 virtual void Initialize(int fd); |
89 | 84 |
90 // Process the incoming packet by creating a new session, passing it to | 85 // Process the incoming packet by creating a new session, passing it to |
91 // an existing session, or passing it to the TimeWaitListManager. | 86 // an existing session, or passing it to the TimeWaitListManager. |
92 void ProcessPacket(const IPEndPoint& server_address, | 87 void ProcessPacket(const IPEndPoint& server_address, |
93 const IPEndPoint& client_address, | 88 const IPEndPoint& client_address, |
94 const QuicEncryptedPacket& packet) override; | 89 const QuicEncryptedPacket& packet) override; |
(...skipping 19 matching lines...) Expand all Loading... |
114 // time-wait list. | 109 // time-wait list. |
115 void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override; | 110 void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override; |
116 | 111 |
117 // Called whenever the QuicTimeWaitListManager removes an old connection from | 112 // Called whenever the QuicTimeWaitListManager removes an old connection from |
118 // the time-wait list. | 113 // the time-wait list. |
119 void OnConnectionRemovedFromTimeWaitList( | 114 void OnConnectionRemovedFromTimeWaitList( |
120 QuicConnectionId connection_id) override; | 115 QuicConnectionId connection_id) override; |
121 | 116 |
122 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; | 117 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; |
123 | 118 |
| 119 const SessionMap& session_map() const { return session_map_; } |
| 120 |
124 // Deletes all sessions on the closed session list and clears the list. | 121 // Deletes all sessions on the closed session list and clears the list. |
125 void DeleteSessions(); | 122 void DeleteSessions(); |
126 | 123 |
127 const SessionMap& session_map() const { return session_map_; } | |
128 | |
129 protected: | 124 protected: |
130 // Instantiates a new low-level packet writer. Caller takes ownership of the | 125 // Instantiates a new low-level packet writer. Caller takes ownership of the |
131 // returned object. | 126 // returned object. |
132 virtual QuicPacketWriter* CreateWriter(int fd); | 127 virtual QuicPacketWriter* CreateWriter(int fd); |
133 | 128 |
134 virtual QuicSession* CreateQuicSession(QuicConnectionId connection_id, | 129 virtual QuicSession* CreateQuicSession(QuicConnectionId connection_id, |
135 const IPEndPoint& server_address, | 130 const IPEndPoint& server_address, |
136 const IPEndPoint& client_address); | 131 const IPEndPoint& client_address); |
137 | 132 |
138 // Called by |framer_visitor_| when the public header has been parsed. | 133 // Called by |framer_visitor_| when the public header has been parsed. |
(...skipping 12 matching lines...) Expand all Loading... |
151 QuicConnectionId connection_id); | 146 QuicConnectionId connection_id); |
152 | 147 |
153 // Create and return the time wait list manager for this dispatcher, which | 148 // Create and return the time wait list manager for this dispatcher, which |
154 // will be owned by the dispatcher as time_wait_list_manager_ | 149 // will be owned by the dispatcher as time_wait_list_manager_ |
155 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); | 150 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); |
156 | 151 |
157 QuicTimeWaitListManager* time_wait_list_manager() { | 152 QuicTimeWaitListManager* time_wait_list_manager() { |
158 return time_wait_list_manager_.get(); | 153 return time_wait_list_manager_.get(); |
159 } | 154 } |
160 | 155 |
161 EpollServer* epoll_server() { return epoll_server_; } | |
162 | |
163 const QuicVersionVector& supported_versions() const { | 156 const QuicVersionVector& supported_versions() const { |
164 return supported_versions_; | 157 return supported_versions_; |
165 } | 158 } |
166 | 159 |
167 const IPEndPoint& current_server_address() { | 160 const IPEndPoint& current_server_address() { |
168 return current_server_address_; | 161 return current_server_address_; |
169 } | 162 } |
170 const IPEndPoint& current_client_address() { | 163 const IPEndPoint& current_client_address() { |
171 return current_client_address_; | 164 return current_client_address_; |
172 } | 165 } |
173 const QuicEncryptedPacket& current_packet() { | 166 const QuicEncryptedPacket& current_packet() { |
174 return *current_packet_; | 167 return *current_packet_; |
175 } | 168 } |
176 | 169 |
177 const QuicConfig& config() const { return config_; } | 170 const QuicConfig& config() const { return config_; } |
178 | 171 |
179 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } | 172 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } |
180 | 173 |
181 QuicFramer* framer() { return &framer_; } | 174 QuicFramer* framer() { return &framer_; } |
182 | 175 |
183 QuicEpollConnectionHelper* helper() { return helper_.get(); } | 176 QuicConnectionHelperInterface* helper() { return helper_.get(); } |
184 | 177 |
185 QuicPacketWriter* writer() { return writer_.get(); } | 178 QuicPacketWriter* writer() { return writer_.get(); } |
186 | 179 |
187 const QuicConnection::PacketWriterFactory& connection_writer_factory() { | 180 const QuicConnection::PacketWriterFactory& connection_writer_factory() { |
188 return connection_writer_factory_; | 181 return connection_writer_factory_; |
189 } | 182 } |
190 | 183 |
191 private: | 184 private: |
192 class QuicFramerVisitor; | 185 class QuicFramerVisitor; |
193 friend class net::tools::test::QuicDispatcherPeer; | 186 friend class net::tools::test::QuicDispatcherPeer; |
(...skipping 28 matching lines...) Expand all Loading... |
222 const QuicCryptoServerConfig& crypto_config_; | 215 const QuicCryptoServerConfig& crypto_config_; |
223 | 216 |
224 // The list of connections waiting to write. | 217 // The list of connections waiting to write. |
225 WriteBlockedList write_blocked_list_; | 218 WriteBlockedList write_blocked_list_; |
226 | 219 |
227 SessionMap session_map_; | 220 SessionMap session_map_; |
228 | 221 |
229 // Entity that manages connection_ids in time wait state. | 222 // Entity that manages connection_ids in time wait state. |
230 scoped_ptr<QuicTimeWaitListManager> time_wait_list_manager_; | 223 scoped_ptr<QuicTimeWaitListManager> time_wait_list_manager_; |
231 | 224 |
232 // An alarm which deletes closed sessions. | |
233 scoped_ptr<DeleteSessionsAlarm> delete_sessions_alarm_; | |
234 | |
235 // The list of closed but not-yet-deleted sessions. | 225 // The list of closed but not-yet-deleted sessions. |
236 std::list<QuicSession*> closed_session_list_; | 226 std::list<QuicSession*> closed_session_list_; |
237 | 227 |
238 EpollServer* epoll_server_; // Owned by the server. | 228 // The helper used for all connections. |
| 229 scoped_ptr<QuicConnectionHelperInterface> helper_; |
239 | 230 |
240 // The helper used for all connections. | 231 // An alarm which deletes closed sessions. |
241 scoped_ptr<QuicEpollConnectionHelper> helper_; | 232 scoped_ptr<QuicAlarm> delete_sessions_alarm_; |
242 | 233 |
243 // The writer to write to the socket with. | 234 // The writer to write to the socket with. |
244 scoped_ptr<QuicPacketWriter> writer_; | 235 scoped_ptr<QuicPacketWriter> writer_; |
245 | 236 |
246 // Used to create per-connection packet writers, not |writer_| itself. | 237 // Used to create per-connection packet writers, not |writer_| itself. |
247 scoped_ptr<PacketWriterFactory> packet_writer_factory_; | 238 scoped_ptr<PacketWriterFactory> packet_writer_factory_; |
248 | 239 |
249 // Passed in to QuicConnection for it to create the per-connection writers | 240 // Passed in to QuicConnection for it to create the per-connection writers |
250 PacketWriterFactoryAdapter connection_writer_factory_; | 241 PacketWriterFactoryAdapter connection_writer_factory_; |
251 | 242 |
(...skipping 11 matching lines...) Expand all Loading... |
263 QuicFramer framer_; | 254 QuicFramer framer_; |
264 scoped_ptr<QuicFramerVisitor> framer_visitor_; | 255 scoped_ptr<QuicFramerVisitor> framer_visitor_; |
265 | 256 |
266 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 257 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
267 }; | 258 }; |
268 | 259 |
269 } // namespace tools | 260 } // namespace tools |
270 } // namespace net | 261 } // namespace net |
271 | 262 |
272 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 263 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
OLD | NEW |