switch to os provided remote have set and other fixes

This commit is contained in:
Green Sky 2024-12-15 01:23:08 +01:00
parent 78390dd342
commit b35babe3f8
No known key found for this signature in database
3 changed files with 25 additions and 28 deletions

View File

@ -272,7 +272,7 @@ std::vector<ChunkPicker::ContentChunkR> ChunkPicker::updateChunkRequests(
ObjectHandle o {objreg, it->first}; ObjectHandle o {objreg, it->first};
// intersect self have with other have // intersect self have with other have
if (!o.all_of<Components::RemoteHaveBitset, Components::FT1ChunkSHA1Cache, Components::FT1InfoSHA1>()) { if (!o.all_of<ObjComp::F::RemoteHaveBitset, Components::FT1ChunkSHA1Cache, Components::FT1InfoSHA1>()) {
// rare case where no one else has anything // rare case where no one else has anything
continue; continue;
} }
@ -284,7 +284,7 @@ std::vector<ChunkPicker::ContentChunkR> ChunkPicker::updateChunkRequests(
//const auto& cc = o.get<Components::FT1ChunkSHA1Cache>(); //const auto& cc = o.get<Components::FT1ChunkSHA1Cache>();
const auto& others_have = o.get<Components::RemoteHaveBitset>().others; const auto& others_have = o.get<ObjComp::F::RemoteHaveBitset>().others;
auto other_it = others_have.find(c); auto other_it = others_have.find(c);
if (other_it == others_have.end()) { if (other_it == others_have.end()) {
// rare case where the other is participating but has nothing // rare case where the other is participating but has nothing

View File

@ -70,14 +70,6 @@ namespace Components {
entt::dense_set<Contact3> participants; entt::dense_set<Contact3> participants;
}; };
struct RemoteHaveBitset {
struct Entry {
bool have_all {false};
BitSet have;
};
entt::dense_map<Contact3, Entry> others;
};
struct ReRequestInfoTimer { struct ReRequestInfoTimer {
float timer {0.f}; float timer {0.f};
}; };

View File

@ -1256,11 +1256,15 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_done& e) {
auto& transfer = _sending_transfers.getTransfer(e.group_number, e.peer_number, e.transfer_id); auto& transfer = _sending_transfers.getTransfer(e.group_number, e.peer_number, e.transfer_id);
if (transfer.isChunk()) { if (transfer.isChunk()) {
// we could cheat here and assume remote has chunk now
_os.throwEventUpdate(transfer.getChunk().content);
updateMessages(transfer.getChunk().content); // mostly for sent bytes updateMessages(transfer.getChunk().content); // mostly for sent bytes
} } // ignore info transfer for now
_sending_transfers.removePeerTransfer(e.group_number, e.peer_number, e.transfer_id); _sending_transfers.removePeerTransfer(e.group_number, e.peer_number, e.transfer_id);
return true; return true;
} }
@ -1403,8 +1407,8 @@ bool SHA1_NGCFT1::onToxEvent(const Tox_Event_Group_Peer_Exit* e) {
for (const auto& [_, o] : _info_to_content) { for (const auto& [_, o] : _info_to_content) {
removeParticipation(c, o); removeParticipation(c, o);
if (o.all_of<Components::RemoteHaveBitset>()) { if (o.all_of<ObjComp::F::RemoteHaveBitset>()) {
o.get<Components::RemoteHaveBitset>().others.erase(c); o.get<ObjComp::F::RemoteHaveBitset>().others.erase(c);
} }
} }
} }
@ -1463,19 +1467,15 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have& e) {
const size_t num_total_chunks = o.get<Components::FT1InfoSHA1>().chunks.size(); const size_t num_total_chunks = o.get<Components::FT1InfoSHA1>().chunks.size();
auto& remote_have = o.get_or_emplace<Components::RemoteHaveBitset>().others; auto& remote_have = o.get_or_emplace<ObjComp::F::RemoteHaveBitset>().others;
if (!remote_have.contains(c)) { if (!remote_have.contains(c)) {
// init // init
remote_have.emplace(c, Components::RemoteHaveBitset::Entry{false, num_total_chunks}); remote_have.emplace(c, ObjComp::F::RemoteHaveBitset::Entry{false, num_total_chunks});
// new have? nice // new have? nice
//c.emplace_or_replace<ChunkPickerUpdateTag>(); //c.emplace_or_replace<ChunkPickerUpdateTag>();
} }
if (o.all_of<ObjComp::F::TagLocalHaveAll>()) {
return true; // we dont care beyond this point
}
auto& remote_have_peer = remote_have.at(c); auto& remote_have_peer = remote_have.at(c);
if (remote_have_peer.have_all) { if (remote_have_peer.have_all) {
return true; // peer somehow already had all, ignoring return true; // peer somehow already had all, ignoring
@ -1496,11 +1496,6 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have& e) {
a_valid_change = true; a_valid_change = true;
} }
if (a_valid_change) {
// new have? nice
c.emplace_or_replace<ChunkPickerUpdateTag>();
}
// check for completion? // check for completion?
// TODO: optimize // TODO: optimize
bool test_all {true}; bool test_all {true};
@ -1517,6 +1512,15 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have& e) {
remote_have_peer.have = BitSet{}; remote_have_peer.have = BitSet{};
} }
if (o.all_of<ObjComp::F::TagLocalHaveAll>()) {
return true; // we dont care beyond this point
}
if (a_valid_change) {
// new have? nice
c.emplace_or_replace<ChunkPickerUpdateTag>();
}
return true; return true;
} }
@ -1566,15 +1570,16 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_bitset& e) {
return false; return false;
} }
auto& remote_have = o.get_or_emplace<Components::RemoteHaveBitset>().others; auto& remote_have = o.get_or_emplace<ObjComp::F::RemoteHaveBitset>().others;
if (!remote_have.contains(c)) { if (!remote_have.contains(c)) {
// init // init
remote_have.emplace(c, Components::RemoteHaveBitset::Entry{false, num_total_chunks}); remote_have.emplace(c, ObjComp::F::RemoteHaveBitset::Entry{false, num_total_chunks});
} }
auto& remote_have_peer = remote_have.at(c); auto& remote_have_peer = remote_have.at(c);
if (!remote_have_peer.have_all) { // TODO: maybe unset with bitset? if (!remote_have_peer.have_all) { // TODO: maybe unset with bitset?
BitSet event_bitset{e.chunk_bitset}; BitSet event_bitset{e.chunk_bitset};
// TODO: range replace instead
remote_have_peer.have.merge(event_bitset, e.start_chunk); remote_have_peer.have.merge(event_bitset, e.start_chunk);
// check for completion? // check for completion?
@ -1629,8 +1634,8 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCEXT_ft1_have_all& e) {
// we might not know yet // we might not know yet
addParticipation(c, o); addParticipation(c, o);
auto& remote_have = o.get_or_emplace<Components::RemoteHaveBitset>().others; auto& remote_have = o.get_or_emplace<ObjComp::F::RemoteHaveBitset>().others;
remote_have[c] = Components::RemoteHaveBitset::Entry{true, {}}; remote_have[c] = ObjComp::F::RemoteHaveBitset::Entry{true, {}};
// new have? nice // new have? nice
c.emplace_or_replace<ChunkPickerUpdateTag>(); c.emplace_or_replace<ChunkPickerUpdateTag>();