diff --git a/solanaceae/ngc_ft1/cca.hpp b/solanaceae/ngc_ft1/cca.hpp index 8117bc5..089585c 100644 --- a/solanaceae/ngc_ft1/cca.hpp +++ b/solanaceae/ngc_ft1/cca.hpp @@ -53,7 +53,7 @@ struct CCAI { virtual int64_t canSend(float time_delta) = 0; // get the list of timed out seq_ids - virtual std::vector getTimeouts(void) const = 0; + virtual std::vector getTimeouts(void) = 0; // returns -1 if not implemented, can return 0 virtual int64_t inFlightCount(void) const { return -1; } diff --git a/solanaceae/ngc_ft1/flow_only.cpp b/solanaceae/ngc_ft1/flow_only.cpp index 2135dd7..3ed73f5 100644 --- a/solanaceae/ngc_ft1/flow_only.cpp +++ b/solanaceae/ngc_ft1/flow_only.cpp @@ -86,15 +86,21 @@ int64_t FlowOnly::canSend(float time_delta) { return (fspace / MAXIMUM_SEGMENT_DATA_SIZE) * MAXIMUM_SEGMENT_DATA_SIZE; } -std::vector FlowOnly::getTimeouts(void) const { +std::vector FlowOnly::getTimeouts(void) { std::vector list; list.reserve(_in_flight.size()/3); // we dont know, so we just guess // after 3 rtt delay, we trigger timeout const auto now_adjusted = getTimeNow() - getCurrentDelay()*3.f; - for (const auto& [seq, time_stamp, size, _] : _in_flight) { + for (auto& [seq, time_stamp, size, acc, _] : _in_flight) { if (now_adjusted > time_stamp) { + // make it so timed out packets no longer count as in-flight + if (acc) { + acc = false; + _in_flight_bytes -= size; + assert(_in_flight_bytes >= 0); + } list.push_back(seq); } } @@ -115,7 +121,9 @@ void FlowOnly::onSent(SeqIDType seq, size_t data_size) { size_t sum {0u}; for (const auto& it : _in_flight) { assert(it.id != seq); - sum += it.bytes; + if (it.accounted) { + sum += it.bytes; + } } assert(_in_flight_bytes == sum); } @@ -125,6 +133,7 @@ void FlowOnly::onSent(SeqIDType seq, size_t data_size) { seq, static_cast(getTimeNow()), data_size + SEGMENT_OVERHEAD, + true, false } ); @@ -184,8 +193,10 @@ void FlowOnly::onAck(std::vector seqs) { continue; // not found, ignore } else { //most_recent = std::max(most_recent, std::get<1>(*it)); - _in_flight_bytes -= it->bytes; - assert(_in_flight_bytes >= 0); + if (it->accounted) { + _in_flight_bytes -= it->bytes; + assert(_in_flight_bytes >= 0); + } //_recently_acked_data += std::get<2>(*it); _in_flight.erase(it); } @@ -207,9 +218,14 @@ void FlowOnly::onLoss(SeqIDType seq, bool discard) { // "if data lost is not to be retransmitted" if (discard) { - _in_flight_bytes -= it->bytes; - assert(_in_flight_bytes >= 0); + if (it->accounted) { + _in_flight_bytes -= it->bytes; + assert(_in_flight_bytes >= 0); + } _in_flight.erase(it); + if (_in_flight.empty()) { + assert(_in_flight_bytes == 0); + } } else { // and not take into rtt it->timestamp = getTimeNow(); diff --git a/solanaceae/ngc_ft1/flow_only.hpp b/solanaceae/ngc_ft1/flow_only.hpp index 9db0a2c..1f8fd18 100644 --- a/solanaceae/ngc_ft1/flow_only.hpp +++ b/solanaceae/ngc_ft1/flow_only.hpp @@ -27,7 +27,10 @@ struct FlowOnly : public CCAI { float timestamp; size_t bytes; - // set to true if counted as ce or resent due to timeout + // unset if it does not count torwards _in_flight_bytes + bool accounted {true}; + + // set if counted as ce or resent due to timeout bool ignore {false}; }; std::vector _in_flight; @@ -71,7 +74,7 @@ struct FlowOnly : public CCAI { int64_t canSend(float time_delta) override; // get the list of timed out seq_ids - std::vector getTimeouts(void) const override; + std::vector getTimeouts(void) override; int64_t inFlightCount(void) const override; int64_t inFlightBytes(void) const override; diff --git a/solanaceae/ngc_ft1/ledbat.cpp b/solanaceae/ngc_ft1/ledbat.cpp index fa0b6dc..f56c9d4 100644 --- a/solanaceae/ngc_ft1/ledbat.cpp +++ b/solanaceae/ngc_ft1/ledbat.cpp @@ -47,7 +47,7 @@ int64_t LEDBAT::canSend(float time_delta) { return std::ceil(std::min(cspace, fspace) / MAXIMUM_SEGMENT_DATA_SIZE) * MAXIMUM_SEGMENT_DATA_SIZE; } -std::vector LEDBAT::getTimeouts(void) const { +std::vector LEDBAT::getTimeouts(void) { std::vector list; // after 2 delays we trigger timeout diff --git a/solanaceae/ngc_ft1/ledbat.hpp b/solanaceae/ngc_ft1/ledbat.hpp index 37c6bcd..00edd13 100644 --- a/solanaceae/ngc_ft1/ledbat.hpp +++ b/solanaceae/ngc_ft1/ledbat.hpp @@ -63,7 +63,7 @@ struct LEDBAT : public CCAI { int64_t canSend(float time_delta) override; // get the list of timed out seq_ids - std::vector getTimeouts(void) const override; + std::vector getTimeouts(void) override; public: // callbacks // data size is without overhead