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_packet_creator.h" | 5 #include "net/quic/core/quic_packet_creator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "net/quic/core/crypto/crypto_protocol.h" | 11 #include "net/quic/core/crypto/crypto_protocol.h" |
12 #include "net/quic/core/crypto/quic_random.h" | 12 #include "net/quic/core/crypto/quic_random.h" |
13 #include "net/quic/core/quic_bug_tracker.h" | 13 #include "net/quic/core/quic_bug_tracker.h" |
14 #include "net/quic/core/quic_data_writer.h" | 14 #include "net/quic/core/quic_data_writer.h" |
15 #include "net/quic/core/quic_flags.h" | 15 #include "net/quic/core/quic_flags.h" |
16 #include "net/quic/core/quic_utils.h" | 16 #include "net/quic/core/quic_utils.h" |
17 | 17 |
18 using base::StringPiece; | 18 using base::StringPiece; |
19 using std::make_pair; | 19 using std::make_pair; |
20 using std::max; | 20 using std::max; |
21 using std::min; | 21 using std::min; |
22 using std::pair; | 22 using std::pair; |
23 using std::string; | 23 using std::string; |
24 using std::vector; | 24 using std::vector; |
25 | 25 |
| 26 // If true, enforce that QUIC CHLOs fit in one packet. |
| 27 bool FLAGS_quic_enforce_single_packet_chlo = true; |
| 28 |
26 namespace net { | 29 namespace net { |
27 | 30 |
28 QuicPacketCreator::QuicPacketCreator(QuicConnectionId connection_id, | 31 QuicPacketCreator::QuicPacketCreator(QuicConnectionId connection_id, |
29 QuicFramer* framer, | 32 QuicFramer* framer, |
30 QuicRandom* random_generator, | 33 QuicRandom* random_generator, |
31 QuicBufferAllocator* buffer_allocator, | 34 QuicBufferAllocator* buffer_allocator, |
32 DelegateInterface* delegate) | 35 DelegateInterface* delegate) |
33 : delegate_(delegate), | 36 : delegate_(delegate), |
34 debug_delegate_(nullptr), | 37 debug_delegate_(nullptr), |
35 framer_(framer), | 38 framer_(framer), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (!HasRoomForStreamFrame(id, offset)) { | 134 if (!HasRoomForStreamFrame(id, offset)) { |
132 return false; | 135 return false; |
133 } | 136 } |
134 CreateStreamFrame(id, iov, iov_offset, offset, fin, frame); | 137 CreateStreamFrame(id, iov, iov_offset, offset, fin, frame); |
135 // Explicitly disallow multi-packet CHLOs. | 138 // Explicitly disallow multi-packet CHLOs. |
136 if (id == kCryptoStreamId && | 139 if (id == kCryptoStreamId && |
137 frame->stream_frame->data_length >= sizeof(kCHLO) && | 140 frame->stream_frame->data_length >= sizeof(kCHLO) && |
138 strncmp(frame->stream_frame->data_buffer, | 141 strncmp(frame->stream_frame->data_buffer, |
139 reinterpret_cast<const char*>(&kCHLO), sizeof(kCHLO)) == 0) { | 142 reinterpret_cast<const char*>(&kCHLO), sizeof(kCHLO)) == 0) { |
140 DCHECK_EQ(static_cast<size_t>(0), iov_offset); | 143 DCHECK_EQ(static_cast<size_t>(0), iov_offset); |
141 if (frame->stream_frame->data_length < iov.iov->iov_len) { | 144 if (FLAGS_quic_enforce_single_packet_chlo && |
| 145 frame->stream_frame->data_length < iov.iov->iov_len) { |
142 const string error_details = "Client hello won't fit in a single packet."; | 146 const string error_details = "Client hello won't fit in a single packet."; |
143 QUIC_BUG << error_details << " Constructed stream frame length: " | 147 QUIC_BUG << error_details << " Constructed stream frame length: " |
144 << frame->stream_frame->data_length | 148 << frame->stream_frame->data_length |
145 << " CHLO length: " << iov.iov->iov_len; | 149 << " CHLO length: " << iov.iov->iov_len; |
146 delegate_->OnUnrecoverableError(QUIC_CRYPTO_CHLO_TOO_LARGE, error_details, | 150 delegate_->OnUnrecoverableError(QUIC_CRYPTO_CHLO_TOO_LARGE, error_details, |
147 ConnectionCloseSource::FROM_SELF); | 151 ConnectionCloseSource::FROM_SELF); |
148 delete frame->stream_frame; | 152 delete frame->stream_frame; |
149 return false; | 153 return false; |
150 } | 154 } |
151 } | 155 } |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 if (bit_mask_ == 0) { | 685 if (bit_mask_ == 0) { |
682 bit_bucket_ = random_->RandUint64(); | 686 bit_bucket_ = random_->RandUint64(); |
683 bit_mask_ = 1; | 687 bit_mask_ = 1; |
684 } | 688 } |
685 bool result = ((bit_bucket_ & bit_mask_) != 0); | 689 bool result = ((bit_bucket_ & bit_mask_) != 0); |
686 bit_mask_ <<= 1; | 690 bit_mask_ <<= 1; |
687 return result; | 691 return result; |
688 } | 692 } |
689 | 693 |
690 } // namespace net | 694 } // namespace net |
OLD | NEW |