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

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

Issue 19858003: * Removed QuicTag kQuicVersion1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compiler errors Created 7 years, 5 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 47
48 QuicPacketSequenceNumber ClosestTo(QuicPacketSequenceNumber target, 48 QuicPacketSequenceNumber ClosestTo(QuicPacketSequenceNumber target,
49 QuicPacketSequenceNumber a, 49 QuicPacketSequenceNumber a,
50 QuicPacketSequenceNumber b) { 50 QuicPacketSequenceNumber b) {
51 return (Delta(target, a) < Delta(target, b)) ? a : b; 51 return (Delta(target, a) < Delta(target, b)) ? a : b;
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 QuicFramer::QuicFramer(QuicTag version, 56 QuicFramer::QuicFramer(QuicVersion version,
57 QuicTime creation_time, 57 QuicTime creation_time,
58 bool is_server) 58 bool is_server)
59 : visitor_(NULL), 59 : visitor_(NULL),
60 fec_builder_(NULL), 60 fec_builder_(NULL),
61 error_(QUIC_NO_ERROR), 61 error_(QUIC_NO_ERROR),
62 last_sequence_number_(0), 62 last_sequence_number_(0),
63 last_serialized_guid_(0), 63 last_serialized_guid_(0),
64 quic_version_(version), 64 quic_version_(version),
65 decrypter_(QuicDecrypter::Create(kNULL)), 65 decrypter_(QuicDecrypter::Create(kNULL)),
66 alternative_decrypter_latch_(false), 66 alternative_decrypter_latch_(false),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // static 135 // static
136 size_t QuicFramer::GetStreamIdSize(QuicStreamId stream_id) { 136 size_t QuicFramer::GetStreamIdSize(QuicStreamId stream_id) {
137 return 4; 137 return 4;
138 } 138 }
139 139
140 // static 140 // static
141 size_t QuicFramer::GetStreamOffsetSize(QuicStreamOffset offset) { 141 size_t QuicFramer::GetStreamOffsetSize(QuicStreamOffset offset) {
142 return 8; 142 return 8;
143 } 143 }
144 144
145 bool QuicFramer::IsSupportedVersion(QuicTag version) { 145 bool QuicFramer::IsSupportedVersion(const QuicVersion version) const {
146 return version == kQuicVersion1; 146 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSupportedQuicVersions); ++i) {
Ryan Hamilton 2013/07/23 03:40:18 ARRAYSIZE_UNSAFE() vs arraysize()?
ramant (doing other things) 2013/07/23 05:05:22 Used arraysize() everywhere. Done.
147 if (version == kSupportedQuicVersions[i]) {
148 return true;
149 }
150 }
151 return false;
147 } 152 }
148 153
149 size_t QuicFramer::GetVersionNegotiationPacketSize(size_t number_versions) { 154 size_t QuicFramer::GetVersionNegotiationPacketSize(size_t number_versions) {
150 return kPublicFlagsSize + PACKET_8BYTE_GUID + 155 return kPublicFlagsSize + PACKET_8BYTE_GUID +
151 number_versions * kQuicVersionSize; 156 number_versions * kQuicVersionSize;
152 } 157 }
153 158
154 size_t QuicFramer::GetSerializedFrameLength( 159 size_t QuicFramer::GetSerializedFrameLength(
155 const QuicFrame& frame, size_t free_bytes, bool first_frame) { 160 const QuicFrame& frame, size_t free_bytes, bool first_frame) {
156 if (frame.type == PADDING_FRAME) { 161 if (frame.type == PADDING_FRAME) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 packet.rejected_sequence_number, 340 packet.rejected_sequence_number,
336 &writer)) { 341 &writer)) {
337 return NULL; 342 return NULL;
338 } 343 }
339 344
340 return new QuicEncryptedPacket(writer.take(), len, true); 345 return new QuicEncryptedPacket(writer.take(), len, true);
341 } 346 }
342 347
343 QuicEncryptedPacket* QuicFramer::ConstructVersionNegotiationPacket( 348 QuicEncryptedPacket* QuicFramer::ConstructVersionNegotiationPacket(
344 const QuicPacketPublicHeader& header, 349 const QuicPacketPublicHeader& header,
345 const QuicTagVector& supported_versions) { 350 const QuicVersionVector& supported_versions) {
346 DCHECK(header.version_flag); 351 DCHECK(header.version_flag);
347 size_t len = GetVersionNegotiationPacketSize(supported_versions.size()); 352 size_t len = GetVersionNegotiationPacketSize(supported_versions.size());
348 QuicDataWriter writer(len); 353 QuicDataWriter writer(len);
349 354
350 uint8 flags = static_cast<uint8>(PACKET_PUBLIC_FLAGS_VERSION | 355 uint8 flags = static_cast<uint8>(PACKET_PUBLIC_FLAGS_VERSION |
351 PACKET_PUBLIC_FLAGS_8BYTE_GUID | 356 PACKET_PUBLIC_FLAGS_8BYTE_GUID |
352 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE); 357 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE);
353 if (!writer.WriteUInt8(flags)) { 358 if (!writer.WriteUInt8(flags)) {
354 return NULL; 359 return NULL;
355 } 360 }
356 361
357 if (!writer.WriteUInt64(header.guid)) { 362 if (!writer.WriteUInt64(header.guid)) {
358 return NULL; 363 return NULL;
359 } 364 }
360 365
361 for (size_t i = 0; i < supported_versions.size(); ++i) { 366 for (size_t i = 0; i < supported_versions.size(); ++i) {
362 if (!writer.WriteUInt32(supported_versions[i])) { 367 if (!writer.WriteUInt32(QuicVersionToQuicTag(supported_versions[i]))) {
363 return NULL; 368 return NULL;
364 } 369 }
365 } 370 }
366 371
367 return new QuicEncryptedPacket(writer.take(), len, true); 372 return new QuicEncryptedPacket(writer.take(), len, true);
368 } 373 }
369 374
370 bool QuicFramer::ProcessPacket(const QuicEncryptedPacket& packet) { 375 bool QuicFramer::ProcessPacket(const QuicEncryptedPacket& packet) {
371 // TODO(satyamshekhar): Don't RaiseError (and close the connection) for 376 // TODO(satyamshekhar): Don't RaiseError (and close the connection) for
372 // invalid (unauthenticated) packets. 377 // invalid (unauthenticated) packets.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 bool QuicFramer::ProcessVersionNegotiationPacket( 411 bool QuicFramer::ProcessVersionNegotiationPacket(
407 QuicPacketPublicHeader* public_header) { 412 QuicPacketPublicHeader* public_header) {
408 DCHECK(!is_server_); 413 DCHECK(!is_server_);
409 // Try reading at least once to raise error if the packet is invalid. 414 // Try reading at least once to raise error if the packet is invalid.
410 do { 415 do {
411 QuicTag version; 416 QuicTag version;
412 if (!reader_->ReadBytes(&version, kQuicVersionSize)) { 417 if (!reader_->ReadBytes(&version, kQuicVersionSize)) {
413 set_detailed_error("Unable to read supported version in negotiation."); 418 set_detailed_error("Unable to read supported version in negotiation.");
414 return RaiseError(QUIC_INVALID_VERSION_NEGOTIATION_PACKET); 419 return RaiseError(QUIC_INVALID_VERSION_NEGOTIATION_PACKET);
415 } 420 }
416 public_header->versions.push_back(version); 421 public_header->versions.push_back(QuicTagToQuicVersion(version));
417 } while (!reader_->IsDoneReading()); 422 } while (!reader_->IsDoneReading());
418 423
419 visitor_->OnVersionNegotiationPacket(*public_header); 424 visitor_->OnVersionNegotiationPacket(*public_header);
420 return true; 425 return true;
421 } 426 }
422 427
423 bool QuicFramer::ProcessDataPacket( 428 bool QuicFramer::ProcessDataPacket(
424 const QuicPacketPublicHeader& public_header, 429 const QuicPacketPublicHeader& public_header,
425 const QuicEncryptedPacket& packet) { 430 const QuicEncryptedPacket& packet) {
426 QuicPacketHeader header(public_header); 431 QuicPacketHeader header(public_header);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 } 566 }
562 if (!writer->WriteUInt64(header.public_header.guid)) { 567 if (!writer->WriteUInt64(header.public_header.guid)) {
563 return false; 568 return false;
564 } 569 }
565 break; 570 break;
566 } 571 }
567 last_serialized_guid_ = header.public_header.guid; 572 last_serialized_guid_ = header.public_header.guid;
568 573
569 if (header.public_header.version_flag) { 574 if (header.public_header.version_flag) {
570 DCHECK(!is_server_); 575 DCHECK(!is_server_);
571 writer->WriteUInt32(quic_version_); 576 writer->WriteUInt32(QuicVersionToQuicTag(quic_version_));
572 } 577 }
573 578
574 if (!AppendPacketSequenceNumber(header.public_header.sequence_number_length, 579 if (!AppendPacketSequenceNumber(header.public_header.sequence_number_length,
575 header.packet_sequence_number, writer)) { 580 header.packet_sequence_number, writer)) {
576 return false; 581 return false;
577 } 582 }
578 583
579 uint8 private_flags = 0; 584 uint8 private_flags = 0;
580 if (header.entropy_flag) { 585 if (header.entropy_flag) {
581 private_flags |= PACKET_PRIVATE_FLAGS_ENTROPY; 586 private_flags |= PACKET_PRIVATE_FLAGS_ENTROPY;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 break; 711 break;
707 case PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE: 712 case PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE:
708 public_header->sequence_number_length = PACKET_2BYTE_SEQUENCE_NUMBER; 713 public_header->sequence_number_length = PACKET_2BYTE_SEQUENCE_NUMBER;
709 break; 714 break;
710 case PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE: 715 case PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE:
711 public_header->sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER; 716 public_header->sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER;
712 break; 717 break;
713 } 718 }
714 719
715 if (public_header->version_flag && is_server_) { 720 if (public_header->version_flag && is_server_) {
716 QuicTag version; 721 QuicTag version_tag;
717 if (!reader_->ReadUInt32(&version)) { 722 if (!reader_->ReadUInt32(&version_tag)) {
718 // Read the version only if the packet is from the client. 723 // Read the version only if the packet is from the client.
719 // version flag from the server means version negotiation packet. 724 // version flag from the server means version negotiation packet.
720 set_detailed_error("Unable to read protocol version."); 725 set_detailed_error("Unable to read protocol version.");
721 return false; 726 return false;
722 } 727 }
728 QuicVersion version = QuicTagToQuicVersion(version_tag);
723 if (version == quic_version_ && public_flags > PACKET_PUBLIC_FLAGS_MAX) { 729 if (version == quic_version_ && public_flags > PACKET_PUBLIC_FLAGS_MAX) {
724 set_detailed_error("Illegal public flags value."); 730 set_detailed_error("Illegal public flags value.");
725 return false; 731 return false;
726 } 732 }
727 public_header->versions.push_back(version); 733 public_header->versions.push_back(version);
728 } 734 }
729 return true; 735 return true;
730 } 736 }
731 737
732 // static 738 // static
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 1713
1708 bool QuicFramer::RaiseError(QuicErrorCode error) { 1714 bool QuicFramer::RaiseError(QuicErrorCode error) {
1709 DLOG(INFO) << detailed_error_; 1715 DLOG(INFO) << detailed_error_;
1710 set_error(error); 1716 set_error(error);
1711 visitor_->OnError(this); 1717 visitor_->OnError(this);
1712 reader_.reset(NULL); 1718 reader_.reset(NULL);
1713 return false; 1719 return false;
1714 } 1720 }
1715 1721
1716 } // namespace net 1722 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698