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

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

Issue 340433002: Port QuicServer to Chrome network stack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix invalid memory access + blocked writers Created 6 years, 6 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_session.h" 22 #include "net/quic/quic_server_session.h"
22 #include "net/quic/quic_time_wait_list_manager.h" 23 #include "net/quic/quic_time_wait_list_manager.h"
23 24
24 #if defined(COMPILER_GCC) 25 #if defined(COMPILER_GCC)
25 namespace BASE_HASH_NAMESPACE { 26 namespace BASE_HASH_NAMESPACE {
26 template <> 27 template <>
27 struct hash<net::QuicBlockedWriterInterface*> { 28 struct hash<net::QuicBlockedWriterInterface*> {
28 std::size_t operator()(const net::QuicBlockedWriterInterface* ptr) const { 29 std::size_t operator()(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
34 35
35 namespace net { 36 namespace net {
36 37
37 class QuicConfig; 38 class QuicConfig;
38 class QuicCryptoServerConfig; 39 class QuicCryptoServerConfig;
39 class QuicPacketWriterWrapper; 40 class QuicPacketWriterWrapper;
wtc 2014/06/18 02:04:46 Delete this unused forward declaration.
dmziegler 2014/06/18 20:13:41 Done.
40 class QuicSession; 41 class QuicSession;
41 class UDPServerSocket; 42 class UDPServerSocket;
wtc 2014/06/18 02:04:46 Delete this unused forward declaration.
dmziegler 2014/06/18 20:13:41 Done.
42 43
43 namespace test { 44 namespace test {
44 class QuicDispatcherPeer; 45 class QuicDispatcherPeer;
45 } // namespace test 46 } // namespace test
46 47
47 class DeleteSessionsAlarm; 48 class DeleteSessionsAlarm;
48 49
49 class QuicDispatcher : public QuicServerSessionVisitor { 50 class QuicDispatcher : public QuicServerSessionVisitor,
51 public QuicServerPacketWriterVisitor {
50 public: 52 public:
51 // Ideally we'd have a linked_hash_set: the boolean is unused. 53 // Ideally we'd have a linked_hash_set: the boolean is unused.
52 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; 54 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList;
53 55
54 // Due to the way delete_sessions_closure_ is registered, the Dispatcher 56 // Due to the way delete_sessions_closure_ is registered, the Dispatcher
55 // must live until epoll_server Shutdown. |supported_versions| specifies the 57 // must live until epoll_server Shutdown. |supported_versions| specifies the
56 // list of supported QUIC versions. 58 // list of supported QUIC versions.
57 QuicDispatcher(const QuicConfig& config, 59 QuicDispatcher(const QuicConfig& config,
58 const QuicCryptoServerConfig& crypto_config, 60 const QuicCryptoServerConfig& crypto_config,
59 const QuicVersionVector& supported_versions, 61 const QuicVersionVector& supported_versions,
60 QuicConnectionHelperInterface* helper, 62 QuicConnectionHelperInterface* helper,
61 uint32 initial_flow_control_window_bytes); 63 uint32 initial_flow_control_window_bytes);
62 64
63 virtual ~QuicDispatcher(); 65 virtual ~QuicDispatcher();
64 66
65 // Takes ownership of the packet writer 67 // Takes ownership of the packet writer
66 virtual void Initialize(QuicPacketWriter* writer); 68 virtual void Initialize(QuicServerPacketWriter* writer);
67 69
68 // Process the incoming packet by creating a new session, passing it to 70 // Process the incoming packet by creating a new session, passing it to
69 // an existing session, or passing it to the TimeWaitListManager. 71 // an existing session, or passing it to the TimeWaitListManager.
70 virtual void ProcessPacket(const IPEndPoint& server_address, 72 virtual void ProcessPacket(const IPEndPoint& server_address,
71 const IPEndPoint& client_address, 73 const IPEndPoint& client_address,
72 const QuicEncryptedPacket& packet); 74 const QuicEncryptedPacket& packet);
73 75
74 // Called when the socket becomes writable to allow queued writes to happen. 76 // Called when the socket becomes writable to allow queued writes to happen.
75 virtual void OnCanWrite(); 77 virtual void OnCanWrite() OVERRIDE;
wtc 2014/06/18 02:04:46 Add a comment to point out that this method is in
dmziegler 2014/06/18 20:13:40 Done (Is now QuicBlockedWriterInterface).
76 78
77 // Returns true if there's anything in the blocked writer list. 79 // Returns true if there's anything in the blocked writer list.
78 virtual bool HasPendingWrites() const; 80 virtual bool HasPendingWrites() const;
79 81
80 // Sends ConnectionClose frames to all connected clients. 82 // Sends ConnectionClose frames to all connected clients.
81 void Shutdown(); 83 void Shutdown();
82 84
83 // QuicServerSessionVisitor interface implementation: 85 // QuicServerSessionVisitor interface implementation:
84 // Ensure that the closed connection is cleaned up asynchronously. 86 // Ensure that the closed connection is cleaned up asynchronously.
85 virtual void OnConnectionClosed(QuicConnectionId connection_id, 87 virtual void OnConnectionClosed(QuicConnectionId connection_id,
(...skipping 23 matching lines...) Expand all
109 111
110 // Called by |framer_visitor_| when the public header has been parsed. 112 // Called by |framer_visitor_| when the public header has been parsed.
111 virtual bool OnUnauthenticatedPublicHeader( 113 virtual bool OnUnauthenticatedPublicHeader(
112 const QuicPacketPublicHeader& header); 114 const QuicPacketPublicHeader& header);
113 115
114 // Create and return the time wait list manager for this dispatcher, which 116 // Create and return the time wait list manager for this dispatcher, which
115 // will be owned by the dispatcher as time_wait_list_manager_ 117 // will be owned by the dispatcher as time_wait_list_manager_
116 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); 118 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager();
117 119
118 // Replaces the packet writer with |writer|. Takes ownership of |writer|. 120 // Replaces the packet writer with |writer|. Takes ownership of |writer|.
119 void set_writer(QuicPacketWriter* writer) { 121 void set_writer(QuicServerPacketWriter* writer) {
120 writer_.reset(writer); 122 writer_.reset(writer);
121 } 123 }
122 124
123 QuicTimeWaitListManager* time_wait_list_manager() { 125 QuicTimeWaitListManager* time_wait_list_manager() {
124 return time_wait_list_manager_.get(); 126 return time_wait_list_manager_.get();
125 } 127 }
126 128
127 const QuicVersionVector& supported_versions() const { 129 const QuicVersionVector& supported_versions() const {
128 return supported_versions_; 130 return supported_versions_;
129 } 131 }
(...skipping 18 matching lines...) Expand all
148 } 150 }
149 151
150 const QuicConfig& config() const { return config_; } 152 const QuicConfig& config() const { return config_; }
151 153
152 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } 154 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; }
153 155
154 QuicFramer* framer() { return &framer_; } 156 QuicFramer* framer() { return &framer_; }
155 157
156 QuicConnectionHelperInterface* helper() { return helper_; } 158 QuicConnectionHelperInterface* helper() { return helper_; }
157 159
158 QuicPacketWriter* writer() { return writer_.get(); } 160 QuicPacketWriter* writer() { return writer_.get(); }
wtc 2014/06/18 02:04:46 Should this return a QuicServerPacketWriter* ?
dmziegler 2014/06/18 20:13:41 Done.
159 161
160 uint32 initial_flow_control_window_bytes() const { 162 uint32 initial_flow_control_window_bytes() const {
161 return initial_flow_control_window_bytes_; 163 return initial_flow_control_window_bytes_;
162 } 164 }
163 165
164 private: 166 private:
165 class QuicFramerVisitor; 167 class QuicFramerVisitor;
166 friend class net::test::QuicDispatcherPeer; 168 friend class net::test::QuicDispatcherPeer;
167 169
168 // Called by |framer_visitor_| when the private header has been parsed 170 // Called by |framer_visitor_| when the private header has been parsed
(...skipping 21 matching lines...) Expand all
190 // The helper used for all connections. Owned by the server. 192 // The helper used for all connections. Owned by the server.
191 QuicConnectionHelperInterface* helper_; 193 QuicConnectionHelperInterface* helper_;
192 194
193 // An alarm which deletes closed sessions. 195 // An alarm which deletes closed sessions.
194 scoped_ptr<QuicAlarm> delete_sessions_alarm_; 196 scoped_ptr<QuicAlarm> delete_sessions_alarm_;
195 197
196 // The list of closed but not-yet-deleted sessions. 198 // The list of closed but not-yet-deleted sessions.
197 std::list<QuicSession*> closed_session_list_; 199 std::list<QuicSession*> closed_session_list_;
198 200
199 // The writer to write to the socket with. 201 // The writer to write to the socket with.
200 scoped_ptr<QuicPacketWriter> writer_; 202 scoped_ptr<QuicServerPacketWriter> writer_;
201 203
202 // This vector contains QUIC versions which we currently support. 204 // This vector contains QUIC versions which we currently support.
203 // This should be ordered such that the highest supported version is the first 205 // This should be ordered such that the highest supported version is the first
204 // element, with subsequent elements in descending order (versions can be 206 // element, with subsequent elements in descending order (versions can be
205 // skipped as necessary). 207 // skipped as necessary).
206 const QuicVersionVector supported_versions_; 208 const QuicVersionVector supported_versions_;
207 209
208 // Versions which do not support flow control (introduced in QUIC_VERSION_17). 210 // Versions which do not support flow control (introduced in QUIC_VERSION_17).
209 // This is used to construct new QuicConnections when flow control is disabled 211 // This is used to construct new QuicConnections when flow control is disabled
210 // via flag. 212 // via flag.
(...skipping 19 matching lines...) Expand all
230 // Initial flow control window size to advertize to peer on newly created 232 // Initial flow control window size to advertize to peer on newly created
231 // connections. 233 // connections.
232 const uint32 initial_flow_control_window_bytes_; 234 const uint32 initial_flow_control_window_bytes_;
233 235
234 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); 236 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher);
235 }; 237 };
236 238
237 } // namespace net 239 } // namespace net
238 240
239 #endif // NET_QUIC_QUIC_DISPATCHER_H_ 241 #endif // NET_QUIC_QUIC_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698