| OLD | NEW |
| (Empty) |
| 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. | |
| 7 | |
| 8 #ifndef NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ | |
| 9 #define NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ | |
| 10 | |
| 11 #include <deque> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "net/base/linked_hash_map.h" | |
| 15 #include "net/quic/quic_framer.h" | |
| 16 #include "net/quic/quic_protocol.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 namespace test { | |
| 21 class QuicConnectionPeer; | |
| 22 } // namespace test | |
| 23 | |
| 24 // Records all sent packets by a connection to track the cumulative entropy of | |
| 25 // sent packets. It is used by the connection to validate an ack | |
| 26 // frame sent by the peer as a preventive measure against the optimistic ack | |
| 27 // attack. | |
| 28 class NET_EXPORT_PRIVATE QuicSentEntropyManager { | |
| 29 public: | |
| 30 QuicSentEntropyManager(); | |
| 31 virtual ~QuicSentEntropyManager(); | |
| 32 | |
| 33 // Record |entropy_hash| for sent packet corresponding to |packet_number|. | |
| 34 void RecordPacketEntropyHash(QuicPacketNumber packet_number, | |
| 35 QuicPacketEntropyHash entropy_hash); | |
| 36 | |
| 37 // Retrieves the cumulative entropy up to |packet_number|. | |
| 38 // Must always be called with a monotonically increasing |packet_number|. | |
| 39 QuicPacketEntropyHash GetCumulativeEntropy(QuicPacketNumber packet_number); | |
| 40 | |
| 41 // Returns true if |entropy_hash| matches the expected sent entropy hash | |
| 42 // up to |largest_observed| removing packet numbers from |missing_packets|. | |
| 43 // Must always be called with a monotonically increasing |largest_observed|. | |
| 44 bool IsValidEntropy(QuicPacketNumber largest_observed, | |
| 45 const PacketNumberQueue& missing_packets, | |
| 46 QuicPacketEntropyHash entropy_hash); | |
| 47 | |
| 48 // Removes unnecessary entries before |packet_number|. | |
| 49 void ClearEntropyBefore(QuicPacketNumber packet_number); | |
| 50 | |
| 51 private: | |
| 52 friend class test::QuicConnectionPeer; | |
| 53 | |
| 54 typedef std::deque<QuicPacketEntropyHash> SentEntropyMap; | |
| 55 | |
| 56 struct CumulativeEntropy { | |
| 57 CumulativeEntropy() : packet_number(0), entropy(0) {} | |
| 58 | |
| 59 QuicPacketNumber packet_number; | |
| 60 QuicPacketEntropyHash entropy; | |
| 61 }; | |
| 62 | |
| 63 // Convenience methods to get the largest and smallest packets with entropies. | |
| 64 QuicPacketNumber GetLargestPacketWithEntropy() const; | |
| 65 QuicPacketNumber GetSmallestPacketWithEntropy() const; | |
| 66 // Convenience method to get the entropy hash for |packet_number|. | |
| 67 QuicPacketEntropyHash GetPacketEntropy(QuicPacketNumber packet_number) const; | |
| 68 | |
| 69 // Update the cumulative entropy to |packet_number|. | |
| 70 void UpdateCumulativeEntropy(QuicPacketNumber packet_number, | |
| 71 CumulativeEntropy* cumulative) const; | |
| 72 | |
| 73 // Maps packet numbers to the sent entropy hash for the packet number. | |
| 74 SentEntropyMap packets_entropy_; | |
| 75 QuicPacketNumber map_offset_; | |
| 76 | |
| 77 // Cache the cumulative entropy for IsValidEntropy. | |
| 78 CumulativeEntropy last_valid_entropy_; | |
| 79 | |
| 80 // Cache the cumulative entropy for the packet number used by EntropyHash. | |
| 81 CumulativeEntropy last_cumulative_entropy_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(QuicSentEntropyManager); | |
| 84 }; | |
| 85 | |
| 86 } // namespace net | |
| 87 | |
| 88 #endif // NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ | |
| OLD | NEW |