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/core/quic_framer.h" | 5 #include "net/quic/core/quic_framer.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 uint8_t flags = static_cast<uint8_t>(PACKET_PUBLIC_FLAGS_RST | | 435 uint8_t flags = static_cast<uint8_t>(PACKET_PUBLIC_FLAGS_RST | |
436 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID); | 436 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID); |
437 if (FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets) { | 437 if (FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets) { |
438 // TODO(rch): Remove this QUIC_VERSION_32 is retired. | 438 // TODO(rch): Remove this QUIC_VERSION_32 is retired. |
439 flags |= static_cast<uint8_t>(PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID_OLD); | 439 flags |= static_cast<uint8_t>(PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID_OLD); |
440 } | 440 } |
441 if (!writer.WriteUInt8(flags)) { | 441 if (!writer.WriteUInt8(flags)) { |
442 return nullptr; | 442 return nullptr; |
443 } | 443 } |
444 | 444 |
445 if (!writer.WriteUInt64(packet.public_header.connection_id)) { | 445 if (!writer.WriteConnectionId(packet.public_header.connection_id)) { |
446 return nullptr; | 446 return nullptr; |
447 } | 447 } |
448 | 448 |
449 if (!writer.WriteBytes(reset_serialized.data(), reset_serialized.length())) { | 449 if (!writer.WriteBytes(reset_serialized.data(), reset_serialized.length())) { |
450 return nullptr; | 450 return nullptr; |
451 } | 451 } |
452 | 452 |
453 return QuicMakeUnique<QuicEncryptedPacket>(buffer.release(), len, true); | 453 return QuicMakeUnique<QuicEncryptedPacket>(buffer.release(), len, true); |
454 } | 454 } |
455 | 455 |
456 // static | 456 // static |
457 std::unique_ptr<QuicEncryptedPacket> QuicFramer::BuildVersionNegotiationPacket( | 457 std::unique_ptr<QuicEncryptedPacket> QuicFramer::BuildVersionNegotiationPacket( |
458 QuicConnectionId connection_id, | 458 QuicConnectionId connection_id, |
459 const QuicVersionVector& versions) { | 459 const QuicVersionVector& versions) { |
460 DCHECK(!versions.empty()); | 460 DCHECK(!versions.empty()); |
461 size_t len = GetVersionNegotiationPacketSize(versions.size()); | 461 size_t len = GetVersionNegotiationPacketSize(versions.size()); |
462 std::unique_ptr<char[]> buffer(new char[len]); | 462 std::unique_ptr<char[]> buffer(new char[len]); |
463 QuicDataWriter writer(len, buffer.get()); | 463 QuicDataWriter writer(len, buffer.get()); |
464 | 464 |
465 uint8_t flags = static_cast<uint8_t>( | 465 uint8_t flags = static_cast<uint8_t>( |
466 PACKET_PUBLIC_FLAGS_VERSION | PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID | | 466 PACKET_PUBLIC_FLAGS_VERSION | PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID | |
467 // TODO(rch): Remove this QUIC_VERSION_32 is retired. | 467 // TODO(rch): Remove this QUIC_VERSION_32 is retired. |
468 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID_OLD); | 468 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID_OLD); |
469 if (!writer.WriteUInt8(flags)) { | 469 if (!writer.WriteUInt8(flags)) { |
470 return nullptr; | 470 return nullptr; |
471 } | 471 } |
472 | 472 |
473 if (!writer.WriteUInt64(connection_id)) { | 473 if (!writer.WriteConnectionId(connection_id)) { |
474 return nullptr; | 474 return nullptr; |
475 } | 475 } |
476 | 476 |
477 for (QuicVersion version : versions) { | 477 for (QuicVersion version : versions) { |
478 if (!writer.WriteUInt32(QuicVersionToQuicTag(version))) { | 478 if (!writer.WriteUInt32(QuicVersionToQuicTag(version))) { |
479 return nullptr; | 479 return nullptr; |
480 } | 480 } |
481 } | 481 } |
482 | 482 |
483 return QuicMakeUnique<QuicEncryptedPacket>(buffer.release(), len, true); | 483 return QuicMakeUnique<QuicEncryptedPacket>(buffer.release(), len, true); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 return false; | 667 return false; |
668 } | 668 } |
669 break; | 669 break; |
670 case PACKET_8BYTE_CONNECTION_ID: | 670 case PACKET_8BYTE_CONNECTION_ID: |
671 public_flags |= PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID; | 671 public_flags |= PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID; |
672 if (!FLAGS_quic_reloadable_flag_quic_remove_v33_hacks2 && | 672 if (!FLAGS_quic_reloadable_flag_quic_remove_v33_hacks2 && |
673 perspective_ == Perspective::IS_CLIENT) { | 673 perspective_ == Perspective::IS_CLIENT) { |
674 public_flags |= PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID_OLD; | 674 public_flags |= PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID_OLD; |
675 } | 675 } |
676 if (!writer->WriteUInt8(public_flags) || | 676 if (!writer->WriteUInt8(public_flags) || |
677 !writer->WriteUInt64(header.public_header.connection_id)) { | 677 !writer->WriteConnectionId(header.public_header.connection_id)) { |
678 return false; | 678 return false; |
679 } | 679 } |
680 break; | 680 break; |
681 } | 681 } |
682 last_serialized_connection_id_ = header.public_header.connection_id; | 682 last_serialized_connection_id_ = header.public_header.connection_id; |
683 | 683 |
684 if (header.public_header.version_flag) { | 684 if (header.public_header.version_flag) { |
685 DCHECK_EQ(Perspective::IS_CLIENT, perspective_); | 685 DCHECK_EQ(Perspective::IS_CLIENT, perspective_); |
686 QuicTag tag = QuicVersionToQuicTag(quic_version_); | 686 QuicTag tag = QuicVersionToQuicTag(quic_version_); |
687 if (!writer->WriteUInt32(tag)) { | 687 if (!writer->WriteUInt32(tag)) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 return false; | 780 return false; |
781 } | 781 } |
782 | 782 |
783 if (public_header->reset_flag && public_header->version_flag) { | 783 if (public_header->reset_flag && public_header->version_flag) { |
784 set_detailed_error("Got version flag in reset packet"); | 784 set_detailed_error("Got version flag in reset packet"); |
785 return false; | 785 return false; |
786 } | 786 } |
787 | 787 |
788 switch (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) { | 788 switch (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) { |
789 case PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID: | 789 case PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID: |
790 if (!reader->ReadUInt64(&public_header->connection_id)) { | 790 if (!reader->ReadConnectionId(&public_header->connection_id)) { |
791 set_detailed_error("Unable to read ConnectionId."); | 791 set_detailed_error("Unable to read ConnectionId."); |
792 return false; | 792 return false; |
793 } | 793 } |
794 public_header->connection_id_length = PACKET_8BYTE_CONNECTION_ID; | 794 public_header->connection_id_length = PACKET_8BYTE_CONNECTION_ID; |
795 break; | 795 break; |
796 case PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID: | 796 case PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID: |
797 public_header->connection_id_length = PACKET_0BYTE_CONNECTION_ID; | 797 public_header->connection_id_length = PACKET_0BYTE_CONNECTION_ID; |
798 public_header->connection_id = last_serialized_connection_id_; | 798 public_header->connection_id = last_serialized_connection_id_; |
799 break; | 799 break; |
800 } | 800 } |
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2105 | 2105 |
2106 bool QuicFramer::RaiseError(QuicErrorCode error) { | 2106 bool QuicFramer::RaiseError(QuicErrorCode error) { |
2107 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error) | 2107 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error) |
2108 << " detail: " << detailed_error_; | 2108 << " detail: " << detailed_error_; |
2109 set_error(error); | 2109 set_error(error); |
2110 visitor_->OnError(this); | 2110 visitor_->OnError(this); |
2111 return false; | 2111 return false; |
2112 } | 2112 } |
2113 | 2113 |
2114 } // namespace net | 2114 } // namespace net |
OLD | NEW |