OLD | NEW |
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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 // Called when a public reset packet has been parsed but has not yet | 85 // Called when a public reset packet has been parsed but has not yet |
86 // been validated. | 86 // been validated. |
87 virtual void OnPublicResetPacket(const QuicPublicResetPacket& packet) = 0; | 87 virtual void OnPublicResetPacket(const QuicPublicResetPacket& packet) = 0; |
88 | 88 |
89 // Called only when |perspective_| is IS_CLIENT and a version negotiation | 89 // Called only when |perspective_| is IS_CLIENT and a version negotiation |
90 // packet has been parsed. | 90 // packet has been parsed. |
91 virtual void OnVersionNegotiationPacket( | 91 virtual void OnVersionNegotiationPacket( |
92 const QuicVersionNegotiationPacket& packet) = 0; | 92 const QuicVersionNegotiationPacket& packet) = 0; |
93 | 93 |
94 // Called when a lost packet has been recovered via FEC, | |
95 // before it has been processed. | |
96 virtual void OnRevivedPacket() = 0; | |
97 | |
98 // Called when the public header has been parsed, but has not been | 94 // Called when the public header has been parsed, but has not been |
99 // authenticated. If it returns false, framing for this packet will cease. | 95 // authenticated. If it returns false, framing for this packet will cease. |
100 virtual bool OnUnauthenticatedPublicHeader( | 96 virtual bool OnUnauthenticatedPublicHeader( |
101 const QuicPacketPublicHeader& header) = 0; | 97 const QuicPacketPublicHeader& header) = 0; |
102 | 98 |
103 // Called when the unauthenticated portion of the header has been parsed. | 99 // Called when the unauthenticated portion of the header has been parsed. |
104 // If OnUnauthenticatedHeader returns false, framing for this packet will | 100 // If OnUnauthenticatedHeader returns false, framing for this packet will |
105 // cease. | 101 // cease. |
106 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) = 0; | 102 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) = 0; |
107 | 103 |
108 // Called when a packet has been decrypted. |level| is the encryption level | 104 // Called when a packet has been decrypted. |level| is the encryption level |
109 // of the packet. | 105 // of the packet. |
110 virtual void OnDecryptedPacket(EncryptionLevel level) = 0; | 106 virtual void OnDecryptedPacket(EncryptionLevel level) = 0; |
111 | 107 |
112 // Called when the complete header of a packet had been parsed. | 108 // Called when the complete header of a packet had been parsed. |
113 // If OnPacketHeader returns false, framing for this packet will cease. | 109 // If OnPacketHeader returns false, framing for this packet will cease. |
114 virtual bool OnPacketHeader(const QuicPacketHeader& header) = 0; | 110 virtual bool OnPacketHeader(const QuicPacketHeader& header) = 0; |
115 | 111 |
116 // Called when a data packet is parsed that is part of an FEC group. | |
117 // |payload| is the non-encrypted FEC protected payload of the packet. | |
118 virtual void OnFecProtectedPayload(base::StringPiece payload) = 0; | |
119 | |
120 // Called when a StreamFrame has been parsed. | 112 // Called when a StreamFrame has been parsed. |
121 virtual bool OnStreamFrame(const QuicStreamFrame& frame) = 0; | 113 virtual bool OnStreamFrame(const QuicStreamFrame& frame) = 0; |
122 | 114 |
123 // Called when a AckFrame has been parsed. If OnAckFrame returns false, | 115 // Called when a AckFrame has been parsed. If OnAckFrame returns false, |
124 // the framer will stop parsing the current packet. | 116 // the framer will stop parsing the current packet. |
125 virtual bool OnAckFrame(const QuicAckFrame& frame) = 0; | 117 virtual bool OnAckFrame(const QuicAckFrame& frame) = 0; |
126 | 118 |
127 // Called when a StopWaitingFrame has been parsed. | 119 // Called when a StopWaitingFrame has been parsed. |
128 virtual bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) = 0; | 120 virtual bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) = 0; |
129 | 121 |
(...skipping 12 matching lines...) Expand all Loading... |
142 | 134 |
143 // Called when a WindowUpdateFrame has been parsed. | 135 // Called when a WindowUpdateFrame has been parsed. |
144 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) = 0; | 136 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) = 0; |
145 | 137 |
146 // Called when a BlockedFrame has been parsed. | 138 // Called when a BlockedFrame has been parsed. |
147 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) = 0; | 139 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) = 0; |
148 | 140 |
149 // Called when a PathCloseFrame has been parsed. | 141 // Called when a PathCloseFrame has been parsed. |
150 virtual bool OnPathCloseFrame(const QuicPathCloseFrame& frame) = 0; | 142 virtual bool OnPathCloseFrame(const QuicPathCloseFrame& frame) = 0; |
151 | 143 |
152 // Called when FEC data has been parsed. | |
153 virtual void OnFecData(base::StringPiece redundancy) = 0; | |
154 | |
155 // Called when a packet has been completely processed. | 144 // Called when a packet has been completely processed. |
156 virtual void OnPacketComplete() = 0; | 145 virtual void OnPacketComplete() = 0; |
157 }; | 146 }; |
158 | 147 |
159 // This class calculates the received entropy of the ack packet being | 148 // This class calculates the received entropy of the ack packet being |
160 // framed, should it get truncated. | 149 // framed, should it get truncated. |
161 class NET_EXPORT_PRIVATE QuicReceivedEntropyHashCalculatorInterface { | 150 class NET_EXPORT_PRIVATE QuicReceivedEntropyHashCalculatorInterface { |
162 public: | 151 public: |
163 virtual ~QuicReceivedEntropyHashCalculatorInterface() {} | 152 virtual ~QuicReceivedEntropyHashCalculatorInterface() {} |
164 | 153 |
165 // When an ack frame gets truncated while being framed the received | 154 // When an ack frame gets truncated while being framed the received |
166 // entropy of the ack frame needs to be calculated since the some of the | 155 // entropy of the ack frame needs to be calculated since the some of the |
167 // missing packets are not added and the largest observed might be lowered. | 156 // missing packets are not added and the largest observed might be lowered. |
168 // This should return the received entropy hash of the packets received up to | 157 // This should return the received entropy hash of the packets received up to |
169 // and including |packet_number|. | 158 // and including |packet_number|. |
170 virtual QuicPacketEntropyHash EntropyHash( | 159 virtual QuicPacketEntropyHash EntropyHash( |
171 QuicPacketNumber packet_number) const = 0; | 160 QuicPacketNumber packet_number) const = 0; |
172 }; | 161 }; |
173 | 162 |
174 // Class for parsing and constructing QUIC packets. It has a | 163 // Class for parsing and constructing QUIC packets. It has a |
175 // QuicFramerVisitorInterface that is called when packets are parsed. | 164 // QuicFramerVisitorInterface that is called when packets are parsed. |
176 // It also has a QuicFecBuilder that is called when packets are constructed | |
177 // in order to generate FEC data for subsequently building FEC packets. | |
178 class NET_EXPORT_PRIVATE QuicFramer { | 165 class NET_EXPORT_PRIVATE QuicFramer { |
179 public: | 166 public: |
180 // Constructs a new framer that installs a kNULL QuicEncrypter and | 167 // Constructs a new framer that installs a kNULL QuicEncrypter and |
181 // QuicDecrypter for level ENCRYPTION_NONE. |supported_versions| specifies the | 168 // QuicDecrypter for level ENCRYPTION_NONE. |supported_versions| specifies the |
182 // list of supported QUIC versions. |quic_version_| is set to the maximum | 169 // list of supported QUIC versions. |quic_version_| is set to the maximum |
183 // version in |supported_versions|. | 170 // version in |supported_versions|. |
184 QuicFramer(const QuicVersionVector& supported_versions, | 171 QuicFramer(const QuicVersionVector& supported_versions, |
185 QuicTime creation_time, | 172 QuicTime creation_time, |
186 Perspective perspective); | 173 Perspective perspective); |
187 | 174 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 208 |
222 QuicErrorCode error() const { return error_; } | 209 QuicErrorCode error() const { return error_; } |
223 | 210 |
224 // Pass a UDP packet into the framer for parsing. | 211 // Pass a UDP packet into the framer for parsing. |
225 // Return true if the packet was processed succesfully. |packet| must be a | 212 // Return true if the packet was processed succesfully. |packet| must be a |
226 // single, complete UDP packet (not a frame of a packet). This packet | 213 // single, complete UDP packet (not a frame of a packet). This packet |
227 // might be null padded past the end of the payload, which will be correctly | 214 // might be null padded past the end of the payload, which will be correctly |
228 // ignored. | 215 // ignored. |
229 bool ProcessPacket(const QuicEncryptedPacket& packet); | 216 bool ProcessPacket(const QuicEncryptedPacket& packet); |
230 | 217 |
231 // Pass a data packet that was revived from FEC data into the framer | |
232 // for parsing. | |
233 // Return true if the packet was processed succesfully. |payload| must be | |
234 // the complete DECRYPTED payload of the revived packet. | |
235 bool ProcessRevivedPacket(QuicPacketHeader* header, | |
236 base::StringPiece payload); | |
237 | |
238 // Largest size in bytes of all stream frame fields without the payload. | 218 // Largest size in bytes of all stream frame fields without the payload. |
239 static size_t GetMinStreamFrameSize(QuicStreamId stream_id, | 219 static size_t GetMinStreamFrameSize(QuicStreamId stream_id, |
240 QuicStreamOffset offset, | 220 QuicStreamOffset offset, |
241 bool last_frame_in_packet, | 221 bool last_frame_in_packet); |
242 InFecGroup is_in_fec_group); | |
243 // Size in bytes of all ack frame fields without the missing packets. | 222 // Size in bytes of all ack frame fields without the missing packets. |
244 static size_t GetMinAckFrameSize( | 223 static size_t GetMinAckFrameSize( |
245 QuicPacketNumberLength largest_observed_length); | 224 QuicPacketNumberLength largest_observed_length); |
246 // Size in bytes of a stop waiting frame. | 225 // Size in bytes of a stop waiting frame. |
247 static size_t GetStopWaitingFrameSize( | 226 static size_t GetStopWaitingFrameSize( |
248 QuicPacketNumberLength packet_number_length); | 227 QuicPacketNumberLength packet_number_length); |
249 // Size in bytes of all reset stream frame without the error details. | 228 // Size in bytes of all reset stream frame without the error details. |
250 // Used before QUIC_VERSION_25. | 229 // Used before QUIC_VERSION_25. |
251 static size_t GetMinRstStreamFrameSize(); | 230 static size_t GetMinRstStreamFrameSize(); |
252 // Size in bytes of all reset stream frame fields. | 231 // Size in bytes of all reset stream frame fields. |
(...skipping 16 matching lines...) Expand all Loading... |
269 // Size in bytes required for a serialized version negotiation packet | 248 // Size in bytes required for a serialized version negotiation packet |
270 static size_t GetVersionNegotiationPacketSize(size_t number_versions); | 249 static size_t GetVersionNegotiationPacketSize(size_t number_versions); |
271 | 250 |
272 // Returns the number of bytes added to the packet for the specified frame, | 251 // Returns the number of bytes added to the packet for the specified frame, |
273 // and 0 if the frame doesn't fit. Includes the header size for the first | 252 // and 0 if the frame doesn't fit. Includes the header size for the first |
274 // frame. | 253 // frame. |
275 size_t GetSerializedFrameLength(const QuicFrame& frame, | 254 size_t GetSerializedFrameLength(const QuicFrame& frame, |
276 size_t free_bytes, | 255 size_t free_bytes, |
277 bool first_frame_in_packet, | 256 bool first_frame_in_packet, |
278 bool last_frame_in_packet, | 257 bool last_frame_in_packet, |
279 InFecGroup is_in_fec_group, | |
280 QuicPacketNumberLength packet_number_length); | 258 QuicPacketNumberLength packet_number_length); |
281 | 259 |
282 // Returns the associated data from the encrypted packet |encrypted| as a | 260 // Returns the associated data from the encrypted packet |encrypted| as a |
283 // stringpiece. | 261 // stringpiece. |
284 static base::StringPiece GetAssociatedDataFromEncryptedPacket( | 262 static base::StringPiece GetAssociatedDataFromEncryptedPacket( |
285 const QuicEncryptedPacket& encrypted, | 263 const QuicEncryptedPacket& encrypted, |
286 QuicConnectionIdLength connection_id_length, | 264 QuicConnectionIdLength connection_id_length, |
287 bool includes_version, | 265 bool includes_version, |
288 bool includes_path_id, | 266 bool includes_path_id, |
289 QuicPacketNumberLength packet_number_length); | 267 QuicPacketNumberLength packet_number_length); |
290 | 268 |
291 // Serializes a packet containing |frames| into |buffer|. | 269 // Serializes a packet containing |frames| into |buffer|. |
292 // Returns the length of the packet, which must not be longer than | 270 // Returns the length of the packet, which must not be longer than |
293 // |packet_length|. Returns 0 if it fails to serialize. | 271 // |packet_length|. Returns 0 if it fails to serialize. |
294 size_t BuildDataPacket(const QuicPacketHeader& header, | 272 size_t BuildDataPacket(const QuicPacketHeader& header, |
295 const QuicFrames& frames, | 273 const QuicFrames& frames, |
296 char* buffer, | 274 char* buffer, |
297 size_t packet_length); | 275 size_t packet_length); |
298 | 276 |
299 // Returns a QuicPacket* that is owned by the caller, and is populated with | |
300 // the fields in |header| and |fec|. Returns nullptr if the packet could | |
301 // not be created. | |
302 QuicPacket* BuildFecPacket(const QuicPacketHeader& header, | |
303 base::StringPiece redundancy); | |
304 | |
305 // Returns a new public reset packet, owned by the caller. | 277 // Returns a new public reset packet, owned by the caller. |
306 static QuicEncryptedPacket* BuildPublicResetPacket( | 278 static QuicEncryptedPacket* BuildPublicResetPacket( |
307 const QuicPublicResetPacket& packet); | 279 const QuicPublicResetPacket& packet); |
308 | 280 |
309 // Returns a new version negotiation packet, owned by the caller. | 281 // Returns a new version negotiation packet, owned by the caller. |
310 static QuicEncryptedPacket* BuildVersionNegotiationPacket( | 282 static QuicEncryptedPacket* BuildVersionNegotiationPacket( |
311 QuicConnectionId connection_id, | 283 QuicConnectionId connection_id, |
312 const QuicVersionVector& versions); | 284 const QuicVersionVector& versions); |
313 | 285 |
314 // SetDecrypter sets the primary decrypter, replacing any that already exists, | 286 // SetDecrypter sets the primary decrypter, replacing any that already exists, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // was created. | 432 // was created. |
461 const QuicTime::Delta CalculateTimestampFromWire(uint32_t time_delta_us); | 433 const QuicTime::Delta CalculateTimestampFromWire(uint32_t time_delta_us); |
462 | 434 |
463 // Computes the wire size in bytes of the |ack| frame, assuming no truncation. | 435 // Computes the wire size in bytes of the |ack| frame, assuming no truncation. |
464 size_t GetAckFrameSize(const QuicAckFrame& ack, | 436 size_t GetAckFrameSize(const QuicAckFrame& ack, |
465 QuicPacketNumberLength packet_number_length); | 437 QuicPacketNumberLength packet_number_length); |
466 | 438 |
467 // Computes the wire size in bytes of the payload of |frame|. | 439 // Computes the wire size in bytes of the payload of |frame|. |
468 size_t ComputeFrameLength(const QuicFrame& frame, | 440 size_t ComputeFrameLength(const QuicFrame& frame, |
469 bool last_frame_in_packet, | 441 bool last_frame_in_packet, |
470 InFecGroup is_in_fec_group, | |
471 QuicPacketNumberLength packet_number_length); | 442 QuicPacketNumberLength packet_number_length); |
472 | 443 |
473 static bool AppendPacketSequenceNumber( | 444 static bool AppendPacketSequenceNumber( |
474 QuicPacketNumberLength packet_number_length, | 445 QuicPacketNumberLength packet_number_length, |
475 QuicPacketNumber packet_number, | 446 QuicPacketNumber packet_number, |
476 QuicDataWriter* writer); | 447 QuicDataWriter* writer); |
477 | 448 |
478 static uint8_t GetSequenceNumberFlags( | 449 static uint8_t GetSequenceNumberFlags( |
479 QuicPacketNumberLength packet_number_length); | 450 QuicPacketNumberLength packet_number_length); |
480 | 451 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 | 493 |
523 std::string detailed_error_; | 494 std::string detailed_error_; |
524 QuicFramerVisitorInterface* visitor_; | 495 QuicFramerVisitorInterface* visitor_; |
525 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator_; | 496 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator_; |
526 QuicErrorCode error_; | 497 QuicErrorCode error_; |
527 // Set of closed paths. A path is considered as closed if a PATH_CLOSED frame | 498 // Set of closed paths. A path is considered as closed if a PATH_CLOSED frame |
528 // has been sent/received. | 499 // has been sent/received. |
529 // TODO(fayang): this set is never cleaned up. A possible improvement is to | 500 // TODO(fayang): this set is never cleaned up. A possible improvement is to |
530 // use intervals. | 501 // use intervals. |
531 std::unordered_set<QuicPathId> closed_paths_; | 502 std::unordered_set<QuicPathId> closed_paths_; |
532 // Map mapping path id to packet number of last successfully decrypted/revived | 503 // Map mapping path id to packet number of last successfully decrypted |
533 // received packet. | 504 // received packet. |
534 std::unordered_map<QuicPathId, QuicPacketNumber> last_packet_numbers_; | 505 std::unordered_map<QuicPathId, QuicPacketNumber> last_packet_numbers_; |
535 // Updated by ProcessPacketHeader when it succeeds. | 506 // Updated by ProcessPacketHeader when it succeeds. |
536 QuicPacketNumber last_packet_number_; | 507 QuicPacketNumber last_packet_number_; |
537 // The path on which last successfully decrypted/revived packet was received. | 508 // The path on which last successfully decrypted packet was received. |
538 QuicPathId last_path_id_; | 509 QuicPathId last_path_id_; |
539 // Updated by WritePacketHeader. | 510 // Updated by WritePacketHeader. |
540 QuicConnectionId last_serialized_connection_id_; | 511 QuicConnectionId last_serialized_connection_id_; |
541 // The last QUIC version tag received. | 512 // The last QUIC version tag received. |
542 QuicTag last_version_tag_; | 513 QuicTag last_version_tag_; |
543 // Version of the protocol being used. | 514 // Version of the protocol being used. |
544 QuicVersion quic_version_; | 515 QuicVersion quic_version_; |
545 // This vector contains QUIC versions which we currently support. | 516 // This vector contains QUIC versions which we currently support. |
546 // This should be ordered such that the highest supported version is the first | 517 // This should be ordered such that the highest supported version is the first |
547 // element, with subsequent elements in descending order (versions can be | 518 // element, with subsequent elements in descending order (versions can be |
(...skipping 24 matching lines...) Expand all Loading... |
572 // The time delta computed for the last timestamp frame. This is relative to | 543 // The time delta computed for the last timestamp frame. This is relative to |
573 // the creation_time. | 544 // the creation_time. |
574 QuicTime::Delta last_timestamp_; | 545 QuicTime::Delta last_timestamp_; |
575 | 546 |
576 DISALLOW_COPY_AND_ASSIGN(QuicFramer); | 547 DISALLOW_COPY_AND_ASSIGN(QuicFramer); |
577 }; | 548 }; |
578 | 549 |
579 } // namespace net | 550 } // namespace net |
580 | 551 |
581 #endif // NET_QUIC_QUIC_FRAMER_H_ | 552 #endif // NET_QUIC_QUIC_FRAMER_H_ |
OLD | NEW |