OLD | NEW |
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 #include "net/quic/quic_flags.h" |
9 | 10 |
10 using std::make_pair; | 11 using std::make_pair; |
11 using std::max; | 12 using std::max; |
12 using std::min; | 13 using std::min; |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 QuicSentEntropyManager::QuicSentEntropyManager() : map_offset_(1) {} | 17 QuicSentEntropyManager::QuicSentEntropyManager() : map_offset_(1) {} |
17 | 18 |
18 QuicSentEntropyManager::~QuicSentEntropyManager() {} | 19 QuicSentEntropyManager::~QuicSentEntropyManager() {} |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 74 } |
74 if (!missing_packets.Empty() && | 75 if (!missing_packets.Empty() && |
75 missing_packets.Min() < GetSmallestPacketWithEntropy()) { | 76 missing_packets.Min() < GetSmallestPacketWithEntropy()) { |
76 return false; | 77 return false; |
77 } | 78 } |
78 // First the entropy for largest_observed packet number should be updated. | 79 // First the entropy for largest_observed packet number should be updated. |
79 UpdateCumulativeEntropy(largest_observed, &last_valid_entropy_); | 80 UpdateCumulativeEntropy(largest_observed, &last_valid_entropy_); |
80 | 81 |
81 // Now XOR out all the missing entropies. | 82 // Now XOR out all the missing entropies. |
82 QuicPacketEntropyHash expected_entropy_hash = last_valid_entropy_.entropy; | 83 QuicPacketEntropyHash expected_entropy_hash = last_valid_entropy_.entropy; |
83 for (QuicPacketNumber packet : missing_packets) { | 84 if (FLAGS_quic_use_packet_number_queue_intervals) { |
84 expected_entropy_hash ^= GetPacketEntropy(packet); | 85 for (auto itr = missing_packets.begin_intervals(); |
| 86 itr != missing_packets.end_intervals(); ++itr) { |
| 87 const auto& interval = *itr; |
| 88 for (QuicPacketNumber packet_number = interval.min(); |
| 89 packet_number < interval.max(); ++packet_number) { |
| 90 expected_entropy_hash ^= GetPacketEntropy(packet_number); |
| 91 } |
| 92 } |
| 93 } else { |
| 94 for (QuicPacketNumber packet : missing_packets) { |
| 95 expected_entropy_hash ^= GetPacketEntropy(packet); |
| 96 } |
85 } | 97 } |
86 DLOG_IF(WARNING, entropy_hash != expected_entropy_hash) | 98 DLOG_IF(WARNING, entropy_hash != expected_entropy_hash) |
87 << "Invalid entropy hash: " << static_cast<int>(entropy_hash) | 99 << "Invalid entropy hash: " << static_cast<int>(entropy_hash) |
88 << " expected entropy hash: " << static_cast<int>(expected_entropy_hash); | 100 << " expected entropy hash: " << static_cast<int>(expected_entropy_hash); |
89 return entropy_hash == expected_entropy_hash; | 101 return entropy_hash == expected_entropy_hash; |
90 } | 102 } |
91 | 103 |
92 void QuicSentEntropyManager::ClearEntropyBefore( | 104 void QuicSentEntropyManager::ClearEntropyBefore( |
93 QuicPacketNumber packet_number) { | 105 QuicPacketNumber packet_number) { |
94 // Don't discard entropy before updating the cumulative entropy used to | 106 // Don't discard entropy before updating the cumulative entropy used to |
95 // calculate EntropyHash and IsValidEntropy. | 107 // calculate EntropyHash and IsValidEntropy. |
96 if (last_cumulative_entropy_.packet_number < packet_number) { | 108 if (last_cumulative_entropy_.packet_number < packet_number) { |
97 UpdateCumulativeEntropy(packet_number, &last_cumulative_entropy_); | 109 UpdateCumulativeEntropy(packet_number, &last_cumulative_entropy_); |
98 } | 110 } |
99 if (last_valid_entropy_.packet_number < packet_number) { | 111 if (last_valid_entropy_.packet_number < packet_number) { |
100 UpdateCumulativeEntropy(packet_number, &last_valid_entropy_); | 112 UpdateCumulativeEntropy(packet_number, &last_valid_entropy_); |
101 } | 113 } |
102 while (map_offset_ < packet_number) { | 114 while (map_offset_ < packet_number) { |
103 packets_entropy_.pop_front(); | 115 packets_entropy_.pop_front(); |
104 ++map_offset_; | 116 ++map_offset_; |
105 } | 117 } |
106 DVLOG(2) << "Cleared entropy before: " << packet_number; | 118 DVLOG(2) << "Cleared entropy before: " << packet_number; |
107 } | 119 } |
108 | 120 |
109 } // namespace net | 121 } // namespace net |
OLD | NEW |