QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2017 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 | |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 5 | #include "quic/core/quic_control_frame_manager.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6 | |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 7 | #include <string> |
| 8 | |
vasilvv | 9edb31e | 2020-12-03 19:32:58 -0800 | [diff] [blame] | 9 | #include "absl/strings/str_cat.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 10 | #include "quic/core/frames/quic_ack_frequency_frame.h" |
| 11 | #include "quic/core/frames/quic_frame.h" |
haoyuewang | e1c0321 | 2021-01-07 09:15:08 -0800 | [diff] [blame] | 12 | #include "quic/core/frames/quic_new_connection_id_frame.h" |
| 13 | #include "quic/core/frames/quic_retire_connection_id_frame.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 14 | #include "quic/core/quic_constants.h" |
| 15 | #include "quic/core/quic_session.h" |
| 16 | #include "quic/core/quic_types.h" |
haoyuewang | e1c0321 | 2021-01-07 09:15:08 -0800 | [diff] [blame] | 17 | #include "quic/core/quic_utils.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 18 | #include "quic/platform/api/quic_bug_tracker.h" |
| 19 | #include "quic/platform/api/quic_flag_utils.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 20 | |
| 21 | namespace quic { |
| 22 | |
fayang | 83d7e3e | 2019-07-31 14:45:19 -0700 | [diff] [blame] | 23 | namespace { |
| 24 | |
| 25 | // The maximum number of buffered control frames which are waiting to be ACKed |
| 26 | // or sent for the first time. |
| 27 | const size_t kMaxNumControlFrames = 1000; |
| 28 | |
| 29 | } // namespace |
| 30 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 31 | QuicControlFrameManager::QuicControlFrameManager(QuicSession* session) |
| 32 | : last_control_frame_id_(kInvalidControlFrameId), |
| 33 | least_unacked_(1), |
| 34 | least_unsent_(1), |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 35 | delegate_(session) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 36 | |
| 37 | QuicControlFrameManager::~QuicControlFrameManager() { |
| 38 | while (!control_frames_.empty()) { |
| 39 | DeleteFrame(&control_frames_.front()); |
| 40 | control_frames_.pop_front(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void QuicControlFrameManager::WriteOrBufferQuicFrame(QuicFrame frame) { |
| 45 | const bool had_buffered_frames = HasBufferedFrames(); |
| 46 | control_frames_.emplace_back(frame); |
fayang | b4f3bc0 | 2019-11-04 09:20:12 -0800 | [diff] [blame] | 47 | if (control_frames_.size() > kMaxNumControlFrames) { |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 48 | delegate_->OnControlFrameManagerError( |
fayang | 83d7e3e | 2019-07-31 14:45:19 -0700 | [diff] [blame] | 49 | QUIC_TOO_MANY_BUFFERED_CONTROL_FRAMES, |
vasilvv | 9edb31e | 2020-12-03 19:32:58 -0800 | [diff] [blame] | 50 | absl::StrCat("More than ", kMaxNumControlFrames, |
| 51 | "buffered control frames, least_unacked: ", least_unacked_, |
| 52 | ", least_unsent_: ", least_unsent_)); |
fayang | 83d7e3e | 2019-07-31 14:45:19 -0700 | [diff] [blame] | 53 | return; |
| 54 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 55 | if (had_buffered_frames) { |
| 56 | return; |
| 57 | } |
| 58 | WriteBufferedFrames(); |
| 59 | } |
| 60 | |
| 61 | void QuicControlFrameManager::WriteOrBufferRstStream( |
vasilvv | 9d05f4a | 2021-09-21 18:19:03 -0700 | [diff] [blame] | 62 | QuicStreamId id, QuicResetStreamError error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 63 | QuicStreamOffset bytes_written) { |
| 64 | QUIC_DVLOG(1) << "Writing RST_STREAM_FRAME"; |
| 65 | WriteOrBufferQuicFrame((QuicFrame(new QuicRstStreamFrame( |
| 66 | ++last_control_frame_id_, id, error, bytes_written)))); |
| 67 | } |
| 68 | |
| 69 | void QuicControlFrameManager::WriteOrBufferGoAway( |
vasilvv | fef8b49 | 2021-09-14 06:08:53 -0700 | [diff] [blame] | 70 | QuicErrorCode error, QuicStreamId last_good_stream_id, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 71 | const std::string& reason) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 72 | QUIC_DVLOG(1) << "Writing GOAWAY_FRAME"; |
| 73 | WriteOrBufferQuicFrame(QuicFrame(new QuicGoAwayFrame( |
| 74 | ++last_control_frame_id_, error, last_good_stream_id, reason))); |
| 75 | } |
| 76 | |
| 77 | void QuicControlFrameManager::WriteOrBufferWindowUpdate( |
vasilvv | fef8b49 | 2021-09-14 06:08:53 -0700 | [diff] [blame] | 78 | QuicStreamId id, QuicStreamOffset byte_offset) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 79 | QUIC_DVLOG(1) << "Writing WINDOW_UPDATE_FRAME"; |
| 80 | WriteOrBufferQuicFrame(QuicFrame( |
| 81 | new QuicWindowUpdateFrame(++last_control_frame_id_, id, byte_offset))); |
| 82 | } |
| 83 | |
| 84 | void QuicControlFrameManager::WriteOrBufferBlocked(QuicStreamId id) { |
| 85 | QUIC_DVLOG(1) << "Writing BLOCKED_FRAME"; |
| 86 | WriteOrBufferQuicFrame( |
| 87 | QuicFrame(new QuicBlockedFrame(++last_control_frame_id_, id))); |
| 88 | } |
| 89 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 90 | void QuicControlFrameManager::WriteOrBufferStreamsBlocked(QuicStreamCount count, |
| 91 | bool unidirectional) { |
| 92 | QUIC_DVLOG(1) << "Writing STREAMS_BLOCKED Frame"; |
| 93 | QUIC_CODE_COUNT(quic_streams_blocked_transmits); |
| 94 | WriteOrBufferQuicFrame(QuicFrame(QuicStreamsBlockedFrame( |
| 95 | ++last_control_frame_id_, count, unidirectional))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 96 | } |
| 97 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 98 | void QuicControlFrameManager::WriteOrBufferMaxStreams(QuicStreamCount count, |
| 99 | bool unidirectional) { |
| 100 | QUIC_DVLOG(1) << "Writing MAX_STREAMS Frame"; |
| 101 | QUIC_CODE_COUNT(quic_max_streams_transmits); |
| 102 | WriteOrBufferQuicFrame(QuicFrame( |
| 103 | QuicMaxStreamsFrame(++last_control_frame_id_, count, unidirectional))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 104 | } |
| 105 | |
bnc | 187eea3 | 2020-09-02 12:16:15 -0700 | [diff] [blame] | 106 | void QuicControlFrameManager::WriteOrBufferStopSending( |
vasilvv | 9d05f4a | 2021-09-21 18:19:03 -0700 | [diff] [blame] | 107 | QuicResetStreamError error, QuicStreamId stream_id) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 108 | QUIC_DVLOG(1) << "Writing STOP_SENDING_FRAME"; |
| 109 | WriteOrBufferQuicFrame(QuicFrame( |
vasilvv | 9d05f4a | 2021-09-21 18:19:03 -0700 | [diff] [blame] | 110 | new QuicStopSendingFrame(++last_control_frame_id_, stream_id, error))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 111 | } |
| 112 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 113 | void QuicControlFrameManager::WriteOrBufferHandshakeDone() { |
| 114 | QUIC_DVLOG(1) << "Writing HANDSHAKE_DONE"; |
| 115 | WriteOrBufferQuicFrame( |
| 116 | QuicFrame(QuicHandshakeDoneFrame(++last_control_frame_id_))); |
| 117 | } |
| 118 | |
haoyuewang | 5b0f14f | 2020-09-18 14:31:54 -0700 | [diff] [blame] | 119 | void QuicControlFrameManager::WriteOrBufferAckFrequency( |
haoyuewang | c921f8d | 2020-10-14 18:06:52 -0700 | [diff] [blame] | 120 | const QuicAckFrequencyFrame& ack_frequency_frame) { |
haoyuewang | 5b0f14f | 2020-09-18 14:31:54 -0700 | [diff] [blame] | 121 | QUIC_DVLOG(1) << "Writing ACK_FREQUENCY frame"; |
| 122 | QuicControlFrameId control_frame_id = ++last_control_frame_id_; |
haoyuewang | c921f8d | 2020-10-14 18:06:52 -0700 | [diff] [blame] | 123 | // Using the control_frame_id for sequence_number here leaves gaps in |
| 124 | // sequence_number. |
| 125 | WriteOrBufferQuicFrame( |
| 126 | QuicFrame(new QuicAckFrequencyFrame(control_frame_id, |
| 127 | /*sequence_number=*/control_frame_id, |
| 128 | ack_frequency_frame.packet_tolerance, |
| 129 | ack_frequency_frame.max_ack_delay))); |
haoyuewang | 5b0f14f | 2020-09-18 14:31:54 -0700 | [diff] [blame] | 130 | } |
| 131 | |
haoyuewang | e1c0321 | 2021-01-07 09:15:08 -0800 | [diff] [blame] | 132 | void QuicControlFrameManager::WriteOrBufferNewConnectionId( |
vasilvv | fef8b49 | 2021-09-14 06:08:53 -0700 | [diff] [blame] | 133 | const QuicConnectionId& connection_id, uint64_t sequence_number, |
haoyuewang | e1c0321 | 2021-01-07 09:15:08 -0800 | [diff] [blame] | 134 | uint64_t retire_prior_to, |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 135 | const StatelessResetToken& stateless_reset_token) { |
haoyuewang | e1c0321 | 2021-01-07 09:15:08 -0800 | [diff] [blame] | 136 | QUIC_DVLOG(1) << "Writing NEW_CONNECTION_ID frame"; |
| 137 | WriteOrBufferQuicFrame(QuicFrame(new QuicNewConnectionIdFrame( |
| 138 | ++last_control_frame_id_, connection_id, sequence_number, |
| 139 | stateless_reset_token, retire_prior_to))); |
| 140 | } |
| 141 | |
| 142 | void QuicControlFrameManager::WriteOrBufferRetireConnectionId( |
| 143 | uint64_t sequence_number) { |
| 144 | QUIC_DVLOG(1) << "Writing RETIRE_CONNECTION_ID frame"; |
| 145 | WriteOrBufferQuicFrame(QuicFrame(new QuicRetireConnectionIdFrame( |
| 146 | ++last_control_frame_id_, sequence_number))); |
| 147 | } |
| 148 | |
fayang | 133b868 | 2020-12-08 05:50:33 -0800 | [diff] [blame] | 149 | void QuicControlFrameManager::WriteOrBufferNewToken(absl::string_view token) { |
| 150 | QUIC_DVLOG(1) << "Writing NEW_TOKEN frame"; |
| 151 | WriteOrBufferQuicFrame( |
| 152 | QuicFrame(new QuicNewTokenFrame(++last_control_frame_id_, token))); |
| 153 | } |
| 154 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 155 | void QuicControlFrameManager::OnControlFrameSent(const QuicFrame& frame) { |
| 156 | QuicControlFrameId id = GetControlFrameId(frame); |
| 157 | if (id == kInvalidControlFrameId) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 158 | QUIC_BUG(quic_bug_12727_1) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 159 | << "Send or retransmit a control frame with invalid control frame id"; |
| 160 | return; |
| 161 | } |
| 162 | if (frame.type == WINDOW_UPDATE_FRAME) { |
| 163 | QuicStreamId stream_id = frame.window_update_frame->stream_id; |
bnc | 20dcfc8 | 2021-06-10 07:13:46 -0700 | [diff] [blame] | 164 | if (window_update_frames_.contains(stream_id) && |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 165 | id > window_update_frames_[stream_id]) { |
| 166 | // Consider the older window update of the same stream as acked. |
| 167 | OnControlFrameIdAcked(window_update_frames_[stream_id]); |
| 168 | } |
| 169 | window_update_frames_[stream_id] = id; |
| 170 | } |
bnc | 20dcfc8 | 2021-06-10 07:13:46 -0700 | [diff] [blame] | 171 | if (pending_retransmissions_.contains(id)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 172 | // This is retransmitted control frame. |
| 173 | pending_retransmissions_.erase(id); |
| 174 | return; |
| 175 | } |
| 176 | if (id > least_unsent_) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 177 | QUIC_BUG(quic_bug_10517_1) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 178 | << "Try to send control frames out of order, id: " << id |
| 179 | << " least_unsent: " << least_unsent_; |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 180 | delegate_->OnControlFrameManagerError( |
| 181 | QUIC_INTERNAL_ERROR, "Try to send control frames out of order"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 182 | return; |
| 183 | } |
| 184 | ++least_unsent_; |
| 185 | } |
| 186 | |
| 187 | bool QuicControlFrameManager::OnControlFrameAcked(const QuicFrame& frame) { |
| 188 | QuicControlFrameId id = GetControlFrameId(frame); |
| 189 | if (!OnControlFrameIdAcked(id)) { |
| 190 | return false; |
| 191 | } |
| 192 | if (frame.type == WINDOW_UPDATE_FRAME) { |
| 193 | QuicStreamId stream_id = frame.window_update_frame->stream_id; |
bnc | 20dcfc8 | 2021-06-10 07:13:46 -0700 | [diff] [blame] | 194 | if (window_update_frames_.contains(stream_id) && |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 195 | window_update_frames_[stream_id] == id) { |
| 196 | window_update_frames_.erase(stream_id); |
| 197 | } |
| 198 | } |
| 199 | return true; |
| 200 | } |
| 201 | |
| 202 | void QuicControlFrameManager::OnControlFrameLost(const QuicFrame& frame) { |
| 203 | QuicControlFrameId id = GetControlFrameId(frame); |
| 204 | if (id == kInvalidControlFrameId) { |
| 205 | // Frame does not have a valid control frame ID, ignore it. |
| 206 | return; |
| 207 | } |
| 208 | if (id >= least_unsent_) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 209 | QUIC_BUG(quic_bug_10517_2) << "Try to mark unsent control frame as lost"; |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 210 | delegate_->OnControlFrameManagerError( |
| 211 | QUIC_INTERNAL_ERROR, "Try to mark unsent control frame as lost"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 212 | return; |
| 213 | } |
| 214 | if (id < least_unacked_ || |
| 215 | GetControlFrameId(control_frames_.at(id - least_unacked_)) == |
| 216 | kInvalidControlFrameId) { |
| 217 | // This frame has already been acked. |
| 218 | return; |
| 219 | } |
bnc | 20dcfc8 | 2021-06-10 07:13:46 -0700 | [diff] [blame] | 220 | if (!pending_retransmissions_.contains(id)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 221 | pending_retransmissions_[id] = true; |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 222 | QUIC_BUG_IF(quic_bug_12727_2, |
| 223 | pending_retransmissions_.size() > control_frames_.size()) |
fayang | 83d7e3e | 2019-07-31 14:45:19 -0700 | [diff] [blame] | 224 | << "least_unacked_: " << least_unacked_ |
| 225 | << ", least_unsent_: " << least_unsent_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | bool QuicControlFrameManager::IsControlFrameOutstanding( |
| 230 | const QuicFrame& frame) const { |
| 231 | QuicControlFrameId id = GetControlFrameId(frame); |
| 232 | if (id == kInvalidControlFrameId) { |
| 233 | // Frame without a control frame ID should not be retransmitted. |
| 234 | return false; |
| 235 | } |
| 236 | // Consider this frame is outstanding if it does not get acked. |
| 237 | return id < least_unacked_ + control_frames_.size() && id >= least_unacked_ && |
| 238 | GetControlFrameId(control_frames_.at(id - least_unacked_)) != |
| 239 | kInvalidControlFrameId; |
| 240 | } |
| 241 | |
| 242 | bool QuicControlFrameManager::HasPendingRetransmission() const { |
| 243 | return !pending_retransmissions_.empty(); |
| 244 | } |
| 245 | |
| 246 | bool QuicControlFrameManager::WillingToWrite() const { |
| 247 | return HasPendingRetransmission() || HasBufferedFrames(); |
| 248 | } |
| 249 | |
| 250 | QuicFrame QuicControlFrameManager::NextPendingRetransmission() const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 251 | QUIC_BUG_IF(quic_bug_12727_3, pending_retransmissions_.empty()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 252 | << "Unexpected call to NextPendingRetransmission() with empty pending " |
| 253 | << "retransmission list."; |
| 254 | QuicControlFrameId id = pending_retransmissions_.begin()->first; |
| 255 | return control_frames_.at(id - least_unacked_); |
| 256 | } |
| 257 | |
| 258 | void QuicControlFrameManager::OnCanWrite() { |
| 259 | if (HasPendingRetransmission()) { |
| 260 | // Exit early to allow streams to write pending retransmissions if any. |
| 261 | WritePendingRetransmission(); |
| 262 | return; |
| 263 | } |
| 264 | WriteBufferedFrames(); |
| 265 | } |
| 266 | |
renjietang | 4d992bf | 2020-03-03 13:01:55 -0800 | [diff] [blame] | 267 | bool QuicControlFrameManager::RetransmitControlFrame(const QuicFrame& frame, |
| 268 | TransmissionType type) { |
vasilvv | f803516 | 2021-02-01 14:49:14 -0800 | [diff] [blame] | 269 | QUICHE_DCHECK(type == PTO_RETRANSMISSION || type == RTO_RETRANSMISSION || |
| 270 | type == TLP_RETRANSMISSION || type == PROBING_RETRANSMISSION); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 271 | QuicControlFrameId id = GetControlFrameId(frame); |
| 272 | if (id == kInvalidControlFrameId) { |
| 273 | // Frame does not have a valid control frame ID, ignore it. Returns true |
| 274 | // to allow writing following frames. |
| 275 | return true; |
| 276 | } |
| 277 | if (id >= least_unsent_) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 278 | QUIC_BUG(quic_bug_10517_3) << "Try to retransmit unsent control frame"; |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 279 | delegate_->OnControlFrameManagerError( |
| 280 | QUIC_INTERNAL_ERROR, "Try to retransmit unsent control frame"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 281 | return false; |
| 282 | } |
| 283 | if (id < least_unacked_ || |
| 284 | GetControlFrameId(control_frames_.at(id - least_unacked_)) == |
| 285 | kInvalidControlFrameId) { |
| 286 | // This frame has already been acked. |
| 287 | return true; |
| 288 | } |
| 289 | QuicFrame copy = CopyRetransmittableControlFrame(frame); |
| 290 | QUIC_DVLOG(1) << "control frame manager is forced to retransmit frame: " |
| 291 | << frame; |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 292 | if (delegate_->WriteControlFrame(copy, type)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 293 | return true; |
| 294 | } |
| 295 | DeleteFrame(©); |
| 296 | return false; |
| 297 | } |
| 298 | |
| 299 | void QuicControlFrameManager::WriteBufferedFrames() { |
| 300 | while (HasBufferedFrames()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 301 | QuicFrame frame_to_send = |
| 302 | control_frames_.at(least_unsent_ - least_unacked_); |
| 303 | QuicFrame copy = CopyRetransmittableControlFrame(frame_to_send); |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 304 | if (!delegate_->WriteControlFrame(copy, NOT_RETRANSMISSION)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 305 | // Connection is write blocked. |
| 306 | DeleteFrame(©); |
| 307 | break; |
| 308 | } |
| 309 | OnControlFrameSent(frame_to_send); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | void QuicControlFrameManager::WritePendingRetransmission() { |
| 314 | while (HasPendingRetransmission()) { |
| 315 | QuicFrame pending = NextPendingRetransmission(); |
| 316 | QuicFrame copy = CopyRetransmittableControlFrame(pending); |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 317 | if (!delegate_->WriteControlFrame(copy, LOSS_RETRANSMISSION)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 318 | // Connection is write blocked. |
| 319 | DeleteFrame(©); |
| 320 | break; |
| 321 | } |
| 322 | OnControlFrameSent(pending); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | bool QuicControlFrameManager::OnControlFrameIdAcked(QuicControlFrameId id) { |
| 327 | if (id == kInvalidControlFrameId) { |
| 328 | // Frame does not have a valid control frame ID, ignore it. |
| 329 | return false; |
| 330 | } |
| 331 | if (id >= least_unsent_) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 332 | QUIC_BUG(quic_bug_10517_4) << "Try to ack unsent control frame"; |
renjietang | 8ccbf79 | 2020-07-15 16:28:09 -0700 | [diff] [blame] | 333 | delegate_->OnControlFrameManagerError(QUIC_INTERNAL_ERROR, |
| 334 | "Try to ack unsent control frame"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 335 | return false; |
| 336 | } |
| 337 | if (id < least_unacked_ || |
| 338 | GetControlFrameId(control_frames_.at(id - least_unacked_)) == |
| 339 | kInvalidControlFrameId) { |
| 340 | // This frame has already been acked. |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | // Set control frame ID of acked frames to 0. |
| 345 | SetControlFrameId(kInvalidControlFrameId, |
| 346 | &control_frames_.at(id - least_unacked_)); |
| 347 | // Remove acked control frames from pending retransmissions. |
| 348 | pending_retransmissions_.erase(id); |
| 349 | // Clean up control frames queue and increment least_unacked_. |
| 350 | while (!control_frames_.empty() && |
| 351 | GetControlFrameId(control_frames_.front()) == kInvalidControlFrameId) { |
| 352 | DeleteFrame(&control_frames_.front()); |
| 353 | control_frames_.pop_front(); |
| 354 | ++least_unacked_; |
| 355 | } |
| 356 | return true; |
| 357 | } |
| 358 | |
| 359 | bool QuicControlFrameManager::HasBufferedFrames() const { |
| 360 | return least_unsent_ < least_unacked_ + control_frames_.size(); |
| 361 | } |
| 362 | |
| 363 | } // namespace quic |