Index: net/quic/core/quic_protocol.h |
diff --git a/net/quic/core/quic_protocol.h b/net/quic/core/quic_protocol.h |
index cf659ca286b238c8ae3638fb7e499ed2b4d1025b..788cf42dbc43c9b249c77202d6f6a792a80a732d 100644 |
--- a/net/quic/core/quic_protocol.h |
+++ b/net/quic/core/quic_protocol.h |
@@ -5,16 +5,10 @@ |
#ifndef NET_QUIC_QUIC_PROTOCOL_H_ |
#define NET_QUIC_QUIC_PROTOCOL_H_ |
-#include <stddef.h> |
-#include <stdint.h> |
- |
-#include <array> |
#include <limits> |
#include <list> |
-#include <map> |
#include <memory> |
#include <ostream> |
-#include <set> |
#include <string> |
#include <utility> |
#include <vector> |
@@ -26,11 +20,10 @@ |
#include "net/base/int128.h" |
#include "net/base/iovec.h" |
#include "net/base/net_export.h" |
-#include "net/quic/core/interval_set.h" |
#include "net/quic/core/quic_bandwidth.h" |
-#include "net/quic/core/quic_buffer_allocator.h" |
#include "net/quic/core/quic_constants.h" |
#include "net/quic/core/quic_error_codes.h" |
+#include "net/quic/core/quic_frames.h" |
#include "net/quic/core/quic_time.h" |
#include "net/quic/core/quic_types.h" |
#include "net/quic/core/quic_versions.h" |
@@ -112,369 +105,8 @@ struct NET_EXPORT_PRIVATE QuicPublicResetPacket { |
typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
-// A padding frame contains no payload. |
-struct NET_EXPORT_PRIVATE QuicPaddingFrame { |
- QuicPaddingFrame() : num_padding_bytes(-1) {} |
- explicit QuicPaddingFrame(int num_padding_bytes) |
- : num_padding_bytes(num_padding_bytes) {} |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
- const QuicPaddingFrame& s); |
- |
- // -1: full padding to the end of a max-sized packet |
- // otherwise: only pad up to num_padding_bytes bytes |
- int num_padding_bytes; |
-}; |
- |
-// A ping frame contains no payload, though it is retransmittable, |
-// and ACK'd just like other normal frames. |
-struct NET_EXPORT_PRIVATE QuicPingFrame {}; |
- |
-// A path MTU discovery frame contains no payload and is serialized as a ping |
-// frame. |
-struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {}; |
- |
-// Deleter for stream buffers. Copyable to support platforms where the deleter |
-// of a unique_ptr must be copyable. Otherwise it would be nice for this to be |
-// move-only. |
-class NET_EXPORT_PRIVATE StreamBufferDeleter { |
- public: |
- StreamBufferDeleter() : allocator_(nullptr) {} |
- explicit StreamBufferDeleter(QuicBufferAllocator* allocator) |
- : allocator_(allocator) {} |
- |
- // Deletes |buffer| using |allocator_|. |
- void operator()(char* buffer) const; |
- |
- private: |
- // Not owned; must be valid so long as the buffer stored in the unique_ptr |
- // that owns |this| is valid. |
- QuicBufferAllocator* allocator_; |
-}; |
- |
-using UniqueStreamBuffer = std::unique_ptr<char[], StreamBufferDeleter>; |
- |
-// Allocates memory of size |size| using |allocator| for a QUIC stream buffer. |
-NET_EXPORT_PRIVATE UniqueStreamBuffer |
-NewStreamBuffer(QuicBufferAllocator* allocator, size_t size); |
- |
-struct NET_EXPORT_PRIVATE QuicStreamFrame { |
- QuicStreamFrame(); |
- QuicStreamFrame(QuicStreamId stream_id, |
- bool fin, |
- QuicStreamOffset offset, |
- base::StringPiece data); |
- QuicStreamFrame(QuicStreamId stream_id, |
- bool fin, |
- QuicStreamOffset offset, |
- QuicPacketLength data_length, |
- UniqueStreamBuffer buffer); |
- ~QuicStreamFrame(); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
- const QuicStreamFrame& s); |
- |
- QuicStreamId stream_id; |
- bool fin; |
- QuicPacketLength data_length; |
- const char* data_buffer; |
- QuicStreamOffset offset; // Location of this data in the stream. |
- // nullptr when the QuicStreamFrame is received, and non-null when sent. |
- UniqueStreamBuffer buffer; |
- |
- private: |
- QuicStreamFrame(QuicStreamId stream_id, |
- bool fin, |
- QuicStreamOffset offset, |
- const char* data_buffer, |
- QuicPacketLength data_length, |
- UniqueStreamBuffer buffer); |
- |
- DISALLOW_COPY_AND_ASSIGN(QuicStreamFrame); |
-}; |
-static_assert(sizeof(QuicStreamFrame) <= 64, |
- "Keep the QuicStreamFrame size to a cacheline."); |
- |
typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector; |
-struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { |
- QuicStopWaitingFrame(); |
- ~QuicStopWaitingFrame(); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
- std::ostream& os, |
- const QuicStopWaitingFrame& s); |
- // Path which this stop waiting frame belongs to. |
- QuicPathId path_id; |
- // The lowest packet we've sent which is unacked, and we expect an ack for. |
- QuicPacketNumber least_unacked; |
-}; |
- |
-// A sequence of packet numbers where each number is unique. Intended to be used |
-// in a sliding window fashion, where smaller old packet numbers are removed and |
-// larger new packet numbers are added, with the occasional random access. |
-class NET_EXPORT_PRIVATE PacketNumberQueue { |
- public: |
- using const_iterator = IntervalSet<QuicPacketNumber>::const_iterator; |
- using const_reverse_iterator = |
- IntervalSet<QuicPacketNumber>::const_reverse_iterator; |
- |
- PacketNumberQueue(); |
- PacketNumberQueue(const PacketNumberQueue& other); |
- // TODO(rtenneti): on windows RValue reference gives errors. |
- // PacketNumberQueue(PacketNumberQueue&& other); |
- ~PacketNumberQueue(); |
- |
- PacketNumberQueue& operator=(const PacketNumberQueue& other); |
- // PacketNumberQueue& operator=(PacketNumberQueue&& other); |
- |
- // Adds |packet_number| to the set of packets in the queue. |
- void Add(QuicPacketNumber packet_number); |
- |
- // Adds packets between [lower, higher) to the set of packets in the queue. It |
- // is undefined behavior to call this with |higher| < |lower|. |
- void Add(QuicPacketNumber lower, QuicPacketNumber higher); |
- |
- // Removes |packet_number| from the set of packets in the queue. |
- void Remove(QuicPacketNumber packet_number); |
- |
- // Removes packets numbers between [lower, higher) to the set of packets in |
- // the queue. It is undefined behavior to call this with |higher| < |lower|. |
- void Remove(QuicPacketNumber lower, QuicPacketNumber higher); |
- |
- // Removes packets with values less than |higher| from the set of packets in |
- // the queue. Returns true if packets were removed. |
- bool RemoveUpTo(QuicPacketNumber higher); |
- |
- // Mutates packet number set so that it contains only those packet numbers |
- // from minimum to maximum packet number not currently in the set. Do nothing |
- // if packet number set is empty. |
- void Complement(); |
- |
- // Returns true if the queue contains |packet_number|. |
- bool Contains(QuicPacketNumber packet_number) const; |
- |
- // Returns true if the queue is empty. |
- bool Empty() const; |
- |
- // Returns the minimum packet number stored in the queue. It is undefined |
- // behavior to call this if the queue is empty. |
- QuicPacketNumber Min() const; |
- |
- // Returns the maximum packet number stored in the queue. It is undefined |
- // behavior to call this if the queue is empty. |
- QuicPacketNumber Max() const; |
- |
- // Returns the number of unique packets stored in the queue. Inefficient; only |
- // exposed for testing. |
- size_t NumPacketsSlow() const; |
- |
- // Returns the number of disjoint packet number intervals contained in the |
- // queue. |
- size_t NumIntervals() const; |
- |
- // Returns the length of last interval. |
- QuicPacketNumber LastIntervalLength() const; |
- |
- // Returns iterators over the packet number intervals. |
- const_iterator begin() const; |
- const_iterator end() const; |
- const_reverse_iterator rbegin() const; |
- const_reverse_iterator rend() const; |
- const_iterator lower_bound(QuicPacketNumber packet_number) const; |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
- std::ostream& os, |
- const PacketNumberQueue& q); |
- |
- private: |
- IntervalSet<QuicPacketNumber> packet_number_intervals_; |
-}; |
- |
-struct NET_EXPORT_PRIVATE QuicAckFrame { |
- QuicAckFrame(); |
- QuicAckFrame(const QuicAckFrame& other); |
- ~QuicAckFrame(); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
- const QuicAckFrame& s); |
- |
- // The highest packet number we've observed from the peer. |
- QuicPacketNumber largest_observed; |
- |
- // Time elapsed since largest_observed was received until this Ack frame was |
- // sent. |
- QuicTime::Delta ack_delay_time; |
- |
- // Vector of <packet_number, time> for when packets arrived. |
- PacketTimeVector received_packet_times; |
- |
- // Set of packets. |
- PacketNumberQueue packets; |
- |
- // Path which this ack belongs to. |
- QuicPathId path_id; |
-}; |
- |
-// True if the packet number is greater than largest_observed or is listed |
-// as missing. |
-// Always returns false for packet numbers less than least_unacked. |
-bool NET_EXPORT_PRIVATE |
-IsAwaitingPacket(const QuicAckFrame& ack_frame, |
- QuicPacketNumber packet_number, |
- QuicPacketNumber peer_least_packet_awaiting_ack); |
- |
-struct NET_EXPORT_PRIVATE QuicRstStreamFrame { |
- QuicRstStreamFrame(); |
- QuicRstStreamFrame(QuicStreamId stream_id, |
- QuicRstStreamErrorCode error_code, |
- QuicStreamOffset bytes_written); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
- std::ostream& os, |
- const QuicRstStreamFrame& r); |
- |
- QuicStreamId stream_id; |
- QuicRstStreamErrorCode error_code; |
- |
- // Used to update flow control windows. On termination of a stream, both |
- // endpoints must inform the peer of the number of bytes they have sent on |
- // that stream. This can be done through normal termination (data packet with |
- // FIN) or through a RST. |
- QuicStreamOffset byte_offset; |
-}; |
- |
-struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { |
- QuicConnectionCloseFrame(); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
- std::ostream& os, |
- const QuicConnectionCloseFrame& c); |
- |
- QuicErrorCode error_code; |
- std::string error_details; |
-}; |
- |
-struct NET_EXPORT_PRIVATE QuicGoAwayFrame { |
- QuicGoAwayFrame(); |
- QuicGoAwayFrame(QuicErrorCode error_code, |
- QuicStreamId last_good_stream_id, |
- const std::string& reason); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
- const QuicGoAwayFrame& g); |
- |
- QuicErrorCode error_code; |
- QuicStreamId last_good_stream_id; |
- std::string reason_phrase; |
-}; |
- |
-// Flow control updates per-stream and at the connection levoel. |
-// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather |
-// than a window delta. |
-// TODO(rjshade): A possible future optimization is to make stream_id and |
-// byte_offset variable length, similar to stream frames. |
-struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame { |
- QuicWindowUpdateFrame() {} |
- QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
- std::ostream& os, |
- const QuicWindowUpdateFrame& w); |
- |
- // The stream this frame applies to. 0 is a special case meaning the overall |
- // connection rather than a specific stream. |
- QuicStreamId stream_id; |
- |
- // Byte offset in the stream or connection. The receiver of this frame must |
- // not send data which would result in this offset being exceeded. |
- QuicStreamOffset byte_offset; |
-}; |
- |
-// The BLOCKED frame is used to indicate to the remote endpoint that this |
-// endpoint believes itself to be flow-control blocked but otherwise ready to |
-// send data. The BLOCKED frame is purely advisory and optional. |
-// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28). |
-struct NET_EXPORT_PRIVATE QuicBlockedFrame { |
- QuicBlockedFrame() {} |
- explicit QuicBlockedFrame(QuicStreamId stream_id); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
- const QuicBlockedFrame& b); |
- |
- // The stream this frame applies to. 0 is a special case meaning the overall |
- // connection rather than a specific stream. |
- QuicStreamId stream_id; |
-}; |
- |
-// The PATH_CLOSE frame is used to explicitly close a path. Both endpoints can |
-// send a PATH_CLOSE frame to initiate a path termination. A path is considered |
-// to be closed either a PATH_CLOSE frame is sent or received. An endpoint drops |
-// receive side of a closed path, and packets with retransmittable frames on a |
-// closed path are marked as retransmissions which will be transmitted on other |
-// paths. |
-struct NET_EXPORT_PRIVATE QuicPathCloseFrame { |
- QuicPathCloseFrame() {} |
- explicit QuicPathCloseFrame(QuicPathId path_id); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
- std::ostream& os, |
- const QuicPathCloseFrame& p); |
- |
- QuicPathId path_id; |
-}; |
- |
-struct NET_EXPORT_PRIVATE QuicFrame { |
- QuicFrame(); |
- explicit QuicFrame(QuicPaddingFrame padding_frame); |
- explicit QuicFrame(QuicMtuDiscoveryFrame frame); |
- explicit QuicFrame(QuicPingFrame frame); |
- |
- explicit QuicFrame(QuicStreamFrame* stream_frame); |
- explicit QuicFrame(QuicAckFrame* frame); |
- explicit QuicFrame(QuicRstStreamFrame* frame); |
- explicit QuicFrame(QuicConnectionCloseFrame* frame); |
- explicit QuicFrame(QuicStopWaitingFrame* frame); |
- explicit QuicFrame(QuicGoAwayFrame* frame); |
- explicit QuicFrame(QuicWindowUpdateFrame* frame); |
- explicit QuicFrame(QuicBlockedFrame* frame); |
- explicit QuicFrame(QuicPathCloseFrame* frame); |
- |
- NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
- const QuicFrame& frame); |
- |
- QuicFrameType type; |
- union { |
- // Frames smaller than a pointer are inline. |
- QuicPaddingFrame padding_frame; |
- QuicMtuDiscoveryFrame mtu_discovery_frame; |
- QuicPingFrame ping_frame; |
- |
- // Frames larger than a pointer. |
- QuicStreamFrame* stream_frame; |
- QuicAckFrame* ack_frame; |
- QuicStopWaitingFrame* stop_waiting_frame; |
- QuicRstStreamFrame* rst_stream_frame; |
- QuicConnectionCloseFrame* connection_close_frame; |
- QuicGoAwayFrame* goaway_frame; |
- QuicWindowUpdateFrame* window_update_frame; |
- QuicBlockedFrame* blocked_frame; |
- QuicPathCloseFrame* path_close_frame; |
- }; |
-}; |
-// QuicFrameType consumes 8 bytes with padding. |
-static_assert(sizeof(QuicFrame) <= 16, |
- "Frames larger than 8 bytes should be referenced by pointer."); |
- |
-typedef std::vector<QuicFrame> QuicFrames; |
- |
-// Deletes all the sub-frames contained in |frames|. |
-NET_EXPORT_PRIVATE void DeleteFrames(QuicFrames* frames); |
- |
-// Deletes all the QuicStreamFrames for the specified |stream_id|. |
-NET_EXPORT_PRIVATE void RemoveFramesForStream(QuicFrames* frames, |
- QuicStreamId stream_id); |
- |
class NET_EXPORT_PRIVATE QuicData { |
public: |
QuicData(const char* buffer, size_t length); |