| 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 // Manages the packet entropy calculation for both sent and received packets |
| 6 // for a connection. |
| 7 |
| 8 #ifndef NET_QUIC_QUIC_RECEIVED_ENTROPY_MANAGER_H_ |
| 9 #define NET_QUIC_QUIC_RECEIVED_ENTROPY_MANAGER_H_ |
| 10 |
| 11 #include "net/quic/quic_framer.h" |
| 12 #include "net/quic/quic_protocol.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 // Records all received packets by a connection to track the cumulative |
| 17 // entropy of received packets. Also, called by the framer when it truncates |
| 18 // an ack frame to calculate the correct entropy value for the ack frame being |
| 19 // serialized. |
| 20 class NET_EXPORT_PRIVATE QuicReceivedEntropyManager : |
| 21 public QuicReceivedEntropyHashCalculatorInterface { |
| 22 public: |
| 23 QuicReceivedEntropyManager(); |
| 24 virtual ~QuicReceivedEntropyManager(); |
| 25 |
| 26 // Record the received entropy hash against |sequence_number|. |
| 27 void RecordPacketEntropyHash(QuicPacketSequenceNumber sequence_number, |
| 28 QuicPacketEntropyHash entropy_hash); |
| 29 |
| 30 // QuicReceivedEntropyHashCalculatorInterface |
| 31 // Called by QuicFramer, when the outgoing ack gets truncated, to recalculate |
| 32 // the received entropy hash for the truncated ack frame. |
| 33 virtual QuicPacketEntropyHash EntropyHash( |
| 34 QuicPacketSequenceNumber sequence_number) const OVERRIDE; |
| 35 |
| 36 QuicPacketSequenceNumber LargestSequenceNumber() const; |
| 37 |
| 38 // Recalculate the entropy hash and clears old packet entropies, |
| 39 // now that the sender sent us the |entropy_hash| for packets up to, |
| 40 // but not including, |peer_least_unacked|. |
| 41 void RecalculateEntropyHash(QuicPacketSequenceNumber peer_least_unacked, |
| 42 QuicPacketEntropyHash entropy_hash); |
| 43 |
| 44 QuicPacketEntropyHash packets_entropy_hash() const { |
| 45 return packets_entropy_hash_; |
| 46 } |
| 47 |
| 48 private: |
| 49 typedef std::map<QuicPacketSequenceNumber, |
| 50 QuicPacketEntropyHash> ReceivedEntropyMap; |
| 51 |
| 52 // TODO(satyamshekhar): Can be optimized using an interval set like data |
| 53 // structure. |
| 54 // Map of received sequence numbers to their corresponding entropy. |
| 55 // Every received packet has an entry, and packets without the entropy bit set |
| 56 // have an entropy value of 0. |
| 57 // TODO(ianswett): When the entropy flag is off, the entropy should not be 0. |
| 58 ReceivedEntropyMap packets_entropy_; |
| 59 |
| 60 // Cumulative hash of entropy of all received packets. |
| 61 QuicPacketEntropyHash packets_entropy_hash_; |
| 62 |
| 63 // The largest sequence number cleared by RecalculateEntropyHash. |
| 64 // Received entropy cannot be calculated for numbers less than it. |
| 65 QuicPacketSequenceNumber largest_sequence_number_; |
| 66 }; |
| 67 |
| 68 } // namespace net |
| 69 |
| 70 #endif // NET_QUIC_QUIC_RECEIVED_ENTROPY_MANAGER_H_ |
| OLD | NEW |