Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / net / quic / quic_unacked_packet_map.h
blob24abfeff11d51b3cdae3470208eb8310754a315e
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
3 // found in the LICENSE file.
5 #ifndef NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_
6 #define NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_
8 #include <deque>
10 #include "net/quic/quic_protocol.h"
12 namespace net {
14 // Class which tracks unacked packets for three purposes:
15 // 1) Track retransmittable data, including multiple transmissions of frames.
16 // 2) Track packets and bytes in flight for congestion control.
17 // 3) Track sent time of packets to provide RTT measurements from acks.
18 class NET_EXPORT_PRIVATE QuicUnackedPacketMap {
19 public:
20 QuicUnackedPacketMap();
21 ~QuicUnackedPacketMap();
23 // Adds |serialized_packet| to the map and marks it as sent at |sent_time|.
24 // Marks the packet as in flight if |set_in_flight| is true.
25 // Packets marked as in flight are expected to be marked as missing when they
26 // don't arrive, indicating the need for retransmission.
27 // |old_sequence_number| is the sequence number of the previous transmission,
28 // or 0 if there was none.
29 void AddSentPacket(const SerializedPacket& serialized_packet,
30 QuicPacketSequenceNumber old_sequence_number,
31 TransmissionType transmission_type,
32 QuicTime sent_time,
33 QuicByteCount bytes_sent,
34 bool set_in_flight);
36 // Returns true if the packet |sequence_number| is unacked.
37 bool IsUnacked(QuicPacketSequenceNumber sequence_number) const;
39 // Sets the nack count to the max of the current nack count and |min_nacks|.
40 void NackPacket(QuicPacketSequenceNumber sequence_number,
41 QuicPacketCount min_nacks);
43 // Marks |sequence_number| as no longer in flight.
44 void RemoveFromInFlight(QuicPacketSequenceNumber sequence_number);
46 // No longer retransmit data for |stream_id|.
47 void CancelRetransmissionsForStream(QuicStreamId stream_id);
49 // Returns true if the unacked packet |sequence_number| has retransmittable
50 // frames. This will return false if the packet has been acked, if a
51 // previous transmission of this packet was ACK'd, or if this packet has been
52 // retransmitted as with different sequence number, or if the packet never
53 // had any retransmittable packets in the first place.
54 bool HasRetransmittableFrames(QuicPacketSequenceNumber sequence_number) const;
56 // Returns true if there are any unacked packets.
57 bool HasUnackedPackets() const;
59 // Returns true if there are any unacked packets which have retransmittable
60 // frames.
61 bool HasUnackedRetransmittableFrames() const;
63 // Returns the largest sequence number that has been sent.
64 QuicPacketSequenceNumber largest_sent_packet() const {
65 return largest_sent_packet_;
68 // Returns the largest sequence number that has been acked.
69 QuicPacketSequenceNumber largest_observed() const {
70 return largest_observed_;
73 // Returns the sum of bytes from all packets in flight.
74 QuicByteCount bytes_in_flight() const {
75 return bytes_in_flight_;
78 // Returns the smallest sequence number of a serialized packet which has not
79 // been acked by the peer. If there are no unacked packets, returns 0.
80 QuicPacketSequenceNumber GetLeastUnacked() const;
82 // Clears all previous transmissions in order to make room in the ack frame
83 // for newly acked packets.
84 void ClearAllPreviousRetransmissions();
86 typedef std::deque<TransmissionInfo> UnackedPacketMap;
88 typedef UnackedPacketMap::const_iterator const_iterator;
90 const_iterator begin() const { return unacked_packets_.begin(); }
91 const_iterator end() const { return unacked_packets_.end(); }
93 // Returns true if there are unacked packets that are in flight.
94 bool HasInFlightPackets() const;
96 // Returns the TransmissionInfo associated with |sequence_number|, which
97 // must be unacked.
98 const TransmissionInfo& GetTransmissionInfo(
99 QuicPacketSequenceNumber sequence_number) const;
101 // Returns the time that the last unacked packet was sent.
102 QuicTime GetLastPacketSentTime() const;
104 // Returns the number of unacked packets.
105 size_t GetNumUnackedPacketsDebugOnly() const;
107 // Returns true if there are multiple packets in flight.
108 bool HasMultipleInFlightPackets() const;
110 // Returns true if there are any pending crypto packets.
111 bool HasPendingCryptoPackets() const;
113 // Removes any retransmittable frames from this transmission or an associated
114 // transmission. It removes now useless transmissions, and disconnects any
115 // other packets from other transmissions.
116 void RemoveRetransmittability(QuicPacketSequenceNumber sequence_number);
118 // Removes any other retransmissions and marks all transmissions unackable.
119 void RemoveAckability(TransmissionInfo* info);
121 // Increases the largest observed. Any packets less or equal to
122 // |largest_acked_packet| are discarded if they are only for the RTT purposes.
123 void IncreaseLargestObserved(QuicPacketSequenceNumber largest_observed);
125 // Remove any packets no longer needed for retransmission, congestion, or
126 // RTT measurement purposes.
127 void RemoveObsoletePackets();
129 private:
130 // Called when a packet is retransmitted with a new sequence number.
131 // |old_sequence_number| will remain unacked, but will have no
132 // retransmittable data associated with it. Retransmittable frames will be
133 // transferred to |info| and all_transmissions will be populated.
134 void TransferRetransmissionInfo(QuicPacketSequenceNumber old_sequence_number,
135 QuicPacketSequenceNumber new_sequence_number,
136 TransmissionType transmission_type,
137 TransmissionInfo* info);
139 void MaybeRemoveRetransmittableFrames(TransmissionInfo* transmission_info);
141 // Returns true if packet may be useful for an RTT measurement.
142 bool IsPacketUsefulForMeasuringRtt(QuicPacketSequenceNumber sequence_number,
143 const TransmissionInfo& info) const;
145 // Returns true if packet may be useful for congestion control purposes.
146 bool IsPacketUsefulForCongestionControl(const TransmissionInfo& info) const;
148 // Returns true if packet may be associated with retransmittable data
149 // directly or through retransmissions.
150 bool IsPacketUsefulForRetransmittableData(const TransmissionInfo& info) const;
152 // Returns true if the packet no longer has a purpose in the map.
153 bool IsPacketUseless(QuicPacketSequenceNumber sequence_number,
154 const TransmissionInfo& info) const;
156 // Returns true if the packet is useless or it's only purpose is RTT
157 // measurement, and it's old enough that is unlikely to ever happen.
158 bool IsPacketRemovable(QuicPacketSequenceNumber sequence_number,
159 const TransmissionInfo& info) const;
161 QuicPacketSequenceNumber largest_sent_packet_;
162 QuicPacketSequenceNumber largest_observed_;
164 // Newly serialized retransmittable and fec packets are added to this map,
165 // which contains owning pointers to any contained frames. If a packet is
166 // retransmitted, this map will contain entries for both the old and the new
167 // packet. The old packet's retransmittable frames entry will be nullptr,
168 // while the new packet's entry will contain the frames to retransmit.
169 // If the old packet is acked before the new packet, then the old entry will
170 // be removed from the map and the new entry's retransmittable frames will be
171 // set to nullptr.
172 UnackedPacketMap unacked_packets_;
173 // The packet at the 0th index of unacked_packets_.
174 QuicPacketSequenceNumber least_unacked_;
176 QuicByteCount bytes_in_flight_;
177 // Number of retransmittable crypto handshake packets.
178 size_t pending_crypto_packet_count_;
180 DISALLOW_COPY_AND_ASSIGN(QuicUnackedPacketMap);
183 } // namespace net
185 #endif // NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_