| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | |
| 6 #define NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <deque> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "net/quic/quic_protocol.h" | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 class AckNotifierManager; | |
| 18 | |
| 19 // Class which tracks unacked packets for three purposes: | |
| 20 // 1) Track retransmittable data, including multiple transmissions of frames. | |
| 21 // 2) Track packets and bytes in flight for congestion control. | |
| 22 // 3) Track sent time of packets to provide RTT measurements from acks. | |
| 23 class NET_EXPORT_PRIVATE QuicUnackedPacketMap { | |
| 24 public: | |
| 25 QuicUnackedPacketMap(); | |
| 26 ~QuicUnackedPacketMap(); | |
| 27 | |
| 28 // Adds |serialized_packet| to the map and marks it as sent at |sent_time|. | |
| 29 // Marks the packet as in flight if |set_in_flight| is true. | |
| 30 // Packets marked as in flight are expected to be marked as missing when they | |
| 31 // don't arrive, indicating the need for retransmission. | |
| 32 // |old_packet_number| is the packet number of the previous transmission, | |
| 33 // or 0 if there was none. | |
| 34 // Any AckNotifierWrappers in |serialized_packet| are swapped from the | |
| 35 // serialized packet into the TransmissionInfo. | |
| 36 void AddSentPacket(SerializedPacket* serialized_packet, | |
| 37 QuicPacketNumber old_packet_number, | |
| 38 TransmissionType transmission_type, | |
| 39 QuicTime sent_time, | |
| 40 bool set_in_flight); | |
| 41 | |
| 42 // Returns true if the packet |packet_number| is unacked. | |
| 43 bool IsUnacked(QuicPacketNumber packet_number) const; | |
| 44 | |
| 45 // Notifies all the AckListeners attached to the |info| and | |
| 46 // clears them to ensure they're not notified again. | |
| 47 void NotifyAndClearListeners(std::list<AckListenerWrapper>* ack_listeners, | |
| 48 QuicTime::Delta delta_largest_observed); | |
| 49 | |
| 50 // Notifies all the AckListeners attached to |newest_transmission|. | |
| 51 void NotifyAndClearListeners(QuicPacketNumber newest_transmission, | |
| 52 QuicTime::Delta delta_largest_observed); | |
| 53 | |
| 54 // Marks |info| as no longer in flight. | |
| 55 void RemoveFromInFlight(TransmissionInfo* info); | |
| 56 | |
| 57 // Marks |packet_number| as no longer in flight. | |
| 58 void RemoveFromInFlight(QuicPacketNumber packet_number); | |
| 59 | |
| 60 // Marks |packet_number| as in flight. Must not be unackable. | |
| 61 void RestoreToInFlight(QuicPacketNumber packet_number); | |
| 62 | |
| 63 // No longer retransmit data for |stream_id|. | |
| 64 void CancelRetransmissionsForStream(QuicStreamId stream_id); | |
| 65 | |
| 66 // Returns true if the unacked packet |packet_number| has retransmittable | |
| 67 // frames. This will return false if the packet has been acked, if a | |
| 68 // previous transmission of this packet was ACK'd, or if this packet has been | |
| 69 // retransmitted as with different packet number, or if the packet never | |
| 70 // had any retransmittable packets in the first place. | |
| 71 bool HasRetransmittableFrames(QuicPacketNumber packet_number) const; | |
| 72 | |
| 73 // Returns true if there are any unacked packets. | |
| 74 bool HasUnackedPackets() const; | |
| 75 | |
| 76 // Returns true if there are any unacked packets which have retransmittable | |
| 77 // frames. | |
| 78 bool HasUnackedRetransmittableFrames() const; | |
| 79 | |
| 80 // Returns the largest packet number that has been sent. | |
| 81 QuicPacketNumber largest_sent_packet() const { return largest_sent_packet_; } | |
| 82 | |
| 83 // Returns the largest packet number that has been acked. | |
| 84 QuicPacketNumber largest_observed() const { return largest_observed_; } | |
| 85 | |
| 86 // Returns the sum of bytes from all packets in flight. | |
| 87 QuicByteCount bytes_in_flight() const { return bytes_in_flight_; } | |
| 88 | |
| 89 // Returns the smallest packet number of a serialized packet which has not | |
| 90 // been acked by the peer. If there are no unacked packets, returns 0. | |
| 91 QuicPacketNumber GetLeastUnacked() const; | |
| 92 | |
| 93 typedef std::deque<TransmissionInfo> UnackedPacketMap; | |
| 94 | |
| 95 typedef UnackedPacketMap::const_iterator const_iterator; | |
| 96 typedef UnackedPacketMap::iterator iterator; | |
| 97 | |
| 98 const_iterator begin() const { return unacked_packets_.begin(); } | |
| 99 const_iterator end() const { return unacked_packets_.end(); } | |
| 100 iterator begin() { return unacked_packets_.begin(); } | |
| 101 iterator end() { return unacked_packets_.end(); } | |
| 102 | |
| 103 // Returns true if there are unacked packets that are in flight. | |
| 104 bool HasInFlightPackets() const; | |
| 105 | |
| 106 // Returns the TransmissionInfo associated with |packet_number|, which | |
| 107 // must be unacked. | |
| 108 const TransmissionInfo& GetTransmissionInfo( | |
| 109 QuicPacketNumber packet_number) const; | |
| 110 | |
| 111 // Returns mutable TransmissionInfo associated with |packet_number|, which | |
| 112 // must be unacked. | |
| 113 TransmissionInfo* GetMutableTransmissionInfo(QuicPacketNumber packet_number); | |
| 114 | |
| 115 // Returns the time that the last unacked packet was sent. | |
| 116 QuicTime GetLastPacketSentTime() const; | |
| 117 | |
| 118 // Returns the number of unacked packets. | |
| 119 size_t GetNumUnackedPacketsDebugOnly() const; | |
| 120 | |
| 121 // Returns true if there are multiple packets in flight. | |
| 122 bool HasMultipleInFlightPackets() const; | |
| 123 | |
| 124 // Returns true if there are any pending crypto packets. | |
| 125 bool HasPendingCryptoPackets() const; | |
| 126 | |
| 127 // Removes any retransmittable frames from this transmission or an associated | |
| 128 // transmission. It removes now useless transmissions, and disconnects any | |
| 129 // other packets from other transmissions. | |
| 130 void RemoveRetransmittability(TransmissionInfo* info); | |
| 131 | |
| 132 // Looks up the TransmissionInfo by |packet_number| and calls | |
| 133 // RemoveRetransmittability. | |
| 134 void RemoveRetransmittability(QuicPacketNumber packet_number); | |
| 135 | |
| 136 // Increases the largest observed. Any packets less or equal to | |
| 137 // |largest_acked_packet| are discarded if they are only for the RTT purposes. | |
| 138 void IncreaseLargestObserved(QuicPacketNumber largest_observed); | |
| 139 | |
| 140 // Remove any packets no longer needed for retransmission, congestion, or | |
| 141 // RTT measurement purposes. | |
| 142 void RemoveObsoletePackets(); | |
| 143 | |
| 144 private: | |
| 145 // Called when a packet is retransmitted with a new packet number. | |
| 146 // |old_packet_number| will remain unacked, but will have no | |
| 147 // retransmittable data associated with it. Retransmittable frames will be | |
| 148 // transferred to |info| and all_transmissions will be populated. | |
| 149 void TransferRetransmissionInfo(QuicPacketNumber old_packet_number, | |
| 150 QuicPacketNumber new_packet_number, | |
| 151 TransmissionType transmission_type, | |
| 152 TransmissionInfo* info); | |
| 153 | |
| 154 void MaybeRemoveRetransmittableFrames(TransmissionInfo* transmission_info); | |
| 155 | |
| 156 // Returns true if packet may be useful for an RTT measurement. | |
| 157 bool IsPacketUsefulForMeasuringRtt(QuicPacketNumber packet_number, | |
| 158 const TransmissionInfo& info) const; | |
| 159 | |
| 160 // Returns true if packet may be useful for congestion control purposes. | |
| 161 bool IsPacketUsefulForCongestionControl(const TransmissionInfo& info) const; | |
| 162 | |
| 163 // Returns true if packet may be associated with retransmittable data | |
| 164 // directly or through retransmissions. | |
| 165 bool IsPacketUsefulForRetransmittableData(const TransmissionInfo& info) const; | |
| 166 | |
| 167 // Returns true if the packet no longer has a purpose in the map. | |
| 168 bool IsPacketUseless(QuicPacketNumber packet_number, | |
| 169 const TransmissionInfo& info) const; | |
| 170 | |
| 171 QuicPacketNumber largest_sent_packet_; | |
| 172 QuicPacketNumber largest_observed_; | |
| 173 | |
| 174 // Newly serialized retransmittable packets are added to this map, which | |
| 175 // contains owning pointers to any contained frames. If a packet is | |
| 176 // retransmitted, this map will contain entries for both the old and the new | |
| 177 // packet. The old packet's retransmittable frames entry will be nullptr, | |
| 178 // while the new packet's entry will contain the frames to retransmit. | |
| 179 // If the old packet is acked before the new packet, then the old entry will | |
| 180 // be removed from the map and the new entry's retransmittable frames will be | |
| 181 // set to nullptr. | |
| 182 UnackedPacketMap unacked_packets_; | |
| 183 // The packet at the 0th index of unacked_packets_. | |
| 184 QuicPacketNumber least_unacked_; | |
| 185 | |
| 186 QuicByteCount bytes_in_flight_; | |
| 187 // Number of retransmittable crypto handshake packets. | |
| 188 size_t pending_crypto_packet_count_; | |
| 189 | |
| 190 DISALLOW_COPY_AND_ASSIGN(QuicUnackedPacketMap); | |
| 191 }; | |
| 192 | |
| 193 } // namespace net | |
| 194 | |
| 195 #endif // NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | |
| OLD | NEW |