Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: net/quic/quic_dispatcher.h

Issue 467963002: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Wan-Teh's comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/quic/quic_server_session.h"
23 #include "net/quic/quic_time_wait_list_manager.h" 23 #include "net/quic/quic_time_wait_list_manager.h"
24 24
25 #if defined(COMPILER_GCC)
26 namespace BASE_HASH_NAMESPACE {
27 template <>
28 struct hash<net::QuicBlockedWriterInterface*> {
29 std::size_t operator()(const net::QuicBlockedWriterInterface* ptr) const {
30 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
31 }
32 };
33 }
34 #endif
35
36 namespace net { 25 namespace net {
37 26
38 class QuicConfig; 27 class QuicConfig;
39 class QuicCryptoServerConfig; 28 class QuicCryptoServerConfig;
40 class QuicSession; 29 class QuicSession;
41 30
42 namespace test { 31 namespace test {
43 class QuicDispatcherPeer; 32 class QuicDispatcherPeer;
44 } // namespace test 33 } // namespace test
45 34
46 class DeleteSessionsAlarm; 35 class DeleteSessionsAlarm;
47 36
48 class ProcessPacketInterface { 37 class ProcessPacketInterface {
49 public: 38 public:
50 virtual ~ProcessPacketInterface() {} 39 virtual ~ProcessPacketInterface() {}
51 virtual void ProcessPacket(const IPEndPoint& server_address, 40 virtual void ProcessPacket(const IPEndPoint& server_address,
52 const IPEndPoint& client_address, 41 const IPEndPoint& client_address,
53 const QuicEncryptedPacket& packet) = 0; 42 const QuicEncryptedPacket& packet) = 0;
54 }; 43 };
55 44
56 class QuicDispatcher : public QuicBlockedWriterInterface, 45 class QuicDispatcher : public QuicBlockedWriterInterface,
57 public QuicServerSessionVisitor, 46 public QuicServerSessionVisitor,
58 public ProcessPacketInterface { 47 public ProcessPacketInterface {
59 public: 48 public:
49 // Creates per-connection packet writers out of the QuicDispatcher's shared
50 // QuicPacketWriter. The per-connection writers' IsWriteBlocked() state must
51 // always be the same as the shared writer's IsWriteBlocked(), or else the
52 // QuicDispatcher::OnCanWrite logic will not work. (This will hopefully be
53 // cleaned up for bug 16950226.)
54 class PacketWriterFactory {
55 public:
56 virtual ~PacketWriterFactory() {}
57
58 virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer,
59 QuicConnection* connection) = 0;
60 };
61
62 // Creates ordinary QuicPerConnectionPacketWriter instances.
63 class DefaultPacketWriterFactory : public PacketWriterFactory {
64 public:
65 virtual ~DefaultPacketWriterFactory() {}
66
67 virtual QuicPacketWriter* Create(
68 QuicServerPacketWriter* writer,
69 QuicConnection* connection) OVERRIDE;
70 };
71
60 // Ideally we'd have a linked_hash_set: the boolean is unused. 72 // Ideally we'd have a linked_hash_set: the boolean is unused.
61 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; 73 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList;
62 74
63 // Due to the way delete_sessions_closure_ is registered, the Dispatcher 75 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must
64 // must live until epoll_server Shutdown. |supported_versions| specifies the 76 // live until epoll_server Shutdown. |supported_versions| specifies the list
65 // list of supported QUIC versions. 77 // of supported QUIC versions. Takes ownership of |packet_writer_factory|,
78 // which is used to create per-connection writers.
66 QuicDispatcher(const QuicConfig& config, 79 QuicDispatcher(const QuicConfig& config,
67 const QuicCryptoServerConfig& crypto_config, 80 const QuicCryptoServerConfig& crypto_config,
68 const QuicVersionVector& supported_versions, 81 const QuicVersionVector& supported_versions,
82 PacketWriterFactory* packet_writer_factory,
69 QuicConnectionHelperInterface* helper); 83 QuicConnectionHelperInterface* helper);
70 84
71 virtual ~QuicDispatcher(); 85 virtual ~QuicDispatcher();
72 86
73 // Takes ownership of the packet writer 87 // Takes ownership of the packet writer
74 virtual void Initialize(QuicServerPacketWriter* writer); 88 virtual void Initialize(QuicServerPacketWriter* writer);
75 89
76 // 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
77 // an existing session, or passing it to the TimeWaitListManager. 91 // an existing session, or passing it to the TimeWaitListManager.
78 virtual void ProcessPacket(const IPEndPoint& server_address, 92 virtual void ProcessPacket(const IPEndPoint& server_address,
(...skipping 27 matching lines...) Expand all
106 const SessionMap& session_map() const { return session_map_; } 120 const SessionMap& session_map() const { return session_map_; }
107 121
108 protected: 122 protected:
109 virtual QuicSession* CreateQuicSession(QuicConnectionId connection_id, 123 virtual QuicSession* CreateQuicSession(QuicConnectionId connection_id,
110 const IPEndPoint& server_address, 124 const IPEndPoint& server_address,
111 const IPEndPoint& client_address); 125 const IPEndPoint& client_address);
112 126
113 virtual QuicConnection* CreateQuicConnection( 127 virtual QuicConnection* CreateQuicConnection(
114 QuicConnectionId connection_id, 128 QuicConnectionId connection_id,
115 const IPEndPoint& server_address, 129 const IPEndPoint& server_address,
116 const IPEndPoint& client_address, 130 const IPEndPoint& client_address);
117 QuicPerConnectionPacketWriter* writer);
118 131
119 // Called by |framer_visitor_| when the public header has been parsed. 132 // Called by |framer_visitor_| when the public header has been parsed.
120 virtual bool OnUnauthenticatedPublicHeader( 133 virtual bool OnUnauthenticatedPublicHeader(
121 const QuicPacketPublicHeader& header); 134 const QuicPacketPublicHeader& header);
122 135
123 // Create and return the time wait list manager for this dispatcher, which 136 // Create and return the time wait list manager for this dispatcher, which
124 // will be owned by the dispatcher as time_wait_list_manager_ 137 // will be owned by the dispatcher as time_wait_list_manager_
125 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); 138 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager();
126 139
127 // Replaces the packet writer with |writer|. Takes ownership of |writer|. 140 // Replaces the packet writer with |writer|. Takes ownership of |writer|.
(...skipping 22 matching lines...) Expand all
150 const QuicConfig& config() const { return config_; } 163 const QuicConfig& config() const { return config_; }
151 164
152 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } 165 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; }
153 166
154 QuicFramer* framer() { return &framer_; } 167 QuicFramer* framer() { return &framer_; }
155 168
156 QuicConnectionHelperInterface* helper() { return helper_; } 169 QuicConnectionHelperInterface* helper() { return helper_; }
157 170
158 QuicServerPacketWriter* writer() { return writer_.get(); } 171 QuicServerPacketWriter* writer() { return writer_.get(); }
159 172
173 const QuicConnection::PacketWriterFactory& connection_writer_factory() {
174 return connection_writer_factory_;
175 }
176
160 private: 177 private:
161 class QuicFramerVisitor; 178 class QuicFramerVisitor;
162 friend class net::test::QuicDispatcherPeer; 179 friend class net::test::QuicDispatcherPeer;
163 180
181 // An adapter that creates packet writers using the dispatcher's
182 // PacketWriterFactory and shared writer. Essentially, it just curries the
183 // writer argument away from QuicDispatcher::PacketWriterFactory.
184 class PacketWriterFactoryAdapter :
185 public QuicConnection::PacketWriterFactory {
186 public:
187 PacketWriterFactoryAdapter(QuicDispatcher* dispatcher);
188 virtual ~PacketWriterFactoryAdapter ();
189
190 virtual QuicPacketWriter* Create(QuicConnection* connection) const OVERRIDE;
191
192 private:
193 QuicDispatcher* dispatcher_;
194 };
195
164 // Called by |framer_visitor_| when the private header has been parsed 196 // Called by |framer_visitor_| when the private header has been parsed
165 // of a data packet that is destined for the time wait manager. 197 // of a data packet that is destined for the time wait manager.
166 void OnUnauthenticatedHeader(const QuicPacketHeader& header); 198 void OnUnauthenticatedHeader(const QuicPacketHeader& header);
167 199
168 // Removes the session from the session map and write blocked list, and 200 // Removes the session from the session map and write blocked list, and
169 // adds the ConnectionId to the time-wait list. 201 // adds the ConnectionId to the time-wait list.
170 void CleanUpSession(SessionMap::iterator it); 202 void CleanUpSession(SessionMap::iterator it);
171 203
172 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); 204 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header);
173 205
(...skipping 14 matching lines...) Expand all
188 220
189 // An alarm which deletes closed sessions. 221 // An alarm which deletes closed sessions.
190 scoped_ptr<QuicAlarm> delete_sessions_alarm_; 222 scoped_ptr<QuicAlarm> delete_sessions_alarm_;
191 223
192 // The list of closed but not-yet-deleted sessions. 224 // The list of closed but not-yet-deleted sessions.
193 std::list<QuicSession*> closed_session_list_; 225 std::list<QuicSession*> closed_session_list_;
194 226
195 // The writer to write to the socket with. 227 // The writer to write to the socket with.
196 scoped_ptr<QuicServerPacketWriter> writer_; 228 scoped_ptr<QuicServerPacketWriter> writer_;
197 229
230 // Used to create per-connection packet writers, not |writer_| itself.
231 scoped_ptr<PacketWriterFactory> packet_writer_factory_;
232
233 // Passed in to QuicConnection for it to create the per-connection writers
234 PacketWriterFactoryAdapter connection_writer_factory_;
235
198 // This vector contains QUIC versions which we currently support. 236 // This vector contains QUIC versions which we currently support.
199 // This should be ordered such that the highest supported version is the first 237 // This should be ordered such that the highest supported version is the first
200 // element, with subsequent elements in descending order (versions can be 238 // element, with subsequent elements in descending order (versions can be
201 // skipped as necessary). 239 // skipped as necessary).
202 const QuicVersionVector supported_versions_; 240 const QuicVersionVector supported_versions_;
203 241
204 // Information about the packet currently being handled. 242 // Information about the packet currently being handled.
205 IPEndPoint current_client_address_; 243 IPEndPoint current_client_address_;
206 IPEndPoint current_server_address_; 244 IPEndPoint current_server_address_;
207 const QuicEncryptedPacket* current_packet_; 245 const QuicEncryptedPacket* current_packet_;
208 246
209 QuicFramer framer_; 247 QuicFramer framer_;
210 scoped_ptr<QuicFramerVisitor> framer_visitor_; 248 scoped_ptr<QuicFramerVisitor> framer_visitor_;
211 249
212 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); 250 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher);
213 }; 251 };
214 252
215 } // namespace net 253 } // namespace net
216 254
217 #endif // NET_QUIC_QUIC_DISPATCHER_H_ 255 #endif // NET_QUIC_QUIC_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698