diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index 0b49ad3..391fa5b 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace Message::Components { @@ -253,7 +254,7 @@ SHA1_NGCFT1::SHA1_NGCFT1( NGCFT1& nft, ToxContactModel2& tcm, ToxEventProviderI& tep, - NGCEXTEventProviderI& neep + NGCEXTEventProvider& neep ) : _os(os), _cr(cr), @@ -641,6 +642,34 @@ bool SHA1_NGCFT1::onEvent(const Message::Events::MessageUpdated& e) { ce.emplace(std::move(file_impl)); + // announce we are participating + // since this is the first time, we publicly announce to all + if (e.e.all_of()) { + const auto c_f = e.e.get().c; + const auto c_t = e.e.get().c; + + std::vector announce_id; + const uint32_t file_kind = static_cast(NGCFT1_file_kind::HASH_SHA1_INFO); + for (size_t i = 0; i < sizeof(file_kind); i++) { + announce_id.push_back((file_kind>>(i*8)) & 0xff); + } + assert(ce.all_of()); + const auto& info_hash = ce.get().hash; + announce_id.insert(announce_id.cend(), info_hash.cbegin(), info_hash.cend()); + + if (_cr.all_of(c_t)) { + // public + const auto group_number = _cr.get(c_t).group_number; + + _neep.send_all_pc1_announce(group_number, announce_id.data(), announce_id.size()); + } else if (_cr.all_of(c_f)) { + // private ? + const auto [group_number, peer_number] = _cr.get(c_f); + + _neep.send_pc1_announce(group_number, peer_number, announce_id.data(), announce_id.size()); + } + } + ce.remove(); // should? @@ -1067,6 +1096,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_message& e) { 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) + // TODO: use the message dup test provided via rmm auto new_msg_e = reg.create(); { // contact @@ -1469,6 +1499,7 @@ bool SHA1_NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) { } bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_pc1_announce& e) { + std::cerr << "SHA1_NGCFT1: PC1_ANNOUNCE s:" << e.id.size() << "\n"; // id is file_kind + id uint32_t file_kind = 0u; diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp index 81c04bc..92dabd3 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp @@ -29,7 +29,7 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public NGCFT1& _nft; ToxContactModel2& _tcm; ToxEventProviderI& _tep; - NGCEXTEventProviderI& _neep; + NGCEXTEventProvider& _neep; std::minstd_rand _rng {1337*11}; @@ -126,7 +126,7 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public NGCFT1& nft, ToxContactModel2& tcm, ToxEventProviderI& tep, - NGCEXTEventProviderI& neep + NGCEXTEventProvider& neep ); void iterate(float delta);