| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Manages the packet entropy calculation for both sent and received packets | 5 // Manages the packet entropy calculation for both sent and received packets |
| 6 // for a connection. | 6 // for a connection. |
| 7 | 7 |
| 8 #ifndef NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ | 8 #ifndef NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ |
| 9 #define NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ | 9 #define NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ |
| 10 | 10 |
| 11 #include "net/base/linked_hash_map.h" | 11 #include "net/base/linked_hash_map.h" |
| 12 #include "net/quic/quic_framer.h" | 12 #include "net/quic/quic_framer.h" |
| 13 #include "net/quic/quic_protocol.h" | 13 #include "net/quic/quic_protocol.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 namespace test { |
| 18 class QuicConnectionPeer; |
| 19 } // namespace test |
| 20 |
| 17 // Records all sent packets by a connection to track the cumulative entropy of | 21 // 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 | 22 // 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 | 23 // frame sent by the peer as a preventive measure against the optimistic ack |
| 20 // attack. | 24 // attack. |
| 21 class NET_EXPORT_PRIVATE QuicSentEntropyManager { | 25 class NET_EXPORT_PRIVATE QuicSentEntropyManager { |
| 22 public: | 26 public: |
| 23 QuicSentEntropyManager(); | 27 QuicSentEntropyManager(); |
| 24 virtual ~QuicSentEntropyManager(); | 28 virtual ~QuicSentEntropyManager(); |
| 25 | 29 |
| 26 // Record |entropy_hash| for sent packet corresponding to |sequence_number|. | 30 // Record |entropy_hash| for sent packet corresponding to |sequence_number|. |
| 27 void RecordPacketEntropyHash(QuicPacketSequenceNumber sequence_number, | 31 void RecordPacketEntropyHash(QuicPacketSequenceNumber sequence_number, |
| 28 QuicPacketEntropyHash entropy_hash); | 32 QuicPacketEntropyHash entropy_hash); |
| 29 | 33 |
| 30 QuicPacketEntropyHash EntropyHash( | 34 QuicPacketEntropyHash EntropyHash( |
| 31 QuicPacketSequenceNumber sequence_number) const; | 35 QuicPacketSequenceNumber sequence_number) const; |
| 32 | 36 |
| 33 // Returns true if |entropy_hash| matches the expected sent entropy hash | 37 // Returns true if |entropy_hash| matches the expected sent entropy hash |
| 34 // up to |sequence_number| removing sequence numbers from |missing_packets|. | 38 // up to |sequence_number| removing sequence numbers from |missing_packets|. |
| 35 bool IsValidEntropy(QuicPacketSequenceNumber sequence_number, | 39 bool IsValidEntropy(QuicPacketSequenceNumber sequence_number, |
| 36 const SequenceNumberSet& missing_packets, | 40 const SequenceNumberSet& missing_packets, |
| 37 QuicPacketEntropyHash entropy_hash) const; | 41 QuicPacketEntropyHash entropy_hash) const; |
| 38 | 42 |
| 39 // Removes not required entries from |packets_entropy_| before | 43 // Removes not required entries from |packets_entropy_| before |
| 40 // |sequence_number|. | 44 // |sequence_number|. |
| 41 void ClearEntropyBefore(QuicPacketSequenceNumber sequence_number); | 45 void ClearEntropyBefore(QuicPacketSequenceNumber sequence_number); |
| 42 | 46 |
| 43 private: | 47 private: |
| 48 friend class test::QuicConnectionPeer; |
| 49 |
| 44 typedef linked_hash_map<QuicPacketSequenceNumber, | 50 typedef linked_hash_map<QuicPacketSequenceNumber, |
| 45 std::pair<QuicPacketEntropyHash, | 51 std::pair<QuicPacketEntropyHash, |
| 46 QuicPacketEntropyHash> > SentEntropyMap; | 52 QuicPacketEntropyHash> > SentEntropyMap; |
| 47 | 53 |
| 48 // Linked hash map from sequence numbers to the sent entropy hash up to the | 54 // Linked hash map from sequence numbers to the sent entropy hash up to the |
| 49 // sequence number in the key. | 55 // sequence number in the key. |
| 50 SentEntropyMap packets_entropy_; | 56 SentEntropyMap packets_entropy_; |
| 51 | 57 |
| 52 // Cumulative hash of entropy of all sent packets. | 58 // Cumulative hash of entropy of all sent packets. |
| 53 QuicPacketEntropyHash packets_entropy_hash_; | 59 QuicPacketEntropyHash packets_entropy_hash_; |
| 54 | 60 |
| 55 DISALLOW_COPY_AND_ASSIGN(QuicSentEntropyManager); | 61 DISALLOW_COPY_AND_ASSIGN(QuicSentEntropyManager); |
| 56 }; | 62 }; |
| 57 | 63 |
| 58 } // namespace net | 64 } // namespace net |
| 59 | 65 |
| 60 #endif // NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ | 66 #endif // NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ |
| OLD | NEW |