Refactor some QUIC version code

Our VersionSupportsFeatureFoo functions currently take multiple forms (QuicUtils::VersionSupportsFeatureFoo(), VersionHasFeatureFoo(QuicTransportVersion) and ParsedQuicVersion::HasFeatureFoo()). This CL starts consolidating these on ParsedQuicVersion in an effort to clean this up.

This CL also adds a few DCHECKs to validate the assumption that we only use valid versions outside of the early parsing code in the dispatcher.

Note that VersionAllowsVariableLengthConnectionIds now only allows known versions so callers that deal with unknown versions need to check ParsedQuicVersion::IsKnown before calling VersionAllowsVariableLengthConnectionIds.

gfe-relnote: refactor, no behavior change, not flag-protected
PiperOrigin-RevId: 289536281
Change-Id: Iafa1ab9c228d9a8fe0ab4c998437526a1b7191dd
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index 11d3aa6..8c2f86a 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -423,7 +423,7 @@
       current_received_frame_type_(0) {
   DCHECK(!supported_versions.empty());
   version_ = supported_versions_[0];
-  DCHECK(version_.transport_version != QUIC_VERSION_UNSUPPORTED ||
+  DCHECK(version_.IsKnown() ||
          !GetQuicRestartFlag(quic_fix_handling_of_bad_prox_packet))
       << ParsedQuicVersionVectorToString(supported_versions_);
 }
@@ -2528,10 +2528,7 @@
   if (!should_update_expected_server_connection_id_length &&
       (dcil != *destination_connection_id_length ||
        scil != *source_connection_id_length) &&
-      !QuicUtils::VariableLengthConnectionIdAllowedForVersion(
-          version.transport_version)) {
-    // TODO(dschinazi): use the framer's version once the
-    // OnProtocolVersionMismatch call is moved to before this is run.
+      version.IsKnown() && !version.AllowsVariableLengthConnectionIds()) {
     QUIC_DVLOG(1) << "dcil: " << static_cast<uint32_t>(dcil)
                   << ", scil: " << static_cast<uint32_t>(scil);
     *detailed_error = "Invalid ConnectionId length.";
@@ -2626,7 +2623,7 @@
       }
       return true;
     }
-    if (!header->version.HasHeaderProtection()) {
+    if (header->version.IsKnown() && !header->version.HasHeaderProtection()) {
       header->packet_number_length =
           GetLongHeaderPacketNumberLength(header->type_byte);
     }