work around missing contact events and properly clear on exit

This commit is contained in:
Green Sky 2024-07-07 14:15:26 +02:00
parent ea945e6360
commit 269daaa764
No known key found for this signature in database

View File

@ -394,8 +394,16 @@ float SHA1_NGCFT1::iterate(float delta) {
}
// new chunk picker code
_cr.view<ChunkPicker>().each([this, &_peer_open_requests](const Contact3 cv, ChunkPicker& cp) {
// HACK: work around missing contact events
std::vector<Contact3Handle> cp_to_remove;
_cr.view<ChunkPicker>().each([this, &_peer_open_requests, &cp_to_remove](const Contact3 cv, ChunkPicker& cp) {
Contact3Handle c{_cr, cv};
if (!c.all_of<Contact::Components::ToxGroupPeerEphemeral>()) {
cp_to_remove.push_back(c);
return;
}
// HACK: expensive, dont do every tick, only on events
// do verification in debug instead?
cp.updateParticipation(
@ -437,6 +445,18 @@ float SHA1_NGCFT1::iterate(float delta) {
std::cout << "SHA1_NGCFT1: requesting chunk [" << info.chunks.at(r_idx) << "] from " << group_number << ":" << peer_number << "\n";
}
});
for (const auto& c : cp_to_remove) {
c.remove<ChunkPicker>();
for (const auto& [_, o] : _info_to_content) {
removeParticipation(c, o);
if (o.all_of<Components::RemoteHave>()) {
o.get<Components::RemoteHave>().others.erase(c);
}
}
}
}
if (_peer_open_requests.empty()) {
@ -1423,6 +1443,8 @@ bool SHA1_NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) {
// peer disconnected
// - remove from all participantions
{
// FIXME: this does not work, tcm just delteded the relation ship
auto c = _tcm.getContactGroupPeer(group_number, peer_number);
if (!static_cast<bool>(c)) {
return false;
@ -1437,6 +1459,7 @@ bool SHA1_NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) {
o.get<Components::RemoteHave>().others.erase(c);
}
}
}
// - clear queues