| 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 "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
| 8 #include "net/quic/crypto/quic_decrypter.h" | 8 #include "net/quic/crypto/quic_decrypter.h" |
| 9 #include "net/quic/crypto/quic_encrypter.h" | 9 #include "net/quic/crypto/quic_encrypter.h" |
| 10 #include "net/quic/quic_data_reader.h" | 10 #include "net/quic/quic_data_reader.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 QuicPacket* packet = | 44 QuicPacket* packet = |
| 45 ConstructMaxFrameDataPacket(header, frames, &num_consumed); | 45 ConstructMaxFrameDataPacket(header, frames, &num_consumed); |
| 46 DCHECK_EQ(frames.size(), num_consumed); | 46 DCHECK_EQ(frames.size(), num_consumed); |
| 47 return packet; | 47 return packet; |
| 48 } | 48 } |
| 49 | 49 |
| 50 QuicPacket* QuicFramer::ConstructMaxFrameDataPacket( | 50 QuicPacket* QuicFramer::ConstructMaxFrameDataPacket( |
| 51 const QuicPacketHeader& header, | 51 const QuicPacketHeader& header, |
| 52 const QuicFrames& frames, | 52 const QuicFrames& frames, |
| 53 size_t* num_consumed) { | 53 size_t* num_consumed) { |
| 54 DCHECK(!frames.empty()); |
| 54 // Compute the length of the packet. We use "magic numbers" here because | 55 // Compute the length of the packet. We use "magic numbers" here because |
| 55 // sizeof(member_) is not necessarily the same as sizeof(member_wire_format). | 56 // sizeof(member_) is not necessarily the same as sizeof(member_wire_format). |
| 56 const size_t max_plaintext_size = GetMaxPlaintextSize(kMaxPacketSize); | 57 const size_t max_plaintext_size = GetMaxPlaintextSize(kMaxPacketSize); |
| 57 size_t len = kPacketHeaderSize; | 58 size_t len = kPacketHeaderSize; |
| 58 len += 1; // frame count | 59 len += 1; // frame count |
| 59 bool truncating = false; | 60 bool truncating = false; |
| 60 for (size_t i = 0; i < frames.size(); ++i) { | 61 for (size_t i = 0; i < frames.size(); ++i) { |
| 61 size_t frame_len = 1; // Space for the 8 bit type. | 62 size_t frame_len = 1; // Space for the 8 bit type. |
| 62 frame_len += ComputeFramePayloadLength(frames[i]); | 63 frame_len += ComputeFramePayloadLength(frames[i]); |
| 63 if (len + frame_len > max_plaintext_size) { | 64 if (len + frame_len > max_plaintext_size) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 82 *num_consumed = i + 1; | 83 *num_consumed = i + 1; |
| 83 } | 84 } |
| 84 | 85 |
| 85 QuicDataWriter writer(len); | 86 QuicDataWriter writer(len); |
| 86 | 87 |
| 87 if (!WritePacketHeader(header, &writer)) { | 88 if (!WritePacketHeader(header, &writer)) { |
| 88 return NULL; | 89 return NULL; |
| 89 } | 90 } |
| 90 | 91 |
| 91 // frame count | 92 // frame count |
| 92 if (frames.size() > 256u) { | 93 if (*num_consumed > 256u) { |
| 93 return NULL; | 94 return NULL; |
| 94 } | 95 } |
| 95 if (!writer.WriteUInt8(*num_consumed)) { | 96 if (!writer.WriteUInt8(*num_consumed)) { |
| 96 return NULL; | 97 return NULL; |
| 97 } | 98 } |
| 98 | 99 |
| 99 for (size_t i = 0; i < *num_consumed; ++i) { | 100 for (size_t i = 0; i < *num_consumed; ++i) { |
| 100 const QuicFrame& frame = frames[i]; | 101 const QuicFrame& frame = frames[i]; |
| 101 if (!writer.WriteUInt8(frame.type)) { | 102 if (!writer.WriteUInt8(frame.type)) { |
| 102 return NULL; | 103 return NULL; |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 | 602 |
| 602 if (!ProcessAckFrame(&frame.ack_frame)) { | 603 if (!ProcessAckFrame(&frame.ack_frame)) { |
| 603 DLOG(WARNING) << "Unable to process ack frame."; | 604 DLOG(WARNING) << "Unable to process ack frame."; |
| 604 return false; | 605 return false; |
| 605 } | 606 } |
| 606 | 607 |
| 607 visitor_->OnConnectionCloseFrame(frame); | 608 visitor_->OnConnectionCloseFrame(frame); |
| 608 return true; | 609 return true; |
| 609 } | 610 } |
| 610 | 611 |
| 611 void QuicFramer::WriteSequenceNumber(QuicPacketSequenceNumber sequence_number, | |
| 612 QuicPacket* packet) { | |
| 613 QuicDataWriter::WriteUint48ToBuffer( | |
| 614 sequence_number, packet->mutable_data() + kSequenceNumberOffset); | |
| 615 } | |
| 616 | |
| 617 void QuicFramer::WriteFecGroup(QuicFecGroupNumber fec_group, | |
| 618 QuicPacket* packet) { | |
| 619 QuicDataWriter::WriteUint8ToBuffer( | |
| 620 fec_group, packet->mutable_data() + kFecGroupOffset); | |
| 621 } | |
| 622 | |
| 623 QuicEncryptedPacket* QuicFramer::EncryptPacket(const QuicPacket& packet) { | 612 QuicEncryptedPacket* QuicFramer::EncryptPacket(const QuicPacket& packet) { |
| 624 scoped_ptr<QuicData> out(encrypter_->Encrypt(packet.AssociatedData(), | 613 scoped_ptr<QuicData> out(encrypter_->Encrypt(packet.AssociatedData(), |
| 625 packet.Plaintext())); | 614 packet.Plaintext())); |
| 626 if (out.get() == NULL) { | 615 if (out.get() == NULL) { |
| 627 RaiseError(QUIC_ENCRYPTION_FAILURE); | 616 RaiseError(QUIC_ENCRYPTION_FAILURE); |
| 628 return NULL; | 617 return NULL; |
| 629 } | 618 } |
| 630 size_t len = kStartOfEncryptedData + out->length(); | 619 size_t len = kStartOfEncryptedData + out->length(); |
| 631 char* buffer = new char[len]; | 620 char* buffer = new char[len]; |
| 632 // TODO(rch): eliminate this buffer copy by passing in a buffer to Encrypt(). | 621 // TODO(rch): eliminate this buffer copy by passing in a buffer to Encrypt(). |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 | 923 |
| 935 bool QuicFramer::RaiseError(QuicErrorCode error) { | 924 bool QuicFramer::RaiseError(QuicErrorCode error) { |
| 936 DLOG(INFO) << detailed_error_; | 925 DLOG(INFO) << detailed_error_; |
| 937 set_error(error); | 926 set_error(error); |
| 938 visitor_->OnError(this); | 927 visitor_->OnError(this); |
| 939 reader_.reset(NULL); | 928 reader_.reset(NULL); |
| 940 return false; | 929 return false; |
| 941 } | 930 } |
| 942 | 931 |
| 943 } // namespace net | 932 } // namespace net |
| OLD | NEW |