| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 encrypter_[ENCRYPTION_NONE].reset(QuicEncrypter::Create(kNULL)); | 153 encrypter_[ENCRYPTION_NONE].reset(QuicEncrypter::Create(kNULL)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 QuicFramer::~QuicFramer() {} | 156 QuicFramer::~QuicFramer() {} |
| 157 | 157 |
| 158 // static | 158 // static |
| 159 size_t QuicFramer::GetMinStreamFrameSize(QuicStreamId stream_id, | 159 size_t QuicFramer::GetMinStreamFrameSize(QuicStreamId stream_id, |
| 160 QuicStreamOffset offset, | 160 QuicStreamOffset offset, |
| 161 bool last_frame_in_packet, | 161 bool last_frame_in_packet, |
| 162 InFecGroup is_in_fec_group) { | 162 InFecGroup is_in_fec_group) { |
| 163 bool no_stream_frame_length = last_frame_in_packet && | 163 bool no_stream_frame_length = |
| 164 is_in_fec_group == NOT_IN_FEC_GROUP; | 164 last_frame_in_packet && is_in_fec_group == NOT_IN_FEC_GROUP; |
| 165 return kQuicFrameTypeSize + GetStreamIdSize(stream_id) + | 165 return kQuicFrameTypeSize + GetStreamIdSize(stream_id) + |
| 166 GetStreamOffsetSize(offset) + | 166 GetStreamOffsetSize(offset) + |
| 167 (no_stream_frame_length ? 0 : kQuicStreamPayloadLengthSize); | 167 (no_stream_frame_length ? 0 : kQuicStreamPayloadLengthSize); |
| 168 } | 168 } |
| 169 | 169 |
| 170 // static | 170 // static |
| 171 size_t QuicFramer::GetMinAckFrameSize( | 171 size_t QuicFramer::GetMinAckFrameSize( |
| 172 QuicPacketNumberLength largest_observed_length) { | 172 QuicPacketNumberLength largest_observed_length) { |
| 173 return kQuicFrameTypeSize + kQuicEntropyHashSize + | 173 return kQuicFrameTypeSize + kQuicEntropyHashSize + largest_observed_length + |
| 174 largest_observed_length + kQuicDeltaTimeLargestObservedSize; | 174 kQuicDeltaTimeLargestObservedSize; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // static | 177 // static |
| 178 size_t QuicFramer::GetStopWaitingFrameSize( | 178 size_t QuicFramer::GetStopWaitingFrameSize( |
| 179 QuicPacketNumberLength packet_number_length) { | 179 QuicPacketNumberLength packet_number_length) { |
| 180 return kQuicFrameTypeSize + kQuicEntropyHashSize + packet_number_length; | 180 return kQuicFrameTypeSize + kQuicEntropyHashSize + packet_number_length; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // static | 183 // static |
| 184 size_t QuicFramer::GetMinRstStreamFrameSize() { | 184 size_t QuicFramer::GetMinRstStreamFrameSize() { |
| 185 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + | 185 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize + |
| 186 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize + | 186 kQuicErrorCodeSize + kQuicErrorDetailsLengthSize; |
| 187 kQuicErrorDetailsLengthSize; | |
| 188 } | 187 } |
| 189 | 188 |
| 190 // static | 189 // static |
| 191 size_t QuicFramer::GetRstStreamFrameSize() { | 190 size_t QuicFramer::GetRstStreamFrameSize() { |
| 192 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize + | 191 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize + |
| 193 kQuicErrorCodeSize; | 192 kQuicErrorCodeSize; |
| 194 } | 193 } |
| 195 | 194 |
| 196 // static | 195 // static |
| 197 size_t QuicFramer::GetMinConnectionCloseFrameSize() { | 196 size_t QuicFramer::GetMinConnectionCloseFrameSize() { |
| 198 return kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicErrorDetailsLengthSize; | 197 return kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicErrorDetailsLengthSize; |
| 199 } | 198 } |
| 200 | 199 |
| 201 // static | 200 // static |
| 202 size_t QuicFramer::GetMinGoAwayFrameSize() { | 201 size_t QuicFramer::GetMinGoAwayFrameSize() { |
| 203 return kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicErrorDetailsLengthSize + | 202 return kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicErrorDetailsLengthSize + |
| 204 kQuicMaxStreamIdSize; | 203 kQuicMaxStreamIdSize; |
| 205 } | 204 } |
| 206 | 205 |
| 207 // static | 206 // static |
| 208 size_t QuicFramer::GetWindowUpdateFrameSize() { | 207 size_t QuicFramer::GetWindowUpdateFrameSize() { |
| 209 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; | 208 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; |
| 210 } | 209 } |
| 211 | 210 |
| 212 // static | 211 // static |
| 213 size_t QuicFramer::GetBlockedFrameSize() { | 212 size_t QuicFramer::GetBlockedFrameSize() { |
| 214 return kQuicFrameTypeSize + kQuicMaxStreamIdSize; | 213 return kQuicFrameTypeSize + kQuicMaxStreamIdSize; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 241 return i; | 240 return i; |
| 242 } | 241 } |
| 243 } | 242 } |
| 244 LOG(DFATAL) << "Failed to determine StreamOffsetSize."; | 243 LOG(DFATAL) << "Failed to determine StreamOffsetSize."; |
| 245 return 8; | 244 return 8; |
| 246 } | 245 } |
| 247 | 246 |
| 248 // static | 247 // static |
| 249 size_t QuicFramer::GetVersionNegotiationPacketSize(size_t number_versions) { | 248 size_t QuicFramer::GetVersionNegotiationPacketSize(size_t number_versions) { |
| 250 return kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID + | 249 return kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID + |
| 251 number_versions * kQuicVersionSize; | 250 number_versions * kQuicVersionSize; |
| 252 } | 251 } |
| 253 | 252 |
| 254 bool QuicFramer::IsSupportedVersion(const QuicVersion version) const { | 253 bool QuicFramer::IsSupportedVersion(const QuicVersion version) const { |
| 255 for (size_t i = 0; i < supported_versions_.size(); ++i) { | 254 for (size_t i = 0; i < supported_versions_.size(); ++i) { |
| 256 if (version == supported_versions_[i]) { | 255 if (version == supported_versions_[i]) { |
| 257 return true; | 256 return true; |
| 258 } | 257 } |
| 259 } | 258 } |
| 260 return false; | 259 return false; |
| 261 } | 260 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 if (!AppendTypeByte(frame, no_stream_frame_length, &writer)) { | 335 if (!AppendTypeByte(frame, no_stream_frame_length, &writer)) { |
| 337 LOG(DFATAL) << "AppendTypeByte failed"; | 336 LOG(DFATAL) << "AppendTypeByte failed"; |
| 338 return 0; | 337 return 0; |
| 339 } | 338 } |
| 340 | 339 |
| 341 switch (frame.type) { | 340 switch (frame.type) { |
| 342 case PADDING_FRAME: | 341 case PADDING_FRAME: |
| 343 writer.WritePadding(); | 342 writer.WritePadding(); |
| 344 break; | 343 break; |
| 345 case STREAM_FRAME: | 344 case STREAM_FRAME: |
| 346 if (!AppendStreamFrame( | 345 if (!AppendStreamFrame(*frame.stream_frame, no_stream_frame_length, |
| 347 *frame.stream_frame, no_stream_frame_length, &writer)) { | 346 &writer)) { |
| 348 LOG(DFATAL) << "AppendStreamFrame failed"; | 347 LOG(DFATAL) << "AppendStreamFrame failed"; |
| 349 return 0; | 348 return 0; |
| 350 } | 349 } |
| 351 break; | 350 break; |
| 352 case ACK_FRAME: | 351 case ACK_FRAME: |
| 353 if (!AppendAckFrameAndTypeByte( | 352 if (!AppendAckFrameAndTypeByte(header, *frame.ack_frame, &writer)) { |
| 354 header, *frame.ack_frame, &writer)) { | |
| 355 LOG(DFATAL) << "AppendAckFrameAndTypeByte failed"; | 353 LOG(DFATAL) << "AppendAckFrameAndTypeByte failed"; |
| 356 return 0; | 354 return 0; |
| 357 } | 355 } |
| 358 break; | 356 break; |
| 359 case STOP_WAITING_FRAME: | 357 case STOP_WAITING_FRAME: |
| 360 if (!AppendStopWaitingFrame( | 358 if (!AppendStopWaitingFrame(header, *frame.stop_waiting_frame, |
| 361 header, *frame.stop_waiting_frame, &writer)) { | 359 &writer)) { |
| 362 LOG(DFATAL) << "AppendStopWaitingFrame failed"; | 360 LOG(DFATAL) << "AppendStopWaitingFrame failed"; |
| 363 return 0; | 361 return 0; |
| 364 } | 362 } |
| 365 break; | 363 break; |
| 366 case MTU_DISCOVERY_FRAME: | 364 case MTU_DISCOVERY_FRAME: |
| 367 // MTU discovery frames are serialized as ping frames. | 365 // MTU discovery frames are serialized as ping frames. |
| 368 case PING_FRAME: | 366 case PING_FRAME: |
| 369 // Ping has no payload. | 367 // Ping has no payload. |
| 370 break; | 368 break; |
| 371 case RST_STREAM_FRAME: | 369 case RST_STREAM_FRAME: |
| 372 if (!AppendRstStreamFrame(*frame.rst_stream_frame, &writer)) { | 370 if (!AppendRstStreamFrame(*frame.rst_stream_frame, &writer)) { |
| 373 LOG(DFATAL) << "AppendRstStreamFrame failed"; | 371 LOG(DFATAL) << "AppendRstStreamFrame failed"; |
| 374 return 0; | 372 return 0; |
| 375 } | 373 } |
| 376 break; | 374 break; |
| 377 case CONNECTION_CLOSE_FRAME: | 375 case CONNECTION_CLOSE_FRAME: |
| 378 if (!AppendConnectionCloseFrame( | 376 if (!AppendConnectionCloseFrame(*frame.connection_close_frame, |
| 379 *frame.connection_close_frame, &writer)) { | 377 &writer)) { |
| 380 LOG(DFATAL) << "AppendConnectionCloseFrame failed"; | 378 LOG(DFATAL) << "AppendConnectionCloseFrame failed"; |
| 381 return 0; | 379 return 0; |
| 382 } | 380 } |
| 383 break; | 381 break; |
| 384 case GOAWAY_FRAME: | 382 case GOAWAY_FRAME: |
| 385 if (!AppendGoAwayFrame(*frame.goaway_frame, &writer)) { | 383 if (!AppendGoAwayFrame(*frame.goaway_frame, &writer)) { |
| 386 LOG(DFATAL) << "AppendGoAwayFrame failed"; | 384 LOG(DFATAL) << "AppendGoAwayFrame failed"; |
| 387 return 0; | 385 return 0; |
| 388 } | 386 } |
| 389 break; | 387 break; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 if (reset->GetUint64(kRSEQ, &packet.rejected_packet_number) != | 650 if (reset->GetUint64(kRSEQ, &packet.rejected_packet_number) != |
| 653 QUIC_NO_ERROR) { | 651 QUIC_NO_ERROR) { |
| 654 set_detailed_error("Unable to read rejected packet number."); | 652 set_detailed_error("Unable to read rejected packet number."); |
| 655 return RaiseError(QUIC_INVALID_PUBLIC_RST_PACKET); | 653 return RaiseError(QUIC_INVALID_PUBLIC_RST_PACKET); |
| 656 } | 654 } |
| 657 | 655 |
| 658 StringPiece address; | 656 StringPiece address; |
| 659 if (reset->GetStringPiece(kCADR, &address)) { | 657 if (reset->GetStringPiece(kCADR, &address)) { |
| 660 QuicSocketAddressCoder address_coder; | 658 QuicSocketAddressCoder address_coder; |
| 661 if (address_coder.Decode(address.data(), address.length())) { | 659 if (address_coder.Decode(address.data(), address.length())) { |
| 662 packet.client_address = IPEndPoint(address_coder.ip(), | 660 packet.client_address = |
| 663 address_coder.port()); | 661 IPEndPoint(address_coder.ip(), address_coder.port()); |
| 664 } | 662 } |
| 665 } | 663 } |
| 666 | 664 |
| 667 visitor_->OnPublicResetPacket(packet); | 665 visitor_->OnPublicResetPacket(packet); |
| 668 return true; | 666 return true; |
| 669 } | 667 } |
| 670 | 668 |
| 671 bool QuicFramer::ProcessRevivedPacket(QuicPacketHeader* header, | 669 bool QuicFramer::ProcessRevivedPacket(QuicPacketHeader* header, |
| 672 StringPiece payload) { | 670 StringPiece payload) { |
| 673 visitor_->OnRevivedPacket(); | 671 visitor_->OnRevivedPacket(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 if (header.public_header.version_flag) { | 703 if (header.public_header.version_flag) { |
| 706 public_flags |= PACKET_PUBLIC_FLAGS_VERSION; | 704 public_flags |= PACKET_PUBLIC_FLAGS_VERSION; |
| 707 } | 705 } |
| 708 | 706 |
| 709 public_flags |= | 707 public_flags |= |
| 710 GetSequenceNumberFlags(header.public_header.packet_number_length) | 708 GetSequenceNumberFlags(header.public_header.packet_number_length) |
| 711 << kPublicHeaderSequenceNumberShift; | 709 << kPublicHeaderSequenceNumberShift; |
| 712 | 710 |
| 713 switch (header.public_header.connection_id_length) { | 711 switch (header.public_header.connection_id_length) { |
| 714 case PACKET_0BYTE_CONNECTION_ID: | 712 case PACKET_0BYTE_CONNECTION_ID: |
| 715 if (!writer->WriteUInt8( | 713 if (!writer->WriteUInt8(public_flags | |
| 716 public_flags | PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID)) { | 714 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID)) { |
| 717 return false; | 715 return false; |
| 718 } | 716 } |
| 719 break; | 717 break; |
| 720 case PACKET_1BYTE_CONNECTION_ID: | 718 case PACKET_1BYTE_CONNECTION_ID: |
| 721 if (!writer->WriteUInt8( | 719 if (!writer->WriteUInt8(public_flags | |
| 722 public_flags | PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID)) { | 720 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID)) { |
| 723 return false; | 721 return false; |
| 724 } | 722 } |
| 725 if (!writer->WriteUInt8( | 723 if (!writer->WriteUInt8(header.public_header.connection_id & |
| 726 header.public_header.connection_id & k1ByteConnectionIdMask)) { | 724 k1ByteConnectionIdMask)) { |
| 727 return false; | 725 return false; |
| 728 } | 726 } |
| 729 break; | 727 break; |
| 730 case PACKET_4BYTE_CONNECTION_ID: | 728 case PACKET_4BYTE_CONNECTION_ID: |
| 731 if (!writer->WriteUInt8( | 729 if (!writer->WriteUInt8(public_flags | |
| 732 public_flags | PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID)) { | 730 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID)) { |
| 733 return false; | 731 return false; |
| 734 } | 732 } |
| 735 if (!writer->WriteUInt32( | 733 if (!writer->WriteUInt32(header.public_header.connection_id & |
| 736 header.public_header.connection_id & k4ByteConnectionIdMask)) { | 734 k4ByteConnectionIdMask)) { |
| 737 return false; | 735 return false; |
| 738 } | 736 } |
| 739 break; | 737 break; |
| 740 case PACKET_8BYTE_CONNECTION_ID: | 738 case PACKET_8BYTE_CONNECTION_ID: |
| 741 if (!writer->WriteUInt8( | 739 if (!writer->WriteUInt8(public_flags | |
| 742 public_flags | PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID)) { | 740 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID)) { |
| 743 return false; | 741 return false; |
| 744 } | 742 } |
| 745 if (!writer->WriteUInt64(header.public_header.connection_id)) { | 743 if (!writer->WriteUInt64(header.public_header.connection_id)) { |
| 746 return false; | 744 return false; |
| 747 } | 745 } |
| 748 break; | 746 break; |
| 749 } | 747 } |
| 750 last_serialized_connection_id_ = header.public_header.connection_id; | 748 last_serialized_connection_id_ = header.public_header.connection_id; |
| 751 | 749 |
| 752 if (header.public_header.version_flag) { | 750 if (header.public_header.version_flag) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 // time. | 799 // time. |
| 802 // | 800 // |
| 803 // epoch_delta is the delta between epochs. A delta is 4 bytes of | 801 // epoch_delta is the delta between epochs. A delta is 4 bytes of |
| 804 // microseconds. | 802 // microseconds. |
| 805 const uint64 epoch_delta = UINT64_C(1) << 32; | 803 const uint64 epoch_delta = UINT64_C(1) << 32; |
| 806 uint64 epoch = last_timestamp_.ToMicroseconds() & ~(epoch_delta - 1); | 804 uint64 epoch = last_timestamp_.ToMicroseconds() & ~(epoch_delta - 1); |
| 807 // Wrapping is safe here because a wrapped value will not be ClosestTo below. | 805 // Wrapping is safe here because a wrapped value will not be ClosestTo below. |
| 808 uint64 prev_epoch = epoch - epoch_delta; | 806 uint64 prev_epoch = epoch - epoch_delta; |
| 809 uint64 next_epoch = epoch + epoch_delta; | 807 uint64 next_epoch = epoch + epoch_delta; |
| 810 | 808 |
| 811 uint64 time = ClosestTo(last_timestamp_.ToMicroseconds(), | 809 uint64 time = ClosestTo( |
| 812 epoch + time_delta_us, | 810 last_timestamp_.ToMicroseconds(), epoch + time_delta_us, |
| 813 ClosestTo(last_timestamp_.ToMicroseconds(), | 811 ClosestTo(last_timestamp_.ToMicroseconds(), prev_epoch + time_delta_us, |
| 814 prev_epoch + time_delta_us, | 812 next_epoch + time_delta_us)); |
| 815 next_epoch + time_delta_us)); | |
| 816 | 813 |
| 817 return QuicTime::Delta::FromMicroseconds(time); | 814 return QuicTime::Delta::FromMicroseconds(time); |
| 818 } | 815 } |
| 819 | 816 |
| 820 QuicPacketNumber QuicFramer::CalculatePacketNumberFromWire( | 817 QuicPacketNumber QuicFramer::CalculatePacketNumberFromWire( |
| 821 QuicPacketNumberLength packet_number_length, | 818 QuicPacketNumberLength packet_number_length, |
| 822 QuicPacketNumber packet_number) const { | 819 QuicPacketNumber packet_number) const { |
| 823 // The new packet number might have wrapped to the next epoch, or | 820 // The new packet number might have wrapped to the next epoch, or |
| 824 // it might have reverse wrapped to the previous epoch, or it might | 821 // it might have reverse wrapped to the previous epoch, or it might |
| 825 // remain in the same epoch. Select the packet number closest to the | 822 // remain in the same epoch. Select the packet number closest to the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 845 uint8 public_flags; | 842 uint8 public_flags; |
| 846 if (!reader->ReadBytes(&public_flags, 1)) { | 843 if (!reader->ReadBytes(&public_flags, 1)) { |
| 847 set_detailed_error("Unable to read public flags."); | 844 set_detailed_error("Unable to read public flags."); |
| 848 return false; | 845 return false; |
| 849 } | 846 } |
| 850 | 847 |
| 851 public_header->reset_flag = (public_flags & PACKET_PUBLIC_FLAGS_RST) != 0; | 848 public_header->reset_flag = (public_flags & PACKET_PUBLIC_FLAGS_RST) != 0; |
| 852 public_header->version_flag = | 849 public_header->version_flag = |
| 853 (public_flags & PACKET_PUBLIC_FLAGS_VERSION) != 0; | 850 (public_flags & PACKET_PUBLIC_FLAGS_VERSION) != 0; |
| 854 | 851 |
| 855 if (validate_flags_ && | 852 if (validate_flags_ && !public_header->version_flag && |
| 856 !public_header->version_flag && public_flags > PACKET_PUBLIC_FLAGS_MAX) { | 853 public_flags > PACKET_PUBLIC_FLAGS_MAX) { |
| 857 set_detailed_error("Illegal public flags value."); | 854 set_detailed_error("Illegal public flags value."); |
| 858 return false; | 855 return false; |
| 859 } | 856 } |
| 860 | 857 |
| 861 if (public_header->reset_flag && public_header->version_flag) { | 858 if (public_header->reset_flag && public_header->version_flag) { |
| 862 set_detailed_error("Got version flag in reset packet"); | 859 set_detailed_error("Got version flag in reset packet"); |
| 863 return false; | 860 return false; |
| 864 } | 861 } |
| 865 | 862 |
| 866 switch (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) { | 863 switch (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) { |
| 867 case PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID: | 864 case PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID: |
| 868 if (!reader->ReadUInt64(&public_header->connection_id)) { | 865 if (!reader->ReadUInt64(&public_header->connection_id)) { |
| 869 set_detailed_error("Unable to read ConnectionId."); | 866 set_detailed_error("Unable to read ConnectionId."); |
| 870 return false; | 867 return false; |
| 871 } | 868 } |
| 872 public_header->connection_id_length = PACKET_8BYTE_CONNECTION_ID; | 869 public_header->connection_id_length = PACKET_8BYTE_CONNECTION_ID; |
| 873 break; | 870 break; |
| 874 case PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID: | 871 case PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID: |
| 875 // If the connection_id is truncated, expect to read the last serialized | 872 // If the connection_id is truncated, expect to read the last serialized |
| 876 // connection_id. | 873 // connection_id. |
| 877 if (!reader->ReadBytes(&public_header->connection_id, | 874 if (!reader->ReadBytes(&public_header->connection_id, |
| 878 PACKET_4BYTE_CONNECTION_ID)) { | 875 PACKET_4BYTE_CONNECTION_ID)) { |
| 879 set_detailed_error("Unable to read ConnectionId."); | 876 set_detailed_error("Unable to read ConnectionId."); |
| 880 return false; | 877 return false; |
| 881 } | 878 } |
| 882 if (last_serialized_connection_id_ && | 879 if (last_serialized_connection_id_ && |
| 883 (public_header->connection_id & k4ByteConnectionIdMask) != | 880 (public_header->connection_id & k4ByteConnectionIdMask) != |
| 884 (last_serialized_connection_id_ & k4ByteConnectionIdMask)) { | 881 (last_serialized_connection_id_ & k4ByteConnectionIdMask)) { |
| 885 set_detailed_error("Truncated 4 byte ConnectionId does not match " | 882 set_detailed_error( |
| 886 "previous connection_id."); | 883 "Truncated 4 byte ConnectionId does not match " |
| 884 "previous connection_id."); |
| 887 return false; | 885 return false; |
| 888 } | 886 } |
| 889 public_header->connection_id_length = PACKET_4BYTE_CONNECTION_ID; | 887 public_header->connection_id_length = PACKET_4BYTE_CONNECTION_ID; |
| 890 public_header->connection_id = last_serialized_connection_id_; | 888 public_header->connection_id = last_serialized_connection_id_; |
| 891 break; | 889 break; |
| 892 case PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID: | 890 case PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID: |
| 893 if (!reader->ReadBytes(&public_header->connection_id, | 891 if (!reader->ReadBytes(&public_header->connection_id, |
| 894 PACKET_1BYTE_CONNECTION_ID)) { | 892 PACKET_1BYTE_CONNECTION_ID)) { |
| 895 set_detailed_error("Unable to read ConnectionId."); | 893 set_detailed_error("Unable to read ConnectionId."); |
| 896 return false; | 894 return false; |
| 897 } | 895 } |
| 898 if (last_serialized_connection_id_ && | 896 if (last_serialized_connection_id_ && |
| 899 (public_header->connection_id & k1ByteConnectionIdMask) != | 897 (public_header->connection_id & k1ByteConnectionIdMask) != |
| 900 (last_serialized_connection_id_ & k1ByteConnectionIdMask)) { | 898 (last_serialized_connection_id_ & k1ByteConnectionIdMask)) { |
| 901 set_detailed_error("Truncated 1 byte ConnectionId does not match " | 899 set_detailed_error( |
| 902 "previous connection_id."); | 900 "Truncated 1 byte ConnectionId does not match " |
| 901 "previous connection_id."); |
| 903 return false; | 902 return false; |
| 904 } | 903 } |
| 905 public_header->connection_id_length = PACKET_1BYTE_CONNECTION_ID; | 904 public_header->connection_id_length = PACKET_1BYTE_CONNECTION_ID; |
| 906 public_header->connection_id = last_serialized_connection_id_; | 905 public_header->connection_id = last_serialized_connection_id_; |
| 907 break; | 906 break; |
| 908 case PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID: | 907 case PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID: |
| 909 public_header->connection_id_length = PACKET_0BYTE_CONNECTION_ID; | 908 public_header->connection_id_length = PACKET_0BYTE_CONNECTION_ID; |
| 910 public_header->connection_id = last_serialized_connection_id_; | 909 public_header->connection_id = last_serialized_connection_id_; |
| 911 break; | 910 break; |
| 912 } | 911 } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 DVLOG(1) << "Visitor asked to stop further processing."; | 1116 DVLOG(1) << "Visitor asked to stop further processing."; |
| 1118 // Returning true since there was no parsing error. | 1117 // Returning true since there was no parsing error. |
| 1119 return true; | 1118 return true; |
| 1120 } | 1119 } |
| 1121 continue; | 1120 continue; |
| 1122 } | 1121 } |
| 1123 | 1122 |
| 1124 // This was a special frame type that did not match any | 1123 // This was a special frame type that did not match any |
| 1125 // of the known ones. Error. | 1124 // of the known ones. Error. |
| 1126 set_detailed_error("Illegal frame type."); | 1125 set_detailed_error("Illegal frame type."); |
| 1127 DLOG(WARNING) << "Illegal frame type: " | 1126 DLOG(WARNING) << "Illegal frame type: " << static_cast<int>(frame_type); |
| 1128 << static_cast<int>(frame_type); | |
| 1129 return RaiseError(QUIC_INVALID_FRAME_DATA); | 1127 return RaiseError(QUIC_INVALID_FRAME_DATA); |
| 1130 } | 1128 } |
| 1131 | 1129 |
| 1132 switch (frame_type) { | 1130 switch (frame_type) { |
| 1133 case PADDING_FRAME: | 1131 case PADDING_FRAME: |
| 1134 // We're done with the packet. | 1132 // We're done with the packet. |
| 1135 return true; | 1133 return true; |
| 1136 | 1134 |
| 1137 case RST_STREAM_FRAME: { | 1135 case RST_STREAM_FRAME: { |
| 1138 QuicRstStreamFrame frame; | 1136 QuicRstStreamFrame frame; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 if (!visitor_->OnPingFrame(ping_frame)) { | 1216 if (!visitor_->OnPingFrame(ping_frame)) { |
| 1219 DVLOG(1) << "Visitor asked to stop further processing."; | 1217 DVLOG(1) << "Visitor asked to stop further processing."; |
| 1220 // Returning true since there was no parsing error. | 1218 // Returning true since there was no parsing error. |
| 1221 return true; | 1219 return true; |
| 1222 } | 1220 } |
| 1223 continue; | 1221 continue; |
| 1224 } | 1222 } |
| 1225 | 1223 |
| 1226 default: | 1224 default: |
| 1227 set_detailed_error("Illegal frame type."); | 1225 set_detailed_error("Illegal frame type."); |
| 1228 DLOG(WARNING) << "Illegal frame type: " | 1226 DLOG(WARNING) << "Illegal frame type: " << static_cast<int>(frame_type); |
| 1229 << static_cast<int>(frame_type); | |
| 1230 return RaiseError(QUIC_INVALID_FRAME_DATA); | 1227 return RaiseError(QUIC_INVALID_FRAME_DATA); |
| 1231 } | 1228 } |
| 1232 } | 1229 } |
| 1233 | 1230 |
| 1234 return true; | 1231 return true; |
| 1235 } | 1232 } |
| 1236 | 1233 |
| 1237 bool QuicFramer::ProcessStreamFrame(QuicDataReader* reader, | 1234 bool QuicFramer::ProcessStreamFrame(QuicDataReader* reader, |
| 1238 uint8 frame_type, | 1235 uint8 frame_type, |
| 1239 QuicStreamFrame* frame) { | 1236 QuicStreamFrame* frame) { |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1597 } | 1594 } |
| 1598 | 1595 |
| 1599 const QuicDecrypter* QuicFramer::decrypter() const { | 1596 const QuicDecrypter* QuicFramer::decrypter() const { |
| 1600 return decrypter_.get(); | 1597 return decrypter_.get(); |
| 1601 } | 1598 } |
| 1602 | 1599 |
| 1603 const QuicDecrypter* QuicFramer::alternative_decrypter() const { | 1600 const QuicDecrypter* QuicFramer::alternative_decrypter() const { |
| 1604 return alternative_decrypter_.get(); | 1601 return alternative_decrypter_.get(); |
| 1605 } | 1602 } |
| 1606 | 1603 |
| 1607 void QuicFramer::SetEncrypter(EncryptionLevel level, | 1604 void QuicFramer::SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter) { |
| 1608 QuicEncrypter* encrypter) { | |
| 1609 DCHECK_GE(level, 0); | 1605 DCHECK_GE(level, 0); |
| 1610 DCHECK_LT(level, NUM_ENCRYPTION_LEVELS); | 1606 DCHECK_LT(level, NUM_ENCRYPTION_LEVELS); |
| 1611 encrypter_[level].reset(encrypter); | 1607 encrypter_[level].reset(encrypter); |
| 1612 } | 1608 } |
| 1613 | 1609 |
| 1614 size_t QuicFramer::EncryptPayload(EncryptionLevel level, | 1610 size_t QuicFramer::EncryptPayload(EncryptionLevel level, |
| 1615 QuicPacketNumber packet_number, | 1611 QuicPacketNumber packet_number, |
| 1616 const QuicPacket& packet, | 1612 const QuicPacket& packet, |
| 1617 char* buffer, | 1613 char* buffer, |
| 1618 size_t buffer_len) { | 1614 size_t buffer_len) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 const QuicAckFrame& ack, | 1700 const QuicAckFrame& ack, |
| 1705 QuicPacketNumberLength packet_number_length) { | 1701 QuicPacketNumberLength packet_number_length) { |
| 1706 AckFrameInfo ack_info = GetAckFrameInfo(ack); | 1702 AckFrameInfo ack_info = GetAckFrameInfo(ack); |
| 1707 QuicPacketNumberLength largest_observed_length = | 1703 QuicPacketNumberLength largest_observed_length = |
| 1708 GetMinSequenceNumberLength(ack.largest_observed); | 1704 GetMinSequenceNumberLength(ack.largest_observed); |
| 1709 QuicPacketNumberLength missing_packet_number_length = | 1705 QuicPacketNumberLength missing_packet_number_length = |
| 1710 GetMinSequenceNumberLength(ack_info.max_delta); | 1706 GetMinSequenceNumberLength(ack_info.max_delta); |
| 1711 | 1707 |
| 1712 size_t ack_size = GetMinAckFrameSize(largest_observed_length); | 1708 size_t ack_size = GetMinAckFrameSize(largest_observed_length); |
| 1713 if (!ack_info.nack_ranges.empty()) { | 1709 if (!ack_info.nack_ranges.empty()) { |
| 1714 ack_size += kNumberOfNackRangesSize + kNumberOfRevivedPacketsSize; | 1710 ack_size += kNumberOfNackRangesSize + kNumberOfRevivedPacketsSize; |
| 1715 ack_size += min(ack_info.nack_ranges.size(), kMaxNackRanges) * | 1711 ack_size += min(ack_info.nack_ranges.size(), kMaxNackRanges) * |
| 1716 (missing_packet_number_length + PACKET_1BYTE_PACKET_NUMBER); | 1712 (missing_packet_number_length + PACKET_1BYTE_PACKET_NUMBER); |
| 1717 if (ack.latest_revived_packet != 0) { | 1713 if (ack.latest_revived_packet != 0) { |
| 1718 ack_size += largest_observed_length; | 1714 ack_size += largest_observed_length; |
| 1719 } | 1715 } |
| 1720 } | 1716 } |
| 1721 | 1717 |
| 1722 // In version 23, if the ack will be truncated due to too many nack ranges, | 1718 // In version 23, if the ack will be truncated due to too many nack ranges, |
| 1723 // then do not include the number of timestamps (1 byte). | 1719 // then do not include the number of timestamps (1 byte). |
| 1724 if (ack_info.nack_ranges.size() <= kMaxNackRanges) { | 1720 if (ack_info.nack_ranges.size() <= kMaxNackRanges) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 return GetStopWaitingFrameSize(packet_number_length); | 1752 return GetStopWaitingFrameSize(packet_number_length); |
| 1757 case MTU_DISCOVERY_FRAME: | 1753 case MTU_DISCOVERY_FRAME: |
| 1758 // MTU discovery frames are serialized as ping frames. | 1754 // MTU discovery frames are serialized as ping frames. |
| 1759 case PING_FRAME: | 1755 case PING_FRAME: |
| 1760 // Ping has no payload. | 1756 // Ping has no payload. |
| 1761 return kQuicFrameTypeSize; | 1757 return kQuicFrameTypeSize; |
| 1762 case RST_STREAM_FRAME: | 1758 case RST_STREAM_FRAME: |
| 1763 return GetRstStreamFrameSize(); | 1759 return GetRstStreamFrameSize(); |
| 1764 case CONNECTION_CLOSE_FRAME: | 1760 case CONNECTION_CLOSE_FRAME: |
| 1765 return GetMinConnectionCloseFrameSize() + | 1761 return GetMinConnectionCloseFrameSize() + |
| 1766 frame.connection_close_frame->error_details.size(); | 1762 frame.connection_close_frame->error_details.size(); |
| 1767 case GOAWAY_FRAME: | 1763 case GOAWAY_FRAME: |
| 1768 return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size(); | 1764 return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size(); |
| 1769 case WINDOW_UPDATE_FRAME: | 1765 case WINDOW_UPDATE_FRAME: |
| 1770 return GetWindowUpdateFrameSize(); | 1766 return GetWindowUpdateFrameSize(); |
| 1771 case BLOCKED_FRAME: | 1767 case BLOCKED_FRAME: |
| 1772 return GetBlockedFrameSize(); | 1768 return GetBlockedFrameSize(); |
| 1773 case PADDING_FRAME: | 1769 case PADDING_FRAME: |
| 1774 DCHECK(false); | 1770 DCHECK(false); |
| 1775 return 0; | 1771 return 0; |
| 1776 case NUM_FRAME_TYPES: | 1772 case NUM_FRAME_TYPES: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1790 switch (frame.type) { | 1786 switch (frame.type) { |
| 1791 case STREAM_FRAME: { | 1787 case STREAM_FRAME: { |
| 1792 if (frame.stream_frame == nullptr) { | 1788 if (frame.stream_frame == nullptr) { |
| 1793 LOG(DFATAL) << "Failed to append STREAM frame with no stream_frame."; | 1789 LOG(DFATAL) << "Failed to append STREAM frame with no stream_frame."; |
| 1794 } | 1790 } |
| 1795 // Fin bit. | 1791 // Fin bit. |
| 1796 type_byte |= frame.stream_frame->fin ? kQuicStreamFinMask : 0; | 1792 type_byte |= frame.stream_frame->fin ? kQuicStreamFinMask : 0; |
| 1797 | 1793 |
| 1798 // Data Length bit. | 1794 // Data Length bit. |
| 1799 type_byte <<= kQuicStreamDataLengthShift; | 1795 type_byte <<= kQuicStreamDataLengthShift; |
| 1800 type_byte |= no_stream_frame_length ? 0: kQuicStreamDataLengthMask; | 1796 type_byte |= no_stream_frame_length ? 0 : kQuicStreamDataLengthMask; |
| 1801 | 1797 |
| 1802 // Offset 3 bits. | 1798 // Offset 3 bits. |
| 1803 type_byte <<= kQuicStreamOffsetShift; | 1799 type_byte <<= kQuicStreamOffsetShift; |
| 1804 const size_t offset_len = GetStreamOffsetSize(frame.stream_frame->offset); | 1800 const size_t offset_len = GetStreamOffsetSize(frame.stream_frame->offset); |
| 1805 if (offset_len > 0) { | 1801 if (offset_len > 0) { |
| 1806 type_byte |= offset_len - 1; | 1802 type_byte |= offset_len - 1; |
| 1807 } | 1803 } |
| 1808 | 1804 |
| 1809 // stream id 2 bits. | 1805 // stream id 2 bits. |
| 1810 type_byte <<= kQuicStreamIdShift; | 1806 type_byte <<= kQuicStreamIdShift; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 break; | 1843 break; |
| 1848 case PACKET_6BYTE_PACKET_NUMBER: | 1844 case PACKET_6BYTE_PACKET_NUMBER: |
| 1849 return writer->WriteUInt48(packet_number & k6ByteSequenceNumberMask); | 1845 return writer->WriteUInt48(packet_number & k6ByteSequenceNumberMask); |
| 1850 break; | 1846 break; |
| 1851 default: | 1847 default: |
| 1852 DCHECK(false) << "packet_number_length: " << packet_number_length; | 1848 DCHECK(false) << "packet_number_length: " << packet_number_length; |
| 1853 return false; | 1849 return false; |
| 1854 } | 1850 } |
| 1855 } | 1851 } |
| 1856 | 1852 |
| 1857 bool QuicFramer::AppendStreamFrame( | 1853 bool QuicFramer::AppendStreamFrame(const QuicStreamFrame& frame, |
| 1858 const QuicStreamFrame& frame, | 1854 bool no_stream_frame_length, |
| 1859 bool no_stream_frame_length, | 1855 QuicDataWriter* writer) { |
| 1860 QuicDataWriter* writer) { | |
| 1861 if (!writer->WriteBytes(&frame.stream_id, GetStreamIdSize(frame.stream_id))) { | 1856 if (!writer->WriteBytes(&frame.stream_id, GetStreamIdSize(frame.stream_id))) { |
| 1862 LOG(DFATAL) << "Writing stream id size failed."; | 1857 LOG(DFATAL) << "Writing stream id size failed."; |
| 1863 return false; | 1858 return false; |
| 1864 } | 1859 } |
| 1865 if (!writer->WriteBytes(&frame.offset, GetStreamOffsetSize(frame.offset))) { | 1860 if (!writer->WriteBytes(&frame.offset, GetStreamOffsetSize(frame.offset))) { |
| 1866 LOG(DFATAL) << "Writing offset size failed."; | 1861 LOG(DFATAL) << "Writing offset size failed."; |
| 1867 return false; | 1862 return false; |
| 1868 } | 1863 } |
| 1869 if (!no_stream_frame_length) { | 1864 if (!no_stream_frame_length) { |
| 1870 if ((frame.data.size() > numeric_limits<uint16>::max()) || | 1865 if ((frame.data.size() > numeric_limits<uint16>::max()) || |
| 1871 !writer->WriteUInt16(static_cast<uint16>(frame.data.size()))) { | 1866 !writer->WriteUInt16(static_cast<uint16>(frame.data.size()))) { |
| 1872 LOG(DFATAL) << "Writing stream frame length failed"; | 1867 LOG(DFATAL) << "Writing stream frame length failed"; |
| 1873 return false; | 1868 return false; |
| 1874 } | 1869 } |
| 1875 } | 1870 } |
| 1876 | 1871 |
| 1877 if (!writer->WriteBytes(frame.data.data(), frame.data.size())) { | 1872 if (!writer->WriteBytes(frame.data.data(), frame.data.size())) { |
| 1878 LOG(DFATAL) << "Writing frame data failed."; | 1873 LOG(DFATAL) << "Writing frame data failed."; |
| 1879 return false; | 1874 return false; |
| 1880 } | 1875 } |
| 1881 return true; | 1876 return true; |
| 1882 } | 1877 } |
| 1883 | 1878 |
| 1884 void QuicFramer::set_version(const QuicVersion version) { | 1879 void QuicFramer::set_version(const QuicVersion version) { |
| 1885 DCHECK(IsSupportedVersion(version)) << QuicVersionToString(version); | 1880 DCHECK(IsSupportedVersion(version)) << QuicVersionToString(version); |
| 1886 quic_version_ = version; | 1881 quic_version_ = version; |
| 1887 } | 1882 } |
| 1888 | 1883 |
| 1889 bool QuicFramer::AppendAckFrameAndTypeByte( | 1884 bool QuicFramer::AppendAckFrameAndTypeByte(const QuicPacketHeader& header, |
| 1890 const QuicPacketHeader& header, | 1885 const QuicAckFrame& frame, |
| 1891 const QuicAckFrame& frame, | 1886 QuicDataWriter* writer) { |
| 1892 QuicDataWriter* writer) { | |
| 1893 AckFrameInfo ack_info = GetAckFrameInfo(frame); | 1887 AckFrameInfo ack_info = GetAckFrameInfo(frame); |
| 1894 QuicPacketNumber ack_largest_observed = frame.largest_observed; | 1888 QuicPacketNumber ack_largest_observed = frame.largest_observed; |
| 1895 QuicPacketNumberLength largest_observed_length = | 1889 QuicPacketNumberLength largest_observed_length = |
| 1896 GetMinSequenceNumberLength(ack_largest_observed); | 1890 GetMinSequenceNumberLength(ack_largest_observed); |
| 1897 QuicPacketNumberLength missing_packet_number_length = | 1891 QuicPacketNumberLength missing_packet_number_length = |
| 1898 GetMinSequenceNumberLength(ack_info.max_delta); | 1892 GetMinSequenceNumberLength(ack_info.max_delta); |
| 1899 // Determine whether we need to truncate ranges. | 1893 // Determine whether we need to truncate ranges. |
| 1900 size_t available_range_bytes = | 1894 size_t available_range_bytes = |
| 1901 writer->capacity() - writer->length() - kNumberOfRevivedPacketsSize - | 1895 writer->capacity() - writer->length() - kNumberOfRevivedPacketsSize - |
| 1902 kNumberOfNackRangesSize - GetMinAckFrameSize(largest_observed_length); | 1896 kNumberOfNackRangesSize - GetMinAckFrameSize(largest_observed_length); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1946 ack_largest_observed = ack_iter->first - 1; | 1940 ack_largest_observed = ack_iter->first - 1; |
| 1947 // Also update the entropy so it matches the largest observed. | 1941 // Also update the entropy so it matches the largest observed. |
| 1948 ack_entropy_hash = entropy_calculator_->EntropyHash(ack_largest_observed); | 1942 ack_entropy_hash = entropy_calculator_->EntropyHash(ack_largest_observed); |
| 1949 ++ack_iter; | 1943 ++ack_iter; |
| 1950 } | 1944 } |
| 1951 | 1945 |
| 1952 if (!writer->WriteUInt8(ack_entropy_hash)) { | 1946 if (!writer->WriteUInt8(ack_entropy_hash)) { |
| 1953 return false; | 1947 return false; |
| 1954 } | 1948 } |
| 1955 | 1949 |
| 1956 if (!AppendPacketSequenceNumber(largest_observed_length, | 1950 if (!AppendPacketSequenceNumber(largest_observed_length, ack_largest_observed, |
| 1957 ack_largest_observed, writer)) { | 1951 writer)) { |
| 1958 return false; | 1952 return false; |
| 1959 } | 1953 } |
| 1960 | 1954 |
| 1961 uint64 delta_time_largest_observed_us = kUFloat16MaxValue; | 1955 uint64 delta_time_largest_observed_us = kUFloat16MaxValue; |
| 1962 if (!frame.delta_time_largest_observed.IsInfinite()) { | 1956 if (!frame.delta_time_largest_observed.IsInfinite()) { |
| 1963 DCHECK_LE(0u, frame.delta_time_largest_observed.ToMicroseconds()); | 1957 DCHECK_LE(0u, frame.delta_time_largest_observed.ToMicroseconds()); |
| 1964 delta_time_largest_observed_us = | 1958 delta_time_largest_observed_us = |
| 1965 frame.delta_time_largest_observed.ToMicroseconds(); | 1959 frame.delta_time_largest_observed.ToMicroseconds(); |
| 1966 } | 1960 } |
| 1967 | 1961 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2048 PacketTimeVector::const_iterator it = frame.received_packet_times.begin(); | 2042 PacketTimeVector::const_iterator it = frame.received_packet_times.begin(); |
| 2049 QuicPacketNumber packet_number = it->first; | 2043 QuicPacketNumber packet_number = it->first; |
| 2050 QuicPacketNumber delta_from_largest_observed = | 2044 QuicPacketNumber delta_from_largest_observed = |
| 2051 frame.largest_observed - packet_number; | 2045 frame.largest_observed - packet_number; |
| 2052 | 2046 |
| 2053 DCHECK_GE(numeric_limits<uint8>::max(), delta_from_largest_observed); | 2047 DCHECK_GE(numeric_limits<uint8>::max(), delta_from_largest_observed); |
| 2054 if (delta_from_largest_observed > numeric_limits<uint8>::max()) { | 2048 if (delta_from_largest_observed > numeric_limits<uint8>::max()) { |
| 2055 return false; | 2049 return false; |
| 2056 } | 2050 } |
| 2057 | 2051 |
| 2058 if (!writer->WriteUInt8( | 2052 if (!writer->WriteUInt8(delta_from_largest_observed & |
| 2059 delta_from_largest_observed & k1ByteSequenceNumberMask)) { | 2053 k1ByteSequenceNumberMask)) { |
| 2060 return false; | 2054 return false; |
| 2061 } | 2055 } |
| 2062 | 2056 |
| 2063 // Use the lowest 4 bytes of the time delta from the creation_time_. | 2057 // Use the lowest 4 bytes of the time delta from the creation_time_. |
| 2064 const uint64 time_epoch_delta_us = UINT64_C(1) << 32; | 2058 const uint64 time_epoch_delta_us = UINT64_C(1) << 32; |
| 2065 uint32 time_delta_us = | 2059 uint32 time_delta_us = |
| 2066 static_cast<uint32>(it->second.Subtract(creation_time_).ToMicroseconds() | 2060 static_cast<uint32>(it->second.Subtract(creation_time_).ToMicroseconds() & |
| 2067 & (time_epoch_delta_us - 1)); | 2061 (time_epoch_delta_us - 1)); |
| 2068 if (!writer->WriteBytes(&time_delta_us, sizeof(time_delta_us))) { | 2062 if (!writer->WriteBytes(&time_delta_us, sizeof(time_delta_us))) { |
| 2069 return false; | 2063 return false; |
| 2070 } | 2064 } |
| 2071 | 2065 |
| 2072 QuicTime prev_time = it->second; | 2066 QuicTime prev_time = it->second; |
| 2073 | 2067 |
| 2074 for (++it; it != frame.received_packet_times.end(); ++it) { | 2068 for (++it; it != frame.received_packet_times.end(); ++it) { |
| 2075 packet_number = it->first; | 2069 packet_number = it->first; |
| 2076 delta_from_largest_observed = frame.largest_observed - packet_number; | 2070 delta_from_largest_observed = frame.largest_observed - packet_number; |
| 2077 | 2071 |
| 2078 if (delta_from_largest_observed > numeric_limits<uint8>::max()) { | 2072 if (delta_from_largest_observed > numeric_limits<uint8>::max()) { |
| 2079 return false; | 2073 return false; |
| 2080 } | 2074 } |
| 2081 | 2075 |
| 2082 if (!writer->WriteUInt8( | 2076 if (!writer->WriteUInt8(delta_from_largest_observed & |
| 2083 delta_from_largest_observed & k1ByteSequenceNumberMask)) { | 2077 k1ByteSequenceNumberMask)) { |
| 2084 return false; | 2078 return false; |
| 2085 } | 2079 } |
| 2086 | 2080 |
| 2087 uint64 frame_time_delta_us = | 2081 uint64 frame_time_delta_us = |
| 2088 it->second.Subtract(prev_time).ToMicroseconds(); | 2082 it->second.Subtract(prev_time).ToMicroseconds(); |
| 2089 prev_time = it->second; | 2083 prev_time = it->second; |
| 2090 if (!writer->WriteUFloat16(frame_time_delta_us)) { | 2084 if (!writer->WriteUFloat16(frame_time_delta_us)) { |
| 2091 return false; | 2085 return false; |
| 2092 } | 2086 } |
| 2093 } | 2087 } |
| 2094 return true; | 2088 return true; |
| 2095 } | 2089 } |
| 2096 | 2090 |
| 2097 bool QuicFramer::AppendStopWaitingFrame( | 2091 bool QuicFramer::AppendStopWaitingFrame(const QuicPacketHeader& header, |
| 2098 const QuicPacketHeader& header, | 2092 const QuicStopWaitingFrame& frame, |
| 2099 const QuicStopWaitingFrame& frame, | 2093 QuicDataWriter* writer) { |
| 2100 QuicDataWriter* writer) { | |
| 2101 DCHECK_GE(header.packet_number, frame.least_unacked); | 2094 DCHECK_GE(header.packet_number, frame.least_unacked); |
| 2102 const QuicPacketNumber least_unacked_delta = | 2095 const QuicPacketNumber least_unacked_delta = |
| 2103 header.packet_number - frame.least_unacked; | 2096 header.packet_number - frame.least_unacked; |
| 2104 const QuicPacketNumber length_shift = | 2097 const QuicPacketNumber length_shift = |
| 2105 header.public_header.packet_number_length * 8; | 2098 header.public_header.packet_number_length * 8; |
| 2106 if (!writer->WriteUInt8(frame.entropy_hash)) { | 2099 if (!writer->WriteUInt8(frame.entropy_hash)) { |
| 2107 LOG(DFATAL) << " hash failed"; | 2100 LOG(DFATAL) << " hash failed"; |
| 2108 return false; | 2101 return false; |
| 2109 } | 2102 } |
| 2110 | 2103 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2194 | 2187 |
| 2195 bool QuicFramer::RaiseError(QuicErrorCode error) { | 2188 bool QuicFramer::RaiseError(QuicErrorCode error) { |
| 2196 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) | 2189 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) |
| 2197 << " detail: " << detailed_error_; | 2190 << " detail: " << detailed_error_; |
| 2198 set_error(error); | 2191 set_error(error); |
| 2199 visitor_->OnError(this); | 2192 visitor_->OnError(this); |
| 2200 return false; | 2193 return false; |
| 2201 } | 2194 } |
| 2202 | 2195 |
| 2203 } // namespace net | 2196 } // namespace net |
| OLD | NEW |