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_SENT_ENTROPY_MANAGER_H_
9 #define NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_
11 #include "net/base/linked_hash_map.h"
12 #include "net/quic/quic_framer.h"
13 #include "net/quic/quic_protocol.h"
17 // Records all sent packets by a connection to track the cumulative entropy of
18 // sent packets. It is used by the connection to validate an ack
19 // frame sent by the peer as a preventive measure against the optimistic ack
21 class NET_EXPORT_PRIVATE QuicSentEntropyManager
{
23 QuicSentEntropyManager();
24 virtual ~QuicSentEntropyManager();
26 // Record |entropy_hash| for sent packet corresponding to |sequence_number|.
27 void RecordPacketEntropyHash(QuicPacketSequenceNumber sequence_number
,
28 QuicPacketEntropyHash entropy_hash
);
30 QuicPacketEntropyHash
EntropyHash(
31 QuicPacketSequenceNumber sequence_number
) const;
33 // Returns true if |entropy_hash| matches the expected sent entropy hash
34 // up to |sequence_number| removing sequence numbers from |missing_packets|.
35 bool IsValidEntropy(QuicPacketSequenceNumber sequence_number
,
36 const SequenceNumberSet
& missing_packets
,
37 QuicPacketEntropyHash entropy_hash
) const;
39 // Removes not required entries from |packets_entropy_| before
41 void ClearEntropyBefore(QuicPacketSequenceNumber sequence_number
);
44 typedef linked_hash_map
<QuicPacketSequenceNumber
,
45 std::pair
<QuicPacketEntropyHash
,
46 QuicPacketEntropyHash
> > SentEntropyMap
;
48 // Linked hash map from sequence numbers to the sent entropy hash up to the
49 // sequence number in the key.
50 SentEntropyMap packets_entropy_
;
52 // Cumulative hash of entropy of all sent packets.
53 QuicPacketEntropyHash packets_entropy_hash_
;
55 DISALLOW_COPY_AND_ASSIGN(QuicSentEntropyManager
);
60 #endif // NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_