solanaceae_ngc_ft1/solanaceae/ngc_hs2/ngc_hs2_rizzler.hpp

70 lines
1.6 KiB
C++
Raw Normal View History

2024-12-07 23:34:19 +01:00
#pragma once
#include <solanaceae/contact/contact_model3.hpp>
2024-12-08 14:48:24 +01:00
#include <solanaceae/toxcore/tox_event_interface.hpp>
2024-12-07 23:34:19 +01:00
#include <solanaceae/ngc_ft1/ngcft1.hpp>
#include <solanaceae/ngc_ft1_sha1/sha1_ngcft1.hpp>
2024-12-07 23:34:19 +01:00
// fwd
class ToxContactModel2;
class RegistryMessageModelI;
2024-12-07 23:34:19 +01:00
class NGCHS2Rizzler : public ToxEventI, public NGCFT1EventI {
Contact3Registry& _cr;
RegistryMessageModelI& _rmm;
ToxContactModel2& _tcm;
NGCFT1& _nft;
NGCFT1EventProviderI::SubscriptionReference _nftep_sr;
2024-12-08 14:48:24 +01:00
ToxEventProviderI::SubscriptionReference _tep_sr;
SHA1_NGCFT1& _sha1_nft;
2024-12-07 23:34:19 +01:00
// 5s-6s
const float _delay_before_first_request_min {5.f};
const float _delay_before_first_request_add {1.f};
std::uniform_real_distribution<float> _rng_dist {0.0f, 1.0f};
std::minstd_rand _rng;
struct RequestQueueInfo {
float delay; // const
float timer;
uint64_t sync_delta; //?
};
// request queue
// c -> delay, timer
std::map<Contact3, RequestQueueInfo> _request_queue;
public:
NGCHS2Rizzler(
Contact3Registry& cr,
RegistryMessageModelI& rmm,
ToxContactModel2& tcm,
2024-12-08 14:48:24 +01:00
NGCFT1& nft,
ToxEventProviderI& tep,
SHA1_NGCFT1& sha1_nft
2024-12-07 23:34:19 +01:00
);
~NGCHS2Rizzler(void);
float iterate(float delta);
protected:
bool sendRequest(
uint32_t group_number, uint32_t peer_number,
uint64_t ts_start, uint64_t ts_end
);
void handleMsgPack(Contact3Handle c, const std::vector<uint8_t>& data);
2024-12-07 23:34:19 +01:00
protected:
bool onEvent(const Events::NGCFT1_recv_init&) override;
bool onEvent(const Events::NGCFT1_recv_data&) override;
bool onEvent(const Events::NGCFT1_recv_done&) override;
protected:
bool onToxEvent(const Tox_Event_Group_Peer_Join* e) override;
};