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

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

Issue 1160203003: net: Remove the remaining use of GG_(U)INTn_C macros. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stdint.h Created 5 years, 6 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_data_writer_test.cc ('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 <stdint.h>
8
7 #include "base/basictypes.h" 9 #include "base/basictypes.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/stl_util.h" 11 #include "base/stl_util.h"
10 #include "net/quic/crypto/crypto_framer.h" 12 #include "net/quic/crypto/crypto_framer.h"
11 #include "net/quic/crypto/crypto_handshake_message.h" 13 #include "net/quic/crypto/crypto_handshake_message.h"
12 #include "net/quic/crypto/crypto_protocol.h" 14 #include "net/quic/crypto/crypto_protocol.h"
13 #include "net/quic/crypto/quic_decrypter.h" 15 #include "net/quic/crypto/quic_decrypter.h"
14 #include "net/quic/crypto/quic_encrypter.h" 16 #include "net/quic/crypto/quic_encrypter.h"
15 #include "net/quic/quic_data_reader.h" 17 #include "net/quic/quic_data_reader.h"
16 #include "net/quic/quic_data_writer.h" 18 #include "net/quic/quic_data_writer.h"
17 #include "net/quic/quic_flags.h" 19 #include "net/quic/quic_flags.h"
18 #include "net/quic/quic_socket_address_coder.h" 20 #include "net/quic/quic_socket_address_coder.h"
19 #include "net/quic/quic_utils.h" 21 #include "net/quic/quic_utils.h"
20 22
21 using base::StringPiece; 23 using base::StringPiece;
22 using std::map; 24 using std::map;
23 using std::max; 25 using std::max;
24 using std::min; 26 using std::min;
25 using std::numeric_limits; 27 using std::numeric_limits;
26 using std::string; 28 using std::string;
27 29
28 namespace net { 30 namespace net {
29 31
30 namespace { 32 namespace {
31 33
32 // Mask to select the lowest 48 bits of a sequence number. 34 // Mask to select the lowest 48 bits of a sequence number.
33 const QuicPacketSequenceNumber k6ByteSequenceNumberMask = 35 const QuicPacketSequenceNumber k6ByteSequenceNumberMask =
34 GG_UINT64_C(0x0000FFFFFFFFFFFF); 36 UINT64_C(0x0000FFFFFFFFFFFF);
35 const QuicPacketSequenceNumber k4ByteSequenceNumberMask = 37 const QuicPacketSequenceNumber k4ByteSequenceNumberMask =
36 GG_UINT64_C(0x00000000FFFFFFFF); 38 UINT64_C(0x00000000FFFFFFFF);
37 const QuicPacketSequenceNumber k2ByteSequenceNumberMask = 39 const QuicPacketSequenceNumber k2ByteSequenceNumberMask =
38 GG_UINT64_C(0x000000000000FFFF); 40 UINT64_C(0x000000000000FFFF);
39 const QuicPacketSequenceNumber k1ByteSequenceNumberMask = 41 const QuicPacketSequenceNumber k1ByteSequenceNumberMask =
40 GG_UINT64_C(0x00000000000000FF); 42 UINT64_C(0x00000000000000FF);
41 43
42 const QuicConnectionId k1ByteConnectionIdMask = GG_UINT64_C(0x00000000000000FF); 44 const QuicConnectionId k1ByteConnectionIdMask = UINT64_C(0x00000000000000FF);
43 const QuicConnectionId k4ByteConnectionIdMask = GG_UINT64_C(0x00000000FFFFFFFF); 45 const QuicConnectionId k4ByteConnectionIdMask = UINT64_C(0x00000000FFFFFFFF);
44 46
45 // Number of bits the sequence number length bits are shifted from the right 47 // Number of bits the sequence number length bits are shifted from the right
46 // edge of the public header. 48 // edge of the public header.
47 const uint8 kPublicHeaderSequenceNumberShift = 4; 49 const uint8 kPublicHeaderSequenceNumberShift = 4;
48 50
49 // New Frame Types, QUIC v. >= 10: 51 // New Frame Types, QUIC v. >= 10:
50 // There are two interpretations for the Frame Type byte in the QUIC protocol, 52 // There are two interpretations for the Frame Type byte in the QUIC protocol,
51 // resulting in two Frame Types: Special Frame Types and Regular Frame Types. 53 // resulting in two Frame Types: Special Frame Types and Regular Frame Types.
52 // 54 //
53 // Regular Frame Types use the Frame Type byte simply. Currently defined 55 // Regular Frame Types use the Frame Type byte simply. Currently defined
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 805
804 const QuicTime::Delta QuicFramer::CalculateTimestampFromWire( 806 const QuicTime::Delta QuicFramer::CalculateTimestampFromWire(
805 uint32 time_delta_us) { 807 uint32 time_delta_us) {
806 // The new time_delta might have wrapped to the next epoch, or it 808 // The new time_delta might have wrapped to the next epoch, or it
807 // might have reverse wrapped to the previous epoch, or it might 809 // might have reverse wrapped to the previous epoch, or it might
808 // remain in the same epoch. Select the time closest to the previous 810 // remain in the same epoch. Select the time closest to the previous
809 // time. 811 // time.
810 // 812 //
811 // epoch_delta is the delta between epochs. A delta is 4 bytes of 813 // epoch_delta is the delta between epochs. A delta is 4 bytes of
812 // microseconds. 814 // microseconds.
813 const uint64 epoch_delta = GG_UINT64_C(1) << 32; 815 const uint64 epoch_delta = UINT64_C(1) << 32;
814 uint64 epoch = last_timestamp_.ToMicroseconds() & ~(epoch_delta - 1); 816 uint64 epoch = last_timestamp_.ToMicroseconds() & ~(epoch_delta - 1);
815 // Wrapping is safe here because a wrapped value will not be ClosestTo below. 817 // Wrapping is safe here because a wrapped value will not be ClosestTo below.
816 uint64 prev_epoch = epoch - epoch_delta; 818 uint64 prev_epoch = epoch - epoch_delta;
817 uint64 next_epoch = epoch + epoch_delta; 819 uint64 next_epoch = epoch + epoch_delta;
818 820
819 uint64 time = ClosestTo(last_timestamp_.ToMicroseconds(), 821 uint64 time = ClosestTo(last_timestamp_.ToMicroseconds(),
820 epoch + time_delta_us, 822 epoch + time_delta_us,
821 ClosestTo(last_timestamp_.ToMicroseconds(), 823 ClosestTo(last_timestamp_.ToMicroseconds(),
822 prev_epoch + time_delta_us, 824 prev_epoch + time_delta_us,
823 next_epoch + time_delta_us)); 825 next_epoch + time_delta_us));
824 826
825 return QuicTime::Delta::FromMicroseconds(time); 827 return QuicTime::Delta::FromMicroseconds(time);
826 } 828 }
827 829
828 QuicPacketSequenceNumber QuicFramer::CalculatePacketSequenceNumberFromWire( 830 QuicPacketSequenceNumber QuicFramer::CalculatePacketSequenceNumberFromWire(
829 QuicSequenceNumberLength sequence_number_length, 831 QuicSequenceNumberLength sequence_number_length,
830 QuicPacketSequenceNumber packet_sequence_number) const { 832 QuicPacketSequenceNumber packet_sequence_number) const {
831 // The new sequence number might have wrapped to the next epoch, or 833 // The new sequence number might have wrapped to the next epoch, or
832 // it might have reverse wrapped to the previous epoch, or it might 834 // it might have reverse wrapped to the previous epoch, or it might
833 // remain in the same epoch. Select the sequence number closest to the 835 // remain in the same epoch. Select the sequence number closest to the
834 // next expected sequence number, the previous sequence number plus 1. 836 // next expected sequence number, the previous sequence number plus 1.
835 837
836 // epoch_delta is the delta between epochs the sequence number was serialized 838 // epoch_delta is the delta between epochs the sequence number was serialized
837 // with, so the correct value is likely the same epoch as the last sequence 839 // with, so the correct value is likely the same epoch as the last sequence
838 // number or an adjacent epoch. 840 // number or an adjacent epoch.
839 const QuicPacketSequenceNumber epoch_delta = 841 const QuicPacketSequenceNumber epoch_delta =
840 GG_UINT64_C(1) << (8 * sequence_number_length); 842 UINT64_C(1) << (8 * sequence_number_length);
841 QuicPacketSequenceNumber next_sequence_number = last_sequence_number_ + 1; 843 QuicPacketSequenceNumber next_sequence_number = last_sequence_number_ + 1;
842 QuicPacketSequenceNumber epoch = last_sequence_number_ & ~(epoch_delta - 1); 844 QuicPacketSequenceNumber epoch = last_sequence_number_ & ~(epoch_delta - 1);
843 QuicPacketSequenceNumber prev_epoch = epoch - epoch_delta; 845 QuicPacketSequenceNumber prev_epoch = epoch - epoch_delta;
844 QuicPacketSequenceNumber next_epoch = epoch + epoch_delta; 846 QuicPacketSequenceNumber next_epoch = epoch + epoch_delta;
845 847
846 return ClosestTo(next_sequence_number, 848 return ClosestTo(next_sequence_number,
847 epoch + packet_sequence_number, 849 epoch + packet_sequence_number,
848 ClosestTo(next_sequence_number, 850 ClosestTo(next_sequence_number,
849 prev_epoch + packet_sequence_number, 851 prev_epoch + packet_sequence_number,
850 next_epoch + packet_sequence_number)); 852 next_epoch + packet_sequence_number));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 } 950 }
949 951
950 // static 952 // static
951 QuicSequenceNumberLength QuicFramer::GetMinSequenceNumberLength( 953 QuicSequenceNumberLength QuicFramer::GetMinSequenceNumberLength(
952 QuicPacketSequenceNumber sequence_number) { 954 QuicPacketSequenceNumber sequence_number) {
953 if (sequence_number < 1 << (PACKET_1BYTE_SEQUENCE_NUMBER * 8)) { 955 if (sequence_number < 1 << (PACKET_1BYTE_SEQUENCE_NUMBER * 8)) {
954 return PACKET_1BYTE_SEQUENCE_NUMBER; 956 return PACKET_1BYTE_SEQUENCE_NUMBER;
955 } else if (sequence_number < 1 << (PACKET_2BYTE_SEQUENCE_NUMBER * 8)) { 957 } else if (sequence_number < 1 << (PACKET_2BYTE_SEQUENCE_NUMBER * 8)) {
956 return PACKET_2BYTE_SEQUENCE_NUMBER; 958 return PACKET_2BYTE_SEQUENCE_NUMBER;
957 } else if (sequence_number < 959 } else if (sequence_number <
958 GG_UINT64_C(1) << (PACKET_4BYTE_SEQUENCE_NUMBER * 8)) { 960 UINT64_C(1) << (PACKET_4BYTE_SEQUENCE_NUMBER * 8)) {
959 return PACKET_4BYTE_SEQUENCE_NUMBER; 961 return PACKET_4BYTE_SEQUENCE_NUMBER;
960 } else { 962 } else {
961 return PACKET_6BYTE_SEQUENCE_NUMBER; 963 return PACKET_6BYTE_SEQUENCE_NUMBER;
962 } 964 }
963 } 965 }
964 966
965 // static 967 // static
966 uint8 QuicFramer::GetSequenceNumberFlags( 968 uint8 QuicFramer::GetSequenceNumberFlags(
967 QuicSequenceNumberLength sequence_number_length) { 969 QuicSequenceNumberLength sequence_number_length) {
968 switch (sequence_number_length) { 970 switch (sequence_number_length) {
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 if (delta_from_largest_observed > numeric_limits<uint8>::max()) { 2095 if (delta_from_largest_observed > numeric_limits<uint8>::max()) {
2094 return false; 2096 return false;
2095 } 2097 }
2096 2098
2097 if (!writer->WriteUInt8( 2099 if (!writer->WriteUInt8(
2098 delta_from_largest_observed & k1ByteSequenceNumberMask)) { 2100 delta_from_largest_observed & k1ByteSequenceNumberMask)) {
2099 return false; 2101 return false;
2100 } 2102 }
2101 2103
2102 // Use the lowest 4 bytes of the time delta from the creation_time_. 2104 // Use the lowest 4 bytes of the time delta from the creation_time_.
2103 const uint64 time_epoch_delta_us = GG_UINT64_C(1) << 32; 2105 const uint64 time_epoch_delta_us = UINT64_C(1) << 32;
2104 uint32 time_delta_us = 2106 uint32 time_delta_us =
2105 static_cast<uint32>(it->second.Subtract(creation_time_).ToMicroseconds() 2107 static_cast<uint32>(it->second.Subtract(creation_time_).ToMicroseconds()
2106 & (time_epoch_delta_us - 1)); 2108 & (time_epoch_delta_us - 1));
2107 if (!writer->WriteBytes(&time_delta_us, sizeof(time_delta_us))) { 2109 if (!writer->WriteBytes(&time_delta_us, sizeof(time_delta_us))) {
2108 return false; 2110 return false;
2109 } 2111 }
2110 2112
2111 QuicTime prev_time = it->second; 2113 QuicTime prev_time = it->second;
2112 2114
2113 for (++it; it != frame.received_packet_times.end(); ++it) { 2115 for (++it; it != frame.received_packet_times.end(); ++it) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2240 bool QuicFramer::RaiseError(QuicErrorCode error) { 2242 bool QuicFramer::RaiseError(QuicErrorCode error) {
2241 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) 2243 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error)
2242 << " detail: " << detailed_error_; 2244 << " detail: " << detailed_error_;
2243 set_error(error); 2245 set_error(error);
2244 visitor_->OnError(this); 2246 visitor_->OnError(this);
2245 reader_.reset(nullptr); 2247 reader_.reset(nullptr);
2246 return false; 2248 return false;
2247 } 2249 }
2248 2250
2249 } // namespace net 2251 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_data_writer_test.cc ('k') | net/quic/quic_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698