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

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

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 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_received_packet_manager_test.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
(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_
OLDNEW
« no previous file with comments | « net/quic/quic_received_packet_manager_test.cc ('k') | net/quic/quic_sent_entropy_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698