diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index da214ba..e0e6b1a 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -114,7 +114,7 @@ void SHA1_NGCFT1::updateMessages(ObjectHandle ce) { } } -bool SHA1_NGCFT1::addParticipation(Contact3 c, ObjectHandle o) { +bool SHA1_NGCFT1::addParticipation(Contact3Handle c, ObjectHandle o) { bool was_new {false}; if (static_cast(o)) { @@ -122,25 +122,25 @@ bool SHA1_NGCFT1::addParticipation(Contact3 c, ObjectHandle o) { was_new = inserted; } - if (_cr.valid(c)) { - const auto [_, inserted] = _cr.get_or_emplace(c).participating.emplace(o); + if (static_cast(c)) { + const auto [_, inserted] = c.get_or_emplace().participating.emplace(o); was_new = was_new || inserted; // TODO: if not have_all - _cr.get_or_emplace(c).participating_unfinished.emplace(o, ChunkPicker::ParticipationEntry{}); + c.get_or_emplace().participating_unfinished.emplace(o, ChunkPicker::ParticipationEntry{}); } return was_new; } -void SHA1_NGCFT1::removeParticipation(Contact3 c, ObjectHandle o) { +void SHA1_NGCFT1::removeParticipation(Contact3Handle c, ObjectHandle o) { if (static_cast(o) && o.all_of()) { o.get().participants.erase(c); } - if (_cr.valid(c) && _cr.all_of(c)) { - _cr.get(c).participating.erase(o); - _cr.get(c).participating_unfinished.erase(o); + if (static_cast(c) && c.all_of()) { + c.get().participating.erase(o); + c.get().participating_unfinished.erase(o); } } @@ -1474,16 +1474,16 @@ bool SHA1_NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) { // peer disconnected // - remove from all participantions - auto ch = _tcm.getContactGroupPeer(group_number, peer_number); - if (!static_cast(ch)) { + auto c = _tcm.getContactGroupPeer(group_number, peer_number); + if (!static_cast(c)) { return false; } - for (const auto& [_, h] : _info_to_content) { - removeParticipation(ch, h); + for (const auto& [_, o] : _info_to_content) { + removeParticipation(c, o); - if (h.all_of()) { - h.get().others.erase(ch); + if (o.all_of()) { + o.get().others.erase(c); } } @@ -1515,21 +1515,21 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have& e) { return false; } - auto ce = itc_it->second; + auto o = itc_it->second; - if (!static_cast(ce)) { + if (!static_cast(o)) { std::cerr << "SHA1_NGCFT1 error: tracking info has null object\n"; return false; } - const size_t num_total_chunks = ce.get().chunks.size(); + const size_t num_total_chunks = o.get().chunks.size(); const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number); // we might not know yet - addParticipation(c, ce); + addParticipation(c, o); - auto& remote_have = ce.get_or_emplace().others; + auto& remote_have = o.get_or_emplace().others; if (!remote_have.contains(c)) { // init remote_have.emplace(c, Components::RemoteHave::Entry{false, num_total_chunks}); @@ -1589,14 +1589,14 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_bitset& e) { return false; } - auto ce = itc_it->second; + auto o = itc_it->second; - if (!static_cast(ce)) { + if (!static_cast(o)) { std::cerr << "SHA1_NGCFT1 error: tracking info has null object\n"; return false; } - const size_t num_total_chunks = ce.get().chunks.size(); + const size_t num_total_chunks = o.get().chunks.size(); // +1 for byte rounding if (num_total_chunks+1 < e.start_chunk + (e.chunk_bitset.size()*8)) { std::cerr << "SHA1_NGCFT1 error: got bitset.size+start that is larger then number of chunks!!\n"; @@ -1606,9 +1606,9 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_bitset& e) { const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number); // we might not know yet - addParticipation(c, ce); + addParticipation(c, o); - auto& remote_have = ce.get_or_emplace().others; + auto& remote_have = o.get_or_emplace().others; if (!remote_have.contains(c)) { // init remote_have.emplace(c, Components::RemoteHave::Entry{false, num_total_chunks}); @@ -1670,9 +1670,9 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_pc1_announce& e) { } // add them to participants - auto ce = itc_it->second; const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number); - const bool was_new = addParticipation(c, ce); + auto o = itc_it->second; + const bool was_new = addParticipation(c, o); if (was_new) { std::cout << "SHA1_NGCFT1: and we where interested!\n"; // we should probably send the bitset back here / add to queue (can be multiple packets) diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp index 0fcf93e..8e84945 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp @@ -108,8 +108,8 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public void updateMessages(ObjectHandle ce); - bool addParticipation(Contact3 c, ObjectHandle o); - void removeParticipation(Contact3 c, ObjectHandle o); + static bool addParticipation(Contact3Handle c, ObjectHandle o); + static void removeParticipation(Contact3Handle c, ObjectHandle o); std::optional> selectPeerForRequest(ObjectHandle ce);