port to contact4 (not using events yet)
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include "./ngc_hs2_rizzler.hpp"
|
||||
|
||||
#include <solanaceae/contact/contact_store_i.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
#include <solanaceae/tox_contacts/components.hpp>
|
||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||
@ -67,27 +68,15 @@ namespace Components {
|
||||
|
||||
} // Components
|
||||
|
||||
// TODO: move to contact reg?
|
||||
static Contact3 findContactByID(Contact3Registry& cr, const std::vector<uint8_t>& id) {
|
||||
// TODO: id lookup table, this is very inefficent
|
||||
for (const auto& [c_it, id_it] : cr.view<Contact::Components::ID>().each()) {
|
||||
if (id == id_it.data) {
|
||||
return c_it;
|
||||
}
|
||||
}
|
||||
|
||||
return entt::null;
|
||||
}
|
||||
|
||||
NGCHS2Rizzler::NGCHS2Rizzler(
|
||||
Contact3Registry& cr,
|
||||
ContactStore4I& cs,
|
||||
RegistryMessageModelI& rmm,
|
||||
ToxContactModel2& tcm,
|
||||
NGCFT1& nft,
|
||||
ToxEventProviderI& tep,
|
||||
SHA1_NGCFT1& sha1_nft
|
||||
) :
|
||||
_cr(cr),
|
||||
_cs(cs),
|
||||
_rmm(rmm),
|
||||
_tcm(tcm),
|
||||
_nft(nft),
|
||||
@ -117,7 +106,7 @@ float NGCHS2Rizzler::iterate(float delta) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Contact3Handle c {_cr, it->first};
|
||||
const ContactHandle4 c = _cs.contactHandle(it->first);
|
||||
|
||||
if (!c.all_of<Contact::Components::ToxGroupPeerEphemeral>()) {
|
||||
// peer nolonger online
|
||||
@ -184,7 +173,7 @@ bool NGCHS2Rizzler::sendRequest(
|
||||
);
|
||||
}
|
||||
|
||||
void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<uint8_t>& data) {
|
||||
void NGCHS2Rizzler::handleMsgPack(ContactHandle4 sync_by_c, const std::vector<uint8_t>& data) {
|
||||
assert(sync_by_c);
|
||||
|
||||
auto* reg_ptr = _rmm.get(sync_by_c);
|
||||
@ -227,7 +216,7 @@ void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<ui
|
||||
continue;
|
||||
}
|
||||
|
||||
Contact3 from_c{entt::null};
|
||||
Contact4 from_c{entt::null};
|
||||
{ // from_c
|
||||
std::vector<uint8_t> id;
|
||||
if (j_ppk.is_binary()) {
|
||||
@ -236,15 +225,21 @@ void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<ui
|
||||
j_ppk.at("bytes").get_to(id);
|
||||
}
|
||||
|
||||
from_c = findContactByID(_cr, id);
|
||||
const auto parent = sync_by_c.get<Contact::Components::Parent>().parent;
|
||||
|
||||
if (!_cr.valid(from_c)) {
|
||||
from_c = _cs.getOneContactByID(parent, ByteSpan{id});
|
||||
|
||||
auto& cr = _cs.registry();
|
||||
|
||||
if (!cr.valid(from_c)) {
|
||||
// create sparse contact with id only
|
||||
from_c = _cr.create();
|
||||
_cr.emplace_or_replace<Contact::Components::ID>(from_c, id);
|
||||
from_c = cr.create();
|
||||
cr.emplace_or_replace<Contact::Components::ID>(from_c, id);
|
||||
|
||||
// TODO: only if public message
|
||||
_cr.emplace_or_replace<Contact::Components::Parent>(from_c, sync_by_c.get<Contact::Components::Parent>().parent);
|
||||
cr.emplace_or_replace<Contact::Components::Parent>(from_c, parent);
|
||||
|
||||
_cs.throwEventConstruct(from_c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,7 +314,7 @@ void NGCHS2Rizzler::handleMsgPack(Contact3Handle sync_by_c, const std::vector<ui
|
||||
Message3Handle dup_msg{};
|
||||
{ // check preexisting
|
||||
// get comparator from contact
|
||||
const Contact3Handle reg_c {_cr, reg.ctx().get<Contact3>()};
|
||||
const ContactHandle4 reg_c = _cs.contactHandle(reg.ctx().get<Contact4>());
|
||||
if (reg_c.all_of<Contact::Components::MessageIsSame>()) {
|
||||
auto& comp = reg_c.get<Contact::Components::MessageIsSame>().comp;
|
||||
// walking EVERY existing message OOF
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/contact/contact_model3.hpp>
|
||||
#include <solanaceae/contact/fwd.hpp>
|
||||
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
||||
|
||||
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
||||
@ -12,7 +12,7 @@ class RegistryMessageModelI;
|
||||
|
||||
|
||||
class NGCHS2Rizzler : public ToxEventI, public NGCFT1EventI {
|
||||
Contact3Registry& _cr;
|
||||
ContactStore4I& _cs;
|
||||
RegistryMessageModelI& _rmm;
|
||||
ToxContactModel2& _tcm;
|
||||
NGCFT1& _nft;
|
||||
@ -34,15 +34,15 @@ class NGCHS2Rizzler : public ToxEventI, public NGCFT1EventI {
|
||||
};
|
||||
// request queue
|
||||
// c -> delay, timer
|
||||
std::map<Contact3, RequestQueueInfo> _request_queue;
|
||||
std::map<Contact4, RequestQueueInfo> _request_queue;
|
||||
|
||||
// FIXME: workaround missing contact events
|
||||
// only used on peer exit (no, also used to quicken lookups)
|
||||
entt::dense_map<uint64_t, Contact3Handle> _tox_peer_to_contact;
|
||||
entt::dense_map<uint64_t, ContactHandle4> _tox_peer_to_contact;
|
||||
|
||||
public:
|
||||
NGCHS2Rizzler(
|
||||
Contact3Registry& cr,
|
||||
ContactStore4I& cs,
|
||||
RegistryMessageModelI& rmm,
|
||||
ToxContactModel2& tcm,
|
||||
NGCFT1& nft,
|
||||
@ -60,7 +60,7 @@ class NGCHS2Rizzler : public ToxEventI, public NGCFT1EventI {
|
||||
uint64_t ts_start, uint64_t ts_end
|
||||
);
|
||||
|
||||
void handleMsgPack(Contact3Handle c, const std::vector<uint8_t>& data);
|
||||
void handleMsgPack(ContactHandle4 c, const std::vector<uint8_t>& data);
|
||||
|
||||
protected:
|
||||
bool onEvent(const Events::NGCFT1_recv_init&) override;
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <solanaceae/util/span.hpp>
|
||||
|
||||
#include <solanaceae/contact/contact_store_i.hpp>
|
||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
@ -71,12 +72,12 @@ namespace Components {
|
||||
|
||||
|
||||
NGCHS2Sigma::NGCHS2Sigma(
|
||||
Contact3Registry& cr,
|
||||
ContactStore4I& cs,
|
||||
RegistryMessageModelI& rmm,
|
||||
ToxContactModel2& tcm,
|
||||
NGCFT1& nft
|
||||
) :
|
||||
_cr(cr),
|
||||
_cs(cs),
|
||||
_rmm(rmm),
|
||||
_tcm(tcm),
|
||||
_nft(nft),
|
||||
@ -111,7 +112,7 @@ float NGCHS2Sigma::iterate(float delta) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Contact3Handle c{_cr, cv};
|
||||
ContactHandle4 c = _cs.contactHandle(cv);
|
||||
auto& iirr = c.get_or_emplace<Components::IncommingTimeRangeRequestRunning>();
|
||||
|
||||
// dedup queued from running
|
||||
@ -129,7 +130,7 @@ float NGCHS2Sigma::iterate(float delta) {
|
||||
iirq._queue.pop_front();
|
||||
continue; // how
|
||||
}
|
||||
const Contact3Handle group_c = {*c.registry(), c.get<Contact::Components::Parent>().parent};
|
||||
const ContactHandle4 group_c = {*c.registry(), c.get<Contact::Components::Parent>().parent};
|
||||
if (!c.all_of<Contact::Components::ToxGroupPeerEphemeral>()) {
|
||||
iirq._queue.pop_front();
|
||||
continue;
|
||||
@ -166,15 +167,17 @@ float NGCHS2Sigma::iterate(float delta) {
|
||||
}
|
||||
};
|
||||
|
||||
auto& cr = _cs.registry();
|
||||
|
||||
// first handle range requests on weak self
|
||||
fn_iirq(_cr.view<Components::IncommingTimeRangeRequestQueue, Contact::Components::TagSelfWeak>());
|
||||
fn_iirq(cr.view<Components::IncommingTimeRangeRequestQueue, Contact::Components::TagSelfWeak>());
|
||||
|
||||
// we could stop here, if too much is already running
|
||||
|
||||
// then range on others
|
||||
fn_iirq(_cr.view<Components::IncommingTimeRangeRequestQueue>(entt::exclude_t<Contact::Components::TagSelfWeak>{}));
|
||||
fn_iirq(cr.view<Components::IncommingTimeRangeRequestQueue>(entt::exclude_t<Contact::Components::TagSelfWeak>{}));
|
||||
|
||||
_cr.view<Components::IncommingTimeRangeRequestRunning>().each(
|
||||
cr.view<Components::IncommingTimeRangeRequestRunning>().each(
|
||||
[delta](const auto cv, Components::IncommingTimeRangeRequestRunning& irr) {
|
||||
std::vector<uint8_t> to_remove;
|
||||
for (auto&& [ft_id, entry] : irr._list) {
|
||||
@ -195,7 +198,7 @@ float NGCHS2Sigma::iterate(float delta) {
|
||||
return 1000.f;
|
||||
}
|
||||
|
||||
void NGCHS2Sigma::handleTimeRange(Contact3Handle c, const Events::NGCFT1_recv_request& e) {
|
||||
void NGCHS2Sigma::handleTimeRange(ContactHandle4 c, const Events::NGCFT1_recv_request& e) {
|
||||
ByteSpan fid{e.file_id, e.file_id_size};
|
||||
// TODO: better size check
|
||||
if (fid.size != sizeof(uint64_t)+sizeof(uint64_t)) {
|
||||
@ -239,7 +242,7 @@ void NGCHS2Sigma::handleTimeRange(Contact3Handle c, const Events::NGCFT1_recv_re
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> NGCHS2Sigma::buildChatLogFileRange(Contact3Handle c, uint64_t ts_start, uint64_t ts_end) {
|
||||
std::vector<uint8_t> NGCHS2Sigma::buildChatLogFileRange(ContactHandle4 c, uint64_t ts_start, uint64_t ts_end) {
|
||||
const Message3Registry* reg_ptr = static_cast<const RegistryMessageModelI&>(_rmm).get(c);
|
||||
if (reg_ptr == nullptr) {
|
||||
return {};
|
||||
@ -305,12 +308,12 @@ std::vector<uint8_t> NGCHS2Sigma::buildChatLogFileRange(Contact3Handle c, uint64
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_cr.valid(c_from_c.c)) {
|
||||
ContactHandle4 c_from = _cs.contactHandle(c_from_c.c);
|
||||
|
||||
if (!static_cast<bool>(c_from)) {
|
||||
continue; // ???
|
||||
}
|
||||
|
||||
Contact3Handle c_from{_cr, c_from_c.c};
|
||||
|
||||
if (!c_from.all_of<Contact::Components::ToxGroupPeerPersistent>()) {
|
||||
continue; // ???
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
||||
|
||||
#include <solanaceae/contact/contact_model3.hpp>
|
||||
#include <solanaceae/contact/fwd.hpp>
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
|
||||
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
||||
@ -24,7 +24,7 @@ struct TimeRangeRequest {
|
||||
};
|
||||
|
||||
class NGCHS2Sigma : public RegistryMessageModelEventI, public NGCFT1EventI {
|
||||
Contact3Registry& _cr;
|
||||
ContactStore4I& _cs;
|
||||
RegistryMessageModelI& _rmm;
|
||||
ToxContactModel2& _tcm;
|
||||
NGCFT1& _nft;
|
||||
@ -49,11 +49,11 @@ class NGCHS2Sigma : public RegistryMessageModelEventI, public NGCFT1EventI {
|
||||
|
||||
// FIXME: workaround missing contact events
|
||||
// only used on peer exit (no, also used to quicken lookups)
|
||||
entt::dense_map<uint64_t, Contact3Handle> _tox_peer_to_contact;
|
||||
entt::dense_map<uint64_t, ContactHandle4> _tox_peer_to_contact;
|
||||
|
||||
public:
|
||||
NGCHS2Sigma(
|
||||
Contact3Registry& cr,
|
||||
ContactStore4I& cs,
|
||||
RegistryMessageModelI& rmm,
|
||||
ToxContactModel2& tcm,
|
||||
NGCFT1& nft
|
||||
@ -63,11 +63,11 @@ class NGCHS2Sigma : public RegistryMessageModelEventI, public NGCFT1EventI {
|
||||
|
||||
float iterate(float delta);
|
||||
|
||||
void handleTimeRange(Contact3Handle c, const Events::NGCFT1_recv_request&);
|
||||
void handleTimeRange(ContactHandle4 c, const Events::NGCFT1_recv_request&);
|
||||
|
||||
// msg reg contact
|
||||
// time ranges
|
||||
[[nodiscard]] std::vector<uint8_t> buildChatLogFileRange(Contact3Handle c, uint64_t ts_start, uint64_t ts_end);
|
||||
[[nodiscard]] std::vector<uint8_t> buildChatLogFileRange(ContactHandle4 c, uint64_t ts_start, uint64_t ts_end);
|
||||
|
||||
protected:
|
||||
bool onEvent(const Message::Events::MessageConstruct&) override;
|
||||
|
Reference in New Issue
Block a user