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

Side by Side Diff: net/quic/quic_utils.cc

Issue 11125002: Add QuicFramer and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: narrowing in Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 return kPacketHeaderSize +
14 1 + // fragment count
jar (doing other things) 2012/10/14 23:04:38 nit: much better would be some sizeof(names) here.
Ryan Hamilton 2012/10/15 21:22:08 added todo.
15 (1 + // 8 bit type
16 2 + // 16 bit length
17 kMinStreamFragmentLength) * num_fragments;
18 }
19
20 // The following two constants are defined as part of the hash algorithm.
21 // 309485009821345068724781371
22 static uint128 kPrime(16777216, 315);
jar (doing other things) 2012/10/14 23:04:38 nit: I like statics... but I think we're supposed
Ryan Hamilton 2012/10/15 21:22:08 added todo.
23 // 14406626329776981559649562966706236762
24 static uint128 kOffset(780984778246553632, 4400696054689967450);
25
26 uint128 QuicUtils::FNV1a_128_Hash(const char* data, int len) {
27 const uint8* octets = reinterpret_cast<const uint8*>(data);
28
29 uint128 hash = kOffset;
30
31 for (int i = 0; i < len; ++i) {
32 hash = hash ^ uint128(0, octets[i]);
33 hash = hash * kPrime;
34 }
35
36 return hash;
37 }
38
39 #define RETURN_STRING_LITERAL(x) \
40 case x: \
41 return #x;
42
43 const char* QuicUtils::ErrorToString(QuicErrorCode error) {
44 switch (error) {
45 RETURN_STRING_LITERAL(QUIC_NO_ERROR);
46 RETURN_STRING_LITERAL(QUIC_STREAM_DATA_AFTER_TERMINATION);
47 RETURN_STRING_LITERAL(QUIC_SERVER_ERROR_PROCESSING_STREAM);
48 RETURN_STRING_LITERAL(QUIC_MULTIPLE_TERMINATION_OFFSETS);
49 RETURN_STRING_LITERAL(QUIC_BAD_APPLICATION_PAYLOAD);
50 RETURN_STRING_LITERAL(QUIC_INVALID_PACKET_HEADER);
51 RETURN_STRING_LITERAL(QUIC_INVALID_FRAGMENT_DATA);
52 RETURN_STRING_LITERAL(QUIC_INVALID_FEC_DATA);
53 RETURN_STRING_LITERAL(QUIC_INVALID_RST_STREAM_DATA);
54 RETURN_STRING_LITERAL(QUIC_INVALID_CONNECTION_CLOSE_DATA);
55 RETURN_STRING_LITERAL(QUIC_INVALID_ACK_DATA);
56 RETURN_STRING_LITERAL(QUIC_DECRYPTION_FAILURE);
57 RETURN_STRING_LITERAL(QUIC_ENCRYPTION_FAILURE);
58 RETURN_STRING_LITERAL(QUIC_PACKET_TOO_LARGE);
59 RETURN_STRING_LITERAL(QUIC_PACKET_FOR_NONEXISTENT_STREAM);
60 RETURN_STRING_LITERAL(QUIC_CLIENT_GOING_AWAY);
61 RETURN_STRING_LITERAL(QUIC_SERVER_GOING_AWAY);
62 RETURN_STRING_LITERAL(QUIC_CRYPTO_TAGS_OUT_OF_ORDER);
63 RETURN_STRING_LITERAL(QUIC_CRYPTO_TOO_MANY_ENTRIES);
64 RETURN_STRING_LITERAL(QUIC_CRYPTO_INVALID_VALUE_LENGTH)
65 RETURN_STRING_LITERAL(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE);
66 RETURN_STRING_LITERAL(QUIC_INVALID_CRYPTO_MESSAGE_TYPE);
67 RETURN_STRING_LITERAL(QUIC_INVALID_STREAM_ID);
68 RETURN_STRING_LITERAL(QUIC_TOO_MANY_OPEN_STREAMS);
69 RETURN_STRING_LITERAL(QUIC_CONNECTION_TIMED_OUT);
70 // Intentionally have no default case, so we'll break the build
71 // if we add errors and don't put them here.
72 }
73 return "";
74 }
75
76 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698