Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: net/quic/quic_sent_entropy_manager.h

Issue 479543004: Convert QUIC's SentEntropyManager to use a deque instead of a map in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@send_updated_bandwidth_estimates_73579021
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_sent_entropy_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <deque>
12
11 #include "net/base/linked_hash_map.h" 13 #include "net/base/linked_hash_map.h"
12 #include "net/quic/quic_framer.h" 14 #include "net/quic/quic_framer.h"
13 #include "net/quic/quic_protocol.h" 15 #include "net/quic/quic_protocol.h"
14 16
15 namespace net { 17 namespace net {
16 18
17 namespace test { 19 namespace test {
18 class QuicConnectionPeer; 20 class QuicConnectionPeer;
19 } // namespace test 21 } // namespace test
20 22
21 // Records all sent packets by a connection to track the cumulative entropy of 23 // Records all sent packets by a connection to track the cumulative entropy of
22 // sent packets. It is used by the connection to validate an ack 24 // sent packets. It is used by the connection to validate an ack
23 // frame sent by the peer as a preventive measure against the optimistic ack 25 // frame sent by the peer as a preventive measure against the optimistic ack
24 // attack. 26 // attack.
25 class NET_EXPORT_PRIVATE QuicSentEntropyManager { 27 class NET_EXPORT_PRIVATE QuicSentEntropyManager {
26 public: 28 public:
27 QuicSentEntropyManager(); 29 QuicSentEntropyManager();
28 virtual ~QuicSentEntropyManager(); 30 virtual ~QuicSentEntropyManager();
29 31
30 // Record |entropy_hash| for sent packet corresponding to |sequence_number|. 32 // Record |entropy_hash| for sent packet corresponding to |sequence_number|.
31 void RecordPacketEntropyHash(QuicPacketSequenceNumber sequence_number, 33 void RecordPacketEntropyHash(QuicPacketSequenceNumber sequence_number,
32 QuicPacketEntropyHash entropy_hash); 34 QuicPacketEntropyHash entropy_hash);
33 35
34 QuicPacketEntropyHash EntropyHash( 36 // Retrieves the cumulative entropy up to |sequence_number|.
35 QuicPacketSequenceNumber sequence_number) const; 37 // Must always be called with a monotonically increasing |sequence_number|.
38 QuicPacketEntropyHash GetCumulativeEntropy(
39 QuicPacketSequenceNumber sequence_number);
36 40
37 // Returns true if |entropy_hash| matches the expected sent entropy hash 41 // Returns true if |entropy_hash| matches the expected sent entropy hash
38 // up to |sequence_number| removing sequence numbers from |missing_packets|. 42 // up to |largest_observed| removing sequence numbers from |missing_packets|.
39 bool IsValidEntropy(QuicPacketSequenceNumber sequence_number, 43 // Must always be called with a monotonically increasing |largest_observed|.
44 bool IsValidEntropy(QuicPacketSequenceNumber largest_observed,
40 const SequenceNumberSet& missing_packets, 45 const SequenceNumberSet& missing_packets,
41 QuicPacketEntropyHash entropy_hash) const; 46 QuicPacketEntropyHash entropy_hash);
42 47
43 // Removes not required entries from |packets_entropy_| before 48 // Removes unnecessary entries before |sequence_number|.
44 // |sequence_number|.
45 void ClearEntropyBefore(QuicPacketSequenceNumber sequence_number); 49 void ClearEntropyBefore(QuicPacketSequenceNumber sequence_number);
46 50
47 private: 51 private:
48 friend class test::QuicConnectionPeer; 52 friend class test::QuicConnectionPeer;
49 53
50 typedef linked_hash_map<QuicPacketSequenceNumber, 54 typedef std::deque<QuicPacketEntropyHash> SentEntropyMap;
51 std::pair<QuicPacketEntropyHash,
52 QuicPacketEntropyHash> > SentEntropyMap;
53 55
54 // Linked hash map from sequence numbers to the sent entropy hash up to the 56 struct CumulativeEntropy {
55 // sequence number in the key. 57 CumulativeEntropy() : sequence_number(0), entropy(0) {}
58
59 QuicPacketSequenceNumber sequence_number;
60 QuicPacketEntropyHash entropy;
61 };
62
63 // Convenience methods to get the largest and smallest packets with entropies.
64 QuicPacketSequenceNumber GetLargestPacketWithEntropy() const;
65 QuicPacketSequenceNumber GetSmallestPacketWithEntropy() const;
66 // Convenience method to get the entropy hash for |sequence_number|.
67 QuicPacketEntropyHash GetPacketEntropy(
68 QuicPacketSequenceNumber sequence_number) const;
69
70 // Update the cumulative entropy to |sequence_number|.
71 void UpdateCumulativeEntropy(QuicPacketSequenceNumber sequence_number,
72 CumulativeEntropy* cumulative) const;
73
74 // Maps sequence numbers to the sent entropy hash for the sequence number.
56 SentEntropyMap packets_entropy_; 75 SentEntropyMap packets_entropy_;
76 QuicPacketSequenceNumber map_offset_;
57 77
58 // Cumulative hash of entropy of all sent packets. 78 // Cache the cumulative entropy for IsValidEntropy.
59 QuicPacketEntropyHash packets_entropy_hash_; 79 CumulativeEntropy last_valid_entropy_;
80
81 // Cache the cumulative entropy for the sequence number used by EntropyHash.
82 CumulativeEntropy last_cumulative_entropy_;
60 83
61 DISALLOW_COPY_AND_ASSIGN(QuicSentEntropyManager); 84 DISALLOW_COPY_AND_ASSIGN(QuicSentEntropyManager);
62 }; 85 };
63 86
64 } // namespace net 87 } // namespace net
65 88
66 #endif // NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_ 89 #endif // NET_QUIC_QUIC_SENT_ENTROPY_MANAGER_H_
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_sent_entropy_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698