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_CORE_QUIC_FRAMER_H_ | 5 #ifndef NET_QUIC_CORE_QUIC_FRAMER_H_ |
6 #define NET_QUIC_CORE_QUIC_FRAMER_H_ | 6 #define NET_QUIC_CORE_QUIC_FRAMER_H_ |
7 | 7 |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <cstdint> | 9 #include <cstdint> |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "net/quic/core/quic_packets.h" | 14 #include "net/quic/core/quic_packets.h" |
15 #include "net/quic/platform/api/quic_endian.h" | 15 #include "net/quic/platform/api/quic_endian.h" |
16 #include "net/quic/platform/api/quic_export.h" | 16 #include "net/quic/platform/api/quic_export.h" |
17 #include "net/quic/platform/api/quic_string_piece.h" | 17 #include "net/quic/platform/api/quic_string_piece.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 namespace test { | 21 namespace test { |
22 class QuicFramerPeer; | 22 class QuicFramerPeer; |
23 } // namespace test | 23 } // namespace test |
24 | 24 |
25 class QuicDataReader; | 25 class QuicDataReader; |
26 class QuicDataWriter; | 26 class QuicDataWriter; |
27 class QuicDecrypter; | 27 class QuicDecrypter; |
28 class QuicEncrypter; | 28 class QuicEncrypter; |
29 class QuicFramer; | 29 class QuicFramer; |
| 30 class QuicStreamFrameDataProducer; |
30 | 31 |
31 // Number of bytes reserved for the frame type preceding each frame. | 32 // Number of bytes reserved for the frame type preceding each frame. |
32 const size_t kQuicFrameTypeSize = 1; | 33 const size_t kQuicFrameTypeSize = 1; |
33 // Number of bytes reserved for error code. | 34 // Number of bytes reserved for error code. |
34 const size_t kQuicErrorCodeSize = 4; | 35 const size_t kQuicErrorCodeSize = 4; |
35 // Number of bytes reserved to denote the length of error details field. | 36 // Number of bytes reserved to denote the length of error details field. |
36 const size_t kQuicErrorDetailsLengthSize = 2; | 37 const size_t kQuicErrorDetailsLengthSize = 2; |
37 | 38 |
38 // Maximum number of bytes reserved for stream id. | 39 // Maximum number of bytes reserved for stream id. |
39 const size_t kQuicMaxStreamIdSize = 4; | 40 const size_t kQuicMaxStreamIdSize = 4; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 bool includes_version, | 235 bool includes_version, |
235 bool includes_diversification_nonce, | 236 bool includes_diversification_nonce, |
236 QuicPacketNumberLength packet_number_length); | 237 QuicPacketNumberLength packet_number_length); |
237 | 238 |
238 // Serializes a packet containing |frames| into |buffer|. | 239 // Serializes a packet containing |frames| into |buffer|. |
239 // Returns the length of the packet, which must not be longer than | 240 // Returns the length of the packet, which must not be longer than |
240 // |packet_length|. Returns 0 if it fails to serialize. | 241 // |packet_length|. Returns 0 if it fails to serialize. |
241 size_t BuildDataPacket(const QuicPacketHeader& header, | 242 size_t BuildDataPacket(const QuicPacketHeader& header, |
242 const QuicFrames& frames, | 243 const QuicFrames& frames, |
243 char* buffer, | 244 char* buffer, |
244 size_t packet_length); | 245 size_t packet_length, |
| 246 QuicStreamFrameDataProducer* data_producer); |
245 | 247 |
246 // Returns a new public reset packet. | 248 // Returns a new public reset packet. |
247 static std::unique_ptr<QuicEncryptedPacket> BuildPublicResetPacket( | 249 static std::unique_ptr<QuicEncryptedPacket> BuildPublicResetPacket( |
248 const QuicPublicResetPacket& packet); | 250 const QuicPublicResetPacket& packet); |
249 | 251 |
250 // Returns a new version negotiation packet. | 252 // Returns a new version negotiation packet. |
251 static std::unique_ptr<QuicEncryptedPacket> BuildVersionNegotiationPacket( | 253 static std::unique_ptr<QuicEncryptedPacket> BuildVersionNegotiationPacket( |
252 QuicConnectionId connection_id, | 254 QuicConnectionId connection_id, |
253 const QuicVersionVector& versions); | 255 const QuicVersionVector& versions); |
254 | 256 |
255 // If header.public_header.version_flag is set, the version in the | 257 // If header.public_header.version_flag is set, the version in the |
256 // packet will be set -- but it will be set from quic_version_ not | 258 // packet will be set -- but it will be set from quic_version_ not |
257 // header.public_header.versions. | 259 // header.public_header.versions. |
258 bool AppendPacketHeader(const QuicPacketHeader& header, | 260 bool AppendPacketHeader(const QuicPacketHeader& header, |
259 QuicDataWriter* writer); | 261 QuicDataWriter* writer); |
260 bool AppendTypeByte(const QuicFrame& frame, | 262 bool AppendTypeByte(const QuicFrame& frame, |
261 bool last_frame_in_packet, | 263 bool last_frame_in_packet, |
262 QuicDataWriter* writer); | 264 QuicDataWriter* writer); |
263 bool AppendStreamFrame(const QuicStreamFrame& frame, | 265 bool AppendStreamFrame(const QuicStreamFrame& frame, |
264 bool last_frame_in_packet, | 266 bool last_frame_in_packet, |
265 QuicDataWriter* builder); | 267 QuicDataWriter* writer, |
| 268 QuicStreamFrameDataProducer* data_producer); |
266 | 269 |
267 // SetDecrypter sets the primary decrypter, replacing any that already exists, | 270 // SetDecrypter sets the primary decrypter, replacing any that already exists, |
268 // and takes ownership. If an alternative decrypter is in place then the | 271 // and takes ownership. If an alternative decrypter is in place then the |
269 // function DCHECKs. This is intended for cases where one knows that future | 272 // function DCHECKs. This is intended for cases where one knows that future |
270 // packets will be using the new decrypter and the previous decrypter is now | 273 // packets will be using the new decrypter and the previous decrypter is now |
271 // obsolete. |level| indicates the encryption level of the new decrypter. | 274 // obsolete. |level| indicates the encryption level of the new decrypter. |
272 void SetDecrypter(EncryptionLevel level, QuicDecrypter* decrypter); | 275 void SetDecrypter(EncryptionLevel level, QuicDecrypter* decrypter); |
273 | 276 |
274 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt | 277 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt |
275 // future packets and takes ownership of it. |level| indicates the encryption | 278 // future packets and takes ownership of it. |level| indicates the encryption |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 QuicTime::Delta last_timestamp_; | 531 QuicTime::Delta last_timestamp_; |
529 // The diversification nonce from the last received packet. | 532 // The diversification nonce from the last received packet. |
530 DiversificationNonce last_nonce_; | 533 DiversificationNonce last_nonce_; |
531 | 534 |
532 DISALLOW_COPY_AND_ASSIGN(QuicFramer); | 535 DISALLOW_COPY_AND_ASSIGN(QuicFramer); |
533 }; | 536 }; |
534 | 537 |
535 } // namespace net | 538 } // namespace net |
536 | 539 |
537 #endif // NET_QUIC_CORE_QUIC_FRAMER_H_ | 540 #endif // NET_QUIC_CORE_QUIC_FRAMER_H_ |
OLD | NEW |