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

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

Issue 12334063: Land recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more EXPECT_FALSE Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_fec_group_test.cc ('k') | net/quic/quic_framer.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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 #ifndef NET_QUIC_QUIC_FRAMER_H_ 5 #ifndef NET_QUIC_QUIC_FRAMER_H_
6 #define NET_QUIC_QUIC_FRAMER_H_ 6 #define NET_QUIC_QUIC_FRAMER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 virtual void OnCongestionFeedbackFrame( 67 virtual void OnCongestionFeedbackFrame(
68 const QuicCongestionFeedbackFrame& frame) = 0; 68 const QuicCongestionFeedbackFrame& frame) = 0;
69 69
70 // Called when a RstStreamFrame has been parsed. 70 // Called when a RstStreamFrame has been parsed.
71 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) = 0; 71 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) = 0;
72 72
73 // Called when a ConnectionCloseFrame has been parsed. 73 // Called when a ConnectionCloseFrame has been parsed.
74 virtual void OnConnectionCloseFrame( 74 virtual void OnConnectionCloseFrame(
75 const QuicConnectionCloseFrame& frame) = 0; 75 const QuicConnectionCloseFrame& frame) = 0;
76 76
77 // Called when a GoAwayFrame has been parsed.
78 virtual void OnGoAwayFrame(const QuicGoAwayFrame& frame) = 0;
79
77 // Called when FEC data has been parsed. 80 // Called when FEC data has been parsed.
78 virtual void OnFecData(const QuicFecData& fec) = 0; 81 virtual void OnFecData(const QuicFecData& fec) = 0;
79 82
80 // Called when a packet has been completely processed. 83 // Called when a packet has been completely processed.
81 virtual void OnPacketComplete() = 0; 84 virtual void OnPacketComplete() = 0;
82 }; 85 };
83 86
84 class NET_EXPORT_PRIVATE QuicFecBuilderInterface { 87 class NET_EXPORT_PRIVATE QuicFecBuilderInterface {
85 public: 88 public:
86 virtual ~QuicFecBuilderInterface() {} 89 virtual ~QuicFecBuilderInterface() {}
87 90
88 // Called when a data packet is constructed that is part of an FEC group. 91 // Called when a data packet is constructed that is part of an FEC group.
89 // |payload| is the non-encrypted FEC protected payload of the packet. 92 // |payload| is the non-encrypted FEC protected payload of the packet.
90 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header, 93 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header,
91 base::StringPiece payload) = 0; 94 base::StringPiece payload) = 0;
92 }; 95 };
93 96
97 // This class calculates the received entropy of the ack packet being
98 // framed, should it get truncated.
99 class NET_EXPORT_PRIVATE QuicReceivedEntropyHashCalculatorInterface {
100 public:
101 virtual ~QuicReceivedEntropyHashCalculatorInterface() {}
102
103 // When an ack frame gets truncated while being framed the received
104 // entropy of the ack frame needs to be calculated since the some of the
105 // missing packets are not added and the largest observed might be lowered.
106 // This should return the received entropy hash of the packets received up to
107 // and including |sequence_number|.
108 virtual QuicPacketEntropyHash ReceivedEntropyHash(
109 QuicPacketSequenceNumber sequence_number) const = 0;
110 };
111
94 // Class for parsing and constructing QUIC packets. It has a 112 // Class for parsing and constructing QUIC packets. It has a
95 // QuicFramerVisitorInterface that is called when packets are parsed. 113 // QuicFramerVisitorInterface that is called when packets are parsed.
96 // It also has a QuicFecBuilder that is called when packets are constructed 114 // It also has a QuicFecBuilder that is called when packets are constructed
97 // in order to generate FEC data for subsequently building FEC packets. 115 // in order to generate FEC data for subsequently building FEC packets.
98 class NET_EXPORT_PRIVATE QuicFramer { 116 class NET_EXPORT_PRIVATE QuicFramer {
99 public: 117 public:
100 // Constructs a new framer that will own |decrypter| and |encrypter|. 118 // Constructs a new framer that will own |decrypter| and |encrypter|.
101 QuicFramer(QuicDecrypter* decrypter, QuicEncrypter* encrypter); 119 QuicFramer(QuicDecrypter* decrypter, QuicEncrypter* encrypter);
102 120
103 virtual ~QuicFramer(); 121 virtual ~QuicFramer();
104 122
105 // Calculates the largest observed packet to advertise in the case an Ack 123 // Calculates the largest observed packet to advertise in the case an Ack
106 // Frame was truncated. last_written in this case is the iterator for the 124 // Frame was truncated. last_written in this case is the iterator for the
107 // last missing packet which fit in the outgoing ack. 125 // last missing packet which fit in the outgoing ack.
108 static QuicPacketSequenceNumber CalculateLargestObserved( 126 static QuicPacketSequenceNumber CalculateLargestObserved(
109 const SequenceSet& missing_packets, 127 const SequenceNumberSet& missing_packets,
110 SequenceSet::const_iterator last_written); 128 SequenceNumberSet::const_iterator last_written);
111 129
112 // Set callbacks to be called from the framer. A visitor must be set, or 130 // Set callbacks to be called from the framer. A visitor must be set, or
113 // else the framer will likely crash. It is acceptable for the visitor 131 // else the framer will likely crash. It is acceptable for the visitor
114 // to do nothing. If this is called multiple times, only the last visitor 132 // to do nothing. If this is called multiple times, only the last visitor
115 // will be used. 133 // will be used.
116 void set_visitor(QuicFramerVisitorInterface* visitor) { 134 void set_visitor(QuicFramerVisitorInterface* visitor) {
117 visitor_ = visitor; 135 visitor_ = visitor;
118 } 136 }
119 137
120 // Set a builder to be called from the framer when building FEC protected 138 // Set a builder to be called from the framer when building FEC protected
121 // packets. If this is called multiple times, only the last builder 139 // packets. If this is called multiple times, only the last builder
122 // will be used. The builder need not be set. 140 // will be used. The builder need not be set.
123 void set_fec_builder(QuicFecBuilderInterface* builder) { 141 void set_fec_builder(QuicFecBuilderInterface* builder) {
124 fec_builder_ = builder; 142 fec_builder_ = builder;
125 } 143 }
126 144
145 // Set entropy calculator to be called from the framer when it needs the
146 // entropy of a truncated ack frame. An entropy calculator must be set or else
147 // the framer will likely crash. If this is called multiple times, only the
148 // last visitor will be used.
149 void set_entropy_calculator(
150 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator) {
151 entropy_calculator_ = entropy_calculator;
152 }
153
127 QuicErrorCode error() const { 154 QuicErrorCode error() const {
128 return error_; 155 return error_;
129 } 156 }
130 157
131 // Pass a UDP packet into the framer for parsing. 158 // Pass a UDP packet into the framer for parsing.
132 // Return true if the packet was processed succesfully. |packet| must be a 159 // Return true if the packet was processed succesfully. |packet| must be a
133 // single, complete UDP packet (not a frame of a packet). This packet 160 // single, complete UDP packet (not a frame of a packet). This packet
134 // might be null padded past the end of the payload, which will be correctly 161 // might be null padded past the end of the payload, which will be correctly
135 // ignored. 162 // ignored.
136 bool ProcessPacket(const QuicEncryptedPacket& packet); 163 bool ProcessPacket(const QuicEncryptedPacket& packet);
137 164
138 // Pass a data packet that was revived from FEC data into the framer 165 // Pass a data packet that was revived from FEC data into the framer
139 // for parsing. 166 // for parsing.
140 // Return true if the packet was processed succesfully. |payload| must be 167 // Return true if the packet was processed succesfully. |payload| must be
141 // the complete DECRYPTED payload of the revived packet. 168 // the complete DECRYPTED payload of the revived packet.
142 bool ProcessRevivedPacket(const QuicPacketHeader& header, 169 bool ProcessRevivedPacket(QuicPacketHeader* header,
143 base::StringPiece payload); 170 base::StringPiece payload);
144 171
145 // Returns the number of bytes added to the packet for the specified frame, 172 // Returns the number of bytes added to the packet for the specified frame,
146 // and 0 if the frame doesn't fit. Includes the header size for the first 173 // and 0 if the frame doesn't fit. Includes the header size for the first
147 // frame. 174 // frame.
148 size_t GetSerializedFrameLength( 175 size_t GetSerializedFrameLength(
149 const QuicFrame& frame, size_t free_bytes, bool first_frame); 176 const QuicFrame& frame, size_t free_bytes, bool first_frame);
150 177
151 // Returns a new QuicPacket, owned by the caller, populated with the fields 178 // Returns a SerializedPacket whose |packet| member is owned by the caller,
152 // in |header| and |frames|, or NULL if the packet could not be created. 179 // and is populated with the fields in |header| and |frames|, or is NULL if
180 // the packet could not be created.
153 // TODO(ianswett): Used for testing only. 181 // TODO(ianswett): Used for testing only.
154 QuicPacket* ConstructFrameDataPacket(const QuicPacketHeader& header, 182 SerializedPacket ConstructFrameDataPacket(const QuicPacketHeader& header,
155 const QuicFrames& frames); 183 const QuicFrames& frames);
156 184
157 // Returns a new QuicPacket from the first |num_frames| frames, owned by the 185 // Returns a SerializedPacket whose |packet| member is owned by the caller,
158 // caller or NULL if the packet could not be created. The packet must be of 186 // is created from the first |num_frames| frames, or is NULL if the packet
159 // size |packet_size|. 187 // could not be created. The packet must be of size |packet_size|.
160 QuicPacket* ConstructFrameDataPacket(const QuicPacketHeader& header, 188 SerializedPacket ConstructFrameDataPacket(const QuicPacketHeader& header,
161 const QuicFrames& frames, 189 const QuicFrames& frames,
162 size_t packet_size); 190 size_t packet_size);
163 191
164 // Returns a new QuicPacket, owned by the caller, populated with the fields 192 // Returns a SerializedPacket whose |packet| member is owned by the caller,
165 // in |header| and |fec|, or NULL if the packet could not be created. 193 // and is populated with the fields in |header| and |fec|, or is NULL if the
166 QuicPacket* ConstructFecPacket(const QuicPacketHeader& header, 194 // packet could not be created.
195 SerializedPacket ConstructFecPacket(const QuicPacketHeader& header,
167 const QuicFecData& fec); 196 const QuicFecData& fec);
168 197
169 // Returns a new public reset packet, owned by the caller. 198 // Returns a new public reset packet, owned by the caller.
170 static QuicEncryptedPacket* ConstructPublicResetPacket( 199 static QuicEncryptedPacket* ConstructPublicResetPacket(
171 const QuicPublicResetPacket& packet); 200 const QuicPublicResetPacket& packet);
172 201
173 // Returns a new encrypted packet, owned by the caller. 202 // Returns a new encrypted packet, owned by the caller.
174 QuicEncryptedPacket* EncryptPacket(const QuicPacket& packet); 203 QuicEncryptedPacket* EncryptPacket(QuicPacketSequenceNumber sequence_number,
204 const QuicPacket& packet);
175 205
176 // Returns the maximum length of plaintext that can be encrypted 206 // Returns the maximum length of plaintext that can be encrypted
177 // to ciphertext no larger than |ciphertext_size|. 207 // to ciphertext no larger than |ciphertext_size|.
178 size_t GetMaxPlaintextSize(size_t ciphertext_size); 208 size_t GetMaxPlaintextSize(size_t ciphertext_size);
179 209
180 const std::string& detailed_error() { return detailed_error_; } 210 const std::string& detailed_error() { return detailed_error_; }
181 211
182 // Read the guid from a packet header. 212 // Read the guid from a packet header.
183 // Return true on success, else false. 213 // Return true on success, else false.
184 static bool ReadGuidFromPacket(const QuicEncryptedPacket& packet, 214 static bool ReadGuidFromPacket(const QuicEncryptedPacket& packet,
185 QuicGuid* guid); 215 QuicGuid* guid);
186 216
187 private: 217 private:
188 friend class test::QuicFramerPeer; 218 friend class test::QuicFramerPeer;
189 219
220 QuicPacketEntropyHash GetPacketEntropyHash(
221 const QuicPacketHeader& header) const;
222
190 bool ProcessDataPacket(const QuicPacketPublicHeader& public_header, 223 bool ProcessDataPacket(const QuicPacketPublicHeader& public_header,
191 const QuicEncryptedPacket& packet); 224 const QuicEncryptedPacket& packet);
192 225
193 bool ProcessPublicResetPacket(const QuicPacketPublicHeader& public_header); 226 bool ProcessPublicResetPacket(const QuicPacketPublicHeader& public_header);
194 227
195 bool WritePacketHeader(const QuicPacketHeader& header, 228 bool WritePacketHeader(const QuicPacketHeader& header,
196 QuicDataWriter* writer); 229 QuicDataWriter* writer);
197 230
198 bool ProcessPublicHeader(QuicPacketPublicHeader* header); 231 bool ProcessPublicHeader(QuicPacketPublicHeader* header);
199 232
200 bool ProcessPacketHeader(QuicPacketHeader* header, 233 bool ProcessPacketHeader(QuicPacketHeader* header,
201 const QuicEncryptedPacket& packet); 234 const QuicEncryptedPacket& packet);
202 235
203 bool ProcessPacketSequenceNumber(QuicPacketSequenceNumber* sequence_number); 236 bool ProcessPacketSequenceNumber(QuicPacketSequenceNumber* sequence_number);
204 bool ProcessFrameData(); 237 bool ProcessFrameData();
205 bool ProcessStreamFrame(); 238 bool ProcessStreamFrame();
206 bool ProcessAckFrame(QuicAckFrame* frame); 239 bool ProcessAckFrame(QuicAckFrame* frame);
207 bool ProcessReceivedInfo(ReceivedPacketInfo* received_info); 240 bool ProcessReceivedInfo(ReceivedPacketInfo* received_info);
208 bool ProcessSentInfo(SentPacketInfo* sent_info); 241 bool ProcessSentInfo(SentPacketInfo* sent_info);
209 bool ProcessQuicCongestionFeedbackFrame( 242 bool ProcessQuicCongestionFeedbackFrame(
210 QuicCongestionFeedbackFrame* congestion_feedback); 243 QuicCongestionFeedbackFrame* congestion_feedback);
211 bool ProcessRstStreamFrame(); 244 bool ProcessRstStreamFrame();
212 bool ProcessConnectionCloseFrame(); 245 bool ProcessConnectionCloseFrame();
246 bool ProcessGoAwayFrame();
213 247
214 bool DecryptPayload(const QuicEncryptedPacket& packet); 248 bool DecryptPayload(QuicPacketSequenceNumber packet_sequence_number,
249 const QuicEncryptedPacket& packet);
215 250
216 // Returns the full packet sequence number from the truncated 251 // Returns the full packet sequence number from the truncated
217 // wire format version and the last seen packet sequence number. 252 // wire format version and the last seen packet sequence number.
218 QuicPacketSequenceNumber CalculatePacketSequenceNumberFromWire( 253 QuicPacketSequenceNumber CalculatePacketSequenceNumberFromWire(
219 QuicPacketSequenceNumber packet_sequence_number) const; 254 QuicPacketSequenceNumber packet_sequence_number) const;
220 255
221 // Computes the wire size in bytes of the payload of |frame|. 256 // Computes the wire size in bytes of the payload of |frame|.
222 size_t ComputeFramePayloadLength(const QuicFrame& frame); 257 size_t ComputeFramePayloadLength(const QuicFrame& frame);
223 258
224 static bool AppendPacketSequenceNumber( 259 static bool AppendPacketSequenceNumber(
225 QuicPacketSequenceNumber packet_sequence_number, 260 QuicPacketSequenceNumber packet_sequence_number,
226 QuicDataWriter* writer); 261 QuicDataWriter* writer);
227 262
228 bool AppendStreamFramePayload(const QuicStreamFrame& frame, 263 bool AppendStreamFramePayload(const QuicStreamFrame& frame,
229 QuicDataWriter* builder); 264 QuicDataWriter* builder);
230 bool AppendAckFramePayload(const QuicAckFrame& frame, 265 bool AppendAckFramePayload(const QuicAckFrame& frame,
231 QuicDataWriter* builder); 266 QuicDataWriter* builder);
232 bool AppendQuicCongestionFeedbackFramePayload( 267 bool AppendQuicCongestionFeedbackFramePayload(
233 const QuicCongestionFeedbackFrame& frame, 268 const QuicCongestionFeedbackFrame& frame,
234 QuicDataWriter* builder); 269 QuicDataWriter* builder);
235 bool AppendRstStreamFramePayload(const QuicRstStreamFrame& frame, 270 bool AppendRstStreamFramePayload(const QuicRstStreamFrame& frame,
236 QuicDataWriter* builder); 271 QuicDataWriter* builder);
237 bool AppendConnectionCloseFramePayload( 272 bool AppendConnectionCloseFramePayload(
238 const QuicConnectionCloseFrame& frame, 273 const QuicConnectionCloseFrame& frame,
239 QuicDataWriter* builder); 274 QuicDataWriter* builder);
275 bool AppendGoAwayFramePayload(const QuicGoAwayFrame& frame,
276 QuicDataWriter* writer);
240 bool RaiseError(QuicErrorCode error); 277 bool RaiseError(QuicErrorCode error);
241 278
242 void set_error(QuicErrorCode error) { 279 void set_error(QuicErrorCode error) {
243 error_ = error; 280 error_ = error;
244 } 281 }
245 282
246 void set_detailed_error(const char* error) { 283 void set_detailed_error(const char* error) {
247 detailed_error_ = error; 284 detailed_error_ = error;
248 } 285 }
249 286
250 std::string detailed_error_; 287 std::string detailed_error_;
251 scoped_ptr<QuicDataReader> reader_; 288 scoped_ptr<QuicDataReader> reader_;
252 QuicFramerVisitorInterface* visitor_; 289 QuicFramerVisitorInterface* visitor_;
253 QuicFecBuilderInterface* fec_builder_; 290 QuicFecBuilderInterface* fec_builder_;
291 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator_;
254 QuicErrorCode error_; 292 QuicErrorCode error_;
255 QuicPacketSequenceNumber last_sequence_number_; 293 QuicPacketSequenceNumber last_sequence_number_;
256 // Buffer containing decrypted payload data during parsing. 294 // Buffer containing decrypted payload data during parsing.
257 scoped_ptr<QuicData> decrypted_; 295 scoped_ptr<QuicData> decrypted_;
258 // Decrypter used to decrypt packets during parsing. 296 // Decrypter used to decrypt packets during parsing.
259 scoped_ptr<QuicDecrypter> decrypter_; 297 scoped_ptr<QuicDecrypter> decrypter_;
260 // Encrypter used to encrypt packets via EncryptPacket(). 298 // Encrypter used to encrypt packets via EncryptPacket().
261 scoped_ptr<QuicEncrypter> encrypter_; 299 scoped_ptr<QuicEncrypter> encrypter_;
262 300
263 DISALLOW_COPY_AND_ASSIGN(QuicFramer); 301 DISALLOW_COPY_AND_ASSIGN(QuicFramer);
264 }; 302 };
265 303
266 } // namespace net 304 } // namespace net
267 305
268 #endif // NET_QUIC_QUIC_FRAMER_H_ 306 #endif // NET_QUIC_QUIC_FRAMER_H_
OLDNEW
« no previous file with comments | « net/quic/quic_fec_group_test.cc ('k') | net/quic/quic_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698