From 489556e322c9f5608d3612fe88f31976d16ad6e9 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 15 Jul 2024 11:48:16 +0200 Subject: [PATCH] fix front access to empty array and increase send timeout assert --- solanaceae/ngc_ft1_sha1/sending_transfers.cpp | 5 +- .../ngc_ft1_sha1/transfer_stats_systems.cpp | 96 ++++++++++--------- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/solanaceae/ngc_ft1_sha1/sending_transfers.cpp b/solanaceae/ngc_ft1_sha1/sending_transfers.cpp index beda79f..666590c 100644 --- a/solanaceae/ngc_ft1_sha1/sending_transfers.cpp +++ b/solanaceae/ngc_ft1_sha1/sending_transfers.cpp @@ -8,9 +8,10 @@ void SendingTransfers::tick(float delta) { for (auto it = peer_it->second.begin(); it != peer_it->second.end();) { it->second.time_since_activity += delta; - // if we have not heard for 2min, timeout (lower level event on real timeout) + // if we have not heard for 10min, timeout (lower level event on real timeout) + // (2min was too little, so it seems) // TODO: do we really need this if we get events? - if (it->second.time_since_activity >= 120.f) { + if (it->second.time_since_activity >= 60.f*10.f) { std::cerr << "SHA1_NGCFT1 warning: sending tansfer timed out " << "." << int(it->first) << "\n"; assert(false); it = peer_it->second.erase(it); diff --git a/solanaceae/ngc_ft1_sha1/transfer_stats_systems.cpp b/solanaceae/ngc_ft1_sha1/transfer_stats_systems.cpp index ff1454b..da01847 100644 --- a/solanaceae/ngc_ft1_sha1/transfer_stats_systems.cpp +++ b/solanaceae/ngc_ft1_sha1/transfer_stats_systems.cpp @@ -18,58 +18,62 @@ void transfer_tally_update(ObjectRegistry& os_reg, const float time_now) { // if newest older than 2sec // discard - if (!peer.recently_sent.empty() && time_now - peer.recently_sent.back().time_point >= 2.f) { - // clean up stale - auto peer_in_stats_it = tss.find(peer_c); - if (peer_in_stats_it != tss.end()) { - peer_in_stats_it->second.rate_up = 0.f; - } - - peer.recently_sent.clear(); - if (peer.recently_received.empty()) { - to_remove.push_back(peer_c); - } - } else { - // else trim too old front - peer.trimSent(time_now); - - size_t tally_bytes {0u}; - for (auto& [time, bytes, accounted] : peer.recently_sent) { - if (!accounted) { - tss[peer_c].total_up += bytes; - accounted = true; + if (!peer.recently_sent.empty()) { + if (time_now - peer.recently_sent.back().time_point >= 2.f) { + // clean up stale + auto peer_in_stats_it = tss.find(peer_c); + if (peer_in_stats_it != tss.end()) { + peer_in_stats_it->second.rate_up = 0.f; } - tally_bytes += bytes; - } - tss[peer_c].rate_up = tally_bytes / (time_now - peer.recently_sent.front().time_point + 0.00001f); + peer.recently_sent.clear(); + if (peer.recently_received.empty()) { + to_remove.push_back(peer_c); + } + } else { + // else trim too old front + peer.trimSent(time_now); + + size_t tally_bytes {0u}; + for (auto& [time, bytes, accounted] : peer.recently_sent) { + if (!accounted) { + tss[peer_c].total_up += bytes; + accounted = true; + } + tally_bytes += bytes; + } + + tss[peer_c].rate_up = tally_bytes / (time_now - peer.recently_sent.front().time_point + 0.00001f); + } } - if (!peer.recently_received.empty() && time_now - peer.recently_received.back().time_point >= 2.f) { - // clean up stale - auto peer_in_stats_it = tss.find(peer_c); - if (peer_in_stats_it != tss.end()) { - peer_in_stats_it->second.rate_down = 0.f; - } - - peer.recently_received.clear(); - if (peer.recently_sent.empty()) { - to_remove.push_back(peer_c); - } - } else { - // else trim too old front - peer.trimReceived(time_now); - - size_t tally_bytes {0u}; - for (auto& [time, bytes, accounted] : peer.recently_received) { - if (!accounted) { - tss[peer_c].total_down += bytes; - accounted = true; + if (!peer.recently_received.empty()) { + if (time_now - peer.recently_received.back().time_point >= 2.f) { + // clean up stale + auto peer_in_stats_it = tss.find(peer_c); + if (peer_in_stats_it != tss.end()) { + peer_in_stats_it->second.rate_down = 0.f; } - tally_bytes += bytes; - } - tss[peer_c].rate_down = tally_bytes / (time_now - peer.recently_received.front().time_point + 0.00001f); + peer.recently_received.clear(); + if (peer.recently_sent.empty()) { + to_remove.push_back(peer_c); + } + } else { + // else trim too old front + peer.trimReceived(time_now); + + size_t tally_bytes {0u}; + for (auto& [time, bytes, accounted] : peer.recently_received) { + if (!accounted) { + tss[peer_c].total_down += bytes; + accounted = true; + } + tally_bytes += bytes; + } + + tss[peer_c].rate_down = tally_bytes / (time_now - peer.recently_received.front().time_point + 0.00001f); + } } }