fix front access to empty array

and increase send timeout assert
This commit is contained in:
Green Sky 2024-07-15 11:48:16 +02:00
parent 10756e13ce
commit 489556e322
No known key found for this signature in database
2 changed files with 53 additions and 48 deletions

View File

@ -8,9 +8,10 @@ void SendingTransfers::tick(float delta) {
for (auto it = peer_it->second.begin(); it != peer_it->second.end();) { for (auto it = peer_it->second.begin(); it != peer_it->second.end();) {
it->second.time_since_activity += delta; 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? // 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"; std::cerr << "SHA1_NGCFT1 warning: sending tansfer timed out " << "." << int(it->first) << "\n";
assert(false); assert(false);
it = peer_it->second.erase(it); it = peer_it->second.erase(it);

View File

@ -18,7 +18,8 @@ void transfer_tally_update(ObjectRegistry& os_reg, const float time_now) {
// if newest older than 2sec // if newest older than 2sec
// discard // discard
if (!peer.recently_sent.empty() && time_now - peer.recently_sent.back().time_point >= 2.f) { if (!peer.recently_sent.empty()) {
if (time_now - peer.recently_sent.back().time_point >= 2.f) {
// clean up stale // clean up stale
auto peer_in_stats_it = tss.find(peer_c); auto peer_in_stats_it = tss.find(peer_c);
if (peer_in_stats_it != tss.end()) { if (peer_in_stats_it != tss.end()) {
@ -44,8 +45,10 @@ void transfer_tally_update(ObjectRegistry& os_reg, const float time_now) {
tss[peer_c].rate_up = tally_bytes / (time_now - peer.recently_sent.front().time_point + 0.00001f); 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) { if (!peer.recently_received.empty()) {
if (time_now - peer.recently_received.back().time_point >= 2.f) {
// clean up stale // clean up stale
auto peer_in_stats_it = tss.find(peer_c); auto peer_in_stats_it = tss.find(peer_c);
if (peer_in_stats_it != tss.end()) { if (peer_in_stats_it != tss.end()) {
@ -72,6 +75,7 @@ void transfer_tally_update(ObjectRegistry& os_reg, const float time_now) {
tss[peer_c].rate_down = tally_bytes / (time_now - peer.recently_received.front().time_point + 0.00001f); tss[peer_c].rate_down = tally_bytes / (time_now - peer.recently_received.front().time_point + 0.00001f);
} }
} }
}
for (const auto c : to_remove) { for (const auto c : to_remove) {
tally_comp.tally.erase(c); tally_comp.tally.erase(c);