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_packet_writer.h" |
22 #include "net/quic/quic_server_session.h" | 22 #include "net/tools/quic/quic_server_session.h" |
23 #include "net/quic/quic_time_wait_list_manager.h" | 23 #include "net/tools/quic/quic_time_wait_list_manager.h" |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 namespace test { | 26 namespace test { |
27 class QuicDispatcherPeer; | 27 class QuicDispatcherPeer; |
28 } // namespace test | 28 } // namespace test |
29 | 29 |
30 class DeleteSessionsAlarm; | 30 class DeleteSessionsAlarm; |
31 class QuicConfig; | 31 class QuicConfig; |
32 class QuicCryptoServerConfig; | 32 class QuicCryptoServerConfig; |
33 class QuicServerSession; | |
34 | 33 |
35 class ProcessPacketInterface { | 34 class ProcessPacketInterface { |
36 public: | 35 public: |
37 virtual ~ProcessPacketInterface() {} | 36 virtual ~ProcessPacketInterface() {} |
38 virtual void ProcessPacket(const IPEndPoint& server_address, | 37 virtual void ProcessPacket(const IPEndPoint& server_address, |
39 const IPEndPoint& client_address, | 38 const IPEndPoint& client_address, |
40 const QuicEncryptedPacket& packet) = 0; | 39 const QuicEncryptedPacket& packet) = 0; |
41 }; | 40 }; |
42 | 41 |
43 class QuicDispatcher : public QuicBlockedWriterInterface, | 42 class QuicDispatcher : public QuicBlockedWriterInterface, |
44 public QuicServerSessionVisitor, | 43 public tools::QuicServerSessionVisitor, |
45 public ProcessPacketInterface { | 44 public ProcessPacketInterface { |
46 public: | 45 public: |
47 // Creates per-connection packet writers out of the QuicDispatcher's shared | 46 // Creates per-connection packet writers out of the QuicDispatcher's shared |
48 // QuicPacketWriter. The per-connection writers' IsWriteBlocked() state must | 47 // QuicPacketWriter. The per-connection writers' IsWriteBlocked() state must |
49 // always be the same as the shared writer's IsWriteBlocked(), or else the | 48 // always be the same as the shared writer's IsWriteBlocked(), or else the |
50 // QuicDispatcher::OnCanWrite logic will not work. (This will hopefully be | 49 // QuicDispatcher::OnCanWrite logic will not work. (This will hopefully be |
51 // cleaned up for bug 16950226.) | 50 // cleaned up for bug 16950226.) |
52 class PacketWriterFactory { | 51 class PacketWriterFactory { |
53 public: | 52 public: |
54 virtual ~PacketWriterFactory() {} | 53 virtual ~PacketWriterFactory() {} |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 109 |
111 // Called whenever the QuicTimeWaitListManager adds a new connection to the | 110 // Called whenever the QuicTimeWaitListManager adds a new connection to the |
112 // time-wait list. | 111 // time-wait list. |
113 void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override; | 112 void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override; |
114 | 113 |
115 // Called whenever the QuicTimeWaitListManager removes an old connection from | 114 // Called whenever the QuicTimeWaitListManager removes an old connection from |
116 // the time-wait list. | 115 // the time-wait list. |
117 void OnConnectionRemovedFromTimeWaitList( | 116 void OnConnectionRemovedFromTimeWaitList( |
118 QuicConnectionId connection_id) override; | 117 QuicConnectionId connection_id) override; |
119 | 118 |
120 typedef base::hash_map<QuicConnectionId, QuicServerSession*> SessionMap; | 119 typedef base::hash_map<QuicConnectionId, |
| 120 tools::QuicServerSession*> SessionMap; |
121 | 121 |
122 // Deletes all sessions on the closed session list and clears the list. | 122 // Deletes all sessions on the closed session list and clears the list. |
123 void DeleteSessions(); | 123 void DeleteSessions(); |
124 | 124 |
125 const SessionMap& session_map() const { return session_map_; } | 125 const SessionMap& session_map() const { return session_map_; } |
126 | 126 |
127 protected: | 127 protected: |
128 virtual QuicServerSession* CreateQuicSession( | 128 virtual tools::QuicServerSession* CreateQuicSession( |
129 QuicConnectionId connection_id, | 129 QuicConnectionId connection_id, |
130 const IPEndPoint& server_address, | 130 const IPEndPoint& server_address, |
131 const IPEndPoint& client_address); | 131 const IPEndPoint& client_address); |
132 | 132 |
133 // Called by |framer_visitor_| when the public header has been parsed. | 133 // Called by |framer_visitor_| when the public header has been parsed. |
134 virtual bool OnUnauthenticatedPublicHeader( | 134 virtual bool OnUnauthenticatedPublicHeader( |
135 const QuicPacketPublicHeader& header); | 135 const QuicPacketPublicHeader& header); |
136 | 136 |
137 // Called by OnUnauthenticatedPublicHeader when the packet is not for a | 137 // Called by OnUnauthenticatedPublicHeader when the packet is not for a |
138 // connection that the dispatcher has a record of, but is not handled by | 138 // connection that the dispatcher has a record of, but is not handled by |
139 // certain simple processing rules. This method may apply validity checks to | 139 // certain simple processing rules. This method may apply validity checks to |
140 // reject stray packets. If the packet appears to be valid, it calls | 140 // reject stray packets. If the packet appears to be valid, it calls |
141 // CreateQuicSession to create a new session for the packet. Returns the | 141 // CreateQuicSession to create a new session for the packet. Returns the |
142 // QuicServerSession that was created, or nullptr if the packet failed the | 142 // QuicServerSession that was created, or nullptr if the packet failed the |
143 // validity checks. | 143 // validity checks. |
144 virtual QuicServerSession* AdditionalValidityChecksThenCreateSession( | 144 virtual tools::QuicServerSession* AdditionalValidityChecksThenCreateSession( |
145 const QuicPacketPublicHeader& header, | 145 const QuicPacketPublicHeader& header, |
146 QuicConnectionId connection_id); | 146 QuicConnectionId connection_id); |
147 | 147 |
148 // 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 |
149 // will be owned by the dispatcher as time_wait_list_manager_ | 149 // will be owned by the dispatcher as time_wait_list_manager_ |
150 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); | 150 virtual tools::QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); |
151 | 151 |
152 QuicTimeWaitListManager* time_wait_list_manager() { | 152 tools::QuicTimeWaitListManager* time_wait_list_manager() { |
153 return time_wait_list_manager_.get(); | 153 return time_wait_list_manager_.get(); |
154 } | 154 } |
155 | 155 |
156 const QuicVersionVector& supported_versions() const { | 156 const QuicVersionVector& supported_versions() const { |
157 return supported_versions_; | 157 return supported_versions_; |
158 } | 158 } |
159 | 159 |
160 const IPEndPoint& current_server_address() { | 160 const IPEndPoint& current_server_address() { |
161 return current_server_address_; | 161 return current_server_address_; |
162 } | 162 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 const QuicConfig& config_; | 213 const QuicConfig& config_; |
214 | 214 |
215 const QuicCryptoServerConfig& crypto_config_; | 215 const QuicCryptoServerConfig& crypto_config_; |
216 | 216 |
217 // The list of connections waiting to write. | 217 // The list of connections waiting to write. |
218 WriteBlockedList write_blocked_list_; | 218 WriteBlockedList write_blocked_list_; |
219 | 219 |
220 SessionMap session_map_; | 220 SessionMap session_map_; |
221 | 221 |
222 // Entity that manages connection_ids in time wait state. | 222 // Entity that manages connection_ids in time wait state. |
223 scoped_ptr<QuicTimeWaitListManager> time_wait_list_manager_; | 223 scoped_ptr<tools::QuicTimeWaitListManager> time_wait_list_manager_; |
224 | 224 |
225 // The helper used for all connections. Owned by the server. | 225 // The helper used for all connections. Owned by the server. |
226 QuicConnectionHelperInterface* helper_; | 226 QuicConnectionHelperInterface* helper_; |
227 | 227 |
228 // An alarm which deletes closed sessions. | 228 // An alarm which deletes closed sessions. |
229 scoped_ptr<QuicAlarm> delete_sessions_alarm_; | 229 scoped_ptr<QuicAlarm> delete_sessions_alarm_; |
230 | 230 |
231 // The list of closed but not-yet-deleted sessions. | 231 // The list of closed but not-yet-deleted sessions. |
232 std::list<QuicServerSession*> closed_session_list_; | 232 std::list<tools::QuicServerSession*> closed_session_list_; |
233 | 233 |
234 // The writer to write to the socket with. | 234 // The writer to write to the socket with. |
235 scoped_ptr<QuicServerPacketWriter> writer_; | 235 scoped_ptr<QuicServerPacketWriter> writer_; |
236 | 236 |
237 // Used to create per-connection packet writers, not |writer_| itself. | 237 // Used to create per-connection packet writers, not |writer_| itself. |
238 scoped_ptr<PacketWriterFactory> packet_writer_factory_; | 238 scoped_ptr<PacketWriterFactory> packet_writer_factory_; |
239 | 239 |
240 // 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 |
241 PacketWriterFactoryAdapter connection_writer_factory_; | 241 PacketWriterFactoryAdapter connection_writer_factory_; |
242 | 242 |
(...skipping 10 matching lines...) Expand all Loading... |
253 | 253 |
254 QuicFramer framer_; | 254 QuicFramer framer_; |
255 scoped_ptr<QuicFramerVisitor> framer_visitor_; | 255 scoped_ptr<QuicFramerVisitor> framer_visitor_; |
256 | 256 |
257 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 257 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
258 }; | 258 }; |
259 | 259 |
260 } // namespace net | 260 } // namespace net |
261 | 261 |
262 #endif // NET_QUIC_QUIC_DISPATCHER_H_ | 262 #endif // NET_QUIC_QUIC_DISPATCHER_H_ |
OLD | NEW |