| 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/quic_utils.h" | 5 #include "net/quic/quic_utils.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 const uint128 kPrime(16777216, 315); | 45 const uint128 kPrime(16777216, 315); |
| 46 // 144066263297769815596495629667062367629 | 46 // 144066263297769815596495629667062367629 |
| 47 const uint128 kOffset(GG_UINT64_C(7809847782465536322), | 47 const uint128 kOffset(GG_UINT64_C(7809847782465536322), |
| 48 GG_UINT64_C(7113472399480571277)); | 48 GG_UINT64_C(7113472399480571277)); |
| 49 | 49 |
| 50 const uint8* octets = reinterpret_cast<const uint8*>(data); | 50 const uint8* octets = reinterpret_cast<const uint8*>(data); |
| 51 | 51 |
| 52 uint128 hash = kOffset; | 52 uint128 hash = kOffset; |
| 53 | 53 |
| 54 for (int i = 0; i < len; ++i) { | 54 for (int i = 0; i < len; ++i) { |
| 55 hash = hash ^ uint128(0, octets[i]); | 55 hash = hash ^ uint128(0, octets[i]); |
| 56 hash = hash * kPrime; | 56 hash = hash * kPrime; |
| 57 } | 57 } |
| 58 | 58 |
| 59 return hash; | 59 return hash; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // static | 62 // static |
| 63 bool QuicUtils::FindMutualTag(const QuicTagVector& our_tags_vector, | 63 bool QuicUtils::FindMutualTag(const QuicTagVector& our_tags_vector, |
| 64 const QuicTag* their_tags, | 64 const QuicTag* their_tags, |
| 65 size_t num_their_tags, | 65 size_t num_their_tags, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // static | 118 // static |
| 119 void QuicUtils::SerializeUint128Short(uint128 v, uint8* out) { | 119 void QuicUtils::SerializeUint128Short(uint128 v, uint8* out) { |
| 120 const uint64 lo = Uint128Low64(v); | 120 const uint64 lo = Uint128Low64(v); |
| 121 const uint64 hi = Uint128High64(v); | 121 const uint64 hi = Uint128High64(v); |
| 122 // This assumes that the system is little-endian. | 122 // This assumes that the system is little-endian. |
| 123 memcpy(out, &lo, sizeof(lo)); | 123 memcpy(out, &lo, sizeof(lo)); |
| 124 memcpy(out + sizeof(lo), &hi, sizeof(hi) / 2); | 124 memcpy(out + sizeof(lo), &hi, sizeof(hi) / 2); |
| 125 } | 125 } |
| 126 | 126 |
| 127 #define RETURN_STRING_LITERAL(x) \ | 127 #define RETURN_STRING_LITERAL(x) \ |
| 128 case x: \ | 128 case x: \ |
| 129 return #x; | 129 return #x; |
| 130 | 130 |
| 131 // static | 131 // static |
| 132 const char* QuicUtils::StreamErrorToString(QuicRstStreamErrorCode error) { | 132 const char* QuicUtils::StreamErrorToString(QuicRstStreamErrorCode error) { |
| 133 switch (error) { | 133 switch (error) { |
| 134 RETURN_STRING_LITERAL(QUIC_STREAM_NO_ERROR); | 134 RETURN_STRING_LITERAL(QUIC_STREAM_NO_ERROR); |
| 135 RETURN_STRING_LITERAL(QUIC_STREAM_CONNECTION_ERROR); | 135 RETURN_STRING_LITERAL(QUIC_STREAM_CONNECTION_ERROR); |
| 136 RETURN_STRING_LITERAL(QUIC_ERROR_PROCESSING_STREAM); | 136 RETURN_STRING_LITERAL(QUIC_ERROR_PROCESSING_STREAM); |
| 137 RETURN_STRING_LITERAL(QUIC_MULTIPLE_TERMINATION_OFFSETS); | 137 RETURN_STRING_LITERAL(QUIC_MULTIPLE_TERMINATION_OFFSETS); |
| 138 RETURN_STRING_LITERAL(QUIC_BAD_APPLICATION_PAYLOAD); | 138 RETURN_STRING_LITERAL(QUIC_BAD_APPLICATION_PAYLOAD); |
| 139 RETURN_STRING_LITERAL(QUIC_STREAM_PEER_GOING_AWAY); | 139 RETURN_STRING_LITERAL(QUIC_STREAM_PEER_GOING_AWAY); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 if (ascii) { | 266 if (ascii) { |
| 267 return string(chars, sizeof(chars)); | 267 return string(chars, sizeof(chars)); |
| 268 } | 268 } |
| 269 | 269 |
| 270 return base::UintToString(orig_tag); | 270 return base::UintToString(orig_tag); |
| 271 } | 271 } |
| 272 | 272 |
| 273 // static | 273 // static |
| 274 string QuicUtils::StringToHexASCIIDump(StringPiece in_buffer) { | 274 string QuicUtils::StringToHexASCIIDump(StringPiece in_buffer) { |
| 275 int offset = 0; | 275 int offset = 0; |
| 276 const int kBytesPerLine = 16; // Max bytes dumped per line | 276 const int kBytesPerLine = 16; // Max bytes dumped per line |
| 277 const char* buf = in_buffer.data(); | 277 const char* buf = in_buffer.data(); |
| 278 int bytes_remaining = in_buffer.size(); | 278 int bytes_remaining = in_buffer.size(); |
| 279 string s; // our output | 279 string s; // our output |
| 280 const char* p = buf; | 280 const char* p = buf; |
| 281 while (bytes_remaining > 0) { | 281 while (bytes_remaining > 0) { |
| 282 const int line_bytes = std::min(bytes_remaining, kBytesPerLine); | 282 const int line_bytes = std::min(bytes_remaining, kBytesPerLine); |
| 283 base::StringAppendF(&s, "0x%04x: ", offset); // Do the line header | 283 base::StringAppendF(&s, "0x%04x: ", offset); // Do the line header |
| 284 for (int i = 0; i < kBytesPerLine; ++i) { | 284 for (int i = 0; i < kBytesPerLine; ++i) { |
| 285 if (i < line_bytes) { | 285 if (i < line_bytes) { |
| 286 base::StringAppendF(&s, "%02x", static_cast<unsigned char>(p[i])); | 286 base::StringAppendF(&s, "%02x", static_cast<unsigned char>(p[i])); |
| 287 } else { | 287 } else { |
| 288 s += " "; // two-space filler instead of two-space hex digits | 288 s += " "; // two-space filler instead of two-space hex digits |
| 289 } | 289 } |
| 290 if (i % 2) s += ' '; | 290 if (i % 2) |
| 291 s += ' '; |
| 291 } | 292 } |
| 292 s += ' '; | 293 s += ' '; |
| 293 for (int i = 0; i < line_bytes; ++i) { // Do the ASCII dump | 294 for (int i = 0; i < line_bytes; ++i) { // Do the ASCII dump |
| 294 s+= (p[i] > 32 && p[i] < 127) ? p[i] : '.'; | 295 s += (p[i] > 32 && p[i] < 127) ? p[i] : '.'; |
| 295 } | 296 } |
| 296 | 297 |
| 297 bytes_remaining -= line_bytes; | 298 bytes_remaining -= line_bytes; |
| 298 offset += line_bytes; | 299 offset += line_bytes; |
| 299 p += line_bytes; | 300 p += line_bytes; |
| 300 s += '\n'; | 301 s += '\n'; |
| 301 } | 302 } |
| 302 return s; | 303 return s; |
| 303 } | 304 } |
| 304 | 305 |
| 305 // static | 306 // static |
| 306 QuicPriority QuicUtils::LowestPriority() { | 307 QuicPriority QuicUtils::LowestPriority() { |
| 307 return QuicWriteBlockedList::kLowestPriority; | 308 return QuicWriteBlockedList::kLowestPriority; |
| 308 } | 309 } |
| 309 | 310 |
| 310 // static | 311 // static |
| 311 QuicPriority QuicUtils::HighestPriority() { | 312 QuicPriority QuicUtils::HighestPriority() { |
| 312 return QuicWriteBlockedList::kHighestPriority; | 313 return QuicWriteBlockedList::kHighestPriority; |
| 313 } | 314 } |
| 314 | 315 |
| 315 } // namespace net | 316 } // namespace net |
| OLD | NEW |