Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Unified Diff: net/quic/quic_utils.cc

Issue 14651009: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix integer constant is too large for 'unsigned long' type Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_utils.h ('k') | net/quic/reliable_quic_stream.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_utils.cc
diff --git a/net/quic/quic_utils.cc b/net/quic/quic_utils.cc
index 8a9d01b7432d2613ab8dba8839f63b681326676b..142f9ccccaeb3c10daf25544b3a8c716ac57dd90 100644
--- a/net/quic/quic_utils.cc
+++ b/net/quic/quic_utils.cc
@@ -10,6 +10,23 @@
namespace net {
// static
+uint64 QuicUtils::FNV1a_64_Hash(const char* data, int len) {
+ static const uint64 kOffset = GG_UINT64_C(14695981039346656037);
+ static const uint64 kPrime = GG_UINT64_C(1099511628211);
+
+ const uint8* octets = reinterpret_cast<const uint8*>(data);
+
+ uint64 hash = kOffset;
+
+ for (int i = 0; i < len; ++i) {
+ hash = hash ^ octets[i];
+ hash = hash * kPrime;
+ }
+
+ return hash;
+}
+
+// static
uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) {
// The following two constants are defined as part of the hash algorithm.
// see http://www.isthe.com/chongo/tech/comp/fnv/
@@ -31,6 +48,23 @@ uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) {
return hash;
}
+// static
+void QuicUtils::SerializeUint128(uint128 v, uint8* out) {
+ const uint64 lo = Uint128Low64(v);
+ const uint64 hi = Uint128High64(v);
+ // This assumes that the system is little-endian.
+ memcpy(out, &lo, sizeof(lo));
+ memcpy(out + sizeof(lo), &hi, sizeof(hi));
+}
+
+// static
+uint128 QuicUtils::ParseUint128(const uint8* in) {
+ uint64 lo, hi;
+ memcpy(&lo, in, sizeof(lo));
+ memcpy(&hi, in + sizeof(lo), sizeof(hi));
+ return uint128(hi, lo);
+}
+
#define RETURN_STRING_LITERAL(x) \
case x: \
return #x;
@@ -88,6 +122,8 @@ const char* QuicUtils::ErrorToString(QuicErrorCode error) {
RETURN_STRING_LITERAL(QUIC_TOO_MANY_OPEN_STREAMS);
RETURN_STRING_LITERAL(QUIC_PUBLIC_RESET);
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_CONNECTION_TIMED_OUT);
RETURN_STRING_LITERAL(QUIC_PROOF_INVALID);
RETURN_STRING_LITERAL(QUIC_CRYPTO_DUPLICATE_TAG);
« no previous file with comments | « net/quic/quic_utils.h ('k') | net/quic/reliable_quic_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698