| 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 #include <cstdint> | 8 #include <cstdint> |
| 9 | 9 |
| 10 #include "base/logging.h" | |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 12 #include "net/quic/core/crypto/crypto_protocol.h" | 11 #include "net/quic/core/crypto/crypto_protocol.h" |
| 13 #include "net/quic/core/quic_data_writer.h" | 12 #include "net/quic/core/quic_data_writer.h" |
| 14 #include "net/quic/core/quic_flags.h" | 13 #include "net/quic/core/quic_flags.h" |
| 15 #include "net/quic/core/quic_utils.h" | 14 #include "net/quic/core/quic_utils.h" |
| 16 #include "net/quic/platform/api/quic_aligned.h" | 15 #include "net/quic/platform/api/quic_aligned.h" |
| 17 #include "net/quic/platform/api/quic_bug_tracker.h" | 16 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 17 #include "net/quic/platform/api/quic_logging.h" |
| 18 | 18 |
| 19 using base::StringPiece; | 19 using base::StringPiece; |
| 20 using std::string; | 20 using std::string; |
| 21 | 21 |
| 22 // If true, enforce that QUIC CHLOs fit in one packet. | 22 // If true, enforce that QUIC CHLOs fit in one packet. |
| 23 bool FLAGS_quic_enforce_single_packet_chlo = true; | 23 bool FLAGS_quic_enforce_single_packet_chlo = true; |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 QuicPacketCreator::QuicPacketCreator(QuicConnectionId connection_id, | 27 QuicPacketCreator::QuicPacketCreator(QuicConnectionId connection_id, |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 max_plaintext_size_ - writer.length() - min_frame_size; | 376 max_plaintext_size_ - writer.length() - min_frame_size; |
| 377 const size_t bytes_consumed = | 377 const size_t bytes_consumed = |
| 378 std::min<size_t>(available_size, remaining_data_size); | 378 std::min<size_t>(available_size, remaining_data_size); |
| 379 | 379 |
| 380 const bool set_fin = fin && (bytes_consumed == remaining_data_size); | 380 const bool set_fin = fin && (bytes_consumed == remaining_data_size); |
| 381 UniqueStreamBuffer stream_buffer = | 381 UniqueStreamBuffer stream_buffer = |
| 382 NewStreamBuffer(buffer_allocator_, bytes_consumed); | 382 NewStreamBuffer(buffer_allocator_, bytes_consumed); |
| 383 CopyToBuffer(iov, iov_offset, bytes_consumed, stream_buffer.get()); | 383 CopyToBuffer(iov, iov_offset, bytes_consumed, stream_buffer.get()); |
| 384 std::unique_ptr<QuicStreamFrame> frame(new QuicStreamFrame( | 384 std::unique_ptr<QuicStreamFrame> frame(new QuicStreamFrame( |
| 385 id, set_fin, stream_offset, bytes_consumed, std::move(stream_buffer))); | 385 id, set_fin, stream_offset, bytes_consumed, std::move(stream_buffer))); |
| 386 DVLOG(1) << "Adding frame: " << *frame; | 386 QUIC_DVLOG(1) << "Adding frame: " << *frame; |
| 387 | 387 |
| 388 // TODO(ianswett): AppendTypeByte and AppendStreamFrame could be optimized | 388 // TODO(ianswett): AppendTypeByte and AppendStreamFrame could be optimized |
| 389 // into one method that takes a QuicStreamFrame, if warranted. | 389 // into one method that takes a QuicStreamFrame, if warranted. |
| 390 if (!framer_->AppendTypeByte(QuicFrame(frame.get()), | 390 if (!framer_->AppendTypeByte(QuicFrame(frame.get()), |
| 391 /* no stream frame length */ true, &writer)) { | 391 /* no stream frame length */ true, &writer)) { |
| 392 QUIC_BUG << "AppendTypeByte failed"; | 392 QUIC_BUG << "AppendTypeByte failed"; |
| 393 return; | 393 return; |
| 394 } | 394 } |
| 395 if (!framer_->AppendStreamFrame(*frame, /* no stream frame length */ true, | 395 if (!framer_->AppendStreamFrame(*frame, /* no stream frame length */ true, |
| 396 &writer)) { | 396 &writer)) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 case STOP_WAITING_FRAME: | 560 case STOP_WAITING_FRAME: |
| 561 case MTU_DISCOVERY_FRAME: | 561 case MTU_DISCOVERY_FRAME: |
| 562 return false; | 562 return false; |
| 563 default: | 563 default: |
| 564 return true; | 564 return true; |
| 565 } | 565 } |
| 566 } | 566 } |
| 567 | 567 |
| 568 bool QuicPacketCreator::AddFrame(const QuicFrame& frame, | 568 bool QuicPacketCreator::AddFrame(const QuicFrame& frame, |
| 569 bool save_retransmittable_frames) { | 569 bool save_retransmittable_frames) { |
| 570 DVLOG(1) << "Adding frame: " << frame; | 570 QUIC_DVLOG(1) << "Adding frame: " << frame; |
| 571 if (frame.type == STREAM_FRAME && | 571 if (frame.type == STREAM_FRAME && |
| 572 frame.stream_frame->stream_id != kCryptoStreamId && | 572 frame.stream_frame->stream_id != kCryptoStreamId && |
| 573 packet_.encryption_level == ENCRYPTION_NONE) { | 573 packet_.encryption_level == ENCRYPTION_NONE) { |
| 574 const string error_details = "Cannot send stream data without encryption."; | 574 const string error_details = "Cannot send stream data without encryption."; |
| 575 QUIC_BUG << error_details; | 575 QUIC_BUG << error_details; |
| 576 delegate_->OnUnrecoverableError( | 576 delegate_->OnUnrecoverableError( |
| 577 QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA, error_details, | 577 QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA, error_details, |
| 578 ConnectionCloseSource::FROM_SELF); | 578 ConnectionCloseSource::FROM_SELF); |
| 579 return false; | 579 return false; |
| 580 } | 580 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 // Switching path needs to update packet number length. | 656 // Switching path needs to update packet number length. |
| 657 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); | 657 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); |
| 658 } | 658 } |
| 659 | 659 |
| 660 bool QuicPacketCreator::IncludeNonceInPublicHeader() { | 660 bool QuicPacketCreator::IncludeNonceInPublicHeader() { |
| 661 return have_diversification_nonce_ && | 661 return have_diversification_nonce_ && |
| 662 packet_.encryption_level == ENCRYPTION_INITIAL; | 662 packet_.encryption_level == ENCRYPTION_INITIAL; |
| 663 } | 663 } |
| 664 | 664 |
| 665 } // namespace net | 665 } // namespace net |
| OLD | NEW |