[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 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/quic_test_utils.h" |
[email protected] | 9c0b135 | 2012-11-04 00:03:27 | [diff] [blame] | 6 | |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 7 | #include "base/stl_util.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 8 | #include "net/quic/crypto/crypto_framer.h" |
[email protected] | 6f54ab3 | 2013-03-02 17:43:35 | [diff] [blame] | 9 | #include "net/quic/crypto/crypto_handshake.h" |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 10 | #include "net/quic/crypto/crypto_utils.h" |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 11 | #include "net/quic/crypto/null_encrypter.h" |
[email protected] | 4df6984 | 2013-02-27 06:32:16 | [diff] [blame] | 12 | #include "net/quic/crypto/quic_decrypter.h" |
| 13 | #include "net/quic/crypto/quic_encrypter.h" |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 14 | #include "net/quic/quic_framer.h" |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 15 | #include "net/quic/quic_packet_creator.h" |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 16 | #include "net/spdy/spdy_frame_builder.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 17 | |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 18 | using base::StringPiece; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 19 | using std::max; |
| 20 | using std::min; |
| 21 | using std::string; |
[email protected] | cff7b7b | 2013-01-11 08:49:07 | [diff] [blame] | 22 | using testing::_; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 23 | |
| 24 | namespace net { |
| 25 | namespace test { |
| 26 | |
| 27 | MockFramerVisitor::MockFramerVisitor() { |
| 28 | // By default, we want to accept packets. |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 29 | ON_CALL(*this, OnProtocolVersionMismatch(_)) |
| 30 | .WillByDefault(testing::Return(false)); |
| 31 | |
| 32 | // By default, we want to accept packets. |
[email protected] | cff7b7b | 2013-01-11 08:49:07 | [diff] [blame] | 33 | ON_CALL(*this, OnPacketHeader(_)) |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 34 | .WillByDefault(testing::Return(true)); |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 35 | |
| 36 | ON_CALL(*this, OnStreamFrame(_)) |
| 37 | .WillByDefault(testing::Return(true)); |
| 38 | |
| 39 | ON_CALL(*this, OnAckFrame(_)) |
| 40 | .WillByDefault(testing::Return(true)); |
| 41 | |
| 42 | ON_CALL(*this, OnCongestionFeedbackFrame(_)) |
| 43 | .WillByDefault(testing::Return(true)); |
| 44 | |
| 45 | ON_CALL(*this, OnRstStreamFrame(_)) |
| 46 | .WillByDefault(testing::Return(true)); |
| 47 | |
| 48 | ON_CALL(*this, OnConnectionCloseFrame(_)) |
| 49 | .WillByDefault(testing::Return(true)); |
| 50 | |
| 51 | ON_CALL(*this, OnGoAwayFrame(_)) |
| 52 | .WillByDefault(testing::Return(true)); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 53 | } |
| 54 | |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 55 | MockFramerVisitor::~MockFramerVisitor() { |
| 56 | } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 57 | |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 58 | bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicTag version) { |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 59 | return false; |
| 60 | } |
| 61 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 62 | bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) { |
| 63 | return true; |
| 64 | } |
| 65 | |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 66 | bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& frame) { |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | bool NoOpFramerVisitor::OnAckFrame(const QuicAckFrame& frame) { |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | bool NoOpFramerVisitor::OnCongestionFeedbackFrame( |
| 75 | const QuicCongestionFeedbackFrame& frame) { |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | bool NoOpFramerVisitor::OnRstStreamFrame( |
| 80 | const QuicRstStreamFrame& frame) { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | bool NoOpFramerVisitor::OnConnectionCloseFrame( |
| 85 | const QuicConnectionCloseFrame& frame) { |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& frame) { |
| 90 | return true; |
| 91 | } |
| 92 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 93 | FramerVisitorCapturingFrames::FramerVisitorCapturingFrames() : frame_count_(0) { |
[email protected] | 134e5c3 | 2012-12-12 19:20:36 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 96 | FramerVisitorCapturingFrames::~FramerVisitorCapturingFrames() { |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 97 | } |
| 98 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 99 | bool FramerVisitorCapturingFrames::OnPacketHeader( |
[email protected] | 4e6f0ed | 2012-11-02 22:15:38 | [diff] [blame] | 100 | const QuicPacketHeader& header) { |
| 101 | header_ = header; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 102 | frame_count_ = 0; |
[email protected] | 4e6f0ed | 2012-11-02 22:15:38 | [diff] [blame] | 103 | return true; |
| 104 | } |
| 105 | |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 106 | bool FramerVisitorCapturingFrames::OnStreamFrame(const QuicStreamFrame& frame) { |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 107 | // TODO(ianswett): Own the underlying string, so it will not exist outside |
| 108 | // this callback. |
| 109 | stream_frames_.push_back(frame); |
| 110 | ++frame_count_; |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 111 | return true; |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 112 | } |
| 113 | |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 114 | bool FramerVisitorCapturingFrames::OnAckFrame(const QuicAckFrame& frame) { |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 115 | ack_.reset(new QuicAckFrame(frame)); |
| 116 | ++frame_count_; |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 117 | return true; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 118 | } |
| 119 | |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 120 | bool FramerVisitorCapturingFrames::OnCongestionFeedbackFrame( |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 121 | const QuicCongestionFeedbackFrame& frame) { |
| 122 | feedback_.reset(new QuicCongestionFeedbackFrame(frame)); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 123 | ++frame_count_; |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 124 | return true; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 125 | } |
| 126 | |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 127 | bool FramerVisitorCapturingFrames::OnRstStreamFrame( |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 128 | const QuicRstStreamFrame& frame) { |
| 129 | rst_.reset(new QuicRstStreamFrame(frame)); |
| 130 | ++frame_count_; |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 131 | return true; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 132 | } |
| 133 | |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 134 | bool FramerVisitorCapturingFrames::OnConnectionCloseFrame( |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 135 | const QuicConnectionCloseFrame& frame) { |
| 136 | close_.reset(new QuicConnectionCloseFrame(frame)); |
| 137 | ++frame_count_; |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 138 | return true; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 141 | bool FramerVisitorCapturingFrames::OnGoAwayFrame(const QuicGoAwayFrame& frame) { |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 142 | goaway_.reset(new QuicGoAwayFrame(frame)); |
| 143 | ++frame_count_; |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 144 | return true; |
[email protected] | 4e6f0ed | 2012-11-02 22:15:38 | [diff] [blame] | 145 | } |
| 146 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 147 | void FramerVisitorCapturingFrames::OnVersionNegotiationPacket( |
| 148 | const QuicVersionNegotiationPacket& packet) { |
| 149 | version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet)); |
| 150 | frame_count_ = 0; |
| 151 | } |
| 152 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 153 | FramerVisitorCapturingPublicReset::FramerVisitorCapturingPublicReset() { |
| 154 | } |
| 155 | |
| 156 | FramerVisitorCapturingPublicReset::~FramerVisitorCapturingPublicReset() { |
| 157 | } |
| 158 | |
| 159 | void FramerVisitorCapturingPublicReset::OnPublicResetPacket( |
| 160 | const QuicPublicResetPacket& public_reset) { |
| 161 | public_reset_packet_ = public_reset; |
| 162 | } |
| 163 | |
[email protected] | 8d659e2 | 2013-01-19 04:26:10 | [diff] [blame] | 164 | MockConnectionVisitor::MockConnectionVisitor() { |
| 165 | } |
| 166 | |
| 167 | MockConnectionVisitor::~MockConnectionVisitor() { |
| 168 | } |
| 169 | |
[email protected] | 9c0b135 | 2012-11-04 00:03:27 | [diff] [blame] | 170 | MockHelper::MockHelper() { |
| 171 | } |
| 172 | |
| 173 | MockHelper::~MockHelper() { |
| 174 | } |
| 175 | |
[email protected] | 97693d1 | 2012-11-16 16:05:00 | [diff] [blame] | 176 | const QuicClock* MockHelper::GetClock() const { |
[email protected] | 9c0b135 | 2012-11-04 00:03:27 | [diff] [blame] | 177 | return &clock_; |
| 178 | } |
| 179 | |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 180 | QuicRandom* MockHelper::GetRandomGenerator() { |
| 181 | return &random_generator_; |
| 182 | } |
| 183 | |
[email protected] | fe053f9 | 2013-04-23 20:18:55 | [diff] [blame] | 184 | void MockHelper::AdvanceTime(QuicTime::Delta delta) { |
| 185 | clock_.AdvanceTime(delta); |
| 186 | } |
| 187 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 188 | MockConnection::MockConnection(QuicGuid guid, |
| 189 | IPEndPoint address, |
| 190 | bool is_server) |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 191 | : QuicConnection(guid, address, new testing::NiceMock<MockHelper>(), |
| 192 | is_server), |
[email protected] | fe053f9 | 2013-04-23 20:18:55 | [diff] [blame] | 193 | has_mock_helper_(true) { |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 194 | } |
| 195 | |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 196 | MockConnection::MockConnection(QuicGuid guid, |
| 197 | IPEndPoint address, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 198 | QuicConnectionHelperInterface* helper, |
| 199 | bool is_server) |
[email protected] | fe053f9 | 2013-04-23 20:18:55 | [diff] [blame] | 200 | : QuicConnection(guid, address, helper, is_server), |
| 201 | has_mock_helper_(false) { |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 204 | MockConnection::~MockConnection() { |
| 205 | } |
| 206 | |
[email protected] | fe053f9 | 2013-04-23 20:18:55 | [diff] [blame] | 207 | void MockConnection::AdvanceTime(QuicTime::Delta delta) { |
| 208 | CHECK(has_mock_helper_) << "Cannot advance time unless a MockClock is being" |
| 209 | " used"; |
| 210 | static_cast<MockHelper*>(helper())->AdvanceTime(delta); |
| 211 | } |
| 212 | |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 213 | PacketSavingConnection::PacketSavingConnection(QuicGuid guid, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 214 | IPEndPoint address, |
| 215 | bool is_server) |
| 216 | : MockConnection(guid, address, is_server) { |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | PacketSavingConnection::~PacketSavingConnection() { |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 220 | STLDeleteElements(&packets_); |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 221 | STLDeleteElements(&encrypted_packets_); |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 224 | bool PacketSavingConnection::SendOrQueuePacket( |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 225 | EncryptionLevel level, |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 226 | QuicPacketSequenceNumber sequence_number, |
| 227 | QuicPacket* packet, |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 228 | QuicPacketEntropyHash entropy_hash, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 229 | HasRetransmittableData retransmittable) { |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 230 | packets_.push_back(packet); |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 231 | QuicEncryptedPacket* encrypted = |
| 232 | framer_.EncryptPacket(level, sequence_number, *packet); |
| 233 | encrypted_packets_.push_back(encrypted); |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 234 | return true; |
| 235 | } |
| 236 | |
| 237 | MockSession::MockSession(QuicConnection* connection, bool is_server) |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 238 | : QuicSession(connection, DefaultQuicConfig(), is_server) { |
[email protected] | cff7b7b | 2013-01-11 08:49:07 | [diff] [blame] | 239 | ON_CALL(*this, WriteData(_, _, _, _)) |
| 240 | .WillByDefault(testing::Return(QuicConsumedData(0, false))); |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | MockSession::~MockSession() { |
| 244 | } |
| 245 | |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 246 | TestSession::TestSession(QuicConnection* connection, |
| 247 | const QuicConfig& config, |
| 248 | bool is_server) |
| 249 | : QuicSession(connection, config, is_server), |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 250 | crypto_stream_(NULL) { |
| 251 | } |
| 252 | |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 253 | TestSession::~TestSession() {} |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 254 | |
| 255 | void TestSession::SetCryptoStream(QuicCryptoStream* stream) { |
| 256 | crypto_stream_ = stream; |
| 257 | } |
| 258 | |
| 259 | QuicCryptoStream* TestSession::GetCryptoStream() { |
| 260 | return crypto_stream_; |
| 261 | } |
| 262 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 263 | MockSendAlgorithm::MockSendAlgorithm() { |
[email protected] | 8d659e2 | 2013-01-19 04:26:10 | [diff] [blame] | 264 | } |
| 265 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 266 | MockSendAlgorithm::~MockSendAlgorithm() { |
[email protected] | 8d659e2 | 2013-01-19 04:26:10 | [diff] [blame] | 267 | } |
| 268 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 269 | namespace { |
| 270 | |
| 271 | string HexDumpWithMarks(const char* data, int length, |
| 272 | const bool* marks, int mark_length) { |
| 273 | static const char kHexChars[] = "0123456789abcdef"; |
| 274 | static const int kColumns = 4; |
| 275 | |
| 276 | const int kSizeLimit = 1024; |
| 277 | if (length > kSizeLimit || mark_length > kSizeLimit) { |
| 278 | LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes."; |
| 279 | length = min(length, kSizeLimit); |
| 280 | mark_length = min(mark_length, kSizeLimit); |
| 281 | } |
| 282 | |
| 283 | string hex; |
| 284 | for (const char* row = data; length > 0; |
| 285 | row += kColumns, length -= kColumns) { |
| 286 | for (const char *p = row; p < row + 4; ++p) { |
| 287 | if (p < row + length) { |
| 288 | const bool mark = |
| 289 | (marks && (p - data) < mark_length && marks[p - data]); |
| 290 | hex += mark ? '*' : ' '; |
| 291 | hex += kHexChars[(*p & 0xf0) >> 4]; |
| 292 | hex += kHexChars[*p & 0x0f]; |
| 293 | hex += mark ? '*' : ' '; |
| 294 | } else { |
| 295 | hex += " "; |
| 296 | } |
| 297 | } |
| 298 | hex = hex + " "; |
| 299 | |
| 300 | for (const char *p = row; p < row + 4 && p < row + length; ++p) |
| 301 | hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.'; |
| 302 | |
| 303 | hex = hex + '\n'; |
| 304 | } |
| 305 | return hex; |
| 306 | } |
| 307 | |
| 308 | } // namespace |
| 309 | |
| 310 | void CompareCharArraysWithHexError( |
| 311 | const string& description, |
| 312 | const char* actual, |
| 313 | const int actual_len, |
| 314 | const char* expected, |
| 315 | const int expected_len) { |
| 316 | const int min_len = min(actual_len, expected_len); |
| 317 | const int max_len = max(actual_len, expected_len); |
[email protected] | 4356f0f | 2013-04-07 00:58:17 | [diff] [blame] | 318 | scoped_ptr<bool[]> marks(new bool[max_len]); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 319 | bool identical = (actual_len == expected_len); |
| 320 | for (int i = 0; i < min_len; ++i) { |
| 321 | if (actual[i] != expected[i]) { |
| 322 | marks[i] = true; |
| 323 | identical = false; |
| 324 | } else { |
| 325 | marks[i] = false; |
| 326 | } |
| 327 | } |
| 328 | for (int i = min_len; i < max_len; ++i) { |
| 329 | marks[i] = true; |
| 330 | } |
| 331 | if (identical) return; |
| 332 | ADD_FAILURE() |
| 333 | << "Description:\n" |
| 334 | << description |
| 335 | << "\n\nExpected:\n" |
| 336 | << HexDumpWithMarks(expected, expected_len, marks.get(), max_len) |
| 337 | << "\nActual:\n" |
| 338 | << HexDumpWithMarks(actual, actual_len, marks.get(), max_len); |
| 339 | } |
| 340 | |
| 341 | void CompareQuicDataWithHexError( |
| 342 | const string& description, |
| 343 | QuicData* actual, |
| 344 | QuicData* expected) { |
| 345 | CompareCharArraysWithHexError( |
| 346 | description, |
| 347 | actual->data(), actual->length(), |
| 348 | expected->data(), expected->length()); |
| 349 | } |
| 350 | |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 351 | static QuicPacket* ConstructPacketFromHandshakeMessage( |
| 352 | QuicGuid guid, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 353 | const CryptoHandshakeMessage& message, |
| 354 | bool should_include_version) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 355 | CryptoFramer crypto_framer; |
[email protected] | dc2cc74 | 2012-10-21 13:56:13 | [diff] [blame] | 356 | scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message)); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 357 | QuicFramer quic_framer(kQuicVersion1, QuicTime::Zero(), false); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 358 | |
| 359 | QuicPacketHeader header; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 360 | header.public_header.guid = guid; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 361 | header.public_header.reset_flag = false; |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 362 | header.public_header.version_flag = should_include_version; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 363 | header.packet_sequence_number = 1; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 364 | header.entropy_flag = false; |
| 365 | header.entropy_hash = 0; |
| 366 | header.fec_flag = false; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 367 | header.fec_group = 0; |
| 368 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 369 | QuicStreamFrame stream_frame(kCryptoStreamId, false, 0, |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 370 | data->AsStringPiece()); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 371 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 372 | QuicFrame frame(&stream_frame); |
| 373 | QuicFrames frames; |
| 374 | frames.push_back(frame); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 375 | return quic_framer.ConstructFrameDataPacket(header, frames).packet; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 376 | } |
| 377 | |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 378 | QuicPacket* ConstructHandshakePacket(QuicGuid guid, QuicTag tag) { |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 379 | CryptoHandshakeMessage message; |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 380 | message.set_tag(tag); |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 381 | return ConstructPacketFromHandshakeMessage(guid, message, false); |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 382 | } |
| 383 | |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 384 | size_t GetPacketLengthForOneStream( |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame^] | 385 | bool include_version, InFecGroup is_in_fec_group, size_t* payload_length) { |
| 386 | *payload_length = 1; |
| 387 | const size_t stream_length = |
| 388 | NullEncrypter().GetCiphertextSize(*payload_length) + |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 389 | QuicPacketCreator::StreamFramePacketOverhead( |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame^] | 390 | PACKET_8BYTE_GUID, include_version, |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 391 | PACKET_6BYTE_SEQUENCE_NUMBER, is_in_fec_group); |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame^] | 392 | const size_t ack_length = NullEncrypter().GetCiphertextSize( |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 393 | QuicFramer::GetMinAckFrameSize()) + |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 394 | GetPacketHeaderSize(PACKET_8BYTE_GUID, include_version, |
| 395 | PACKET_6BYTE_SEQUENCE_NUMBER, is_in_fec_group); |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame^] | 396 | if (stream_length < ack_length) { |
| 397 | *payload_length = 1 + ack_length - stream_length; |
| 398 | } |
| 399 | |
| 400 | return NullEncrypter().GetCiphertextSize(*payload_length) + |
| 401 | QuicPacketCreator::StreamFramePacketOverhead( |
| 402 | PACKET_8BYTE_GUID, include_version, |
| 403 | PACKET_6BYTE_SEQUENCE_NUMBER, is_in_fec_group); |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 404 | } |
| 405 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 406 | QuicPacketEntropyHash TestEntropyCalculator::ReceivedEntropyHash( |
| 407 | QuicPacketSequenceNumber sequence_number) const { |
| 408 | return 1u; |
| 409 | } |
| 410 | |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 411 | QuicConfig DefaultQuicConfig() { |
| 412 | QuicConfig config; |
| 413 | config.SetDefaults(); |
| 414 | return config; |
| 415 | } |
| 416 | |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 417 | bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) { |
| 418 | data.AppendToString(&data_); |
| 419 | return true; |
| 420 | } |
| 421 | |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 422 | void TestDecompressorVisitor::OnDecompressionError() { |
| 423 | error_ = true; |
| 424 | } |
| 425 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 426 | } // namespace test |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 427 | } // namespace net |