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

Side by Side Diff: net/quic/quic_framer.cc

Issue 123303003: Move all the packet parsing logic into QuicDispatcher from the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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/quic_framer.h ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/containers/hash_tables.h" 7 #include "base/containers/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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 visitor_->OnPacket(); 475 visitor_->OnPacket();
476 476
477 // First parse the public header. 477 // First parse the public header.
478 QuicPacketPublicHeader public_header; 478 QuicPacketPublicHeader public_header;
479 if (!ProcessPublicHeader(&public_header)) { 479 if (!ProcessPublicHeader(&public_header)) {
480 DLOG(WARNING) << "Unable to process public header."; 480 DLOG(WARNING) << "Unable to process public header.";
481 DCHECK_NE("", detailed_error_); 481 DCHECK_NE("", detailed_error_);
482 return RaiseError(QUIC_INVALID_PACKET_HEADER); 482 return RaiseError(QUIC_INVALID_PACKET_HEADER);
483 } 483 }
484 484
485 if (!visitor_->OnUnauthenticatedPublicHeader(public_header)) {
486 // The visitor suppresses further processing of the packet.
487 reader_.reset(NULL);
488 return true;
489 }
490
485 if (is_server_ && public_header.version_flag && 491 if (is_server_ && public_header.version_flag &&
486 public_header.versions[0] != quic_version_) { 492 public_header.versions[0] != quic_version_) {
487 if (!visitor_->OnProtocolVersionMismatch(public_header.versions[0])) { 493 if (!visitor_->OnProtocolVersionMismatch(public_header.versions[0])) {
488 reader_.reset(NULL); 494 reader_.reset(NULL);
489 return true; 495 return true;
490 } 496 }
491 } 497 }
492 498
493 bool rv; 499 bool rv;
494 if (!is_server_ && public_header.version_flag) { 500 if (!is_server_ && public_header.version_flag) {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 if (version == quic_version_ && public_flags > PACKET_PUBLIC_FLAGS_MAX) { 812 if (version == quic_version_ && public_flags > PACKET_PUBLIC_FLAGS_MAX) {
807 set_detailed_error("Illegal public flags value."); 813 set_detailed_error("Illegal public flags value.");
808 return false; 814 return false;
809 } 815 }
810 public_header->versions.push_back(version); 816 public_header->versions.push_back(version);
811 } 817 }
812 return true; 818 return true;
813 } 819 }
814 820
815 // static 821 // static
816 bool QuicFramer::ReadGuidFromPacket(const QuicEncryptedPacket& packet,
817 QuicGuid* guid) {
818 QuicDataReader reader(packet.data(), packet.length());
819 uint8 public_flags;
820 if (!reader.ReadBytes(&public_flags, 1)) {
821 return false;
822 }
823 // Ensure it's an 8 byte guid.
824 if ((public_flags & PACKET_PUBLIC_FLAGS_8BYTE_GUID) !=
825 PACKET_PUBLIC_FLAGS_8BYTE_GUID) {
826 return false;
827 }
828
829 return reader.ReadUInt64(guid);
830 }
831
832 // static
833 QuicSequenceNumberLength QuicFramer::GetMinSequenceNumberLength( 822 QuicSequenceNumberLength QuicFramer::GetMinSequenceNumberLength(
834 QuicPacketSequenceNumber sequence_number) { 823 QuicPacketSequenceNumber sequence_number) {
835 if (sequence_number < 1 << (PACKET_1BYTE_SEQUENCE_NUMBER * 8)) { 824 if (sequence_number < 1 << (PACKET_1BYTE_SEQUENCE_NUMBER * 8)) {
836 return PACKET_1BYTE_SEQUENCE_NUMBER; 825 return PACKET_1BYTE_SEQUENCE_NUMBER;
837 } else if (sequence_number < 1 << (PACKET_2BYTE_SEQUENCE_NUMBER * 8)) { 826 } else if (sequence_number < 1 << (PACKET_2BYTE_SEQUENCE_NUMBER * 8)) {
838 return PACKET_2BYTE_SEQUENCE_NUMBER; 827 return PACKET_2BYTE_SEQUENCE_NUMBER;
839 } else if (sequence_number < 828 } else if (sequence_number <
840 GG_UINT64_C(1) << (PACKET_4BYTE_SEQUENCE_NUMBER * 8)) { 829 GG_UINT64_C(1) << (PACKET_4BYTE_SEQUENCE_NUMBER * 8)) {
841 return PACKET_4BYTE_SEQUENCE_NUMBER; 830 return PACKET_4BYTE_SEQUENCE_NUMBER;
842 } else { 831 } else {
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 } 1750 }
1762 } 1751 }
1763 1752
1764 if (!writer->WriteIOVector(frame.data)) { 1753 if (!writer->WriteIOVector(frame.data)) {
1765 return false; 1754 return false;
1766 } 1755 }
1767 return true; 1756 return true;
1768 } 1757 }
1769 1758
1770 // static 1759 // static
1771 bool QuicFramer::HasVersionFlag(const QuicEncryptedPacket& packet) {
1772 return packet.length() > 0 &&
1773 (packet.data()[0] & PACKET_PUBLIC_FLAGS_VERSION) != 0;
1774 }
1775
1776 void QuicFramer::set_version(const QuicVersion version) { 1760 void QuicFramer::set_version(const QuicVersion version) {
1777 DCHECK(IsSupportedVersion(version)); 1761 DCHECK(IsSupportedVersion(version));
1778 quic_version_ = version; 1762 quic_version_ = version;
1779 } 1763 }
1780 1764
1781 bool QuicFramer::AppendAckFramePayloadAndTypeByte( 1765 bool QuicFramer::AppendAckFramePayloadAndTypeByte(
1782 const QuicPacketHeader& header, 1766 const QuicPacketHeader& header,
1783 const QuicAckFrame& frame, 1767 const QuicAckFrame& frame,
1784 QuicDataWriter* writer) { 1768 QuicDataWriter* writer) {
1785 AckFrameInfo ack_info = GetAckFrameInfo(frame); 1769 AckFrameInfo ack_info = GetAckFrameInfo(frame);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 2036
2053 bool QuicFramer::RaiseError(QuicErrorCode error) { 2037 bool QuicFramer::RaiseError(QuicErrorCode error) {
2054 DVLOG(1) << "Error detail: " << detailed_error_; 2038 DVLOG(1) << "Error detail: " << detailed_error_;
2055 set_error(error); 2039 set_error(error);
2056 visitor_->OnError(this); 2040 visitor_->OnError(this);
2057 reader_.reset(NULL); 2041 reader_.reset(NULL);
2058 return false; 2042 return false;
2059 } 2043 }
2060 2044
2061 } // namespace net 2045 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.h ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698