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

Side by Side Diff: net/quic/test_tools/simple_quic_framer.cc

Issue 12334063: Land recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more EXPECT_FALSE Created 7 years, 10 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/quic/test_tools/simple_quic_framer.h ('k') | no next file » | 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 #include "net/quic/test_tools/simple_quic_framer.h"
6
7 using base::StringPiece;
8 using std::string;
9 using std::vector;
10
11 namespace net {
12 namespace test {
13
14 class SimpleFramerVisitor : public QuicFramerVisitorInterface {
15 public:
16 SimpleFramerVisitor()
17 : error_(QUIC_NO_ERROR) {
18 }
19
20 virtual void OnError(QuicFramer* framer) {
21 error_ = framer->error();
22 }
23
24 virtual void OnPacket() {}
25 virtual void OnPublicResetPacket(const QuicPublicResetPacket& packet) {}
26 virtual void OnRevivedPacket() {}
27 virtual bool OnPacketHeader(const QuicPacketHeader& header) {
28 has_header_ = true;
29 header_ = header;
30 return true;
31 }
32
33 virtual void OnFecProtectedPayload(StringPiece payload) {}
34
35 virtual void OnStreamFrame(const QuicStreamFrame& frame) {
36 // Save a copy of the data so it is valid after the packet is processed.
37 stream_data_.push_back(frame.data.as_string());
38 QuicStreamFrame stream_frame(frame);
39 // Make sure that the stream frame points to this data.
40 stream_frame.data = stream_data_.back();
41 stream_frames_.push_back(stream_frame);
42 }
43
44 virtual void OnAckFrame(const QuicAckFrame& frame) {
45 ack_frames_.push_back(frame);
46 }
47
48 virtual void OnCongestionFeedbackFrame(
49 const QuicCongestionFeedbackFrame& frame) {
50 feedback_frames_.push_back(frame);
51 }
52
53 virtual void OnFecData(const QuicFecData& fec) {
54 fec_data_ = fec;
55 fec_redundancy_ = fec_data_.redundancy.as_string();
56 fec_data_.redundancy = fec_redundancy_;
57 }
58
59 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) {
60 rst_stream_frames_.push_back(frame);
61 }
62
63 virtual void OnConnectionCloseFrame(
64 const QuicConnectionCloseFrame& frame) {
65 connection_close_frames_.push_back(frame);
66 }
67
68 virtual void OnGoAwayFrame(const QuicGoAwayFrame& frame) {
69 goaway_frames_.push_back(frame);
70 }
71
72 virtual void OnPacketComplete() {}
73
74 const QuicPacketHeader& header() const { return header_; }
75 const vector<QuicAckFrame>& ack_frames() const { return ack_frames_; }
76 const vector<QuicConnectionCloseFrame>& connection_close_frames() const {
77 return connection_close_frames_;
78 }
79 const vector<QuicCongestionFeedbackFrame>& feedback_frames() const {
80 return feedback_frames_;
81 }
82 const vector<QuicGoAwayFrame>& goaway_frames() const {
83 return goaway_frames_;
84 }
85 const vector<QuicRstStreamFrame>& rst_stream_frames() const {
86 return rst_stream_frames_;
87 }
88 const vector<QuicStreamFrame>& stream_frames() const {
89 return stream_frames_;
90 }
91 const QuicFecData& fec_data() const {
92 return fec_data_;
93 }
94
95 private:
96 QuicErrorCode error_;
97 bool has_header_;
98 QuicPacketHeader header_;
99 QuicFecData fec_data_;
100 string fec_redundancy_;
101 vector<QuicAckFrame> ack_frames_;
102 vector<QuicCongestionFeedbackFrame> feedback_frames_;
103 vector<QuicStreamFrame> stream_frames_;
104 vector<QuicRstStreamFrame> rst_stream_frames_;
105 vector<QuicGoAwayFrame> goaway_frames_;
106 vector<QuicConnectionCloseFrame> connection_close_frames_;
107 vector<string> stream_data_;
108
109 DISALLOW_COPY_AND_ASSIGN(SimpleFramerVisitor);
110 };
111
112 SimpleQuicFramer::SimpleQuicFramer()
113 : framer_(QuicDecrypter::Create(kNULL), QuicEncrypter::Create(kNULL)),
114 visitor_(NULL) {
115 }
116
117 SimpleQuicFramer::~SimpleQuicFramer() {
118 delete visitor_;
119 }
120
121 bool SimpleQuicFramer::ProcessPacket(const QuicPacket& packet) {
122 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(0, packet));
123 LOG(INFO) << __FUNCTION__ << encrypted.get();
124 LOG(INFO) << __FUNCTION__ << encrypted->length();
125 return ProcessPacket(*encrypted);
126 }
127
128 bool SimpleQuicFramer::ProcessPacket(const QuicEncryptedPacket& packet) {
129 delete visitor_;
130 visitor_ = new SimpleFramerVisitor;
131 framer_.set_visitor(visitor_);
132 return framer_.ProcessPacket(packet);
133 }
134
135 const QuicPacketHeader& SimpleQuicFramer::header() const {
136 return visitor_->header();
137 }
138
139 const QuicFecData& SimpleQuicFramer::fec_data() const {
140 return visitor_->fec_data();
141 }
142
143 size_t SimpleQuicFramer::num_frames() const {
144 return ack_frames().size() +
145 stream_frames().size() +
146 feedback_frames().size() +
147 rst_stream_frames().size() +
148 goaway_frames().size() +
149 connection_close_frames().size();
150 }
151
152 const vector<QuicAckFrame>& SimpleQuicFramer::ack_frames() const {
153 return visitor_->ack_frames();
154 }
155
156 const vector<QuicStreamFrame>& SimpleQuicFramer::stream_frames() const {
157 return visitor_->stream_frames();
158 }
159
160 const vector<QuicRstStreamFrame>& SimpleQuicFramer::rst_stream_frames() const {
161 return visitor_->rst_stream_frames();
162 }
163
164 const vector<QuicCongestionFeedbackFrame>&
165 SimpleQuicFramer::feedback_frames() const {
166 return visitor_->feedback_frames();
167 }
168
169 const vector<QuicGoAwayFrame>&
170 SimpleQuicFramer::goaway_frames() const {
171 return visitor_->goaway_frames();
172 }
173
174 const vector<QuicConnectionCloseFrame>&
175 SimpleQuicFramer::connection_close_frames() const {
176 return visitor_->connection_close_frames();
177 }
178
179 } // namespace test
180 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/simple_quic_framer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698