port to contact4
This commit is contained in:
parent
2f0dba1044
commit
91fdba2249
@ -36,13 +36,13 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
||||
auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI);
|
||||
auto* tox_event_provider_i = PLUG_RESOLVE_INSTANCE(ToxEventProviderI);
|
||||
auto* zox_ngc_event_provider_i = PLUG_RESOLVE_INSTANCE(ZoxNGCEventProviderI);
|
||||
auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
|
||||
auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I);
|
||||
auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2);
|
||||
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
|
||||
|
||||
// static store, could be anywhere tho
|
||||
// construct with fetched dependencies
|
||||
g_zngchs = std::make_unique<ZoxNGCHistorySync>(*tox_event_provider_i, *zox_ngc_event_provider_i, *tox_i, *cr, *tcm, *rmm);
|
||||
g_zngchs = std::make_unique<ZoxNGCHistorySync>(*tox_event_provider_i, *zox_ngc_event_provider_i, *tox_i, *cs, *tcm, *rmm);
|
||||
|
||||
// register types
|
||||
PLUG_PROVIDE_INSTANCE(ZoxNGCHistorySync, plugin_name, g_zngchs.get());
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <solanaceae/util/time.hpp>
|
||||
|
||||
#include <solanaceae/toxcore/tox_interface.hpp>
|
||||
#include <solanaceae/contact/contact_store_i.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||
#include <solanaceae/tox_contacts/components.hpp>
|
||||
@ -16,8 +17,8 @@
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
ZoxNGCHistorySync::ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProviderI& zngcepi, ToxI& t, Contact3Registry& cr, ToxContactModel2& tcm, RegistryMessageModelI& rmm)
|
||||
: _tep_sr(tep.newSubRef(this)), _zngcepi_sr(zngcepi.newSubRef(this)), _t(t), _cr(cr), _tcm(tcm), _rmm(rmm), _rng(std::random_device{}())
|
||||
ZoxNGCHistorySync::ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProviderI& zngcepi, ToxI& t, ContactStore4I& cs, ToxContactModel2& tcm, RegistryMessageModelI& rmm)
|
||||
: _tep_sr(tep.newSubRef(this)), _zngcepi_sr(zngcepi.newSubRef(this)), _t(t), _cs(cs), _tcm(tcm), _rmm(rmm), _rng(std::random_device{}())
|
||||
{
|
||||
_tep_sr.subscribe(Tox_Event_Type::TOX_EVENT_GROUP_PEER_JOIN);
|
||||
|
||||
@ -35,12 +36,14 @@ float ZoxNGCHistorySync::tick(float delta) {
|
||||
it->second.timer += delta;
|
||||
|
||||
if (it->second.timer >= it->second.delay) {
|
||||
if (!_cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(it->first)) {
|
||||
const auto& cr = _cs.registry();
|
||||
|
||||
if (!cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(it->first)) {
|
||||
// peer nolonger online
|
||||
it = _request_queue.erase(it);
|
||||
continue;
|
||||
}
|
||||
const auto [group_number, peer_number] = _cr.get<Contact::Components::ToxGroupPeerEphemeral>(it->first);
|
||||
const auto [group_number, peer_number] = cr.get<Contact::Components::ToxGroupPeerEphemeral>(it->first);
|
||||
|
||||
if (sendRequest(group_number, peer_number, it->second.sync_delta)) {
|
||||
// on success, requeue with longer delay (minutes)
|
||||
@ -77,12 +80,14 @@ float ZoxNGCHistorySync::tick(float delta) {
|
||||
Message3 msg_e = it->second.ents.front();
|
||||
it->second.ents.pop();
|
||||
|
||||
if (!_cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(it->first)) {
|
||||
const auto& cr = _cs.registry();
|
||||
|
||||
if (!cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(it->first)) {
|
||||
// peer nolonger online
|
||||
it = _sync_queue.erase(it);
|
||||
continue;
|
||||
}
|
||||
const auto [group_number, peer_number] = _cr.get<Contact::Components::ToxGroupPeerEphemeral>(it->first);
|
||||
const auto [group_number, peer_number] = cr.get<Contact::Components::ToxGroupPeerEphemeral>(it->first);
|
||||
|
||||
auto* reg_ptr = _rmm.get(it->first);
|
||||
if (reg_ptr == nullptr) {
|
||||
@ -105,7 +110,7 @@ float ZoxNGCHistorySync::tick(float delta) {
|
||||
}
|
||||
const auto& msg_sender = reg.get<Message::Components::ContactFrom>(msg_e).c;
|
||||
|
||||
if (!_cr.all_of<Contact::Components::ToxGroupPeerPersistent>(msg_sender)) {
|
||||
if (!cr.all_of<Contact::Components::ToxGroupPeerPersistent>(msg_sender)) {
|
||||
std::cerr << "ZOX NGCHS error: msg sender without persistant\n";
|
||||
continue;
|
||||
}
|
||||
@ -114,8 +119,8 @@ float ZoxNGCHistorySync::tick(float delta) {
|
||||
// TODO: make sure there is no alias leaked
|
||||
//const auto msg_sender_name = _cm.getContactName(msg_sender);
|
||||
std::string_view msg_sender_name;
|
||||
if (_cr.all_of<Contact::Components::Name>(msg_sender)) {
|
||||
msg_sender_name = _cr.get<Contact::Components::Name>(msg_sender).name;
|
||||
if (cr.all_of<Contact::Components::Name>(msg_sender)) {
|
||||
msg_sender_name = cr.get<Contact::Components::Name>(msg_sender).name;
|
||||
}
|
||||
|
||||
|
||||
@ -123,7 +128,7 @@ float ZoxNGCHistorySync::tick(float delta) {
|
||||
group_number,
|
||||
peer_number,
|
||||
reg.get<Message::Components::ToxGroupMessageID>(msg_e).id,
|
||||
_cr.get<Contact::Components::ToxGroupPeerPersistent>(msg_sender).peer_key.data,
|
||||
cr.get<Contact::Components::ToxGroupPeerPersistent>(msg_sender).peer_key.data,
|
||||
std::chrono::duration_cast<std::chrono::seconds>(std::chrono::milliseconds{reg.get<Message::Components::Timestamp>(msg_e).ts}).count(),
|
||||
msg_sender_name,
|
||||
reg.get<Message::Components::MessageText>(msg_e).text
|
||||
@ -289,8 +294,10 @@ bool ZoxNGCHistorySync::onEvent(const Events::ZoxNGC_ngch_request& e) {
|
||||
const auto& c_t = reg.get<Message::Components::ContactTo>(e);
|
||||
const auto& ts = view.get<Message::Components::Timestamp>(e);
|
||||
|
||||
const auto& cr = _cs.registry();
|
||||
|
||||
// private
|
||||
if (!_cr.all_of<Contact::Components::TagBig>(c_t.c)) {
|
||||
if (!cr.all_of<Contact::Components::TagBig>(c_t.c)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -305,9 +312,9 @@ bool ZoxNGCHistorySync::onEvent(const Events::ZoxNGC_ngch_request& e) {
|
||||
if (
|
||||
std::find_if(
|
||||
list.cbegin(), list.cend(),
|
||||
[this](const auto&& it) {
|
||||
[this, &cr](const auto&& it) {
|
||||
// TODO: add weak self
|
||||
return _cr.all_of<Contact::Components::TagSelfStrong>(it.first);
|
||||
return cr.all_of<Contact::Components::TagSelfStrong>(it.first);
|
||||
}
|
||||
) == list.cend()
|
||||
) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "./ngc.hpp"
|
||||
|
||||
#include <solanaceae/contact/contact_model3.hpp>
|
||||
#include <solanaceae/contact/fwd.hpp>
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
|
||||
#include <array>
|
||||
@ -23,7 +23,7 @@ class ZoxNGCHistorySync : public ToxEventI, public ZoxNGCEventI {
|
||||
ToxEventProviderI::SubscriptionReference _tep_sr;
|
||||
ZoxNGCEventProviderI::SubscriptionReference _zngcepi_sr;
|
||||
ToxI& _t;
|
||||
Contact3Registry& _cr;
|
||||
ContactStore4I& _cs;
|
||||
ToxContactModel2& _tcm;
|
||||
RegistryMessageModelI& _rmm;
|
||||
|
||||
@ -52,7 +52,7 @@ class ZoxNGCHistorySync : public ToxEventI, public ZoxNGCEventI {
|
||||
};
|
||||
// request queue
|
||||
// c -> delay, timer
|
||||
std::map<Contact3, RequestQueueInfo> _request_queue;
|
||||
std::map<Contact4, RequestQueueInfo> _request_queue;
|
||||
|
||||
struct SyncQueueInfo {
|
||||
float delay; // const
|
||||
@ -60,10 +60,10 @@ class ZoxNGCHistorySync : public ToxEventI, public ZoxNGCEventI {
|
||||
std::queue<Message3> ents;
|
||||
//std::reference_wrapper<Message1Registry> reg;
|
||||
};
|
||||
std::map<Contact3, SyncQueueInfo> _sync_queue;
|
||||
std::map<Contact4, SyncQueueInfo> _sync_queue;
|
||||
|
||||
public:
|
||||
ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProviderI& zngcepi, ToxI& t, Contact3Registry& cr, ToxContactModel2& tcm, RegistryMessageModelI& rmm);
|
||||
ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProviderI& zngcepi, ToxI& t, ContactStore4I& cs, ToxContactModel2& tcm, RegistryMessageModelI& rmm);
|
||||
|
||||
float tick(float delta);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user