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/test_tools/quic_test_utils.h" | 5 #include "net/quic/test_tools/quic_test_utils.h" |
6 | 6 |
7 #include "base/sha1.h" | 7 #include "base/sha1.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "net/quic/crypto/crypto_framer.h" | 10 #include "net/quic/crypto/crypto_framer.h" |
11 #include "net/quic/crypto/crypto_handshake.h" | 11 #include "net/quic/crypto/crypto_handshake.h" |
12 #include "net/quic/crypto/crypto_utils.h" | 12 #include "net/quic/crypto/crypto_utils.h" |
13 #include "net/quic/crypto/null_encrypter.h" | 13 #include "net/quic/crypto/null_encrypter.h" |
14 #include "net/quic/crypto/quic_decrypter.h" | 14 #include "net/quic/crypto/quic_decrypter.h" |
15 #include "net/quic/crypto/quic_encrypter.h" | 15 #include "net/quic/crypto/quic_encrypter.h" |
| 16 #include "net/quic/quic_data_writer.h" |
16 #include "net/quic/quic_framer.h" | 17 #include "net/quic/quic_framer.h" |
17 #include "net/quic/quic_packet_creator.h" | 18 #include "net/quic/quic_packet_creator.h" |
18 #include "net/quic/quic_utils.h" | 19 #include "net/quic/quic_utils.h" |
19 #include "net/quic/test_tools/quic_connection_peer.h" | 20 #include "net/quic/test_tools/quic_connection_peer.h" |
20 #include "net/spdy/spdy_frame_builder.h" | 21 #include "net/spdy/spdy_frame_builder.h" |
21 | 22 |
22 using base::StringPiece; | 23 using base::StringPiece; |
23 using std::max; | 24 using std::max; |
24 using std::min; | 25 using std::min; |
25 using std::string; | 26 using std::string; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 DCHECK_LE(packet_size, max_plaintext_size); | 70 DCHECK_LE(packet_size, max_plaintext_size); |
70 bool first_frame = i == 0; | 71 bool first_frame = i == 0; |
71 bool last_frame = i == frames.size() - 1; | 72 bool last_frame = i == frames.size() - 1; |
72 const size_t frame_size = framer->GetSerializedFrameLength( | 73 const size_t frame_size = framer->GetSerializedFrameLength( |
73 frames[i], max_plaintext_size - packet_size, first_frame, last_frame, | 74 frames[i], max_plaintext_size - packet_size, first_frame, last_frame, |
74 header.is_in_fec_group, | 75 header.is_in_fec_group, |
75 header.public_header.sequence_number_length); | 76 header.public_header.sequence_number_length); |
76 DCHECK(frame_size); | 77 DCHECK(frame_size); |
77 packet_size += frame_size; | 78 packet_size += frame_size; |
78 } | 79 } |
79 return framer->BuildDataPacket(header, frames, packet_size); | 80 return BuildUnsizedDataPacket(framer, header, frames, packet_size); |
| 81 } |
| 82 |
| 83 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, |
| 84 const QuicPacketHeader& header, |
| 85 const QuicFrames& frames, |
| 86 size_t packet_size) { |
| 87 char* buffer = new char[packet_size]; |
| 88 scoped_ptr<QuicPacket> packet( |
| 89 framer->BuildDataPacket(header, frames, buffer, packet_size)); |
| 90 DCHECK(packet.get() != nullptr); |
| 91 // Now I have to re-construct the data packet with data ownership. |
| 92 return new QuicPacket(buffer, packet->length(), true, |
| 93 header.public_header.connection_id_length, |
| 94 header.public_header.version_flag, |
| 95 header.public_header.sequence_number_length); |
80 } | 96 } |
81 | 97 |
82 uint64 SimpleRandom::RandUint64() { | 98 uint64 SimpleRandom::RandUint64() { |
83 unsigned char hash[base::kSHA1Length]; | 99 unsigned char hash[base::kSHA1Length]; |
84 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), | 100 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), |
85 hash); | 101 hash); |
86 memcpy(&seed_, hash, sizeof(seed_)); | 102 memcpy(&seed_, hash, sizeof(seed_)); |
87 return seed_; | 103 return seed_; |
88 } | 104 } |
89 | 105 |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 // called. | 678 // called. |
663 factory_->current_writer_ = this; | 679 factory_->current_writer_ = this; |
664 return QuicPerConnectionPacketWriter::WritePacket(buffer, | 680 return QuicPerConnectionPacketWriter::WritePacket(buffer, |
665 buf_len, | 681 buf_len, |
666 self_address, | 682 self_address, |
667 peer_address); | 683 peer_address); |
668 } | 684 } |
669 | 685 |
670 } // namespace test | 686 } // namespace test |
671 } // namespace net | 687 } // namespace net |
OLD | NEW |