dcsctp: Refactor chunk lifecycle state flag

This CL replaces two booleans, that could never be active at the same
time (there is no such thing as an abandoned chunk that is scheduled
for retransmission), with a single enum.

Just for increased readability, and to understand that there is no such
thing as an abandoned chunk that will be retransmitted.

Bug: None
Change-Id: I1682c383aed692db07fd4ae1f84c0166db86c062
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/259864
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36707}
This commit is contained in:
Victor Boivie 2022-04-20 23:27:18 +02:00 committed by WebRTC LUCI CQ
parent 79d566b0cf
commit 8ec4a2eca3
2 changed files with 30 additions and 19 deletions

View File

@ -31,8 +31,8 @@ size_t OutstandingData::GetSerializedChunkSize(const Data& data) const {
}
void OutstandingData::Item::Ack() {
lifecycle_ = Lifecycle::kActive;
ack_state_ = AckState::kAcked;
should_be_retransmitted_ = false;
}
OutstandingData::Item::NackAction OutstandingData::Item::Nack(
@ -43,7 +43,7 @@ OutstandingData::Item::NackAction OutstandingData::Item::Nack(
(retransmit_now || nack_count_ >= kNumberOfNacksForRetransmission)) {
// Nacked enough times - it's considered lost.
if (num_retransmissions_ < *max_retransmissions_) {
should_be_retransmitted_ = true;
lifecycle_ = Lifecycle::kToBeRetransmitted;
return NackAction::kRetransmit;
}
Abandon();
@ -52,17 +52,16 @@ OutstandingData::Item::NackAction OutstandingData::Item::Nack(
return NackAction::kNothing;
}
void OutstandingData::Item::Retransmit() {
void OutstandingData::Item::MarkAsRetransmitted() {
lifecycle_ = Lifecycle::kActive;
ack_state_ = AckState::kUnacked;
should_be_retransmitted_ = false;
nack_count_ = 0;
++num_retransmissions_;
}
void OutstandingData::Item::Abandon() {
is_abandoned_ = true;
should_be_retransmitted_ = false;
lifecycle_ = Lifecycle::kAbandoned;
}
bool OutstandingData::Item::has_expired(TimeMs now) const {
@ -295,7 +294,7 @@ std::vector<std::pair<TSN, Data>> OutstandingData::GetChunksToBeRetransmitted(
size_t serialized_size = GetSerializedChunkSize(item.data());
if (serialized_size <= max_size) {
item.Retransmit();
item.MarkAsRetransmitted();
result.emplace_back(tsn.Wrap(), item.data().Clone());
max_size -= serialized_size;
outstanding_bytes_ += serialized_size;

View File

@ -171,7 +171,7 @@ class OutstandingData {
// Prepares the item to be retransmitted. Sets it as outstanding and
// clears all nack counters.
void Retransmit();
void MarkAsRetransmitted();
// Marks this item as abandoned.
void Abandon();
@ -179,10 +179,12 @@ class OutstandingData {
bool is_outstanding() const { return ack_state_ == AckState::kUnacked; }
bool is_acked() const { return ack_state_ == AckState::kAcked; }
bool is_nacked() const { return ack_state_ == AckState::kNacked; }
bool is_abandoned() const { return is_abandoned_; }
bool is_abandoned() const { return lifecycle_ == Lifecycle::kAbandoned; }
// Indicates if this chunk should be retransmitted.
bool should_be_retransmitted() const { return should_be_retransmitted_; }
bool should_be_retransmitted() const {
return lifecycle_ == Lifecycle::kToBeRetransmitted;
}
// Indicates if this chunk has ever been retransmitted.
bool has_been_retransmitted() const { return num_retransmissions_ > 0; }
@ -191,18 +193,28 @@ class OutstandingData {
bool has_expired(TimeMs now) const;
private:
enum class AckState {
kUnacked,
kAcked,
kNacked,
enum class Lifecycle {
// The chunk is alive (sent, received, etc)
kActive,
// The chunk is scheduled to be retransmitted, and will then transition to
// become active.
kToBeRetransmitted,
// The chunk has been abandoned. This is a terminal state.
kAbandoned
};
enum class AckState {
// The chunk is in-flight.
kUnacked,
// The chunk has been received and acknowledged.
kAcked,
// The chunk has been nacked and is possibly lost.
kNacked
};
// Indicates the life cycle status of this chunk.
Lifecycle lifecycle_ = Lifecycle::kActive;
// Indicates the presence of this chunk, if it's in flight (Unacked), has
// been received (Acked) or is lost (Nacked).
// been received (Acked) or is possibly lost (Nacked).
AckState ack_state_ = AckState::kUnacked;
// Indicates if this chunk has been abandoned, which is a terminal state.
bool is_abandoned_ = false;
// Indicates if this chunk should be retransmitted.
bool should_be_retransmitted_ = false;
// The number of times the DATA chunk has been nacked (by having received a
// SACK which doesn't include it). Will be cleared on retransmissions.