OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/quic/quic_utils.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace net { |
| 10 |
| 11 // static |
| 12 int QuicUtils::StreamFragmentPacketOverhead(int num_fragments) { |
| 13 // TODO(jar): Use sizeof(some name). |
| 14 return kPacketHeaderSize + |
| 15 1 + // fragment count |
| 16 (1 + // 8 bit type |
| 17 2 + // 16 bit length |
| 18 kMinStreamFragmentLength) * num_fragments; |
| 19 } |
| 20 |
| 21 // TODO(jar): put into an anonymous namespage. |
| 22 // The following two constants are defined as part of the hash algorithm. |
| 23 // 309485009821345068724781371 |
| 24 static uint128 kPrime(16777216, 315); |
| 25 // 14406626329776981559649562966706236762 |
| 26 static uint128 kOffset(780984778246553632, 4400696054689967450); |
| 27 |
| 28 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) { |
| 29 const uint8* octets = reinterpret_cast<const uint8*>(data); |
| 30 |
| 31 uint128 hash = kOffset; |
| 32 |
| 33 for (int i = 0; i < len; ++i) { |
| 34 hash = hash ^ uint128(0, octets[i]); |
| 35 hash = hash * kPrime; |
| 36 } |
| 37 |
| 38 return hash; |
| 39 } |
| 40 |
| 41 #define RETURN_STRING_LITERAL(x) \ |
| 42 case x: \ |
| 43 return #x; |
| 44 |
| 45 const char* QuicUtils::ErrorToString(QuicErrorCode error) { |
| 46 switch (error) { |
| 47 RETURN_STRING_LITERAL(QUIC_NO_ERROR); |
| 48 RETURN_STRING_LITERAL(QUIC_STREAM_DATA_AFTER_TERMINATION); |
| 49 RETURN_STRING_LITERAL(QUIC_SERVER_ERROR_PROCESSING_STREAM); |
| 50 RETURN_STRING_LITERAL(QUIC_MULTIPLE_TERMINATION_OFFSETS); |
| 51 RETURN_STRING_LITERAL(QUIC_BAD_APPLICATION_PAYLOAD); |
| 52 RETURN_STRING_LITERAL(QUIC_INVALID_PACKET_HEADER); |
| 53 RETURN_STRING_LITERAL(QUIC_INVALID_FRAGMENT_DATA); |
| 54 RETURN_STRING_LITERAL(QUIC_INVALID_FEC_DATA); |
| 55 RETURN_STRING_LITERAL(QUIC_INVALID_RST_STREAM_DATA); |
| 56 RETURN_STRING_LITERAL(QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 57 RETURN_STRING_LITERAL(QUIC_INVALID_ACK_DATA); |
| 58 RETURN_STRING_LITERAL(QUIC_DECRYPTION_FAILURE); |
| 59 RETURN_STRING_LITERAL(QUIC_ENCRYPTION_FAILURE); |
| 60 RETURN_STRING_LITERAL(QUIC_PACKET_TOO_LARGE); |
| 61 RETURN_STRING_LITERAL(QUIC_PACKET_FOR_NONEXISTENT_STREAM); |
| 62 RETURN_STRING_LITERAL(QUIC_CLIENT_GOING_AWAY); |
| 63 RETURN_STRING_LITERAL(QUIC_SERVER_GOING_AWAY); |
| 64 RETURN_STRING_LITERAL(QUIC_CRYPTO_TAGS_OUT_OF_ORDER); |
| 65 RETURN_STRING_LITERAL(QUIC_CRYPTO_TOO_MANY_ENTRIES); |
| 66 RETURN_STRING_LITERAL(QUIC_CRYPTO_INVALID_VALUE_LENGTH) |
| 67 RETURN_STRING_LITERAL(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE); |
| 68 RETURN_STRING_LITERAL(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); |
| 69 RETURN_STRING_LITERAL(QUIC_INVALID_STREAM_ID); |
| 70 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OPEN_STREAMS); |
| 71 RETURN_STRING_LITERAL(QUIC_CONNECTION_TIMED_OUT); |
| 72 // Intentionally have no default case, so we'll break the build |
| 73 // if we add errors and don't put them here. |
| 74 } |
| 75 return ""; |
| 76 } |
| 77 |
| 78 } // namespace net |
OLD | NEW |