#pragma once #include #include #include #include #include #include #include #include "./ft1_sha1_info.hpp" #include "./hash_utils.hpp" #include #include // TODO: rename to object components namespace Components { struct Messages { // dense set instead? std::vector messages; }; using FT1InfoSHA1 = FT1InfoSHA1; struct FT1InfoSHA1Data { std::vector data; }; struct FT1InfoSHA1Hash { std::vector hash; }; struct FT1ChunkSHA1Cache { // TODO: extract have_count to generic comp // 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}; //bool have_all {false}; size_t have_count {0}; // move? entt::dense_map> chunk_hash_to_index; std::vector chunkIndices(const SHA1Digest& hash) const; bool haveChunk(ObjectHandle o, const SHA1Digest& hash) const; }; struct FT1File2 { // the cached file2 for faster access // should be destroyed when no activity and recreated on demand std::unique_ptr file; }; struct FT1ChunkSHA1Requested { // requested chunks with a timer since last request struct Entry { float timer {0.f}; Contact3 c {entt::null}; }; entt::dense_map chunks; }; // TODO: once announce is shipped, remove the "Suspected" struct SuspectedParticipants { entt::dense_set participants; }; struct ReRequestInfoTimer { float timer {0.f}; }; struct AnnounceTargets { entt::dense_set 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); }; struct TransferStatsSeparated { entt::dense_map stats; }; // used to populate stats struct TransferStatsTally { struct Peer { struct Entry { float time_point {0.f}; uint64_t bytes {0u}; bool accounted {false}; }; std::deque recently_sent; std::deque recently_received; // keep atleast 4 or 1sec // trim too old front void trimSent(const float time_now); void trimReceived(const float time_now); }; entt::dense_map tally; }; } // Components