| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 virtual QuicPacketEntropyHash ReceivedEntropyHash( | 144 virtual QuicPacketEntropyHash ReceivedEntropyHash( |
| 145 QuicPacketSequenceNumber sequence_number) const = 0; | 145 QuicPacketSequenceNumber sequence_number) const = 0; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 // Class for parsing and constructing QUIC packets. It has a | 148 // Class for parsing and constructing QUIC packets. It has a |
| 149 // QuicFramerVisitorInterface that is called when packets are parsed. | 149 // QuicFramerVisitorInterface that is called when packets are parsed. |
| 150 // It also has a QuicFecBuilder that is called when packets are constructed | 150 // It also has a QuicFecBuilder that is called when packets are constructed |
| 151 // in order to generate FEC data for subsequently building FEC packets. | 151 // in order to generate FEC data for subsequently building FEC packets. |
| 152 class NET_EXPORT_PRIVATE QuicFramer { | 152 class NET_EXPORT_PRIVATE QuicFramer { |
| 153 public: | 153 public: |
| 154 // Constructs a new framer that will own |decrypter| and |encrypter|. | 154 // Constructs a new framer that installs a kNULL QuicEncrypter and |
| 155 // QuicDecrypter for level ENCRYPTION_NONE. |
| 155 QuicFramer(QuicVersionTag quic_version, | 156 QuicFramer(QuicVersionTag quic_version, |
| 156 QuicDecrypter* decrypter, | |
| 157 QuicEncrypter* encrypter, | |
| 158 QuicTime creation_time, | 157 QuicTime creation_time, |
| 159 bool is_server); | 158 bool is_server); |
| 160 | 159 |
| 161 virtual ~QuicFramer(); | 160 virtual ~QuicFramer(); |
| 162 | 161 |
| 163 // Returns true if |version| is a supported protocol version. | 162 // Returns true if |version| is a supported protocol version. |
| 164 bool IsSupportedVersion(QuicVersionTag version); | 163 bool IsSupportedVersion(QuicVersionTag version); |
| 165 | 164 |
| 166 // Calculates the largest observed packet to advertise in the case an Ack | 165 // Calculates the largest observed packet to advertise in the case an Ack |
| 167 // Frame was truncated. last_written in this case is the iterator for the | 166 // Frame was truncated. last_written in this case is the iterator for the |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 const QuicFecData& fec); | 266 const QuicFecData& fec); |
| 268 | 267 |
| 269 // Returns a new public reset packet, owned by the caller. | 268 // Returns a new public reset packet, owned by the caller. |
| 270 static QuicEncryptedPacket* ConstructPublicResetPacket( | 269 static QuicEncryptedPacket* ConstructPublicResetPacket( |
| 271 const QuicPublicResetPacket& packet); | 270 const QuicPublicResetPacket& packet); |
| 272 | 271 |
| 273 QuicEncryptedPacket* ConstructVersionNegotiationPacket( | 272 QuicEncryptedPacket* ConstructVersionNegotiationPacket( |
| 274 const QuicPacketPublicHeader& header, | 273 const QuicPacketPublicHeader& header, |
| 275 const QuicVersionTagList& supported_versions); | 274 const QuicVersionTagList& supported_versions); |
| 276 | 275 |
| 277 QuicDecrypter* decrypter() const { return decrypter_.get(); } | 276 // SetDecrypter sets the primary decrypter, replacing any that already exists, |
| 278 void push_decrypter(QuicDecrypter* decrypter); | 277 // and takes ownership. If an alternative decrypter is in place then the |
| 279 void pop_decrypter(); | 278 // function DCHECKs. This is intended for cases where one knows that future |
| 279 // packets will be using the new decrypter and the previous decrypter is not |
| 280 // obsolete. |
| 281 void SetDecrypter(QuicDecrypter* decrypter); |
| 280 | 282 |
| 281 QuicEncrypter* encrypter() const { return encrypter_.get(); } | 283 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt |
| 282 void set_encrypter(QuicEncrypter* encrypter); | 284 // future packets and takes ownership of it. If |latch_once_used| is true, |
| 285 // then the first time that the decrypter is successful it will replace the |
| 286 // primary decrypter. Otherwise both decrypters will remain active and the |
| 287 // primary decrypter will be the one last used. |
| 288 void SetAlternativeDecrypter(QuicDecrypter* decrypter, |
| 289 bool latch_once_used); |
| 290 |
| 291 const QuicDecrypter* decrypter() const; |
| 292 const QuicDecrypter* alternative_decrypter() const; |
| 293 |
| 294 // Changes the encrypter used for level |level| to |encrypter|. The function |
| 295 // takes ownership of |encrypter|. |
| 296 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter); |
| 297 const QuicEncrypter* encrypter(EncryptionLevel level) const; |
| 283 | 298 |
| 284 // Returns a new encrypted packet, owned by the caller. | 299 // Returns a new encrypted packet, owned by the caller. |
| 285 QuicEncryptedPacket* EncryptPacket(QuicPacketSequenceNumber sequence_number, | 300 QuicEncryptedPacket* EncryptPacket(EncryptionLevel level, |
| 301 QuicPacketSequenceNumber sequence_number, |
| 286 const QuicPacket& packet); | 302 const QuicPacket& packet); |
| 287 | 303 |
| 288 // Returns the maximum length of plaintext that can be encrypted | 304 // Returns the maximum length of plaintext that can be encrypted |
| 289 // to ciphertext no larger than |ciphertext_size|. | 305 // to ciphertext no larger than |ciphertext_size|. |
| 290 size_t GetMaxPlaintextSize(size_t ciphertext_size); | 306 size_t GetMaxPlaintextSize(size_t ciphertext_size); |
| 291 | 307 |
| 292 const std::string& detailed_error() { return detailed_error_; } | 308 const std::string& detailed_error() { return detailed_error_; } |
| 293 | 309 |
| 294 // Read the guid from a packet header. | 310 // Read the guid from a packet header. |
| 295 // Return true on success, else false. | 311 // Return true on success, else false. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator_; | 392 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator_; |
| 377 QuicErrorCode error_; | 393 QuicErrorCode error_; |
| 378 // Updated by ProcessPacketHeader when it succeeds. | 394 // Updated by ProcessPacketHeader when it succeeds. |
| 379 QuicPacketSequenceNumber last_sequence_number_; | 395 QuicPacketSequenceNumber last_sequence_number_; |
| 380 // Buffer containing decrypted payload data during parsing. | 396 // Buffer containing decrypted payload data during parsing. |
| 381 scoped_ptr<QuicData> decrypted_; | 397 scoped_ptr<QuicData> decrypted_; |
| 382 // Version of the protocol being used. | 398 // Version of the protocol being used. |
| 383 QuicVersionTag quic_version_; | 399 QuicVersionTag quic_version_; |
| 384 // Primary decrypter used to decrypt packets during parsing. | 400 // Primary decrypter used to decrypt packets during parsing. |
| 385 scoped_ptr<QuicDecrypter> decrypter_; | 401 scoped_ptr<QuicDecrypter> decrypter_; |
| 386 // Backup decrypter used to decrypt packets during parsing. May be NULL. | 402 // Alternative decrypter that can also be used to decrypt packets. |
| 387 scoped_ptr<QuicDecrypter> backup_decrypter_; | 403 scoped_ptr<QuicDecrypter> alternative_decrypter_; |
| 388 // Encrypter used to encrypt packets via EncryptPacket(). | 404 // alternative_decrypter_latch_is true if, when |alternative_decrypter_| |
| 389 scoped_ptr<QuicEncrypter> encrypter_; | 405 // successfully decrypts a packet, we should install it as the only |
| 406 // decrypter. |
| 407 bool alternative_decrypter_latch_; |
| 408 // Encrypters used to encrypt packets via EncryptPacket(). |
| 409 scoped_ptr<QuicEncrypter> encrypter_[NUM_ENCRYPTION_LEVELS]; |
| 390 // Tracks if the framer is being used by the entity that received the | 410 // Tracks if the framer is being used by the entity that received the |
| 391 // connection or the entity that initiated it. | 411 // connection or the entity that initiated it. |
| 392 bool is_server_; | 412 bool is_server_; |
| 393 // The time this frames was created. Time written to the wire will be | 413 // The time this frames was created. Time written to the wire will be |
| 394 // written as a delta from this value. | 414 // written as a delta from this value. |
| 395 QuicTime creation_time_; | 415 QuicTime creation_time_; |
| 396 | 416 |
| 397 DISALLOW_COPY_AND_ASSIGN(QuicFramer); | 417 DISALLOW_COPY_AND_ASSIGN(QuicFramer); |
| 398 }; | 418 }; |
| 399 | 419 |
| 400 } // namespace net | 420 } // namespace net |
| 401 | 421 |
| 402 #endif // NET_QUIC_QUIC_FRAMER_H_ | 422 #endif // NET_QUIC_QUIC_FRAMER_H_ |
| OLD | NEW |