| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
| 9 #define NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 9 #define NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class QuicCryptoServerConfig; | 28 class QuicCryptoServerConfig; |
| 29 class QuicServerSessionBase; | 29 class QuicServerSessionBase; |
| 30 | 30 |
| 31 | 31 |
| 32 namespace test { | 32 namespace test { |
| 33 class QuicDispatcherPeer; | 33 class QuicDispatcherPeer; |
| 34 } // namespace test | 34 } // namespace test |
| 35 | 35 |
| 36 class QuicDispatcher : public QuicServerSessionVisitor, | 36 class QuicDispatcher : public QuicServerSessionVisitor, |
| 37 public ProcessPacketInterface, | 37 public ProcessPacketInterface, |
| 38 public QuicBlockedWriterInterface { | 38 public QuicBlockedWriterInterface, |
| 39 public QuicFramerVisitorInterface { |
| 39 public: | 40 public: |
| 40 // Ideally we'd have a linked_hash_set: the boolean is unused. | 41 // Ideally we'd have a linked_hash_set: the boolean is unused. |
| 41 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; | 42 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; |
| 42 | 43 |
| 43 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must | 44 // Due to the way delete_sessions_closure_ is registered, the Dispatcher must |
| 44 // live until server Shutdown. |supported_versions| specifies the std::list | 45 // live until server Shutdown. |supported_versions| specifies the std::list |
| 45 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, | 46 // of supported QUIC versions. Takes ownership of |packet_writer_factory|, |
| 46 // which is used to create per-connection writers. | 47 // which is used to create per-connection writers. |
| 47 QuicDispatcher(const QuicConfig& config, | 48 QuicDispatcher(const QuicConfig& config, |
| 48 const QuicCryptoServerConfig* crypto_config, | 49 const QuicCryptoServerConfig* crypto_config, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // ID for a connection that is not established yet. The current design will | 98 // ID for a connection that is not established yet. The current design will |
| 98 // send a handshake and then up to 50 or so data packets, and then it may | 99 // send a handshake and then up to 50 or so data packets, and then it may |
| 99 // resend the handshake packet up to 10 times. (Retransmitted packets are | 100 // resend the handshake packet up to 10 times. (Retransmitted packets are |
| 100 // sent with unique packet numbers.) | 101 // sent with unique packet numbers.) |
| 101 static const QuicPacketNumber kMaxReasonableInitialPacketNumber = 100; | 102 static const QuicPacketNumber kMaxReasonableInitialPacketNumber = 100; |
| 102 static_assert(kMaxReasonableInitialPacketNumber >= | 103 static_assert(kMaxReasonableInitialPacketNumber >= |
| 103 kInitialCongestionWindow + 10, | 104 kInitialCongestionWindow + 10, |
| 104 "kMaxReasonableInitialPacketNumber is unreasonably small " | 105 "kMaxReasonableInitialPacketNumber is unreasonably small " |
| 105 "relative to kInitialCongestionWindow."); | 106 "relative to kInitialCongestionWindow."); |
| 106 | 107 |
| 108 // QuicFramerVisitorInterface implementation. Not expected to be called |
| 109 // outside of this class. |
| 110 void OnPacket() override; |
| 111 // Called when the public header has been parsed. |
| 112 bool OnUnauthenticatedPublicHeader( |
| 113 const QuicPacketPublicHeader& header) override; |
| 114 // Called when the private header has been parsed of a data packet that is |
| 115 // destined for the time wait manager. |
| 116 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; |
| 117 void OnError(QuicFramer* framer) override; |
| 118 bool OnProtocolVersionMismatch(QuicVersion received_version) override; |
| 119 |
| 120 // The following methods should never get called because |
| 121 // OnUnauthenticatedPublicHeader() or OnUnauthenticatedHeader() (whichever |
| 122 // was called last), will return false and prevent a subsequent invocation |
| 123 // of these methods. Thus, the payload of the packet is never processed in |
| 124 // the dispatcher. |
| 125 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override; |
| 126 void OnVersionNegotiationPacket( |
| 127 const QuicVersionNegotiationPacket& packet) override; |
| 128 void OnDecryptedPacket(EncryptionLevel level) override; |
| 129 bool OnPacketHeader(const QuicPacketHeader& header) override; |
| 130 void OnRevivedPacket() override; |
| 131 void OnFecProtectedPayload(base::StringPiece payload) override; |
| 132 bool OnStreamFrame(const QuicStreamFrame& frame) override; |
| 133 bool OnAckFrame(const QuicAckFrame& frame) override; |
| 134 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override; |
| 135 bool OnPingFrame(const QuicPingFrame& frame) override; |
| 136 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; |
| 137 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; |
| 138 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
| 139 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
| 140 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
| 141 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override; |
| 142 void OnFecData(base::StringPiece redundancy) override; |
| 143 void OnPacketComplete() override; |
| 144 |
| 107 protected: | 145 protected: |
| 108 virtual QuicServerSessionBase* CreateQuicSession( | 146 virtual QuicServerSessionBase* CreateQuicSession( |
| 109 QuicConnectionId connection_id, | 147 QuicConnectionId connection_id, |
| 110 const IPEndPoint& client_address); | 148 const IPEndPoint& client_address); |
| 111 | 149 |
| 112 // Called by |framer_visitor_| when the public header has been parsed. | |
| 113 virtual bool OnUnauthenticatedPublicHeader( | |
| 114 const QuicPacketPublicHeader& header); | |
| 115 | |
| 116 // Values to be returned by ValidityChecks() to indicate what should be done | 150 // Values to be returned by ValidityChecks() to indicate what should be done |
| 117 // with a packet. Fates with greater values are considered to be higher | 151 // with a packet. Fates with greater values are considered to be higher |
| 118 // priority, in that if one validity check indicates a lower-valued fate and | 152 // priority, in that if one validity check indicates a lower-valued fate and |
| 119 // another validity check indicates a higher-valued fate, the higher-valued | 153 // another validity check indicates a higher-valued fate, the higher-valued |
| 120 // fate should be obeyed. | 154 // fate should be obeyed. |
| 121 enum QuicPacketFate { | 155 enum QuicPacketFate { |
| 122 // Process the packet normally, which is usually to establish a connection. | 156 // Process the packet normally, which is usually to establish a connection. |
| 123 kFateProcess, | 157 kFateProcess, |
| 124 // Put the connection ID into time-wait state and send a public reset. | 158 // Put the connection ID into time-wait state and send a public reset. |
| 125 kFateTimeWait, | 159 kFateTimeWait, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // Creates per-connection packet writers out of the QuicDispatcher's shared | 195 // Creates per-connection packet writers out of the QuicDispatcher's shared |
| 162 // QuicPacketWriter. The per-connection writers' IsWriteBlocked() state must | 196 // QuicPacketWriter. The per-connection writers' IsWriteBlocked() state must |
| 163 // always be the same as the shared writer's IsWriteBlocked(), or else the | 197 // always be the same as the shared writer's IsWriteBlocked(), or else the |
| 164 // QuicDispatcher::OnCanWrite logic will not work. (This will hopefully be | 198 // QuicDispatcher::OnCanWrite logic will not work. (This will hopefully be |
| 165 // cleaned up for bug 16950226.) | 199 // cleaned up for bug 16950226.) |
| 166 virtual QuicPacketWriter* CreatePerConnectionWriter(); | 200 virtual QuicPacketWriter* CreatePerConnectionWriter(); |
| 167 | 201 |
| 168 void SetLastError(QuicErrorCode error); | 202 void SetLastError(QuicErrorCode error); |
| 169 | 203 |
| 170 private: | 204 private: |
| 171 class QuicFramerVisitor; | |
| 172 friend class net::test::QuicDispatcherPeer; | 205 friend class net::test::QuicDispatcherPeer; |
| 173 | 206 |
| 174 // Called by |framer_visitor_| when the private header has been parsed | |
| 175 // of a data packet that is destined for the time wait manager. | |
| 176 void OnUnauthenticatedHeader(const QuicPacketHeader& header); | |
| 177 | |
| 178 // Removes the session from the session map and write blocked list, and adds | 207 // Removes the session from the session map and write blocked list, and adds |
| 179 // the ConnectionId to the time-wait list. If |session_closed_statelessly| is | 208 // the ConnectionId to the time-wait list. If |session_closed_statelessly| is |
| 180 // true, any future packets for the ConnectionId will be black-holed. | 209 // true, any future packets for the ConnectionId will be black-holed. |
| 181 void CleanUpSession(SessionMap::iterator it, bool session_closed_statelessly); | 210 void CleanUpSession(SessionMap::iterator it, bool session_closed_statelessly); |
| 182 | 211 |
| 183 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); | 212 bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header); |
| 184 | 213 |
| 185 const QuicConfig& config_; | 214 const QuicConfig& config_; |
| 186 | 215 |
| 187 const QuicCryptoServerConfig* crypto_config_; | 216 const QuicCryptoServerConfig* crypto_config_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 216 // element, with subsequent elements in descending order (versions can be | 245 // element, with subsequent elements in descending order (versions can be |
| 217 // skipped as necessary). | 246 // skipped as necessary). |
| 218 const QuicVersionVector supported_versions_; | 247 const QuicVersionVector supported_versions_; |
| 219 | 248 |
| 220 // Information about the packet currently being handled. | 249 // Information about the packet currently being handled. |
| 221 IPEndPoint current_client_address_; | 250 IPEndPoint current_client_address_; |
| 222 IPEndPoint current_server_address_; | 251 IPEndPoint current_server_address_; |
| 223 const QuicEncryptedPacket* current_packet_; | 252 const QuicEncryptedPacket* current_packet_; |
| 224 | 253 |
| 225 QuicFramer framer_; | 254 QuicFramer framer_; |
| 226 scoped_ptr<QuicFramerVisitor> framer_visitor_; | |
| 227 | 255 |
| 228 // The last error set by SetLastError(), which is called by | 256 // The last error set by SetLastError(), which is called by |
| 229 // framer_visitor_->OnError(). | 257 // framer_visitor_->OnError(). |
| 230 QuicErrorCode last_error_; | 258 QuicErrorCode last_error_; |
| 231 | 259 |
| 232 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 260 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
| 233 }; | 261 }; |
| 234 | 262 |
| 235 } // namespace net | 263 } // namespace net |
| 236 | 264 |
| 237 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 265 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
| OLD | NEW |