From c61824d95fd366006d500dd228c1112bf2a66efe Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 11 Aug 2023 12:03:01 +0200 Subject: [PATCH] start with receiving file message --- src/sha1_ngcft1.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ src/sha1_ngcft1.hpp | 1 + 2 files changed, 56 insertions(+) diff --git a/src/sha1_ngcft1.cpp b/src/sha1_ngcft1.cpp index 2360969..1b4df3e 100644 --- a/src/sha1_ngcft1.cpp +++ b/src/sha1_ngcft1.cpp @@ -109,6 +109,7 @@ SHA1_NGCFT1::SHA1_NGCFT1( _nft.subscribe(this, NGCFT1_Event::send_data); _nft.subscribe(this, NGCFT1_Event::recv_done); _nft.subscribe(this, NGCFT1_Event::send_done); + _nft.subscribe(this, NGCFT1_Event::recv_message); //_rmm.subscribe(this, RegistryMessageModel_Event::message_construct); //_rmm.subscribe(this, RegistryMessageModel_Event::message_updated); @@ -378,6 +379,60 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_done& e) { return true; } +bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_message& e) { + if (e.file_kind != NGCFT1_file_kind::HASH_SHA1_INFO) { + return false; + } + + uint64_t ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + + const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number); + const auto self_c = c.get().self; + + auto* reg_ptr = _rmm.get(c); + if (reg_ptr == nullptr) { + std::cerr << "SHA1_NGCFT1 error: cant find reg\n"; + return false; + } + + Message3Registry& reg = *reg_ptr; + // TODO: check for existence, hs or other syncing mechanics might have sent it already (or like, it arrived 2x or whatever) + auto new_msg_e = reg.create(); + + { // contact + // from + reg.emplace(new_msg_e, c); + + // to + reg.emplace(new_msg_e, c.get().parent); + } + + reg.emplace(new_msg_e, e.message_id); + + reg.emplace(new_msg_e); // add sending? + + //reg_ptr->emplace(e, sha1_info); + //reg_ptr->emplace(e, sha1_info_data); // keep around? or file? + reg.emplace(new_msg_e, std::vector{e.file_id, e.file_id+e.file_id_size}); + // TODO: queue info dl + + reg.emplace(new_msg_e, ts); + //reg.emplace(new_msg_e, 0); + reg.emplace(new_msg_e, ts); // reactive? + + { // by whom + auto& synced_by = reg.get_or_emplace(new_msg_e).list; + synced_by.emplace(self_c); + } + + + // TODO: queue info/check if we already have info + + _rmm.throwEventConstruct(reg, new_msg_e); + + return true; // false? +} + bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) { if ( // TODO: add support of offline queuing diff --git a/src/sha1_ngcft1.hpp b/src/sha1_ngcft1.hpp index 9c421b6..3a90d05 100644 --- a/src/sha1_ngcft1.hpp +++ b/src/sha1_ngcft1.hpp @@ -79,6 +79,7 @@ class SHA1_NGCFT1 : public RegistryMessageModelEventI, public NGCFT1EventI { bool onEvent(const Events::NGCFT1_send_data&) override; // const? bool onEvent(const Events::NGCFT1_recv_done&) override; bool onEvent(const Events::NGCFT1_send_done&) override; + bool onEvent(const Events::NGCFT1_recv_message&) override; bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) override; };