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

Side by Side Diff: net/quic/quic_received_packet_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_protocol_test.cc ('k') | net/quic/quic_received_packet_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_RECEIVED_PACKET_MANAGER_H_
9 #define NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_
10
11 #include <stddef.h>
12
13 #include <deque>
14
15 #include "base/macros.h"
16 #include "net/quic/quic_config.h"
17 #include "net/quic/quic_framer.h"
18 #include "net/quic/quic_protocol.h"
19
20 namespace net {
21
22 namespace test {
23 class EntropyTrackerPeer;
24 class QuicConnectionPeer;
25 class QuicReceivedPacketManagerPeer;
26 } // namespace test
27
28 struct QuicConnectionStats;
29
30 // Records all received packets by a connection and tracks their entropy.
31 // Also calculates the correct entropy for the framer when it truncates an ack
32 // frame being serialized.
33 class NET_EXPORT_PRIVATE QuicReceivedPacketManager
34 : public QuicReceivedEntropyHashCalculatorInterface {
35 public:
36 class NET_EXPORT_PRIVATE EntropyTracker {
37 public:
38 EntropyTracker();
39 ~EntropyTracker();
40
41 // Compute the XOR of the entropy of all received packets up to
42 // and including packet_number.
43 // Requires that either:
44 // packet_number == largest_observed_
45 // or:
46 // packet_number > first_gap_ &&
47 // packet_number < largest_observed_ &&
48 // packet_number in packets_entropy_
49 QuicPacketEntropyHash EntropyHash(QuicPacketNumber packet_number) const;
50
51 // Record the received entropy hash against |packet_number|.
52 // Performs garbage collection to advance first_gap_ if
53 // packet_number == first_gap_.
54 void RecordPacketEntropyHash(QuicPacketNumber packet_number,
55 QuicPacketEntropyHash entropy_hash);
56
57 // Sets the entropy hash up to but not including a packet number based
58 // on the hash provided by a StopWaiting frame. Clears older packet
59 // entropy entries and performs garbage collection up to the first gap.
60 void SetCumulativeEntropyUpTo(QuicPacketNumber packet_number,
61 QuicPacketEntropyHash entropy_hash);
62
63 size_t size() const { return packets_entropy_.size(); }
64
65 private:
66 friend class test::EntropyTrackerPeer;
67
68 // A deque indexed by packet number storing the packet's hash and whether
69 // a hash was recorded for that packet number.
70 typedef std::deque<std::pair<QuicPacketEntropyHash, bool>>
71 ReceivedEntropyHashes;
72
73 // Recomputes first_gap_ and removes packets_entropy_ entries that are no
74 // longer needed to compute EntropyHash.
75 void AdvanceFirstGapAndGarbageCollectEntropyMap();
76
77 // Map of received packet numbers to their corresponding entropy.
78 // Stores an entry for every received packet whose packet_number is larger
79 // than first_gap_. Packets without the entropy bit set have an entropy
80 // value of 0.
81 ReceivedEntropyHashes packets_entropy_;
82
83 // Cumulative hash of entropy of all received packets.
84 QuicPacketEntropyHash packets_entropy_hash_;
85
86 // packet number of the first packet that we do not know the entropy of.
87 // If there are no gaps in the received packet sequence,
88 // packets_entropy_ will be empty and first_gap_ will be equal to
89 // 'largest_observed_ + 1' since that's the first packet for which
90 // entropy is unknown. If there are gaps, packets_entropy_ will
91 // contain entries for all received packets with packet_number >
92 // first_gap_.
93 QuicPacketNumber first_gap_;
94
95 // packet number of the largest observed packet.
96 QuicPacketNumber largest_observed_;
97
98 DISALLOW_COPY_AND_ASSIGN(EntropyTracker);
99 };
100
101 explicit QuicReceivedPacketManager(QuicConnectionStats* stats);
102 ~QuicReceivedPacketManager() override;
103
104 // Updates the internal state concerning which packets have been received.
105 // bytes: the packet size in bytes including Quic Headers.
106 // header: the packet header.
107 // timestamp: the arrival time of the packet.
108 virtual void RecordPacketReceived(QuicByteCount bytes,
109 const QuicPacketHeader& header,
110 QuicTime receipt_time);
111
112 // Checks whether |packet_number| is missing and less than largest observed.
113 virtual bool IsMissing(QuicPacketNumber packet_number);
114
115 // Checks if we're still waiting for the packet with |packet_number|.
116 virtual bool IsAwaitingPacket(QuicPacketNumber packet_number);
117
118 // Retrieves a frame containing a QuicAckFrame. The ack frame may not be
119 // changed outside QuicReceivedPacketManager and must be serialized before
120 // another packet is received, or it will change.
121 const QuicFrame GetUpdatedAckFrame(QuicTime approximate_now);
122
123 // QuicReceivedEntropyHashCalculatorInterface
124 // Called by QuicFramer, when the outgoing ack gets truncated, to recalculate
125 // the received entropy hash for the truncated ack frame.
126 QuicPacketEntropyHash EntropyHash(
127 QuicPacketNumber packet_number) const override;
128
129 // Updates internal state based on |stop_waiting|.
130 virtual void UpdatePacketInformationSentByPeer(
131 const QuicStopWaitingFrame& stop_waiting);
132
133 // Returns true if there are any missing packets.
134 bool HasMissingPackets() const;
135
136 // Returns true when there are new missing packets to be reported within 3
137 // packets of the largest observed.
138 virtual bool HasNewMissingPackets() const;
139
140 // Returns the number of packets being tracked in the EntropyTracker.
141 size_t NumTrackedPackets() const;
142
143 // Sets the mode of packets set of ack_frame_ based on |version|.
144 void SetVersion(QuicVersion version);
145
146 QuicPacketNumber peer_least_packet_awaiting_ack() {
147 return peer_least_packet_awaiting_ack_;
148 }
149
150 virtual bool ack_frame_updated() const;
151
152 QuicPacketNumber GetLargestObserved() const;
153
154 // For logging purposes.
155 const QuicAckFrame& ack_frame() const { return ack_frame_; }
156
157 private:
158 friend class test::QuicConnectionPeer;
159 friend class test::QuicReceivedPacketManagerPeer;
160
161 // Deletes all missing packets before least unacked. The connection won't
162 // process any packets with packet number before |least_unacked| that it
163 // received after this call. Returns true if there were missing packets before
164 // |least_unacked| unacked, false otherwise.
165 bool DontWaitForPacketsBefore(QuicPacketNumber least_unacked);
166
167 // Tracks entropy hashes of received packets.
168 EntropyTracker entropy_tracker_;
169
170 // Least packet number of the the packet sent by the peer for which it
171 // hasn't received an ack.
172 QuicPacketNumber peer_least_packet_awaiting_ack_;
173
174 // Received packet information used to produce acks.
175 QuicAckFrame ack_frame_;
176
177 // True if |ack_frame_| has been updated since UpdateReceivedPacketInfo was
178 // last called.
179 bool ack_frame_updated_;
180
181 // The time we received the largest_observed packet number, or zero if
182 // no packet numbers have been received since UpdateReceivedPacketInfo.
183 // Needed for calculating ack_delay_time.
184 QuicTime time_largest_observed_;
185
186 QuicConnectionStats* stats_;
187
188 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacketManager);
189 };
190
191 } // namespace net
192
193 #endif // NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_
OLDNEW
« no previous file with comments | « net/quic/quic_protocol_test.cc ('k') | net/quic/quic_received_packet_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698