Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: net/quic/crypto/crypto_framer.h

Issue 11125002: Add QuicFramer and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix final comments. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/net.gyp ('k') | net/quic/crypto/crypto_framer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_
6 #define NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_
7
8 #include <map>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/string_piece.h"
15 #include "net/base/net_export.h"
16 #include "net/quic/crypto/crypto_protocol.h"
17 #include "net/quic/quic_protocol.h"
18
19 namespace net {
20
21 class CryptoFramer;
22 class QuicDataReader;
23 class QuicData;
24
25 class NET_EXPORT_PRIVATE CryptoFramerVisitorInterface {
26 public:
27 virtual ~CryptoFramerVisitorInterface() {}
28
29 // Called if an error is detected.
30 virtual void OnError(CryptoFramer* framer) = 0;
31
32 // Called when a complete handshake message has been parsed.
33 virtual void OnHandshakeMessage(const CryptoHandshakeMessage& message) = 0;
34 };
35
36 // A class for framing the crypto message that are exchanged in a QUIC session.
37 class NET_EXPORT_PRIVATE CryptoFramer {
38 public:
39 CryptoFramer();
40
41 virtual ~CryptoFramer();
42
43 // Set callbacks to be called from the framer. A visitor must be set, or
44 // else the framer will likely crash. It is acceptable for the visitor
45 // to do nothing. If this is called multiple times, only the last visitor
46 // will be used. |visitor| will be owned by the framer.
47 void set_visitor(CryptoFramerVisitorInterface* visitor) {
48 visitor_ = visitor;
49 }
50
51 QuicErrorCode error() const {
52 return error_;
53 }
54
55 // Processes input data, which must be delievered in order. Returns
56 // false if there was an error, and true otherwise.
57 bool ProcessInput(base::StringPiece input);
58
59 // Serializes |message| into |packet|. Returns false if there was an
60 // error, and true otherwise.
61 bool ConstructHandshakeMessage(const CryptoHandshakeMessage& message,
62 QuicData** packet);
63
64 private:
65 // Clears per-message state. Does not clear the visitor.
66 void Clear();
67
68 void set_error(QuicErrorCode error) {
69 error_ = error;
70 }
71
72 enum CryptoFramerState {
73 STATE_READING_TAG,
74 STATE_READING_NUM_ENTRIES,
75 STATE_READING_KEY_TAGS,
76 STATE_READING_LENGTHS,
77 STATE_READING_VALUES
78 };
79
80 // Visitor to send invoke when messages are parsed.
81 CryptoFramerVisitorInterface* visitor_;
82 // Last error.
83 QuicErrorCode error_;
84 // Remaining unparsed data.
85 std::string buffer_;
86 // Current state of the parsing.
87 CryptoFramerState state_;
88 // Tag of the message currently being parsed.
89 CryptoTag message_tag_;
90 // Number of entires in the message currently being parsed.
91 uint16 num_entries_;
92 // Vector of tags in the message currently being parsed.
93 std::vector<CryptoTag> tags_;
94 // Length of the data associated with each tag in the message currently
95 // being parsed.
96 std::map<CryptoTag, size_t> tag_length_map_;
97 // Length of the data associated with each tag in the message currently
98 // being parsed.
99 CryptoTagValueMap tag_value_map_;
100 // Cumulative length of all values in the message currently being parsed.
101 size_t values_len_;
102 };
103
104 } // namespace net
105
106 #endif // NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_
OLDNEW
« no previous file with comments | « net/net.gyp ('k') | net/quic/crypto/crypto_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698