1 // Copyright 2013 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 // Manages the packet entropy calculation for both sent and received packets
8 #ifndef NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_
9 #define NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_
11 #include "net/quic/quic_framer.h"
12 #include "net/quic/quic_protocol.h"
17 class QuicReceivedPacketManagerPeer
;
20 // Records all received packets by a connection and tracks their entropy.
21 // Also calculates the correct entropy for the framer when it truncates an ack
22 // frame being serialized.
23 class NET_EXPORT_PRIVATE QuicReceivedPacketManager
:
24 public QuicReceivedEntropyHashCalculatorInterface
{
26 QuicReceivedPacketManager();
27 virtual ~QuicReceivedPacketManager();
29 // Updates the internal state concerning which packets have been acked.
30 void RecordPacketReceived(const QuicPacketHeader
& header
,
31 QuicTime receipt_time
);
33 // Checks if we're still waiting for the packet with |sequence_number|.
34 bool IsAwaitingPacket(QuicPacketSequenceNumber sequence_number
);
36 // Update the |received_info| for an outgoing ack.
37 void UpdateReceivedPacketInfo(ReceivedPacketInfo
* received_info
,
38 QuicTime approximate_now
);
40 // QuicReceivedEntropyHashCalculatorInterface
41 // Called by QuicFramer, when the outgoing ack gets truncated, to recalculate
42 // the received entropy hash for the truncated ack frame.
43 virtual QuicPacketEntropyHash
EntropyHash(
44 QuicPacketSequenceNumber sequence_number
) const OVERRIDE
;
46 // These two are called by OnAckFrame.
48 // Updates internal state based on |incoming_ack.received_info|.
49 void UpdatePacketInformationReceivedByPeer(const QuicAckFrame
& incoming_ack
);
50 // Updates internal state based on |incoming_ack.sent_info|.
51 void UpdatePacketInformationSentByPeer(const QuicAckFrame
& incoming_ack
);
53 // Returns the number of packets which are missing from the peer.
54 size_t GetNumMissingPackets();
56 QuicPacketSequenceNumber
peer_largest_observed_packet() {
57 return peer_largest_observed_packet_
;
60 QuicPacketSequenceNumber
least_packet_awaited_by_peer() {
61 return least_packet_awaited_by_peer_
;
64 QuicPacketSequenceNumber
peer_least_packet_awaiting_ack() {
65 return peer_least_packet_awaiting_ack_
;
69 friend class test::QuicReceivedPacketManagerPeer
;
71 typedef std::map
<QuicPacketSequenceNumber
,
72 QuicPacketEntropyHash
> ReceivedEntropyMap
;
74 // Record the received entropy hash against |sequence_number|.
75 void RecordPacketEntropyHash(QuicPacketSequenceNumber sequence_number
,
76 QuicPacketEntropyHash entropy_hash
);
78 // Recalculate the entropy hash and clears old packet entropies,
79 // now that the sender sent us the |entropy_hash| for packets up to,
80 // but not including, |peer_least_unacked|.
81 void RecalculateEntropyHash(QuicPacketSequenceNumber peer_least_unacked
,
82 QuicPacketEntropyHash entropy_hash
);
84 // Deletes all missing packets before least unacked. The connection won't
85 // process any packets with sequence number before |least_unacked| that it
86 // received after this call. Returns true if there were missing packets before
87 // |least_unacked| unacked, false otherwise.
88 bool DontWaitForPacketsBefore(QuicPacketSequenceNumber least_unacked
);
90 // TODO(satyamshekhar): Can be optimized using an interval set like data
92 // Map of received sequence numbers to their corresponding entropy.
93 // Every received packet has an entry, and packets without the entropy bit set
94 // have an entropy value of 0.
95 // TODO(ianswett): When the entropy flag is off, the entropy should not be 0.
96 ReceivedEntropyMap packets_entropy_
;
98 // Cumulative hash of entropy of all received packets.
99 QuicPacketEntropyHash packets_entropy_hash_
;
101 // The largest sequence number cleared by RecalculateEntropyHash.
102 // Received entropy cannot be calculated for numbers less than it.
103 QuicPacketSequenceNumber largest_sequence_number_
;
106 // Track some peer state so we can do less bookkeeping.
107 // Largest sequence number that the peer has observed. Mostly received,
108 // missing in case of truncated acks.
109 QuicPacketSequenceNumber peer_largest_observed_packet_
;
110 // Least sequence number which the peer is still waiting for.
111 QuicPacketSequenceNumber least_packet_awaited_by_peer_
;
112 // Least sequence number of the the packet sent by the peer for which it
113 // hasn't received an ack.
114 QuicPacketSequenceNumber peer_least_packet_awaiting_ack_
;
116 // Received packet information used to produce acks.
117 ReceivedPacketInfo received_info_
;
119 // The time we received the largest_observed sequence number, or zero if
120 // no sequence numbers have been received since UpdateReceivedPacketInfo.
121 // Needed for calculating delta_time_largest_observed.
122 QuicTime time_largest_observed_
;
127 #endif // NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_