port to contact4 (not using events yet)
This commit is contained in:
parent
7a54552bd2
commit
dacda24390
@ -38,7 +38,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
auto* os = PLUG_RESOLVE_INSTANCE(ObjectStore2);
|
auto* os = PLUG_RESOLVE_INSTANCE(ObjectStore2);
|
||||||
auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI);
|
auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI);
|
||||||
auto* tox_event_provider_i = PLUG_RESOLVE_INSTANCE(ToxEventProviderI);
|
auto* tox_event_provider_i = PLUG_RESOLVE_INSTANCE(ToxEventProviderI);
|
||||||
auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
|
auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I);
|
||||||
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
|
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
|
||||||
auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2);
|
auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2);
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
// construct with fetched dependencies
|
// construct with fetched dependencies
|
||||||
g_ngcextep = std::make_unique<NGCEXTEventProvider>(*tox_i, *tox_event_provider_i);
|
g_ngcextep = std::make_unique<NGCEXTEventProvider>(*tox_i, *tox_event_provider_i);
|
||||||
g_ngcft1 = std::make_unique<NGCFT1>(*tox_i, *tox_event_provider_i, *g_ngcextep.get());
|
g_ngcft1 = std::make_unique<NGCFT1>(*tox_i, *tox_event_provider_i, *g_ngcextep.get());
|
||||||
g_sha1_ngcft1 = std::make_unique<SHA1_NGCFT1>(*os, *cr, *rmm, *g_ngcft1.get(), *tcm, *tox_event_provider_i, *g_ngcextep.get());
|
g_sha1_ngcft1 = std::make_unique<SHA1_NGCFT1>(*os, *cs, *rmm, *g_ngcft1.get(), *tcm, *tox_event_provider_i, *g_ngcextep.get());
|
||||||
|
|
||||||
// register types
|
// register types
|
||||||
PLUG_PROVIDE_INSTANCE(NGCEXTEventProviderI, plugin_name, g_ngcextep.get());
|
PLUG_PROVIDE_INSTANCE(NGCEXTEventProviderI, plugin_name, g_ngcextep.get());
|
||||||
|
@ -40,7 +40,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
try {
|
try {
|
||||||
//auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI);
|
//auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI);
|
||||||
auto* tox_event_provider_i = PLUG_RESOLVE_INSTANCE(ToxEventProviderI);
|
auto* tox_event_provider_i = PLUG_RESOLVE_INSTANCE(ToxEventProviderI);
|
||||||
auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
|
auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I);
|
||||||
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
|
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
|
||||||
auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2);
|
auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2);
|
||||||
auto* ngcft1 = PLUG_RESOLVE_INSTANCE(NGCFT1);
|
auto* ngcft1 = PLUG_RESOLVE_INSTANCE(NGCFT1);
|
||||||
@ -48,8 +48,8 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
|
|||||||
|
|
||||||
// static store, could be anywhere tho
|
// static store, could be anywhere tho
|
||||||
// construct with fetched dependencies
|
// construct with fetched dependencies
|
||||||
g_ngchs2s = std::make_unique<NGCHS2Sigma>(*cr, *rmm, *tcm, *ngcft1);
|
g_ngchs2s = std::make_unique<NGCHS2Sigma>(*cs, *rmm, *tcm, *ngcft1);
|
||||||
g_ngchs2r = std::make_unique<NGCHS2Rizzler>(*cr, *rmm, *tcm, *ngcft1, *tox_event_provider_i, *sha1_ngcft1);
|
g_ngchs2r = std::make_unique<NGCHS2Rizzler>(*cs, *rmm, *tcm, *ngcft1, *tox_event_provider_i, *sha1_ngcft1);
|
||||||
|
|
||||||
// register types
|
// register types
|
||||||
PLUG_PROVIDE_INSTANCE(NGCHS2Sigma, plugin_name, g_ngchs2s.get());
|
PLUG_PROVIDE_INSTANCE(NGCHS2Sigma, plugin_name, g_ngchs2s.get());
|
||||||
|
@ -123,7 +123,7 @@ static constexpr size_t flowWindowToRequestCount(size_t flow_window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChunkPicker::updateParticipation(
|
void ChunkPicker::updateParticipation(
|
||||||
Contact3Handle c,
|
ContactHandle4 c,
|
||||||
ObjectRegistry& objreg
|
ObjectRegistry& objreg
|
||||||
) {
|
) {
|
||||||
if (!c.all_of<Contact::Components::FT1Participation>()) {
|
if (!c.all_of<Contact::Components::FT1Participation>()) {
|
||||||
@ -211,7 +211,7 @@ void ChunkPicker::updateParticipation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ChunkPicker::ContentChunkR> ChunkPicker::updateChunkRequests(
|
std::vector<ChunkPicker::ContentChunkR> ChunkPicker::updateChunkRequests(
|
||||||
Contact3Handle c,
|
ContactHandle4 c,
|
||||||
ObjectRegistry& objreg,
|
ObjectRegistry& objreg,
|
||||||
const ReceivingTransfers& rt,
|
const ReceivingTransfers& rt,
|
||||||
const size_t open_requests
|
const size_t open_requests
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <solanaceae/contact/contact_model3.hpp>
|
#include <solanaceae/contact/fwd.hpp>
|
||||||
#include <solanaceae/object_store/object_store.hpp>
|
#include <solanaceae/object_store/object_store.hpp>
|
||||||
|
|
||||||
#include "./components.hpp"
|
#include "./components.hpp"
|
||||||
@ -50,7 +50,7 @@ struct ChunkPicker {
|
|||||||
private: // TODO: properly sort
|
private: // TODO: properly sort
|
||||||
// updates participating_unfinished
|
// updates participating_unfinished
|
||||||
void updateParticipation(
|
void updateParticipation(
|
||||||
Contact3Handle c,
|
ContactHandle4 c,
|
||||||
ObjectRegistry& objreg
|
ObjectRegistry& objreg
|
||||||
);
|
);
|
||||||
public:
|
public:
|
||||||
@ -66,7 +66,7 @@ struct ChunkPicker {
|
|||||||
};
|
};
|
||||||
// returns list of chunks to request
|
// returns list of chunks to request
|
||||||
[[nodiscard]] std::vector<ContentChunkR> updateChunkRequests(
|
[[nodiscard]] std::vector<ContentChunkR> updateChunkRequests(
|
||||||
Contact3Handle c,
|
ContactHandle4 c,
|
||||||
ObjectRegistry& objreg,
|
ObjectRegistry& objreg,
|
||||||
const ReceivingTransfers& rt,
|
const ReceivingTransfers& rt,
|
||||||
const size_t open_requests
|
const size_t open_requests
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "./chunk_picker_systems.hpp"
|
#include "./chunk_picker_systems.hpp"
|
||||||
|
|
||||||
|
#include <solanaceae/contact/contact_store_i.hpp>
|
||||||
|
|
||||||
#include <solanaceae/ngc_ft1/ngcft1_file_kind.hpp>
|
#include <solanaceae/ngc_ft1/ngcft1_file_kind.hpp>
|
||||||
|
|
||||||
#include "./components.hpp"
|
#include "./components.hpp"
|
||||||
@ -12,17 +14,19 @@
|
|||||||
namespace Systems {
|
namespace Systems {
|
||||||
|
|
||||||
void chunk_picker_updates(
|
void chunk_picker_updates(
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
ObjectRegistry& os_reg,
|
ObjectRegistry& os_reg,
|
||||||
const entt::dense_map<Contact3, size_t>& peer_open_requests,
|
const entt::dense_map<Contact4, size_t>& peer_open_requests,
|
||||||
const ReceivingTransfers& receiving_transfers,
|
const ReceivingTransfers& receiving_transfers,
|
||||||
NGCFT1& nft, // TODO: remove this somehow
|
NGCFT1& nft, // TODO: remove this somehow
|
||||||
const float delta
|
const float delta
|
||||||
) {
|
) {
|
||||||
std::vector<Contact3Handle> cp_to_remove;
|
std::vector<ContactHandle4> cp_to_remove;
|
||||||
|
|
||||||
|
auto& cr = cs.registry();
|
||||||
|
|
||||||
// first, update timers
|
// first, update timers
|
||||||
cr.view<ChunkPickerTimer>().each([&cr, delta](const Contact3 cv, ChunkPickerTimer& cpt) {
|
cr.view<ChunkPickerTimer>().each([&cr, delta](const Contact4 cv, ChunkPickerTimer& cpt) {
|
||||||
cpt.timer -= delta;
|
cpt.timer -= delta;
|
||||||
if (cpt.timer <= 0.f) {
|
if (cpt.timer <= 0.f) {
|
||||||
cr.emplace_or_replace<ChunkPickerUpdateTag>(cv);
|
cr.emplace_or_replace<ChunkPickerUpdateTag>(cv);
|
||||||
@ -33,8 +37,8 @@ void chunk_picker_updates(
|
|||||||
|
|
||||||
// now check for potentially missing cp
|
// now check for potentially missing cp
|
||||||
auto cput_view = cr.view<ChunkPickerUpdateTag>();
|
auto cput_view = cr.view<ChunkPickerUpdateTag>();
|
||||||
cput_view.each([&cr, &cp_to_remove](const Contact3 cv) {
|
cput_view.each([&cr, &cp_to_remove](const Contact4 cv) {
|
||||||
Contact3Handle c{cr, cv};
|
ContactHandle4 c{cr, cv};
|
||||||
|
|
||||||
//std::cout << "cput :)\n";
|
//std::cout << "cput :)\n";
|
||||||
|
|
||||||
@ -52,8 +56,8 @@ void chunk_picker_updates(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// now update all cp that are tagged
|
// now update all cp that are tagged
|
||||||
cr.view<ChunkPicker, ChunkPickerUpdateTag>().each([&cr, &os_reg, &peer_open_requests, &receiving_transfers, &nft, &cp_to_remove](const Contact3 cv, ChunkPicker& cp) {
|
cr.view<ChunkPicker, ChunkPickerUpdateTag>().each([&cr, &os_reg, &peer_open_requests, &receiving_transfers, &nft, &cp_to_remove](const Contact4 cv, ChunkPicker& cp) {
|
||||||
Contact3Handle c{cr, cv};
|
ContactHandle4 c{cr, cv};
|
||||||
|
|
||||||
if (!c.all_of<Contact::Components::ToxGroupPeerEphemeral, Contact::Components::FT1Participation>()) {
|
if (!c.all_of<Contact::Components::ToxGroupPeerEphemeral, Contact::Components::FT1Participation>()) {
|
||||||
cp_to_remove.push_back(c);
|
cp_to_remove.push_back(c);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <solanaceae/contact/contact_model3.hpp>
|
#include <solanaceae/contact/fwd.hpp>
|
||||||
#include <solanaceae/object_store/object_store.hpp>
|
#include <solanaceae/object_store/object_store.hpp>
|
||||||
#include <solanaceae/tox_contacts/components.hpp>
|
#include <solanaceae/tox_contacts/components.hpp>
|
||||||
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
||||||
@ -10,9 +10,9 @@
|
|||||||
namespace Systems {
|
namespace Systems {
|
||||||
|
|
||||||
void chunk_picker_updates(
|
void chunk_picker_updates(
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
ObjectRegistry& os_reg,
|
ObjectRegistry& os_reg,
|
||||||
const entt::dense_map<Contact3, size_t>& peer_open_requests,
|
const entt::dense_map<Contact4, size_t>& peer_open_requests,
|
||||||
const ReceivingTransfers& receiving_transfers,
|
const ReceivingTransfers& receiving_transfers,
|
||||||
NGCFT1& nft, // TODO: remove this somehow
|
NGCFT1& nft, // TODO: remove this somehow
|
||||||
const float delta
|
const float delta
|
||||||
|
@ -60,14 +60,14 @@ namespace Components {
|
|||||||
// requested chunks with a timer since last request
|
// requested chunks with a timer since last request
|
||||||
struct Entry {
|
struct Entry {
|
||||||
float timer {0.f};
|
float timer {0.f};
|
||||||
Contact3 c {entt::null};
|
Contact4 c {entt::null};
|
||||||
};
|
};
|
||||||
entt::dense_map<size_t, Entry> chunks;
|
entt::dense_map<size_t, Entry> chunks;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: once announce is shipped, remove the "Suspected"
|
// TODO: once announce is shipped, remove the "Suspected"
|
||||||
struct SuspectedParticipants {
|
struct SuspectedParticipants {
|
||||||
entt::dense_set<Contact3> participants;
|
entt::dense_set<Contact4> participants;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReRequestInfoTimer {
|
struct ReRequestInfoTimer {
|
||||||
@ -75,7 +75,7 @@ namespace Components {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct AnnounceTargets {
|
struct AnnounceTargets {
|
||||||
entt::dense_set<Contact3> targets;
|
entt::dense_set<Contact4> targets;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReAnnounceTimer {
|
struct ReAnnounceTimer {
|
||||||
@ -92,7 +92,7 @@ namespace Components {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct TransferStatsSeparated {
|
struct TransferStatsSeparated {
|
||||||
entt::dense_map<Contact3, ObjComp::Ephemeral::File::TransferStats> stats;
|
entt::dense_map<Contact4, ObjComp::Ephemeral::File::TransferStats> stats;
|
||||||
};
|
};
|
||||||
|
|
||||||
// used to populate stats
|
// used to populate stats
|
||||||
@ -111,7 +111,7 @@ namespace Components {
|
|||||||
void trimSent(const float time_now);
|
void trimSent(const float time_now);
|
||||||
void trimReceived(const float time_now);
|
void trimReceived(const float time_now);
|
||||||
};
|
};
|
||||||
entt::dense_map<Contact3, Peer> tally;
|
entt::dense_map<Contact4, Peer> tally;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Components
|
} // Components
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
bool addParticipation(Contact3Handle c, ObjectHandle o) {
|
bool addParticipation(ContactHandle4 c, ObjectHandle o) {
|
||||||
bool was_new {false};
|
bool was_new {false};
|
||||||
assert(static_cast<bool>(o));
|
assert(static_cast<bool>(o));
|
||||||
assert(static_cast<bool>(c));
|
assert(static_cast<bool>(c));
|
||||||
@ -25,7 +25,7 @@ bool addParticipation(Contact3Handle c, ObjectHandle o) {
|
|||||||
return was_new;
|
return was_new;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeParticipation(Contact3Handle c, ObjectHandle o) {
|
void removeParticipation(ContactHandle4 c, ObjectHandle o) {
|
||||||
assert(static_cast<bool>(o));
|
assert(static_cast<bool>(o));
|
||||||
assert(static_cast<bool>(c));
|
assert(static_cast<bool>(c));
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <solanaceae/object_store/object_store.hpp>
|
#include <solanaceae/object_store/object_store.hpp>
|
||||||
#include <solanaceae/contact/contact_model3.hpp>
|
#include <solanaceae/contact/fwd.hpp>
|
||||||
|
|
||||||
bool addParticipation(Contact3Handle c, ObjectHandle o);
|
bool addParticipation(ContactHandle4 c, ObjectHandle o);
|
||||||
void removeParticipation(Contact3Handle c, ObjectHandle o);
|
void removeParticipation(ContactHandle4 c, ObjectHandle o);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "./components.hpp"
|
#include "./components.hpp"
|
||||||
#include <solanaceae/object_store/meta_components_file.hpp>
|
#include <solanaceae/object_store/meta_components_file.hpp>
|
||||||
|
#include <solanaceae/contact/contact_store_i.hpp>
|
||||||
#include <solanaceae/tox_contacts/components.hpp>
|
#include <solanaceae/tox_contacts/components.hpp>
|
||||||
#include <solanaceae/ngc_ft1/ngcft1_file_kind.hpp>
|
#include <solanaceae/ngc_ft1/ngcft1_file_kind.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -11,12 +12,12 @@ namespace Systems {
|
|||||||
|
|
||||||
void re_announce(
|
void re_announce(
|
||||||
ObjectRegistry& os_reg,
|
ObjectRegistry& os_reg,
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
NGCEXTEventProvider& neep,
|
NGCEXTEventProvider& neep,
|
||||||
const float delta
|
const float delta
|
||||||
) {
|
) {
|
||||||
std::vector<Object> to_remove;
|
std::vector<Object> to_remove;
|
||||||
os_reg.view<Components::ReAnnounceTimer>().each([&os_reg, &cr, &neep, &to_remove, delta](Object ov, Components::ReAnnounceTimer& rat) {
|
os_reg.view<Components::ReAnnounceTimer>().each([&os_reg, &cr = cs.registry(), &neep, &to_remove, delta](Object ov, Components::ReAnnounceTimer& rat) {
|
||||||
ObjectHandle o{os_reg, ov};
|
ObjectHandle o{os_reg, ov};
|
||||||
// if no known targets, or no hash, remove
|
// if no known targets, or no hash, remove
|
||||||
if (!o.all_of<Components::AnnounceTargets, Components::FT1InfoSHA1Hash>()) {
|
if (!o.all_of<Components::AnnounceTargets, Components::FT1InfoSHA1Hash>()) {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <solanaceae/object_store/object_store.hpp>
|
#include <solanaceae/object_store/object_store.hpp>
|
||||||
#include <solanaceae/contact/contact_model3.hpp>
|
#include <solanaceae/contact/fwd.hpp>
|
||||||
#include <solanaceae/ngc_ext/ngcext.hpp>
|
#include <solanaceae/ngc_ext/ngcext.hpp>
|
||||||
|
|
||||||
namespace Systems {
|
namespace Systems {
|
||||||
|
|
||||||
void re_announce(
|
void re_announce(
|
||||||
ObjectRegistry& os_reg,
|
ObjectRegistry& os_reg,
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
NGCEXTEventProvider& neep,
|
NGCEXTEventProvider& neep,
|
||||||
const float delta
|
const float delta
|
||||||
);
|
);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include <solanaceae/util/utils.hpp>
|
#include <solanaceae/util/utils.hpp>
|
||||||
#include <solanaceae/util/time.hpp>
|
#include <solanaceae/util/time.hpp>
|
||||||
|
|
||||||
|
#include <solanaceae/contact/contact_store_i.hpp>
|
||||||
|
|
||||||
#include <solanaceae/contact/components.hpp>
|
#include <solanaceae/contact/components.hpp>
|
||||||
#include <solanaceae/tox_contacts/components.hpp>
|
#include <solanaceae/tox_contacts/components.hpp>
|
||||||
#include <solanaceae/message3/components.hpp>
|
#include <solanaceae/message3/components.hpp>
|
||||||
@ -90,6 +92,8 @@ std::optional<std::pair<uint32_t, uint32_t>> SHA1_NGCFT1::selectPeerForRequest(O
|
|||||||
// get a list of peers we can request this file from
|
// get a list of peers we can request this file from
|
||||||
std::vector<std::pair<uint32_t, uint32_t>> tox_peers;
|
std::vector<std::pair<uint32_t, uint32_t>> tox_peers;
|
||||||
|
|
||||||
|
const auto& cr = _cs.registry();
|
||||||
|
|
||||||
// 1 in 20 chance to ask random peer instead
|
// 1 in 20 chance to ask random peer instead
|
||||||
// also works well for empty SuspectedParticipants
|
// also works well for empty SuspectedParticipants
|
||||||
if ((_rng()%20) == 0) {
|
if ((_rng()%20) == 0) {
|
||||||
@ -102,17 +106,17 @@ std::optional<std::pair<uint32_t, uint32_t>> SHA1_NGCFT1::selectPeerForRequest(O
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& target : ce.get<Components::AnnounceTargets>().targets) {
|
for (const auto& target : ce.get<Components::AnnounceTargets>().targets) {
|
||||||
for (const auto child : _cr.get<Contact::Components::ParentOf>(target).subs) {
|
for (const auto child : cr.get<Contact::Components::ParentOf>(target).subs) {
|
||||||
if (const auto* cs = _cr.try_get<Contact::Components::ConnectionState>(child); cs == nullptr || cs->state == Contact::Components::ConnectionState::State::disconnected) {
|
if (const auto* cs = cr.try_get<Contact::Components::ConnectionState>(child); cs == nullptr || cs->state == Contact::Components::ConnectionState::State::disconnected) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cr.all_of<Contact::Components::TagSelfStrong>(child)) {
|
if (cr.all_of<Contact::Components::TagSelfStrong>(child)) {
|
||||||
continue; // skip self
|
continue; // skip self
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(child)) {
|
if (cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(child)) {
|
||||||
const auto& tgpe = _cr.get<Contact::Components::ToxGroupPeerEphemeral>(child);
|
const auto& tgpe = cr.get<Contact::Components::ToxGroupPeerEphemeral>(child);
|
||||||
tox_peers.push_back({tgpe.group_number, tgpe.peer_number});
|
tox_peers.push_back({tgpe.group_number, tgpe.peer_number});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,17 +126,17 @@ std::optional<std::pair<uint32_t, uint32_t>> SHA1_NGCFT1::selectPeerForRequest(O
|
|||||||
for (const auto c : ce.get<Components::SuspectedParticipants>().participants) {
|
for (const auto c : ce.get<Components::SuspectedParticipants>().participants) {
|
||||||
// TODO: sort by con state?
|
// TODO: sort by con state?
|
||||||
// prio to direct?
|
// prio to direct?
|
||||||
if (const auto* cs = _cr.try_get<Contact::Components::ConnectionState>(c); cs == nullptr || cs->state == Contact::Components::ConnectionState::State::disconnected) {
|
if (const auto* cs = cr.try_get<Contact::Components::ConnectionState>(c); cs == nullptr || cs->state == Contact::Components::ConnectionState::State::disconnected) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cr.all_of<Contact::Components::TagSelfStrong>(c)) {
|
if (cr.all_of<Contact::Components::TagSelfStrong>(c)) {
|
||||||
// FIXME: how did we select ourselfs to be a suspected participant
|
// FIXME: how did we select ourselfs to be a suspected participant
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(c)) {
|
if (cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(c)) {
|
||||||
const auto& tgpe = _cr.get<Contact::Components::ToxGroupPeerEphemeral>(c);
|
const auto& tgpe = cr.get<Contact::Components::ToxGroupPeerEphemeral>(c);
|
||||||
tox_peers.push_back({tgpe.group_number, tgpe.peer_number});
|
tox_peers.push_back({tgpe.group_number, tgpe.peer_number});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +152,7 @@ std::optional<std::pair<uint32_t, uint32_t>> SHA1_NGCFT1::selectPeerForRequest(O
|
|||||||
return std::make_pair(group_number, peer_number);
|
return std::make_pair(group_number, peer_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHA1_NGCFT1::queueBitsetSendFull(Contact3Handle c, ObjectHandle o) {
|
void SHA1_NGCFT1::queueBitsetSendFull(ContactHandle4 c, ObjectHandle o) {
|
||||||
if (!static_cast<bool>(c) || !static_cast<bool>(o)) {
|
if (!static_cast<bool>(c) || !static_cast<bool>(o)) {
|
||||||
assert(false);
|
assert(false);
|
||||||
return;
|
return;
|
||||||
@ -201,7 +205,7 @@ File2I* SHA1_NGCFT1::objGetFile2Read(ObjectHandle o) {
|
|||||||
|
|
||||||
SHA1_NGCFT1::SHA1_NGCFT1(
|
SHA1_NGCFT1::SHA1_NGCFT1(
|
||||||
ObjectStore2& os,
|
ObjectStore2& os,
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
RegistryMessageModelI& rmm,
|
RegistryMessageModelI& rmm,
|
||||||
NGCFT1& nft,
|
NGCFT1& nft,
|
||||||
ToxContactModel2& tcm,
|
ToxContactModel2& tcm,
|
||||||
@ -210,7 +214,7 @@ SHA1_NGCFT1::SHA1_NGCFT1(
|
|||||||
) :
|
) :
|
||||||
_os(os),
|
_os(os),
|
||||||
_os_sr(_os.newSubRef(this)),
|
_os_sr(_os.newSubRef(this)),
|
||||||
_cr(cr),
|
_cs(cs),
|
||||||
_rmm(rmm),
|
_rmm(rmm),
|
||||||
_rmm_sr(_rmm.newSubRef(this)),
|
_rmm_sr(_rmm.newSubRef(this)),
|
||||||
_nft(nft),
|
_nft(nft),
|
||||||
@ -321,7 +325,7 @@ float SHA1_NGCFT1::iterate(float delta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Systems::re_announce(_os.registry(), _cr, _neep, delta);
|
Systems::re_announce(_os.registry(), _cs, _neep, delta);
|
||||||
|
|
||||||
{ // send out bitsets
|
{ // send out bitsets
|
||||||
// currently 1 per tick
|
// currently 1 per tick
|
||||||
@ -455,7 +459,7 @@ float SHA1_NGCFT1::iterate(float delta) {
|
|||||||
// new chunk picker code
|
// new chunk picker code
|
||||||
// TODO: need to either split up or remove some things here
|
// TODO: need to either split up or remove some things here
|
||||||
Systems::chunk_picker_updates(
|
Systems::chunk_picker_updates(
|
||||||
_cr,
|
_cs,
|
||||||
_os.registry(),
|
_os.registry(),
|
||||||
_peer_open_requests,
|
_peer_open_requests,
|
||||||
_receiving_transfers,
|
_receiving_transfers,
|
||||||
@ -476,7 +480,7 @@ float SHA1_NGCFT1::iterate(float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// gets called back on main thread after a "new" file info got built on a different thread
|
// gets called back on main thread after a "new" file info got built on a different thread
|
||||||
void SHA1_NGCFT1::onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_ptr, Contact3 c, uint64_t ts) {
|
void SHA1_NGCFT1::onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_ptr, Contact4 c, uint64_t ts) {
|
||||||
// sanity
|
// sanity
|
||||||
if (!o.all_of<Components::FT1InfoSHA1, Components::FT1InfoSHA1Hash>()) {
|
if (!o.all_of<Components::FT1InfoSHA1, Components::FT1InfoSHA1Hash>()) {
|
||||||
assert(false);
|
assert(false);
|
||||||
@ -505,7 +509,7 @@ void SHA1_NGCFT1::onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_p
|
|||||||
// something happend, update all chunk pickers
|
// something happend, update all chunk pickers
|
||||||
if (o.all_of<Components::SuspectedParticipants>()) {
|
if (o.all_of<Components::SuspectedParticipants>()) {
|
||||||
for (const auto& pcv : o.get<Components::SuspectedParticipants>().participants) {
|
for (const auto& pcv : o.get<Components::SuspectedParticipants>().participants) {
|
||||||
Contact3Handle pch{_cr, pcv};
|
ContactHandle4 pch = _cs.contactHandle(pcv);
|
||||||
assert(static_cast<bool>(pch));
|
assert(static_cast<bool>(pch));
|
||||||
pch.emplace_or_replace<ChunkPickerUpdateTag>();
|
pch.emplace_or_replace<ChunkPickerUpdateTag>();
|
||||||
}
|
}
|
||||||
@ -514,9 +518,11 @@ void SHA1_NGCFT1::onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_p
|
|||||||
// in both cases, private and public, c (contact to) is the target
|
// in both cases, private and public, c (contact to) is the target
|
||||||
o.get_or_emplace<Components::AnnounceTargets>().targets.emplace(c);
|
o.get_or_emplace<Components::AnnounceTargets>().targets.emplace(c);
|
||||||
|
|
||||||
|
const auto& cr = _cs.registry();
|
||||||
|
|
||||||
// create message
|
// create message
|
||||||
const auto c_self = _cr.get<Contact::Components::Self>(c).self;
|
const auto c_self = cr.get<Contact::Components::Self>(c).self;
|
||||||
if (!_cr.valid(c_self)) {
|
if (!cr.valid(c_self)) {
|
||||||
std::cerr << "SHA1_NGCFT1 error: failed to get self!\n";
|
std::cerr << "SHA1_NGCFT1 error: failed to get self!\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -537,8 +543,8 @@ void SHA1_NGCFT1::onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_p
|
|||||||
// file id would be sha1_info hash or something
|
// file id would be sha1_info hash or something
|
||||||
//reg_ptr->emplace<Message::Components::Transfer::FileID>(e, file_id);
|
//reg_ptr->emplace<Message::Components::Transfer::FileID>(e, file_id);
|
||||||
|
|
||||||
if (_cr.any_of<Contact::Components::ToxGroupEphemeral>(c)) {
|
if (cr.any_of<Contact::Components::ToxGroupEphemeral>(c)) {
|
||||||
const uint32_t group_number = _cr.get<Contact::Components::ToxGroupEphemeral>(c).group_number;
|
const uint32_t group_number = cr.get<Contact::Components::ToxGroupEphemeral>(c).group_number;
|
||||||
uint32_t message_id = 0;
|
uint32_t message_id = 0;
|
||||||
|
|
||||||
// TODO: check return
|
// TODO: check return
|
||||||
@ -546,7 +552,7 @@ void SHA1_NGCFT1::onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_p
|
|||||||
reg_ptr->emplace<Message::Components::ToxGroupMessageID>(msg_e, message_id);
|
reg_ptr->emplace<Message::Components::ToxGroupMessageID>(msg_e, message_id);
|
||||||
} else if (
|
} else if (
|
||||||
// non online group
|
// non online group
|
||||||
_cr.any_of<Contact::Components::ToxGroupPersistent>(c)
|
cr.any_of<Contact::Components::ToxGroupPersistent>(c)
|
||||||
) {
|
) {
|
||||||
// create msg_id
|
// create msg_id
|
||||||
const uint32_t message_id = randombytes_random();
|
const uint32_t message_id = randombytes_random();
|
||||||
@ -584,8 +590,8 @@ ObjectHandle SHA1_NGCFT1::constructFileMessageInPlace(Message3Handle msg, NGCFT1
|
|||||||
msg.emplace_or_replace<Message::Components::MessageFileObject>(o);
|
msg.emplace_or_replace<Message::Components::MessageFileObject>(o);
|
||||||
|
|
||||||
// TODO: use to_c instead?
|
// TODO: use to_c instead?
|
||||||
if (const auto* from_c_comp = msg.try_get<Message::Components::ContactFrom>(); from_c_comp != nullptr && _cr.valid(from_c_comp->c)) {
|
if (const auto* from_c_comp = msg.try_get<Message::Components::ContactFrom>(); from_c_comp != nullptr && _cs.registry().valid(from_c_comp->c)) {
|
||||||
Contact3Handle c{_cr, from_c_comp->c};
|
ContactHandle4 c = _cs.contactHandle(from_c_comp->c);
|
||||||
|
|
||||||
// TODO: check if public
|
// TODO: check if public
|
||||||
// since public
|
// since public
|
||||||
@ -747,7 +753,7 @@ bool SHA1_NGCFT1::onEvent(const ObjectStore::Events::ObjectUpdate& e) {
|
|||||||
if (e.e.all_of<Components::SuspectedParticipants>()) {
|
if (e.e.all_of<Components::SuspectedParticipants>()) {
|
||||||
std::cout << "SHA1_NGCFT1: accepted ft has " << e.e.get<Components::SuspectedParticipants>().participants.size() << " sp\n";
|
std::cout << "SHA1_NGCFT1: accepted ft has " << e.e.get<Components::SuspectedParticipants>().participants.size() << " sp\n";
|
||||||
for (const auto cv : e.e.get<Components::SuspectedParticipants>().participants) {
|
for (const auto cv : e.e.get<Components::SuspectedParticipants>().participants) {
|
||||||
_cr.emplace_or_replace<ChunkPickerUpdateTag>(cv);
|
_cs.registry().emplace_or_replace<ChunkPickerUpdateTag>(cv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cout << "accepted ft has NO sp!\n";
|
std::cout << "accepted ft has NO sp!\n";
|
||||||
@ -990,7 +996,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_data& e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact3Handle c;
|
ContactHandle4 c;
|
||||||
const auto tpcc_it = _tox_peer_to_contact.find(combine_ids(e.group_number, e.peer_number));
|
const auto tpcc_it = _tox_peer_to_contact.find(combine_ids(e.group_number, e.peer_number));
|
||||||
if (tpcc_it != _tox_peer_to_contact.cend()) {
|
if (tpcc_it != _tox_peer_to_contact.cend()) {
|
||||||
c = tpcc_it->second;
|
c = tpcc_it->second;
|
||||||
@ -1057,7 +1063,7 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_send_data& e) {
|
|||||||
// TODO: add event to propergate to messages
|
// TODO: add event to propergate to messages
|
||||||
//_rmm.throwEventUpdate(transfer); // should we?
|
//_rmm.throwEventUpdate(transfer); // should we?
|
||||||
|
|
||||||
Contact3Handle c;
|
ContactHandle4 c;
|
||||||
const auto tpcc_it = _tox_peer_to_contact.find(combine_ids(e.group_number, e.peer_number));
|
const auto tpcc_it = _tox_peer_to_contact.find(combine_ids(e.group_number, e.peer_number));
|
||||||
if (tpcc_it != _tox_peer_to_contact.cend()) {
|
if (tpcc_it != _tox_peer_to_contact.cend()) {
|
||||||
c = tpcc_it->second;
|
c = tpcc_it->second;
|
||||||
@ -1202,14 +1208,16 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_done& e) {
|
|||||||
o.remove<ObjComp::F::LocalHaveBitset>(); // save space
|
o.remove<ObjComp::F::LocalHaveBitset>(); // save space
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto& cr = _cs.registry();
|
||||||
|
|
||||||
// queue chunk have for all participants
|
// queue chunk have for all participants
|
||||||
// HACK: send immediatly to all participants
|
// HACK: send immediatly to all participants
|
||||||
for (const auto c_part : o.get<Components::SuspectedParticipants>().participants) {
|
for (const auto c_part : o.get<Components::SuspectedParticipants>().participants) {
|
||||||
if (!_cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(c_part)) {
|
if (!cr.all_of<Contact::Components::ToxGroupPeerEphemeral>(c_part)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto [part_group_number, part_peer_number] = _cr.get<Contact::Components::ToxGroupPeerEphemeral>(c_part);
|
const auto [part_group_number, part_peer_number] = cr.get<Contact::Components::ToxGroupPeerEphemeral>(c_part);
|
||||||
|
|
||||||
const auto& info_hash = o.get<Components::FT1InfoSHA1Hash>().hash;
|
const auto& info_hash = o.get<Components::FT1InfoSHA1Hash>().hash;
|
||||||
|
|
||||||
@ -1350,10 +1358,10 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_message& e) {
|
|||||||
return true; // false?
|
return true; // false?
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHA1_NGCFT1::sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) {
|
bool SHA1_NGCFT1::sendFilePath(const Contact4 c, std::string_view file_name, std::string_view file_path) {
|
||||||
if (
|
if (
|
||||||
// TODO: add support of offline queuing
|
// TODO: add support of offline queuing
|
||||||
!_cr.all_of<Contact::Components::ToxGroupEphemeral>(c)
|
!_cs.registry().all_of<Contact::Components::ToxGroupEphemeral>(c)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// solanaceae port of sha1 fts for NGCFT1
|
// solanaceae port of sha1 fts for NGCFT1
|
||||||
|
|
||||||
#include <solanaceae/object_store/object_store.hpp>
|
#include <solanaceae/object_store/object_store.hpp>
|
||||||
#include <solanaceae/contact/contact_model3.hpp>
|
#include <solanaceae/contact/fwd.hpp>
|
||||||
#include <solanaceae/message3/registry_message_model.hpp>
|
#include <solanaceae/message3/registry_message_model.hpp>
|
||||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public
|
|||||||
ObjectStore2& _os;
|
ObjectStore2& _os;
|
||||||
ObjectStore2::SubscriptionReference _os_sr;
|
ObjectStore2::SubscriptionReference _os_sr;
|
||||||
// TODO: backend abstraction
|
// TODO: backend abstraction
|
||||||
Contact3Registry& _cr;
|
ContactStore4I& _cs;
|
||||||
RegistryMessageModelI& _rmm;
|
RegistryMessageModelI& _rmm;
|
||||||
RegistryMessageModelI::SubscriptionReference _rmm_sr;
|
RegistryMessageModelI::SubscriptionReference _rmm_sr;
|
||||||
NGCFT1& _nft;
|
NGCFT1& _nft;
|
||||||
@ -67,23 +67,23 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public
|
|||||||
std::deque<ObjectHandle> _queue_content_want_info;
|
std::deque<ObjectHandle> _queue_content_want_info;
|
||||||
|
|
||||||
struct QBitsetEntry {
|
struct QBitsetEntry {
|
||||||
Contact3Handle c;
|
ContactHandle4 c;
|
||||||
ObjectHandle o;
|
ObjectHandle o;
|
||||||
};
|
};
|
||||||
std::deque<QBitsetEntry> _queue_send_bitset;
|
std::deque<QBitsetEntry> _queue_send_bitset;
|
||||||
|
|
||||||
// FIXME: workaround missing contact events
|
// FIXME: workaround missing contact events
|
||||||
// only used on peer exit (no, also used to quicken lookups)
|
// 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;
|
||||||
|
|
||||||
// reset every iterate; kept here as an allocation optimization
|
// reset every iterate; kept here as an allocation optimization
|
||||||
entt::dense_map<Contact3, size_t> _peer_open_requests;
|
entt::dense_map<Contact4, size_t> _peer_open_requests;
|
||||||
|
|
||||||
void updateMessages(ObjectHandle ce);
|
void updateMessages(ObjectHandle ce);
|
||||||
|
|
||||||
std::optional<std::pair<uint32_t, uint32_t>> selectPeerForRequest(ObjectHandle ce);
|
std::optional<std::pair<uint32_t, uint32_t>> selectPeerForRequest(ObjectHandle ce);
|
||||||
|
|
||||||
void queueBitsetSendFull(Contact3Handle c, ObjectHandle o);
|
void queueBitsetSendFull(ContactHandle4 c, ObjectHandle o);
|
||||||
|
|
||||||
File2I* objGetFile2Write(ObjectHandle o);
|
File2I* objGetFile2Write(ObjectHandle o);
|
||||||
File2I* objGetFile2Read(ObjectHandle o);
|
File2I* objGetFile2Read(ObjectHandle o);
|
||||||
@ -97,7 +97,7 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public
|
|||||||
public:
|
public:
|
||||||
SHA1_NGCFT1(
|
SHA1_NGCFT1(
|
||||||
ObjectStore2& os,
|
ObjectStore2& os,
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
RegistryMessageModelI& rmm,
|
RegistryMessageModelI& rmm,
|
||||||
NGCFT1& nft,
|
NGCFT1& nft,
|
||||||
ToxContactModel2& tcm,
|
ToxContactModel2& tcm,
|
||||||
@ -107,13 +107,13 @@ class SHA1_NGCFT1 : public ToxEventI, public RegistryMessageModelEventI, public
|
|||||||
|
|
||||||
float iterate(float delta);
|
float iterate(float delta);
|
||||||
|
|
||||||
void onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_ptr, Contact3 c, uint64_t ts);
|
void onSendFileHashFinished(ObjectHandle o, Message3Registry* reg_ptr, Contact4 c, uint64_t ts);
|
||||||
|
|
||||||
// construct the file part in a partially constructed message
|
// construct the file part in a partially constructed message
|
||||||
ObjectHandle constructFileMessageInPlace(Message3Handle msg, NGCFT1_file_kind file_kind, ByteSpan file_id);
|
ObjectHandle constructFileMessageInPlace(Message3Handle msg, NGCFT1_file_kind file_kind, ByteSpan file_id);
|
||||||
|
|
||||||
protected: // rmm events (actions)
|
protected: // rmm events (actions)
|
||||||
bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) override;
|
bool sendFilePath(const Contact4 c, std::string_view file_name, std::string_view file_path) override;
|
||||||
|
|
||||||
protected: // os events (actions)
|
protected: // os events (actions)
|
||||||
bool onEvent(const ObjectStore::Events::ObjectUpdate&) override;
|
bool onEvent(const ObjectStore::Events::ObjectUpdate&) override;
|
||||||
|
@ -12,7 +12,7 @@ void transfer_tally_update(ObjectRegistry& os_reg, const float time_now) {
|
|||||||
// for each tally -> stats separated
|
// for each tally -> stats separated
|
||||||
os_reg.view<Components::TransferStatsTally>().each([&os_reg, time_now, &tally_to_remove](const auto ov, Components::TransferStatsTally& tally_comp) {
|
os_reg.view<Components::TransferStatsTally>().each([&os_reg, time_now, &tally_to_remove](const auto ov, Components::TransferStatsTally& tally_comp) {
|
||||||
// for each peer
|
// for each peer
|
||||||
std::vector<Contact3> to_remove;
|
std::vector<Contact4> to_remove;
|
||||||
for (auto&& [peer_c, peer] : tally_comp.tally) {
|
for (auto&& [peer_c, peer] : tally_comp.tally) {
|
||||||
auto& tss = os_reg.get_or_emplace<Components::TransferStatsSeparated>(ov).stats;
|
auto& tss = os_reg.get_or_emplace<Components::TransferStatsSeparated>(ov).stats;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "./ngc_hs2_rizzler.hpp"
|
#include "./ngc_hs2_rizzler.hpp"
|
||||||
|
|
||||||
|
#include <solanaceae/contact/contact_store_i.hpp>
|
||||||
#include <solanaceae/contact/components.hpp>
|
#include <solanaceae/contact/components.hpp>
|
||||||
#include <solanaceae/tox_contacts/components.hpp>
|
#include <solanaceae/tox_contacts/components.hpp>
|
||||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||||
@ -67,27 +68,15 @@ namespace Components {
|
|||||||
|
|
||||||
} // 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(
|
NGCHS2Rizzler::NGCHS2Rizzler(
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
RegistryMessageModelI& rmm,
|
RegistryMessageModelI& rmm,
|
||||||
ToxContactModel2& tcm,
|
ToxContactModel2& tcm,
|
||||||
NGCFT1& nft,
|
NGCFT1& nft,
|
||||||
ToxEventProviderI& tep,
|
ToxEventProviderI& tep,
|
||||||
SHA1_NGCFT1& sha1_nft
|
SHA1_NGCFT1& sha1_nft
|
||||||
) :
|
) :
|
||||||
_cr(cr),
|
_cs(cs),
|
||||||
_rmm(rmm),
|
_rmm(rmm),
|
||||||
_tcm(tcm),
|
_tcm(tcm),
|
||||||
_nft(nft),
|
_nft(nft),
|
||||||
@ -117,7 +106,7 @@ float NGCHS2Rizzler::iterate(float delta) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Contact3Handle c {_cr, it->first};
|
const ContactHandle4 c = _cs.contactHandle(it->first);
|
||||||
|
|
||||||
if (!c.all_of<Contact::Components::ToxGroupPeerEphemeral>()) {
|
if (!c.all_of<Contact::Components::ToxGroupPeerEphemeral>()) {
|
||||||
// peer nolonger online
|
// 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);
|
assert(sync_by_c);
|
||||||
|
|
||||||
auto* reg_ptr = _rmm.get(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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact3 from_c{entt::null};
|
Contact4 from_c{entt::null};
|
||||||
{ // from_c
|
{ // from_c
|
||||||
std::vector<uint8_t> id;
|
std::vector<uint8_t> id;
|
||||||
if (j_ppk.is_binary()) {
|
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);
|
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
|
// create sparse contact with id only
|
||||||
from_c = _cr.create();
|
from_c = cr.create();
|
||||||
_cr.emplace_or_replace<Contact::Components::ID>(from_c, id);
|
cr.emplace_or_replace<Contact::Components::ID>(from_c, id);
|
||||||
|
|
||||||
// TODO: only if public message
|
// 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{};
|
Message3Handle dup_msg{};
|
||||||
{ // check preexisting
|
{ // check preexisting
|
||||||
// get comparator from contact
|
// 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>()) {
|
if (reg_c.all_of<Contact::Components::MessageIsSame>()) {
|
||||||
auto& comp = reg_c.get<Contact::Components::MessageIsSame>().comp;
|
auto& comp = reg_c.get<Contact::Components::MessageIsSame>().comp;
|
||||||
// walking EVERY existing message OOF
|
// walking EVERY existing message OOF
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <solanaceae/contact/contact_model3.hpp>
|
#include <solanaceae/contact/fwd.hpp>
|
||||||
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
||||||
|
|
||||||
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
||||||
@ -12,7 +12,7 @@ class RegistryMessageModelI;
|
|||||||
|
|
||||||
|
|
||||||
class NGCHS2Rizzler : public ToxEventI, public NGCFT1EventI {
|
class NGCHS2Rizzler : public ToxEventI, public NGCFT1EventI {
|
||||||
Contact3Registry& _cr;
|
ContactStore4I& _cs;
|
||||||
RegistryMessageModelI& _rmm;
|
RegistryMessageModelI& _rmm;
|
||||||
ToxContactModel2& _tcm;
|
ToxContactModel2& _tcm;
|
||||||
NGCFT1& _nft;
|
NGCFT1& _nft;
|
||||||
@ -34,15 +34,15 @@ class NGCHS2Rizzler : public ToxEventI, public NGCFT1EventI {
|
|||||||
};
|
};
|
||||||
// request queue
|
// request queue
|
||||||
// c -> delay, timer
|
// c -> delay, timer
|
||||||
std::map<Contact3, RequestQueueInfo> _request_queue;
|
std::map<Contact4, RequestQueueInfo> _request_queue;
|
||||||
|
|
||||||
// FIXME: workaround missing contact events
|
// FIXME: workaround missing contact events
|
||||||
// only used on peer exit (no, also used to quicken lookups)
|
// 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:
|
public:
|
||||||
NGCHS2Rizzler(
|
NGCHS2Rizzler(
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
RegistryMessageModelI& rmm,
|
RegistryMessageModelI& rmm,
|
||||||
ToxContactModel2& tcm,
|
ToxContactModel2& tcm,
|
||||||
NGCFT1& nft,
|
NGCFT1& nft,
|
||||||
@ -60,7 +60,7 @@ class NGCHS2Rizzler : public ToxEventI, public NGCFT1EventI {
|
|||||||
uint64_t ts_start, uint64_t ts_end
|
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:
|
protected:
|
||||||
bool onEvent(const Events::NGCFT1_recv_init&) override;
|
bool onEvent(const Events::NGCFT1_recv_init&) override;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <solanaceae/util/span.hpp>
|
#include <solanaceae/util/span.hpp>
|
||||||
|
|
||||||
|
#include <solanaceae/contact/contact_store_i.hpp>
|
||||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||||
|
|
||||||
#include <solanaceae/contact/components.hpp>
|
#include <solanaceae/contact/components.hpp>
|
||||||
@ -71,12 +72,12 @@ namespace Components {
|
|||||||
|
|
||||||
|
|
||||||
NGCHS2Sigma::NGCHS2Sigma(
|
NGCHS2Sigma::NGCHS2Sigma(
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
RegistryMessageModelI& rmm,
|
RegistryMessageModelI& rmm,
|
||||||
ToxContactModel2& tcm,
|
ToxContactModel2& tcm,
|
||||||
NGCFT1& nft
|
NGCFT1& nft
|
||||||
) :
|
) :
|
||||||
_cr(cr),
|
_cs(cs),
|
||||||
_rmm(rmm),
|
_rmm(rmm),
|
||||||
_tcm(tcm),
|
_tcm(tcm),
|
||||||
_nft(nft),
|
_nft(nft),
|
||||||
@ -111,7 +112,7 @@ float NGCHS2Sigma::iterate(float delta) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact3Handle c{_cr, cv};
|
ContactHandle4 c = _cs.contactHandle(cv);
|
||||||
auto& iirr = c.get_or_emplace<Components::IncommingTimeRangeRequestRunning>();
|
auto& iirr = c.get_or_emplace<Components::IncommingTimeRangeRequestRunning>();
|
||||||
|
|
||||||
// dedup queued from running
|
// dedup queued from running
|
||||||
@ -129,7 +130,7 @@ float NGCHS2Sigma::iterate(float delta) {
|
|||||||
iirq._queue.pop_front();
|
iirq._queue.pop_front();
|
||||||
continue; // how
|
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>()) {
|
if (!c.all_of<Contact::Components::ToxGroupPeerEphemeral>()) {
|
||||||
iirq._queue.pop_front();
|
iirq._queue.pop_front();
|
||||||
continue;
|
continue;
|
||||||
@ -166,15 +167,17 @@ float NGCHS2Sigma::iterate(float delta) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto& cr = _cs.registry();
|
||||||
|
|
||||||
// first handle range requests on weak self
|
// 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
|
// we could stop here, if too much is already running
|
||||||
|
|
||||||
// then range on others
|
// 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) {
|
[delta](const auto cv, Components::IncommingTimeRangeRequestRunning& irr) {
|
||||||
std::vector<uint8_t> to_remove;
|
std::vector<uint8_t> to_remove;
|
||||||
for (auto&& [ft_id, entry] : irr._list) {
|
for (auto&& [ft_id, entry] : irr._list) {
|
||||||
@ -195,7 +198,7 @@ float NGCHS2Sigma::iterate(float delta) {
|
|||||||
return 1000.f;
|
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};
|
ByteSpan fid{e.file_id, e.file_id_size};
|
||||||
// TODO: better size check
|
// TODO: better size check
|
||||||
if (fid.size != sizeof(uint64_t)+sizeof(uint64_t)) {
|
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);
|
const Message3Registry* reg_ptr = static_cast<const RegistryMessageModelI&>(_rmm).get(c);
|
||||||
if (reg_ptr == nullptr) {
|
if (reg_ptr == nullptr) {
|
||||||
return {};
|
return {};
|
||||||
@ -305,12 +308,12 @@ std::vector<uint8_t> NGCHS2Sigma::buildChatLogFileRange(Contact3Handle c, uint64
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_cr.valid(c_from_c.c)) {
|
ContactHandle4 c_from = _cs.contactHandle(c_from_c.c);
|
||||||
|
|
||||||
|
if (!static_cast<bool>(c_from)) {
|
||||||
continue; // ???
|
continue; // ???
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact3Handle c_from{_cr, c_from_c.c};
|
|
||||||
|
|
||||||
if (!c_from.all_of<Contact::Components::ToxGroupPeerPersistent>()) {
|
if (!c_from.all_of<Contact::Components::ToxGroupPeerPersistent>()) {
|
||||||
continue; // ???
|
continue; // ???
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
#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/message3/registry_message_model.hpp>
|
||||||
|
|
||||||
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
||||||
@ -24,7 +24,7 @@ struct TimeRangeRequest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class NGCHS2Sigma : public RegistryMessageModelEventI, public NGCFT1EventI {
|
class NGCHS2Sigma : public RegistryMessageModelEventI, public NGCFT1EventI {
|
||||||
Contact3Registry& _cr;
|
ContactStore4I& _cs;
|
||||||
RegistryMessageModelI& _rmm;
|
RegistryMessageModelI& _rmm;
|
||||||
ToxContactModel2& _tcm;
|
ToxContactModel2& _tcm;
|
||||||
NGCFT1& _nft;
|
NGCFT1& _nft;
|
||||||
@ -49,11 +49,11 @@ class NGCHS2Sigma : public RegistryMessageModelEventI, public NGCFT1EventI {
|
|||||||
|
|
||||||
// FIXME: workaround missing contact events
|
// FIXME: workaround missing contact events
|
||||||
// only used on peer exit (no, also used to quicken lookups)
|
// 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:
|
public:
|
||||||
NGCHS2Sigma(
|
NGCHS2Sigma(
|
||||||
Contact3Registry& cr,
|
ContactStore4I& cs,
|
||||||
RegistryMessageModelI& rmm,
|
RegistryMessageModelI& rmm,
|
||||||
ToxContactModel2& tcm,
|
ToxContactModel2& tcm,
|
||||||
NGCFT1& nft
|
NGCFT1& nft
|
||||||
@ -63,11 +63,11 @@ class NGCHS2Sigma : public RegistryMessageModelEventI, public NGCFT1EventI {
|
|||||||
|
|
||||||
float iterate(float delta);
|
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
|
// msg reg contact
|
||||||
// time ranges
|
// 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:
|
protected:
|
||||||
bool onEvent(const Message::Events::MessageConstruct&) override;
|
bool onEvent(const Message::Events::MessageConstruct&) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user