| 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_protocol.h" | 5 #include "net/quic/core/quic_protocol.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_utils.h" | 10 #include "net/quic/core/quic_utils.h" |
| 11 #include "net/quic/core/quic_versions.h" |
| 11 | 12 |
| 12 using base::StringPiece; | 13 using base::StringPiece; |
| 13 using std::map; | 14 using std::map; |
| 14 using std::numeric_limits; | 15 using std::numeric_limits; |
| 15 using std::ostream; | 16 using std::ostream; |
| 16 using std::string; | 17 using std::string; |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 const char* const kFinalOffsetHeaderKey = ":final-offset"; | 21 const char* const kFinalOffsetHeaderKey = ":final-offset"; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 uint32_t MakeQuicTag(char a, char b, char c, char d) { | 163 uint32_t MakeQuicTag(char a, char b, char c, char d) { |
| 163 return static_cast<uint32_t>(a) | static_cast<uint32_t>(b) << 8 | | 164 return static_cast<uint32_t>(a) | static_cast<uint32_t>(b) << 8 | |
| 164 static_cast<uint32_t>(c) << 16 | static_cast<uint32_t>(d) << 24; | 165 static_cast<uint32_t>(c) << 16 | static_cast<uint32_t>(d) << 24; |
| 165 } | 166 } |
| 166 | 167 |
| 167 bool ContainsQuicTag(const QuicTagVector& tag_vector, QuicTag tag) { | 168 bool ContainsQuicTag(const QuicTagVector& tag_vector, QuicTag tag) { |
| 168 return std::find(tag_vector.begin(), tag_vector.end(), tag) != | 169 return std::find(tag_vector.begin(), tag_vector.end(), tag) != |
| 169 tag_vector.end(); | 170 tag_vector.end(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 QuicVersionVector AllSupportedVersions() { | |
| 173 QuicVersionVector supported_versions; | |
| 174 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | |
| 175 supported_versions.push_back(kSupportedQuicVersions[i]); | |
| 176 } | |
| 177 return supported_versions; | |
| 178 } | |
| 179 | |
| 180 QuicVersionVector CurrentSupportedVersions() { | |
| 181 return FilterSupportedVersions(AllSupportedVersions()); | |
| 182 } | |
| 183 | |
| 184 QuicVersionVector FilterSupportedVersions(QuicVersionVector versions) { | |
| 185 QuicVersionVector filtered_versions(versions.size()); | |
| 186 filtered_versions.clear(); // Guaranteed by spec not to change capacity. | |
| 187 for (QuicVersion version : versions) { | |
| 188 if (version < QUIC_VERSION_34) { | |
| 189 if (!FLAGS_quic_disable_pre_34) { | |
| 190 filtered_versions.push_back(version); | |
| 191 } | |
| 192 } else if (version == QUIC_VERSION_35) { | |
| 193 if (FLAGS_quic_enable_version_35) { | |
| 194 filtered_versions.push_back(version); | |
| 195 } | |
| 196 } else if (version == QUIC_VERSION_36) { | |
| 197 if (FLAGS_quic_enable_version_35 && FLAGS_quic_enable_version_36_v2) { | |
| 198 filtered_versions.push_back(version); | |
| 199 } | |
| 200 } else { | |
| 201 filtered_versions.push_back(version); | |
| 202 } | |
| 203 } | |
| 204 return filtered_versions; | |
| 205 } | |
| 206 | |
| 207 QuicVersionVector VersionOfIndex(const QuicVersionVector& versions, int index) { | |
| 208 QuicVersionVector version; | |
| 209 int version_count = versions.size(); | |
| 210 if (index >= 0 && index < version_count) { | |
| 211 version.push_back(versions[index]); | |
| 212 } else { | |
| 213 version.push_back(QUIC_VERSION_UNSUPPORTED); | |
| 214 } | |
| 215 return version; | |
| 216 } | |
| 217 | |
| 218 QuicTag QuicVersionToQuicTag(const QuicVersion version) { | |
| 219 switch (version) { | |
| 220 case QUIC_VERSION_32: | |
| 221 return MakeQuicTag('Q', '0', '3', '2'); | |
| 222 case QUIC_VERSION_33: | |
| 223 return MakeQuicTag('Q', '0', '3', '3'); | |
| 224 case QUIC_VERSION_34: | |
| 225 return MakeQuicTag('Q', '0', '3', '4'); | |
| 226 case QUIC_VERSION_35: | |
| 227 return MakeQuicTag('Q', '0', '3', '5'); | |
| 228 case QUIC_VERSION_36: | |
| 229 return MakeQuicTag('Q', '0', '3', '6'); | |
| 230 default: | |
| 231 // This shold be an ERROR because we should never attempt to convert an | |
| 232 // invalid QuicVersion to be written to the wire. | |
| 233 LOG(ERROR) << "Unsupported QuicVersion: " << version; | |
| 234 return 0; | |
| 235 } | |
| 236 } | |
| 237 | |
| 238 QuicVersion QuicTagToQuicVersion(const QuicTag version_tag) { | |
| 239 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | |
| 240 if (version_tag == QuicVersionToQuicTag(kSupportedQuicVersions[i])) { | |
| 241 return kSupportedQuicVersions[i]; | |
| 242 } | |
| 243 } | |
| 244 // Reading from the client so this should not be considered an ERROR. | |
| 245 DVLOG(1) << "Unsupported QuicTag version: " | |
| 246 << QuicUtils::TagToString(version_tag); | |
| 247 return QUIC_VERSION_UNSUPPORTED; | |
| 248 } | |
| 249 | |
| 250 #define RETURN_STRING_LITERAL(x) \ | |
| 251 case x: \ | |
| 252 return #x | |
| 253 | |
| 254 string QuicVersionToString(const QuicVersion version) { | |
| 255 switch (version) { | |
| 256 RETURN_STRING_LITERAL(QUIC_VERSION_32); | |
| 257 RETURN_STRING_LITERAL(QUIC_VERSION_33); | |
| 258 RETURN_STRING_LITERAL(QUIC_VERSION_34); | |
| 259 RETURN_STRING_LITERAL(QUIC_VERSION_35); | |
| 260 RETURN_STRING_LITERAL(QUIC_VERSION_36); | |
| 261 default: | |
| 262 return "QUIC_VERSION_UNSUPPORTED"; | |
| 263 } | |
| 264 } | |
| 265 | |
| 266 string QuicVersionVectorToString(const QuicVersionVector& versions) { | |
| 267 string result = ""; | |
| 268 for (size_t i = 0; i < versions.size(); ++i) { | |
| 269 if (i != 0) { | |
| 270 result.append(","); | |
| 271 } | |
| 272 result.append(QuicVersionToString(versions[i])); | |
| 273 } | |
| 274 return result; | |
| 275 } | |
| 276 | |
| 277 ostream& operator<<(ostream& os, const Perspective& s) { | 173 ostream& operator<<(ostream& os, const Perspective& s) { |
| 278 if (s == Perspective::IS_SERVER) { | 174 if (s == Perspective::IS_SERVER) { |
| 279 os << "IS_SERVER"; | 175 os << "IS_SERVER"; |
| 280 } else { | 176 } else { |
| 281 os << "IS_CLIENT"; | 177 os << "IS_CLIENT"; |
| 282 } | 178 } |
| 283 return os; | 179 return os; |
| 284 } | 180 } |
| 285 | 181 |
| 286 ostream& operator<<(ostream& os, const QuicPacketHeader& header) { | 182 ostream& operator<<(ostream& os, const QuicPacketHeader& header) { |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 is_unackable(false), | 743 is_unackable(false), |
| 848 has_crypto_handshake(has_crypto_handshake), | 744 has_crypto_handshake(has_crypto_handshake), |
| 849 num_padding_bytes(num_padding_bytes), | 745 num_padding_bytes(num_padding_bytes), |
| 850 retransmission(0) {} | 746 retransmission(0) {} |
| 851 | 747 |
| 852 TransmissionInfo::TransmissionInfo(const TransmissionInfo& other) = default; | 748 TransmissionInfo::TransmissionInfo(const TransmissionInfo& other) = default; |
| 853 | 749 |
| 854 TransmissionInfo::~TransmissionInfo() {} | 750 TransmissionInfo::~TransmissionInfo() {} |
| 855 | 751 |
| 856 } // namespace net | 752 } // namespace net |
| OLD | NEW |