| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 virtual ~QuicFramerVisitorInterface() {} | 57 virtual ~QuicFramerVisitorInterface() {} |
| 58 | 58 |
| 59 // Called if an error is detected in the QUIC protocol. | 59 // Called if an error is detected in the QUIC protocol. |
| 60 virtual void OnError(QuicFramer* framer) = 0; | 60 virtual void OnError(QuicFramer* framer) = 0; |
| 61 | 61 |
| 62 // Called only when |is_server_| is true and the the framer gets a packet with | 62 // Called only when |is_server_| is true and the the framer gets a packet with |
| 63 // version flag true and the version on the packet doesn't match | 63 // version flag true and the version on the packet doesn't match |
| 64 // |quic_version_|. The visitor should return true after it updates the | 64 // |quic_version_|. The visitor should return true after it updates the |
| 65 // version of the |framer_| to |received_version| or false to stop processing | 65 // version of the |framer_| to |received_version| or false to stop processing |
| 66 // this packet. | 66 // this packet. |
| 67 virtual bool OnProtocolVersionMismatch(QuicTag received_version) = 0; | 67 virtual bool OnProtocolVersionMismatch(QuicVersion received_version) = 0; |
| 68 | 68 |
| 69 // Called when a new packet has been received, before it | 69 // Called when a new packet has been received, before it |
| 70 // has been validated or processed. | 70 // has been validated or processed. |
| 71 virtual void OnPacket() = 0; | 71 virtual void OnPacket() = 0; |
| 72 | 72 |
| 73 // Called when a public reset packet has been parsed but has not yet | 73 // Called when a public reset packet has been parsed but has not yet |
| 74 // been validated. | 74 // been validated. |
| 75 virtual void OnPublicResetPacket( | 75 virtual void OnPublicResetPacket( |
| 76 const QuicPublicResetPacket& packet) = 0; | 76 const QuicPublicResetPacket& packet) = 0; |
| 77 | 77 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // framed, should it get truncated. | 134 // framed, should it get truncated. |
| 135 class NET_EXPORT_PRIVATE QuicReceivedEntropyHashCalculatorInterface { | 135 class NET_EXPORT_PRIVATE QuicReceivedEntropyHashCalculatorInterface { |
| 136 public: | 136 public: |
| 137 virtual ~QuicReceivedEntropyHashCalculatorInterface() {} | 137 virtual ~QuicReceivedEntropyHashCalculatorInterface() {} |
| 138 | 138 |
| 139 // When an ack frame gets truncated while being framed the received | 139 // When an ack frame gets truncated while being framed the received |
| 140 // entropy of the ack frame needs to be calculated since the some of the | 140 // entropy of the ack frame needs to be calculated since the some of the |
| 141 // missing packets are not added and the largest observed might be lowered. | 141 // missing packets are not added and the largest observed might be lowered. |
| 142 // This should return the received entropy hash of the packets received up to | 142 // This should return the received entropy hash of the packets received up to |
| 143 // and including |sequence_number|. | 143 // and including |sequence_number|. |
| 144 virtual QuicPacketEntropyHash ReceivedEntropyHash( | 144 virtual QuicPacketEntropyHash EntropyHash( |
| 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 installs a kNULL QuicEncrypter and | 154 // Constructs a new framer that installs a kNULL QuicEncrypter and |
| 155 // QuicDecrypter for level ENCRYPTION_NONE. | 155 // QuicDecrypter for level ENCRYPTION_NONE. |
| 156 QuicFramer(QuicTag quic_version, | 156 QuicFramer(QuicVersion quic_version, |
| 157 QuicTime creation_time, | 157 QuicTime creation_time, |
| 158 bool is_server); | 158 bool is_server); |
| 159 | 159 |
| 160 virtual ~QuicFramer(); | 160 virtual ~QuicFramer(); |
| 161 | 161 |
| 162 // Returns true if |version| is a supported protocol version. | 162 // Returns true if |version| is a supported protocol version. |
| 163 bool IsSupportedVersion(QuicTag version); | 163 bool IsSupportedVersion(const QuicVersion version) const; |
| 164 | 164 |
| 165 // 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 |
| 166 // 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 |
| 167 // last missing packet which fit in the outgoing ack. | 167 // last missing packet which fit in the outgoing ack. |
| 168 static QuicPacketSequenceNumber CalculateLargestObserved( | 168 static QuicPacketSequenceNumber CalculateLargestObserved( |
| 169 const SequenceNumberSet& missing_packets, | 169 const SequenceNumberSet& missing_packets, |
| 170 SequenceNumberSet::const_iterator last_written); | 170 SequenceNumberSet::const_iterator last_written); |
| 171 | 171 |
| 172 // Set callbacks to be called from the framer. A visitor must be set, or | 172 // Set callbacks to be called from the framer. A visitor must be set, or |
| 173 // else the framer will likely crash. It is acceptable for the visitor | 173 // else the framer will likely crash. It is acceptable for the visitor |
| 174 // to do nothing. If this is called multiple times, only the last visitor | 174 // to do nothing. If this is called multiple times, only the last visitor |
| 175 // will be used. | 175 // will be used. |
| 176 void set_visitor(QuicFramerVisitorInterface* visitor) { | 176 void set_visitor(QuicFramerVisitorInterface* visitor) { |
| 177 visitor_ = visitor; | 177 visitor_ = visitor; |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Set a builder to be called from the framer when building FEC protected | 180 // Set a builder to be called from the framer when building FEC protected |
| 181 // packets. If this is called multiple times, only the last builder | 181 // packets. If this is called multiple times, only the last builder |
| 182 // will be used. The builder need not be set. | 182 // will be used. The builder need not be set. |
| 183 void set_fec_builder(QuicFecBuilderInterface* builder) { | 183 void set_fec_builder(QuicFecBuilderInterface* builder) { |
| 184 fec_builder_ = builder; | 184 fec_builder_ = builder; |
| 185 } | 185 } |
| 186 | 186 |
| 187 QuicTag version() const { | 187 QuicVersion version() const { |
| 188 return quic_version_; | 188 return quic_version_; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void set_version(QuicTag version) { | 191 void set_version(const QuicVersion version) { |
| 192 DCHECK(IsSupportedVersion(version)); | 192 DCHECK(IsSupportedVersion(version)); |
| 193 quic_version_ = version; | 193 quic_version_ = version; |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Does not DCHECK for supported version. Used by tests to set unsupported |
| 197 // version to trigger version negotiation. |
| 198 void set_version_for_tests(const QuicVersion version) { |
| 199 quic_version_ = version; |
| 200 } |
| 201 |
| 196 // Set entropy calculator to be called from the framer when it needs the | 202 // Set entropy calculator to be called from the framer when it needs the |
| 197 // entropy of a truncated ack frame. An entropy calculator must be set or else | 203 // entropy of a truncated ack frame. An entropy calculator must be set or else |
| 198 // the framer will likely crash. If this is called multiple times, only the | 204 // the framer will likely crash. If this is called multiple times, only the |
| 199 // last visitor will be used. | 205 // last calculator will be used. |
| 200 void set_entropy_calculator( | 206 void set_received_entropy_calculator( |
| 201 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator) { | 207 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator) { |
| 202 entropy_calculator_ = entropy_calculator; | 208 entropy_calculator_ = entropy_calculator; |
| 203 } | 209 } |
| 204 | 210 |
| 205 QuicErrorCode error() const { | 211 QuicErrorCode error() const { |
| 206 return error_; | 212 return error_; |
| 207 } | 213 } |
| 208 | 214 |
| 209 // Pass a UDP packet into the framer for parsing. | 215 // Pass a UDP packet into the framer for parsing. |
| 210 // Return true if the packet was processed succesfully. |packet| must be a | 216 // Return true if the packet was processed succesfully. |packet| must be a |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // packet could not be created. | 284 // packet could not be created. |
| 279 SerializedPacket ConstructFecPacket(const QuicPacketHeader& header, | 285 SerializedPacket ConstructFecPacket(const QuicPacketHeader& header, |
| 280 const QuicFecData& fec); | 286 const QuicFecData& fec); |
| 281 | 287 |
| 282 // Returns a new public reset packet, owned by the caller. | 288 // Returns a new public reset packet, owned by the caller. |
| 283 static QuicEncryptedPacket* ConstructPublicResetPacket( | 289 static QuicEncryptedPacket* ConstructPublicResetPacket( |
| 284 const QuicPublicResetPacket& packet); | 290 const QuicPublicResetPacket& packet); |
| 285 | 291 |
| 286 QuicEncryptedPacket* ConstructVersionNegotiationPacket( | 292 QuicEncryptedPacket* ConstructVersionNegotiationPacket( |
| 287 const QuicPacketPublicHeader& header, | 293 const QuicPacketPublicHeader& header, |
| 288 const QuicTagVector& supported_versions); | 294 const QuicVersionVector& supported_versions); |
| 289 | 295 |
| 290 // SetDecrypter sets the primary decrypter, replacing any that already exists, | 296 // SetDecrypter sets the primary decrypter, replacing any that already exists, |
| 291 // and takes ownership. If an alternative decrypter is in place then the | 297 // and takes ownership. If an alternative decrypter is in place then the |
| 292 // function DCHECKs. This is intended for cases where one knows that future | 298 // function DCHECKs. This is intended for cases where one knows that future |
| 293 // packets will be using the new decrypter and the previous decrypter is not | 299 // packets will be using the new decrypter and the previous decrypter is not |
| 294 // obsolete. | 300 // obsolete. |
| 295 void SetDecrypter(QuicDecrypter* decrypter); | 301 void SetDecrypter(QuicDecrypter* decrypter); |
| 296 | 302 |
| 297 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt | 303 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt |
| 298 // future packets and takes ownership of it. If |latch_once_used| is true, | 304 // future packets and takes ownership of it. If |latch_once_used| is true, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 QuicFecBuilderInterface* fec_builder_; | 418 QuicFecBuilderInterface* fec_builder_; |
| 413 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator_; | 419 QuicReceivedEntropyHashCalculatorInterface* entropy_calculator_; |
| 414 QuicErrorCode error_; | 420 QuicErrorCode error_; |
| 415 // Updated by ProcessPacketHeader when it succeeds. | 421 // Updated by ProcessPacketHeader when it succeeds. |
| 416 QuicPacketSequenceNumber last_sequence_number_; | 422 QuicPacketSequenceNumber last_sequence_number_; |
| 417 // Updated by WritePacketHeader. | 423 // Updated by WritePacketHeader. |
| 418 QuicGuid last_serialized_guid_; | 424 QuicGuid last_serialized_guid_; |
| 419 // Buffer containing decrypted payload data during parsing. | 425 // Buffer containing decrypted payload data during parsing. |
| 420 scoped_ptr<QuicData> decrypted_; | 426 scoped_ptr<QuicData> decrypted_; |
| 421 // Version of the protocol being used. | 427 // Version of the protocol being used. |
| 422 QuicTag quic_version_; | 428 QuicVersion quic_version_; |
| 423 // Primary decrypter used to decrypt packets during parsing. | 429 // Primary decrypter used to decrypt packets during parsing. |
| 424 scoped_ptr<QuicDecrypter> decrypter_; | 430 scoped_ptr<QuicDecrypter> decrypter_; |
| 425 // Alternative decrypter that can also be used to decrypt packets. | 431 // Alternative decrypter that can also be used to decrypt packets. |
| 426 scoped_ptr<QuicDecrypter> alternative_decrypter_; | 432 scoped_ptr<QuicDecrypter> alternative_decrypter_; |
| 427 // alternative_decrypter_latch_is true if, when |alternative_decrypter_| | 433 // alternative_decrypter_latch_is true if, when |alternative_decrypter_| |
| 428 // successfully decrypts a packet, we should install it as the only | 434 // successfully decrypts a packet, we should install it as the only |
| 429 // decrypter. | 435 // decrypter. |
| 430 bool alternative_decrypter_latch_; | 436 bool alternative_decrypter_latch_; |
| 431 // Encrypters used to encrypt packets via EncryptPacket(). | 437 // Encrypters used to encrypt packets via EncryptPacket(). |
| 432 scoped_ptr<QuicEncrypter> encrypter_[NUM_ENCRYPTION_LEVELS]; | 438 scoped_ptr<QuicEncrypter> encrypter_[NUM_ENCRYPTION_LEVELS]; |
| 433 // Tracks if the framer is being used by the entity that received the | 439 // Tracks if the framer is being used by the entity that received the |
| 434 // connection or the entity that initiated it. | 440 // connection or the entity that initiated it. |
| 435 bool is_server_; | 441 bool is_server_; |
| 436 // The time this frames was created. Time written to the wire will be | 442 // The time this frames was created. Time written to the wire will be |
| 437 // written as a delta from this value. | 443 // written as a delta from this value. |
| 438 QuicTime creation_time_; | 444 QuicTime creation_time_; |
| 439 | 445 |
| 440 DISALLOW_COPY_AND_ASSIGN(QuicFramer); | 446 DISALLOW_COPY_AND_ASSIGN(QuicFramer); |
| 441 }; | 447 }; |
| 442 | 448 |
| 443 } // namespace net | 449 } // namespace net |
| 444 | 450 |
| 445 #endif // NET_QUIC_QUIC_FRAMER_H_ | 451 #endif // NET_QUIC_QUIC_FRAMER_H_ |
| OLD | NEW |