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

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

Issue 1009543004: Create a Perspective enum to use instead of a bool is_server to improve (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added NET_EXPORT_PRIVATE to fix compiler error Created 5 years, 9 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
« 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 "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "net/quic/crypto/crypto_framer.h" 9 #include "net/quic/crypto/crypto_framer.h"
10 #include "net/quic/crypto/crypto_handshake_message.h" 10 #include "net/quic/crypto/crypto_handshake_message.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 const QuicWindowUpdateFrame& frame) { 135 const QuicWindowUpdateFrame& frame) {
136 return true; 136 return true;
137 } 137 }
138 138
139 bool QuicFramerVisitorInterface::OnBlockedFrame(const QuicBlockedFrame& frame) { 139 bool QuicFramerVisitorInterface::OnBlockedFrame(const QuicBlockedFrame& frame) {
140 return true; 140 return true;
141 } 141 }
142 142
143 QuicFramer::QuicFramer(const QuicVersionVector& supported_versions, 143 QuicFramer::QuicFramer(const QuicVersionVector& supported_versions,
144 QuicTime creation_time, 144 QuicTime creation_time,
145 bool is_server) 145 Perspective perspective)
146 : visitor_(nullptr), 146 : visitor_(nullptr),
147 fec_builder_(nullptr), 147 fec_builder_(nullptr),
148 entropy_calculator_(nullptr), 148 entropy_calculator_(nullptr),
149 error_(QUIC_NO_ERROR), 149 error_(QUIC_NO_ERROR),
150 last_sequence_number_(0), 150 last_sequence_number_(0),
151 last_serialized_connection_id_(0), 151 last_serialized_connection_id_(0),
152 supported_versions_(supported_versions), 152 supported_versions_(supported_versions),
153 decrypter_level_(ENCRYPTION_NONE), 153 decrypter_level_(ENCRYPTION_NONE),
154 alternative_decrypter_level_(ENCRYPTION_NONE), 154 alternative_decrypter_level_(ENCRYPTION_NONE),
155 alternative_decrypter_latch_(false), 155 alternative_decrypter_latch_(false),
156 is_server_(is_server), 156 perspective_(perspective),
157 validate_flags_(true), 157 validate_flags_(true),
158 creation_time_(creation_time), 158 creation_time_(creation_time),
159 last_timestamp_(QuicTime::Delta::Zero()) { 159 last_timestamp_(QuicTime::Delta::Zero()) {
160 DCHECK(!supported_versions.empty()); 160 DCHECK(!supported_versions.empty());
161 quic_version_ = supported_versions_[0]; 161 quic_version_ = supported_versions_[0];
162 decrypter_.reset(QuicDecrypter::Create(kNULL)); 162 decrypter_.reset(QuicDecrypter::Create(kNULL));
163 encrypter_[ENCRYPTION_NONE].reset(QuicEncrypter::Create(kNULL)); 163 encrypter_[ENCRYPTION_NONE].reset(QuicEncrypter::Create(kNULL));
164 } 164 }
165 165
166 QuicFramer::~QuicFramer() {} 166 QuicFramer::~QuicFramer() {}
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 DCHECK_NE("", detailed_error_); 524 DCHECK_NE("", detailed_error_);
525 return RaiseError(QUIC_INVALID_PACKET_HEADER); 525 return RaiseError(QUIC_INVALID_PACKET_HEADER);
526 } 526 }
527 527
528 if (!visitor_->OnUnauthenticatedPublicHeader(public_header)) { 528 if (!visitor_->OnUnauthenticatedPublicHeader(public_header)) {
529 // The visitor suppresses further processing of the packet. 529 // The visitor suppresses further processing of the packet.
530 reader_.reset(nullptr); 530 reader_.reset(nullptr);
531 return true; 531 return true;
532 } 532 }
533 533
534 if (is_server_ && public_header.version_flag && 534 if (perspective_ == Perspective::IS_SERVER && public_header.version_flag &&
535 public_header.versions[0] != quic_version_) { 535 public_header.versions[0] != quic_version_) {
536 if (!visitor_->OnProtocolVersionMismatch(public_header.versions[0])) { 536 if (!visitor_->OnProtocolVersionMismatch(public_header.versions[0])) {
537 reader_.reset(nullptr); 537 reader_.reset(nullptr);
538 return true; 538 return true;
539 } 539 }
540 } 540 }
541 541
542 bool rv; 542 bool rv;
543 if (!is_server_ && public_header.version_flag) { 543 if (perspective_ == Perspective::IS_CLIENT && public_header.version_flag) {
544 rv = ProcessVersionNegotiationPacket(&public_header); 544 rv = ProcessVersionNegotiationPacket(&public_header);
545 } else if (public_header.reset_flag) { 545 } else if (public_header.reset_flag) {
546 rv = ProcessPublicResetPacket(public_header); 546 rv = ProcessPublicResetPacket(public_header);
547 } else if (packet.length() <= kMaxPacketSize) { 547 } else if (packet.length() <= kMaxPacketSize) {
548 char buffer[kMaxPacketSize]; 548 char buffer[kMaxPacketSize];
549 rv = ProcessDataPacket(public_header, packet, buffer, kMaxPacketSize); 549 rv = ProcessDataPacket(public_header, packet, buffer, kMaxPacketSize);
550 } else { 550 } else {
551 scoped_ptr<char[]> large_buffer(new char[packet.length()]); 551 scoped_ptr<char[]> large_buffer(new char[packet.length()]);
552 rv = ProcessDataPacket(public_header, packet, large_buffer.get(), 552 rv = ProcessDataPacket(public_header, packet, large_buffer.get(),
553 packet.length()); 553 packet.length());
554 LOG_IF(DFATAL, rv) << "QUIC should never successfully process packets " 554 LOG_IF(DFATAL, rv) << "QUIC should never successfully process packets "
555 << "larger than kMaxPacketSize. packet size:" 555 << "larger than kMaxPacketSize. packet size:"
556 << packet.length(); 556 << packet.length();
557 } 557 }
558 558
559 reader_.reset(nullptr); 559 reader_.reset(nullptr);
560 return rv; 560 return rv;
561 } 561 }
562 562
563 bool QuicFramer::ProcessVersionNegotiationPacket( 563 bool QuicFramer::ProcessVersionNegotiationPacket(
564 QuicPacketPublicHeader* public_header) { 564 QuicPacketPublicHeader* public_header) {
565 DCHECK(!is_server_); 565 DCHECK_EQ(Perspective::IS_CLIENT, perspective_);
566 // Try reading at least once to raise error if the packet is invalid. 566 // Try reading at least once to raise error if the packet is invalid.
567 do { 567 do {
568 QuicTag version; 568 QuicTag version;
569 if (!reader_->ReadBytes(&version, kQuicVersionSize)) { 569 if (!reader_->ReadBytes(&version, kQuicVersionSize)) {
570 set_detailed_error("Unable to read supported version in negotiation."); 570 set_detailed_error("Unable to read supported version in negotiation.");
571 return RaiseError(QUIC_INVALID_VERSION_NEGOTIATION_PACKET); 571 return RaiseError(QUIC_INVALID_VERSION_NEGOTIATION_PACKET);
572 } 572 }
573 public_header->versions.push_back(QuicTagToQuicVersion(version)); 573 public_header->versions.push_back(QuicTagToQuicVersion(version));
574 } while (!reader_->IsDoneReading()); 574 } while (!reader_->IsDoneReading());
575 575
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 return false; 737 return false;
738 } 738 }
739 if (!writer->WriteUInt64(header.public_header.connection_id)) { 739 if (!writer->WriteUInt64(header.public_header.connection_id)) {
740 return false; 740 return false;
741 } 741 }
742 break; 742 break;
743 } 743 }
744 last_serialized_connection_id_ = header.public_header.connection_id; 744 last_serialized_connection_id_ = header.public_header.connection_id;
745 745
746 if (header.public_header.version_flag) { 746 if (header.public_header.version_flag) {
747 DCHECK(!is_server_); 747 DCHECK_EQ(Perspective::IS_CLIENT, perspective_);
748 writer->WriteUInt32(QuicVersionToQuicTag(quic_version_)); 748 writer->WriteUInt32(QuicVersionToQuicTag(quic_version_));
749 } 749 }
750 750
751 if (!AppendPacketSequenceNumber(header.public_header.sequence_number_length, 751 if (!AppendPacketSequenceNumber(header.public_header.sequence_number_length,
752 header.packet_sequence_number, writer)) { 752 header.packet_sequence_number, writer)) {
753 return false; 753 return false;
754 } 754 }
755 755
756 uint8 private_flags = 0; 756 uint8 private_flags = 0;
757 if (header.entropy_flag) { 757 if (header.entropy_flag) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 public_header->connection_id = last_serialized_connection_id_; 903 public_header->connection_id = last_serialized_connection_id_;
904 break; 904 break;
905 } 905 }
906 906
907 public_header->sequence_number_length = 907 public_header->sequence_number_length =
908 ReadSequenceNumberLength( 908 ReadSequenceNumberLength(
909 public_flags >> kPublicHeaderSequenceNumberShift); 909 public_flags >> kPublicHeaderSequenceNumberShift);
910 910
911 // Read the version only if the packet is from the client. 911 // Read the version only if the packet is from the client.
912 // version flag from the server means version negotiation packet. 912 // version flag from the server means version negotiation packet.
913 if (public_header->version_flag && is_server_) { 913 if (public_header->version_flag && perspective_ == Perspective::IS_SERVER) {
914 QuicTag version_tag; 914 QuicTag version_tag;
915 if (!reader_->ReadUInt32(&version_tag)) { 915 if (!reader_->ReadUInt32(&version_tag)) {
916 set_detailed_error("Unable to read protocol version."); 916 set_detailed_error("Unable to read protocol version.");
917 return false; 917 return false;
918 } 918 }
919 919
920 // If the version from the new packet is the same as the version of this 920 // If the version from the new packet is the same as the version of this
921 // framer, then the public flags should be set to something we understand. 921 // framer, then the public flags should be set to something we understand.
922 // If not, this raises an error. 922 // If not, this raises an error.
923 QuicVersion version = QuicTagToQuicVersion(version_tag); 923 QuicVersion version = QuicTagToQuicVersion(version_tag);
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 2214
2215 bool QuicFramer::RaiseError(QuicErrorCode error) { 2215 bool QuicFramer::RaiseError(QuicErrorCode error) {
2216 DVLOG(1) << "Error detail: " << detailed_error_; 2216 DVLOG(1) << "Error detail: " << detailed_error_;
2217 set_error(error); 2217 set_error(error);
2218 visitor_->OnError(this); 2218 visitor_->OnError(this);
2219 reader_.reset(nullptr); 2219 reader_.reset(nullptr);
2220 return false; 2220 return false;
2221 } 2221 }
2222 2222
2223 } // namespace net 2223 } // 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