solanaceae_ngc_ft1/solanaceae/ngc_ft1_sha1/receiving_transfers.hpp

67 lines
2.3 KiB
C++
Raw Normal View History

2024-06-30 14:03:06 +02:00
#pragma once
#include <solanaceae/object_store/object_store.hpp>
#include <entt/container/dense_map.hpp>
2024-07-02 16:09:59 +02:00
#include "./util.hpp"
2024-06-30 14:03:06 +02:00
#include <cstdint>
#include <variant>
#include <vector>
struct ReceivingTransfers {
struct Entry {
struct Info {
ObjectHandle content;
// copy of info data
// too large?
std::vector<uint8_t> info_data;
};
struct Chunk {
ObjectHandle content;
std::vector<size_t> chunk_indices;
// or data?
// if memmapped, this would be just a pointer
};
std::variant<Info, Chunk> v;
float time_since_activity {0.f};
bool isInfo(void) const { return std::holds_alternative<Info>(v); }
bool isChunk(void) const { return std::holds_alternative<Chunk>(v); }
Info& getInfo(void) { return std::get<Info>(v); }
const Info& getInfo(void) const { return std::get<Info>(v); }
Chunk& getChunk(void) { return std::get<Chunk>(v); }
const Chunk& getChunk(void) const { return std::get<Chunk>(v); }
};
// key is groupid + peerid
// TODO: replace with contact
//using ReceivingTransfers = entt::dense_map<uint64_t, entt::dense_map<uint8_t, ReceivingTransferE>>;
entt::dense_map<uint64_t, entt::dense_map<uint8_t, Entry>> _data;
void tick(float delta);
2024-07-02 16:09:59 +02:00
Entry& emplaceInfo(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, const Entry::Info& info);
Entry& emplaceChunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, const Entry::Chunk& chunk);
2024-06-30 14:03:06 +02:00
2024-07-02 16:09:59 +02:00
bool containsPeer(uint32_t group_number, uint32_t peer_number) const { return _data.count(combine_ids(group_number, peer_number)); }
bool containsPeerTransfer(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id) const;
2024-06-30 14:03:06 +02:00
bool containsChunk(ObjectHandle o, size_t chunk_idx) const;
2024-07-02 16:09:59 +02:00
bool containsPeerChunk(uint32_t group_number, uint32_t peer_number, ObjectHandle o, size_t chunk_idx) const;
2024-06-30 14:03:06 +02:00
2024-07-02 16:09:59 +02:00
auto& getPeer(uint32_t group_number, uint32_t peer_number) { return _data.at(combine_ids(group_number, peer_number)); }
auto& getTransfer(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id) { return getPeer(group_number, peer_number).at(transfer_id); }
2024-06-30 14:03:06 +02:00
2024-07-02 16:09:59 +02:00
void removePeer(uint32_t group_number, uint32_t peer_number);
void removePeerTransfer(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
2024-06-30 14:03:06 +02:00
size_t size(void) const;
2024-07-02 16:09:59 +02:00
size_t sizePeer(uint32_t group_number, uint32_t peer_number) const;
2024-06-30 14:03:06 +02:00
};