From b35babe3f869c3213c7ee838db8ed114df8e9712 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sun, 15 Dec 2024 01:23:08 +0100 Subject: [PATCH] switch to os provided remote have set and other fixes --- solanaceae/ngc_ft1_sha1/chunk_picker.cpp | 4 +-- solanaceae/ngc_ft1_sha1/components.hpp | 8 ----- solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp | 41 +++++++++++++----------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/solanaceae/ngc_ft1_sha1/chunk_picker.cpp b/solanaceae/ngc_ft1_sha1/chunk_picker.cpp index 2288741..c308174 100644 --- a/solanaceae/ngc_ft1_sha1/chunk_picker.cpp +++ b/solanaceae/ngc_ft1_sha1/chunk_picker.cpp @@ -272,7 +272,7 @@ std::vector ChunkPicker::updateChunkRequests( ObjectHandle o {objreg, it->first}; // intersect self have with other have - if (!o.all_of()) { + if (!o.all_of()) { // rare case where no one else has anything continue; } @@ -284,7 +284,7 @@ std::vector ChunkPicker::updateChunkRequests( //const auto& cc = o.get(); - const auto& others_have = o.get().others; + const auto& others_have = o.get().others; auto other_it = others_have.find(c); if (other_it == others_have.end()) { // rare case where the other is participating but has nothing diff --git a/solanaceae/ngc_ft1_sha1/components.hpp b/solanaceae/ngc_ft1_sha1/components.hpp index ad13a02..a44932e 100644 --- a/solanaceae/ngc_ft1_sha1/components.hpp +++ b/solanaceae/ngc_ft1_sha1/components.hpp @@ -70,14 +70,6 @@ namespace Components { entt::dense_set participants; }; - struct RemoteHaveBitset { - struct Entry { - bool have_all {false}; - BitSet have; - }; - entt::dense_map others; - }; - struct ReRequestInfoTimer { float timer {0.f}; }; diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index 5654463..e3df546 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -1256,11 +1256,15 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_done& e) { auto& transfer = _sending_transfers.getTransfer(e.group_number, e.peer_number, e.transfer_id); if (transfer.isChunk()) { + // we could cheat here and assume remote has chunk now + _os.throwEventUpdate(transfer.getChunk().content); + updateMessages(transfer.getChunk().content); // mostly for sent bytes - } + } // ignore info transfer for now _sending_transfers.removePeerTransfer(e.group_number, e.peer_number, e.transfer_id); + return true; } @@ -1403,8 +1407,8 @@ bool SHA1_NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) { 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); } } } @@ -1463,19 +1467,15 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have& e) { const size_t num_total_chunks = o.get().chunks.size(); - auto& remote_have = o.get_or_emplace().others; + auto& remote_have = o.get_or_emplace().others; if (!remote_have.contains(c)) { // init - remote_have.emplace(c, Components::RemoteHaveBitset::Entry{false, num_total_chunks}); + remote_have.emplace(c, ObjComp::F::RemoteHaveBitset::Entry{false, num_total_chunks}); // new have? nice //c.emplace_or_replace(); } - if (o.all_of()) { - return true; // we dont care beyond this point - } - auto& remote_have_peer = remote_have.at(c); if (remote_have_peer.have_all) { return true; // peer somehow already had all, ignoring @@ -1496,11 +1496,6 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have& e) { a_valid_change = true; } - if (a_valid_change) { - // new have? nice - c.emplace_or_replace(); - } - // check for completion? // TODO: optimize bool test_all {true}; @@ -1517,6 +1512,15 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have& e) { remote_have_peer.have = BitSet{}; } + if (o.all_of()) { + return true; // we dont care beyond this point + } + + if (a_valid_change) { + // new have? nice + c.emplace_or_replace(); + } + return true; } @@ -1566,15 +1570,16 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_bitset& e) { return false; } - auto& remote_have = o.get_or_emplace().others; + auto& remote_have = o.get_or_emplace().others; if (!remote_have.contains(c)) { // init - remote_have.emplace(c, Components::RemoteHaveBitset::Entry{false, num_total_chunks}); + remote_have.emplace(c, ObjComp::F::RemoteHaveBitset::Entry{false, num_total_chunks}); } auto& remote_have_peer = remote_have.at(c); if (!remote_have_peer.have_all) { // TODO: maybe unset with bitset? BitSet event_bitset{e.chunk_bitset}; + // TODO: range replace instead remote_have_peer.have.merge(event_bitset, e.start_chunk); // check for completion? @@ -1629,8 +1634,8 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have_all& e) { // we might not know yet addParticipation(c, o); - auto& remote_have = o.get_or_emplace().others; - remote_have[c] = Components::RemoteHaveBitset::Entry{true, {}}; + auto& remote_have = o.get_or_emplace().others; + remote_have[c] = ObjComp::F::RemoteHaveBitset::Entry{true, {}}; // new have? nice c.emplace_or_replace();