| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/quic/quic_ack_notifier_manager.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <list> | |
| 9 #include <map> | |
| 10 #include <utility> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/stl_util.h" | |
| 14 #include "net/quic/quic_ack_notifier.h" | |
| 15 #include "net/quic/quic_flags.h" | |
| 16 #include "net/quic/quic_protocol.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 AckNotifierManager::AckNotifierManager() {} | |
| 21 | |
| 22 AckNotifierManager::~AckNotifierManager() { | |
| 23 for (const auto& pair : ack_notifier_map_) { | |
| 24 for (QuicAckNotifier* notifier : pair.second) { | |
| 25 if (notifier->OnPacketAbandoned()) { | |
| 26 delete notifier; | |
| 27 } | |
| 28 } | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 void AckNotifierManager::OnPacketAcked(QuicPacketSequenceNumber sequence_number, | |
| 33 QuicTime::Delta delta_largest_observed) { | |
| 34 // Inform all the registered AckNotifiers of the new ACK. | |
| 35 auto map_it = ack_notifier_map_.find(sequence_number); | |
| 36 if (map_it == ack_notifier_map_.end()) { | |
| 37 // No AckNotifier is interested in this sequence number. | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 // One or more AckNotifiers are registered as interested in this sequence | |
| 42 // number. Iterate through them and call OnAck on each. | |
| 43 for (QuicAckNotifier* ack_notifier : map_it->second) { | |
| 44 if (ack_notifier->OnAck(delta_largest_observed)) { | |
| 45 // If this has resulted in an empty AckNotifer, erase it. | |
| 46 delete ack_notifier; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 // Remove the sequence number from the map as we have notified all the | |
| 51 // registered AckNotifiers, and we won't see it again. | |
| 52 ack_notifier_map_.erase(map_it); | |
| 53 } | |
| 54 | |
| 55 void AckNotifierManager::OnPacketRetransmitted( | |
| 56 QuicPacketSequenceNumber old_sequence_number, | |
| 57 QuicPacketSequenceNumber new_sequence_number, | |
| 58 int packet_payload_size) { | |
| 59 auto map_it = ack_notifier_map_.find(old_sequence_number); | |
| 60 if (map_it == ack_notifier_map_.end()) { | |
| 61 // No AckNotifiers are interested in the old sequence number. | |
| 62 return; | |
| 63 } | |
| 64 | |
| 65 // Update the existing QuicAckNotifiers to the new sequence number. | |
| 66 AckNotifierList& ack_notifier_list = map_it->second; | |
| 67 for (QuicAckNotifier* ack_notifier : ack_notifier_list) { | |
| 68 ack_notifier->OnPacketRetransmitted(packet_payload_size); | |
| 69 } | |
| 70 | |
| 71 // The old sequence number is no longer of interest, copy the updated | |
| 72 // AckNotifiers to the new sequence number before deleting the old. | |
| 73 ack_notifier_map_[new_sequence_number] = ack_notifier_list; | |
| 74 ack_notifier_map_.erase(map_it); | |
| 75 } | |
| 76 | |
| 77 void AckNotifierManager::OnSerializedPacket( | |
| 78 const SerializedPacket& serialized_packet) { | |
| 79 if (FLAGS_quic_attach_ack_notifiers_to_packets) { | |
| 80 // Inform each attached AckNotifier of the packet's serialization. | |
| 81 AckNotifierList& notifier_list = | |
| 82 ack_notifier_map_[serialized_packet.sequence_number]; | |
| 83 for (QuicAckNotifier* notifier : serialized_packet.notifiers) { | |
| 84 if (notifier == nullptr) { | |
| 85 LOG(DFATAL) << "AckNotifier should not be nullptr."; | |
| 86 continue; | |
| 87 } | |
| 88 notifier->OnSerializedPacket(); | |
| 89 | |
| 90 // Update the mapping in the other direction, from sequence number to | |
| 91 // AckNotifier. | |
| 92 notifier_list.push_back(notifier); | |
| 93 } | |
| 94 } else { | |
| 95 // AckNotifiers can only be attached to retransmittable frames. | |
| 96 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; | |
| 97 if (frames == nullptr) { | |
| 98 return; | |
| 99 } | |
| 100 | |
| 101 // For each frame in |serialized_packet|, inform any attached AckNotifiers | |
| 102 // of the packet's sequence number. | |
| 103 for (const QuicFrame& quic_frame : frames->frames()) { | |
| 104 if (quic_frame.type != STREAM_FRAME || | |
| 105 quic_frame.stream_frame->notifier == nullptr) { | |
| 106 continue; | |
| 107 } | |
| 108 | |
| 109 QuicAckNotifier* notifier = quic_frame.stream_frame->notifier; | |
| 110 notifier->OnSerializedPacket(); | |
| 111 | |
| 112 // Update the mapping in the other direction, from sequence number to | |
| 113 // AckNotifier. | |
| 114 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); | |
| 115 } | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 } // namespace net | |
| OLD | NEW |