| 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 // Manages the packet entropy calculation for both sent and received packets | 5 // Manages the packet entropy calculation for both sent and received packets |
| 6 // for a connection. | 6 // for a connection. |
| 7 | 7 |
| 8 #ifndef NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ | 8 #ifndef NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ |
| 9 #define NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ | 9 #define NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ |
| 10 | 10 |
| 11 #include <deque> |
| 12 |
| 11 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 13 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
| 12 #include "net/quic/quic_framer.h" | 14 #include "net/quic/quic_framer.h" |
| 13 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
| 14 | 16 |
| 15 namespace net { | 17 namespace net { |
| 16 | 18 |
| 17 namespace test { | 19 namespace test { |
| 18 class EntropyTrackerPeer; | 20 class EntropyTrackerPeer; |
| 19 class QuicConnectionPeer; | 21 class QuicConnectionPeer; |
| 20 class QuicReceivedPacketManagerPeer; | 22 class QuicReceivedPacketManagerPeer; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 54 |
| 53 // Sets the entropy hash up to but not including a sequence number based | 55 // Sets the entropy hash up to but not including a sequence number based |
| 54 // on the hash provided by a StopWaiting frame. Clears older packet | 56 // on the hash provided by a StopWaiting frame. Clears older packet |
| 55 // entropy entries and performs garbage collection up to the first gap. | 57 // entropy entries and performs garbage collection up to the first gap. |
| 56 void SetCumulativeEntropyUpTo(QuicPacketSequenceNumber sequence_number, | 58 void SetCumulativeEntropyUpTo(QuicPacketSequenceNumber sequence_number, |
| 57 QuicPacketEntropyHash entropy_hash); | 59 QuicPacketEntropyHash entropy_hash); |
| 58 | 60 |
| 59 private: | 61 private: |
| 60 friend class test::EntropyTrackerPeer; | 62 friend class test::EntropyTrackerPeer; |
| 61 | 63 |
| 62 typedef std::map<QuicPacketSequenceNumber, | 64 // A deque indexed by sequence number storing the packet's hash and whether |
| 63 QuicPacketEntropyHash> ReceivedEntropyMap; | 65 // a hash was recorded for that sequence number. |
| 66 typedef std::deque<std::pair<QuicPacketEntropyHash, bool>> |
| 67 ReceivedEntropyHashes; |
| 64 | 68 |
| 65 // Recomputes first_gap_ and removes packets_entropy_ entries that are no | 69 // Recomputes first_gap_ and removes packets_entropy_ entries that are no |
| 66 // longer needed to compute EntropyHash. | 70 // longer needed to compute EntropyHash. |
| 67 void AdvanceFirstGapAndGarbageCollectEntropyMap(); | 71 void AdvanceFirstGapAndGarbageCollectEntropyMap(); |
| 68 | 72 |
| 69 // TODO(satyamshekhar): Can be optimized using an interval set like data | |
| 70 // structure. | |
| 71 // Map of received sequence numbers to their corresponding entropy. | 73 // Map of received sequence numbers to their corresponding entropy. |
| 72 // Stores an entry for every received packet whose sequence_number is larger | 74 // Stores an entry for every received packet whose sequence_number is larger |
| 73 // than first_gap_. Packets without the entropy bit set have an entropy | 75 // than first_gap_. Packets without the entropy bit set have an entropy |
| 74 // value of 0. | 76 // value of 0. |
| 75 // TODO(ianswett): When the entropy flag is off, the entropy | 77 ReceivedEntropyHashes packets_entropy_; |
| 76 // should not be 0. | |
| 77 ReceivedEntropyMap packets_entropy_; | |
| 78 | 78 |
| 79 // Cumulative hash of entropy of all received packets. | 79 // Cumulative hash of entropy of all received packets. |
| 80 QuicPacketEntropyHash packets_entropy_hash_; | 80 QuicPacketEntropyHash packets_entropy_hash_; |
| 81 | 81 |
| 82 // Sequence number of the first packet that we do not know the entropy of. | 82 // Sequence number of the first packet that we do not know the entropy of. |
| 83 // If there are no gaps in the received packet sequence, | 83 // If there are no gaps in the received packet sequence, |
| 84 // packets_entropy_ will be empty and first_gap_ will be equal to | 84 // packets_entropy_ will be empty and first_gap_ will be equal to |
| 85 // 'largest_observed_ + 1' since that's the first packet for which | 85 // 'largest_observed_ + 1' since that's the first packet for which |
| 86 // entropy is unknown. If there are gaps, packets_entropy_ will | 86 // entropy is unknown. If there are gaps, packets_entropy_ will |
| 87 // contain entries for all received packets with sequence_number > | 87 // contain entries for all received packets with sequence_number > |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // QuicReceivedEntropyHashCalculatorInterface | 128 // QuicReceivedEntropyHashCalculatorInterface |
| 129 // Called by QuicFramer, when the outgoing ack gets truncated, to recalculate | 129 // Called by QuicFramer, when the outgoing ack gets truncated, to recalculate |
| 130 // the received entropy hash for the truncated ack frame. | 130 // the received entropy hash for the truncated ack frame. |
| 131 virtual QuicPacketEntropyHash EntropyHash( | 131 virtual QuicPacketEntropyHash EntropyHash( |
| 132 QuicPacketSequenceNumber sequence_number) const OVERRIDE; | 132 QuicPacketSequenceNumber sequence_number) const OVERRIDE; |
| 133 | 133 |
| 134 // Updates internal state based on |stop_waiting|. | 134 // Updates internal state based on |stop_waiting|. |
| 135 void UpdatePacketInformationSentByPeer( | 135 void UpdatePacketInformationSentByPeer( |
| 136 const QuicStopWaitingFrame& stop_waiting); | 136 const QuicStopWaitingFrame& stop_waiting); |
| 137 | 137 |
| 138 // Returns whether the peer is missing packets. | |
| 139 bool HasMissingPackets(); | |
| 140 | |
| 141 // Returns true when there are new missing packets to be reported within 3 | 138 // Returns true when there are new missing packets to be reported within 3 |
| 142 // packets of the largest observed. | 139 // packets of the largest observed. |
| 143 bool HasNewMissingPackets(); | 140 bool HasNewMissingPackets(); |
| 144 | 141 |
| 145 QuicPacketSequenceNumber peer_least_packet_awaiting_ack() { | 142 QuicPacketSequenceNumber peer_least_packet_awaiting_ack() { |
| 146 return peer_least_packet_awaiting_ack_; | 143 return peer_least_packet_awaiting_ack_; |
| 147 } | 144 } |
| 148 | 145 |
| 149 private: | 146 private: |
| 150 friend class test::QuicConnectionPeer; | 147 friend class test::QuicConnectionPeer; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 174 scoped_ptr<ReceiveAlgorithmInterface> receive_algorithm_; | 171 scoped_ptr<ReceiveAlgorithmInterface> receive_algorithm_; |
| 175 | 172 |
| 176 QuicConnectionStats* stats_; | 173 QuicConnectionStats* stats_; |
| 177 | 174 |
| 178 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacketManager); | 175 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacketManager); |
| 179 }; | 176 }; |
| 180 | 177 |
| 181 } // namespace net | 178 } // namespace net |
| 182 | 179 |
| 183 #endif // NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ | 180 #endif // NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ |
| OLD | NEW |