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 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 public: | 53 public: |
54 virtual ~PacketWriterFactory() {} | 54 virtual ~PacketWriterFactory() {} |
55 | 55 |
56 virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer, | 56 virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer, |
57 QuicConnection* connection) = 0; | 57 QuicConnection* connection) = 0; |
58 }; | 58 }; |
59 | 59 |
60 // Creates ordinary QuicPerConnectionPacketWriter instances. | 60 // Creates ordinary QuicPerConnectionPacketWriter instances. |
61 class DefaultPacketWriterFactory : public PacketWriterFactory { | 61 class DefaultPacketWriterFactory : public PacketWriterFactory { |
62 public: | 62 public: |
63 virtual ~DefaultPacketWriterFactory() {} | 63 ~DefaultPacketWriterFactory() override {} |
64 | 64 |
65 virtual QuicPacketWriter* Create( | 65 QuicPacketWriter* Create(QuicServerPacketWriter* writer, |
66 QuicServerPacketWriter* writer, | 66 QuicConnection* connection) override; |
67 QuicConnection* connection) override; | |
68 }; | 67 }; |
69 | 68 |
70 // Ideally we'd have a linked_hash_set: the boolean is unused. | 69 // Ideally we'd have a linked_hash_set: the boolean is unused. |
71 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; | 70 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; |
72 | 71 |
73 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must | 72 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must |
74 // live until epoll_server Shutdown. |supported_versions| specifies the list | 73 // live until epoll_server Shutdown. |supported_versions| specifies the list |
75 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, | 74 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, |
76 // which is used to create per-connection writers. | 75 // which is used to create per-connection writers. |
77 QuicDispatcher(const QuicConfig& config, | 76 QuicDispatcher(const QuicConfig& config, |
78 const QuicCryptoServerConfig& crypto_config, | 77 const QuicCryptoServerConfig& crypto_config, |
79 const QuicVersionVector& supported_versions, | 78 const QuicVersionVector& supported_versions, |
80 PacketWriterFactory* packet_writer_factory, | 79 PacketWriterFactory* packet_writer_factory, |
81 QuicConnectionHelperInterface* helper); | 80 QuicConnectionHelperInterface* helper); |
82 | 81 |
83 virtual ~QuicDispatcher(); | 82 ~QuicDispatcher() override; |
84 | 83 |
85 // Takes ownership of the packet writer. | 84 // Takes ownership of the packet writer. |
86 virtual void Initialize(QuicServerPacketWriter* writer); | 85 virtual void Initialize(QuicServerPacketWriter* writer); |
87 | 86 |
88 // Process the incoming packet by creating a new session, passing it to | 87 // Process the incoming packet by creating a new session, passing it to |
89 // an existing session, or passing it to the TimeWaitListManager. | 88 // an existing session, or passing it to the TimeWaitListManager. |
90 virtual void ProcessPacket(const IPEndPoint& server_address, | 89 void ProcessPacket(const IPEndPoint& server_address, |
91 const IPEndPoint& client_address, | 90 const IPEndPoint& client_address, |
92 const QuicEncryptedPacket& packet) override; | 91 const QuicEncryptedPacket& packet) override; |
93 | 92 |
94 // Returns true if there's anything in the blocked writer list. | 93 // Returns true if there's anything in the blocked writer list. |
95 virtual bool HasPendingWrites() const; | 94 virtual bool HasPendingWrites() const; |
96 | 95 |
97 // Sends ConnectionClose frames to all connected clients. | 96 // Sends ConnectionClose frames to all connected clients. |
98 void Shutdown(); | 97 void Shutdown(); |
99 | 98 |
100 // QuicBlockedWriterInterface implementation: | 99 // QuicBlockedWriterInterface implementation: |
101 // Called when the socket becomes writable to allow queued writes to happen. | 100 // Called when the socket becomes writable to allow queued writes to happen. |
102 virtual void OnCanWrite() override; | 101 void OnCanWrite() override; |
103 | 102 |
104 // QuicServerSessionVisitor interface implementation: | 103 // QuicServerSessionVisitor interface implementation: |
105 // Ensure that the closed connection is cleaned up asynchronously. | 104 // Ensure that the closed connection is cleaned up asynchronously. |
106 virtual void OnConnectionClosed(QuicConnectionId connection_id, | 105 void OnConnectionClosed(QuicConnectionId connection_id, |
107 QuicErrorCode error) override; | 106 QuicErrorCode error) override; |
108 | 107 |
109 // Queues the blocked writer for later resumption. | 108 // Queues the blocked writer for later resumption. |
110 virtual void OnWriteBlocked( | 109 void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) override; |
111 QuicBlockedWriterInterface* blocked_writer) override; | |
112 | 110 |
113 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; | 111 typedef base::hash_map<QuicConnectionId, QuicSession*> SessionMap; |
114 | 112 |
115 // Deletes all sessions on the closed session list and clears the list. | 113 // Deletes all sessions on the closed session list and clears the list. |
116 void DeleteSessions(); | 114 void DeleteSessions(); |
117 | 115 |
118 const SessionMap& session_map() const { return session_map_; } | 116 const SessionMap& session_map() const { return session_map_; } |
119 | 117 |
120 protected: | 118 protected: |
121 virtual QuicSession* CreateQuicSession(QuicConnectionId connection_id, | 119 virtual QuicSession* CreateQuicSession(QuicConnectionId connection_id, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 class QuicFramerVisitor; | 174 class QuicFramerVisitor; |
177 friend class net::test::QuicDispatcherPeer; | 175 friend class net::test::QuicDispatcherPeer; |
178 | 176 |
179 // An adapter that creates packet writers using the dispatcher's | 177 // An adapter that creates packet writers using the dispatcher's |
180 // PacketWriterFactory and shared writer. Essentially, it just curries the | 178 // PacketWriterFactory and shared writer. Essentially, it just curries the |
181 // writer argument away from QuicDispatcher::PacketWriterFactory. | 179 // writer argument away from QuicDispatcher::PacketWriterFactory. |
182 class PacketWriterFactoryAdapter : | 180 class PacketWriterFactoryAdapter : |
183 public QuicConnection::PacketWriterFactory { | 181 public QuicConnection::PacketWriterFactory { |
184 public: | 182 public: |
185 PacketWriterFactoryAdapter(QuicDispatcher* dispatcher); | 183 PacketWriterFactoryAdapter(QuicDispatcher* dispatcher); |
186 virtual ~PacketWriterFactoryAdapter (); | 184 ~PacketWriterFactoryAdapter() override; |
187 | 185 |
188 virtual QuicPacketWriter* Create(QuicConnection* connection) const override; | 186 QuicPacketWriter* Create(QuicConnection* connection) const override; |
189 | 187 |
190 private: | 188 private: |
191 QuicDispatcher* dispatcher_; | 189 QuicDispatcher* dispatcher_; |
192 }; | 190 }; |
193 | 191 |
194 // Called by |framer_visitor_| when the private header has been parsed | 192 // Called by |framer_visitor_| when the private header has been parsed |
195 // of a data packet that is destined for the time wait manager. | 193 // of a data packet that is destined for the time wait manager. |
196 void OnUnauthenticatedHeader(const QuicPacketHeader& header); | 194 void OnUnauthenticatedHeader(const QuicPacketHeader& header); |
197 | 195 |
198 // Removes the session from the session map and write blocked list, and | 196 // Removes the session from the session map and write blocked list, and |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 242 |
245 QuicFramer framer_; | 243 QuicFramer framer_; |
246 scoped_ptr<QuicFramerVisitor> framer_visitor_; | 244 scoped_ptr<QuicFramerVisitor> framer_visitor_; |
247 | 245 |
248 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 246 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
249 }; | 247 }; |
250 | 248 |
251 } // namespace net | 249 } // namespace net |
252 | 250 |
253 #endif // NET_QUIC_QUIC_DISPATCHER_H_ | 251 #endif // NET_QUIC_QUIC_DISPATCHER_H_ |
OLD | NEW |