#include "quiche/quic/core/quic_packet_creator.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "absl/base/macros.h"
#include "absl/base/optimization.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include "quiche/quic/core/crypto/crypto_protocol.h"
#include "quiche/quic/core/frames/quic_frame.h"
#include "quiche/quic/core/frames/quic_padding_frame.h"
#include "quiche/quic/core/frames/quic_path_challenge_frame.h"
#include "quiche/quic/core/frames/quic_stream_frame.h"
#include "quiche/quic/core/quic_chaos_protector.h"
#include "quiche/quic/core/quic_connection_id.h"
#include "quiche/quic/core/quic_constants.h"
#include "quiche/quic/core/quic_data_writer.h"
#include "quiche/quic/core/quic_error_codes.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/core/quic_versions.h"
#include "quiche/quic/platform/api/quic_bug_tracker.h"
#include "quiche/quic/platform/api/quic_exported_stats.h"
#include "quiche/quic/platform/api/quic_flag_utils.h"
#include "quiche/quic/platform/api/quic_flags.h"
#include "quiche/quic/platform/api/quic_logging.h"
#include "quiche/quic/platform/api/quic_server_stats.h"
#include "quiche/common/print_elements.h"
namespace quic {
namespace {
QuicLongHeaderType EncryptionlevelToLongHeaderType(EncryptionLevel level) { … }
void LogCoalesceStreamFrameStatus(bool success) { … }
class ScopedPacketContextSwitcher { … };
}
#define ENDPOINT …
QuicPacketCreator::QuicPacketCreator(QuicConnectionId server_connection_id,
QuicFramer* framer,
DelegateInterface* delegate)
: … { … }
QuicPacketCreator::QuicPacketCreator(QuicConnectionId server_connection_id,
QuicFramer* framer, QuicRandom* random,
DelegateInterface* delegate)
: … { … }
QuicPacketCreator::~QuicPacketCreator() { … }
void QuicPacketCreator::SetEncrypter(EncryptionLevel level,
std::unique_ptr<QuicEncrypter> encrypter) { … }
bool QuicPacketCreator::CanSetMaxPacketLength() const { … }
void QuicPacketCreator::SetMaxPacketLength(QuicByteCount length) { … }
void QuicPacketCreator::SetMaxDatagramFrameSize(
QuicByteCount max_datagram_frame_size) { … }
void QuicPacketCreator::SetSoftMaxPacketLength(QuicByteCount length) { … }
void QuicPacketCreator::SetDiversificationNonce(
const DiversificationNonce& nonce) { … }
void QuicPacketCreator::UpdatePacketNumberLength(
QuicPacketNumber least_packet_awaited_by_peer,
QuicPacketCount max_packets_in_flight) { … }
void QuicPacketCreator::SkipNPacketNumbers(
QuicPacketCount count, QuicPacketNumber least_packet_awaited_by_peer,
QuicPacketCount max_packets_in_flight) { … }
bool QuicPacketCreator::ConsumeCryptoDataToFillCurrentPacket(
EncryptionLevel level, size_t write_length, QuicStreamOffset offset,
bool needs_full_padding, TransmissionType transmission_type,
QuicFrame* frame) { … }
bool QuicPacketCreator::ConsumeDataToFillCurrentPacket(
QuicStreamId id, size_t data_size, QuicStreamOffset offset, bool fin,
bool needs_full_padding, TransmissionType transmission_type,
QuicFrame* frame) { … }
bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id,
QuicStreamOffset offset,
size_t data_size) { … }
bool QuicPacketCreator::HasRoomForMessageFrame(QuicByteCount length) { … }
size_t QuicPacketCreator::StreamFramePacketOverhead(
QuicTransportVersion version, uint8_t destination_connection_id_length,
uint8_t source_connection_id_length, bool include_version,
bool include_diversification_nonce,
QuicPacketNumberLength packet_number_length,
quiche::QuicheVariableLengthIntegerLength retry_token_length_length,
quiche::QuicheVariableLengthIntegerLength length_length,
QuicStreamOffset offset) { … }
void QuicPacketCreator::CreateStreamFrame(QuicStreamId id, size_t data_size,
QuicStreamOffset offset, bool fin,
QuicFrame* frame) { … }
bool QuicPacketCreator::CreateCryptoFrame(EncryptionLevel level,
size_t write_length,
QuicStreamOffset offset,
QuicFrame* frame) { … }
void QuicPacketCreator::FlushCurrentPacket() { … }
void QuicPacketCreator::OnSerializedPacket() { … }
void QuicPacketCreator::ClearPacket() { … }
size_t QuicPacketCreator::ReserializeInitialPacketInCoalescedPacket(
const SerializedPacket& packet, size_t padding_size, char* buffer,
size_t buffer_len) { … }
void QuicPacketCreator::CreateAndSerializeStreamFrame(
QuicStreamId id, size_t write_length, QuicStreamOffset iov_offset,
QuicStreamOffset stream_offset, bool fin,
TransmissionType transmission_type, size_t* num_bytes_consumed) { … }
bool QuicPacketCreator::HasPendingFrames() const { … }
std::string QuicPacketCreator::GetPendingFramesInfo() const { … }
bool QuicPacketCreator::HasPendingRetransmittableFrames() const { … }
bool QuicPacketCreator::HasPendingStreamFramesOfStream(QuicStreamId id) const { … }
size_t QuicPacketCreator::ExpansionOnNewFrame() const { … }
size_t QuicPacketCreator::ExpansionOnNewFrameWithLastFrame(
const QuicFrame& last_frame, QuicTransportVersion version) { … }
size_t QuicPacketCreator::BytesFree() const { … }
size_t QuicPacketCreator::BytesFreeForPadding() const { … }
size_t QuicPacketCreator::PacketSize() const { … }
bool QuicPacketCreator::AddPaddedSavedFrame(
const QuicFrame& frame, TransmissionType transmission_type) { … }
std::optional<size_t>
QuicPacketCreator::MaybeBuildDataPacketWithChaosProtection(
const QuicPacketHeader& header, char* buffer) { … }
bool QuicPacketCreator::SerializePacket(QuicOwnedPacketBuffer encrypted_buffer,
size_t encrypted_buffer_len,
bool allow_padding) { … }
std::unique_ptr<SerializedPacket>
QuicPacketCreator::SerializeConnectivityProbingPacket() { … }
std::unique_ptr<SerializedPacket>
QuicPacketCreator::SerializePathChallengeConnectivityProbingPacket(
const QuicPathFrameBuffer& payload) { … }
std::unique_ptr<SerializedPacket>
QuicPacketCreator::SerializePathResponseConnectivityProbingPacket(
const quiche::QuicheCircularDeque<QuicPathFrameBuffer>& payloads,
const bool is_padded) { … }
std::unique_ptr<SerializedPacket>
QuicPacketCreator::SerializeLargePacketNumberConnectionClosePacket(
QuicPacketNumber largest_acked_packet, QuicErrorCode error,
const std::string& error_details) { … }
size_t QuicPacketCreator::BuildPaddedPathChallengePacket(
const QuicPacketHeader& header, char* buffer, size_t packet_length,
const QuicPathFrameBuffer& payload, EncryptionLevel level) { … }
size_t QuicPacketCreator::BuildPathResponsePacket(
const QuicPacketHeader& header, char* buffer, size_t packet_length,
const quiche::QuicheCircularDeque<QuicPathFrameBuffer>& payloads,
const bool is_padded, EncryptionLevel level) { … }
size_t QuicPacketCreator::BuildConnectivityProbingPacket(
const QuicPacketHeader& header, char* buffer, size_t packet_length,
EncryptionLevel level) { … }
size_t QuicPacketCreator::SerializeCoalescedPacket(
const QuicCoalescedPacket& coalesced, char* buffer, size_t buffer_len) { … }
SerializedPacket QuicPacketCreator::NoPacket() { … }
QuicConnectionId QuicPacketCreator::GetDestinationConnectionId() const { … }
QuicConnectionId QuicPacketCreator::GetSourceConnectionId() const { … }
QuicConnectionIdIncluded QuicPacketCreator::GetDestinationConnectionIdIncluded()
const { … }
QuicConnectionIdIncluded QuicPacketCreator::GetSourceConnectionIdIncluded()
const { … }
uint8_t QuicPacketCreator::GetDestinationConnectionIdLength() const { … }
uint8_t QuicPacketCreator::GetSourceConnectionIdLength() const { … }
QuicPacketNumberLength QuicPacketCreator::GetPacketNumberLength() const { … }
size_t QuicPacketCreator::PacketHeaderSize() const { … }
quiche::QuicheVariableLengthIntegerLength
QuicPacketCreator::GetRetryTokenLengthLength() const { … }
absl::string_view QuicPacketCreator::GetRetryToken() const { … }
void QuicPacketCreator::SetRetryToken(absl::string_view retry_token) { … }
bool QuicPacketCreator::ConsumeRetransmittableControlFrame(
const QuicFrame& frame) { … }
void QuicPacketCreator::MaybeBundleOpportunistically() { … }
QuicConsumedData QuicPacketCreator::ConsumeData(QuicStreamId id,
size_t write_length,
QuicStreamOffset offset,
StreamSendingState state) { … }
QuicConsumedData QuicPacketCreator::ConsumeDataFastPath(
QuicStreamId id, size_t write_length, QuicStreamOffset offset, bool fin,
size_t total_bytes_consumed) { … }
size_t QuicPacketCreator::ConsumeCryptoData(EncryptionLevel level,
size_t write_length,
QuicStreamOffset offset) { … }
void QuicPacketCreator::GenerateMtuDiscoveryPacket(QuicByteCount target_mtu) { … }
bool QuicPacketCreator::FlushAckFrame(const QuicFrames& frames) { … }
void QuicPacketCreator::AddRandomPadding() { … }
void QuicPacketCreator::AttachPacketFlusher() { … }
void QuicPacketCreator::Flush() { … }
void QuicPacketCreator::SendRemainingPendingPadding() { … }
void QuicPacketCreator::SetServerConnectionIdLength(uint32_t length) { … }
void QuicPacketCreator::SetTransmissionType(TransmissionType type) { … }
MessageStatus QuicPacketCreator::AddMessageFrame(
QuicMessageId message_id, absl::Span<quiche::QuicheMemSlice> message) { … }
quiche::QuicheVariableLengthIntegerLength QuicPacketCreator::GetLengthLength()
const { … }
void QuicPacketCreator::FillPacketHeader(QuicPacketHeader* header) { … }
size_t QuicPacketCreator::GetSerializedFrameLength(const QuicFrame& frame) { … }
bool QuicPacketCreator::AddFrame(const QuicFrame& frame,
TransmissionType transmission_type) { … }
void QuicPacketCreator::MaybeAddExtraPaddingForHeaderProtection() { … }
bool QuicPacketCreator::MaybeCoalesceStreamFrame(const QuicStreamFrame& frame) { … }
bool QuicPacketCreator::RemoveSoftMaxPacketLength() { … }
void QuicPacketCreator::MaybeAddPadding() { … }
bool QuicPacketCreator::IncludeNonceInPublicHeader() const { … }
bool QuicPacketCreator::IncludeVersionInHeader() const { … }
void QuicPacketCreator::AddPendingPadding(QuicByteCount size) { … }
bool QuicPacketCreator::StreamFrameIsClientHello(
const QuicStreamFrame& frame) const { … }
void QuicPacketCreator::SetServerConnectionIdIncluded(
QuicConnectionIdIncluded server_connection_id_included) { … }
void QuicPacketCreator::SetServerConnectionId(
QuicConnectionId server_connection_id) { … }
void QuicPacketCreator::SetClientConnectionId(
QuicConnectionId client_connection_id) { … }
QuicPacketLength QuicPacketCreator::GetCurrentLargestMessagePayload() const { … }
QuicPacketLength QuicPacketCreator::GetGuaranteedLargestMessagePayload() const { … }
bool QuicPacketCreator::AttemptingToSendUnencryptedStreamData() { … }
bool QuicPacketCreator::HasIetfLongHeader() const { … }
size_t QuicPacketCreator::MinPlaintextPacketSize(
const ParsedQuicVersion& version,
QuicPacketNumberLength packet_number_length) { … }
QuicPacketNumber QuicPacketCreator::NextSendingPacketNumber() const { … }
bool QuicPacketCreator::PacketFlusherAttached() const { … }
bool QuicPacketCreator::HasSoftMaxPacketLength() const { … }
void QuicPacketCreator::SetDefaultPeerAddress(QuicSocketAddress address) { … }
#define ENDPOINT2 …
QuicPacketCreator::ScopedPeerAddressContext::ScopedPeerAddressContext(
QuicPacketCreator* creator, QuicSocketAddress address,
const QuicConnectionId& client_connection_id,
const QuicConnectionId& server_connection_id)
: … { … }
QuicPacketCreator::ScopedPeerAddressContext::~ScopedPeerAddressContext() { … }
QuicPacketCreator::ScopedSerializationFailureHandler::
ScopedSerializationFailureHandler(QuicPacketCreator* creator)
: … { … }
QuicPacketCreator::ScopedSerializationFailureHandler::
~ScopedSerializationFailureHandler() { … }
#undef ENDPOINT2
void QuicPacketCreator::set_encryption_level(EncryptionLevel level) { … }
void QuicPacketCreator::AddPathChallengeFrame(
const QuicPathFrameBuffer& payload) { … }
bool QuicPacketCreator::AddPathResponseFrame(
const QuicPathFrameBuffer& data_buffer) { … }
bool QuicPacketCreator::AddPaddedFrameWithRetry(const QuicFrame& frame) { … }
bool QuicPacketCreator::HasRetryToken() const { … }
#undef ENDPOINT
}