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 #include "net/quic/quic_framer.h" | 5 #include "net/quic/quic_framer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... |
39 const QuicPacketSequenceNumber kEpoch = GG_UINT64_C(1) << 48; | 39 const QuicPacketSequenceNumber kEpoch = GG_UINT64_C(1) << 48; |
40 const QuicPacketSequenceNumber kMask = kEpoch - 1; | 40 const QuicPacketSequenceNumber kMask = kEpoch - 1; |
41 | 41 |
42 // Index into the connection_id offset in the header. | 42 // Index into the connection_id offset in the header. |
43 const size_t kConnectionIdOffset = kPublicFlagsSize; | 43 const size_t kConnectionIdOffset = kPublicFlagsSize; |
44 // Index into the version string in the header. (if present). | 44 // Index into the version string in the header. (if present). |
45 const size_t kVersionOffset = kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID; | 45 const size_t kVersionOffset = kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID; |
46 | 46 |
47 // Size in bytes of the stream frame fields for an arbitrary StreamID and | 47 // Size in bytes of the stream frame fields for an arbitrary StreamID and |
48 // offset and the last frame in a packet. | 48 // offset and the last frame in a packet. |
49 size_t GetMinStreamFrameSize(QuicVersion version) { | 49 size_t GetMinStreamFrameSize() { |
50 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; | 50 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; |
51 } | 51 } |
52 | 52 |
53 // Index into the sequence number offset in the header. | 53 // Index into the sequence number offset in the header. |
54 size_t GetSequenceNumberOffset(QuicConnectionIdLength connection_id_length, | 54 size_t GetSequenceNumberOffset(QuicConnectionIdLength connection_id_length, |
55 bool include_version) { | 55 bool include_version) { |
56 return kConnectionIdOffset + connection_id_length + | 56 return kConnectionIdOffset + connection_id_length + |
57 (include_version ? kQuicVersionSize : 0); | 57 (include_version ? kQuicVersionSize : 0); |
58 } | 58 } |
59 | 59 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 // Checks if the supplied string matches data in the supplied StreamFrame. | 454 // Checks if the supplied string matches data in the supplied StreamFrame. |
455 void CheckStreamFrameData(string str, QuicStreamFrame* frame) { | 455 void CheckStreamFrameData(string str, QuicStreamFrame* frame) { |
456 scoped_ptr<string> frame_data(frame->GetDataAsString()); | 456 scoped_ptr<string> frame_data(frame->GetDataAsString()); |
457 EXPECT_EQ(str, *frame_data); | 457 EXPECT_EQ(str, *frame_data); |
458 } | 458 } |
459 | 459 |
460 void CheckStreamFrameBoundaries(unsigned char* packet, | 460 void CheckStreamFrameBoundaries(unsigned char* packet, |
461 size_t stream_id_size, | 461 size_t stream_id_size, |
462 bool include_version) { | 462 bool include_version) { |
463 // Now test framing boundaries | 463 // Now test framing boundaries |
464 for (size_t i = kQuicFrameTypeSize; | 464 for (size_t i = kQuicFrameTypeSize; i < GetMinStreamFrameSize(); ++i) { |
465 i < GetMinStreamFrameSize(framer_.version()); ++i) { | |
466 string expected_error; | 465 string expected_error; |
467 if (i < kQuicFrameTypeSize + stream_id_size) { | 466 if (i < kQuicFrameTypeSize + stream_id_size) { |
468 expected_error = "Unable to read stream_id."; | 467 expected_error = "Unable to read stream_id."; |
469 } else if (i < kQuicFrameTypeSize + stream_id_size + | 468 } else if (i < kQuicFrameTypeSize + stream_id_size + |
470 kQuicMaxStreamOffsetSize) { | 469 kQuicMaxStreamOffsetSize) { |
471 expected_error = "Unable to read offset."; | 470 expected_error = "Unable to read offset."; |
472 } else { | 471 } else { |
473 expected_error = "Unable to read frame data."; | 472 expected_error = "Unable to read frame data."; |
474 } | 473 } |
475 CheckProcessingFails( | 474 CheckProcessingFails( |
(...skipping 3851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4327 EXPECT_CALL(visitor, OnPacketComplete()); | 4326 EXPECT_CALL(visitor, OnPacketComplete()); |
4328 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); | 4327 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
4329 | 4328 |
4330 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 4329 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
4331 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 4330 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
4332 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 4331 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
4333 } | 4332 } |
4334 | 4333 |
4335 } // namespace test | 4334 } // namespace test |
4336 } // namespace net | 4335 } // namespace net |
OLD | NEW |