From 269daaa764605df6a020e96a9b7410369713f747 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sun, 7 Jul 2024 14:15:26 +0200 Subject: [PATCH] work around missing contact events and properly clear on exit --- solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp | 43 +++++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index 7a3b4f3..160c392 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -394,8 +394,16 @@ float SHA1_NGCFT1::iterate(float delta) { } // new chunk picker code - _cr.view().each([this, &_peer_open_requests](const Contact3 cv, ChunkPicker& cp) { + // HACK: work around missing contact events + std::vector cp_to_remove; + _cr.view().each([this, &_peer_open_requests, &cp_to_remove](const Contact3 cv, ChunkPicker& cp) { Contact3Handle c{_cr, cv}; + + if (!c.all_of()) { + cp_to_remove.push_back(c); + return; + } + // HACK: expensive, dont do every tick, only on events // do verification in debug instead? cp.updateParticipation( @@ -437,6 +445,18 @@ float SHA1_NGCFT1::iterate(float delta) { std::cout << "SHA1_NGCFT1: requesting chunk [" << info.chunks.at(r_idx) << "] from " << group_number << ":" << peer_number << "\n"; } }); + + for (const auto& c : cp_to_remove) { + c.remove(); + + for (const auto& [_, o] : _info_to_content) { + removeParticipation(c, o); + + if (o.all_of()) { + o.get().others.erase(c); + } + } + } } if (_peer_open_requests.empty()) { @@ -1423,18 +1443,21 @@ bool SHA1_NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) { // peer disconnected // - remove from all participantions - auto c = _tcm.getContactGroupPeer(group_number, peer_number); - if (!static_cast(c)) { - return false; - } + { + // FIXME: this does not work, tcm just delteded the relation ship + auto c = _tcm.getContactGroupPeer(group_number, peer_number); + if (!static_cast(c)) { + return false; + } - c.remove(); + c.remove(); - for (const auto& [_, o] : _info_to_content) { - removeParticipation(c, o); + for (const auto& [_, o] : _info_to_content) { + removeParticipation(c, o); - if (o.all_of()) { - o.get().others.erase(c); + if (o.all_of()) { + o.get().others.erase(c); + } } }