From eb169b27794903d25938e2999576baee20dadae9 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 11 Dec 2024 23:23:05 +0100 Subject: [PATCH] add participation and log spam fix --- solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp | 13 ++++++++++--- solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp | 3 +-- solanaceae/ngc_hs2/ts_find_start.hpp | 6 +++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index e8c3d76..cd5516b 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -560,9 +560,9 @@ void SHA1_NGCFT1::onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_p updateMessages(o); // nop // TODO: remove } -void SHA1_NGCFT1::constructFileMessageInPlace(Message3Handle msg, NGCFT1_file_kind file_kind, ByteSpan file_id) { +ObjectHandle SHA1_NGCFT1::constructFileMessageInPlace(Message3Handle msg, NGCFT1_file_kind file_kind, ByteSpan file_id) { if (file_kind != NGCFT1_file_kind::HASH_SHA1_INFO) { - return; + return {}; } // check if content exists @@ -624,6 +624,8 @@ void SHA1_NGCFT1::constructFileMessageInPlace(Message3Handle msg, NGCFT1_file_ki } _os.throwEventUpdate(o); + + return o; } bool SHA1_NGCFT1::onEvent(const ObjectStore::Events::ObjectUpdate& e) { @@ -1304,7 +1306,12 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_message& e) { rb.try_emplace(self_c, ts); } - constructFileMessageInPlace({reg, new_msg_e}, e.file_kind, {e.file_id, e.file_id_size}); + auto o = constructFileMessageInPlace({reg, new_msg_e}, e.file_kind, {e.file_id, e.file_id_size}); + + if (o) { + // the other peer just sent the file message, so it is likely they have the file + addParticipation(c, o); + } _rmm.throwEventConstruct(reg, new_msg_e); diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp index 30d4e59..49ac9af 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp @@ -108,8 +108,7 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public void onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_ptr, Contact3 c, uint64_t ts); // construct the file part in a partially constructed message - // TODO: maybe return file object? - void constructFileMessageInPlace(Message3Handle msg, NGCFT1_file_kind file_kind, ByteSpan file_id); + ObjectHandle constructFileMessageInPlace(Message3Handle msg, NGCFT1_file_kind file_kind, ByteSpan file_id); protected: // rmm events (actions) bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) override; diff --git a/solanaceae/ngc_hs2/ts_find_start.hpp b/solanaceae/ngc_hs2/ts_find_start.hpp index 6ff86e8..aa59f24 100644 --- a/solanaceae/ngc_hs2/ts_find_start.hpp +++ b/solanaceae/ngc_hs2/ts_find_start.hpp @@ -8,7 +8,7 @@ // perform binary search to find the first message not newer than ts_start template auto find_start_by_ts(const View& view, uint64_t ts_start) { - std::cout << "!!!! starting msg ts search, ts_start:" << ts_start << "\n"; + //std::cout << "!!!! starting msg ts search, ts_start:" << ts_start << "\n"; // -> first value smaller than start ts auto res = std::lower_bound( @@ -22,9 +22,9 @@ auto find_start_by_ts(const View& view, uint64_t ts_start) { if (res != view.end()) { const auto& [ts_comp] = view.get(*res); - std::cout << "!!!! first value not newer than start ts is " << ts_comp.ts << "\n"; + //std::cout << "!!!! first value not newer than start ts is " << ts_comp.ts << "\n"; } else { - std::cout << "!!!! no first value not newer than start ts\n"; + //std::cout << "!!!! no first value not newer than start ts\n"; } return res; }