| 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 // The base class for client/server QUIC streams. | 5 // The base class for client/server QUIC streams. |
| 6 | 6 |
| 7 // It does not contain the entire interface needed by an application to interact | 7 // It does not contain the entire interface needed by an application to interact |
| 8 // with a QUIC stream. Some parts of the interface must be obtained by | 8 // with a QUIC stream. Some parts of the interface must be obtained by |
| 9 // accessing the owning session object. A subclass of QuicStream | 9 // accessing the owning session object. A subclass of QuicStream |
| 10 // connects the object and the application that generates and consumes the data | 10 // connects the object and the application that generates and consumes the data |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include <list> | 22 #include <list> |
| 23 #include <string> | 23 #include <string> |
| 24 | 24 |
| 25 #include "base/macros.h" | 25 #include "base/macros.h" |
| 26 #include "net/base/iovec.h" | 26 #include "net/base/iovec.h" |
| 27 #include "net/quic/core/quic_flow_controller.h" | 27 #include "net/quic/core/quic_flow_controller.h" |
| 28 #include "net/quic/core/quic_iovector.h" | 28 #include "net/quic/core/quic_iovector.h" |
| 29 #include "net/quic/core/quic_packets.h" | 29 #include "net/quic/core/quic_packets.h" |
| 30 #include "net/quic/core/quic_stream_sequencer.h" | 30 #include "net/quic/core/quic_stream_sequencer.h" |
| 31 #include "net/quic/core/quic_types.h" | 31 #include "net/quic/core/quic_types.h" |
| 32 #include "net/quic/core/stream_notifier_interface.h" |
| 32 #include "net/quic/platform/api/quic_export.h" | 33 #include "net/quic/platform/api/quic_export.h" |
| 33 #include "net/quic/platform/api/quic_reference_counted.h" | 34 #include "net/quic/platform/api/quic_reference_counted.h" |
| 34 #include "net/quic/platform/api/quic_string_piece.h" | 35 #include "net/quic/platform/api/quic_string_piece.h" |
| 35 | 36 |
| 36 namespace net { | 37 namespace net { |
| 37 | 38 |
| 38 namespace test { | 39 namespace test { |
| 39 class QuicStreamPeer; | 40 class QuicStreamPeer; |
| 40 } // namespace test | 41 } // namespace test |
| 41 | 42 |
| 42 class QuicSession; | 43 class QuicSession; |
| 43 | 44 |
| 44 class QUIC_EXPORT_PRIVATE QuicStream { | 45 class QUIC_EXPORT_PRIVATE QuicStream : public StreamNotifierInterface { |
| 45 public: | 46 public: |
| 46 QuicStream(QuicStreamId id, QuicSession* session); | 47 QuicStream(QuicStreamId id, QuicSession* session); |
| 47 | 48 |
| 48 virtual ~QuicStream(); | 49 ~QuicStream() override; |
| 49 | 50 |
| 50 // Not in use currently. | 51 // Not in use currently. |
| 51 void SetFromConfig(); | 52 void SetFromConfig(); |
| 52 | 53 |
| 53 // Called by the session when a (potentially duplicate) stream frame has been | 54 // Called by the session when a (potentially duplicate) stream frame has been |
| 54 // received for this stream. | 55 // received for this stream. |
| 55 virtual void OnStreamFrame(const QuicStreamFrame& frame); | 56 virtual void OnStreamFrame(const QuicStreamFrame& frame); |
| 56 | 57 |
| 57 // Called by the session when the connection becomes writeable to allow the | 58 // Called by the session when the connection becomes writeable to allow the |
| 58 // stream to write any pending data. | 59 // stream to write any pending data. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 size_t busy_counter() const { return busy_counter_; } | 119 size_t busy_counter() const { return busy_counter_; } |
| 119 void set_busy_counter(size_t busy_counter) { busy_counter_ = busy_counter; } | 120 void set_busy_counter(size_t busy_counter) { busy_counter_ = busy_counter; } |
| 120 | 121 |
| 121 void set_fin_sent(bool fin_sent) { fin_sent_ = fin_sent; } | 122 void set_fin_sent(bool fin_sent) { fin_sent_ = fin_sent; } |
| 122 void set_fin_received(bool fin_received) { fin_received_ = fin_received; } | 123 void set_fin_received(bool fin_received) { fin_received_ = fin_received; } |
| 123 void set_rst_sent(bool rst_sent) { rst_sent_ = rst_sent; } | 124 void set_rst_sent(bool rst_sent) { rst_sent_ = rst_sent; } |
| 124 | 125 |
| 125 void set_rst_received(bool rst_received) { rst_received_ = rst_received; } | 126 void set_rst_received(bool rst_received) { rst_received_ = rst_received; } |
| 126 void set_stream_error(QuicRstStreamErrorCode error) { stream_error_ = error; } | 127 void set_stream_error(QuicRstStreamErrorCode error) { stream_error_ = error; } |
| 127 | 128 |
| 129 bool is_deletable() const { return is_deletable_; } |
| 130 |
| 128 // Adjust the flow control window according to new offset in |frame|. | 131 // Adjust the flow control window according to new offset in |frame|. |
| 129 virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame); | 132 virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame); |
| 130 | 133 |
| 131 // Used in Chrome. | 134 // Used in Chrome. |
| 132 int num_frames_received() const; | 135 int num_frames_received() const; |
| 133 int num_duplicate_frames_received() const; | 136 int num_duplicate_frames_received() const; |
| 134 | 137 |
| 135 QuicFlowController* flow_controller() { return &flow_controller_; } | 138 QuicFlowController* flow_controller() { return &flow_controller_; } |
| 136 | 139 |
| 137 // Called when endpoint receives a frame which could increase the highest | 140 // Called when endpoint receives a frame which could increase the highest |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // If fin is true: if it is immediately passed on to the session, | 185 // If fin is true: if it is immediately passed on to the session, |
| 183 // write_side_closed() becomes true, otherwise fin_buffered_ becomes true. | 186 // write_side_closed() becomes true, otherwise fin_buffered_ becomes true. |
| 184 void WriteOrBufferData( | 187 void WriteOrBufferData( |
| 185 QuicStringPiece data, | 188 QuicStringPiece data, |
| 186 bool fin, | 189 bool fin, |
| 187 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); | 190 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); |
| 188 | 191 |
| 189 // Adds random padding after the fin is consumed for this stream. | 192 // Adds random padding after the fin is consumed for this stream. |
| 190 void AddRandomPaddingAfterFin(); | 193 void AddRandomPaddingAfterFin(); |
| 191 | 194 |
| 195 // Sets this stream as deletable. Delete this stream from zombie stream map if |
| 196 // exists. |
| 197 void SetIsDeletable(bool is_deletable); |
| 198 |
| 199 // StreamNotifierInterface methods: |
| 200 void OnStreamFrameAcked(const QuicStreamFrame& frame, |
| 201 QuicTime::Delta ack_delay_time) override; |
| 202 void OnStreamFrameRetransmitted(const QuicStreamFrame& frame) override; |
| 203 |
| 192 protected: | 204 protected: |
| 193 // Sends as many bytes in the first |count| buffers of |iov| to the connection | 205 // Sends as many bytes in the first |count| buffers of |iov| to the connection |
| 194 // as the connection will consume. | 206 // as the connection will consume. |
| 195 // If |ack_listener| is provided, then it will be notified once all | 207 // If |ack_listener| is provided, then it will be notified once all |
| 196 // the ACKs for this write have been received. | 208 // the ACKs for this write have been received. |
| 197 // Returns the number of bytes consumed by the connection. | 209 // Returns the number of bytes consumed by the connection. |
| 198 QuicConsumedData WritevData( | 210 QuicConsumedData WritevData( |
| 199 const struct iovec* iov, | 211 const struct iovec* iov, |
| 200 int iov_count, | 212 int iov_count, |
| 201 bool fin, | 213 bool fin, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 219 const QuicSession* session() const { return session_; } | 231 const QuicSession* session() const { return session_; } |
| 220 QuicSession* session() { return session_; } | 232 QuicSession* session() { return session_; } |
| 221 | 233 |
| 222 const QuicStreamSequencer* sequencer() const { return &sequencer_; } | 234 const QuicStreamSequencer* sequencer() const { return &sequencer_; } |
| 223 QuicStreamSequencer* sequencer() { return &sequencer_; } | 235 QuicStreamSequencer* sequencer() { return &sequencer_; } |
| 224 | 236 |
| 225 void DisableConnectionFlowControlForThisStream() { | 237 void DisableConnectionFlowControlForThisStream() { |
| 226 stream_contributes_to_connection_flow_control_ = false; | 238 stream_contributes_to_connection_flow_control_ = false; |
| 227 } | 239 } |
| 228 | 240 |
| 241 void set_ack_listener( |
| 242 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
| 243 ack_listener_ = std::move(ack_listener); |
| 244 } |
| 245 |
| 229 private: | 246 private: |
| 230 friend class test::QuicStreamPeer; | 247 friend class test::QuicStreamPeer; |
| 231 friend class QuicStreamUtils; | 248 friend class QuicStreamUtils; |
| 232 | 249 |
| 233 // Close the read side of the socket. May cause the stream to be closed. | 250 // Close the read side of the socket. May cause the stream to be closed. |
| 234 // Subclasses and consumers should use StopReading to terminate reading early. | 251 // Subclasses and consumers should use StopReading to terminate reading early. |
| 235 void CloseReadSide(); | 252 void CloseReadSide(); |
| 236 | 253 |
| 237 // Subclasses and consumers should use reading_stopped. | 254 // Subclasses and consumers should use reading_stopped. |
| 238 bool read_side_closed() const { return read_side_closed_; } | 255 bool read_side_closed() const { return read_side_closed_; } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 263 uint64_t queued_data_bytes_; | 280 uint64_t queued_data_bytes_; |
| 264 | 281 |
| 265 QuicStreamSequencer sequencer_; | 282 QuicStreamSequencer sequencer_; |
| 266 QuicStreamId id_; | 283 QuicStreamId id_; |
| 267 // Pointer to the owning QuicSession object. | 284 // Pointer to the owning QuicSession object. |
| 268 QuicSession* session_; | 285 QuicSession* session_; |
| 269 // Bytes read and written refer to payload bytes only: they do not include | 286 // Bytes read and written refer to payload bytes only: they do not include |
| 270 // framing, encryption overhead etc. | 287 // framing, encryption overhead etc. |
| 271 uint64_t stream_bytes_read_; | 288 uint64_t stream_bytes_read_; |
| 272 uint64_t stream_bytes_written_; | 289 uint64_t stream_bytes_written_; |
| 290 // Written bytes which have been acked. |
| 291 uint64_t stream_bytes_acked_; |
| 273 | 292 |
| 274 // Stream error code received from a RstStreamFrame or error code sent by the | 293 // Stream error code received from a RstStreamFrame or error code sent by the |
| 275 // visitor or sequencer in the RstStreamFrame. | 294 // visitor or sequencer in the RstStreamFrame. |
| 276 QuicRstStreamErrorCode stream_error_; | 295 QuicRstStreamErrorCode stream_error_; |
| 277 // Connection error code due to which the stream was closed. |stream_error_| | 296 // Connection error code due to which the stream was closed. |stream_error_| |
| 278 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers | 297 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers |
| 279 // should check |connection_error_|. | 298 // should check |connection_error_|. |
| 280 QuicErrorCode connection_error_; | 299 QuicErrorCode connection_error_; |
| 281 | 300 |
| 282 // True if the read side is closed and further frames should be rejected. | 301 // True if the read side is closed and further frames should be rejected. |
| 283 bool read_side_closed_; | 302 bool read_side_closed_; |
| 284 // True if the write side is closed, and further writes should fail. | 303 // True if the write side is closed, and further writes should fail. |
| 285 bool write_side_closed_; | 304 bool write_side_closed_; |
| 286 | 305 |
| 287 // True if the subclass has written a FIN with WriteOrBufferData, but it was | 306 // True if the subclass has written a FIN with WriteOrBufferData, but it was |
| 288 // buffered in queued_data_ rather than being sent to the session. | 307 // buffered in queued_data_ rather than being sent to the session. |
| 289 bool fin_buffered_; | 308 bool fin_buffered_; |
| 290 // True if a FIN has been sent to the session. | 309 // True if a FIN has been sent to the session. |
| 291 bool fin_sent_; | 310 bool fin_sent_; |
| 311 // True if a FIN has been acked. |
| 312 bool fin_acked_; |
| 292 | 313 |
| 293 // True if this stream has received (and the sequencer has accepted) a | 314 // True if this stream has received (and the sequencer has accepted) a |
| 294 // StreamFrame with the FIN set. | 315 // StreamFrame with the FIN set. |
| 295 bool fin_received_; | 316 bool fin_received_; |
| 296 | 317 |
| 297 // True if an RST_STREAM has been sent to the session. | 318 // True if an RST_STREAM has been sent to the session. |
| 298 // In combination with fin_sent_, used to ensure that a FIN and/or a | 319 // In combination with fin_sent_, used to ensure that a FIN and/or a |
| 299 // RST_STREAM is always sent to terminate the stream. | 320 // RST_STREAM is always sent to terminate the stream. |
| 300 bool rst_sent_; | 321 bool rst_sent_; |
| 301 | 322 |
| 302 // True if this stream has received a RST_STREAM frame. | 323 // True if this stream has received a RST_STREAM frame. |
| 303 bool rst_received_; | 324 bool rst_received_; |
| 304 | 325 |
| 326 // True if this stream object may be deleted. Currently, this means this |
| 327 // stream does not have unacked data (including FIN). Please note, this stream |
| 328 // may not finish sending. |
| 329 bool is_deletable_; |
| 330 |
| 305 // Tracks if the session this stream is running under was created by a | 331 // Tracks if the session this stream is running under was created by a |
| 306 // server or a client. | 332 // server or a client. |
| 307 Perspective perspective_; | 333 Perspective perspective_; |
| 308 | 334 |
| 309 QuicFlowController flow_controller_; | 335 QuicFlowController flow_controller_; |
| 310 | 336 |
| 311 // The connection level flow controller. Not owned. | 337 // The connection level flow controller. Not owned. |
| 312 QuicFlowController* connection_flow_controller_; | 338 QuicFlowController* connection_flow_controller_; |
| 313 | 339 |
| 314 // Special streams, such as the crypto and headers streams, do not respect | 340 // Special streams, such as the crypto and headers streams, do not respect |
| 315 // connection level flow control limits (but are stream level flow control | 341 // connection level flow control limits (but are stream level flow control |
| 316 // limited). | 342 // limited). |
| 317 bool stream_contributes_to_connection_flow_control_; | 343 bool stream_contributes_to_connection_flow_control_; |
| 318 | 344 |
| 319 // A counter incremented when OnCanWrite() is called and no progress is made. | 345 // A counter incremented when OnCanWrite() is called and no progress is made. |
| 320 // For debugging only. | 346 // For debugging only. |
| 321 size_t busy_counter_; | 347 size_t busy_counter_; |
| 322 | 348 |
| 323 // Indicates whether paddings will be added after the fin is consumed for this | 349 // Indicates whether paddings will be added after the fin is consumed for this |
| 324 // stream. | 350 // stream. |
| 325 bool add_random_padding_after_fin_; | 351 bool add_random_padding_after_fin_; |
| 326 | 352 |
| 353 // Ack listener of this stream, and it is notified when any of written bytes |
| 354 // are acked. |
| 355 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener_; |
| 356 |
| 327 DISALLOW_COPY_AND_ASSIGN(QuicStream); | 357 DISALLOW_COPY_AND_ASSIGN(QuicStream); |
| 328 }; | 358 }; |
| 329 | 359 |
| 330 } // namespace net | 360 } // namespace net |
| 331 | 361 |
| 332 #endif // NET_QUIC_CORE_QUIC_STREAM_H_ | 362 #endif // NET_QUIC_CORE_QUIC_STREAM_H_ |
| OLD | NEW |