| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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 "net/base/linked_hash_map.h" |
| 12 #include "net/quic/quic_framer.h" |
| 13 #include "net/quic/quic_protocol.h" |
| 14 |
| 15 namespace net { |
| 16 |
| 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(); |
| 25 |
| 26 // Record |entropy_hash| for sent packet corresponding to |sequence_number|. |
| 27 void RecordPacketEntropyHash(QuicPacketSequenceNumber sequence_number, |
| 28 QuicPacketEntropyHash entropy_hash); |
| 29 |
| 30 QuicPacketEntropyHash EntropyHash( |
| 31 QuicPacketSequenceNumber sequence_number) const; |
| 32 |
| 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; |
| 38 |
| 39 // Removes not required entries from |packets_entropy_| before |
| 40 // |sequence_number|. |
| 41 void ClearEntropyBefore(QuicPacketSequenceNumber sequence_number); |
| 42 |
| 43 QuicPacketEntropyHash packets_entropy_hash() const { |
| 44 return packets_entropy_hash_; |
| 45 } |
| 46 |
| 47 private: |
| 48 typedef linked_hash_map<QuicPacketSequenceNumber, |
| 49 std::pair<QuicPacketEntropyHash, |
| 50 QuicPacketEntropyHash> > SentEntropyMap; |
| 51 |
| 52 // Linked hash map from sequence numbers to the sent entropy hash up to the |
| 53 // sequence number in the key. |
| 54 SentEntropyMap packets_entropy_; |
| 55 |
| 56 // Cumulative hash of entropy of all sent packets. |
| 57 QuicPacketEntropyHash packets_entropy_hash_; |
| 58 }; |
| 59 |
| 60 } // namespace net |
| 61 |
| 62 #endif // NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ |
| OLD | NEW |