Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / quic / quic_sent_entropy_manager.h
blobc89d97730de047f3797e85b98f4892da21042f50
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.
4 //
5 // Manages the packet entropy calculation for both sent and received packets
6 // for a connection.
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"
15 namespace net {
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
20 // attack.
21 class NET_EXPORT_PRIVATE QuicSentEntropyManager {
22 public:
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
40 // |sequence_number|.
41 void ClearEntropyBefore(QuicPacketSequenceNumber sequence_number);
43 private:
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);
58 } // namespace net
60 #endif // NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_