2024-11-03 18:21:02 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
|
|
|
|
|
|
|
#include <solanaceae/contact/contact_model3.hpp>
|
|
|
|
#include <solanaceae/message3/registry_message_model.hpp>
|
|
|
|
|
|
|
|
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
|
|
|
|
|
|
|
#include <entt/container/dense_map.hpp>
|
|
|
|
|
2024-11-22 13:51:25 +01:00
|
|
|
#include <solanaceae/util/span.hpp>
|
|
|
|
|
|
|
|
#include <vector>
|
2024-12-06 22:41:05 +01:00
|
|
|
#include <deque>
|
2024-11-22 13:51:25 +01:00
|
|
|
|
2024-11-03 18:21:02 +01:00
|
|
|
// fwd
|
|
|
|
class ToxContactModel2;
|
|
|
|
|
2024-11-22 13:51:25 +01:00
|
|
|
|
2024-11-28 12:39:57 +01:00
|
|
|
struct TimeRangeRequest {
|
2024-11-22 13:51:25 +01:00
|
|
|
uint64_t ts_start{0};
|
|
|
|
uint64_t ts_end{0};
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: move to own file
|
|
|
|
namespace Components {
|
2024-11-28 12:39:57 +01:00
|
|
|
struct IncommingTimeRangeRequestQueue {
|
2024-12-06 22:41:05 +01:00
|
|
|
struct Entry {
|
|
|
|
TimeRangeRequest ir;
|
|
|
|
std::vector<uint8_t> fid;
|
|
|
|
};
|
|
|
|
std::deque<Entry> _queue;
|
2024-11-22 13:51:25 +01:00
|
|
|
|
|
|
|
// we should remove/notadd queued requests
|
|
|
|
// that are subsets of same or larger ranges
|
2024-12-06 22:41:05 +01:00
|
|
|
void queueRequest(const TimeRangeRequest& new_request, const ByteSpan fid);
|
2024-11-22 13:51:25 +01:00
|
|
|
};
|
|
|
|
|
2024-11-28 12:39:57 +01:00
|
|
|
struct IncommingTimeRangeRequestRunning {
|
2024-11-22 13:51:25 +01:00
|
|
|
struct Entry {
|
2024-11-28 12:39:57 +01:00
|
|
|
TimeRangeRequest ir;
|
2024-12-06 22:41:05 +01:00
|
|
|
std::vector<uint8_t> data; // transfer data in memory
|
|
|
|
float last_activity {0.f};
|
2024-11-22 13:51:25 +01:00
|
|
|
};
|
|
|
|
entt::dense_map<uint8_t, Entry> _list;
|
|
|
|
};
|
|
|
|
} // Components
|
2024-11-03 18:21:02 +01:00
|
|
|
|
2024-12-07 11:38:31 +01:00
|
|
|
class NGCHS2Sigma : public RegistryMessageModelEventI, public NGCFT1EventI {
|
2024-11-03 18:21:02 +01:00
|
|
|
Contact3Registry& _cr;
|
|
|
|
RegistryMessageModelI& _rmm;
|
|
|
|
ToxContactModel2& _tcm;
|
|
|
|
NGCFT1& _nft;
|
|
|
|
NGCFT1EventProviderI::SubscriptionReference _nftep_sr;
|
|
|
|
|
2024-11-22 13:51:25 +01:00
|
|
|
float _iterate_heat {0.f};
|
|
|
|
constexpr static float _iterate_cooldown {1.22f}; // sec
|
|
|
|
|
2024-12-05 23:06:44 +01:00
|
|
|
// open/running range requests (by c)
|
2024-11-22 13:51:25 +01:00
|
|
|
// comp on peer c
|
2024-11-03 18:21:02 +01:00
|
|
|
|
2024-12-05 23:06:44 +01:00
|
|
|
// open/running range responses (by c)
|
2024-11-22 13:51:25 +01:00
|
|
|
// comp on peer c
|
|
|
|
|
|
|
|
// limit to 2 uploads per peer simultaniously
|
2024-11-28 12:39:57 +01:00
|
|
|
// TODO: increase for prod (4?) or maybe even lower?
|
2024-11-22 13:51:25 +01:00
|
|
|
// currently per type
|
|
|
|
constexpr static size_t _max_parallel_per_peer {2};
|
2024-11-03 18:21:02 +01:00
|
|
|
|
2024-11-22 13:51:25 +01:00
|
|
|
constexpr static bool _only_send_self_observed {true};
|
|
|
|
constexpr static int64_t _max_time_into_past_default {60*15}; // s
|
2024-11-03 18:21:02 +01:00
|
|
|
|
|
|
|
public:
|
2024-12-07 11:38:31 +01:00
|
|
|
NGCHS2Sigma(
|
2024-11-03 18:21:02 +01:00
|
|
|
Contact3Registry& cr,
|
|
|
|
RegistryMessageModelI& rmm,
|
|
|
|
ToxContactModel2& tcm,
|
2024-12-08 14:48:24 +01:00
|
|
|
NGCFT1& nft
|
2024-11-03 18:21:02 +01:00
|
|
|
);
|
|
|
|
|
2024-12-07 11:38:31 +01:00
|
|
|
~NGCHS2Sigma(void);
|
2024-11-03 18:21:02 +01:00
|
|
|
|
|
|
|
float iterate(float delta);
|
|
|
|
|
2024-11-28 12:39:57 +01:00
|
|
|
void handleTimeRange(Contact3Handle c, const Events::NGCFT1_recv_request&);
|
2024-11-03 18:21:02 +01:00
|
|
|
|
2024-12-05 23:06:44 +01:00
|
|
|
// msg reg contact
|
|
|
|
// time ranges
|
2024-12-06 22:41:05 +01:00
|
|
|
[[nodiscard]] std::vector<uint8_t> buildChatLogFileRange(Contact3Handle c, uint64_t ts_start, uint64_t ts_end);
|
2024-12-05 23:06:44 +01:00
|
|
|
|
2024-11-03 18:21:02 +01:00
|
|
|
protected:
|
|
|
|
bool onEvent(const Message::Events::MessageConstruct&) override;
|
|
|
|
bool onEvent(const Message::Events::MessageUpdated&) override;
|
|
|
|
bool onEvent(const Message::Events::MessageDestory&) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEvent(const Events::NGCFT1_recv_request&) override;
|
|
|
|
bool onEvent(const Events::NGCFT1_send_data&) override;
|
|
|
|
bool onEvent(const Events::NGCFT1_send_done&) override;
|
|
|
|
};
|
|
|
|
|