Add QUIC_BUG_IF to QuicUtils::GetCryptoStreamId
In QUIC versions that use CRYPTO frames (instead of stream 1 frames) for
the crypto handshake, the concept of a "crypto stream ID" makes no
sense, so QuicUtils::GetCryptoStreamId should hit a QUIC_BUG_IF to
prevent its misuse.
gfe-relnote: Add QUIC_BUG_IF protected behind QuicVersionUsesCryptoFrames
PiperOrigin-RevId: 248463613
Change-Id: If6768658e9ffc058778b53a91f95839826602fbf
diff --git a/quic/core/quic_utils.cc b/quic/core/quic_utils.cc
index 85ce4f2..dc40122 100644
--- a/quic/core/quic_utils.cc
+++ b/quic/core/quic_utils.cc
@@ -383,9 +383,18 @@
// static
QuicStreamId QuicUtils::GetCryptoStreamId(QuicTransportVersion version) {
- // TODO(nharper): Change this to return GetInvalidStreamId for version 47 or
- // greater. Currently, too many things break with that change.
- return version == QUIC_VERSION_99 ? 0 : 1;
+ QUIC_BUG_IF(QuicVersionUsesCryptoFrames(version))
+ << "CRYPTO data aren't in stream frames; they have no stream ID.";
+ return QuicVersionUsesCryptoFrames(version) ? GetInvalidStreamId(version) : 1;
+}
+
+// static
+bool QuicUtils::IsCryptoStreamId(QuicTransportVersion version,
+ QuicStreamId stream_id) {
+ if (QuicVersionUsesCryptoFrames(version)) {
+ return false;
+ }
+ return stream_id == GetCryptoStreamId(version);
}
// static
@@ -453,6 +462,7 @@
QuicTransportVersion version,
Perspective perspective) {
if (perspective == Perspective::IS_CLIENT) {
+ // TODO(nharper): Return 0 instead of 4 when CRYPTO frames are used.
return version == QUIC_VERSION_99 ? 4 : 3;
}
return version == QUIC_VERSION_99 ? 1 : 2;