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

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: Address review comments and fix blocked writers using callbacks 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 QuicSession; 40 class QuicSession;
41 class UDPServerSocket;
42 41
43 namespace test { 42 namespace test {
44 class QuicDispatcherPeer; 43 class QuicDispatcherPeer;
45 } // namespace test 44 } // namespace test
46 45
47 class DeleteSessionsAlarm; 46 class DeleteSessionsAlarm;
48 47
49 class QuicDispatcher : public QuicServerSessionVisitor { 48 class QuicDispatcher : public QuicServerSessionVisitor,
49 public QuicBlockedWriterInterface {
50 public: 50 public:
51 // Ideally we'd have a linked_hash_set: the boolean is unused. 51 // Ideally we'd have a linked_hash_set: the boolean is unused.
52 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; 52 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList;
53 53
54 // Due to the way delete_sessions_closure_ is registered, the Dispatcher 54 // Due to the way delete_sessions_closure_ is registered, the Dispatcher
55 // must live until epoll_server Shutdown. |supported_versions| specifies the 55 // must live until epoll_server Shutdown. |supported_versions| specifies the
56 // list of supported QUIC versions. 56 // list of supported QUIC versions.
57 QuicDispatcher(const QuicConfig& config, 57 QuicDispatcher(const QuicConfig& config,
58 const QuicCryptoServerConfig& crypto_config, 58 const QuicCryptoServerConfig& crypto_config,
59 const QuicVersionVector& supported_versions, 59 const QuicVersionVector& supported_versions,
60 QuicConnectionHelperInterface* helper, 60 QuicConnectionHelperInterface* helper,
61 uint32 initial_flow_control_window_bytes); 61 uint32 initial_flow_control_window_bytes);
62 62
63 virtual ~QuicDispatcher(); 63 virtual ~QuicDispatcher();
64 64
65 // Takes ownership of the packet writer 65 // Takes ownership of the packet writer
66 virtual void Initialize(QuicPacketWriter* writer); 66 virtual void Initialize(QuicServerPacketWriter* writer);
67 67
68 // Process the incoming packet by creating a new session, passing it to 68 // Process the incoming packet by creating a new session, passing it to
69 // an existing session, or passing it to the TimeWaitListManager. 69 // an existing session, or passing it to the TimeWaitListManager.
70 virtual void ProcessPacket(const IPEndPoint& server_address, 70 virtual void ProcessPacket(const IPEndPoint& server_address,
71 const IPEndPoint& client_address, 71 const IPEndPoint& client_address,
72 const QuicEncryptedPacket& packet); 72 const QuicEncryptedPacket& packet);
73 73
74 // Called when the socket becomes writable to allow queued writes to happen.
75 virtual void OnCanWrite();
76
77 // Returns true if there's anything in the blocked writer list. 74 // Returns true if there's anything in the blocked writer list.
78 virtual bool HasPendingWrites() const; 75 virtual bool HasPendingWrites() const;
79 76
80 // Sends ConnectionClose frames to all connected clients. 77 // Sends ConnectionClose frames to all connected clients.
81 void Shutdown(); 78 void Shutdown();
82 79
80 // QuicBlockedWriterInterface implementation:
81 // Called when the socket becomes writable to allow queued writes to happen.
82 virtual void OnCanWrite() OVERRIDE;
83
83 // QuicServerSessionVisitor interface implementation: 84 // QuicServerSessionVisitor interface implementation:
84 // Ensure that the closed connection is cleaned up asynchronously. 85 // Ensure that the closed connection is cleaned up asynchronously.
85 virtual void OnConnectionClosed(QuicConnectionId connection_id, 86 virtual void OnConnectionClosed(QuicConnectionId connection_id,
86 QuicErrorCode error) OVERRIDE; 87 QuicErrorCode error) OVERRIDE;
87 88
88 // Queues the blocked writer for later resumption. 89 // Queues the blocked writer for later resumption.
89 virtual void OnWriteBlocked(QuicBlockedWriterInterface* writer) OVERRIDE; 90 virtual void OnWriteBlocked(QuicBlockedWriterInterface* writer) OVERRIDE;
90 91
91 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; 92 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap;
92 93
(...skipping 16 matching lines...) Expand all
109 110
110 // Called by |framer_visitor_| when the public header has been parsed. 111 // Called by |framer_visitor_| when the public header has been parsed.
111 virtual bool OnUnauthenticatedPublicHeader( 112 virtual bool OnUnauthenticatedPublicHeader(
112 const QuicPacketPublicHeader& header); 113 const QuicPacketPublicHeader& header);
113 114
114 // Create and return the time wait list manager for this dispatcher, which 115 // Create and return the time wait list manager for this dispatcher, which
115 // will be owned by the dispatcher as time_wait_list_manager_ 116 // will be owned by the dispatcher as time_wait_list_manager_
116 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager(); 117 virtual QuicTimeWaitListManager* CreateQuicTimeWaitListManager();
117 118
118 // Replaces the packet writer with |writer|. Takes ownership of |writer|. 119 // Replaces the packet writer with |writer|. Takes ownership of |writer|.
119 void set_writer(QuicPacketWriter* writer) { 120 void set_writer(QuicServerPacketWriter* writer) {
120 writer_.reset(writer); 121 writer_.reset(writer);
121 } 122 }
122 123
123 QuicTimeWaitListManager* time_wait_list_manager() { 124 QuicTimeWaitListManager* time_wait_list_manager() {
124 return time_wait_list_manager_.get(); 125 return time_wait_list_manager_.get();
125 } 126 }
126 127
127 const QuicVersionVector& supported_versions() const { 128 const QuicVersionVector& supported_versions() const {
128 return supported_versions_; 129 return supported_versions_;
129 } 130 }
(...skipping 18 matching lines...) Expand all
148 } 149 }
149 150
150 const QuicConfig& config() const { return config_; } 151 const QuicConfig& config() const { return config_; }
151 152
152 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } 153 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; }
153 154
154 QuicFramer* framer() { return &framer_; } 155 QuicFramer* framer() { return &framer_; }
155 156
156 QuicConnectionHelperInterface* helper() { return helper_; } 157 QuicConnectionHelperInterface* helper() { return helper_; }
157 158
158 QuicPacketWriter* writer() { return writer_.get(); } 159 QuicServerPacketWriter* writer() { return writer_.get(); }
159 160
160 uint32 initial_flow_control_window_bytes() const { 161 uint32 initial_flow_control_window_bytes() const {
161 return initial_flow_control_window_bytes_; 162 return initial_flow_control_window_bytes_;
162 } 163 }
163 164
164 private: 165 private:
165 class QuicFramerVisitor; 166 class QuicFramerVisitor;
166 friend class net::test::QuicDispatcherPeer; 167 friend class net::test::QuicDispatcherPeer;
167 168
168 // Called by |framer_visitor_| when the private header has been parsed 169 // 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. 191 // The helper used for all connections. Owned by the server.
191 QuicConnectionHelperInterface* helper_; 192 QuicConnectionHelperInterface* helper_;
192 193
193 // An alarm which deletes closed sessions. 194 // An alarm which deletes closed sessions.
194 scoped_ptr<QuicAlarm> delete_sessions_alarm_; 195 scoped_ptr<QuicAlarm> delete_sessions_alarm_;
195 196
196 // The list of closed but not-yet-deleted sessions. 197 // The list of closed but not-yet-deleted sessions.
197 std::list<QuicSession*> closed_session_list_; 198 std::list<QuicSession*> closed_session_list_;
198 199
199 // The writer to write to the socket with. 200 // The writer to write to the socket with.
200 scoped_ptr<QuicPacketWriter> writer_; 201 scoped_ptr<QuicServerPacketWriter> writer_;
201 202
202 // This vector contains QUIC versions which we currently support. 203 // This vector contains QUIC versions which we currently support.
203 // This should be ordered such that the highest supported version is the first 204 // This should be ordered such that the highest supported version is the first
204 // element, with subsequent elements in descending order (versions can be 205 // element, with subsequent elements in descending order (versions can be
205 // skipped as necessary). 206 // skipped as necessary).
206 const QuicVersionVector supported_versions_; 207 const QuicVersionVector supported_versions_;
207 208
208 // Versions which do not support flow control (introduced in QUIC_VERSION_17). 209 // 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 210 // This is used to construct new QuicConnections when flow control is disabled
210 // via flag. 211 // via flag.
(...skipping 19 matching lines...) Expand all
230 // Initial flow control window size to advertize to peer on newly created 231 // Initial flow control window size to advertize to peer on newly created
231 // connections. 232 // connections.
232 const uint32 initial_flow_control_window_bytes_; 233 const uint32 initial_flow_control_window_bytes_;
233 234
234 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); 235 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher);
235 }; 236 };
236 237
237 } // namespace net 238 } // namespace net
238 239
239 #endif // NET_QUIC_QUIC_DISPATCHER_H_ 240 #endif // NET_QUIC_QUIC_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698