Index: net/quic/quic_utils.cc |
diff --git a/net/quic/quic_utils.cc b/net/quic/quic_utils.cc |
index 228b796ef6e2318ab57dd873917567bbb97e3c7d..a42993cf877add67d0568436e198da1f5530d7b1 100644 |
--- a/net/quic/quic_utils.cc |
+++ b/net/quic/quic_utils.cc |
@@ -4,8 +4,13 @@ |
#include "net/quic/quic_utils.h" |
+#include <ctype.h> |
+ |
#include "base/logging.h" |
#include "base/port.h" |
+#include "base/strings/string_number_conversions.h" |
+ |
+using std::string; |
namespace net { |
@@ -49,6 +54,53 @@ uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { |
} |
// static |
+bool QuicUtils::FindMutualTag(const QuicTagVector& our_tags_vector, |
+ const QuicTag* their_tags, |
+ size_t num_their_tags, |
+ Priority priority, |
+ QuicTag* out_result, |
+ size_t* out_index) { |
+ if (our_tags_vector.empty()) { |
+ return false; |
+ } |
+ const size_t num_our_tags = our_tags_vector.size(); |
+ const QuicTag* our_tags = &our_tags_vector[0]; |
+ |
+ size_t num_priority_tags, num_inferior_tags; |
+ const QuicTag* priority_tags; |
+ const QuicTag* inferior_tags; |
+ if (priority == LOCAL_PRIORITY) { |
+ num_priority_tags = num_our_tags; |
+ priority_tags = our_tags; |
+ num_inferior_tags = num_their_tags; |
+ inferior_tags = their_tags; |
+ } else { |
+ num_priority_tags = num_their_tags; |
+ priority_tags = their_tags; |
+ num_inferior_tags = num_our_tags; |
+ inferior_tags = our_tags; |
+ } |
+ |
+ for (size_t i = 0; i < num_priority_tags; i++) { |
+ for (size_t j = 0; j < num_inferior_tags; j++) { |
+ if (priority_tags[i] == inferior_tags[j]) { |
+ *out_result = priority_tags[i]; |
+ if (out_index) { |
+ if (priority == LOCAL_PRIORITY) { |
+ *out_index = j; |
+ } else { |
+ *out_index = i; |
+ } |
+ } |
+ return true; |
+ } |
+ } |
+ } |
+ |
+ return false; |
+} |
+ |
+// static |
void QuicUtils::SerializeUint128(uint128 v, uint8* out) { |
const uint64 lo = Uint128Low64(v); |
const uint64 hi = Uint128High64(v); |
@@ -100,6 +152,7 @@ const char* QuicUtils::ErrorToString(QuicErrorCode error) { |
RETURN_STRING_LITERAL(QUIC_INVALID_GOAWAY_DATA); |
RETURN_STRING_LITERAL(QUIC_INVALID_ACK_DATA); |
RETURN_STRING_LITERAL(QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
+ RETURN_STRING_LITERAL(QUIC_INVALID_PUBLIC_RST_PACKET); |
RETURN_STRING_LITERAL(QUIC_DECRYPTION_FAILURE); |
RETURN_STRING_LITERAL(QUIC_ENCRYPTION_FAILURE); |
RETURN_STRING_LITERAL(QUIC_PACKET_TOO_LARGE); |
@@ -124,7 +177,11 @@ const char* QuicUtils::ErrorToString(QuicErrorCode error) { |
RETURN_STRING_LITERAL(QUIC_INVALID_VERSION); |
RETURN_STRING_LITERAL(QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED); |
RETURN_STRING_LITERAL(QUIC_INVALID_HEADER_ID); |
+ RETURN_STRING_LITERAL(QUIC_INVALID_NEGOTIATED_VALUE); |
+ RETURN_STRING_LITERAL(QUIC_DECOMPRESSION_FAILURE); |
RETURN_STRING_LITERAL(QUIC_CONNECTION_TIMED_OUT); |
+ RETURN_STRING_LITERAL(QUIC_ERROR_MIGRATING_ADDRESS); |
+ RETURN_STRING_LITERAL(QUIC_PACKET_WRITE_ERROR); |
RETURN_STRING_LITERAL(QUIC_PROOF_INVALID); |
RETURN_STRING_LITERAL(QUIC_CRYPTO_DUPLICATE_TAG); |
RETURN_STRING_LITERAL(QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT); |
@@ -139,4 +196,29 @@ const char* QuicUtils::ErrorToString(QuicErrorCode error) { |
return "INVALID_ERROR_CODE"; |
} |
+// static |
+string QuicUtils::TagToString(QuicTag tag) { |
+ char chars[4]; |
+ bool ascii = true; |
+ const QuicTag orig_tag = tag; |
+ |
+ for (size_t i = 0; i < sizeof(chars); i++) { |
+ chars[i] = tag; |
+ if (chars[i] == 0 && i == 3) { |
+ chars[i] = ' '; |
+ } |
+ if (!isprint(static_cast<unsigned char>(chars[i]))) { |
+ ascii = false; |
+ break; |
+ } |
+ tag >>= 8; |
+ } |
+ |
+ if (ascii) { |
+ return string(chars, sizeof(chars)); |
+ } |
+ |
+ return base::UintToString(orig_tag); |
+} |
+ |
} // namespace net |