From b9f8636c5a4dc3e9f3cf305d01afd9ef3d72ce9f Mon Sep 17 00:00:00 2001 From: Victor Boivie Date: Tue, 18 Feb 2025 11:27:22 +0100 Subject: [PATCH] dcsctp: Fix incorrect merge conflict from last CL A refactoring was lost after revision 3 of https://webrtc-review.googlesource.com/c/src/+/377122 due to an incorrect merging/cherry-picking. Reapplied it. Bug: webrtc:396373001 Change-Id: Ice7a8e94ad984cb308eb9cab83df2e9ecca3d53c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/377283 Commit-Queue: Victor Boivie Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#43912} --- net/dcsctp/tx/retransmission_queue.cc | 36 ++++++++++++--------------- net/dcsctp/tx/retransmission_queue.h | 4 --- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/net/dcsctp/tx/retransmission_queue.cc b/net/dcsctp/tx/retransmission_queue.cc index d81c912c5e..65b572e18e 100644 --- a/net/dcsctp/tx/retransmission_queue.cc +++ b/net/dcsctp/tx/retransmission_queue.cc @@ -456,12 +456,23 @@ std::vector> RetransmissionQueue::GetChunksToSend( size_t old_unacked_packet_bytes = unacked_packet_bytes(); size_t old_rwnd = rwnd_; - // Calculate the bandwidth budget (how many bytes that is - // allowed to be sent), and fill that up first with chunks that are - // scheduled to be retransmitted. If there is still budget, send new chunks - // (which will have their TSN assigned here.) + // Calculate the bandwidth budget (how many bytes that is allowed to be sent). + size_t max_packet_bytes_allowed_by_cwnd = + old_unacked_packet_bytes >= cwnd_ ? 0 : cwnd_ - old_unacked_packet_bytes; + size_t max_packet_bytes_allowed_by_rwnd = + RoundUpTo4(rwnd() + data_chunk_header_size_); + + if (outstanding_data_.unacked_items() == 0) { + // https://datatracker.ietf.org/doc/html/rfc4960#section-6.1 + // ... However, regardless of the value of rwnd (including if it is 0), the + // data sender can always have one DATA chunk in flight to the receiver if + // allowed by cwnd (see rule B, below). + max_packet_bytes_allowed_by_rwnd = options_.mtu; + } size_t max_bytes = - RoundDownTo4(std::min(max_bytes_to_send(), bytes_remaining_in_packet)); + RoundDownTo4(std::min(std::min(max_packet_bytes_allowed_by_cwnd, + max_packet_bytes_allowed_by_rwnd), + bytes_remaining_in_packet)); to_be_sent = outstanding_data_.GetChunksToBeRetransmitted(max_bytes); @@ -544,21 +555,6 @@ bool RetransmissionQueue::ShouldSendForwardTsn(Timestamp now) { return ret; } -size_t RetransmissionQueue::max_bytes_to_send() const { - size_t left = - unacked_packet_bytes() >= cwnd_ ? 0 : cwnd_ - unacked_packet_bytes(); - - if (unacked_packet_bytes() == 0) { - // https://datatracker.ietf.org/doc/html/rfc4960#section-6.1 - // ... However, regardless of the value of rwnd (including if it is 0), the - // data sender can always have one DATA chunk in flight to the receiver if - // allowed by cwnd (see rule B, below). - return left; - } - - return std::min(rwnd(), left); -} - void RetransmissionQueue::PrepareResetStream(StreamID stream_id) { // TODO(boivie): These calls are now only affecting the send queue. The // packet buffer can also change behavior - for example draining the chunk diff --git a/net/dcsctp/tx/retransmission_queue.h b/net/dcsctp/tx/retransmission_queue.h index 69e0ba28f0..4d8766c148 100644 --- a/net/dcsctp/tx/retransmission_queue.h +++ b/net/dcsctp/tx/retransmission_queue.h @@ -210,10 +210,6 @@ class RetransmissionQueue { : CongestionAlgorithmPhase::kCongestionAvoidance; } - // Returns the number of bytes that may be sent in a single packet according - // to the congestion control algorithm. - size_t max_bytes_to_send() const; - DcSctpSocketCallbacks& callbacks_; const DcSctpOptions options_; // If the peer supports RFC3758 - SCTP Partial Reliability Extension.