diff options
Diffstat (limited to 'net/dcsctp/tx/outstanding_data.cc')
-rw-r--r-- | net/dcsctp/tx/outstanding_data.cc | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/net/dcsctp/tx/outstanding_data.cc b/net/dcsctp/tx/outstanding_data.cc index c65c195432..30d83870e3 100644 --- a/net/dcsctp/tx/outstanding_data.cc +++ b/net/dcsctp/tx/outstanding_data.cc @@ -14,12 +14,15 @@ #include <utility> #include <vector> +#include "api/units/time_delta.h" +#include "api/units/timestamp.h" #include "net/dcsctp/common/math.h" #include "net/dcsctp/common/sequence_numbers.h" #include "net/dcsctp/public/types.h" #include "rtc_base/logging.h" namespace dcsctp { +using ::webrtc::Timestamp; // The number of times a packet must be NACKed before it's retransmitted. // See https://tools.ietf.org/html/rfc4960#section-7.2.4 @@ -63,10 +66,12 @@ void OutstandingData::Item::MarkAsRetransmitted() { } void OutstandingData::Item::Abandon() { + RTC_DCHECK(!expires_at_.IsPlusInfinity() || + max_retransmissions_ != MaxRetransmits::NoLimit()); lifecycle_ = Lifecycle::kAbandoned; } -bool OutstandingData::Item::has_expired(TimeMs now) const { +bool OutstandingData::Item::has_expired(Timestamp now) const { return expires_at_ <= now; } @@ -252,6 +257,7 @@ bool OutstandingData::NackItem(UnwrappedTSN tsn, RTC_DLOG(LS_VERBOSE) << *tsn.Wrap() << " marked for retransmission"; break; case Item::NackAction::kAbandon: + RTC_DLOG(LS_VERBOSE) << *tsn.Wrap() << " Nacked, resulted in abandoning"; AbandonAllFor(item); break; } @@ -260,8 +266,7 @@ bool OutstandingData::NackItem(UnwrappedTSN tsn, void OutstandingData::AbandonAllFor(const Item& item) { // Erase all remaining chunks from the producer, if any. - if (discard_from_send_queue_(item.data().is_unordered, item.data().stream_id, - item.data().message_id)) { + if (discard_from_send_queue_(item.data().stream_id, item.message_id())) { // There were remaining chunks to be produced for this message. Since the // receiver may have already received all chunks (up till now) for this // message, we can't just FORWARD-TSN to the last fragment in this @@ -272,17 +277,17 @@ void OutstandingData::AbandonAllFor(const Item& item) { // TSN in the sent FORWARD-TSN. UnwrappedTSN tsn = next_tsn_; next_tsn_.Increment(); - Data message_end(item.data().stream_id, item.data().ssn, - item.data().message_id, item.data().fsn, item.data().ppid, - std::vector<uint8_t>(), Data::IsBeginning(false), - Data::IsEnd(true), item.data().is_unordered); + Data message_end(item.data().stream_id, item.data().ssn, item.data().mid, + item.data().fsn, item.data().ppid, std::vector<uint8_t>(), + Data::IsBeginning(false), Data::IsEnd(true), + item.data().is_unordered); Item& added_item = outstanding_data_ .emplace(std::piecewise_construct, std::forward_as_tuple(tsn), - std::forward_as_tuple(std::move(message_end), TimeMs(0), - MaxRetransmits::NoLimit(), - TimeMs::InfiniteFuture(), - LifecycleId::NotSet())) + std::forward_as_tuple( + item.message_id(), std::move(message_end), + Timestamp::Zero(), MaxRetransmits(0), + Timestamp::PlusInfinity(), LifecycleId::NotSet())) .first->second; // The added chunk shouldn't be included in `outstanding_bytes`, so set it // as acked. @@ -294,8 +299,7 @@ void OutstandingData::AbandonAllFor(const Item& item) { for (auto& [tsn, other] : outstanding_data_) { if (!other.is_abandoned() && other.data().stream_id == item.data().stream_id && - other.data().is_unordered == item.data().is_unordered && - other.data().message_id == item.data().message_id) { + other.message_id() == item.message_id()) { RTC_DLOG(LS_VERBOSE) << "Marking chunk " << *tsn.Wrap() << " as abandoned"; if (other.should_be_retransmitted()) { @@ -369,7 +373,7 @@ std::vector<std::pair<TSN, Data>> OutstandingData::GetChunksToBeRetransmitted( return ExtractChunksThatCanFit(to_be_retransmitted_, max_size); } -void OutstandingData::ExpireOutstandingChunks(TimeMs now) { +void OutstandingData::ExpireOutstandingChunks(Timestamp now) { for (const auto& [tsn, item] : outstanding_data_) { // Chunks that are nacked can be expired. Care should be taken not to expire // unacked (in-flight) chunks as they might have been received, but the SACK @@ -378,7 +382,7 @@ void OutstandingData::ExpireOutstandingChunks(TimeMs now) { // Already abandoned. } else if (item.is_nacked() && item.has_expired(now)) { RTC_DLOG(LS_VERBOSE) << "Marking nacked chunk " << *tsn.Wrap() - << " and message " << *item.data().message_id + << " and message " << *item.data().mid << " as expired"; AbandonAllFor(item); } else { @@ -395,10 +399,11 @@ UnwrappedTSN OutstandingData::highest_outstanding_tsn() const { } absl::optional<UnwrappedTSN> OutstandingData::Insert( + OutgoingMessageId message_id, const Data& data, - TimeMs time_sent, + Timestamp time_sent, MaxRetransmits max_retransmissions, - TimeMs expires_at, + Timestamp expires_at, LifecycleId lifecycle_id) { UnwrappedTSN tsn = next_tsn_; next_tsn_.Increment(); @@ -409,9 +414,9 @@ absl::optional<UnwrappedTSN> OutstandingData::Insert( ++outstanding_items_; auto it = outstanding_data_ .emplace(std::piecewise_construct, std::forward_as_tuple(tsn), - std::forward_as_tuple(data.Clone(), time_sent, - max_retransmissions, expires_at, - lifecycle_id)) + std::forward_as_tuple(message_id, data.Clone(), + time_sent, max_retransmissions, + expires_at, lifecycle_id)) .first; if (it->second.has_expired(time_sent)) { @@ -419,7 +424,7 @@ absl::optional<UnwrappedTSN> OutstandingData::Insert( // queue. RTC_DLOG(LS_VERBOSE) << "Marking freshly produced chunk " << *it->first.Wrap() << " and message " - << *it->second.data().message_id << " as expired"; + << *it->second.data().mid << " as expired"; AbandonAllFor(it->second); RTC_DCHECK(IsConsistent()); return absl::nullopt; @@ -439,8 +444,8 @@ void OutstandingData::NackAll() { RTC_DCHECK(IsConsistent()); } -absl::optional<DurationMs> OutstandingData::MeasureRTT(TimeMs now, - UnwrappedTSN tsn) const { +webrtc::TimeDelta OutstandingData::MeasureRTT(Timestamp now, + UnwrappedTSN tsn) const { auto it = outstanding_data_.find(tsn); if (it != outstanding_data_.end() && !it->second.has_been_retransmitted()) { // https://tools.ietf.org/html/rfc4960#section-6.3.1 @@ -450,7 +455,7 @@ absl::optional<DurationMs> OutstandingData::MeasureRTT(TimeMs now, // later instance)" return now - it->second.time_sent(); } - return absl::nullopt; + return webrtc::TimeDelta::PlusInfinity(); } std::vector<std::pair<TSN, OutstandingData::State>> @@ -522,15 +527,15 @@ IForwardTsnChunk OutstandingData::CreateIForwardTsn() const { std::pair<IsUnordered, StreamID> stream_id = std::make_pair(item.data().is_unordered, item.data().stream_id); - if (item.data().message_id > skipped_per_stream[stream_id]) { - skipped_per_stream[stream_id] = item.data().message_id; + if (item.data().mid > skipped_per_stream[stream_id]) { + skipped_per_stream[stream_id] = item.data().mid; } } std::vector<IForwardTsnChunk::SkippedStream> skipped_streams; skipped_streams.reserve(skipped_per_stream.size()); - for (const auto& [stream, message_id] : skipped_per_stream) { - skipped_streams.emplace_back(stream.first, stream.second, message_id); + for (const auto& [stream, mid] : skipped_per_stream) { + skipped_streams.emplace_back(stream.first, stream.second, mid); } return IForwardTsnChunk(new_cumulative_ack.Wrap(), |