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

Side by Side Diff: net/quic/quic_framer.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_frame_list.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_QUIC_FRAMER_H_
6 #define NET_QUIC_QUIC_FRAMER_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12 #include <string>
13 #include <unordered_map>
14 #include <unordered_set>
15 #include <vector>
16
17 #include "base/logging.h"
18 #include "base/macros.h"
19 #include "base/strings/string_piece.h"
20 #include "net/base/net_export.h"
21 #include "net/quic/quic_protocol.h"
22
23 namespace net {
24
25 namespace test {
26 class QuicFramerPeer;
27 } // namespace test
28
29 class QuicDataReader;
30 class QuicDataWriter;
31 class QuicDecrypter;
32 class QuicEncrypter;
33 class QuicFramer;
34
35 // Number of bytes reserved for the frame type preceding each frame.
36 const size_t kQuicFrameTypeSize = 1;
37 // Number of bytes reserved for error code.
38 const size_t kQuicErrorCodeSize = 4;
39 // Number of bytes reserved to denote the length of error details field.
40 const size_t kQuicErrorDetailsLengthSize = 2;
41
42 // Maximum number of bytes reserved for stream id.
43 const size_t kQuicMaxStreamIdSize = 4;
44 // Maximum number of bytes reserved for byte offset in stream frame.
45 const size_t kQuicMaxStreamOffsetSize = 8;
46 // Number of bytes reserved to store payload length in stream frame.
47 const size_t kQuicStreamPayloadLengthSize = 2;
48
49 // Size in bytes of the entropy hash sent in ack frames.
50 const size_t kQuicEntropyHashSize = 1;
51 // Size in bytes reserved for the delta time of the largest observed
52 // packet number in ack frames.
53 const size_t kQuicDeltaTimeLargestObservedSize = 2;
54 // Size in bytes reserved for the number of received packets with timestamps.
55 const size_t kQuicNumTimestampsSize = 1;
56 // Size in bytes reserved for the number of missing packets in ack frames.
57 const size_t kNumberOfNackRangesSize = 1;
58 // Size in bytes reserved for the number of ack blocks in ack frames.
59 const size_t kNumberOfAckBlocksSize = 1;
60 // Maximum number of missing packet ranges that can fit within an ack frame.
61 const size_t kMaxNackRanges = (1 << (kNumberOfNackRangesSize * 8)) - 1;
62 // Maximum number of ack blocks that can fit within an ack frame.
63 const size_t kMaxAckBlocks = (1 << (kNumberOfAckBlocksSize * 8)) - 1;
64 // Size in bytes reserved for the number of revived packets in ack frames.
65 const size_t kNumberOfRevivedPacketsSize = 1;
66
67 // This class receives callbacks from the framer when packets
68 // are processed.
69 class NET_EXPORT_PRIVATE QuicFramerVisitorInterface {
70 public:
71 virtual ~QuicFramerVisitorInterface() {}
72
73 // Called if an error is detected in the QUIC protocol.
74 virtual void OnError(QuicFramer* framer) = 0;
75
76 // Called only when |perspective_| is IS_SERVER and the the framer gets a
77 // packet with version flag true and the version on the packet doesn't match
78 // |quic_version_|. The visitor should return true after it updates the
79 // version of the |framer_| to |received_version| or false to stop processing
80 // this packet.
81 virtual bool OnProtocolVersionMismatch(QuicVersion received_version) = 0;
82
83 // Called when a new packet has been received, before it
84 // has been validated or processed.
85 virtual void OnPacket() = 0;
86
87 // Called when a public reset packet has been parsed but has not yet
88 // been validated.
89 virtual void OnPublicResetPacket(const QuicPublicResetPacket& packet) = 0;
90
91 // Called only when |perspective_| is IS_CLIENT and a version negotiation
92 // packet has been parsed.
93 virtual void OnVersionNegotiationPacket(
94 const QuicVersionNegotiationPacket& packet) = 0;
95
96 // Called when the public header has been parsed, but has not been
97 // authenticated. If it returns false, framing for this packet will cease.
98 virtual bool OnUnauthenticatedPublicHeader(
99 const QuicPacketPublicHeader& header) = 0;
100
101 // Called when the unauthenticated portion of the header has been parsed.
102 // If OnUnauthenticatedHeader returns false, framing for this packet will
103 // cease.
104 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) = 0;
105
106 // Called when a packet has been decrypted. |level| is the encryption level
107 // of the packet.
108 virtual void OnDecryptedPacket(EncryptionLevel level) = 0;
109
110 // Called when the complete header of a packet had been parsed.
111 // If OnPacketHeader returns false, framing for this packet will cease.
112 virtual bool OnPacketHeader(const QuicPacketHeader& header) = 0;
113
114 // Called when a StreamFrame has been parsed.
115 virtual bool OnStreamFrame(const QuicStreamFrame& frame) = 0;
116
117 // Called when a AckFrame has been parsed. If OnAckFrame returns false,
118 // the framer will stop parsing the current packet.
119 virtual bool OnAckFrame(const QuicAckFrame& frame) = 0;
120
121 // Called when a StopWaitingFrame has been parsed.
122 virtual bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) = 0;
123
124 // Called when a QuicPaddingFrame has been parsed.
125 virtual bool OnPaddingFrame(const QuicPaddingFrame& frame) = 0;
126
127 // Called when a PingFrame has been parsed.
128 virtual bool OnPingFrame(const QuicPingFrame& frame) = 0;
129
130 // Called when a RstStreamFrame has been parsed.
131 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) = 0;
132
133 // Called when a ConnectionCloseFrame has been parsed.
134 virtual bool OnConnectionCloseFrame(
135 const QuicConnectionCloseFrame& frame) = 0;
136
137 // Called when a GoAwayFrame has been parsed.
138 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) = 0;
139
140 // Called when a WindowUpdateFrame has been parsed.
141 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) = 0;
142
143 // Called when a BlockedFrame has been parsed.
144 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) = 0;
145
146 // Called when a PathCloseFrame has been parsed.
147 virtual bool OnPathCloseFrame(const QuicPathCloseFrame& frame) = 0;
148
149 // Called when a packet has been completely processed.
150 virtual void OnPacketComplete() = 0;
151 };
152
153 // This class calculates the received entropy of the ack packet being
154 // framed, should it get truncated.
155 class NET_EXPORT_PRIVATE QuicReceivedEntropyHashCalculatorInterface {
156 public:
157 virtual ~QuicReceivedEntropyHashCalculatorInterface() {}
158
159 // When an ack frame gets truncated while being framed the received
160 // entropy of the ack frame needs to be calculated since the some of the
161 // missing packets are not added and the largest observed might be lowered.
162 // This should return the received entropy hash of the packets received up to
163 // and including |packet_number|.
164 virtual QuicPacketEntropyHash EntropyHash(
165 QuicPacketNumber packet_number) const = 0;
166 };
167
168 // Class for parsing and constructing QUIC packets. It has a
169 // QuicFramerVisitorInterface that is called when packets are parsed.
170 class NET_EXPORT_PRIVATE QuicFramer {
171 public:
172 // Constructs a new framer that installs a kNULL QuicEncrypter and
173 // QuicDecrypter for level ENCRYPTION_NONE. |supported_versions| specifies the
174 // list of supported QUIC versions. |quic_version_| is set to the maximum
175 // version in |supported_versions|.
176 QuicFramer(const QuicVersionVector& supported_versions,
177 QuicTime creation_time,
178 Perspective perspective);
179
180 virtual ~QuicFramer();
181
182 // Returns true if |version| is a supported protocol version.
183 bool IsSupportedVersion(const QuicVersion version) const;
184
185 // Set callbacks to be called from the framer. A visitor must be set, or
186 // else the framer will likely crash. It is acceptable for the visitor
187 // to do nothing. If this is called multiple times, only the last visitor
188 // will be used.
189 void set_visitor(QuicFramerVisitorInterface* visitor) { visitor_ = visitor; }
190
191 const QuicVersionVector& supported_versions() const {
192 return supported_versions_;
193 }
194
195 QuicVersion version() const { return quic_version_; }
196
197 void set_version(const QuicVersion version);
198
199 // Does not DCHECK for supported version. Used by tests to set unsupported
200 // version to trigger version negotiation.
201 void set_version_for_tests(const QuicVersion version) {
202 quic_version_ = version;
203 }
204
205 // Set entropy calculator to be called from the framer when it needs the
206 // entropy of a truncated ack frame. An entropy calculator must be set or else
207 // the framer will likely crash. If this is called multiple times, only the
208 // last calculator will be used.
209 void set_received_entropy_calculator(
210 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator) {
211 entropy_calculator_ = entropy_calculator;
212 }
213
214 QuicErrorCode error() const { return error_; }
215
216 // Pass a UDP packet into the framer for parsing.
217 // Return true if the packet was processed succesfully. |packet| must be a
218 // single, complete UDP packet (not a frame of a packet). This packet
219 // might be null padded past the end of the payload, which will be correctly
220 // ignored.
221 bool ProcessPacket(const QuicEncryptedPacket& packet);
222
223 // Largest size in bytes of all stream frame fields without the payload.
224 static size_t GetMinStreamFrameSize(QuicStreamId stream_id,
225 QuicStreamOffset offset,
226 bool last_frame_in_packet);
227 // Size in bytes of all ack frame fields without the missing packets or ack
228 // blocks.
229 static size_t GetMinAckFrameSize(
230 QuicVersion version,
231 QuicPacketNumberLength largest_observed_length);
232 // Size in bytes of a stop waiting frame.
233 static size_t GetStopWaitingFrameSize(
234 QuicVersion version,
235 QuicPacketNumberLength packet_number_length);
236 // Size in bytes of all reset stream frame fields.
237 static size_t GetRstStreamFrameSize();
238 // Size in bytes of all connection close frame fields without the error
239 // details and the missing packets from the enclosed ack frame.
240 static size_t GetMinConnectionCloseFrameSize();
241 // Size in bytes of all GoAway frame fields without the reason phrase.
242 static size_t GetMinGoAwayFrameSize();
243 // Size in bytes of all WindowUpdate frame fields.
244 static size_t GetWindowUpdateFrameSize();
245 // Size in bytes of all Blocked frame fields.
246 static size_t GetBlockedFrameSize();
247 // Size in bytes of all PathClose frame fields.
248 static size_t GetPathCloseFrameSize();
249 // Size in bytes required to serialize the stream id.
250 static size_t GetStreamIdSize(QuicStreamId stream_id);
251 // Size in bytes required to serialize the stream offset.
252 static size_t GetStreamOffsetSize(QuicStreamOffset offset);
253 // Size in bytes required for a serialized version negotiation packet
254 static size_t GetVersionNegotiationPacketSize(size_t number_versions);
255
256 // Returns the number of bytes added to the packet for the specified frame,
257 // and 0 if the frame doesn't fit. Includes the header size for the first
258 // frame.
259 size_t GetSerializedFrameLength(const QuicFrame& frame,
260 size_t free_bytes,
261 bool first_frame_in_packet,
262 bool last_frame_in_packet,
263 QuicPacketNumberLength packet_number_length);
264
265 // Returns the associated data from the encrypted packet |encrypted| as a
266 // stringpiece.
267 static base::StringPiece GetAssociatedDataFromEncryptedPacket(
268 QuicVersion version,
269 const QuicEncryptedPacket& encrypted,
270 QuicConnectionIdLength connection_id_length,
271 bool includes_version,
272 bool includes_path_id,
273 bool includes_diversification_nonce,
274 QuicPacketNumberLength packet_number_length);
275
276 // Serializes a packet containing |frames| into |buffer|.
277 // Returns the length of the packet, which must not be longer than
278 // |packet_length|. Returns 0 if it fails to serialize.
279 size_t BuildDataPacket(const QuicPacketHeader& header,
280 const QuicFrames& frames,
281 char* buffer,
282 size_t packet_length);
283
284 // Returns a new public reset packet, owned by the caller.
285 static QuicEncryptedPacket* BuildPublicResetPacket(
286 const QuicPublicResetPacket& packet);
287
288 // Returns a new version negotiation packet, owned by the caller.
289 static QuicEncryptedPacket* BuildVersionNegotiationPacket(
290 QuicConnectionId connection_id,
291 const QuicVersionVector& versions);
292
293 // If header.public_header.version_flag is set, the version in the
294 // packet will be set -- but it will be set from quic_version_ not
295 // header.public_header.versions.
296 bool AppendPacketHeader(const QuicPacketHeader& header,
297 QuicDataWriter* writer);
298 bool AppendTypeByte(const QuicFrame& frame,
299 bool last_frame_in_packet,
300 QuicDataWriter* writer);
301 bool AppendStreamFrame(const QuicStreamFrame& frame,
302 bool last_frame_in_packet,
303 QuicDataWriter* builder);
304
305 // SetDecrypter sets the primary decrypter, replacing any that already exists,
306 // and takes ownership. If an alternative decrypter is in place then the
307 // function DCHECKs. This is intended for cases where one knows that future
308 // packets will be using the new decrypter and the previous decrypter is now
309 // obsolete. |level| indicates the encryption level of the new decrypter.
310 void SetDecrypter(EncryptionLevel level, QuicDecrypter* decrypter);
311
312 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt
313 // future packets and takes ownership of it. |level| indicates the encryption
314 // level of the decrypter. If |latch_once_used| is true, then the first time
315 // that the decrypter is successful it will replace the primary decrypter.
316 // Otherwise both decrypters will remain active and the primary decrypter
317 // will be the one last used.
318 void SetAlternativeDecrypter(EncryptionLevel level,
319 QuicDecrypter* decrypter,
320 bool latch_once_used);
321
322 const QuicDecrypter* decrypter() const;
323 const QuicDecrypter* alternative_decrypter() const;
324
325 // Changes the encrypter used for level |level| to |encrypter|. The function
326 // takes ownership of |encrypter|.
327 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter);
328
329 // Encrypts a payload in |buffer|. |ad_len| is the length of the associated
330 // data. |total_len| is the length of the associated data plus plaintext.
331 // |buffer_len| is the full length of the allocated buffer.
332 size_t EncryptInPlace(EncryptionLevel level,
333 QuicPathId path_id,
334 QuicPacketNumber packet_number,
335 size_t ad_len,
336 size_t total_len,
337 size_t buffer_len,
338 char* buffer);
339
340 // Returns the length of the data encrypted into |buffer| if |buffer_len| is
341 // long enough, and otherwise 0.
342 size_t EncryptPayload(EncryptionLevel level,
343 QuicPathId path_id,
344 QuicPacketNumber packet_number,
345 const QuicPacket& packet,
346 char* buffer,
347 size_t buffer_len);
348
349 // Returns the maximum length of plaintext that can be encrypted
350 // to ciphertext no larger than |ciphertext_size|.
351 size_t GetMaxPlaintextSize(size_t ciphertext_size);
352
353 const std::string& detailed_error() { return detailed_error_; }
354
355 // The minimum packet number length required to represent |packet_number|.
356 static QuicPacketNumberLength GetMinSequenceNumberLength(
357 QuicPacketNumber packet_number);
358
359 void SetSupportedVersions(const QuicVersionVector& versions) {
360 supported_versions_ = versions;
361 quic_version_ = versions[0];
362 }
363
364 void set_validate_flags(bool value) { validate_flags_ = value; }
365
366 Perspective perspective() const { return perspective_; }
367
368 static QuicPacketEntropyHash GetPacketEntropyHash(
369 const QuicPacketHeader& header);
370
371 // Called when a PATH_CLOSED frame has been sent/received on |path_id|.
372 void OnPathClosed(QuicPathId path_id);
373
374 QuicTag last_version_tag() { return last_version_tag_; }
375
376 private:
377 friend class test::QuicFramerPeer;
378
379 typedef std::map<QuicPacketNumber, uint8_t> NackRangeMap;
380
381 struct AckFrameInfo {
382 AckFrameInfo();
383 AckFrameInfo(const AckFrameInfo& other);
384 ~AckFrameInfo();
385
386 // The maximum delta between ranges.
387 QuicPacketNumber max_delta;
388 // Nack ranges starting with start packet numbers and lengths.
389 NackRangeMap nack_ranges;
390 };
391
392 struct AckBlock {
393 AckBlock(uint8_t gap, QuicPacketNumber length);
394 AckBlock(const AckBlock& other);
395 ~AckBlock();
396
397 // Gap to the next ack block.
398 uint8_t gap;
399 // Length of this ack block.
400 QuicPacketNumber length;
401 };
402
403 struct NewAckFrameInfo {
404 NewAckFrameInfo();
405 NewAckFrameInfo(const NewAckFrameInfo& other);
406 ~NewAckFrameInfo();
407
408 // The maximum ack block length.
409 QuicPacketNumber max_block_length;
410 // Length of first ack block.
411 QuicPacketNumber first_block_length;
412 // Ack blocks starting with gaps to next block and ack block lengths.
413 std::vector<AckBlock> ack_blocks;
414 // Number of ACK blocks. If |ack_blocks| is generated, must equal
415 // |ack_blocks.size()|.
416 size_t num_ack_blocks;
417 };
418
419 bool ProcessDataPacket(QuicDataReader* reader,
420 const QuicPacketPublicHeader& public_header,
421 const QuicEncryptedPacket& packet,
422 char* decrypted_buffer,
423 size_t buffer_length);
424
425 bool ProcessPublicResetPacket(QuicDataReader* reader,
426 const QuicPacketPublicHeader& public_header);
427
428 bool ProcessVersionNegotiationPacket(QuicDataReader* reader,
429 QuicPacketPublicHeader* public_header);
430
431 bool ProcessPublicHeader(QuicDataReader* reader,
432 QuicPacketPublicHeader* header);
433
434 // Processes the unauthenticated portion of the header into |header| from
435 // the current QuicDataReader. Returns true on success, false on failure.
436 bool ProcessUnauthenticatedHeader(QuicDataReader* encrypted_reader,
437 QuicPacketHeader* header);
438
439 // Processes the authenticated portion of the header into |header| from
440 // the current QuicDataReader. Returns true on success, false on failure.
441 bool ProcessAuthenticatedHeader(QuicDataReader* reader,
442 QuicPacketHeader* header);
443
444 bool ProcessPathId(QuicDataReader* reader, QuicPathId* path_id);
445 bool ProcessPacketSequenceNumber(QuicDataReader* reader,
446 QuicPacketNumberLength packet_number_length,
447 QuicPacketNumber last_packet_number,
448 QuicPacketNumber* packet_number);
449 bool ProcessFrameData(QuicDataReader* reader, const QuicPacketHeader& header);
450 bool ProcessStreamFrame(QuicDataReader* reader,
451 uint8_t frame_type,
452 QuicStreamFrame* frame);
453 bool ProcessAckFrame(QuicDataReader* reader,
454 uint8_t frame_type,
455 QuicAckFrame* frame);
456 bool ProcessNewAckFrame(QuicDataReader* reader,
457 uint8_t frame_type,
458 QuicAckFrame* frame);
459 bool ProcessTimestampsInAckFrame(QuicDataReader* reader, QuicAckFrame* frame);
460 bool ProcessStopWaitingFrame(QuicDataReader* reader,
461 const QuicPacketHeader& public_header,
462 QuicStopWaitingFrame* stop_waiting);
463 bool ProcessRstStreamFrame(QuicDataReader* reader, QuicRstStreamFrame* frame);
464 bool ProcessConnectionCloseFrame(QuicDataReader* reader,
465 QuicConnectionCloseFrame* frame);
466 bool ProcessGoAwayFrame(QuicDataReader* reader, QuicGoAwayFrame* frame);
467 bool ProcessWindowUpdateFrame(QuicDataReader* reader,
468 QuicWindowUpdateFrame* frame);
469 bool ProcessBlockedFrame(QuicDataReader* reader, QuicBlockedFrame* frame);
470 bool ProcessPathCloseFrame(QuicDataReader* reader, QuicPathCloseFrame* frame);
471
472 bool DecryptPayload(QuicDataReader* encrypted_reader,
473 const QuicPacketHeader& header,
474 const QuicEncryptedPacket& packet,
475 char* decrypted_buffer,
476 size_t buffer_length,
477 size_t* decrypted_length);
478
479 // Checks if |path_id| is a viable path to receive packets on. Returns true
480 // and sets |last_packet_number| if the path is not closed. Returns false
481 // otherwise.
482 bool IsValidPath(QuicPathId path_id, QuicPacketNumber* last_packet_number);
483
484 // Sets last_packet_number_. This can only be called after the packet is
485 // successfully decrypted.
486 void SetLastPacketNumber(const QuicPacketHeader& header);
487
488 // Returns the full packet number from the truncated
489 // wire format version and the last seen packet number.
490 QuicPacketNumber CalculatePacketNumberFromWire(
491 QuicPacketNumberLength packet_number_length,
492 QuicPacketNumber last_packet_number,
493 QuicPacketNumber packet_number) const;
494
495 // Returns the QuicTime::Delta corresponding to the time from when the framer
496 // was created.
497 const QuicTime::Delta CalculateTimestampFromWire(uint32_t time_delta_us);
498
499 // Computes the wire size in bytes of time stamps in |ack|.
500 size_t GetAckFrameTimeStampSize(const QuicAckFrame& ack);
501
502 // Computes the wire size in bytes of the |ack| frame, assuming no truncation.
503 size_t GetAckFrameSize(const QuicAckFrame& ack,
504 QuicPacketNumberLength packet_number_length);
505
506 // Computes the wire size in bytes of the |ack| frame.
507 size_t GetNewAckFrameSize(const QuicAckFrame& ack);
508
509 // Computes the wire size in bytes of the payload of |frame|.
510 size_t ComputeFrameLength(const QuicFrame& frame,
511 bool last_frame_in_packet,
512 QuicPacketNumberLength packet_number_length);
513
514 static bool AppendPacketSequenceNumber(
515 QuicPacketNumberLength packet_number_length,
516 QuicPacketNumber packet_number,
517 QuicDataWriter* writer);
518
519 // Appends a single ACK block to |writer| and returns true if the block was
520 // successfully appended.
521 static bool AppendAckBlock(uint8_t gap,
522 QuicPacketNumberLength length_length,
523 QuicPacketNumber length,
524 QuicDataWriter* writer);
525
526 static uint8_t GetSequenceNumberFlags(
527 QuicPacketNumberLength packet_number_length);
528
529 static AckFrameInfo GetAckFrameInfo(const QuicAckFrame& frame);
530
531 static NewAckFrameInfo GetNewAckFrameInfo(const QuicAckFrame& frame,
532 bool construct_blocks);
533
534 // The Append* methods attempt to write the provided header or frame using the
535 // |writer|, and return true if successful.
536
537 bool AppendAckFrameAndTypeByte(const QuicPacketHeader& header,
538 const QuicAckFrame& frame,
539 QuicDataWriter* builder);
540 bool AppendNewAckFrameAndTypeByte(const QuicAckFrame& frame,
541 QuicDataWriter* builder);
542 bool AppendTimestampToAckFrame(const QuicAckFrame& frame,
543 QuicDataWriter* builder);
544 bool AppendStopWaitingFrame(const QuicPacketHeader& header,
545 const QuicStopWaitingFrame& frame,
546 QuicDataWriter* builder);
547 bool AppendRstStreamFrame(const QuicRstStreamFrame& frame,
548 QuicDataWriter* builder);
549 bool AppendConnectionCloseFrame(const QuicConnectionCloseFrame& frame,
550 QuicDataWriter* builder);
551 bool AppendGoAwayFrame(const QuicGoAwayFrame& frame, QuicDataWriter* writer);
552 bool AppendWindowUpdateFrame(const QuicWindowUpdateFrame& frame,
553 QuicDataWriter* writer);
554 bool AppendBlockedFrame(const QuicBlockedFrame& frame,
555 QuicDataWriter* writer);
556 bool AppendPathCloseFrame(const QuicPathCloseFrame& frame,
557 QuicDataWriter* writer);
558
559 bool RaiseError(QuicErrorCode error);
560
561 void set_error(QuicErrorCode error) { error_ = error; }
562
563 void set_detailed_error(const char* error) { detailed_error_ = error; }
564
565 std::string detailed_error_;
566 QuicFramerVisitorInterface* visitor_;
567 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator_;
568 QuicErrorCode error_;
569 // Set of closed paths. A path is considered as closed if a PATH_CLOSED frame
570 // has been sent/received.
571 // TODO(fayang): this set is never cleaned up. A possible improvement is to
572 // use intervals.
573 std::unordered_set<QuicPathId> closed_paths_;
574 // Map mapping path id to packet number of last successfully decrypted
575 // received packet.
576 std::unordered_map<QuicPathId, QuicPacketNumber> last_packet_numbers_;
577 // Updated by ProcessPacketHeader when it succeeds.
578 QuicPacketNumber last_packet_number_;
579 // The path on which last successfully decrypted packet was received.
580 QuicPathId last_path_id_;
581 // Updated by WritePacketHeader.
582 QuicConnectionId last_serialized_connection_id_;
583 // The last QUIC version tag received.
584 QuicTag last_version_tag_;
585 // Version of the protocol being used.
586 QuicVersion quic_version_;
587 // This vector contains QUIC versions which we currently support.
588 // This should be ordered such that the highest supported version is the first
589 // element, with subsequent elements in descending order (versions can be
590 // skipped as necessary).
591 QuicVersionVector supported_versions_;
592 // Primary decrypter used to decrypt packets during parsing.
593 std::unique_ptr<QuicDecrypter> decrypter_;
594 // Alternative decrypter that can also be used to decrypt packets.
595 std::unique_ptr<QuicDecrypter> alternative_decrypter_;
596 // The encryption level of |decrypter_|.
597 EncryptionLevel decrypter_level_;
598 // The encryption level of |alternative_decrypter_|.
599 EncryptionLevel alternative_decrypter_level_;
600 // |alternative_decrypter_latch_| is true if, when |alternative_decrypter_|
601 // successfully decrypts a packet, we should install it as the only
602 // decrypter.
603 bool alternative_decrypter_latch_;
604 // Encrypters used to encrypt packets via EncryptPayload().
605 std::unique_ptr<QuicEncrypter> encrypter_[NUM_ENCRYPTION_LEVELS];
606 // Tracks if the framer is being used by the entity that received the
607 // connection or the entity that initiated it.
608 Perspective perspective_;
609 // If false, skip validation that the public flags are set to legal values.
610 bool validate_flags_;
611 // The time this framer was created. Time written to the wire will be
612 // written as a delta from this value.
613 QuicTime creation_time_;
614 // The time delta computed for the last timestamp frame. This is relative to
615 // the creation_time.
616 QuicTime::Delta last_timestamp_;
617 // The diversification nonce from the last received packet.
618 DiversificationNonce last_nonce_;
619
620 DISALLOW_COPY_AND_ASSIGN(QuicFramer);
621 };
622
623 } // namespace net
624
625 #endif // NET_QUIC_QUIC_FRAMER_H_
OLDNEW
« no previous file with comments | « net/quic/quic_frame_list.cc ('k') | net/quic/quic_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698