From 78390dd342344c92e136f7a38b63615f0d77a8ae Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 13 Dec 2024 01:30:03 +0100 Subject: [PATCH] update object, object update lock and rare crash --- solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp | 23 ++++++++++++++++++++--- solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index cd5516b..5654463 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -629,6 +629,10 @@ ObjectHandle SHA1_NGCFT1::constructFileMessageInPlace(Message3Handle msg, NGCFT1 } bool SHA1_NGCFT1::onEvent(const ObjectStore::Events::ObjectUpdate& e) { + if (_object_update_lock) { + return false; + } + if (!e.e.all_of()) { return false; } @@ -637,10 +641,17 @@ bool SHA1_NGCFT1::onEvent(const ObjectStore::Events::ObjectUpdate& e) { // not ready to load yet, skip return false; } + + if (e.e.all_of()) { + // now we update on recv_done, which included info + std::cerr << "SHA1_NGCFT1 warning: accepted but already has FT1ChunkSHA1Cache\n"; + return false; + } + + _object_update_lock = true; + assert(!e.e.all_of()); - assert(!e.e.all_of()); assert(!e.e.all_of()); - //accept(e.e, e.e.get().save_to_path); // first, open file for write(+readback) std::string full_file_path{e.e.get().save_to_path}; @@ -665,6 +676,7 @@ bool SHA1_NGCFT1::onEvent(const ObjectStore::Events::ObjectUpdate& e) { std::cerr << "SHA1_NGCFT1 error: failed opening file '" << full_file_path << "'!\n"; // we failed opening that filepath, so we should offer the user the oportunity to save it differently e.e.remove(); // stop + _object_update_lock = false; return false; } @@ -743,6 +755,7 @@ bool SHA1_NGCFT1::onEvent(const ObjectStore::Events::ObjectUpdate& e) { updateMessages(e.e); + _object_update_lock = false; return false; // ? } @@ -1111,11 +1124,13 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_done& e) { o.emplace_or_replace(); + _os.throwEventUpdate(o); + updateMessages(o); } else if (transfer.isChunk()) { auto o = transfer.getChunk().content; const auto& info = o.get(); - auto& cc = o.get(); + auto& cc = o.get(); // is this assumption save? // HACK: only check first chunk (they *should* all be the same) const auto chunk_index = transfer.getChunk().chunk_indices.front(); @@ -1223,6 +1238,8 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_done& e) { o.get_or_emplace().chunks.erase(it); } + _os.throwEventUpdate(o); + updateMessages(o); // mostly for received bytes } diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp index 49ac9af..2897e99 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp @@ -37,6 +37,8 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public Backends::SHA1MappedFilesystem _mfb; + bool _object_update_lock {false}; + std::minstd_rand _rng {1337*11}; using clock = std::chrono::steady_clock;