Chromium Code Reviews| Index: net/quic/crypto/crypto_framer.h |
| diff --git a/net/quic/crypto/crypto_framer.h b/net/quic/crypto/crypto_framer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..483ef6803093a0103cccca2cde6770cbd5b9770d |
| --- /dev/null |
| +++ b/net/quic/crypto/crypto_framer.h |
| @@ -0,0 +1,106 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ |
| +#define NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ |
| + |
| +#include <map> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "net/quic/quic_protocol.h" |
| +#include "net/quic/crypto/crypto_protocol.h" |
|
jar (doing other things)
2012/10/14 23:04:38
nit: alphabetize
Ryan Hamilton
2012/10/15 21:22:08
Done.
|
| +#include "base/string_piece.h" |
| + |
| +namespace net { |
| + |
| +class CryptoFramer; |
| +class QuicDataReader; |
| +class QuicData; |
| + |
| +class CryptoFramerVisitorInterface { |
| + public: |
| + virtual ~CryptoFramerVisitorInterface() {} |
| + |
| + // Called if an error is detected. |
| + virtual void OnError(CryptoFramer* framer) = 0; |
| + |
| + // Called when a complete handshake message has been parsed. |
| + virtual void OnHandshakeMessage(const CryptoHandshakeMessage& message) = 0; |
| +}; |
| + |
| +class CryptoFramer { |
|
jar (doing other things)
2012/10/14 23:04:38
It might be helpful to have a class comment, indic
Ryan Hamilton
2012/10/15 21:22:08
Done.
|
| + public: |
| + CryptoFramer(); |
| + |
| + virtual ~CryptoFramer(); |
| + |
| + // Set callbacks to be called from the framer. A visitor must be set, or |
| + // else the framer will likely crash. It is acceptable for the visitor |
| + // to do nothing. If this is called multiple times, only the last visitor |
| + // will be used. |
| + void set_visitor(CryptoFramerVisitorInterface* visitor) { |
| + visitor_ = visitor; |
|
jar (doing other things)
2012/10/14 23:04:38
Perhaps it is worth a comment that the ownership o
Ryan Hamilton
2012/10/15 21:22:08
Done.
Ryan Hamilton
2012/10/15 21:22:08
Done.
|
| + } |
| + |
| + QuicErrorCode error() const { |
| + return error_; |
| + } |
| + |
| + // Processes input data, which must be delievered in order. Returns |
| + // false if there was an error, and true otherwise. |
| + bool ProcessInput(base::StringPiece input); |
| + |
| + // Serializes |message| into |packet|. Returns fase if there was an |
|
jar (doing other things)
2012/10/14 23:04:38
nit: fase-->false
Ryan Hamilton
2012/10/15 21:22:08
Done.
|
| + // error, and true otherwise. |
| + bool ConstructHandshakeMessage(const CryptoHandshakeMessage& message, |
| + QuicData** packet); |
| + |
| + private: |
| + // Clears per-message state. Does not clear the visitor. |
| + void Clear(); |
| + |
| + void set_error(QuicErrorCode error) { |
| + error_ = error; |
| + } |
| + |
| + enum CryptoFramerState { |
| + STATE_READING_TAG, |
| + STATE_READING_NUM_ENTRIES, |
| + STATE_READING_KEY_TAGS, |
| + STATE_READING_LENGTHS, |
| + STATE_READING_VALUES |
| + }; |
| + |
| + // Reader for parsing data. |
| + scoped_ptr<QuicDataReader> reader_; |
| + // Visitor to send invoke when messages are parsed. |
| + CryptoFramerVisitorInterface* visitor_; |
| + // Last error. |
| + QuicErrorCode error_; |
| + // Remaining unparsed data. |
| + std::string buffer_; |
| + // Current state of the parsing. |
| + CryptoFramerState state_; |
| + // Tag of the message currently being parsed. |
| + CryptoTag message_tag_; |
| + // Number of entires in the message currently being parsed. |
| + uint16 num_entries_; |
| + // Vector of tags in the message currently being parsed. |
| + std::vector<CryptoTag> tags_; |
| + // Length of the data associated with each tag in the message currently |
| + // being parsed. |
| + std::map<CryptoTag, size_t> tag_length_map_; |
| + // Length of the data associated with each tag in the message currently |
|
jar (doing other things)
2012/10/14 23:04:38
This says "Length" just like line 94, but it looks
Ryan Hamilton
2012/10/15 21:22:08
Will be fixed when the changes from cl/35411506 ar
|
| + // being parsed. |
| + CryptoTagValueMap tag_value_map_; |
| + // Cumulative length of all values in the message currently being parsed. |
| + size_t values_len_; |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ |