OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/quic/core/quic_versions.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "net/quic/core/quic_flags.h" |
| 10 #include "net/quic/core/quic_types.h" |
| 11 #include "net/quic/core/quic_utils.h" |
| 12 |
| 13 using base::StringPiece; |
| 14 using std::map; |
| 15 using std::numeric_limits; |
| 16 using std::ostream; |
| 17 using std::string; |
| 18 |
| 19 namespace net { |
| 20 |
| 21 QuicVersionVector AllSupportedVersions() { |
| 22 QuicVersionVector supported_versions; |
| 23 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| 24 supported_versions.push_back(kSupportedQuicVersions[i]); |
| 25 } |
| 26 return supported_versions; |
| 27 } |
| 28 |
| 29 QuicVersionVector CurrentSupportedVersions() { |
| 30 return FilterSupportedVersions(AllSupportedVersions()); |
| 31 } |
| 32 |
| 33 QuicVersionVector FilterSupportedVersions(QuicVersionVector versions) { |
| 34 QuicVersionVector filtered_versions(versions.size()); |
| 35 filtered_versions.clear(); // Guaranteed by spec not to change capacity. |
| 36 for (QuicVersion version : versions) { |
| 37 if (version < QUIC_VERSION_34) { |
| 38 if (!FLAGS_quic_disable_pre_34) { |
| 39 filtered_versions.push_back(version); |
| 40 } |
| 41 } else if (version == QUIC_VERSION_35) { |
| 42 if (FLAGS_quic_enable_version_35) { |
| 43 filtered_versions.push_back(version); |
| 44 } |
| 45 } else if (version == QUIC_VERSION_36) { |
| 46 if (FLAGS_quic_enable_version_35 && FLAGS_quic_enable_version_36_v2) { |
| 47 filtered_versions.push_back(version); |
| 48 } |
| 49 } else { |
| 50 filtered_versions.push_back(version); |
| 51 } |
| 52 } |
| 53 return filtered_versions; |
| 54 } |
| 55 |
| 56 QuicVersionVector VersionOfIndex(const QuicVersionVector& versions, int index) { |
| 57 QuicVersionVector version; |
| 58 int version_count = versions.size(); |
| 59 if (index >= 0 && index < version_count) { |
| 60 version.push_back(versions[index]); |
| 61 } else { |
| 62 version.push_back(QUIC_VERSION_UNSUPPORTED); |
| 63 } |
| 64 return version; |
| 65 } |
| 66 |
| 67 QuicTag QuicVersionToQuicTag(const QuicVersion version) { |
| 68 switch (version) { |
| 69 case QUIC_VERSION_32: |
| 70 return MakeQuicTag('Q', '0', '3', '2'); |
| 71 case QUIC_VERSION_33: |
| 72 return MakeQuicTag('Q', '0', '3', '3'); |
| 73 case QUIC_VERSION_34: |
| 74 return MakeQuicTag('Q', '0', '3', '4'); |
| 75 case QUIC_VERSION_35: |
| 76 return MakeQuicTag('Q', '0', '3', '5'); |
| 77 case QUIC_VERSION_36: |
| 78 return MakeQuicTag('Q', '0', '3', '6'); |
| 79 default: |
| 80 // This shold be an ERROR because we should never attempt to convert an |
| 81 // invalid QuicVersion to be written to the wire. |
| 82 LOG(ERROR) << "Unsupported QuicVersion: " << version; |
| 83 return 0; |
| 84 } |
| 85 } |
| 86 |
| 87 QuicVersion QuicTagToQuicVersion(const QuicTag version_tag) { |
| 88 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| 89 if (version_tag == QuicVersionToQuicTag(kSupportedQuicVersions[i])) { |
| 90 return kSupportedQuicVersions[i]; |
| 91 } |
| 92 } |
| 93 // Reading from the client so this should not be considered an ERROR. |
| 94 DVLOG(1) << "Unsupported QuicTag version: " |
| 95 << QuicUtils::TagToString(version_tag); |
| 96 return QUIC_VERSION_UNSUPPORTED; |
| 97 } |
| 98 |
| 99 #define RETURN_STRING_LITERAL(x) \ |
| 100 case x: \ |
| 101 return #x |
| 102 |
| 103 string QuicVersionToString(const QuicVersion version) { |
| 104 switch (version) { |
| 105 RETURN_STRING_LITERAL(QUIC_VERSION_32); |
| 106 RETURN_STRING_LITERAL(QUIC_VERSION_33); |
| 107 RETURN_STRING_LITERAL(QUIC_VERSION_34); |
| 108 RETURN_STRING_LITERAL(QUIC_VERSION_35); |
| 109 RETURN_STRING_LITERAL(QUIC_VERSION_36); |
| 110 default: |
| 111 return "QUIC_VERSION_UNSUPPORTED"; |
| 112 } |
| 113 } |
| 114 |
| 115 string QuicVersionVectorToString(const QuicVersionVector& versions) { |
| 116 string result = ""; |
| 117 for (size_t i = 0; i < versions.size(); ++i) { |
| 118 if (i != 0) { |
| 119 result.append(","); |
| 120 } |
| 121 result.append(QuicVersionToString(versions[i])); |
| 122 } |
| 123 return result; |
| 124 } |
| 125 |
| 126 } // namespace net |
OLD | NEW |