2024-06-28 15:13:17 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <solanaceae/contact/contact_model3.hpp>
|
|
|
|
#include <solanaceae/object_store/object_store.hpp>
|
|
|
|
|
|
|
|
#include "./components.hpp"
|
|
|
|
|
2024-07-02 15:52:25 +02:00
|
|
|
#include "./receiving_transfers.hpp"
|
|
|
|
|
2024-06-28 15:13:17 +02:00
|
|
|
#include <entt/container/dense_map.hpp>
|
|
|
|
#include <entt/container/dense_set.hpp>
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2024-07-07 16:49:31 +02:00
|
|
|
#include <random>
|
2024-06-28 15:13:17 +02:00
|
|
|
|
|
|
|
//#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
|
|
|
|
|
|
|
// goal is to always keep 2 transfers running and X(6) requests queued up
|
|
|
|
// per peer
|
|
|
|
|
2024-07-08 18:12:47 +02:00
|
|
|
struct ChunkPickerUpdateTag {};
|
|
|
|
|
|
|
|
struct ChunkPickerTimer {
|
|
|
|
// adds update tag on 0
|
|
|
|
float timer {0.f};
|
|
|
|
};
|
|
|
|
|
2024-06-28 15:13:17 +02:00
|
|
|
// contact component?
|
|
|
|
struct ChunkPicker {
|
|
|
|
// max transfers
|
|
|
|
static constexpr size_t max_tf_info_requests {1};
|
2024-07-10 10:41:25 +02:00
|
|
|
static constexpr size_t max_tf_chunk_requests {3}; // TODO: dynamic, function/factor of (window(delay*speed)/chunksize)
|
2024-06-28 15:13:17 +02:00
|
|
|
|
2024-07-10 10:41:25 +02:00
|
|
|
// TODO: cheaper init? tls rng for deep seeding?
|
|
|
|
std::minstd_rand _rng{std::random_device{}()};
|
2024-06-28 15:13:17 +02:00
|
|
|
|
|
|
|
// TODO: handle with hash utils?
|
|
|
|
struct ParticipationEntry {
|
|
|
|
ParticipationEntry(void) {}
|
2024-07-10 11:13:57 +02:00
|
|
|
ParticipationEntry(uint16_t s) : should_skip(s) {}
|
2024-06-28 15:13:17 +02:00
|
|
|
// skips in round robin -> lower should_skip => higher priority
|
2024-07-10 10:41:25 +02:00
|
|
|
// TODO: replace with enum value
|
2024-06-28 15:13:17 +02:00
|
|
|
uint16_t should_skip {2}; // 0 high, 8 low (double each time? 0,1,2,4,8)
|
2024-07-10 11:13:57 +02:00
|
|
|
uint16_t skips {0};
|
2024-06-28 15:13:17 +02:00
|
|
|
};
|
|
|
|
entt::dense_map<Object, ParticipationEntry> participating_unfinished;
|
|
|
|
Object participating_in_last {entt::null};
|
|
|
|
|
2024-07-10 10:41:25 +02:00
|
|
|
private: // TODO: properly sort
|
2024-07-08 18:12:47 +02:00
|
|
|
// updates participating_unfinished
|
2024-07-03 12:11:20 +02:00
|
|
|
void updateParticipation(
|
|
|
|
Contact3Handle c,
|
|
|
|
ObjectRegistry& objreg
|
|
|
|
);
|
2024-07-08 18:12:47 +02:00
|
|
|
public:
|
|
|
|
|
2024-07-10 10:41:25 +02:00
|
|
|
// ---------- tick ----------
|
2024-07-03 12:11:20 +02:00
|
|
|
|
2024-06-28 15:13:17 +02:00
|
|
|
//void sendInfoRequests();
|
2024-07-10 10:41:25 +02:00
|
|
|
|
2024-06-28 15:13:17 +02:00
|
|
|
// is this like a system?
|
|
|
|
struct ContentChunkR {
|
|
|
|
ObjectHandle object;
|
|
|
|
size_t chunk_index;
|
|
|
|
};
|
|
|
|
// returns list of chunks to request
|
2024-07-03 12:11:20 +02:00
|
|
|
[[nodiscard]] std::vector<ContentChunkR> updateChunkRequests(
|
2024-06-28 15:13:17 +02:00
|
|
|
Contact3Handle c,
|
|
|
|
ObjectRegistry& objreg,
|
2024-07-07 12:44:17 +02:00
|
|
|
ReceivingTransfers& rt,
|
|
|
|
const size_t open_requests
|
2024-06-28 15:13:17 +02:00
|
|
|
//NGCFT1& nft
|
2024-07-02 15:52:25 +02:00
|
|
|
);
|
2024-06-28 15:13:17 +02:00
|
|
|
};
|
|
|
|
|