| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/core/quic_versions.h" | 5 #include "net/quic/core/quic_versions.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "net/quic/core/quic_flags.h" | 9 #include "net/quic/core/quic_flags.h" |
| 10 #include "net/quic/core/quic_types.h" | 10 #include "net/quic/core/quic_types.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } | 27 } |
| 28 | 28 |
| 29 QuicVersionVector CurrentSupportedVersions() { | 29 QuicVersionVector CurrentSupportedVersions() { |
| 30 return FilterSupportedVersions(AllSupportedVersions()); | 30 return FilterSupportedVersions(AllSupportedVersions()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 QuicVersionVector FilterSupportedVersions(QuicVersionVector versions) { | 33 QuicVersionVector FilterSupportedVersions(QuicVersionVector versions) { |
| 34 QuicVersionVector filtered_versions(versions.size()); | 34 QuicVersionVector filtered_versions(versions.size()); |
| 35 filtered_versions.clear(); // Guaranteed by spec not to change capacity. | 35 filtered_versions.clear(); // Guaranteed by spec not to change capacity. |
| 36 for (QuicVersion version : versions) { | 36 for (QuicVersion version : versions) { |
| 37 if (version < QUIC_VERSION_34) { | 37 if (version == QUIC_VERSION_35) { |
| 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) { | 38 if (FLAGS_quic_enable_version_35) { |
| 43 filtered_versions.push_back(version); | 39 filtered_versions.push_back(version); |
| 44 } | 40 } |
| 45 } else if (version == QUIC_VERSION_36) { | 41 } else if (version == QUIC_VERSION_36) { |
| 46 if (FLAGS_quic_enable_version_35 && FLAGS_quic_enable_version_36_v2) { | 42 if (FLAGS_quic_enable_version_35 && FLAGS_quic_enable_version_36_v2) { |
| 47 filtered_versions.push_back(version); | 43 filtered_versions.push_back(version); |
| 48 } | 44 } |
| 49 } else { | 45 } else { |
| 50 filtered_versions.push_back(version); | 46 filtered_versions.push_back(version); |
| 51 } | 47 } |
| 52 } | 48 } |
| 53 return filtered_versions; | 49 return filtered_versions; |
| 54 } | 50 } |
| 55 | 51 |
| 56 QuicVersionVector VersionOfIndex(const QuicVersionVector& versions, int index) { | 52 QuicVersionVector VersionOfIndex(const QuicVersionVector& versions, int index) { |
| 57 QuicVersionVector version; | 53 QuicVersionVector version; |
| 58 int version_count = versions.size(); | 54 int version_count = versions.size(); |
| 59 if (index >= 0 && index < version_count) { | 55 if (index >= 0 && index < version_count) { |
| 60 version.push_back(versions[index]); | 56 version.push_back(versions[index]); |
| 61 } else { | 57 } else { |
| 62 version.push_back(QUIC_VERSION_UNSUPPORTED); | 58 version.push_back(QUIC_VERSION_UNSUPPORTED); |
| 63 } | 59 } |
| 64 return version; | 60 return version; |
| 65 } | 61 } |
| 66 | 62 |
| 67 QuicTag QuicVersionToQuicTag(const QuicVersion version) { | 63 QuicTag QuicVersionToQuicTag(const QuicVersion version) { |
| 68 switch (version) { | 64 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: | 65 case QUIC_VERSION_34: |
| 74 return MakeQuicTag('Q', '0', '3', '4'); | 66 return MakeQuicTag('Q', '0', '3', '4'); |
| 75 case QUIC_VERSION_35: | 67 case QUIC_VERSION_35: |
| 76 return MakeQuicTag('Q', '0', '3', '5'); | 68 return MakeQuicTag('Q', '0', '3', '5'); |
| 77 case QUIC_VERSION_36: | 69 case QUIC_VERSION_36: |
| 78 return MakeQuicTag('Q', '0', '3', '6'); | 70 return MakeQuicTag('Q', '0', '3', '6'); |
| 79 default: | 71 default: |
| 80 // This shold be an ERROR because we should never attempt to convert an | 72 // This shold be an ERROR because we should never attempt to convert an |
| 81 // invalid QuicVersion to be written to the wire. | 73 // invalid QuicVersion to be written to the wire. |
| 82 LOG(ERROR) << "Unsupported QuicVersion: " << version; | 74 LOG(ERROR) << "Unsupported QuicVersion: " << version; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 << QuicUtils::TagToString(version_tag); | 87 << QuicUtils::TagToString(version_tag); |
| 96 return QUIC_VERSION_UNSUPPORTED; | 88 return QUIC_VERSION_UNSUPPORTED; |
| 97 } | 89 } |
| 98 | 90 |
| 99 #define RETURN_STRING_LITERAL(x) \ | 91 #define RETURN_STRING_LITERAL(x) \ |
| 100 case x: \ | 92 case x: \ |
| 101 return #x | 93 return #x |
| 102 | 94 |
| 103 string QuicVersionToString(const QuicVersion version) { | 95 string QuicVersionToString(const QuicVersion version) { |
| 104 switch (version) { | 96 switch (version) { |
| 105 RETURN_STRING_LITERAL(QUIC_VERSION_32); | |
| 106 RETURN_STRING_LITERAL(QUIC_VERSION_33); | |
| 107 RETURN_STRING_LITERAL(QUIC_VERSION_34); | 97 RETURN_STRING_LITERAL(QUIC_VERSION_34); |
| 108 RETURN_STRING_LITERAL(QUIC_VERSION_35); | 98 RETURN_STRING_LITERAL(QUIC_VERSION_35); |
| 109 RETURN_STRING_LITERAL(QUIC_VERSION_36); | 99 RETURN_STRING_LITERAL(QUIC_VERSION_36); |
| 110 default: | 100 default: |
| 111 return "QUIC_VERSION_UNSUPPORTED"; | 101 return "QUIC_VERSION_UNSUPPORTED"; |
| 112 } | 102 } |
| 113 } | 103 } |
| 114 | 104 |
| 115 string QuicVersionVectorToString(const QuicVersionVector& versions) { | 105 string QuicVersionVectorToString(const QuicVersionVector& versions) { |
| 116 string result = ""; | 106 string result = ""; |
| 117 for (size_t i = 0; i < versions.size(); ++i) { | 107 for (size_t i = 0; i < versions.size(); ++i) { |
| 118 if (i != 0) { | 108 if (i != 0) { |
| 119 result.append(","); | 109 result.append(","); |
| 120 } | 110 } |
| 121 result.append(QuicVersionToString(versions[i])); | 111 result.append(QuicVersionToString(versions[i])); |
| 122 } | 112 } |
| 123 return result; | 113 return result; |
| 124 } | 114 } |
| 125 | 115 |
| 126 } // namespace net | 116 } // namespace net |
| OLD | NEW |