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