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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_sent_entropy_manager.h" 5 #include "net/quic/quic_sent_entropy_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/linked_hash_map.h" 8 #include "net/base/linked_hash_map.h"
9 9
10 using std::make_pair; 10 using std::make_pair;
11 using std::max; 11 using std::max;
12 using std::min; 12 using std::min;
13 13
14 namespace net { 14 namespace net {
15 15
16 QuicSentEntropyManager::QuicSentEntropyManager() 16 QuicSentEntropyManager::QuicSentEntropyManager() : packets_entropy_hash_(0) {
17 : packets_entropy_hash_(0) {} 17 }
18 18
19 QuicSentEntropyManager::~QuicSentEntropyManager() {} 19 QuicSentEntropyManager::~QuicSentEntropyManager() {
20 }
20 21
21 void QuicSentEntropyManager::RecordPacketEntropyHash( 22 void QuicSentEntropyManager::RecordPacketEntropyHash(
22 QuicPacketSequenceNumber sequence_number, 23 QuicPacketSequenceNumber sequence_number,
23 QuicPacketEntropyHash entropy_hash) { 24 QuicPacketEntropyHash entropy_hash) {
24 // TODO(satyamshekhar): Check this logic again when/if we enable packet 25 // TODO(satyamshekhar): Check this logic again when/if we enable packet
25 // reordering. 26 // reordering.
26 packets_entropy_hash_ ^= entropy_hash; 27 packets_entropy_hash_ ^= entropy_hash;
27 packets_entropy_.insert( 28 packets_entropy_.insert(make_pair(
28 make_pair(sequence_number, 29 sequence_number, make_pair(entropy_hash, packets_entropy_hash_)));
29 make_pair(entropy_hash, packets_entropy_hash_)));
30 DVLOG(2) << "setting cumulative sent entropy hash to: " 30 DVLOG(2) << "setting cumulative sent entropy hash to: "
31 << static_cast<int>(packets_entropy_hash_) 31 << static_cast<int>(packets_entropy_hash_)
32 << " updated with sequence number " << sequence_number 32 << " updated with sequence number " << sequence_number
33 << " entropy hash: " << static_cast<int>(entropy_hash); 33 << " entropy hash: " << static_cast<int>(entropy_hash);
34 } 34 }
35 35
36 QuicPacketEntropyHash QuicSentEntropyManager::EntropyHash( 36 QuicPacketEntropyHash QuicSentEntropyManager::EntropyHash(
37 QuicPacketSequenceNumber sequence_number) const { 37 QuicPacketSequenceNumber sequence_number) const {
38 SentEntropyMap::const_iterator it = 38 SentEntropyMap::const_iterator it = packets_entropy_.find(sequence_number);
39 packets_entropy_.find(sequence_number);
40 if (it == packets_entropy_.end()) { 39 if (it == packets_entropy_.end()) {
41 // Should only happen when we have not received ack for any packet. 40 // Should only happen when we have not received ack for any packet.
42 DCHECK_EQ(0u, sequence_number); 41 DCHECK_EQ(0u, sequence_number);
43 return 0; 42 return 0;
44 } 43 }
45 return it->second.second; 44 return it->second.second;
46 } 45 }
47 46
48 bool QuicSentEntropyManager::IsValidEntropy( 47 bool QuicSentEntropyManager::IsValidEntropy(
49 QuicPacketSequenceNumber sequence_number, 48 QuicPacketSequenceNumber sequence_number,
50 const SequenceNumberSet& missing_packets, 49 const SequenceNumberSet& missing_packets,
51 QuicPacketEntropyHash entropy_hash) const { 50 QuicPacketEntropyHash entropy_hash) const {
52 SentEntropyMap::const_iterator entropy_it = 51 SentEntropyMap::const_iterator entropy_it =
53 packets_entropy_.find(sequence_number); 52 packets_entropy_.find(sequence_number);
54 if (entropy_it == packets_entropy_.end()) { 53 if (entropy_it == packets_entropy_.end()) {
55 DCHECK_EQ(0u, sequence_number); 54 DCHECK_EQ(0u, sequence_number);
56 // Close connection if something goes wrong. 55 // Close connection if something goes wrong.
57 return 0 == sequence_number; 56 return 0 == sequence_number;
58 } 57 }
59 QuicPacketEntropyHash expected_entropy_hash = entropy_it->second.second; 58 QuicPacketEntropyHash expected_entropy_hash = entropy_it->second.second;
60 for (SequenceNumberSet::const_iterator it = missing_packets.begin(); 59 for (SequenceNumberSet::const_iterator it = missing_packets.begin();
61 it != missing_packets.end(); ++it) { 60 it != missing_packets.end();
61 ++it) {
62 entropy_it = packets_entropy_.find(*it); 62 entropy_it = packets_entropy_.find(*it);
63 DCHECK(entropy_it != packets_entropy_.end()); 63 DCHECK(entropy_it != packets_entropy_.end());
64 expected_entropy_hash ^= entropy_it->second.first; 64 expected_entropy_hash ^= entropy_it->second.first;
65 } 65 }
66 DLOG_IF(WARNING, entropy_hash != expected_entropy_hash) 66 DLOG_IF(WARNING, entropy_hash != expected_entropy_hash)
67 << "Invalid entropy hash: " << static_cast<int>(entropy_hash) 67 << "Invalid entropy hash: " << static_cast<int>(entropy_hash)
68 << " expected entropy hash: " << static_cast<int>(expected_entropy_hash); 68 << " expected entropy hash: " << static_cast<int>(expected_entropy_hash);
69 return entropy_hash == expected_entropy_hash; 69 return entropy_hash == expected_entropy_hash;
70 } 70 }
71 71
72 void QuicSentEntropyManager::ClearEntropyBefore( 72 void QuicSentEntropyManager::ClearEntropyBefore(
73 QuicPacketSequenceNumber sequence_number) { 73 QuicPacketSequenceNumber sequence_number) {
74 if (packets_entropy_.empty()) { 74 if (packets_entropy_.empty()) {
75 return; 75 return;
76 } 76 }
77 SentEntropyMap::iterator it = packets_entropy_.begin(); 77 SentEntropyMap::iterator it = packets_entropy_.begin();
78 while (it->first < sequence_number) { 78 while (it->first < sequence_number) {
79 packets_entropy_.erase(it); 79 packets_entropy_.erase(it);
80 it = packets_entropy_.begin(); 80 it = packets_entropy_.begin();
81 DCHECK(it != packets_entropy_.end()); 81 DCHECK(it != packets_entropy_.end());
82 } 82 }
83 DVLOG(2) << "Cleared entropy before: " 83 DVLOG(2) << "Cleared entropy before: " << packets_entropy_.begin()->first;
84 << packets_entropy_.begin()->first;
85 } 84 }
86 85
87 } // namespace net 86 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698