2024-06-24 16:42:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <solanaceae/contact/components.hpp>
|
|
|
|
#include <solanaceae/message3/components.hpp>
|
|
|
|
#include <solanaceae/message3/registry_message_model.hpp>
|
|
|
|
|
2024-06-25 12:45:28 +02:00
|
|
|
#include <solanaceae/util/bitset.hpp>
|
|
|
|
|
2024-06-24 16:42:23 +02:00
|
|
|
#include <entt/container/dense_set.hpp>
|
2024-07-12 15:04:49 +02:00
|
|
|
#include <entt/container/dense_map.hpp>
|
2024-06-24 16:42:23 +02:00
|
|
|
|
|
|
|
#include "./ft1_sha1_info.hpp"
|
|
|
|
#include "./hash_utils.hpp"
|
|
|
|
|
|
|
|
#include <vector>
|
2024-07-12 15:04:49 +02:00
|
|
|
#include <deque>
|
2024-06-24 16:42:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
// TODO: rename to object components
|
|
|
|
namespace Components {
|
|
|
|
|
|
|
|
struct Messages {
|
2024-06-25 12:45:28 +02:00
|
|
|
// dense set instead?
|
2024-06-24 16:42:23 +02:00
|
|
|
std::vector<Message3Handle> messages;
|
|
|
|
};
|
|
|
|
|
|
|
|
using FT1InfoSHA1 = FT1InfoSHA1;
|
|
|
|
|
|
|
|
struct FT1InfoSHA1Data {
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FT1InfoSHA1Hash {
|
|
|
|
std::vector<uint8_t> hash;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FT1ChunkSHA1Cache {
|
2024-06-25 21:09:46 +02:00
|
|
|
// TODO: extract have_chunk, have_all and have_count to generic comp
|
|
|
|
|
2024-06-25 12:08:17 +02:00
|
|
|
// have_chunk is the size of info.chunks.size(), or empty if have_all
|
|
|
|
// keep in mind bitset rounds up to 8s
|
|
|
|
BitSet have_chunk{0};
|
|
|
|
|
2024-06-24 16:42:23 +02:00
|
|
|
bool have_all {false};
|
|
|
|
size_t have_count {0};
|
|
|
|
entt::dense_map<SHA1Digest, std::vector<size_t>> chunk_hash_to_index;
|
|
|
|
|
|
|
|
std::vector<size_t> chunkIndices(const SHA1Digest& hash) const;
|
|
|
|
bool haveChunk(const SHA1Digest& hash) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FT1ChunkSHA1Requested {
|
|
|
|
// requested chunks with a timer since last request
|
2024-07-07 12:44:17 +02:00
|
|
|
struct Entry {
|
|
|
|
float timer {0.f};
|
|
|
|
Contact3 c {entt::null};
|
|
|
|
};
|
|
|
|
entt::dense_map<size_t, Entry> chunks;
|
2024-06-24 16:42:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: once announce is shipped, remove the "Suspected"
|
|
|
|
struct SuspectedParticipants {
|
|
|
|
entt::dense_set<Contact3> participants;
|
|
|
|
};
|
|
|
|
|
2024-06-25 21:09:46 +02:00
|
|
|
struct RemoteHave {
|
|
|
|
struct Entry {
|
|
|
|
bool have_all {false};
|
|
|
|
BitSet have;
|
|
|
|
};
|
|
|
|
entt::dense_map<Contact3, Entry> others;
|
|
|
|
};
|
|
|
|
|
2024-06-24 16:42:23 +02:00
|
|
|
struct ReRequestInfoTimer {
|
|
|
|
float timer {0.f};
|
|
|
|
};
|
|
|
|
|
2024-07-14 12:38:00 +02:00
|
|
|
struct AnnounceTargets {
|
|
|
|
entt::dense_set<Contact3> targets;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ReAnnounceTimer {
|
|
|
|
float timer {0.f};
|
|
|
|
float last_max {0.f};
|
|
|
|
|
|
|
|
void set(const float new_timer);
|
|
|
|
|
|
|
|
// exponential back-off
|
|
|
|
void reset(void);
|
|
|
|
|
|
|
|
// on peer join to group
|
|
|
|
void lower(void);
|
|
|
|
};
|
|
|
|
|
2024-07-10 11:13:57 +02:00
|
|
|
struct DownloadPriority {
|
|
|
|
// download/retreival priority in comparison to other objects
|
|
|
|
// not all backends implement this
|
|
|
|
// priority can be weak, meaning low priority dls will still get transfer activity, just less often
|
|
|
|
enum class Priority {
|
|
|
|
HIGHER,
|
|
|
|
HIGH,
|
|
|
|
NORMAL,
|
|
|
|
LOW,
|
|
|
|
LOWER,
|
|
|
|
} p = Priority::NORMAL;
|
|
|
|
};
|
|
|
|
|
2024-06-24 16:42:23 +02:00
|
|
|
struct ReadHeadHint {
|
|
|
|
// points to the first byte we want
|
|
|
|
// this is just a hint, that can be set from outside
|
|
|
|
// to guide the sequential "piece picker" strategy
|
2024-07-10 11:13:57 +02:00
|
|
|
// ? the strategy *should* set this to the first byte we dont yet have
|
2024-06-24 16:42:23 +02:00
|
|
|
uint64_t offset_into_file {0u};
|
|
|
|
};
|
|
|
|
|
2024-07-12 15:04:49 +02:00
|
|
|
// this is per object/content
|
|
|
|
// more aplicable than "separated", so should be supported by most backends
|
|
|
|
struct TransferStats {
|
|
|
|
// in bytes per second
|
|
|
|
float rate_up {0.f};
|
|
|
|
float rate_down {0.f};
|
|
|
|
|
|
|
|
// bytes
|
|
|
|
uint64_t total_up {0u};
|
|
|
|
uint64_t total_down {0u};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TransferStatsSeparated {
|
|
|
|
entt::dense_map<Contact3, TransferStats> stats;
|
|
|
|
};
|
|
|
|
|
|
|
|
// used to populate stats
|
|
|
|
struct TransferStatsTally {
|
|
|
|
struct Peer {
|
|
|
|
struct Entry {
|
2024-07-13 11:46:33 +02:00
|
|
|
float time_point {0.f};
|
2024-07-12 15:04:49 +02:00
|
|
|
size_t bytes {0u};
|
2024-07-13 11:46:33 +02:00
|
|
|
bool accounted {false};
|
2024-07-12 15:04:49 +02:00
|
|
|
};
|
|
|
|
std::deque<Entry> recently_sent;
|
|
|
|
std::deque<Entry> recently_received;
|
2024-07-13 11:46:33 +02:00
|
|
|
|
|
|
|
// keep atleast 4 or 1sec
|
|
|
|
// trim too old front
|
|
|
|
void trimSent(const float time_now);
|
|
|
|
void trimReceived(const float time_now);
|
2024-07-12 15:04:49 +02:00
|
|
|
};
|
|
|
|
entt::dense_map<Contact3, Peer> tally;
|
|
|
|
};
|
|
|
|
|
2024-06-24 16:42:23 +02:00
|
|
|
} // Components
|
|
|
|
|