Change Application and Transport ConnectionClose codes to uint64_t
IETF QUIC Transport and Application ConnectionClose Error Codes were 16 bit
unsigned numbers. Draft 22 of the IETF QUIC specification changed them to be a
varint62, which we keep internally as a uint64_t. This CL effects that change.
The benefits of this CL are A) somewhat cleaner internal code (elimination of random casts) and B) applications can use the full 62 bits of the connection close codes when using IETF QUIC.
gfe-relnote: N/A IETF QUIC only, V99 flag protected.
PiperOrigin-RevId: 267594523
Change-Id: I0d6a8af0bb134c15d6b034de4237a02e0458ee47
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index 9890f36..3a1be5e 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -524,17 +524,14 @@
const size_t truncated_error_string_size = TruncatedErrorStringSize(
GenerateErrorString(frame.error_details, frame.extracted_error_code));
- uint64_t close_code = 0;
- if (frame.close_type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE) {
- close_code = static_cast<uint64_t>(frame.transport_error_code);
- } else if (frame.close_type == IETF_QUIC_APPLICATION_CONNECTION_CLOSE) {
- close_code = static_cast<uint64_t>(frame.application_error_code);
- }
-
const size_t frame_size =
truncated_error_string_size +
QuicDataWriter::GetVarInt62Len(truncated_error_string_size) +
- kQuicFrameTypeSize + QuicDataWriter::GetVarInt62Len(close_code);
+ kQuicFrameTypeSize +
+ QuicDataWriter::GetVarInt62Len(
+ (frame.close_type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE)
+ ? frame.transport_error_code
+ : frame.application_error_code);
if (frame.close_type == IETF_QUIC_APPLICATION_CONNECTION_CLOSE) {
return frame_size;
}
@@ -5695,14 +5692,10 @@
return false;
}
- uint64_t close_code = 0;
- if (frame.close_type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE) {
- close_code = static_cast<uint64_t>(frame.transport_error_code);
- } else if (frame.close_type == IETF_QUIC_APPLICATION_CONNECTION_CLOSE) {
- close_code = static_cast<uint64_t>(frame.application_error_code);
- }
-
- if (!writer->WriteVarInt62(close_code)) {
+ if (!writer->WriteVarInt62(
+ (frame.close_type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE)
+ ? frame.transport_error_code
+ : frame.application_error_code)) {
set_detailed_error("Can not write connection close frame error code");
return false;
}
@@ -5734,32 +5727,18 @@
QuicConnectionCloseType type,
QuicConnectionCloseFrame* frame) {
frame->close_type = type;
- uint64_t error_code;
+ uint64_t error_code;
if (!reader->ReadVarInt62(&error_code)) {
set_detailed_error("Unable to read connection close error code.");
return false;
}
- // TODO(fkastenholz): When error codes uniformly go to uint64, remove the
- // range check.
if (frame->close_type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE) {
- if (error_code > 0xffff) {
- frame->transport_error_code =
- static_cast<QuicIetfTransportErrorCodes>(0xffff);
- QUIC_DLOG(ERROR) << "Transport error code " << error_code << " > 0xffff";
- } else {
- frame->transport_error_code =
- static_cast<QuicIetfTransportErrorCodes>(error_code);
- }
+ frame->transport_error_code =
+ static_cast<QuicIetfTransportErrorCodes>(error_code);
} else if (frame->close_type == IETF_QUIC_APPLICATION_CONNECTION_CLOSE) {
- if (error_code > 0xffff) {
- frame->application_error_code = 0xffff;
- QUIC_DLOG(ERROR) << "Application error code " << error_code
- << " > 0xffff";
- } else {
- frame->application_error_code = static_cast<uint16_t>(error_code);
- }
+ frame->application_error_code = error_code;
}
if (type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE) {