#pragma once #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_chunk, have_all and 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}; entt::dense_map> chunk_hash_to_index; std::vector chunkIndices(const SHA1Digest& hash) const; bool haveChunk(const SHA1Digest& hash) const; }; 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 RemoteHave { struct Entry { bool have_all {false}; BitSet have; }; entt::dense_map others; }; struct ReRequestInfoTimer { float timer {0.f}; }; 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; }; 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 // ? the strategy *should* set this to the first byte we dont yet have uint64_t offset_into_file {0u}; }; // 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 stats; }; // used to populate stats struct TransferStatsTally { struct Peer { struct Entry { float time_point {0.f}; size_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